diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2016-08-19 16:00:03 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2016-08-19 14:12:00 +0000 |
commit | 9b7e62a88b9d86ba6b391bf7abc18cba3c147ed5 (patch) | |
tree | ee0e87b37b314dd5357bb192613bf91bb91793a1 /src | |
parent | 47f32f2f768edbaa96c9356f0b2b4cb4f566b814 (diff) |
Universal: ensure setting background/foreground works
- Add HasGlobalForeground and HasGlobalBackground. These are set
to true when a foreground/background color is specified via settings
(qtquickcontrols2.conf file or environment variables), and then used
to initialize each attached style object's m_hasForeground and
m_hasBackground property.
- Add tst_qquickuniversalstyleconf auto test to ensure that global
settings are respected.
Task-number: QTBUG-55366
Change-Id: I7a8b219506f9528c4ae323bd890b418ba056ed23
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/controls/universal/qquickuniversalstyle.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/imports/controls/universal/qquickuniversalstyle.cpp b/src/imports/controls/universal/qquickuniversalstyle.cpp index 51776fbd..c5516a9e 100644 --- a/src/imports/controls/universal/qquickuniversalstyle.cpp +++ b/src/imports/controls/universal/qquickuniversalstyle.cpp @@ -136,10 +136,14 @@ static QQuickUniversalStyle::Theme GlobalTheme = QQuickUniversalStyle::Light; static QRgb GlobalAccent = qquickuniversal_accent_color(QQuickUniversalStyle::Cobalt); static QRgb GlobalForeground = qquickuniversal_light_color(QQuickUniversalStyle::BaseHigh); static QRgb GlobalBackground = qquickuniversal_light_color(QQuickUniversalStyle::AltHigh); +// These represent whether a global foreground/background was set. +// Each style's m_hasForeground/m_hasBackground are initialized to these values. +static bool HasGlobalForeground = false; +static bool HasGlobalBackground = false; QQuickUniversalStyle::QQuickUniversalStyle(QObject *parent) : QQuickStyleAttached(parent), m_explicitTheme(false), m_explicitAccent(false), m_explicitForeground(false), m_explicitBackground(false), - m_hasForeground(false), m_hasBackground(false), m_theme(GlobalTheme), + m_hasForeground(HasGlobalForeground), m_hasBackground(HasGlobalBackground), m_theme(GlobalTheme), m_accent(GlobalAccent), m_foreground(GlobalForeground), m_background(GlobalBackground) { init(); @@ -549,24 +553,30 @@ void QQuickUniversalStyle::init() Color foregroundEnum = toEnumValue<Color>(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()) + if (color.isValid()) { GlobalForeground = m_foreground = color.rgba(); - else + HasGlobalForeground = m_hasForeground = true; + } else { qWarning().nospace().noquote() << "Universal: unknown foreground value: " << foregroundValue; + } } QByteArray backgroundValue = resolveSetting("QT_QUICK_CONTROLS_UNIVERSAL_BACKGROUND", settings, QStringLiteral("Background")); Color backgroundEnum = toEnumValue<Color>(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()) + if (color.isValid()) { GlobalBackground = m_background = color.rgba(); - else + HasGlobalBackground = m_hasBackground = true; + } else { qWarning().nospace().noquote() << "Universal: unknown background value: " << backgroundValue; + } } globalsInitialized = true; |