-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostLayout.qml
More file actions
157 lines (136 loc) · 4.98 KB
/
PostLayout.qml
File metadata and controls
157 lines (136 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import QtQuick 2.0
import QtGraphicalEffects 1.0
import Ubuntu.Components 0.1
import "Utils/Misc.js" as MiscUtils
Item {
id: postRow
property var postObj
property real spacingConstant: units.gu(1.25)
readonly property bool stickied: postObj ? postObj.data.stickied : false
signal commentsTriggered
height: Math.max(postColumn.height, postIcon.height) + units.gu(2.5)
anchors{
left: parent.left
right: parent.right
}
EmblemRow {
id: emblemRow
thingObj: postRow.postObj
padding: postRow.spacingConstant
lineHeight: emblemRow.height
}
UbuntuShape {
id: postIcon
property bool hasThumbnail: postObj !== undefined && postObj.data.thumbnail !== "self" && postObj.data.thumbnail !== "default" && postObj.data.thumbnail !== "nsfw"
color: "#2e0020"
anchors{
top: parent.top
topMargin: postRow.spacingConstant
left: parent.left
leftMargin: postRow.spacingConstant
}
width: visible ? units.gu(6) : 0
height: units.gu(6)
image: Image {
source: postIcon.hasThumbnail ? postObj.data.thumbnail : ""
fillMode: Image.PreserveAspectCrop
}
visible: hasThumbnail
}
Column {
id: postColumn
height: childrenRect.height
anchors {
top: parent.top
topMargin: postRow.spacingConstant
left: postIcon.right
leftMargin: postIcon.visible ? units.gu(1) : 0
right: postComments.left
}
spacing: units.gu(0.25)
Label {
id: postTitle
text: postObj ? MiscUtils.simpleFixHtmlChars(postObj.data.title) : ""
width: parent.width
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignLeft
font.weight: Font.DemiBold
color: !postRow.stickied ? UbuntuColors.coolGrey : "#2D692D"
}
Row {
id: postInfo
height: Math.max(postScore.height, postMiniInfo.height)
spacing: units.gu(1)
Label {
id: postScore
text: postObj ? " " + postObj.data.score : ":)"
color: "#999999"
horizontalAlignment: Text.AlignLeft
fontSize: "large"
font.weight: Font.Light
}
Label {
id: postMiniInfo
text: {
var author = postObj ? postObj.data.author : "author"
if (postObj && postObj.data.distinguished === "admin"){
author = "<font color='#DF4D4D'>" + author + " [a]</font>"
} else if (postObj && postObj.data.distinguished === "moderator"){
author = "<font color='#6EAF6E'>" + author + " [m]</font>"
}
var subreddit = postObj ? postObj.data.subreddit : "reddit"
var over18 = postObj && postObj.data.over_18 ? "<b><font color='#D97474'>NSFW</font> ·</b> " : ""
var timeRaw = postObj ? postObj.data.created_utc : 0
var time = MiscUtils.timeSince(new Date(timeRaw * 1000))
var domain = postObj ? postObj.data.domain : "reddit.com"
return "<b>" + author + "</b> in <b>r/" + subreddit + "</b><br/>" + over18 + time + " <b>·</b> " + domain
}
horizontalAlignment: Text.AlignLeft
fontSize: "x-small"
color: "#999999"
}
}
}
MouseArea {
id: postComments
width: units.gu(5)
height: parent.height - 2*postRow.spacingConstant
anchors{
top: emblemRow.bottom
topMargin: emblemRow.empty ? postRow.spacingConstant : 0
right: parent.right
rightMargin: postRow.spacingConstant
}
onClicked: postRow.commentsTriggered()
z: -1
Label {
text: postObj ? MiscUtils.commentsSimple(postObj.data.num_comments) : "0"
color: "white"
anchors {
verticalCenter: parent.verticalCenter
verticalCenterOffset: units.gu(-0.4)
horizontalCenter: parent.horizontalCenter
horizontalCenterOffset: units.gu(1)
}
fontSize: "xx-small"
font.weight: Font.DemiBold
z: 100
}
Image {
id: commentIcon
source: "media/ui/comments@30.svg"
width: units.gu(3.125); height: units.gu(3.125)
anchors {
verticalCenter: parent.verticalCenter
horizontalCenter: parent.horizontalCenter
horizontalCenterOffset: units.gu(1)
}
sourceSize { width: width; height: height }
}
ColorOverlay {
anchors.fill: commentIcon
source: commentIcon
color: "#bababa"
}
}
}