Merge lp:~unity-team/ubuntu-settings-components/status-icon into lp:~registry/ubuntu-settings-components/trunk

Proposed by Michał Sawicz
Status: Merged
Approved by: Nick Dedekind
Approved revision: 85
Merged at revision: 70
Proposed branch: lp:~unity-team/ubuntu-settings-components/status-icon
Merge into: lp:~registry/ubuntu-settings-components/trunk
Prerequisite: lp:~unity-team/ubuntu-settings-components/suru-theme
Diff against target: 307 lines (+243/-0)
6 files modified
SettingsComponents.qml (+30/-0)
Ubuntu/Settings/Components/StatusIcon.qml (+129/-0)
Ubuntu/Settings/Components/qmldir (+1/-0)
debian/control (+2/-0)
tests/qmltests/CMakeLists.txt (+1/-0)
tests/qmltests/Components/tst_StatusIcon.qml (+80/-0)
To merge this branch: bzr merge lp:~unity-team/ubuntu-settings-components/status-icon
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Nick Dedekind (community) Approve
Review via email: mp+225034@code.launchpad.net

Commit message

Add new StatusIcon component.

New run-time dependency: suru-icon-theme.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

A couple of comments added

review: Needs Fixing
Revision history for this message
Michał Sawicz (saviq) wrote :

Fixed.

Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

LGTM.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'SettingsComponents.qml'
2--- SettingsComponents.qml 2014-07-01 12:51:37 +0000
3+++ SettingsComponents.qml 2014-07-01 12:51:37 +0000
4@@ -18,6 +18,7 @@
5
6 import QtQuick 2.0
7 import Ubuntu.Components 0.1
8+import Ubuntu.Settings.Components 0.1
9 import Ubuntu.Settings.Menus 0.1
10
11 MainView {
12@@ -236,6 +237,35 @@
13 }
14 }
15 }
16+
17+ Row {
18+ anchors {
19+ left: parent.left
20+ right: parent.right
21+ }
22+
23+ spacing: units.gu(1)
24+
25+ Label {
26+ text: "StatusIcon"
27+ anchors.verticalCenter: parent.verticalCenter
28+ }
29+
30+ StatusIcon {
31+ height: units.gu(5)
32+ source: "image://theme/gps"
33+ }
34+
35+ StatusIcon {
36+ height: units.gu(5)
37+ source: "image://theme/battery-caution"
38+ }
39+
40+ StatusIcon {
41+ height: units.gu(5)
42+ source: "image://theme/missing,gpm-battery-000-charging"
43+ }
44+ }
45 }
46 }
47 }
48
49=== added file 'Ubuntu/Settings/Components/StatusIcon.qml'
50--- Ubuntu/Settings/Components/StatusIcon.qml 1970-01-01 00:00:00 +0000
51+++ Ubuntu/Settings/Components/StatusIcon.qml 2014-07-01 12:51:37 +0000
52@@ -0,0 +1,129 @@
53+/*
54+ * Copyright 2014 Canonical Ltd.
55+ *
56+ * This program is free software; you can redistribute it and/or modify
57+ * it under the terms of the GNU General Public License as published by
58+ * the Free Software Foundation; version 3.
59+ *
60+ * This program is distributed in the hope that it will be useful,
61+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
62+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63+ * GNU General Public License for more details.
64+ *
65+ * You should have received a copy of the GNU General Public License
66+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
67+ */
68+
69+import QtQuick 2.0
70+
71+Item {
72+ id: root
73+
74+ /*!
75+ The source of the icon to display.
76+ \qmlproperty url source
77+ */
78+ property url source
79+
80+ /*!
81+ The color that all pixels that originally are of color \l keyColor should take.
82+ \qmlproperty color color
83+ */
84+ property alias color: colorizedImage.keyColorOut
85+
86+ /*!
87+ The color of the pixels that should be colorized.
88+ By default it is set to #808080.
89+ \qmlproperty color keyColor
90+ */
91+ property alias keyColor: colorizedImage.keyColorIn
92+
93+ // FIXME: should only be "status", but overriding in settings app doesn't work.
94+ property var sets: ["status","apps"]
95+
96+ implicitWidth: image.width
97+
98+ Image {
99+ id: image
100+ objectName: "image"
101+ anchors { top: parent.top; bottom: parent.bottom }
102+ sourceSize.height: height
103+
104+ visible: !colorizedImage.active
105+
106+ property string iconPath: "/usr/share/icons/suru/%1/scalable/%2.svg"
107+ property var icons: {
108+ if (String(root.source).match(/^image:\/\/theme/)) {
109+ return String(root.source).replace("image://theme/", "").split(",");
110+ } else return null;
111+ }
112+ property int fallback: 0
113+ property int setFallback: 0
114+
115+ Component.onCompleted: updateSource()
116+ onStatusChanged: if (status == Image.Error) bump();
117+ onIconsChanged: reset()
118+
119+ Connections {
120+ target: root
121+ onSetsChanged: image.reset()
122+ }
123+
124+ function reset() {
125+ fallback = 0;
126+ setFallback = 0;
127+
128+ updateSource();
129+ }
130+
131+ function bump() {
132+ if (icons === null) return;
133+ if (fallback < icons.length - 1) fallback += 1;
134+ else if (setFallback < root.sets.length - 1) {
135+ setFallback += 1;
136+ fallback = 0;
137+ } else {
138+ console.warn("Could not load StatusIcon with source \"%1\" and sets %2.".arg(root.source).arg(root.sets));
139+ return;
140+ }
141+
142+ updateSource();
143+ }
144+
145+ function updateSource() {
146+ if (icons === null) {
147+ source = root.source;
148+ } else {
149+ source = (root.sets && root.sets.length > setFallback) && (icons && icons.length > fallback) ?
150+ iconPath.arg(root.sets[setFallback]).arg(icons[fallback]) : "";
151+ }
152+ }
153+ }
154+
155+ ShaderEffect {
156+ id: colorizedImage
157+
158+ anchors.fill: parent
159+ visible: active && image.status == Image.Ready
160+
161+ // Whether or not a color has been set.
162+ property bool active: keyColorOut != Qt.rgba(0.0, 0.0, 0.0, 0.0)
163+
164+ property Image source: visible ? image : null
165+ property color keyColorOut: Qt.rgba(0.0, 0.0, 0.0, 0.0)
166+ property color keyColorIn: "#808080"
167+ property real threshold: 0.1
168+
169+ fragmentShader: "
170+ varying highp vec2 qt_TexCoord0;
171+ uniform sampler2D source;
172+ uniform highp vec4 keyColorOut;
173+ uniform highp vec4 keyColorIn;
174+ uniform lowp float threshold;
175+ uniform lowp float qt_Opacity;
176+ void main() {
177+ lowp vec4 sourceColor = texture2D(source, qt_TexCoord0);
178+ gl_FragColor = mix(vec4(keyColorOut.rgb, 1.0) * sourceColor.a, sourceColor, step(threshold, distance(sourceColor.rgb / sourceColor.a, keyColorIn.rgb))) * qt_Opacity;
179+ }"
180+ }
181+}
182
183=== modified file 'Ubuntu/Settings/Components/qmldir'
184--- Ubuntu/Settings/Components/qmldir 2013-10-29 17:40:23 +0000
185+++ Ubuntu/Settings/Components/qmldir 2014-07-01 12:51:37 +0000
186@@ -5,3 +5,4 @@
187 HeroMessageHeader 0.1 HeroMessageHeader.qml
188 IconVisual 0.1 IconVisual.qml
189 QuickReply 0.1 QuickReply.qml
190+StatusIcon 0.1 StatusIcon.qml
191
192=== modified file 'debian/control'
193--- debian/control 2014-07-01 12:51:37 +0000
194+++ debian/control 2014-07-01 12:51:37 +0000
195@@ -13,6 +13,7 @@
196 qtdeclarative5-qtquick2-plugin,
197 qtdeclarative5-test-plugin,
198 qtdeclarative5-ubuntu-ui-toolkit-plugin (>= 0.1.48),
199+ suru-icon-theme,
200 Standards-Version: 3.9.4
201 Homepage: https://launchpad.net/ubuntu-settings-components
202 # If you don't have have commit access to this branch but would like to upload
203@@ -27,6 +28,7 @@
204 Depends: qml-module-qtquick-layouts,
205 qtdeclarative5-ubuntu-settings-components-assets (= ${source:Version}),
206 qtdeclarative5-ubuntu-ui-toolkit-plugin (>= 0.1.48),
207+ suru-icon-theme,
208 ${misc:Depends},
209 ${shlibs:Depends},
210 Description: Ubuntu Settings Components
211
212=== modified file 'tests/qmltests/CMakeLists.txt'
213--- tests/qmltests/CMakeLists.txt 2013-10-04 10:10:47 +0000
214+++ tests/qmltests/CMakeLists.txt 2014-07-01 12:51:37 +0000
215@@ -11,6 +11,7 @@
216 )
217
218 add_qml_test(Components Calendar)
219+add_qml_test(Components StatusIcon)
220
221 add_qml_test(Menus AccessPointMenu)
222 add_qml_test(Menus ButtonMenu)
223
224=== added file 'tests/qmltests/Components/tst_StatusIcon.qml'
225--- tests/qmltests/Components/tst_StatusIcon.qml 1970-01-01 00:00:00 +0000
226+++ tests/qmltests/Components/tst_StatusIcon.qml 2014-07-01 12:51:37 +0000
227@@ -0,0 +1,80 @@
228+/*
229+ * Copyright 2014 Canonical Ltd.
230+ *
231+ * This program is free software; you can redistribute it and/or modify
232+ * it under the terms of the GNU General Public License as published by
233+ * the Free Software Foundation; version 3.
234+ *
235+ * This program is distributed in the hope that it will be useful,
236+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
237+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
238+ * GNU General Public License for more details.
239+ *
240+ * You should have received a copy of the GNU General Public License
241+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
242+ */
243+
244+import QtQuick 2.0
245+import QtTest 1.0
246+import Ubuntu.Components 0.1
247+import Ubuntu.Settings.Components 0.1
248+import "../utils.js" as UtilsJS
249+
250+Item {
251+ width: units.gu(40)
252+ height: units.gu(70)
253+
254+ StatusIcon {
255+ id: icon
256+
257+ height: units.gu(3)
258+ }
259+
260+ TestCase {
261+ name: "StatusIcon"
262+ when: windowShown
263+
264+ function init() {
265+ icon.source = "";
266+ icon.sets = [ "status" ]
267+ waitForRendering(icon)
268+ }
269+
270+ function test_icon() {
271+ icon.source = "image://theme/bar,gps,baz";
272+
273+ var image = UtilsJS.findChild(icon, "image");
274+ tryCompare(image, "source", "file://" + image.iconPath.arg("status").arg("gps"));
275+ }
276+
277+ function test_iconFallback() {
278+ icon.source = "image://theme/foo,bar,baz";
279+
280+ var image = UtilsJS.findChild(icon, "image");
281+ tryCompare(image, "source", "file://" + image.iconPath.arg("status").arg("baz"));
282+ }
283+
284+ function test_iconSets() {
285+ icon.source = "image://theme/bar,add,baz";
286+ icon.sets = [ "foo", "actions", "bar" ]
287+
288+ var image = UtilsJS.findChild(icon, "image");
289+ tryCompare(image, "source", "file://" + image.iconPath.arg("actions").arg("add"));
290+ }
291+
292+ function test_iconSetsFallback() {
293+ icon.source = "image://theme/add,bar,baz";
294+ icon.sets = [ "foo", "bar", "baz" ]
295+
296+ var image = UtilsJS.findChild(icon, "image");
297+ tryCompare(image, "source", "file://" + image.iconPath.arg("baz").arg("baz"));
298+ }
299+
300+ function test_iconSource() {
301+ var image = UtilsJS.findChild(icon, "image");
302+ icon.source = image.iconPath.arg("status").arg("gps");
303+
304+ tryCompare(image, "source", "file://" + image.iconPath.arg("status").arg("gps"));
305+ }
306+ }
307+}

Subscribers

People subscribed via source and target branches

to all changes: