aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/controls/material
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2016-04-22 10:07:45 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-05-26 10:00:21 +0000
commit9ca63fbd0b022bd48d112f4beb38712e41612fb5 (patch)
tree53520b7dbc4b70f9cda47dcbc9429fbb4b4c2479 /src/imports/controls/material
parent44ac831c51d248b115e594ae930c3bb359df68a1 (diff)
Introduce a 'System' theme to the styles.
Setting the theme to System chooses either the light or dark theme based on the system theme colors. However, when reading the value of the theme property, the value is never System, but the actual theme. [ChangeLog][Controls][Material] Added Material.System theme enum value, that can be used to let the Material style choose either the light or dark theme based on the system theme colors. [ChangeLog][Controls][Universal] Added Universal.System theme enum value, that can be used to let the Universal style choose either the light or dark theme based on the system theme colors. Change-Id: Ibfc9f01953cb8322b64d59413cfbaef9d4bb28fd Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/imports/controls/material')
-rw-r--r--src/imports/controls/material/qquickmaterialstyle.cpp14
-rw-r--r--src/imports/controls/material/qquickmaterialstyle_p.h3
2 files changed, 15 insertions, 2 deletions
diff --git a/src/imports/controls/material/qquickmaterialstyle.cpp b/src/imports/controls/material/qquickmaterialstyle.cpp
index ce72e04b..8ad1ba66 100644
--- a/src/imports/controls/material/qquickmaterialstyle.cpp
+++ b/src/imports/controls/material/qquickmaterialstyle.cpp
@@ -426,6 +426,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),
@@ -460,6 +469,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;
@@ -1195,7 +1207,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 e7434d83..2686d14b 100644
--- a/src/imports/controls/material/qquickmaterialstyle_p.h
+++ b/src/imports/controls/material/qquickmaterialstyle_p.h
@@ -108,7 +108,8 @@ class QQuickMaterialStyle : public QQuickStyleAttached
public:
enum Theme {
Light,
- Dark
+ Dark,
+ System
};
enum Color {