diff options
Diffstat (limited to 'src/imports/controls/material')
-rw-r--r-- | src/imports/controls/material/qquickmaterialstyle.cpp | 14 | ||||
-rw-r--r-- | src/imports/controls/material/qquickmaterialstyle_p.h | 3 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/imports/controls/material/qquickmaterialstyle.cpp b/src/imports/controls/material/qquickmaterialstyle.cpp index 7e9ba001..76d81e5f 100644 --- a/src/imports/controls/material/qquickmaterialstyle.cpp +++ b/src/imports/controls/material/qquickmaterialstyle.cpp @@ -428,6 +428,15 @@ static QColor alphaBlend(const QColor &bg, const QColor &fg) return result; } +extern bool qt_is_dark_system_theme(); + +static QQuickMaterialStyle::Theme effectiveTheme(QQuickMaterialStyle::Theme theme) +{ + if (theme == QQuickMaterialStyle::System) + theme = qt_is_dark_system_theme() ? QQuickMaterialStyle::Dark : QQuickMaterialStyle::Light; + return theme; +} + QQuickMaterialStyle::QQuickMaterialStyle(QObject *parent) : QQuickStyleAttached(parent), m_explicitTheme(false), m_explicitPrimary(false), @@ -462,6 +471,9 @@ QQuickMaterialStyle::Theme QQuickMaterialStyle::theme() const void QQuickMaterialStyle::setTheme(Theme theme) { + if (theme == System) + theme = qt_is_dark_system_theme() ? Dark : Light; + m_explicitTheme = true; if (m_theme == theme) return; @@ -1208,7 +1220,7 @@ void QQuickMaterialStyle::init() QByteArray themeValue = resolveSetting("QT_QUICK_CONTROLS_MATERIAL_THEME", settings, QStringLiteral("Theme")); Theme themeEnum = toEnumValue<Theme>(themeValue, &ok); if (ok) - defaultTheme = m_theme = themeEnum; + defaultTheme = m_theme = effectiveTheme(themeEnum); else if (!themeValue.isEmpty()) qWarning().nospace().noquote() << "Material: unknown theme value: " << themeValue; diff --git a/src/imports/controls/material/qquickmaterialstyle_p.h b/src/imports/controls/material/qquickmaterialstyle_p.h index 7572d38c..59858a5e 100644 --- a/src/imports/controls/material/qquickmaterialstyle_p.h +++ b/src/imports/controls/material/qquickmaterialstyle_p.h @@ -109,7 +109,8 @@ class QQuickMaterialStyle : public QQuickStyleAttached public: enum Theme { Light, - Dark + Dark, + System }; enum Color { |