on xenial help sign in
Add emblem to the preview header widget
ceaf21cAlbert Astals Cid
qml/Dash/Previews/PreviewHeader.qml+37−9
@@ -25,6 +25,7 @@ import "../"
25 * The mascot fall back image comes in widgetData["fallback"]
25 * The mascot fall back image comes in widgetData["fallback"]
26 * The subtitle comes in widgetData["subtitle"]
26 * The subtitle comes in widgetData["subtitle"]
27 * The attributes comes in widgetData["attributes"]
27 * The attributes comes in widgetData["attributes"]
28+ * The emblem comes in widgetData["emblem"]
28 */
29 */
29
30
30PreviewWidget {
31PreviewWidget {
@@ -40,6 +41,7 @@ PreviewWidget {
40 readonly property string title: root.widgetData["title"] || ""
41 readonly property string title: root.widgetData["title"] || ""
41 readonly property string subtitle: root.widgetData["subtitle"] || ""
42 readonly property string subtitle: root.widgetData["subtitle"] || ""
42 readonly property var attributes: root.widgetData["attributes"] || null
43 readonly property var attributes: root.widgetData["attributes"] || null
44+ readonly property url emblem: root.widgetData["emblem"] || ""
43 readonly property color fontColor: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText
45 readonly property color fontColor: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText
44
46
45 // Rewire the source since we may have unwired it on onStatusChanged
47 // Rewire the source since we may have unwired it on onStatusChanged
@@ -98,16 +100,42 @@ PreviewWidget {
98 spacing: units.dp(2)
100 spacing: units.dp(2)
99 anchors.verticalCenter: parent.verticalCenter
101 anchors.verticalCenter: parent.verticalCenter
100
102
101− Label {
103+ Item {
102− id: titleLabel
103− objectName: "titleLabel"
104 anchors { left: parent.left; right: parent.right }
104 anchors { left: parent.left; right: parent.right }
105+ height: titleLabel.height
106+
107+ Label {
108+ id: titleLabel
109+ objectName: "titleLabel"
110+ anchors {
111+ left: parent.left;
112+ right: iconLoader.right
113+ rightMargin: iconLoader.width > 0 ? units.gu(0.5) : 0
114+ }
105− elide: Text.ElideRight
115+ elide: Text.ElideRight
106− font.weight: Font.Normal
116+ font.weight: Font.Normal
107− fontSize: "large"
117+ fontSize: "large"
108− wrapMode: Text.Wrap
118+ wrapMode: Text.Wrap
109− color: headerRoot.fontColor
119+ color: headerRoot.fontColor
110− text: headerRoot.title
120+ text: headerRoot.title
121+ }
122+
123+ Loader {
124+ id: iconLoader
125+ active: headerRoot.emblem != ""
126+ anchors {
127+ bottom: titleLabel.baseline
128+ right: parent.right
129+ }
130+ sourceComponent: Icon {
131+ objectName: "emblemIcon"
132+ source: headerRoot.emblem
133+ color: headerRoot.fontColor
134+ height: source != "" ? titleLabel.font.pixelSize : 0
135+ // FIXME Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
136+ width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth
137+ }
138+ }
111 }
139 }
112
140
113 Loader {
141 Loader {
tests/qmltests/Dash/Previews/tst_PreviewHeader.qml+18−1
@@ -38,6 +38,14 @@ Rectangle {
38 "attributes": [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}]
38 "attributes": [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}]
39 }
39 }
40
40
41+ property var emblemheaderjson: {
42+ "title": "THE TITLE",
43+ "subtitle": "Something catchy",
44+ "mascot": "../graphics/play_button.png",
45+ "attributes": [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}],
46+ "emblem": Qt.resolvedUrl("../artwork/emblem.png")
47+ }
48+
41 property var brokenheaderjson: {
49 property var brokenheaderjson: {
42 "title": "THE TITLE",
50 "title": "THE TITLE",
43 "subtitle": "Something catchy",
51 "subtitle": "Something catchy",
@@ -56,7 +64,7 @@ Rectangle {
56
64
57 PreviewHeader {
65 PreviewHeader {
58 id: previewHeader
66 id: previewHeader
59− widgetData: headerjson
67+ widgetData: emblemheaderjson
60 width: units.gu(30)
68 width: units.gu(30)
61
69
62 Rectangle {
70 Rectangle {
@@ -128,6 +136,15 @@ Rectangle {
128 }
136 }
129 }
137 }
130
138
139+ function test_emblem() {
140+ previewHeader.widgetData = emblemheaderjson;
141+
142+ var emblemIcon = findChild(previewHeader, "emblemIcon");
143+ var titleLabel = findChild(previewHeader, "titleLabel");
144+ verify(emblemIcon.height > 0);
145+ compare(emblemIcon.height, titleLabel.font.pixelSize);
146+ }
147+
131 function test_json() {
148 function test_json() {
132 headerjson = origHeaderjson;
149 headerjson = origHeaderjson;
133 previewHeader.widgetData = headerjson;
150 previewHeader.widgetData = headerjson;