aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-03-21 17:03:55 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2017-03-22 11:17:13 +0000
commite7d03ea7aae172bb2ef5e89b89156f8ea143eca1 (patch)
tree3dcb330fdd91dcfe6b63b85a059de0d95c250bc6
parentf7c0efb42bd7f8b331525b42ec16536c1b4862f9 (diff)
Move isDarkTheme() to QQuickStylePrivate
QQuickStyleAttached is being generalized to a recursive attached object type that can be used for palettes too, which are planned to be used for the upcoming image-based style. Change-Id: I4c1d25624ee11bb0ec6cd5ee2656c36e622e2139 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/imports/controls/material/qquickmaterialstyle.cpp6
-rw-r--r--src/imports/controls/universal/qquickuniversalstyle.cpp4
-rw-r--r--src/quickcontrols2/qquickstyle.cpp20
-rw-r--r--src/quickcontrols2/qquickstyle_p.h1
-rw-r--r--src/quickcontrols2/qquickstyleattached.cpp21
5 files changed, 24 insertions, 28 deletions
diff --git a/src/imports/controls/material/qquickmaterialstyle.cpp b/src/imports/controls/material/qquickmaterialstyle.cpp
index 5685b197..94dfa80d 100644
--- a/src/imports/controls/material/qquickmaterialstyle.cpp
+++ b/src/imports/controls/material/qquickmaterialstyle.cpp
@@ -419,12 +419,10 @@ static const QRgb rippleColorDark = 0x20FFFFFF;
static const QRgb spinBoxDisabledIconColorLight = 0xFFCCCCCC;
static const QRgb spinBoxDisabledIconColorDark = 0xFF666666;
-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;
+ theme = QQuickStylePrivate::isDarkSystemTheme() ? QQuickMaterialStyle::Dark : QQuickMaterialStyle::Light;
return theme;
}
@@ -463,7 +461,7 @@ QQuickMaterialStyle::Theme QQuickMaterialStyle::theme() const
void QQuickMaterialStyle::setTheme(Theme theme)
{
if (theme == System)
- theme = qt_is_dark_system_theme() ? Dark : Light;
+ theme = QQuickStylePrivate::isDarkSystemTheme() ? Dark : Light;
m_explicitTheme = true;
if (m_theme == theme)
diff --git a/src/imports/controls/universal/qquickuniversalstyle.cpp b/src/imports/controls/universal/qquickuniversalstyle.cpp
index 7257683c..8afb4e29 100644
--- a/src/imports/controls/universal/qquickuniversalstyle.cpp
+++ b/src/imports/controls/universal/qquickuniversalstyle.cpp
@@ -132,12 +132,10 @@ static QRgb qquickuniversal_accent_color(QQuickUniversalStyle::Color accent)
return colors[accent];
}
-extern bool qt_is_dark_system_theme();
-
static QQuickUniversalStyle::Theme qquickuniversal_effective_theme(QQuickUniversalStyle::Theme theme)
{
if (theme == QQuickUniversalStyle::System)
- theme = qt_is_dark_system_theme() ? QQuickUniversalStyle::Dark : QQuickUniversalStyle::Light;
+ theme = QQuickStylePrivate::isDarkSystemTheme() ? QQuickUniversalStyle::Dark : QQuickUniversalStyle::Light;
return theme;
}
diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp
index d4e72efb..f154f0ce 100644
--- a/src/quickcontrols2/qquickstyle.cpp
+++ b/src/quickcontrols2/qquickstyle.cpp
@@ -43,7 +43,10 @@
#include <QtCore/qsettings.h>
#include <QtCore/qfileselector.h>
#include <QtCore/qlibraryinfo.h>
+#include <QtGui/qcolor.h>
+#include <QtGui/qpalette.h>
#include <QtGui/private/qguiapplication_p.h>
+#include <QtGui/qpa/qplatformtheme.h>
#include <QtQml/private/qqmlmetatype_p.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlfile.h>
@@ -329,6 +332,23 @@ QSharedPointer<QSettings> QQuickStylePrivate::settings(const QString &group)
return QSharedPointer<QSettings>();
}
+static bool qt_is_dark_system_theme()
+{
+ 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;
+}
+
+bool QQuickStylePrivate::isDarkSystemTheme()
+{
+ static bool dark = qt_is_dark_system_theme();
+ return dark;
+}
+
/*!
Returns the name of the application style.
diff --git a/src/quickcontrols2/qquickstyle_p.h b/src/quickcontrols2/qquickstyle_p.h
index 5f51737b..b92df3c2 100644
--- a/src/quickcontrols2/qquickstyle_p.h
+++ b/src/quickcontrols2/qquickstyle_p.h
@@ -66,6 +66,7 @@ public:
static void reset();
static QString configFilePath();
static QSharedPointer<QSettings> settings(const QString &group = QString());
+ static bool isDarkSystemTheme();
};
QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickstyleattached.cpp b/src/quickcontrols2/qquickstyleattached.cpp
index fd02790f..8b87a6d0 100644
--- a/src/quickcontrols2/qquickstyleattached.cpp
+++ b/src/quickcontrols2/qquickstyleattached.cpp
@@ -36,33 +36,12 @@
#include "qquickstyleattached_p.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)