Merge lp:~zsombi/ubuntu-ui-toolkit/05-palettechanges into lp:ubuntu-ui-toolkit/staging

Proposed by Zsombor Egri
Status: Rejected
Rejected by: Zsombor Egri
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/05-palettechanges
Merge into: lp:ubuntu-ui-toolkit/staging
Prerequisite: lp:~zsombi/ubuntu-ui-toolkit/04-apply-styleset
Diff against target: 1261 lines (+1002/-7)
25 files modified
components.api (+5/-0)
modules/Ubuntu/Components/plugin/plugin.cpp (+2/-0)
modules/Ubuntu/Components/plugin/plugin.pro (+4/-2)
modules/Ubuntu/Components/plugin/ucpalettesettings.cpp (+297/-0)
modules/Ubuntu/Components/plugin/ucpalettesettings.h (+95/-0)
modules/Ubuntu/Components/plugin/uctheme.cpp (+25/-1)
modules/Ubuntu/Components/plugin/uctheme.h (+7/-0)
tests/resources/styleset/Simple.qml (+22/-0)
tests/unit_x11/tst_subtheming/ChangeDefaultPaletteInChildren.qml (+36/-0)
tests/unit_x11/tst_subtheming/ChangePaletteValueWhenParentChanges.qml (+32/-0)
tests/unit_x11/tst_subtheming/ExplicitPaletteSettings.qml (+34/-0)
tests/unit_x11/tst_subtheming/ImplicitPaletteSettings.qml (+34/-0)
tests/unit_x11/tst_subtheming/InvalidPaletteSettings1.qml (+27/-0)
tests/unit_x11/tst_subtheming/InvalidPaletteSettings2.qml (+27/-0)
tests/unit_x11/tst_subtheming/InvalidPaletteSettings3.qml (+27/-0)
tests/unit_x11/tst_subtheming/InvalidPaletteSettings4.qml (+27/-0)
tests/unit_x11/tst_subtheming/InvalidPaletteSettings5.qml (+27/-0)
tests/unit_x11/tst_subtheming/InvalidPaletteSettings6.qml (+28/-0)
tests/unit_x11/tst_subtheming/MorePaletteSettingsInTheme.qml (+28/-0)
tests/unit_x11/tst_subtheming/SameNamedPaletteSettings.qml (+38/-0)
tests/unit_x11/tst_subtheming/WrongPaletteSettingsDeclaration.qml (+27/-0)
tests/unit_x11/tst_subtheming/themes/CustomTheme/Palette.qml (+29/-0)
tests/unit_x11/tst_subtheming/themes/CustomTheme/parent_theme (+1/-1)
tests/unit_x11/tst_subtheming/tst_subtheming.cpp (+108/-0)
tests/unit_x11/tst_subtheming/tst_subtheming.pro (+15/-3)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/05-palettechanges
Reviewer Review Type Date Requested Status
Ubuntu SDK team Pending
Review via email: mp+252695@code.launchpad.net

Commit message

Introducing PaletteChanges component to customize palette values. It can only be assigned to StyleSet component.

To post a comment you must log in.
1444. By Zsombor Egri

prereq sync

1445. By Zsombor Egri

tests added, more featuires to come

1446. By Zsombor Egri

prereq sync

1447. By Zsombor Egri

switchColors and explicit properties added; test cases covering both implemented

1448. By Zsombor Egri

API complete

1449. By Zsombor Egri

propertychanges reverted to original

1450. By Zsombor Egri

component renamed to PaletteSettings, not to be confused with PropertyChanges derivates

1451. By Zsombor Egri

documentation updated

1452. By Zsombor Egri

prereq sync

Unmerged revisions

1452. By Zsombor Egri

prereq sync

1451. By Zsombor Egri

documentation updated

1450. By Zsombor Egri

component renamed to PaletteSettings, not to be confused with PropertyChanges derivates

1449. By Zsombor Egri

propertychanges reverted to original

1448. By Zsombor Egri

API complete

1447. By Zsombor Egri

switchColors and explicit properties added; test cases covering both implemented

1446. By Zsombor Egri

prereq sync

1445. By Zsombor Egri

tests added, more featuires to come

1444. By Zsombor Egri

prereq sync

1443. By Zsombor Egri

change implementation

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'components.api'
2--- components.api 2015-03-17 16:55:26 +0000
3+++ components.api 2015-03-17 16:55:27 +0000
4@@ -1016,6 +1016,10 @@
5 prototype: "QObject"
6 exports: ["Ubuntu 1.2"]
7 name: "CaptionsStyle"
8+ name: "UCPaletteSettings"
9+ prototype: "QObject"
10+ exports: ["PaletteSettings 1.3"]
11+ Property { name: "explicit"; type: "bool" }
12 name: "UCQQuickImageExtension"
13 prototype: "QQuickImageBase"
14 exports: ["QQuickImageBase 0.1", "QQuickImageBase 1.0"]
15@@ -1065,6 +1069,7 @@
16 Property { name: "parentTheme"; type: "UCTheme"; isReadonly: true; isPointer: true }
17 Property { name: "name"; type: "string" }
18 Property { name: "palette"; type: "QObject"; isReadonly: true; isPointer: true }
19+ Property { name: "paletteSettings"; type: "UCPaletteSettings"; isPointer: true }
20 Method {
21 name: "createStyleComponent"
22 Parameter { name: "styleName"; type: "string" }
23
24=== modified file 'modules/Ubuntu/Components/plugin/plugin.cpp'
25--- modules/Ubuntu/Components/plugin/plugin.cpp 2015-03-17 16:55:26 +0000
26+++ modules/Ubuntu/Components/plugin/plugin.cpp 2015-03-17 16:55:27 +0000
27@@ -24,6 +24,7 @@
28 #include "plugin.h"
29 #include "uctheme.h"
30 #include "ucdeprecatedtheme.h"
31+#include "ucpalettesettings.h"
32
33 #include <QtQml/QQmlContext>
34 #include "i18n.h"
35@@ -194,6 +195,7 @@
36 // register 1.3 API
37 qmlRegisterType<UCTheme>(uri, 1, 3, "ThemeSettings");
38 qmlRegisterType<UCStyledItemBase, 2>(uri, 1, 3, "StyledItemBase");
39+ qmlRegisterCustomType<UCPaletteSettings>(uri, 1, 3, "PaletteSettings", new UCPaletteSettingsParser);
40 }
41
42 void UbuntuComponentsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
43
44=== modified file 'modules/Ubuntu/Components/plugin/plugin.pro'
45--- modules/Ubuntu/Components/plugin/plugin.pro 2015-03-17 16:55:26 +0000
46+++ modules/Ubuntu/Components/plugin/plugin.pro 2015-03-17 16:55:27 +0000
47@@ -80,7 +80,8 @@
48 privates/listitemdraghandler.h \
49 ucnamespace.h \
50 ucdeprecatedtheme.h \
51- ucdefaulttheme.h
52+ ucdefaulttheme.h \
53+ ucpalettesettings.h
54
55 SOURCES += plugin.cpp \
56 uctheme.cpp \
57@@ -128,7 +129,8 @@
58 privates/listitemdraghandler.cpp \
59 ucnamespace.cpp \
60 ucdeprecatedtheme.cpp \
61- ucdefaulttheme.cpp
62+ ucdefaulttheme.cpp \
63+ ucpalettesettings.cpp
64
65 # adapters
66 SOURCES += adapters/alarmsadapter_organizer.cpp
67
68=== added file 'modules/Ubuntu/Components/plugin/ucpalettesettings.cpp'
69--- modules/Ubuntu/Components/plugin/ucpalettesettings.cpp 1970-01-01 00:00:00 +0000
70+++ modules/Ubuntu/Components/plugin/ucpalettesettings.cpp 2015-03-17 16:55:27 +0000
71@@ -0,0 +1,297 @@
72+/*
73+ * Copyright 2015 Canonical Ltd.
74+ *
75+ * This program is free software; you can redistribute it and/or modify
76+ * it under the terms of the GNU Lesser General Public License as published by
77+ * the Free Software Foundation; version 3.
78+ *
79+ * This program is distributed in the hope that it will be useful,
80+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
81+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82+ * GNU Lesser General Public License for more details.
83+ *
84+ * You should have received a copy of the GNU Lesser General Public License
85+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
86+ *
87+ * Author: Zsombor Egri <zsombor.egri@canonical.com>
88+ */
89+
90+#include "ucpalettesettings.h"
91+#include "i18n.h"
92+#include "uctheme.h"
93+#include "propertychange_p.h"
94+
95+#include <QtQml/QQmlInfo>
96+#include <QtQml/QQmlProperty>
97+
98+void UCPaletteSettingsParser::verifyBindings(const QV4::CompiledData::Unit *qmlUnit, const QList<const QV4::CompiledData::Binding *> &bindings)
99+{
100+ Q_FOREACH(const QV4::CompiledData::Binding *binding, bindings) {
101+ verifyProperty(qmlUnit, binding);
102+ }
103+}
104+
105+void UCPaletteSettingsParser::applyBindings(QObject *obj, QQmlCompiledData *cdata, const QList<const QV4::CompiledData::Binding *> &bindings)
106+{
107+ UCPaletteSettings *changes = static_cast<UCPaletteSettings*>(obj);
108+ if (!changes->palette()) {
109+ qmlInfo(changes->theme()) << UbuntuI18n::instance().tr("ThemeSettings does not define a palette.");
110+ return;
111+ }
112+
113+ Q_FOREACH(const QV4::CompiledData::Binding *binding, bindings) {
114+ changes->applyProperty(NULL, QString(), cdata->compilationUnit->data, binding);
115+ }
116+
117+ changes->m_cdata = cdata;
118+ changes->m_decoded = true;
119+}
120+
121+void UCPaletteSettingsParser::verifyProperty(const QV4::CompiledData::Unit *qmlUnit, const QV4::CompiledData::Binding *binding)
122+{
123+ if (binding->type == QV4::CompiledData::Binding::Type_Object) {
124+ error(qmlUnit->objectAt(binding->value.objectIndex), UbuntuI18n::instance().tr("PaletteSettings does not support creating state-specific objects."));
125+ return;
126+ }
127+
128+ if (binding->type == QV4::CompiledData::Binding::Type_GroupProperty
129+ || binding->type == QV4::CompiledData::Binding::Type_AttachedProperty) {
130+ const QV4::CompiledData::Object *subObj = qmlUnit->objectAt(binding->value.objectIndex);
131+ const QV4::CompiledData::Binding *subBinding = subObj->bindingTable();
132+ for (quint32 i = 0; i < subObj->nBindings; ++i, ++subBinding) {
133+ verifyProperty(qmlUnit, subBinding);
134+ }
135+ }
136+}
137+
138+void UCPaletteSettings::applyProperty(QObject *paletteSet, const QString &propertyPrefix, const QV4::CompiledData::Unit *qmlUnit, const QV4::CompiledData::Binding *binding)
139+{
140+ QString propertyName = propertyPrefix + qmlUnit->stringAt(binding->propertyNameIndex);
141+
142+ if (binding->type == QV4::CompiledData::Binding::Type_GroupProperty
143+ || binding->type == QV4::CompiledData::Binding::Type_AttachedProperty) {
144+
145+ // check if the palette has this value set
146+ int propIndex = palette()->metaObject()->indexOfProperty(propertyName.toUtf8());
147+ if (propIndex < 0) {
148+ qmlInfo(this) << UbuntuI18n::instance().tr("Palette has no valueset %1").arg(propertyName);
149+ return;
150+ }
151+
152+ QString pre = propertyName + QLatin1Char('.');
153+ const QV4::CompiledData::Object *subObj = qmlUnit->objectAt(binding->value.objectIndex);
154+ const QV4::CompiledData::Binding *subBinding = subObj->bindingTable();
155+ for (quint32 i = 0; i < subObj->nBindings; ++i, ++subBinding) {
156+ applyProperty(valueSet(propertyName), pre, qmlUnit, subBinding);
157+ }
158+ return;
159+ }
160+
161+ // check if palette has the given property
162+ if (!paletteSet) {
163+ qmlInfo(this) << UbuntuI18n::instance().tr("Palette has no property called '%1'.").arg(propertyName);
164+ return;
165+ }
166+ if (paletteSet->metaObject()->indexOfProperty(qmlUnit->stringAt(binding->propertyNameIndex).toUtf8()) < 0) {
167+ qmlInfo(this) << UbuntuI18n::instance().tr("Palette has no property called '%1'.").arg(propertyName);
168+ return;
169+ }
170+
171+ switch (binding->type) {
172+ case QV4::CompiledData::Binding::Type_Script:
173+ {
174+ QString expression = binding->valueAsScriptString(qmlUnit);
175+ QUrl url = QUrl();
176+ int line = -1;
177+ int column = -1;
178+
179+ QQmlData *ddata = QQmlData::get(this);
180+ if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) {
181+ url = ddata->outerContext->url;
182+ line = ddata->lineNumber;
183+ column = ddata->columnNumber;
184+ }
185+ m_expressions << Expression(propertyName, binding->value.compiledScriptIndex, expression, url, line, column);
186+ break;
187+ }
188+ case QV4::CompiledData::Binding::Type_String:
189+ {
190+ m_values << qMakePair(propertyName, binding->valueAsString(qmlUnit));
191+ break;
192+ }
193+ default:
194+ qmlInfo(this) << UbuntuI18n::instance().tr("Not a valid color value.");
195+ break;
196+ }
197+}
198+
199+
200+/******************************************************************************
201+ * PaletteSettings
202+ */
203+/*!
204+ * \qmltype PaletteSettings
205+ * \instantiates UCPaletteSettings
206+ * \inqmlmodule Ubuntu.Components 1.3
207+ * \since Ubuntu.Components 1.3
208+ * \ingroup theming
209+ * \brief The component is used to apply changes on a ThemeSettings individual
210+ * palette values.
211+ *
212+ * The component provides the ability to configure different palette values of a
213+ * theme. It can only contain palette value properties.
214+ * \qml
215+ * import QtQuick 2.4
216+ * import Ubuntu.Components 1.3
217+ *
218+ * StyledItem {
219+ * theme: ThemeSettings {
220+ * name: "Ubuntu.Components.Themes.Ambiance"
221+ * PaletteSettings {
222+ * normal.background: "#ABFFAB"
223+ * selected.base: Qt.rgba(1, 0.3, 0.8, 1)
224+ * }
225+ * }
226+ * }
227+ * \endqml
228+ * This example creates a styled item with Ambiance theme having the \c normal.background
229+ * and the \c selected.base palette values modified.
230+ *
231+ * The component can be declared only inside a ThemeSettings, and there can be only
232+ * one PaletteSettings instance declared per ThemeSettings component.
233+ *
234+ * Palette settings are applied on component completion as well as when the palette
235+ * property is changed. In the following example the palette values are set to
236+ * the given values whenever the theme name is changed
237+ * \qml
238+ * import QtQuick 2.4
239+ * import Ubuntu.Components 1.3
240+ *
241+ * StyledItem {
242+ * theme: ThemeSettings {
243+ * // bind to parent theme name to make sure the parent theme is always used
244+ * name: parentTheme ? parentTheme.name : undefined
245+ * PaletteSettings {
246+ * normal.background: "#ABFFAB"
247+ * selected.base: parentTheme ? parentTheme.palette.normal.base : "#00FFCC"
248+ * }
249+ * }
250+ * }
251+ * \endqml
252+ */
253+
254+/*!
255+ * \qmlproperty bool PaletteSettings::explicit
256+ * The property drives the way the property bindings are evaluated. If explicit
257+ * is set to true, any potential bindings will be interpreted as once-off assignments
258+ * that occur when the settings are applied.
259+ *
260+ * In the following example, the addition of explicit prevents \c selected.base
261+ * from being bound to \c parentTheme.palette.normal.base. Instead, it is assigned
262+ * the value of \c parentTheme.palette.normal.base at the time the palette settings
263+ * are applied - which is the time the theme palette is changed. This means that
264+ * in case \c parentTheme.palette.normal.base is changed, the change will not be
265+ * applied on the current theme palette.
266+ * \qml
267+ * import QtQuick 2.4
268+ * import Ubuntu.Components 1.3
269+ *
270+ * StyledItem {
271+ * theme: ThemeSettings {
272+ * // bind to parent theme name to make sure the parent theme is always used
273+ * name: parentTheme ? parentTheme.name : undefined
274+ * PaletteSettings {
275+ * explicit: true
276+ * normal.background: "#ABFFAB"
277+ * selected.base: parentTheme ? parentTheme.palette.normal.base : "#00FFCC"
278+ * }
279+ * }
280+ * }
281+ * \endqml
282+ *
283+ * The property defaults to \c false.
284+ */
285+
286+UCPaletteSettings::UCPaletteSettings(QObject *parent)
287+ : QObject(parent)
288+ , m_decoded(false)
289+ , m_explicit(false)
290+{
291+}
292+
293+void UCPaletteSettings::classBegin()
294+{
295+ if (!qobject_cast<UCTheme*>(parent())) {
296+ qmlInfo(this) << UbuntuI18n::instance().tr("PaletteSettings can only be declared in ThemeSettings components.");
297+ } else {
298+ connect(theme(), &UCTheme::paletteChanged, this, &UCPaletteSettings::_q_applyPaletteSettings);
299+ }
300+}
301+void UCPaletteSettings::componentComplete()
302+{
303+ if (palette() && m_decoded) {
304+ _q_applyPaletteSettings();
305+ }
306+}
307+
308+UCTheme *UCPaletteSettings::theme()
309+{
310+ return qobject_cast<UCTheme*>(parent());
311+}
312+QObject *UCPaletteSettings::palette()
313+{
314+ UCTheme *set = theme();
315+ return set ? set->palette() : NULL;
316+}
317+
318+QObject *UCPaletteSettings::valueSet(const QString &name)
319+{
320+ QObject *stylePalette = palette();
321+ return stylePalette ? stylePalette->property(name.toLocal8Bit()).value<QObject*>() : NULL;
322+}
323+
324+void UCPaletteSettings::_q_applyPaletteSettings()
325+{
326+ // first, apply the value changes
327+ QObject *object = palette();
328+ QQmlContext *context = qmlContext(object);
329+ for (int i = 0; i < m_values.count(); i++) {
330+ QQmlProperty::write(object, m_values[i].first, m_values[i].second, context);
331+ }
332+
333+ // override context to use this context
334+ context = qmlContext(this);
335+ // then apply expressions/bindings
336+ for (int ii = 0; ii < m_expressions.count(); ii++) {
337+ Expression e = m_expressions[ii];
338+ QQmlProperty prop(object, e.name, qmlContext(object));
339+ if (!prop.isValid()) {
340+ continue;
341+ }
342+
343+ // create a binding object from the expression using the palette context
344+ QQmlContextData *cdata = QQmlContextData::get(context);
345+ QQmlBinding *newBinding = 0;
346+ if (e.id != QQmlBinding::Invalid) {
347+ QV4::Scope scope(QQmlEnginePrivate::getV4Engine(qmlEngine(this)));
348+ QV4::ScopedValue function(scope, QV4::QmlBindingWrapper::createQmlCallableForFunction(cdata, object, m_cdata->compilationUnit->runtimeFunctions[e.id]));
349+ newBinding = new QQmlBinding(function, object, cdata);
350+ }
351+ if (!newBinding) {
352+ newBinding = new QQmlBinding(e.expression, object, cdata, e.url.toString(), e.line, e.column);
353+ }
354+
355+ if (m_explicit) {
356+ // in this case, we don't want to assign a binding, per se,
357+ // so we evaluate the expression and assign the result.
358+ prop.write(newBinding->evaluate());
359+ newBinding->destroy();
360+ } else {
361+ newBinding->setTarget(prop);
362+ QQmlAbstractBinding *prevBinding = QQmlPropertyPrivate::setBinding(prop, newBinding);
363+ if (prevBinding && prevBinding != newBinding) {
364+ prevBinding->destroy();
365+ }
366+ }
367+ }
368+}
369
370=== added file 'modules/Ubuntu/Components/plugin/ucpalettesettings.h'
371--- modules/Ubuntu/Components/plugin/ucpalettesettings.h 1970-01-01 00:00:00 +0000
372+++ modules/Ubuntu/Components/plugin/ucpalettesettings.h 2015-03-17 16:55:27 +0000
373@@ -0,0 +1,95 @@
374+/*
375+ * Copyright 2015 Canonical Ltd.
376+ *
377+ * This program is free software; you can redistribute it and/or modify
378+ * it under the terms of the GNU Lesser General Public License as published by
379+ * the Free Software Foundation; version 3.
380+ *
381+ * This program is distributed in the hope that it will be useful,
382+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
383+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
384+ * GNU Lesser General Public License for more details.
385+ *
386+ * You should have received a copy of the GNU Lesser General Public License
387+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
388+ *
389+ * Author: Zsombor Egri <zsombor.egri@canonical.com>
390+ */
391+
392+#ifndef UCPALETTESETTINGS_H
393+#define UCPALETTESETTINGS_H
394+
395+#include <QtCore/QObject>
396+
397+#define foreach Q_FOREACH
398+#include <QtQml/private/qqmlcustomparser_p.h>
399+#include <private/qv4engine_p.h>
400+#include <private/qpodvector_p.h>
401+#undef foreach
402+#include <QtQml/private/qqmlcompiler_p.h>
403+
404+class UCPaletteSettingsParser;
405+
406+class UCTheme;
407+class UCPaletteSettings : public QObject, public QQmlParserStatus
408+{
409+ Q_OBJECT
410+ Q_INTERFACES(QQmlParserStatus)
411+ Q_PROPERTY(bool explicit MEMBER m_explicit NOTIFY explicitChanged FINAL)
412+public:
413+ explicit UCPaletteSettings(QObject *parent = 0);
414+
415+ UCTheme *theme();
416+ QObject *palette();
417+ QObject *valueSet(const QString &name);
418+
419+ void applyProperty(QObject *valueSet, const QString &propertyPrefix, const QV4::CompiledData::Unit *qmlUnit, const QV4::CompiledData::Binding *binding);
420+
421+Q_SIGNALS:
422+ void explicitChanged();
423+
424+private Q_SLOTS:
425+ void _q_applyPaletteSettings();
426+
427+protected:
428+ void classBegin();
429+ void componentComplete();
430+
431+private:
432+
433+ class Expression {
434+ public:
435+ Expression(const QString &name, QQmlBinding::Identifier id, const QString& expr,
436+ const QUrl &url, int line, int column)
437+ : name(name), id(id), expression(expr), url(url), line(line), column(column) {}
438+ QString name;
439+ QQmlBinding::Identifier id;
440+ QString expression;
441+ QUrl url;
442+ int line;
443+ int column;
444+ };
445+
446+ bool m_decoded:1;
447+ bool m_explicit:1;
448+ QList< QPair<QString, QString> > m_values;
449+ QList<Expression> m_expressions;
450+ // from parser
451+ QQmlRefPointer<QQmlCompiledData> m_cdata;
452+
453+ friend class UCPaletteSettingsParser;
454+};
455+
456+class UCPaletteSettingsParser : public QQmlCustomParser
457+{
458+public:
459+ UCPaletteSettingsParser() : QQmlCustomParser(QQmlCustomParser::AcceptsSignalHandlers) {}
460+
461+ virtual void verifyBindings(const QV4::CompiledData::Unit *qmlUnit, const QList<const QV4::CompiledData::Binding *> &bindings);
462+ virtual void applyBindings(QObject *obj, QQmlCompiledData *cdata, const QList<const QV4::CompiledData::Binding *> &bindings);
463+
464+private:
465+ void verifyProperty(const QV4::CompiledData::Unit *qmlUnit, const QV4::CompiledData::Binding *binding);
466+};
467+
468+#endif // UCPALETTESETTINGS_H
469
470=== modified file 'modules/Ubuntu/Components/plugin/uctheme.cpp'
471--- modules/Ubuntu/Components/plugin/uctheme.cpp 2015-03-17 16:55:26 +0000
472+++ modules/Ubuntu/Components/plugin/uctheme.cpp 2015-03-17 16:55:27 +0000
473@@ -23,6 +23,7 @@
474 #include "i18n.h"
475 #include "ucfontutils.h"
476 #include "ucstyleditembase_p.h"
477+#include "ucpalettesettings.h"
478
479 #include <QtQml/qqml.h>
480 #include <QtQml/qqmlinfo.h>
481@@ -84,7 +85,7 @@
482
483 When declared, the ThemeSettings's name points to the system defined theme. There
484 can be cases when the parent defined style set is needed but with small modifications.
485- In these situations the \l parent property can be used to get the parent
486+ In these situations the \l parentTheme property can be used to get the parent
487 style set, and so the name can be bound to the parent's name.
488 \qml
489 import QtQuick 2.4
490@@ -318,6 +319,29 @@
491 return m_palette;
492 }
493
494+/*!
495+ * \qmlproperty PaletteSettings ThemeSettings::paletteSettings
496+ * The property holds the PaletteSettings component applied on the theme. When
497+ * set, the palette values will be applied on the style palette value sets.
498+ * Defaults to null.
499+ */
500+UCPaletteSettings *UCTheme::paletteSettings() const
501+{
502+ return m_paletteSettings;
503+}
504+void UCTheme::setPaletteSettings(UCPaletteSettings *paletteSettings)
505+{
506+ if (m_paletteSettings == paletteSettings) {
507+ return;
508+ }
509+ if (m_paletteSettings && paletteSettings && paletteSettings->parent() == this) {
510+ qmlInfo(this) << UbuntuI18n::instance().tr("ThemeSettings can have only one PaletteSettings set.");
511+ } else {
512+ m_paletteSettings = paletteSettings;
513+ Q_EMIT paletteSettingsChanged();
514+ }
515+}
516+
517 QUrl UCTheme::styleUrl(const QString& styleName)
518 {
519 Q_FOREACH (const QUrl& themePath, m_themePaths) {
520
521=== modified file 'modules/Ubuntu/Components/plugin/uctheme.h'
522--- modules/Ubuntu/Components/plugin/uctheme.h 2015-03-17 16:55:26 +0000
523+++ modules/Ubuntu/Components/plugin/uctheme.h 2015-03-17 16:55:27 +0000
524@@ -29,6 +29,7 @@
525
526 #include "ucdefaulttheme.h"
527
528+class UCPaletteSettings;
529 class UCStyledItemBase;
530 class UCTheme : public QObject, public QQmlParserStatus
531 {
532@@ -37,6 +38,8 @@
533 Q_PROPERTY(UCTheme *parentTheme READ parentTheme NOTIFY parentThemeChanged)
534 Q_PROPERTY(QString name READ name WRITE setName RESET resetName NOTIFY nameChanged)
535 Q_PROPERTY(QObject* palette READ palette NOTIFY paletteChanged)
536+ Q_PROPERTY(UCPaletteSettings *paletteSettings READ paletteSettings WRITE setPaletteSettings NOTIFY paletteSettingsChanged)
537+ Q_CLASSINFO("DefaultProperty", "paletteSettings")
538 public:
539 explicit UCTheme(QObject *parent = 0);
540 static UCTheme &defaultTheme()
541@@ -51,6 +54,8 @@
542 void setName(const QString& name);
543 void resetName();
544 QObject* palette();
545+ UCPaletteSettings *paletteSettings() const;
546+ void setPaletteSettings(UCPaletteSettings *paletteSettings);
547
548 Q_INVOKABLE QQmlComponent* createStyleComponent(const QString& styleName, QObject* parent);
549 static void registerToContext(QQmlContext* context);
550@@ -62,6 +67,7 @@
551 void parentThemeChanged();
552 void nameChanged();
553 void paletteChanged();
554+ void paletteSettingsChanged();
555
556 protected:
557 void classBegin();
558@@ -83,6 +89,7 @@
559
560 QString m_name;
561 QPointer<QObject> m_palette; // the palette might be from the default style if the theme doesn't define palette
562+ QPointer<UCPaletteSettings> m_paletteSettings;
563 QQmlEngine *m_engine;
564 QList<QUrl> m_themePaths;
565 UCDefaultTheme m_defaultTheme;
566
567=== modified file 'tests/resources/styleset/Simple.qml'
568--- tests/resources/styleset/Simple.qml 2015-03-17 16:55:26 +0000
569+++ tests/resources/styleset/Simple.qml 2015-03-17 16:55:27 +0000
570@@ -38,11 +38,33 @@
571 objectName: "OuterText"
572 property string styleName: theme.name
573 onStyleNameChanged: print(objectName, styleName)
574+ Connections {
575+ target: theme
576+ onPaletteChanged: {
577+ print("TextField:", styleSet.name)
578+ print("normal.foregroundText", styleSet.palette.normal.foregroundText)
579+ print("normal.overlayText", styleSet.palette.normal.overlayText)
580+ print("selected.foregroundText", styleSet.palette.selected.foregroundText)
581+ print("selected.overlayText", styleSet.palette.selected.overlayText)
582+ }
583+ }
584 }
585 StyledItem {
586 objectName: "SuruDarkStyled"
587 width: parent.width
588 height: units.gu(10)
589+ theme: ThemeSettings {
590+ name: "Ubuntu.Components.Themes.SuruDark"
591+ // override normal.foregroundText
592+ PaletteChanges {
593+ normal.foregroundText: UbuntuColors.blue
594+ normal.overlayText: "blue"
595+ selected.foregroundText: Qt.rgba(0, 0, 1, 1)
596+ selected.overlayText: normal.overlayText
597+ selected.foreground: Qt.rgba(UbuntuColors.blue.r, UbuntuColors.blue.g, UbuntuColors.blue.b, 0.2)
598+ }
599+ }
600+
601 TextField {
602 objectName: "InnerText"
603 property string styleName: theme.name
604
605=== added file 'tests/unit_x11/tst_subtheming/ChangeDefaultPaletteInChildren.qml'
606--- tests/unit_x11/tst_subtheming/ChangeDefaultPaletteInChildren.qml 1970-01-01 00:00:00 +0000
607+++ tests/unit_x11/tst_subtheming/ChangeDefaultPaletteInChildren.qml 2015-03-17 16:55:27 +0000
608@@ -0,0 +1,36 @@
609+/*
610+ * Copyright 2015 Canonical Ltd.
611+ *
612+ * This program is free software; you can redistribute it and/or modify
613+ * it under the terms of the GNU Lesser General Public License as published by
614+ * the Free Software Foundation; version 3.
615+ *
616+ * This program is distributed in the hope that it will be useful,
617+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
618+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
619+ * GNU Lesser General Public License for more details.
620+ *
621+ * You should have received a copy of the GNU Lesser General Public License
622+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
623+ */
624+
625+import QtQuick 2.4
626+import Ubuntu.Components 1.3
627+
628+StyledItem {
629+ Loader {
630+ objectName: "loader"
631+ anchors.fill: parent
632+ sourceComponent: dynamicItem
633+ }
634+
635+ Component {
636+ id: dynamicItem
637+ StyledItem {
638+ theme.paletteSettings: PaletteSettings {
639+ normal.background: "blue"
640+ }
641+ }
642+ }
643+}
644+
645
646=== added file 'tests/unit_x11/tst_subtheming/ChangePaletteValueWhenParentChanges.qml'
647--- tests/unit_x11/tst_subtheming/ChangePaletteValueWhenParentChanges.qml 1970-01-01 00:00:00 +0000
648+++ tests/unit_x11/tst_subtheming/ChangePaletteValueWhenParentChanges.qml 2015-03-17 16:55:27 +0000
649@@ -0,0 +1,32 @@
650+/*
651+ * Copyright 2015 Canonical Ltd.
652+ *
653+ * This program is free software; you can redistribute it and/or modify
654+ * it under the terms of the GNU Lesser General Public License as published by
655+ * the Free Software Foundation; version 3.
656+ *
657+ * This program is distributed in the hope that it will be useful,
658+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
659+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
660+ * GNU Lesser General Public License for more details.
661+ *
662+ * You should have received a copy of the GNU Lesser General Public License
663+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
664+ */
665+
666+import QtQuick 2.4
667+import Ubuntu.Components 1.3
668+
669+// the style of the root object will be changed
670+StyledItem {
671+ StyledItem {
672+ theme: ThemeSettings {
673+ objectName: "firstTheme"
674+ name: parentTheme.name
675+ PaletteSettings{
676+ normal.background: "blue"
677+ }
678+ }
679+ }
680+}
681+
682
683=== added file 'tests/unit_x11/tst_subtheming/ExplicitPaletteSettings.qml'
684--- tests/unit_x11/tst_subtheming/ExplicitPaletteSettings.qml 1970-01-01 00:00:00 +0000
685+++ tests/unit_x11/tst_subtheming/ExplicitPaletteSettings.qml 2015-03-17 16:55:27 +0000
686@@ -0,0 +1,34 @@
687+/*
688+ * Copyright 2015 Canonical Ltd.
689+ *
690+ * This program is free software; you can redistribute it and/or modify
691+ * it under the terms of the GNU Lesser General Public License as published by
692+ * the Free Software Foundation; version 3.
693+ *
694+ * This program is distributed in the hope that it will be useful,
695+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
696+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
697+ * GNU Lesser General Public License for more details.
698+ *
699+ * You should have received a copy of the GNU Lesser General Public License
700+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
701+ */
702+
703+import QtQuick 2.4
704+import Ubuntu.Components 1.3
705+
706+StyledItem {
707+ id: main
708+ width: units.gu(40)
709+ height: units.gu(71)
710+
711+ property color color: "red"
712+
713+ theme: ThemeSettings {
714+ objectName: "testSet"
715+ PaletteSettings {
716+ explicit: true
717+ normal.background: main.color
718+ }
719+ }
720+}
721
722=== added file 'tests/unit_x11/tst_subtheming/ImplicitPaletteSettings.qml'
723--- tests/unit_x11/tst_subtheming/ImplicitPaletteSettings.qml 1970-01-01 00:00:00 +0000
724+++ tests/unit_x11/tst_subtheming/ImplicitPaletteSettings.qml 2015-03-17 16:55:27 +0000
725@@ -0,0 +1,34 @@
726+/*
727+ * Copyright 2015 Canonical Ltd.
728+ *
729+ * This program is free software; you can redistribute it and/or modify
730+ * it under the terms of the GNU Lesser General Public License as published by
731+ * the Free Software Foundation; version 3.
732+ *
733+ * This program is distributed in the hope that it will be useful,
734+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
735+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
736+ * GNU Lesser General Public License for more details.
737+ *
738+ * You should have received a copy of the GNU Lesser General Public License
739+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
740+ */
741+
742+import QtQuick 2.4
743+import Ubuntu.Components 1.3
744+
745+StyledItem {
746+ id: main
747+ width: units.gu(40)
748+ height: units.gu(71)
749+
750+ property color color: "red"
751+
752+ theme: ThemeSettings {
753+ objectName: "testSet"
754+ PaletteSettings {
755+ explicit: false
756+ normal.background: main.color
757+ }
758+ }
759+}
760
761=== added file 'tests/unit_x11/tst_subtheming/InvalidPaletteSettings1.qml'
762--- tests/unit_x11/tst_subtheming/InvalidPaletteSettings1.qml 1970-01-01 00:00:00 +0000
763+++ tests/unit_x11/tst_subtheming/InvalidPaletteSettings1.qml 2015-03-17 16:55:27 +0000
764@@ -0,0 +1,27 @@
765+/*
766+ * Copyright 2015 Canonical Ltd.
767+ *
768+ * This program is free software; you can redistribute it and/or modify
769+ * it under the terms of the GNU Lesser General Public License as published by
770+ * the Free Software Foundation; version 3.
771+ *
772+ * This program is distributed in the hope that it will be useful,
773+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
774+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
775+ * GNU Lesser General Public License for more details.
776+ *
777+ * You should have received a copy of the GNU Lesser General Public License
778+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
779+ */
780+
781+import QtQuick 2.4
782+import Ubuntu.Components 1.3
783+
784+StyledItem {
785+ id: item
786+ theme: ThemeSettings {
787+ PaletteSettings{
788+ invalid: 1
789+ }
790+ }
791+}
792
793=== added file 'tests/unit_x11/tst_subtheming/InvalidPaletteSettings2.qml'
794--- tests/unit_x11/tst_subtheming/InvalidPaletteSettings2.qml 1970-01-01 00:00:00 +0000
795+++ tests/unit_x11/tst_subtheming/InvalidPaletteSettings2.qml 2015-03-17 16:55:27 +0000
796@@ -0,0 +1,27 @@
797+/*
798+ * Copyright 2015 Canonical Ltd.
799+ *
800+ * This program is free software; you can redistribute it and/or modify
801+ * it under the terms of the GNU Lesser General Public License as published by
802+ * the Free Software Foundation; version 3.
803+ *
804+ * This program is distributed in the hope that it will be useful,
805+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
806+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
807+ * GNU Lesser General Public License for more details.
808+ *
809+ * You should have received a copy of the GNU Lesser General Public License
810+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
811+ */
812+
813+import QtQuick 2.4
814+import Ubuntu.Components 1.3
815+
816+StyledItem {
817+ id: item
818+ theme: ThemeSettings {
819+ PaletteSettings{
820+ normal.invalid: 1
821+ }
822+ }
823+}
824
825=== added file 'tests/unit_x11/tst_subtheming/InvalidPaletteSettings3.qml'
826--- tests/unit_x11/tst_subtheming/InvalidPaletteSettings3.qml 1970-01-01 00:00:00 +0000
827+++ tests/unit_x11/tst_subtheming/InvalidPaletteSettings3.qml 2015-03-17 16:55:27 +0000
828@@ -0,0 +1,27 @@
829+/*
830+ * Copyright 2015 Canonical Ltd.
831+ *
832+ * This program is free software; you can redistribute it and/or modify
833+ * it under the terms of the GNU Lesser General Public License as published by
834+ * the Free Software Foundation; version 3.
835+ *
836+ * This program is distributed in the hope that it will be useful,
837+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
838+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
839+ * GNU Lesser General Public License for more details.
840+ *
841+ * You should have received a copy of the GNU Lesser General Public License
842+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
843+ */
844+
845+import QtQuick 2.4
846+import Ubuntu.Components 1.3
847+
848+StyledItem {
849+ id: item
850+ theme: ThemeSettings {
851+ PaletteSettings{
852+ normal.background: 1
853+ }
854+ }
855+}
856
857=== added file 'tests/unit_x11/tst_subtheming/InvalidPaletteSettings4.qml'
858--- tests/unit_x11/tst_subtheming/InvalidPaletteSettings4.qml 1970-01-01 00:00:00 +0000
859+++ tests/unit_x11/tst_subtheming/InvalidPaletteSettings4.qml 2015-03-17 16:55:27 +0000
860@@ -0,0 +1,27 @@
861+/*
862+ * Copyright 2015 Canonical Ltd.
863+ *
864+ * This program is free software; you can redistribute it and/or modify
865+ * it under the terms of the GNU Lesser General Public License as published by
866+ * the Free Software Foundation; version 3.
867+ *
868+ * This program is distributed in the hope that it will be useful,
869+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
870+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
871+ * GNU Lesser General Public License for more details.
872+ *
873+ * You should have received a copy of the GNU Lesser General Public License
874+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
875+ */
876+
877+import QtQuick 2.4
878+import Ubuntu.Components 1.3
879+
880+StyledItem {
881+ id: item
882+ theme: ThemeSettings {
883+ PaletteSettings{
884+ normal.background: 1.2
885+ }
886+ }
887+}
888
889=== added file 'tests/unit_x11/tst_subtheming/InvalidPaletteSettings5.qml'
890--- tests/unit_x11/tst_subtheming/InvalidPaletteSettings5.qml 1970-01-01 00:00:00 +0000
891+++ tests/unit_x11/tst_subtheming/InvalidPaletteSettings5.qml 2015-03-17 16:55:27 +0000
892@@ -0,0 +1,27 @@
893+/*
894+ * Copyright 2015 Canonical Ltd.
895+ *
896+ * This program is free software; you can redistribute it and/or modify
897+ * it under the terms of the GNU Lesser General Public License as published by
898+ * the Free Software Foundation; version 3.
899+ *
900+ * This program is distributed in the hope that it will be useful,
901+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
902+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
903+ * GNU Lesser General Public License for more details.
904+ *
905+ * You should have received a copy of the GNU Lesser General Public License
906+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
907+ */
908+
909+import QtQuick 2.4
910+import Ubuntu.Components 1.3
911+
912+StyledItem {
913+ id: item
914+ theme: ThemeSettings {
915+ PaletteSettings{
916+ normal.background: true
917+ }
918+ }
919+}
920
921=== added file 'tests/unit_x11/tst_subtheming/InvalidPaletteSettings6.qml'
922--- tests/unit_x11/tst_subtheming/InvalidPaletteSettings6.qml 1970-01-01 00:00:00 +0000
923+++ tests/unit_x11/tst_subtheming/InvalidPaletteSettings6.qml 2015-03-17 16:55:27 +0000
924@@ -0,0 +1,28 @@
925+/*
926+ * Copyright 2015 Canonical Ltd.
927+ *
928+ * This program is free software; you can redistribute it and/or modify
929+ * it under the terms of the GNU Lesser General Public License as published by
930+ * the Free Software Foundation; version 3.
931+ *
932+ * This program is distributed in the hope that it will be useful,
933+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
934+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
935+ * GNU Lesser General Public License for more details.
936+ *
937+ * You should have received a copy of the GNU Lesser General Public License
938+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
939+ */
940+
941+import QtQuick 2.4
942+import Ubuntu.Components 1.3
943+
944+StyledItem {
945+ id: item
946+ property int value: 10
947+ theme: ThemeSettings {
948+ PaletteSettings{
949+ normal.background: value
950+ }
951+ }
952+}
953
954=== added file 'tests/unit_x11/tst_subtheming/MorePaletteSettingsInTheme.qml'
955--- tests/unit_x11/tst_subtheming/MorePaletteSettingsInTheme.qml 1970-01-01 00:00:00 +0000
956+++ tests/unit_x11/tst_subtheming/MorePaletteSettingsInTheme.qml 2015-03-17 16:55:27 +0000
957@@ -0,0 +1,28 @@
958+/*
959+ * Copyright 2015 Canonical Ltd.
960+ *
961+ * This program is free software; you can redistribute it and/or modify
962+ * it under the terms of the GNU Lesser General Public License as published by
963+ * the Free Software Foundation; version 3.
964+ *
965+ * This program is distributed in the hope that it will be useful,
966+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
967+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
968+ * GNU Lesser General Public License for more details.
969+ *
970+ * You should have received a copy of the GNU Lesser General Public License
971+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
972+ */
973+
974+import QtQuick 2.4
975+import Ubuntu.Components 1.3
976+
977+StyledItem {
978+ id: item
979+ theme: ThemeSettings {
980+ PaletteSettings{
981+ }
982+ PaletteSettings{
983+ }
984+ }
985+}
986
987=== added file 'tests/unit_x11/tst_subtheming/SameNamedPaletteSettings.qml'
988--- tests/unit_x11/tst_subtheming/SameNamedPaletteSettings.qml 1970-01-01 00:00:00 +0000
989+++ tests/unit_x11/tst_subtheming/SameNamedPaletteSettings.qml 2015-03-17 16:55:27 +0000
990@@ -0,0 +1,38 @@
991+/*
992+ * Copyright 2015 Canonical Ltd.
993+ *
994+ * This program is free software; you can redistribute it and/or modify
995+ * it under the terms of the GNU Lesser General Public License as published by
996+ * the Free Software Foundation; version 3.
997+ *
998+ * This program is distributed in the hope that it will be useful,
999+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1000+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1001+ * GNU Lesser General Public License for more details.
1002+ *
1003+ * You should have received a copy of the GNU Lesser General Public License
1004+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1005+ */
1006+
1007+import QtQuick 2.4
1008+import Ubuntu.Components 1.3
1009+
1010+Item {
1011+ StyledItem {
1012+ theme: ThemeSettings {
1013+ objectName: "firstTheme"
1014+ name: "Ubuntu.Components.Themes.SuruDark"
1015+ PaletteSettings{
1016+ normal.background: UbuntuColors.red
1017+ }
1018+ }
1019+ }
1020+ StyledItem {
1021+ theme: ThemeSettings {
1022+ objectName: "secondTheme"
1023+ name: "Ubuntu.Components.Themes.SuruDark"
1024+ }
1025+ }
1026+
1027+}
1028+
1029
1030=== added file 'tests/unit_x11/tst_subtheming/WrongPaletteSettingsDeclaration.qml'
1031--- tests/unit_x11/tst_subtheming/WrongPaletteSettingsDeclaration.qml 1970-01-01 00:00:00 +0000
1032+++ tests/unit_x11/tst_subtheming/WrongPaletteSettingsDeclaration.qml 2015-03-17 16:55:27 +0000
1033@@ -0,0 +1,27 @@
1034+/*
1035+ * Copyright 2015 Canonical Ltd.
1036+ *
1037+ * This program is free software; you can redistribute it and/or modify
1038+ * it under the terms of the GNU Lesser General Public License as published by
1039+ * the Free Software Foundation; version 3.
1040+ *
1041+ * This program is distributed in the hope that it will be useful,
1042+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1043+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1044+ * GNU Lesser General Public License for more details.
1045+ *
1046+ * You should have received a copy of the GNU Lesser General Public License
1047+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1048+ */
1049+
1050+import QtQuick 2.4
1051+import Ubuntu.Components 1.3
1052+
1053+StyledItem {
1054+ id: item
1055+ theme: ThemeSettings {}
1056+
1057+ PaletteSettings{
1058+ objectName: "testChange"
1059+ }
1060+}
1061
1062=== added file 'tests/unit_x11/tst_subtheming/themes/CustomTheme/Palette.qml'
1063--- tests/unit_x11/tst_subtheming/themes/CustomTheme/Palette.qml 1970-01-01 00:00:00 +0000
1064+++ tests/unit_x11/tst_subtheming/themes/CustomTheme/Palette.qml 2015-03-17 16:55:27 +0000
1065@@ -0,0 +1,29 @@
1066+/*
1067+ * Copyright 2014 Canonical Ltd.
1068+ *
1069+ * This program is free software; you can redistribute it and/or modify
1070+ * it under the terms of the GNU Lesser General Public License as published by
1071+ * the Free Software Foundation; version 3.
1072+ *
1073+ * This program is distributed in the hope that it will be useful,
1074+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1075+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1076+ * GNU Lesser General Public License for more details.
1077+ *
1078+ * You should have received a copy of the GNU Lesser General Public License
1079+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1080+ */
1081+
1082+import QtQuick 2.0
1083+import Ubuntu.Components 1.1
1084+import Ubuntu.Components.Themes.Ambiance 1.1 as Suru
1085+
1086+Suru.Palette {
1087+ normal.selection: "#A21E1C"
1088+ selected.selection: "#1C1EA2"
1089+ selected.base: "lightblue"
1090+ selected.baseText: "pink"
1091+ selected.overlay: "#ABCDEF"
1092+ selected.overlayText: "#FEDCBA"
1093+ selected.fieldText: UbuntuColors.red
1094+}
1095
1096=== modified file 'tests/unit_x11/tst_subtheming/themes/CustomTheme/parent_theme'
1097--- tests/unit_x11/tst_subtheming/themes/CustomTheme/parent_theme 2015-03-17 16:55:26 +0000
1098+++ tests/unit_x11/tst_subtheming/themes/CustomTheme/parent_theme 2015-03-17 16:55:27 +0000
1099@@ -1,1 +1,1 @@
1100-TestTheme
1101+Ubuntu.Components.Themes.Ambiance
1102
1103=== modified file 'tests/unit_x11/tst_subtheming/tst_subtheming.cpp'
1104--- tests/unit_x11/tst_subtheming/tst_subtheming.cpp 2015-03-17 16:55:26 +0000
1105+++ tests/unit_x11/tst_subtheming/tst_subtheming.cpp 2015-03-17 16:55:27 +0000
1106@@ -23,6 +23,7 @@
1107 #include "uctheme.h"
1108 #include "uctestcase.h"
1109 #include "ucstyleditembase_p.h"
1110+#include "ucpalettesettings.h"
1111
1112 class ThemeTestCase : public UbuntuTestCase
1113 {
1114@@ -489,6 +490,113 @@
1115 QCOMPARE(UCStyledItemBasePrivate::get(main)->getTheme()->name(),
1116 UCStyledItemBasePrivate::get(test)->getTheme()->name());
1117 }
1118+
1119+ // PaletteSettings tests
1120+
1121+ void test_palettesettings_api_data()
1122+ {
1123+ QTest::addColumn<QString>("test");
1124+ QTest::addColumn<int>("line");
1125+ QTest::addColumn<int>("column");
1126+ QTest::addColumn<QString>("warning");
1127+
1128+ QTest::newRow("Wrong PalettChanges ownership")
1129+ << "WrongPaletteSettingsDeclaration.qml" << 24 << 5
1130+ << "QML PaletteSettings: PaletteSettings can only be declared in ThemeSettings components.";
1131+ QTest::newRow("More PalettChanges in ThemeSettings")
1132+ << "MorePaletteSettingsInTheme.qml" << 22 << 12
1133+ << "QML ThemeSettings: ThemeSettings can have only one PaletteSettings set.";
1134+ QTest::newRow("Invalid Palette property")
1135+ << "InvalidPaletteSettings1.qml" << 23 << 9
1136+ << "QML PaletteSettings: Palette has no property called 'invalid'.";
1137+ QTest::newRow("Invalid PaletteValues property")
1138+ << "InvalidPaletteSettings2.qml" << 23 << 9
1139+ << "QML PaletteSettings: Palette has no property called 'normal.invalid'.";
1140+ QTest::newRow("Invalid property type - int.")
1141+ << "InvalidPaletteSettings3.qml" << 23 << 9
1142+ << "QML PaletteSettings: Not a valid color value.";
1143+ QTest::newRow("Invalid property type - real.")
1144+ << "InvalidPaletteSettings4.qml" << 23 << 9
1145+ << "QML PaletteSettings: Not a valid color value.";
1146+ QTest::newRow("Invalid property type - bool.")
1147+ << "InvalidPaletteSettings5.qml" << 23 << 9
1148+ << "QML PaletteSettings: Not a valid color value.";
1149+ QTest::newRow("Invalid property binding result.")
1150+ << "InvalidPaletteSettings6.qml" << 25 << 32
1151+ << "Unable to assign int to QColor";
1152+ }
1153+ void test_palettesettings_api()
1154+ {
1155+ QFETCH(QString, test);
1156+ QFETCH(int, line);
1157+ QFETCH(int, column);
1158+ QFETCH(QString, warning);
1159+
1160+ ThemeTestCase::ignoreWarning(test, line, column, warning);
1161+ QScopedPointer<ThemeTestCase> view(new ThemeTestCase(test));
1162+ }
1163+
1164+ void test_no_change_in_other_suru_dark()
1165+ {
1166+ QScopedPointer<ThemeTestCase> view(new ThemeTestCase("SameNamedPaletteSettings.qml"));
1167+ UCTheme *firstTheme = view->findItem<UCTheme*>("firstTheme");
1168+ UCTheme *secondTheme = view->findItem<UCTheme*>("secondTheme");
1169+ QVERIFY(firstTheme->getPaletteColor("normal", "background") != secondTheme->getPaletteColor("normal", "background"));
1170+ }
1171+
1172+ void test_keep_palette_value_when_theme_changes()
1173+ {
1174+ QScopedPointer<ThemeTestCase> view(new ThemeTestCase("ChangePaletteValueWhenParentChanges.qml"));
1175+ UCTheme *firstTheme = view->findItem<UCTheme*>("firstTheme");
1176+
1177+ QCOMPARE(firstTheme->getPaletteColor("normal", "background"), QColor("blue"));
1178+ // change the theme
1179+ view->setGlobalTheme("Ubuntu.Components.Themes.SuruDark");
1180+ QTest::waitForEvents();
1181+ QCOMPARE(firstTheme->getPaletteColor("normal", "background"), QColor("blue"));
1182+ }
1183+
1184+ void test_change_default_palette_in_children_kept_after_child_deletion()
1185+ {
1186+ QScopedPointer<ThemeTestCase> view(new ThemeTestCase("ChangeDefaultPaletteInChildren.qml"));
1187+ QQuickItem *loader = view->findItem<QQuickItem*>("loader");
1188+ UCStyledItemBase *main = qobject_cast<UCStyledItemBase*>(view->rootObject());
1189+ UCTheme *mainSet = UCStyledItemBasePrivate::get(main)->getTheme();
1190+ QQuickItem *item = loader->property("item").value<QQuickItem*>();
1191+ QVERIFY(item);
1192+
1193+ QCOMPARE(mainSet->getPaletteColor("normal", "background"), QColor("blue"));
1194+ // unload component
1195+ QSignalSpy itemSpy(item, SIGNAL(destroyed()));
1196+ loader->setProperty("sourceComponent", QVariant());
1197+ itemSpy.wait();
1198+ // palette stays!
1199+ QCOMPARE(mainSet->getPaletteColor("normal", "background"), QColor("blue"));
1200+ }
1201+
1202+ void test_explicit_palettesettings_data()
1203+ {
1204+ QTest::addColumn<QString>("test");
1205+ QTest::addColumn<QColor>("color");
1206+ QTest::addColumn<QColor>("expected");
1207+
1208+ QTest::newRow("explicit: false") << "ImplicitPaletteSettings.qml" << QColor("blue") << QColor("blue");
1209+ QTest::newRow("explicit: true") << "ExplicitPaletteSettings.qml" << QColor("blue") << QColor("red");
1210+ }
1211+ void test_explicit_palettesettings()
1212+ {
1213+ QFETCH(QString, test);
1214+ QFETCH(QColor, color);
1215+ QFETCH(QColor, expected);
1216+
1217+ QScopedPointer<ThemeTestCase> view(new ThemeTestCase(test));
1218+ UCStyledItemBase *main = qobject_cast<UCStyledItemBase*>(view->rootObject());
1219+ UCTheme *theme = view->findItem<UCTheme*>("testSet");
1220+ // set the main color
1221+ main->setProperty("color", color);
1222+ QColor paletteColor = theme->getPaletteColor("normal", "background");
1223+ QCOMPARE(paletteColor, expected);
1224+ }
1225 };
1226
1227 QTEST_MAIN(tst_Subtheming)
1228
1229=== modified file 'tests/unit_x11/tst_subtheming/tst_subtheming.pro'
1230--- tests/unit_x11/tst_subtheming/tst_subtheming.pro 2015-03-17 16:55:26 +0000
1231+++ tests/unit_x11/tst_subtheming/tst_subtheming.pro 2015-03-17 16:55:27 +0000
1232@@ -5,9 +5,8 @@
1233 OTHER_FILES += \
1234 TestStyle.qml \
1235 SimpleItem.qml \
1236- themes/AppTheme/Palette.qml \
1237- themes/AppTheme/parent_theme \
1238 themes/CustomTheme/TestStyle.qml \
1239+ themes/CustomTheme/Palette.qml \
1240 themes/CustomTheme/parent_theme \
1241 themes/TestModule/TestTheme/TestStyle.qml \
1242 themes/TestModule/TestTheme/qmldir \
1243@@ -16,5 +15,18 @@
1244 ParentChanges.qml \
1245 TestMain.qml \
1246 TestStyleChange.qml \
1247- DifferentThemes.qml
1248+ DifferentThemes.qml \
1249+ ChangePaletteValueWhenParentChanges.qml \
1250+ ChangeDefaultPaletteInChildren.qml \
1251+ ImplicitPaletteSettings.qml \
1252+ ExplicitPaletteSettings.qml \
1253+ InvalidPaletteSettings1.qml \
1254+ InvalidPaletteSettings2.qml \
1255+ InvalidPaletteSettings3.qml \
1256+ InvalidPaletteSettings4.qml \
1257+ InvalidPaletteSettings5.qml \
1258+ InvalidPaletteSettings6.qml \
1259+ MorePaletteSettingsInTheme.qml \
1260+ SameNamedPaletteSettings.qml \
1261+ WrongPaletteSettingsDeclaration.qml
1262

Subscribers

People subscribed via source and target branches