Merge lp:~fboucault/ubuntu-ui-toolkit/ubuntu_colors into lp:ubuntu-ui-toolkit

Proposed by Florian Boucault
Status: Merged
Approved by: Tim Peeters
Approved revision: 595
Merged at revision: 573
Proposed branch: lp:~fboucault/ubuntu-ui-toolkit/ubuntu_colors
Merge into: lp:ubuntu-ui-toolkit
Prerequisite: lp:~fboucault/ubuntu-ui-toolkit/simple_theming
Diff against target: 458 lines (+147/-23)
23 files modified
debian/qtdeclarative5-ubuntu-ui-toolkit-plugin.install (+1/-0)
examples/ubuntu-ui-toolkit-gallery/AnimationCircle.qml (+1/-1)
examples/ubuntu-ui-toolkit-gallery/Dialog.qml (+1/-1)
examples/ubuntu-ui-toolkit-gallery/Icons.qml (+2/-2)
examples/ubuntu-ui-toolkit-gallery/UbuntuShape.qml (+3/-3)
modules/Ubuntu/Components/Colors/Colors.pro (+9/-0)
modules/Ubuntu/Components/Colors/FIXME (+3/-0)
modules/Ubuntu/Components/Colors/UbuntuColors.qml (+63/-0)
modules/Ubuntu/Components/Components.pro (+1/-1)
modules/Ubuntu/Components/Icon.qml (+1/-1)
modules/Ubuntu/Components/Label.qml (+2/-2)
modules/Ubuntu/Components/ListItems/LabelVisual.qml (+1/-1)
modules/Ubuntu/Components/MainView.qml (+3/-3)
modules/Ubuntu/Components/PageStack.qml (+1/-1)
modules/Ubuntu/Components/Popups/ComposerSheet.qml (+1/-1)
modules/Ubuntu/Components/Popups/DefaultSheet.qml (+1/-1)
modules/Ubuntu/Components/Popups/Dialog.qml (+2/-2)
modules/Ubuntu/Components/Themes/Ambiance/TextAreaStyle.qml (+1/-1)
modules/Ubuntu/Components/UbuntuNumberAnimation.qml (+1/-1)
modules/Ubuntu/Components/plugin/plugin.cpp (+30/-0)
modules/Ubuntu/Components/plugin/plugin.h (+2/-0)
modules/Ubuntu/Components/plugin/quickutils.cpp (+15/-1)
modules/Ubuntu/Components/plugin/quickutils.h (+2/-0)
To merge this branch: bzr merge lp:~fboucault/ubuntu-ui-toolkit/ubuntu_colors
Reviewer Review Type Date Requested Status
Tim Peeters Approve
PS Jenkins bot continuous-integration Approve
Zsombor Egri Needs Fixing
Review via email: mp+172340@code.launchpad.net

Commit message

New UbuntuColors singleton defining the standard Ubuntu color palette.

To post a comment you must log in.
Revision history for this message
Tim Peeters (tpeeters) wrote :

Checkbox and Switch styles use the color #DD4814. Could you replace these by UbuntuColors.orange?

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

UbuntuColors is in the module Ubuntu.Components, which already has Ubuntu in the name so instead of Ubuntu.Components.UbuntuColors we could rename the colors to Ubuntu.Components.Colors.

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

367 +void UbuntuComponentsPlugin::registerQmlSingletonType(QQmlEngine *engine, const char* uri, const char* typeName, const char* qmlFile)

Is it really a singleton? You can still use UbuntuColors { } right? The qml component doesn't keep track of its instances. Also, the function name may cause some confusion with qmlRegisterSingletonType(). What about registerQmlContextProperty() as a function name?

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

394 public:
395 void registerTypes(const char *uri);
396 void initializeEngine(QQmlEngine *engine, const char *uri);
397 + QUrl baseUrl(QStringList importPathList, const char* uri);
398 + void registerQmlSingletonType(QQmlEngine *engine, const char* uri, const char* typeName, const char* qmlFile);

Do they have to be public?

Revision history for this message
Florian Boucault (fboucault) wrote :

> 367 +void UbuntuComponentsPlugin::registerQmlSingletonType(QQmlEngine
> *engine, const char* uri, const char* typeName, const char* qmlFile)
>
>
> Is it really a singleton? You can still use UbuntuColors { } right? The qml
> component doesn't keep track of its instances. Also, the function name may
> cause some confusion with qmlRegisterSingletonType(). What about
> registerQmlContextProperty() as a function name?

You cannot import it nor instantiate it.
The idea of naming it similarly to qmlRegisterSingletonType is because it behaves similarly.

Revision history for this message
Florian Boucault (fboucault) wrote :

> Checkbox and Switch styles use the color #DD4814. Could you replace these by
> UbuntuColors.orange?

Some of the colors where not replaced (such as these ones) on purpose because a separate MR is about to introduce a theme color palette from which these colors will be taken.

Revision history for this message
Florian Boucault (fboucault) wrote :

> 394 public:
> 395 void registerTypes(const char *uri);
> 396 void initializeEngine(QQmlEngine *engine, const char *uri);
> 397 + QUrl baseUrl(QStringList importPathList, const char* uri);
> 398 + void registerQmlSingletonType(QQmlEngine *engine, const char* uri,
> const char* typeName, const char* qmlFile);
>
> Do they have to be public?

Nobody can nor will instantiate the plugin manually so it does not really matter :)

Revision history for this message
Florian Boucault (fboucault) wrote :

> UbuntuColors is in the module Ubuntu.Components, which already has Ubuntu in
> the name so instead of Ubuntu.Components.UbuntuColors we could rename the
> colors to Ubuntu.Components.Colors.

As a developer you wouldn't readily associate in your mind the Colors object with the Ubuntu color palette, hence the name. The import name is quite distant code wise (as a developer you put it at the beginning of the file and forget it) and does not really help making the connection.

Revision history for this message
Florian Boucault (fboucault) wrote :

> > UbuntuColors is in the module Ubuntu.Components, which already has Ubuntu in
> > the name so instead of Ubuntu.Components.UbuntuColors we could rename the
> > colors to Ubuntu.Components.Colors.
>
> As a developer you wouldn't readily associate in your mind the Colors object
> with the Ubuntu color palette, hence the name. The import name is quite
> distant code wise (as a developer you put it at the beginning of the file and
> forget it) and does not really help making the connection.

A similar reasoning was used for UbuntuAnimation.

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

ok, agreed.

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

When closing gallery, the qmlscene does not exit (the prompt in terminal is not retrieved).

review: Needs Fixing
Revision history for this message
Zsombor Egri (zsombi) wrote :

> When closing gallery, the qmlscene does not exit (the prompt in terminal is
> not retrieved).

Actually the following code causes the trouble:
419 +QObject* QuickUtils::createQmlObject(const QUrl &url)
420 +{
421 + /* FIXME: if the directory pointed to by url contains a qmldir file that
422 + declares a JavaScript module then QQmlComponent::create() fails with
423 + the error "QQmlComponent: Component is not ready".
424 + */
425 + static QQmlEngine engine;
426 + QQmlComponent *component = new QQmlComponent(&engine, url, QQmlComponent::PreferSynchronous);
427 + QObject* result = component->create();
428 + delete component;
429 + return result;
430 +}

Having a quick look on the call stack seems to hang on the static QQmlEngien cleanup:

0 pthread_cond_wait@@GLIBC_2.3.2 185 0x7ffff4815ca4
1 QWaitCondition::wait(QMutex*, unsigned long) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff611e4fb
2 ?? /usr/lib/x86_64-linux-gnu/libQt5Qml.so.5 0x7ffff75a940a
3 ?? /usr/lib/x86_64-linux-gnu/libQt5Qml.so.5 0x7ffff75398f9
4 QQmlEnginePrivate::~QQmlEnginePrivate() /usr/lib/x86_64-linux-gnu/libQt5Qml.so.5 0x7ffff74e76d3
5 QQmlEnginePrivate::~QQmlEnginePrivate() /usr/lib/x86_64-linux-gnu/libQt5Qml.so.5 0x7ffff74e7ab9
6 QObject::~QObject() /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff62c5398
7 QQmlEngine::~QQmlEngine() /usr/lib/x86_64-linux-gnu/libQt5Qml.so.5 0x7ffff74e40a9
8 __run_exit_handlers 77 0x7ffff5701121
9 __GI_exit 99 0x7ffff57011a5
10 __libc_start_main 294 0x7ffff56e6eac
11 ?? 0x40629d

So the static QQmlEngine causes the hang when closing qmlscene. I did some small prototyping with using the plugin's QmlEngine, but then a second call on createQmlObject() causes "QQmlComponent: Component not ready" error, which is somewhat anticipated as we are trying to instantiate a component in the plugin's registration stage (we had this kind of error in the early times of the plugin creation with the theming engine).

Connecting the static engine's quit() signal to the parent one's does not help either. Therefore seems we need a different way of creating the UbuntuColors component.

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
595. By Florian Boucault

Fixed lockup.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Tim Peeters (tpeeters) wrote :

hurray :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/qtdeclarative5-ubuntu-ui-toolkit-plugin.install'
2--- debian/qtdeclarative5-ubuntu-ui-toolkit-plugin.install 2013-06-27 20:59:19 +0000
3+++ debian/qtdeclarative5-ubuntu-ui-toolkit-plugin.install 2013-07-02 15:41:27 +0000
4@@ -7,3 +7,4 @@
5 usr/lib/*/qt5/qml/Ubuntu/Components/artwork
6 usr/lib/*/qt5/qml/Ubuntu/Components/ListItems
7 usr/lib/*/qt5/qml/Ubuntu/Components/Popups
8+usr/lib/*/qt5/qml/Ubuntu/Components/Colors
9
10=== modified file 'examples/ubuntu-ui-toolkit-gallery/AnimationCircle.qml'
11--- examples/ubuntu-ui-toolkit-gallery/AnimationCircle.qml 2013-05-14 14:24:25 +0000
12+++ examples/ubuntu-ui-toolkit-gallery/AnimationCircle.qml 2013-07-02 15:41:27 +0000
13@@ -19,7 +19,7 @@
14 Rectangle {
15 id: circle
16
17- color: "#dd4814"
18+ color: UbuntuColors.orange
19 width: radius
20 height: radius
21 radius: units.gu(12)
22
23=== modified file 'examples/ubuntu-ui-toolkit-gallery/Dialog.qml'
24--- examples/ubuntu-ui-toolkit-gallery/Dialog.qml 2013-04-25 12:34:57 +0000
25+++ examples/ubuntu-ui-toolkit-gallery/Dialog.qml 2013-07-02 15:41:27 +0000
26@@ -47,7 +47,7 @@
27 }
28 Button {
29 text: "Delete"
30- color: "red"
31+ color: UbuntuColors.orange
32 onClicked: PopupUtils.close(dialogue)
33 }
34 }
35
36=== modified file 'examples/ubuntu-ui-toolkit-gallery/Icons.qml'
37--- examples/ubuntu-ui-toolkit-gallery/Icons.qml 2013-04-24 17:09:29 +0000
38+++ examples/ubuntu-ui-toolkit-gallery/Icons.qml 2013-07-02 15:41:27 +0000
39@@ -58,7 +58,7 @@
40
41 Icon {
42 name: "computer-symbolic"
43- color: "red"
44+ color: UbuntuColors.orange
45 keyColor: "#bebebe"
46 width: 24
47 height: 24
48@@ -66,7 +66,7 @@
49
50 Icon {
51 name: "computer-symbolic"
52- color: "lightblue"
53+ color: UbuntuColors.lightAubergine
54 keyColor: "#bebebe"
55 width: 24
56 height: 24
57
58=== modified file 'examples/ubuntu-ui-toolkit-gallery/UbuntuShape.qml'
59--- examples/ubuntu-ui-toolkit-gallery/UbuntuShape.qml 2013-05-21 14:39:57 +0000
60+++ examples/ubuntu-ui-toolkit-gallery/UbuntuShape.qml 2013-07-02 15:41:27 +0000
61@@ -29,17 +29,17 @@
62
63 UbuntuShape {
64 objectName: "ubuntushape_color_hex"
65- color: "#5da357"
66+ color: UbuntuColors.orange
67 }
68
69 UbuntuShape {
70 objectName: "ubuntushape_color_lightblue"
71- color: "lightblue"
72+ color: UbuntuColors.lightAubergine
73 }
74
75 UbuntuShape {
76 objectName: "ubuntushape_color_darkgray"
77- color: "darkgray"
78+ color: UbuntuColors.warmGrey
79 }
80 }
81
82
83=== added directory 'modules/Ubuntu/Components/Colors'
84=== added file 'modules/Ubuntu/Components/Colors/Colors.pro'
85--- modules/Ubuntu/Components/Colors/Colors.pro 1970-01-01 00:00:00 +0000
86+++ modules/Ubuntu/Components/Colors/Colors.pro 2013-07-02 15:41:27 +0000
87@@ -0,0 +1,9 @@
88+TEMPLATE = subdirs
89+
90+uri = Ubuntu.Components.Colors
91+installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /)
92+
93+qml_files.path = $$installPath
94+qml_files.files = *.qml
95+
96+INSTALLS += qml_files
97
98=== added file 'modules/Ubuntu/Components/Colors/FIXME'
99--- modules/Ubuntu/Components/Colors/FIXME 1970-01-01 00:00:00 +0000
100+++ modules/Ubuntu/Components/Colors/FIXME 2013-07-02 15:41:27 +0000
101@@ -0,0 +1,3 @@
102+UbuntuColors.qml is located in the Colors subdirectory because
103+QuickUtils::createQmlObject() fails if the QML file is located in a
104+folder that has a qmldir file with JavaScript modules.
105
106=== added file 'modules/Ubuntu/Components/Colors/UbuntuColors.qml'
107--- modules/Ubuntu/Components/Colors/UbuntuColors.qml 1970-01-01 00:00:00 +0000
108+++ modules/Ubuntu/Components/Colors/UbuntuColors.qml 2013-07-02 15:41:27 +0000
109@@ -0,0 +1,63 @@
110+/*
111+ Copyright 2013 Canonical Ltd.
112+ *
113+ This program is free software; you can redistribute it and/or modify
114+ it under the terms of the GNU Lesser General Public License as published by
115+ the Free Software Foundation; version 3.
116+ *
117+ This program is distributed in the hope that it will be useful,
118+ but WITHOUT ANY WARRANTY; without even the implied warranty of
119+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
120+ GNU Lesser General Public License for more details.
121+ *
122+ You should have received a copy of the GNU Lesser General Public License
123+ along with this program. If not, see <http://www.gnu.org/licenses/>.
124+ */
125+
126+import QtQuick 2.0
127+
128+/*!
129+ \qmltype UbuntuColors
130+ \inqmlmodule Ubuntu.Components 0.1
131+ \ingroup theming
132+ \brief Singleton defining the Ubuntu color palette.
133+
134+ Each color of the Ubuntu color palette is accesible from it.
135+ For more information on how to appropriately use the colors according to
136+ the context, please refer to the
137+ \l{http://design.ubuntu.com/brand/colour-palette}{Ubuntu brand guidelines}.
138+
139+ Example of use:
140+
141+ \qml
142+ Rectangle {
143+ color: UbuntuColors.orange
144+ }
145+ \endqml
146+*/
147+QtObject {
148+ /*!
149+ Ubuntu core color: Ubuntu orange
150+ */
151+ readonly property color orange: "#DD4814"
152+ /*!
153+ Ubuntu supporting color: light aubergine
154+ */
155+ readonly property color lightAubergine: "#77216F"
156+ /*!
157+ Ubuntu supporting color: mid aubergine
158+ */
159+ readonly property color midAubergine: "#5E2750"
160+ /*!
161+ Ubuntu supporting color: dark aubergine
162+ */
163+ readonly property color darkAubergine: "#2C001E"
164+ /*!
165+ Ubuntu neutral color: warm grey
166+ */
167+ readonly property color warmGrey: "#AEA79F"
168+ /*!
169+ Ubuntu neutral color: cool grey
170+ */
171+ readonly property color coolGrey: "#333333"
172+}
173
174=== modified file 'modules/Ubuntu/Components/Components.pro'
175--- modules/Ubuntu/Components/Components.pro 2013-06-30 13:04:37 +0000
176+++ modules/Ubuntu/Components/Components.pro 2013-07-02 15:41:27 +0000
177@@ -1,5 +1,5 @@
178 TEMPLATE = subdirs
179
180-SUBDIRS += plugin Themes
181+SUBDIRS += plugin Themes Colors
182
183 include(deployment.pri)
184
185=== modified file 'modules/Ubuntu/Components/Icon.qml'
186--- modules/Ubuntu/Components/Icon.qml 2013-04-11 01:18:01 +0000
187+++ modules/Ubuntu/Components/Icon.qml 2013-07-02 15:41:27 +0000
188@@ -45,7 +45,7 @@
189 width: 64
190 height: 64
191 name: "search"
192- color: "red"
193+ color: UbuntuColors.warmGrey
194 }
195 \endqml
196
197
198=== modified file 'modules/Ubuntu/Components/Label.qml'
199--- modules/Ubuntu/Components/Label.qml 2013-06-26 19:25:09 +0000
200+++ modules/Ubuntu/Components/Label.qml 2013-07-02 15:41:27 +0000
201@@ -25,7 +25,7 @@
202 Example:
203 \qml
204 Rectangle {
205- color: "grey"
206+ color: UbuntuColors.coolGrey
207 width: units.gu(30)
208 height: units.gu(30)
209
210@@ -56,5 +56,5 @@
211
212 font.pixelSize: FontUtils.sizeToPixels(fontSize)
213 font.family: "Ubuntu"
214- color: "#757373"
215+ color: UbuntuColors.coolGrey
216 }
217
218=== modified file 'modules/Ubuntu/Components/ListItems/LabelVisual.qml'
219--- modules/Ubuntu/Components/ListItems/LabelVisual.qml 2012-12-07 13:43:17 +0000
220+++ modules/Ubuntu/Components/ListItems/LabelVisual.qml 2013-07-02 15:41:27 +0000
221@@ -24,6 +24,6 @@
222
223 fontSize: "medium"
224 elide: Text.ElideRight
225- color: selected ? "#f37505" : Qt.rgba(0.4, 0.4, 0.4, 1.0)
226+ color: selected ? UbuntuColors.orange : Qt.rgba(0.4, 0.4, 0.4, 1.0)
227 opacity: label.enabled ? 1.0 : 0.5
228 }
229
230=== modified file 'modules/Ubuntu/Components/MainView.qml'
231--- modules/Ubuntu/Components/MainView.qml 2013-06-27 15:20:12 +0000
232+++ modules/Ubuntu/Components/MainView.qml 2013-07-02 15:41:27 +0000
233@@ -99,20 +99,20 @@
234 anchors.centerIn: parent
235 width: units.gu(20)
236 height: units.gu(20)
237- color: "blue"
238+ color: UbuntuColors.coolGrey
239 }
240
241 tools: ToolbarActions {
242 ToolbarButton {
243 action: Action {
244 text: "red"
245- onTriggered: rectangle.color = "red"
246+ onTriggered: rectangle.color = UbuntuColors.orange
247 }
248 }
249 ToolbarButton {
250 action: Action {
251 text: "green"
252- onTriggered: rectangle.color = "green"
253+ onTriggered: rectangle.color = UbuntuColors.lightAubergine
254 }
255 }
256 }
257
258=== modified file 'modules/Ubuntu/Components/PageStack.qml'
259--- modules/Ubuntu/Components/PageStack.qml 2013-04-04 10:26:43 +0000
260+++ modules/Ubuntu/Components/PageStack.qml 2013-07-02 15:41:27 +0000
261@@ -59,7 +59,7 @@
262 anchors.fill: parent
263 ListItem.Standard {
264 text: i18n.tr("Page one")
265- onClicked: pageStack.push(page1, {color: "red"})
266+ onClicked: pageStack.push(page1, {color: UbuntuColors.orange})
267 progression: true
268 }
269 ListItem.Standard {
270
271=== modified file 'modules/Ubuntu/Components/Popups/ComposerSheet.qml'
272--- modules/Ubuntu/Components/Popups/ComposerSheet.qml 2012-11-29 18:13:17 +0000
273+++ modules/Ubuntu/Components/Popups/ComposerSheet.qml 2013-07-02 15:41:27 +0000
274@@ -84,7 +84,7 @@
275
276 __rightButton: Button {
277 text: i18n.dtr("ubuntu-sdk", "confirm")
278- color: "#5da357"
279+ color: UbuntuColors.orange
280 /*! \internal */ // avoid warning when generating documentation
281 onClicked: {
282 composer.confirmClicked();
283
284=== modified file 'modules/Ubuntu/Components/Popups/DefaultSheet.qml'
285--- modules/Ubuntu/Components/Popups/DefaultSheet.qml 2012-11-29 18:13:17 +0000
286+++ modules/Ubuntu/Components/Popups/DefaultSheet.qml 2013-07-02 15:41:27 +0000
287@@ -93,7 +93,7 @@
288
289 __rightButton: Button {
290 text: i18n.dtr("ubuntu-sdk", "done")
291- color: "#5da357"
292+ color: UbuntuColors.orange
293 visible: doneButton
294 /*! \internal */
295 onClicked: {
296
297=== modified file 'modules/Ubuntu/Components/Popups/Dialog.qml'
298--- modules/Ubuntu/Components/Popups/Dialog.qml 2013-06-27 15:20:12 +0000
299+++ modules/Ubuntu/Components/Popups/Dialog.qml 2013-07-02 15:41:27 +0000
300@@ -48,12 +48,12 @@
301 }
302 Button {
303 text: "overwrite previous version"
304- color: "orange"
305+ color: UbuntuColors.orange
306 onClicked: PopupUtils.close(dialogue)
307 }
308 Button {
309 text: "save a copy"
310- color: "orange"
311+ color: UbuntuColors.orange
312 onClicked: PopupUtils.close(dialogue)
313 }
314 }
315
316=== modified file 'modules/Ubuntu/Components/Themes/Ambiance/TextAreaStyle.qml'
317--- modules/Ubuntu/Components/Themes/Ambiance/TextAreaStyle.qml 2013-06-27 18:04:07 +0000
318+++ modules/Ubuntu/Components/Themes/Ambiance/TextAreaStyle.qml 2013-07-02 15:41:27 +0000
319@@ -30,7 +30,7 @@
320 Background fill color
321 */
322 property color backgroundColor: (styledItem.focus || styledItem.highlighted) ? "white" : Qt.rgba(0, 0, 0, 0.1)
323- property color errorColor: "red"
324+ property color errorColor: UbuntuColors.orange
325 property real backgroundOpacity: styledItem.enabled ? 1.0 : 0.1
326
327 /*!
328
329=== modified file 'modules/Ubuntu/Components/UbuntuNumberAnimation.qml'
330--- modules/Ubuntu/Components/UbuntuNumberAnimation.qml 2013-05-14 13:09:44 +0000
331+++ modules/Ubuntu/Components/UbuntuNumberAnimation.qml 2013-07-02 15:41:27 +0000
332@@ -33,7 +33,7 @@
333
334 Rectangle {
335 width: 100; height: 100
336- color: "red"
337+ color: UbuntuColors.orange
338
339 UbuntuNumberAnimation on x { to: 50 }
340 }
341
342=== modified file 'modules/Ubuntu/Components/plugin/plugin.cpp'
343--- modules/Ubuntu/Components/plugin/plugin.cpp 2013-07-01 22:13:31 +0000
344+++ modules/Ubuntu/Components/plugin/plugin.cpp 2013-07-02 15:41:27 +0000
345@@ -58,6 +58,33 @@
346 return clipboard;
347 }
348
349+
350+QUrl UbuntuComponentsPlugin::baseUrl(QStringList importPathList, const char* uri)
351+{
352+ /* FIXME: remove when migrating to Qt 5.1 and use QQmlExtensionPlugin::baseUrl()
353+ http://doc-snapshot.qt-project.org/qt5-stable/qtqml/qqmlextensionplugin.html#baseUrl
354+ */
355+ QString pluginRelativePath = QString::fromUtf8(uri).replace(".", "/").prepend("/").append("/");
356+ QString pluginPath;
357+ Q_FOREACH (QString importPath, importPathList) {
358+ pluginPath = importPath.append(pluginRelativePath);
359+ if (QDir(pluginPath).exists()) {
360+ return QUrl::fromLocalFile(pluginPath);
361+ }
362+ }
363+
364+ return QUrl();
365+}
366+
367+void UbuntuComponentsPlugin::registerQmlSingletonType(QQmlEngine *engine, const char* uri, const char* typeName, const char* qmlFile)
368+{
369+ QUrl url = baseUrl(engine->importPathList(), uri).resolved(QUrl::fromLocalFile(qmlFile));
370+ QObject* object = QuickUtils::instance().createQmlObject(url);
371+ if (object != NULL) {
372+ engine->rootContext()->setContextProperty(typeName, object);
373+ }
374+}
375+
376 void UbuntuComponentsPlugin::registerTypes(const char *uri)
377 {
378 Q_ASSERT(uri == QLatin1String("Ubuntu.Components"));
379@@ -108,6 +135,9 @@
380
381 context->setContextProperty("bottomBarVisibilityCommunicator", &BottomBarVisibilityCommunicator::instance());
382
383+ // register UbuntuColors
384+ registerQmlSingletonType(engine, uri, "UbuntuColors", "Colors/UbuntuColors.qml");
385+
386 engine->addImageProvider(QLatin1String("scaling"), new UCScalingImageProvider);
387
388 // register gicon provider
389
390=== modified file 'modules/Ubuntu/Components/plugin/plugin.h'
391--- modules/Ubuntu/Components/plugin/plugin.h 2012-10-25 13:35:32 +0000
392+++ modules/Ubuntu/Components/plugin/plugin.h 2013-07-02 15:41:27 +0000
393@@ -30,6 +30,8 @@
394 public:
395 void registerTypes(const char *uri);
396 void initializeEngine(QQmlEngine *engine, const char *uri);
397+ QUrl baseUrl(QStringList importPathList, const char* uri);
398+ void registerQmlSingletonType(QQmlEngine *engine, const char* uri, const char* typeName, const char* qmlFile);
399 };
400 #endif // UBUNTU_COMPONENTS_PLUGIN_H
401
402
403=== modified file 'modules/Ubuntu/Components/plugin/quickutils.cpp'
404--- modules/Ubuntu/Components/plugin/quickutils.cpp 2013-05-27 09:48:42 +0000
405+++ modules/Ubuntu/Components/plugin/quickutils.cpp 2013-07-02 15:41:27 +0000
406@@ -25,13 +25,15 @@
407 #include <QtCore/QAbstractProxyModel>
408 #include <QtQml/QQmlPropertyMap>
409 #include <QtQml/QQmlInfo>
410+#include <QtQml/QQmlEngine>
411
412 #include <private/qquicktextinput_p.h>
413 #include <private/qquicktextedit_p.h>
414
415 QuickUtils::QuickUtils(QObject *parent) :
416 QObject(parent),
417- m_rootView(0)
418+ m_rootView(0),
419+ m_engine(new QQmlEngine)
420 {
421 QGuiApplication::instance()->installEventFilter(this);
422 // connect to focusObjectChanged() to get the latest active focus object
423@@ -231,3 +233,15 @@
424 }
425 }
426 }
427+
428+QObject* QuickUtils::createQmlObject(const QUrl &url)
429+{
430+ /* FIXME: if the directory pointed to by url contains a qmldir file that
431+ declares a JavaScript module then QQmlComponent::create() fails with
432+ the error "QQmlComponent: Component is not ready".
433+ */
434+ QQmlComponent *component = new QQmlComponent(m_engine, url, QQmlComponent::PreferSynchronous);
435+ QObject* result = component->create();
436+ delete component;
437+ return result;
438+}
439
440=== modified file 'modules/Ubuntu/Components/plugin/quickutils.h'
441--- modules/Ubuntu/Components/plugin/quickutils.h 2013-05-24 10:07:44 +0000
442+++ modules/Ubuntu/Components/plugin/quickutils.h 2013-07-02 15:41:27 +0000
443@@ -43,6 +43,7 @@
444
445 Q_INVOKABLE qreal modelDelegateHeight(QQmlComponent *delegate, const QVariant &model);
446 Q_INVOKABLE QString className(QQuickItem *item);
447+ QObject* createQmlObject(const QUrl &url);
448
449 Q_SIGNALS:
450 void rootObjectChanged();
451@@ -56,6 +57,7 @@
452 private:
453 explicit QuickUtils(QObject *parent = 0);
454 QQuickView *m_rootView;
455+ QQmlEngine *m_engine;
456
457 void lookupQuickView();
458 };

Subscribers

People subscribed via source and target branches

to status/vote changes: