11#include <QtQuickTemplates2/private/qquickdeferredexecute_p_p.h>
12#include <QtQml/private/qqmllist_p.h>
14#include <QtGui/QGuiApplication>
15#include <QtGui/QStyleHints>
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
58
59
60
61
62
63
64
65
68
69
70
71
72
73
74
75
76
77
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
100
101
102
103
104
105
106
107
108
109
112
113
114
115
116
117
118
119
120
121
122
123
124
125
128
129
130
131
132
133
134
135
136
137
138
139
140
141
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
171
172
173
174
175
176
177
178
186 , m_paletteProxy(
new QQuickPalette(
this))
187 , m_themeName(kSystem)
194 m_theme->deleteLater();
199 return m_paletteProxy;
209 if (!m_fallbackStyle) {
211 self->executeFallbackStyle();
213 return m_fallbackStyle;
218 if (m_fallbackStyle == fallbackStyle)
221 m_fallbackStyle = fallbackStyle;
222 emit fallbackStyleChanged();
225 palettes()->setFallbackPalette(m_fallbackStyle ? m_fallbackStyle->palettes() :
nullptr);
228 fonts()->setFallbackFont(m_fallbackStyle ? m_fallbackStyle->fonts() :
nullptr);
234 if (m_light == lightTheme)
237 m_light = lightTheme;
249 if (m_dark == darkTheme)
264 QList<QObject *> list;
265 for (
auto *customTheme : customThemes())
266 list.append(customTheme);
272 QList<QQStyleKitCustomTheme *> list;
273 for (
auto *obj : children()) {
274 if (
auto *customTheme = qobject_cast<QQStyleKitCustomTheme *>(obj))
275 list.append(customTheme);
282 m_themeNames = QStringList({kSystem});
285 m_themeNames << kLight;
287 m_themeNames << kDark;
289 for (
auto *customTheme : customThemes()) {
290 const QString name = customTheme->name();
293 m_themeNames << name;
294 m_customThemeNames << name;
297 emit themeNamesChanged();
298 emit customThemeNamesChanged();
313 return m_customThemeNames;
318 if (m_themeName == themeName)
321 m_themeName = themeName;
324 emit themeNameChanged();
329 QString effectiveThemeName;
330 QQmlComponent *effectiveThemeComponent =
nullptr;
332 if (QString::compare(m_themeName, kSystem, Qt::CaseInsensitive) == 0) {
333 const auto scheme = QGuiApplication::styleHints()->colorScheme();
334 if (scheme == Qt::ColorScheme::Light) {
335 effectiveThemeName = kLight;
336 effectiveThemeComponent = m_light;
338 else if (scheme == Qt::ColorScheme::Dark) {
339 effectiveThemeName = kDark;
340 effectiveThemeComponent = m_dark;
342 }
else if (QString::compare(m_themeName, kLight, Qt::CaseInsensitive) == 0) {
343 effectiveThemeName = kLight;
344 effectiveThemeComponent = m_light;
345 }
else if (QString::compare(m_themeName,kDark, Qt::CaseInsensitive) == 0) {
346 effectiveThemeName =kDark;
347 effectiveThemeComponent = m_dark;
348 }
else if (!m_themeName.isEmpty()){
349 for (
auto *customTheme : customThemes()) {
350 if (QString::compare(m_themeName, customTheme->name(), Qt::CaseInsensitive) == 0) {
351 effectiveThemeName = customTheme->name();
352 effectiveThemeComponent = customTheme->theme();
356 if (effectiveThemeName.isEmpty())
357 qmlWarning(
this) <<
"No theme found with name:" << m_themeName;
358 else if (!effectiveThemeComponent)
359 qmlWarning(
this) <<
"Custom theme '" << effectiveThemeName <<
"' has no theme component set";
362 if (m_effectiveThemeName == effectiveThemeName) {
365 emit themeNameChanged();
370 m_theme->deleteLater();
374 m_currentThemeComponent = effectiveThemeComponent;
376 if (effectiveThemeComponent) {
377 if (effectiveThemeComponent->status() != QQmlComponent::Ready) {
378 qmlWarning(
this) <<
"failed to create theme '" << effectiveThemeName <<
"': " << effectiveThemeComponent->errorString();
381
382
383
384
385 QVariant themeAsVariant;
386 QMetaObject::invokeMethod(
this,
"createThemeInsideStyle", Qt::DirectConnection,
387 qReturnArg(themeAsVariant), QVariant::fromValue(effectiveThemeComponent));
388 m_theme = qvariant_cast<QQStyleKitTheme *>(themeAsVariant);
390 if (!m_theme || !effectiveThemeComponent->errorString().isEmpty()) {
391 qmlWarning(
this) <<
"failed to create theme '" << effectiveThemeName <<
"': " << effectiveThemeComponent->errorString();
393 m_theme->setParent(
this);
400 m_theme =
new QQStyleKitTheme(
this);
401 m_theme->setObjectName(
"<empty theme>"_L1);
402 m_theme->m_completed =
true;
404 m_theme->setParent(
this);
407 if (m_theme->fonts())
408 m_theme->fonts()->setFallbackFont(fonts());
409 if (m_theme->palettes())
410 m_theme->palettes()->setFallbackPalette(palettes());
412 m_theme->updateThemePalettes();
413 m_theme->updateThemeFonts();
422 return QQStyleKit::qmlAttachedProperties()->style();
427 return m_theme->paletteForControlType(type);
432 return m_theme->fontForControlType(type);
438
439
440
443 if (!m_theme || !m_theme->m_completed)
451 if (m_fallbackStyle.wasExecuted())
454 const QString name =
"fallbackStyle"_L1;
455 if (!m_fallbackStyle || complete)
456 quickBeginDeferred(
this, name, m_fallbackStyle);
458 quickCompleteDeferred(
this, name, m_fallbackStyle);
463 if (m_isUpdatingPalette)
465 QScopedValueRollback<
bool> rb(m_isUpdatingPalette,
true);
466 if (palette == m_effectivePalette)
468 m_effectivePalette = palette;
469 m_paletteProxy->fromQPalette(m_effectivePalette);
470 emit paletteChanged();
475 return m_effectivePalette;
483
484
487 executeFallbackStyle(
true);
494#include "moc_qqstylekitstyle_p.cpp"
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
QQStyleKitPalette * palettes()
QList< QQStyleKitCustomTheme * > customThemes() const
QStringList themeNames() const
QQmlComponent * dark() const
QQmlComponent * light() const
QStringList customThemeNames() const
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
QQStyleKitStyle * fallbackStyle() const
QQStyleKitTheme * theme() const
static QQStyleKitStyle * current()
QQuickPalette * palette() const
void setThemeName(const QString &themeName)
void setDark(QQmlComponent *darkTheme)
QPalette paletteForControlType(QQStyleKitExtendableControlType type) const
QFont fontForControlType(QQStyleKitExtendableControlType type) const
void setLight(QQmlComponent *lightTheme)
QString themeName() const
void setFallbackStyle(QQStyleKitStyle *fallbackStyle)
Combined button and popup list for selecting options.
static const QString kDark
static const QString kLight
static QT_BEGIN_NAMESPACE const QString kSystem
\qmltype Style \inqmlmodule Qt.labs.StyleKit \inherits AbstractStyle