37
37
#include <QtGui/QFont>
41
\instantiates UCStyleSet
40
\qmltype ThemeSettings
42
42
\inqmlmodule Ubuntu.Components 1.3
43
43
\since Ubuntu.Components 1.3
45
\brief The StyleSet class provides facilities to define the styleset of a
45
\brief The ThemeSettings class provides facilities to define the theme of a
48
A global instance, which is the default styleset, is exposed as the \b styleSet
48
A global instance is exposed as the \b theme context property.
51
The styleset or theme defines the visual aspect of the Ubuntu components. An
52
application can use one or more styleset the same time. The StyleSet component
53
provides abilities to change thye styleset used by the component and all its
50
The theme or theme defines the visual aspect of the Ubuntu components. An
51
application can use one or more theme the same time. The ThemeSettings component
52
provides abilities to change thye theme used by the component and all its
56
Changing the styleset of the entire application can be achieved by changing
57
the name of the root StyledItem's, i.e. MainView's current styleset.
55
Changing the theme of the entire application can be achieved by changing
56
the name of the root StyledItem's, i.e. MainView's current theme.
64
63
width: units.gu(40)
65
64
height: units.gu(71)
67
styleSet.name: "Ubuntu.Components.Themes.Ambiance"
66
theme.name: "Ubuntu.Components.Themes.Ambiance"
70
69
\note Changing the style set name in this way will result in a change of the
71
70
inherited style set. In case a different style set is desired, a new instance
72
of the StyleSet must be created.
71
of the ThemeSettings must be created.
74
73
The \l createStyleComponent function can be used to create the style for a
75
74
component. The following example will create the style with the inherited
159
UCStyleSet::UCStyleSet(QObject *parent)
158
UCTheme::UCTheme(QObject *parent)
160
159
: QObject(parent)
161
, m_palette(UCStyleSet::defaultSet().m_palette)
162
, m_engine(UCStyleSet::defaultSet().m_engine)
160
, m_palette(UCTheme::defaultTheme().m_palette)
161
, m_engine(UCTheme::defaultTheme().m_engine)
163
162
, m_defaultStyle(false)
168
UCStyleSet::UCStyleSet(bool defaultStyle)
167
UCTheme::UCTheme(bool defaultStyle, QObject *parent)
170
169
, m_palette(NULL)
172
171
, m_defaultStyle(defaultStyle)
180
179
QGuiApplication::setFont(defaultFont);
183
void UCStyleSet::init()
185
184
m_completed = false;
186
185
QObject::connect(&m_themeSettings, &UCThemeSettings::themeNameChanged,
187
this, &UCStyleSet::onThemeNameChanged);
186
this, &UCTheme::onThemeNameChanged);
188
187
updateThemePaths();
191
void UCStyleSet::classBegin()
190
void UCTheme::classBegin()
193
192
m_engine = qmlEngine(this);
194
193
updateEnginePaths();
197
void UCStyleSet::updateEnginePaths()
196
void UCTheme::updateEnginePaths()
211
210
// slot called when the styleset uses the system theme
212
void UCStyleSet::onThemeNameChanged()
211
void UCTheme::onThemeNameChanged()
214
213
updateThemePaths();
215
214
Q_EMIT nameChanged();
218
void UCStyleSet::updateThemePaths()
217
void UCTheme::updateThemePaths()
220
219
m_themePaths.clear();
233
* \qmlproperty StyleSet StyleSet::parent
234
* The property specifies the parent StyleSet. The property only has a valid value
235
* when assigned to \l StyledItem::styleSet property.
232
* \qmlproperty ThemeSettings ThemeSettings::parentTheme
233
* The property specifies the parent ThemeSettings instance. The property only
234
* has a valid value when assigned to \l StyledItem::theme property.
237
UCStyleSet *UCStyleSet::parentSet()
236
UCTheme *UCTheme::parentTheme()
239
238
UCStyledItemBase *owner = qobject_cast<UCStyledItemBase*>(parent());
240
239
UCStyledItemBasePrivate *pOwner = owner ? UCStyledItemBasePrivate::get(owner) : NULL;
241
if (pOwner && pOwner->styleSet == this && pOwner->parentStyledItem) {
242
return UCStyledItemBasePrivate::get(pOwner->parentStyledItem)->getStyleSet();
240
if (pOwner && pOwner->theme == this && pOwner->parentStyledItem) {
241
return UCStyledItemBasePrivate::get(pOwner->parentStyledItem)->getTheme();
248
\qmlproperty string StyleSet::name
247
\qmlproperty string ThemeSettings::name
250
249
The name of the current theme. The name can be set only at creation time, runtime
251
250
changes will be omitted.
255
254
import Ubuntu.Componenst 1.3
257
style: ThemeSettings {
260
259
name: "Ubuntu.Components.Themes.Ambiance"
262
261
// this is not allowed, and will be omitted
263
Components.onCompleted: styleSet.name = "Ubuntu.Components.Themes.SuruDark"
262
Components.onCompleted: theme.name = "Ubuntu.Components.Themes.SuruDark"
267
QString UCStyleSet::name() const
266
QString UCTheme::name() const
269
268
return !m_name.isEmpty() ? m_name : m_themeSettings.themeName();
271
void UCStyleSet::setName(const QString& name)
270
void UCTheme::setName(const QString& name)
273
272
if (name == m_name) {
280
279
QObject::disconnect(&m_themeSettings, &UCThemeSettings::themeNameChanged,
281
this, &UCStyleSet::onThemeNameChanged);
280
this, &UCTheme::onThemeNameChanged);
282
281
updateThemePaths();
284
283
updateEnginePaths();
286
285
Q_EMIT nameChanged();
288
void UCStyleSet::resetName()
287
void UCTheme::resetName()
290
289
setName(QString());
294
\qmlproperty Palette StyleSet::palette
293
\qmlproperty Palette ThemeSettings::palette
296
295
The palette of the current theme.
298
QObject* UCStyleSet::palette()
297
QObject* UCTheme::palette()
300
299
if (!m_palette) {
301
300
loadPalette(false);
303
302
return m_palette;
306
QUrl UCStyleSet::styleUrl(const QString& styleName)
305
QUrl UCTheme::styleUrl(const QString& styleName)
308
307
Q_FOREACH (const QUrl& themePath, m_themePaths) {
309
308
QUrl styleUrl = themePath.resolved(styleName);
331
330
return parentTheme;
334
// registers the default styleSet property to the root context
335
void UCStyleSet::registerToContext(QQmlContext* context)
333
// registers the default theme property to the root context
334
void UCTheme::registerToContext(QQmlContext* context)
337
UCStyleSet *defaultSet = &UCStyleSet::defaultSet();
338
defaultSet->m_engine = context->engine();
339
defaultSet->updateEnginePaths();
336
UCTheme *defaultTheme = &UCTheme::defaultTheme();
337
defaultTheme->m_engine = context->engine();
338
defaultTheme->updateEnginePaths();
341
context->setContextProperty("styleSet", defaultSet);
340
context->setContextProperty("theme", defaultTheme);
342
341
ContextPropertyChangeListener *listener =
343
new ContextPropertyChangeListener(context, "styleSet");
344
QObject::connect(defaultSet, &UCStyleSet::nameChanged,
342
new ContextPropertyChangeListener(context, "theme");
343
QObject::connect(defaultTheme, &UCTheme::nameChanged,
345
344
listener, &ContextPropertyChangeListener::updateContextProperty);
349
\qmlmethod Component StyleSet::createStyleComponent(string styleName, object parent)
348
\qmlmethod Component ThemeSettings::createStyleComponent(string styleName, object parent)
351
350
Returns an instance of the style component named \a styleName and parented
354
QQmlComponent* UCStyleSet::createStyleComponent(const QString& styleName, QObject* parent)
353
QQmlComponent* UCTheme::createStyleComponent(const QString& styleName, QObject* parent)
356
355
QQmlComponent *component = NULL;