11#include <QtQuickTemplates2/private/qquickdeferredexecute_p_p.h>
12#include <QtQml/private/qqmllist_p.h>
14#include <QtGui/QGuiApplication>
15#include <QtGui/QStyleHints>
25 , m_paletteProxy(
new QQuickPalette(
this))
26 , m_themeName(kSystem)
33 m_theme->deleteLater();
38 return m_paletteProxy;
48 if (!m_fallbackStyle) {
50 self->executeFallbackStyle();
52 return m_fallbackStyle;
57 if (m_fallbackStyle == fallbackStyle)
60 m_fallbackStyle = fallbackStyle;
61 emit fallbackStyleChanged();
64 palettes()->setFallbackPalette(m_fallbackStyle ? m_fallbackStyle->palettes() :
nullptr);
67 fonts()->setFallbackFont(m_fallbackStyle ? m_fallbackStyle->fonts() :
nullptr);
73 if (m_light == lightTheme)
88 if (m_dark == darkTheme)
103 QList<QObject *> list;
104 for (
auto *customTheme : customThemes())
105 list.append(customTheme);
111 QList<QQStyleKitCustomTheme *> list;
112 for (
auto *obj : children()) {
113 if (
auto *customTheme = qobject_cast<QQStyleKitCustomTheme *>(obj))
114 list.append(customTheme);
121 m_themeNames = QStringList({kSystem, kLight, kDark});
123 for (
auto *customTheme : customThemes()) {
124 const QString name = customTheme->name();
127 m_themeNames << name;
128 m_customThemeNames << name;
131 emit themeNamesChanged();
132 emit customThemeNamesChanged();
147 return m_customThemeNames;
152 if (m_themeName == themeName)
155 m_themeName = themeName;
158 emit themeNameChanged();
163 QString effectiveThemeName;
164 QQmlComponent *effectiveThemeComponent =
nullptr;
166 if (QString::compare(m_themeName, kSystem, Qt::CaseInsensitive) == 0) {
167 const auto scheme = QGuiApplication::styleHints()->colorScheme();
168 if (scheme == Qt::ColorScheme::Light) {
169 effectiveThemeName = kLight;
170 effectiveThemeComponent = m_light;
172 else if (scheme == Qt::ColorScheme::Dark) {
173 effectiveThemeName =kDark;
174 effectiveThemeComponent = m_dark;
176 }
else if (QString::compare(m_themeName, kLight, Qt::CaseInsensitive) == 0) {
177 effectiveThemeName = kLight;
178 effectiveThemeComponent = m_light;
179 }
else if (QString::compare(m_themeName,kDark, Qt::CaseInsensitive) == 0) {
180 effectiveThemeName =kDark;
181 effectiveThemeComponent = m_dark;
182 }
else if (!m_themeName.isEmpty()){
183 for (
auto *customTheme : customThemes()) {
184 if (QString::compare(m_themeName, customTheme->name(), Qt::CaseInsensitive) == 0) {
185 effectiveThemeName = customTheme->name();
186 effectiveThemeComponent = customTheme->theme();
190 if (effectiveThemeName.isEmpty())
191 qmlWarning(
this) <<
"No theme found with name:" << m_themeName;
192 else if (!effectiveThemeComponent)
193 qmlWarning(
this) <<
"Custom theme '" << effectiveThemeName <<
"' has no theme component set";
196 if (m_effectiveThemeName == effectiveThemeName) {
199 emit themeNameChanged();
204 m_theme->deleteLater();
208 m_currentThemeComponent = effectiveThemeComponent;
210 if (effectiveThemeComponent) {
211 if (effectiveThemeComponent->status() != QQmlComponent::Ready) {
212 qmlWarning(
this) <<
"failed to create theme '" << effectiveThemeName <<
"': " << effectiveThemeComponent->errorString();
215
216
217
218
219 QVariant themeAsVariant;
220 QMetaObject::invokeMethod(
this,
"createThemeInsideStyle", Qt::DirectConnection,
221 qReturnArg(themeAsVariant), QVariant::fromValue(effectiveThemeComponent));
222 m_theme = qvariant_cast<QQStyleKitTheme *>(themeAsVariant);
224 if (!m_theme || !effectiveThemeComponent->errorString().isEmpty()) {
225 qmlWarning(
this) <<
"failed to create theme '" << effectiveThemeName <<
"': " << effectiveThemeComponent->errorString();
227 m_theme->setParent(
this);
234 m_theme =
new QQStyleKitTheme(
this);
235 m_theme->setObjectName(
"<empty theme>"_L1);
236 m_theme->m_completed =
true;
238 m_theme->setParent(
this);
241 if (m_theme->fonts())
242 m_theme->fonts()->setFallbackFont(fonts());
243 if (m_theme->palettes())
244 m_theme->palettes()->setFallbackPalette(palettes());
246 m_theme->updateThemePalettes();
247 m_theme->updateThemeFonts();
256 return QQStyleKit::qmlAttachedProperties()->style();
261 return m_theme->paletteForControlType(type);
266 return m_theme->fontForControlType(type);
272
273
274
277 if (!m_theme || !m_theme->m_completed)
285 if (m_fallbackStyle.wasExecuted())
288 const QString name =
"fallbackStyle"_L1;
289 if (!m_fallbackStyle || complete)
290 quickBeginDeferred(
this, name, m_fallbackStyle);
292 quickCompleteDeferred(
this, name, m_fallbackStyle);
297 if (m_isUpdatingPalette)
299 QScopedValueRollback<
bool> rb(m_isUpdatingPalette,
true);
300 if (palette == m_effectivePalette)
302 m_effectivePalette = palette;
303 m_paletteProxy->fromQPalette(m_effectivePalette);
304 emit paletteChanged();
309 return m_effectivePalette;
317
318
321 executeFallbackStyle(
true);
328#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