on xenial help sign in
Add emblem to the preview header widget
commitceaf21cec7fef167bdc41bd35b03b62b810c879c authorAlbert Astals Cid <albert.astals@canonical.com> dateMon 15 Feb 2016, 12:17 (11 years ago) parent90bbff2
2 files changed+55−10
qml/Dash/Previews/PreviewHeader.qml+37−9 tests/qmltests/Dash/Previews/tst_PreviewHeader.qml+18−1
qml/Dash/Previews/PreviewHeader.qml+37−9
@@ -25,6 +25,7 @@ import "../"
2525 * The mascot fall back image comes in widgetData["fallback"]
2626 * The subtitle comes in widgetData["subtitle"]
2727 * The attributes comes in widgetData["attributes"]
28+ * The emblem comes in widgetData["emblem"]
2829 */
2930
3031PreviewWidget {
@@ -40,6 +41,7 @@ PreviewWidget {
4041 readonly property string title: root.widgetData["title"] || ""
4142 readonly property string subtitle: root.widgetData["subtitle"] || ""
4243 readonly property var attributes: root.widgetData["attributes"] || null
44+ readonly property url emblem: root.widgetData["emblem"] || ""
4345 readonly property color fontColor: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText
4446
4547 // Rewire the source since we may have unwired it on onStatusChanged
@@ -98,16 +100,42 @@ PreviewWidget {
98100 spacing: units.dp(2)
99101 anchors.verticalCenter: parent.verticalCenter
100102
101− Label {
102− id: titleLabel
103− objectName: "titleLabel"
103+ Item {
104104 anchors { left: parent.left; right: parent.right }
105− elide: Text.ElideRight
106− font.weight: Font.Normal
107− fontSize: "large"
108− wrapMode: Text.Wrap
109− color: headerRoot.fontColor
110− text: headerRoot.title
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+ }
115+ elide: Text.ElideRight
116+ font.weight: Font.Normal
117+ fontSize: "large"
118+ wrapMode: Text.Wrap
119+ color: headerRoot.fontColor
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+ }
111139 }
112140
113141 Loader {
tests/qmltests/Dash/Previews/tst_PreviewHeader.qml+18−1
@@ -38,6 +38,14 @@ Rectangle {
3838 "attributes": [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}]
3939 }
4040
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+
4149 property var brokenheaderjson: {
4250 "title": "THE TITLE",
4351 "subtitle": "Something catchy",
@@ -56,7 +64,7 @@ Rectangle {
5664
5765 PreviewHeader {
5866 id: previewHeader
59− widgetData: headerjson
67+ widgetData: emblemheaderjson
6068 width: units.gu(30)
6169
6270 Rectangle {
@@ -128,6 +136,15 @@ Rectangle {
128136 }
129137 }
130138
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+
131148 function test_json() {
132149 headerjson = origHeaderjson;
133150 previewHeader.widgetData = headerjson;