diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2016-04-22 10:07:45 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-05-26 10:00:21 +0000 |
commit | 9ca63fbd0b022bd48d112f4beb38712e41612fb5 (patch) | |
tree | 53520b7dbc4b70f9cda47dcbc9429fbb4b4c2479 /src/quickcontrols2 | |
parent | 44ac831c51d248b115e594ae930c3bb359df68a1 (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/quickcontrols2')
-rw-r--r-- | src/quickcontrols2/qquickstyleattached.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/quickcontrols2/qquickstyleattached.cpp b/src/quickcontrols2/qquickstyleattached.cpp index d0df79c5..6683b018 100644 --- a/src/quickcontrols2/qquickstyleattached.cpp +++ b/src/quickcontrols2/qquickstyleattached.cpp @@ -39,12 +39,33 @@ #include <QtCore/qfile.h> #include <QtCore/qsettings.h> #include <QtCore/qfileselector.h> +#include <QtGui/qcolor.h> +#include <QtGui/qpalette.h> +#include <QtGui/private/qguiapplication_p.h> +#include <QtGui/qpa/qplatformtheme.h> #include <QtQuick/qquickwindow.h> #include <QtQuick/private/qquickitem_p.h> #include <QtQuickTemplates2/private/qquickpopup_p.h> QT_BEGIN_NAMESPACE +static bool isDarkSystemTheme() +{ + if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { + if (const QPalette *systemPalette = theme->palette(QPlatformTheme::SystemPalette)) { + const QColor textColor = systemPalette->color(QPalette::WindowText); + return textColor.red() > 128 && textColor.blue() > 128 && textColor.green() > 128; + } + } + return false; +} + +Q_QUICKCONTROLS2_PRIVATE_EXPORT bool qt_is_dark_system_theme() +{ + static bool dark = isDarkSystemTheme(); + return dark; +} + static QQuickStyleAttached *attachedStyle(const QMetaObject *type, QObject *object, bool create = false) { if (!object) |