From 92c85dc58c198796b1682b0e9fb3f14ad724abd0 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 12 Feb 2018 13:48:54 +0100 Subject: QQuickUniversalStyle: init the globals from the plugin Change-Id: I9df13f980b565b4f846edc3bce8333b74f5366b9 Reviewed-by: Mitch Curtis --- .../controls/universal/qquickuniversalstyle.cpp | 103 ++++++++++----------- .../controls/universal/qquickuniversalstyle_p.h | 3 +- .../qtquickcontrols2universalstyleplugin.cpp | 1 + 3 files changed, 51 insertions(+), 56 deletions(-) diff --git a/src/imports/controls/universal/qquickuniversalstyle.cpp b/src/imports/controls/universal/qquickuniversalstyle.cpp index 157d5ddb..dbc409fd 100644 --- a/src/imports/controls/universal/qquickuniversalstyle.cpp +++ b/src/imports/controls/universal/qquickuniversalstyle.cpp @@ -536,66 +536,59 @@ static QByteArray resolveSetting(const QByteArray &env, const QSharedPointer settings = QQuickStylePrivate::settings(QStringLiteral("Universal")); - - bool ok = false; - QByteArray themeValue = resolveSetting("QT_QUICK_CONTROLS_UNIVERSAL_THEME", settings, QStringLiteral("Theme")); - Theme themeEnum = toEnumValue(themeValue, &ok); - if (ok) - GlobalTheme = m_theme = qquickuniversal_effective_theme(themeEnum); - else if (!themeValue.isEmpty()) - qWarning().nospace().noquote() << "Universal: unknown theme value: " << themeValue; - - QByteArray accentValue = resolveSetting("QT_QUICK_CONTROLS_UNIVERSAL_ACCENT", settings, QStringLiteral("Accent")); - Color accentEnum = toEnumValue(accentValue, &ok); - if (ok) { - GlobalAccent = m_accent = qquickuniversal_accent_color(accentEnum); - } else if (!accentValue.isEmpty()) { - QColor color(accentValue.constData()); - if (color.isValid()) - GlobalAccent = m_accent = color.rgba(); - else - qWarning().nospace().noquote() << "Universal: unknown accent value: " << accentValue; - } +void QQuickUniversalStyle::initGlobals() +{ + QSharedPointer settings = QQuickStylePrivate::settings(QStringLiteral("Universal")); + + bool ok = false; + QByteArray themeValue = resolveSetting("QT_QUICK_CONTROLS_UNIVERSAL_THEME", settings, QStringLiteral("Theme")); + Theme themeEnum = toEnumValue(themeValue, &ok); + if (ok) + GlobalTheme = qquickuniversal_effective_theme(themeEnum); + else if (!themeValue.isEmpty()) + qWarning().nospace().noquote() << "Universal: unknown theme value: " << themeValue; + + QByteArray accentValue = resolveSetting("QT_QUICK_CONTROLS_UNIVERSAL_ACCENT", settings, QStringLiteral("Accent")); + Color accentEnum = toEnumValue(accentValue, &ok); + if (ok) { + GlobalAccent = qquickuniversal_accent_color(accentEnum); + } else if (!accentValue.isEmpty()) { + QColor color(accentValue.constData()); + if (color.isValid()) + GlobalAccent = color.rgba(); + else + qWarning().nospace().noquote() << "Universal: unknown accent value: " << accentValue; + } - QByteArray foregroundValue = resolveSetting("QT_QUICK_CONTROLS_UNIVERSAL_FOREGROUND", settings, QStringLiteral("Foreground")); - Color foregroundEnum = toEnumValue(foregroundValue, &ok); - if (ok) { - GlobalForeground = m_foreground = qquickuniversal_accent_color(foregroundEnum); - HasGlobalForeground = m_hasForeground = true; - } else if (!foregroundValue.isEmpty()) { - QColor color(foregroundValue.constData()); - if (color.isValid()) { - GlobalForeground = m_foreground = color.rgba(); - HasGlobalForeground = m_hasForeground = true; - } else { - qWarning().nospace().noquote() << "Universal: unknown foreground value: " << foregroundValue; - } + QByteArray foregroundValue = resolveSetting("QT_QUICK_CONTROLS_UNIVERSAL_FOREGROUND", settings, QStringLiteral("Foreground")); + Color foregroundEnum = toEnumValue(foregroundValue, &ok); + if (ok) { + GlobalForeground = qquickuniversal_accent_color(foregroundEnum); + HasGlobalForeground = true; + } else if (!foregroundValue.isEmpty()) { + QColor color(foregroundValue.constData()); + if (color.isValid()) { + GlobalForeground = color.rgba(); + HasGlobalForeground = true; + } else { + qWarning().nospace().noquote() << "Universal: unknown foreground value: " << foregroundValue; } + } - QByteArray backgroundValue = resolveSetting("QT_QUICK_CONTROLS_UNIVERSAL_BACKGROUND", settings, QStringLiteral("Background")); - Color backgroundEnum = toEnumValue(backgroundValue, &ok); - if (ok) { - GlobalBackground = m_background = qquickuniversal_accent_color(backgroundEnum); - HasGlobalBackground = m_hasBackground = true; - } else if (!backgroundValue.isEmpty()) { - QColor color(backgroundValue.constData()); - if (color.isValid()) { - GlobalBackground = m_background = color.rgba(); - HasGlobalBackground = m_hasBackground = true; - } else { - qWarning().nospace().noquote() << "Universal: unknown background value: " << backgroundValue; - } + QByteArray backgroundValue = resolveSetting("QT_QUICK_CONTROLS_UNIVERSAL_BACKGROUND", settings, QStringLiteral("Background")); + Color backgroundEnum = toEnumValue(backgroundValue, &ok); + if (ok) { + GlobalBackground = qquickuniversal_accent_color(backgroundEnum); + HasGlobalBackground = true; + } else if (!backgroundValue.isEmpty()) { + QColor color(backgroundValue.constData()); + if (color.isValid()) { + GlobalBackground = color.rgba(); + HasGlobalBackground = true; + } else { + qWarning().nospace().noquote() << "Universal: unknown background value: " << backgroundValue; } - - globalsInitialized = true; } - - QQuickAttachedObject::init(); // TODO: lazy init? } bool QQuickUniversalStyle::variantToRgba(const QVariant &var, const char *name, QRgb *rgba) const diff --git a/src/imports/controls/universal/qquickuniversalstyle_p.h b/src/imports/controls/universal/qquickuniversalstyle_p.h index 196048ef..eb9f6d83 100644 --- a/src/imports/controls/universal/qquickuniversalstyle_p.h +++ b/src/imports/controls/universal/qquickuniversalstyle_p.h @@ -200,6 +200,8 @@ public: QColor systemColor(SystemColor role) const; + static void initGlobals(); + Q_SIGNALS: void themeChanged(); void accentChanged(); @@ -211,7 +213,6 @@ protected: void attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent) override; private: - void init(); bool variantToRgba(const QVariant &var, const char *name, QRgb *rgba) const; // These reflect whether a color value was explicitly set on the specific diff --git a/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.cpp b/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.cpp index 8e5477ec..139acab9 100644 --- a/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.cpp +++ b/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.cpp @@ -69,6 +69,7 @@ public: QtQuickControls2UniversalStylePlugin::QtQuickControls2UniversalStylePlugin(QObject *parent) : QQuickStylePlugin(parent) { initResources(); + QQuickUniversalStyle::initGlobals(); } void QtQuickControls2UniversalStylePlugin::registerTypes(const char *uri) -- cgit v1.2.3