Merge lp:~zsombi/ubuntu-ui-toolkit/app-theming into lp:ubuntu-ui-toolkit/rtm

Proposed by Zsombor Egri
Status: Rejected
Rejected by: Zoltan Balogh
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/app-theming
Merge into: lp:ubuntu-ui-toolkit/rtm
Diff against target: 529 lines (+370/-21)
16 files modified
examples/customtheme/customtheme.apparmor (+8/-0)
examples/customtheme/customtheme.desktop (+8/-0)
examples/customtheme/customtheme.qmlproject (+59/-0)
examples/customtheme/main.qml (+103/-0)
examples/customtheme/manifest.json (+15/-0)
examples/customtheme/theme/Palette.qml (+24/-0)
examples/customtheme/theme/parent_theme (+1/-0)
modules/Ubuntu/Components/MainView.qml (+16/-0)
modules/Ubuntu/Components/Themes/Ambiance/MainViewStyle.qml (+0/-17)
modules/Ubuntu/Components/plugin/uctheme.cpp (+4/-2)
tests/unit_x11/tst_components/tst_theming.qml (+60/-0)
tests/unit_x11/tst_theme_engine/AppTheme/Palette.qml (+24/-0)
tests/unit_x11/tst_theme_engine/AppTheme/parent_theme (+1/-0)
tests/unit_x11/tst_theme_engine/TestApp.qml (+29/-0)
tests/unit_x11/tst_theme_engine/tst_theme_engine.pro (+3/-1)
tests/unit_x11/tst_theme_engine/tst_theme_enginetest.cpp (+15/-1)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/app-theming
Reviewer Review Type Date Requested Status
Tim Peeters quick look Approve
Cris Dywan Approve
Review via email: mp+243054@code.launchpad.net

Commit message

Fixing application theming discarded due to auto-theming from MainViewStyle.
Auto-theming moved into MainView and it is applied only on system themes.
Binding loops caused by the auto-theming fixed.
Support for the deprecated SuruGradient theme removed. SuruDark or Ambiance should be used in all appropriate cases.

To post a comment you must log in.
Revision history for this message
Cris Dywan (kalikiana) wrote :

I like it. Not only is the binding loop gone, the colors are also applied consistently on start-up as well as later at runtime.

One thing: the example like that won't be easily importable into QtCreator. But no reason to block on that, to be honest we're not having much of a policy with regard to that anyway and it'll need more discussion.

review: Approve
Revision history for this message
Tim Peeters (tpeeters) wrote :

nice!

review: Approve (quick look)
1134. By Zsombor Egri

roll back unnecessary change on theme not found warning

Unmerged revisions

1134. By Zsombor Egri

roll back unnecessary change on theme not found warning

1133. By Zsombor Egri

more tests added

1132. By Zsombor Egri

fixing application theme loading; automatic theme change from style transferred to MainView and made system theme dependent, fixed binding loops and ones detected by Valgrind, also causing application themes to be discarded.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'examples/customtheme'
2=== added file 'examples/customtheme/customtheme.apparmor'
3--- examples/customtheme/customtheme.apparmor 1970-01-01 00:00:00 +0000
4+++ examples/customtheme/customtheme.apparmor 2014-12-03 06:57:14 +0000
5@@ -0,0 +1,8 @@
6+{
7+ "policy_groups": [
8+ "networking"
9+ ],
10+ "policy_version": 1.2
11+}
12+
13+
14
15=== added file 'examples/customtheme/customtheme.desktop'
16--- examples/customtheme/customtheme.desktop 1970-01-01 00:00:00 +0000
17+++ examples/customtheme/customtheme.desktop 2014-12-03 06:57:14 +0000
18@@ -0,0 +1,8 @@
19+[Desktop Entry]
20+Name=customtheme
21+Exec=qmlscene $@ main.qml
22+Icon=customtheme.png
23+Terminal=false
24+Type=Application
25+X-Ubuntu-Touch=true
26+
27
28=== added file 'examples/customtheme/customtheme.png'
29Binary files examples/customtheme/customtheme.png 1970-01-01 00:00:00 +0000 and examples/customtheme/customtheme.png 2014-12-03 06:57:14 +0000 differ
30=== added file 'examples/customtheme/customtheme.qmlproject'
31--- examples/customtheme/customtheme.qmlproject 1970-01-01 00:00:00 +0000
32+++ examples/customtheme/customtheme.qmlproject 2014-12-03 06:57:14 +0000
33@@ -0,0 +1,59 @@
34+import QmlProject 1.1
35+
36+Project {
37+ mainFile: "main.qml"
38+
39+ /* Include .qml, .js, and image files from current directory and subdirectories */
40+ QmlFiles {
41+ directory: "."
42+ }
43+ JavaScriptFiles {
44+ directory: "."
45+ }
46+ ImageFiles {
47+ directory: "."
48+ }
49+ Files {
50+ filter: "*.desktop"
51+ }
52+ Files {
53+ filter: "www/*.html"
54+ }
55+ Files {
56+ filter: "Makefile"
57+ }
58+ Files {
59+ filter: "*.apparmor"
60+ }
61+ Files {
62+ directory: "."
63+ paths: ["manifest.json",".excludes"]
64+ }
65+ Files {
66+ directory: "www"
67+ filter: "*"
68+ }
69+ Files {
70+ directory: "www/img/"
71+ filter: "*"
72+ }
73+ Files {
74+ directory: "www/css/"
75+ filter: "*"
76+ }
77+ Files {
78+ directory: "www/js/"
79+ filter: "*"
80+ }
81+ Files {
82+ directory: "tests/"
83+ filter: "*"
84+ }
85+ Files {
86+ directory: "debian"
87+ filter: "*"
88+ }
89+ /* List of plugin directories passed to QML runtime */
90+ importPaths: [ "." ,"/usr/bin","/usr/lib/x86_64-linux-gnu/qt5/qml" ]
91+}
92+
93
94=== added file 'examples/customtheme/main.qml'
95--- examples/customtheme/main.qml 1970-01-01 00:00:00 +0000
96+++ examples/customtheme/main.qml 2014-12-03 06:57:14 +0000
97@@ -0,0 +1,103 @@
98+/*
99+ * Copyright 2014 Canonical Ltd.
100+ *
101+ * This program is free software; you can redistribute it and/or modify
102+ * it under the terms of the GNU Lesser General Public License as published by
103+ * the Free Software Foundation; version 3.
104+ *
105+ * This program is distributed in the hope that it will be useful,
106+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
107+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
108+ * GNU Lesser General Public License for more details.
109+ *
110+ * You should have received a copy of the GNU Lesser General Public License
111+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
112+ */
113+
114+import QtQuick 2.0
115+import Ubuntu.Components 1.1
116+
117+/*!
118+ \brief MainView with a Label and Button elements.
119+*/
120+
121+MainView {
122+ id: mainView
123+ // objectName for functional testing purposes (autopilot-qt5)
124+ objectName: "mainView"
125+
126+ // Note! applicationName needs to match the "name" field of the click manifest
127+ applicationName: "customtheme"
128+
129+ /*
130+ This property enables the application to change orientation
131+ when the device is rotated. The default is false.
132+ */
133+ //automaticOrientation: true
134+
135+ // Removes the old toolbar and enables new features of the new header.
136+ useDeprecatedToolbar: false
137+
138+ width: units.gu(100)
139+ height: units.gu(75)
140+
141+ Component.onCompleted: Theme.name = "theme"
142+
143+ Page {
144+ title: i18n.tr("Theme sample")
145+
146+ Column {
147+ spacing: units.gu(1)
148+ anchors {
149+ margins: units.gu(2)
150+ fill: parent
151+ }
152+
153+ Label {
154+ text: i18n.tr("Theme.name:") + " " + Theme.name
155+ }
156+
157+ Button {
158+ width: parent.width
159+ text: i18n.tr("Light background")
160+
161+ onClicked: {
162+ mainView.backgroundColor = "white";
163+ }
164+ }
165+ Button {
166+ width: parent.width
167+ text: i18n.tr("Dark background")
168+
169+ onClicked: {
170+ mainView.backgroundColor = "blue";
171+ }
172+ }
173+ Button {
174+ width: parent.width
175+ text: i18n.tr("Set Ambiance theme")
176+
177+ onClicked: {
178+ Theme.name = "Ubuntu.Components.Themes.Ambiance";
179+ }
180+ }
181+ Button {
182+ width: parent.width
183+ text: i18n.tr("Set SuruDark theme")
184+
185+ onClicked: {
186+ Theme.name = "Ubuntu.Components.Themes.SuruDark";
187+ }
188+ }
189+ Button {
190+ width: parent.width
191+ text: i18n.tr("Application theme")
192+
193+ onClicked: {
194+ Theme.name = "theme";
195+ }
196+ }
197+ }
198+ }
199+}
200+
201
202=== added file 'examples/customtheme/manifest.json'
203--- examples/customtheme/manifest.json 1970-01-01 00:00:00 +0000
204+++ examples/customtheme/manifest.json 2014-12-03 06:57:14 +0000
205@@ -0,0 +1,15 @@
206+{
207+ "architecture": "all",
208+ "description": "description of customtheme",
209+ "framework": "ubuntu-sdk-14.10-dev2",
210+ "hooks": {
211+ "customtheme": {
212+ "apparmor": "customtheme.apparmor",
213+ "desktop": "customtheme.desktop"
214+ }
215+ },
216+ "maintainer": "Zsombor Egri <zsombor.egri@canonical.com>",
217+ "name": "customtheme",
218+ "title": "customtheme",
219+ "version": "0.1"
220+}
221
222=== added directory 'examples/customtheme/theme'
223=== added file 'examples/customtheme/theme/Palette.qml'
224--- examples/customtheme/theme/Palette.qml 1970-01-01 00:00:00 +0000
225+++ examples/customtheme/theme/Palette.qml 2014-12-03 06:57:14 +0000
226@@ -0,0 +1,24 @@
227+/*
228+ * Copyright 2014 Canonical Ltd.
229+ *
230+ * This program is free software; you can redistribute it and/or modify
231+ * it under the terms of the GNU Lesser General Public License as published by
232+ * the Free Software Foundation; version 3.
233+ *
234+ * This program is distributed in the hope that it will be useful,
235+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
236+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
237+ * GNU Lesser General Public License for more details.
238+ *
239+ * You should have received a copy of the GNU Lesser General Public License
240+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
241+ */
242+
243+import QtQuick 2.0
244+import Ubuntu.Components 1.1
245+import Ubuntu.Components.Themes.SuruDark 1.1 as Suru
246+
247+Suru.Palette {
248+ normal.background: "#A21E1C"
249+ selected.backgroundText: "lightblue"
250+}
251
252=== added file 'examples/customtheme/theme/parent_theme'
253--- examples/customtheme/theme/parent_theme 1970-01-01 00:00:00 +0000
254+++ examples/customtheme/theme/parent_theme 2014-12-03 06:57:14 +0000
255@@ -0,0 +1,1 @@
256+Ubuntu.Components.Themes.SuruDark
257
258=== modified file 'modules/Ubuntu/Components/MainView.qml'
259--- modules/Ubuntu/Components/MainView.qml 2014-10-06 13:55:39 +0000
260+++ modules/Ubuntu/Components/MainView.qml 2014-12-03 06:57:14 +0000
261@@ -207,6 +207,22 @@
262 property color headerColor: backgroundColor
263 property color backgroundColor: Theme.palette.normal.background
264 property color footerColor: backgroundColor
265+
266+ /*
267+ As we don't know the order the property bindings and onXXXChanged signals are evaluated
268+ we should rely only on one property when changing the theme to avoid intermediate
269+ theme changes due to properties being evaluated separately.
270+
271+ Qt bug: https://bugreports.qt-project.org/browse/QTBUG-11712
272+ */
273+ property string theme: (ColorUtils.luminance(backgroundColor) >= 0.85) ?
274+ "Ambiance" : "SuruDark"
275+ onThemeChanged: {
276+ // only change the theme if the current one is a system one.
277+ if (theme !== "" && (Theme.name.search("Ubuntu.Components.Themes") >= 0)) {
278+ Theme.name = "Ubuntu.Components.Themes.%1".arg(theme);
279+ }
280+ }
281 }
282
283 /*!
284
285=== modified file 'modules/Ubuntu/Components/Themes/Ambiance/MainViewStyle.qml'
286--- modules/Ubuntu/Components/Themes/Ambiance/MainViewStyle.qml 2014-08-21 19:40:18 +0000
287+++ modules/Ubuntu/Components/Themes/Ambiance/MainViewStyle.qml 2014-12-03 06:57:14 +0000
288@@ -55,22 +55,5 @@
289 id: internals
290 property bool isGradient: styledItem.backgroundColor != styledItem.headerColor ||
291 styledItem.backgroundColor != styledItem.footerColor
292- /*
293- As we don't know the order the property bindings and onXXXChanged signals are evaluated
294- we should rely only on one property when changing the theme to avoid intermediate
295- theme changes due to properties being evaluated separately.
296-
297- Qt bug: https://bugreports.qt-project.org/browse/QTBUG-11712
298- */
299- property string theme: (ColorUtils.luminance(styledItem.backgroundColor) >= 0.85) ? "Ambiance" :
300- (isGradient ? "SuruGradient" : "SuruDark")
301- }
302-
303- // automatically select the appropriate theme depending on the background colors
304- Binding {
305- target: Theme
306- property: "name"
307- value: "Ubuntu.Components.Themes.%1".arg(internals.theme)
308- when: internals.theme !== ""
309 }
310 }
311
312=== modified file 'modules/Ubuntu/Components/plugin/uctheme.cpp'
313--- modules/Ubuntu/Components/plugin/uctheme.cpp 2014-06-26 15:24:06 +0000
314+++ modules/Ubuntu/Components/plugin/uctheme.cpp 2014-12-03 06:57:14 +0000
315@@ -101,6 +101,8 @@
316 }
317 // append standard QML2_IMPORT_PATH value
318 result << QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath);
319+ // prepend current folder
320+ result.prepend(QDir::currentPath());
321 return result;
322 }
323
324@@ -134,7 +136,7 @@
325
326 QStringList paths = themeSearchPath();
327 Q_FOREACH(const QString &path, paths) {
328- if (QDir(path).exists()) {
329+ if (QDir(path).exists() && !m_engine->importPathList().contains(path)) {
330 m_engine->addImportPath(path);
331 }
332 }
333@@ -230,7 +232,7 @@
334 QString parentTheme;
335 QUrl themePath = pathFromThemeName(themeName);
336 if (!themePath.isValid()) {
337- qWarning() << UbuntuI18n::instance().tr("Theme not found: ") << themeName;
338+ qWarning() << UbuntuI18n::instance().tr("Theme not found: \"%1\"").arg(themeName);
339 } else {
340 QFile file(themePath.resolved(PARENT_THEME_FILE).toLocalFile());
341 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
342
343=== added file 'tests/unit_x11/tst_components/tst_theming.qml'
344--- tests/unit_x11/tst_components/tst_theming.qml 1970-01-01 00:00:00 +0000
345+++ tests/unit_x11/tst_components/tst_theming.qml 2014-12-03 06:57:14 +0000
346@@ -0,0 +1,60 @@
347+/*
348+ * Copyright 2012 Canonical Ltd.
349+ *
350+ * This program is free software; you can redistribute it and/or modify
351+ * it under the terms of the GNU Lesser General Public License as published by
352+ * the Free Software Foundation; version 3.
353+ *
354+ * This program is distributed in the hope that it will be useful,
355+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
356+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
357+ * GNU Lesser General Public License for more details.
358+ *
359+ * You should have received a copy of the GNU Lesser General Public License
360+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
361+ */
362+
363+import QtQuick 2.0
364+import QtTest 1.0
365+import Ubuntu.Components 1.1
366+import Ubuntu.Test 1.0
367+
368+MainView {
369+ id: mainView
370+ width: units.gu(50)
371+ height: units.gu(10)
372+
373+ useDeprecatedToolbar: false
374+
375+ UbuntuTestCase {
376+ when: windowShown
377+
378+ SignalSpy {
379+ id: themeSpy
380+ signalName: "paletteChanged"
381+ target: Theme
382+ }
383+
384+ function cleanup() {
385+ themeSpy.clear();
386+ }
387+
388+ function test_backgroundcolor_change_data() {
389+ return [
390+ {tag: "Light color", oldTheme: "Ubuntu.Components.Themes.SuruDark", newTheme: "Ubuntu.Components.Themes.Ambiance", color: "white"},
391+ {tag: "Dark color", oldTheme: "Ubuntu.Components.Themes.Ambiance", newTheme: "Ubuntu.Components.Themes.SuruDark", color: "blue"},
392+ ];
393+ }
394+ function test_backgroundcolor_change(data) {
395+ if (data.oldTheme !== Theme.name) {
396+ Theme.name = data.oldTheme;
397+ themeSpy.wait();
398+ }
399+ // change color;
400+ themeSpy.clear();
401+ mainView.backgroundColor = data.color;
402+ themeSpy.wait();
403+ compare(Theme.name, data.newTheme, "Theme not chnaged");
404+ }
405+ }
406+}
407
408=== added directory 'tests/unit_x11/tst_theme_engine/AppTheme'
409=== added file 'tests/unit_x11/tst_theme_engine/AppTheme/Palette.qml'
410--- tests/unit_x11/tst_theme_engine/AppTheme/Palette.qml 1970-01-01 00:00:00 +0000
411+++ tests/unit_x11/tst_theme_engine/AppTheme/Palette.qml 2014-12-03 06:57:14 +0000
412@@ -0,0 +1,24 @@
413+/*
414+ * Copyright 2014 Canonical Ltd.
415+ *
416+ * This program is free software; you can redistribute it and/or modify
417+ * it under the terms of the GNU Lesser General Public License as published by
418+ * the Free Software Foundation; version 3.
419+ *
420+ * This program is distributed in the hope that it will be useful,
421+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
422+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
423+ * GNU Lesser General Public License for more details.
424+ *
425+ * You should have received a copy of the GNU Lesser General Public License
426+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
427+ */
428+
429+import QtQuick 2.0
430+import Ubuntu.Components 1.1
431+import Ubuntu.Components.Themes.SuruDark 1.1 as Suru
432+
433+Suru.Palette {
434+ normal.background: "#A21E1C"
435+ selected.backgroundText: "lightblue"
436+}
437
438=== added file 'tests/unit_x11/tst_theme_engine/AppTheme/parent_theme'
439--- tests/unit_x11/tst_theme_engine/AppTheme/parent_theme 1970-01-01 00:00:00 +0000
440+++ tests/unit_x11/tst_theme_engine/AppTheme/parent_theme 2014-12-03 06:57:14 +0000
441@@ -0,0 +1,1 @@
442+Ubuntu.Components.Themes.SuruDark
443
444=== added file 'tests/unit_x11/tst_theme_engine/TestApp.qml'
445--- tests/unit_x11/tst_theme_engine/TestApp.qml 1970-01-01 00:00:00 +0000
446+++ tests/unit_x11/tst_theme_engine/TestApp.qml 2014-12-03 06:57:14 +0000
447@@ -0,0 +1,29 @@
448+/*
449+ * Copyright 2014 Canonical Ltd.
450+ *
451+ * This program is free software; you can redistribute it and/or modify
452+ * it under the terms of the GNU Lesser General Public License as published by
453+ * the Free Software Foundation; version 3.
454+ *
455+ * This program is distributed in the hope that it will be useful,
456+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
457+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
458+ * GNU Lesser General Public License for more details.
459+ *
460+ * You should have received a copy of the GNU Lesser General Public License
461+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
462+ */
463+
464+import QtQuick 2.0
465+import Ubuntu.Components 1.1
466+
467+MainView {
468+ width: units.gu(40)
469+ height: units.gu(71)
470+
471+ Component.onCompleted: Theme.name = "AppTheme"
472+
473+ Label {
474+ objectName: "test_label"
475+ }
476+}
477
478=== modified file 'tests/unit_x11/tst_theme_engine/tst_theme_engine.pro'
479--- tests/unit_x11/tst_theme_engine/tst_theme_engine.pro 2013-07-01 16:01:20 +0000
480+++ tests/unit_x11/tst_theme_engine/tst_theme_engine.pro 2014-12-03 06:57:14 +0000
481@@ -1,5 +1,7 @@
482 include(../test-include.pri)
483+QT += quick-private gui-private
484 SOURCES += tst_theme_enginetest.cpp
485
486 OTHER_FILES += \
487- TestStyle.qml
488+ TestStyle.qml \
489+ TestApp.qml
490
491=== modified file 'tests/unit_x11/tst_theme_engine/tst_theme_enginetest.cpp'
492--- tests/unit_x11/tst_theme_engine/tst_theme_enginetest.cpp 2014-03-28 17:02:52 +0000
493+++ tests/unit_x11/tst_theme_engine/tst_theme_enginetest.cpp 2014-12-03 06:57:14 +0000
494@@ -20,6 +20,8 @@
495 #include <QtQml/QQmlEngine>
496 #include <QtQml/QQmlComponent>
497 #include "uctheme.h"
498+#include "uctestcase.h"
499+#include <private/qquicktext_p.h>
500
501 Q_DECLARE_METATYPE(QList<QQmlError>)
502
503@@ -42,6 +44,7 @@
504 void testThemesRelativePathWithParentXDGDATA();
505 void testThemesRelativePathWithParentNoVariablesSet();
506 void testThemesRelativePathWithParentOneXDGPathSet();
507+ void testAppTheme();
508 };
509
510 void tst_UCTheme::initTestCase()
511@@ -180,7 +183,18 @@
512 QQmlComponent* component = theme.createStyleComponent("TestStyle.qml", parent);
513
514 QCOMPARE(component != NULL, true);
515- QCOMPARE(component->status(), QQmlComponent::Ready);}
516+ QCOMPARE(component->status(), QQmlComponent::Ready);
517+}
518+
519+void tst_UCTheme::testAppTheme()
520+{
521+ QScopedPointer<UbuntuTestCase> test(new UbuntuTestCase("TestApp.qml"));
522+ QColor backgroundColor = test->rootObject()->property("backgroundColor").value<QColor>();
523+ QCOMPARE(backgroundColor, QColor("#A21E1C"));
524+ QQuickText *label = test->findItem<QQuickText*>("test_label");
525+ QVERIFY(label);
526+ QCOMPARE(label->color(), QColor("lightblue"));
527+}
528
529 QTEST_MAIN(tst_UCTheme)
530

Subscribers

People subscribed via source and target branches

to all changes: