diff options
Diffstat (limited to 'src/imports/controls')
14 files changed, 145 insertions, 83 deletions
diff --git a/src/imports/controls/ComboBox.qml b/src/imports/controls/ComboBox.qml index 1470ad7c..aeeabbb7 100644 --- a/src/imports/controls/ComboBox.qml +++ b/src/imports/controls/ComboBox.qml @@ -58,7 +58,7 @@ T.ComboBox { //! [delegate] delegate: ItemDelegate { - width: control.width + width: control.popup.width text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData font.weight: control.currentIndex === index ? Font.DemiBold : Font.Normal highlighted: control.highlightedIndex == index diff --git a/src/imports/controls/TabBar.qml b/src/imports/controls/TabBar.qml index 5fa81f38..2c3a665b 100644 --- a/src/imports/controls/TabBar.qml +++ b/src/imports/controls/TabBar.qml @@ -34,7 +34,7 @@ ** ****************************************************************************/ -import QtQuick 2.6 +import QtQuick 2.7 import QtQuick.Templates 2.1 as T T.TabBar { @@ -58,7 +58,13 @@ T.TabBar { spacing: control.spacing orientation: ListView.Horizontal boundsBehavior: Flickable.StopAtBounds + flickableDirection: Flickable.AutoFlickIfNeeded snapMode: ListView.SnapToItem + + highlightMoveDuration: 0 + highlightRangeMode: ListView.ApplyRange + preferredHighlightBegin: 40 + preferredHighlightEnd: width - 40 } //! [contentItem] diff --git a/src/imports/controls/doc/src/qtquickcontrols2-deployment.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-deployment.qdoc index 51a9b613..fe78ca55 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-deployment.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-deployment.qdoc @@ -30,7 +30,7 @@ \title Deploying Qt Quick Controls 2 Applications Deployment of Qt Quick Controls 2 applications is very similar to - deploment of other types of Qt applications. However, there are a few + deployment of other types of Qt applications. However, there are a few factors to consider. \section1 Deploying an Application with Several Styles diff --git a/src/imports/controls/doc/src/qtquickcontrols2-differences.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-differences.qdoc index e6fdcb10..bbdf7f89 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-differences.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-differences.qdoc @@ -115,7 +115,7 @@ \row \li Can be used on Desktop \li Yes - \li Yes \b * + \li Yes \row \li Can be used on Mobile \li Yes @@ -130,8 +130,6 @@ \li C++ \endtable - \b {* No hover effects} - \section2 Porting Qt Quick Controls Code The API of Qt Quick Controls 2 is very similar to Qt Quick Controls, but it @@ -262,6 +260,9 @@ \li \l [QML QtQuickControls] {MenuItem} \li \l [QML QtQuickControls2] {MenuItem} \row + \li \l [QML QtQuickControls] {MenuSeparator} + \li \l [QML QtQuickControls2] {MenuSeparator} + \row \li \mdash \li \l [QML QtQuickControls2] {Page} \row @@ -349,6 +350,9 @@ \li \l [QML QtQuickControls2] {ToolButton} \row \li \mdash + \li \l [QML QtQuickControls2] {ToolSeparator} + \row + \li \mdash \li \l [QML QtQuickControls2] {ToolTip} \row \li \l [QML QtQuickControls] {TreeView} diff --git a/src/imports/controls/doc/src/qtquickcontrols2-material.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-material.qdoc index 818ad7fd..74a7ece1 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-material.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-material.qdoc @@ -134,7 +134,8 @@ In addition to specifying the attributes in QML, it is also possible to specify them via environment variables or in a \l {qtquickcontrols2-conf} - {configuration file}. + {configuration file}. Attributes specified in QML take precedence over all + other methods. \section3 Environment Variables diff --git a/src/imports/controls/doc/src/qtquickcontrols2-universal.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-universal.qdoc index db1e2766..cb6ac17e 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-universal.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-universal.qdoc @@ -134,7 +134,8 @@ In addition to specifying the attributes in QML, it is also possible to specify them via environment variables or in a \l {qtquickcontrols2-conf} - {configuration file}. + {configuration file}. Attributes specified in QML take precedence over all + other methods. \section3 Environment Variables diff --git a/src/imports/controls/material/ComboBox.qml b/src/imports/controls/material/ComboBox.qml index c18a2624..a48c6884 100644 --- a/src/imports/controls/material/ComboBox.qml +++ b/src/imports/controls/material/ComboBox.qml @@ -62,7 +62,7 @@ T.ComboBox { Material.foreground: flat ? undefined : Material.foreground delegate: MenuItem { - width: control.width + width: control.popup.width text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData Material.foreground: control.currentIndex === index ? control.popup.Material.accent : control.popup.Material.foreground highlighted: control.highlightedIndex === index diff --git a/src/imports/controls/material/TabBar.qml b/src/imports/controls/material/TabBar.qml index 2b693809..5b2c8888 100644 --- a/src/imports/controls/material/TabBar.qml +++ b/src/imports/controls/material/TabBar.qml @@ -34,7 +34,7 @@ ** ****************************************************************************/ -import QtQuick 2.6 +import QtQuick 2.7 import QtQuick.Templates 2.1 as T import QtQuick.Controls.Material 2.1 import QtQuick.Controls.Material.impl 2.1 @@ -59,11 +59,16 @@ T.TabBar { spacing: control.spacing orientation: ListView.Horizontal boundsBehavior: Flickable.StopAtBounds + flickableDirection: Flickable.AutoFlickIfNeeded snapMode: ListView.SnapToItem highlightMoveDuration: 250 highlightResizeDuration: 0 highlightFollowsCurrentItem: true + highlightRangeMode: ListView.ApplyRange + preferredHighlightBegin: 48 + preferredHighlightEnd: width - 48 + highlight: Item { z: 2 Rectangle { diff --git a/src/imports/controls/material/qquickmaterialstyle.cpp b/src/imports/controls/material/qquickmaterialstyle.cpp index d71545b7..76332c51 100644 --- a/src/imports/controls/material/qquickmaterialstyle.cpp +++ b/src/imports/controls/material/qquickmaterialstyle.cpp @@ -369,15 +369,24 @@ static const QRgb colors[][14] = { } }; -static QQuickMaterialStyle::Theme defaultTheme = QQuickMaterialStyle::Light; -static uint defaultPrimary = QQuickMaterialStyle::Indigo; -static uint defaultAccent = QQuickMaterialStyle::Pink; -static uint defaultForeground = 0xDD000000; // primaryTextColorLight -static uint defaultBackground = 0xFFFAFAFA; // backgroundColorLight -static bool defaultPrimaryCustom = false; -static bool defaultAccentCustom = false; -static bool defaultForegroundCustom = true; -static bool defaultBackgroundCustom = true; +// If no value was inherited from a parent or explicitly set, the "global" values are used. +// The initial, default values of the globals are hard-coded here, but the environment +// variables and .conf file override them if specified. +static QQuickMaterialStyle::Theme globalTheme = QQuickMaterialStyle::Light; +static uint globalPrimary = QQuickMaterialStyle::Indigo; +static uint globalAccent = QQuickMaterialStyle::Pink; +static uint globalForeground = 0xDD000000; // primaryTextColorLight +static uint globalBackground = 0xFFFAFAFA; // backgroundColorLight +// 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; +// These represent whether or not the global color value was specified as one of the +// values that QColor accepts, as opposed to one of the pre-defined colors like Red. +static bool globalPrimaryCustom = false; +static bool globalAccentCustom = false; +static bool globalForegroundCustom = true; +static bool globalBackgroundCustom = true; static const QRgb backgroundColorLight = 0xFFFAFAFA; static const QRgb backgroundColorDark = 0xFF303030; @@ -421,17 +430,17 @@ QQuickMaterialStyle::QQuickMaterialStyle(QObject *parent) : QQuickStyleAttached( m_explicitAccent(false), m_explicitForeground(false), m_explicitBackground(false), - m_customPrimary(defaultPrimaryCustom), - m_customAccent(defaultAccentCustom), - m_customForeground(defaultForegroundCustom), - m_customBackground(defaultBackgroundCustom), - m_hasForeground(false), - m_hasBackground(false), - m_theme(defaultTheme), - m_primary(defaultPrimary), - m_accent(defaultAccent), - m_foreground(defaultForeground), - m_background(defaultBackground), + m_customPrimary(globalPrimaryCustom), + m_customAccent(globalAccentCustom), + m_customForeground(globalForegroundCustom), + m_customBackground(globalBackgroundCustom), + m_hasForeground(hasGlobalForeground), + m_hasBackground(hasGlobalBackground), + m_theme(globalTheme), + m_primary(globalPrimary), + m_accent(globalAccent), + m_foreground(globalForeground), + m_background(globalBackground), m_elevation(0) { init(); @@ -498,7 +507,7 @@ void QQuickMaterialStyle::resetTheme() m_explicitTheme = false; QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(parentStyle()); - inheritTheme(material ? material->theme() : defaultTheme); + inheritTheme(material ? material->theme() : globalTheme); } QVariant QQuickMaterialStyle::primary() const @@ -557,7 +566,7 @@ void QQuickMaterialStyle::resetPrimary() if (material) inheritPrimary(material->m_primary, material->m_customPrimary); else - inheritPrimary(defaultPrimary, false); + inheritPrimary(globalPrimary, false); } QVariant QQuickMaterialStyle::accent() const @@ -616,7 +625,7 @@ void QQuickMaterialStyle::resetAccent() if (material) inheritAccent(material->m_accent, material->m_customAccent); else - inheritAccent(defaultAccent, false); + inheritAccent(globalAccent, false); } QVariant QQuickMaterialStyle::foreground() const @@ -673,7 +682,7 @@ void QQuickMaterialStyle::resetForeground() m_customForeground = false; m_explicitForeground = false; QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(parentStyle()); - inheritForeground(material ? material->m_foreground : defaultForeground, true, material ? material->m_hasForeground : false); + inheritForeground(material ? material->m_foreground : globalForeground, true, material ? material->m_hasForeground : false); } QVariant QQuickMaterialStyle::background() const @@ -731,7 +740,7 @@ void QQuickMaterialStyle::resetBackground() m_customBackground = false; m_explicitBackground = false; QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(parentStyle()); - inheritBackground(material ? material->m_background : defaultBackground, true, material ? material->m_hasBackground : false); + inheritBackground(material ? material->m_background : globalBackground, true, material ? material->m_hasBackground : false); } int QQuickMaterialStyle::elevation() const @@ -1135,28 +1144,28 @@ static QByteArray resolveSetting(const QByteArray &env, const QSharedPointer<QSe void QQuickMaterialStyle::init() { - static bool defaultsInitialized = false; - if (!defaultsInitialized) { + static bool globalsInitialized = false; + if (!globalsInitialized) { QSharedPointer<QSettings> settings = QQuickStyleAttached::settings(QStringLiteral("Material")); bool ok = false; QByteArray themeValue = resolveSetting("QT_QUICK_CONTROLS_MATERIAL_THEME", settings, QStringLiteral("Theme")); Theme themeEnum = toEnumValue<Theme>(themeValue, &ok); if (ok) - defaultTheme = m_theme = effectiveTheme(themeEnum); + globalTheme = m_theme = effectiveTheme(themeEnum); else if (!themeValue.isEmpty()) qWarning().nospace().noquote() << "Material: unknown theme value: " << themeValue; QByteArray primaryValue = resolveSetting("QT_QUICK_CONTROLS_MATERIAL_PRIMARY", settings, QStringLiteral("Primary")); Color primaryEnum = toEnumValue<Color>(primaryValue, &ok); if (ok) { - defaultPrimaryCustom = m_customPrimary = false; - defaultPrimary = m_primary = primaryEnum; + globalPrimaryCustom = m_customPrimary = false; + globalPrimary = m_primary = primaryEnum; } else { QColor color(primaryValue.constData()); if (color.isValid()) { - defaultPrimaryCustom = m_customPrimary = true; - defaultPrimary = m_primary = color.rgba(); + globalPrimaryCustom = m_customPrimary = true; + globalPrimary = m_primary = color.rgba(); } else if (!primaryValue.isEmpty()) { qWarning().nospace().noquote() << "Material: unknown primary value: " << primaryValue; } @@ -1165,13 +1174,13 @@ void QQuickMaterialStyle::init() QByteArray accentValue = resolveSetting("QT_QUICK_CONTROLS_MATERIAL_ACCENT", settings, QStringLiteral("Accent")); Color accentEnum = toEnumValue<Color>(accentValue, &ok); if (ok) { - defaultAccentCustom = m_customAccent = false; - defaultAccent = m_accent = accentEnum; + globalAccentCustom = m_customAccent = false; + globalAccent = m_accent = accentEnum; } else if (!accentValue.isEmpty()) { QColor color(accentValue.constData()); if (color.isValid()) { - defaultAccentCustom = m_customAccent = true; - defaultAccent = m_accent = color.rgba(); + globalAccentCustom = m_customAccent = true; + globalAccent = m_accent = color.rgba(); } else { qWarning().nospace().noquote() << "Material: unknown accent value: " << accentValue; } @@ -1180,13 +1189,15 @@ void QQuickMaterialStyle::init() QByteArray foregroundValue = resolveSetting("QT_QUICK_CONTROLS_MATERIAL_FOREGROUND", settings, QStringLiteral("Foreground")); Color foregroundEnum = toEnumValue<Color>(foregroundValue, &ok); if (ok) { - defaultForegroundCustom = m_customForeground = false; - defaultForeground = m_foreground = foregroundEnum; + globalForegroundCustom = m_customForeground = false; + globalForeground = m_foreground = foregroundEnum; + hasGlobalForeground = m_hasForeground = true; } else if (!foregroundValue.isEmpty()) { QColor color(foregroundValue.constData()); if (color.isValid()) { - defaultForegroundCustom = m_customForeground = true; - defaultForeground = m_foreground = color.rgba(); + globalForegroundCustom = m_customForeground = true; + globalForeground = m_foreground = color.rgba(); + hasGlobalForeground = m_hasForeground = true; } else { qWarning().nospace().noquote() << "Material: unknown foreground value: " << foregroundValue; } @@ -1195,19 +1206,21 @@ void QQuickMaterialStyle::init() QByteArray backgroundValue = resolveSetting("QT_QUICK_CONTROLS_MATERIAL_BACKGROUND", settings, QStringLiteral("Background")); Color backgroundEnum = toEnumValue<Color>(backgroundValue, &ok); if (ok) { - defaultBackgroundCustom = m_customBackground = false; - defaultBackground = m_background = backgroundEnum; + globalBackgroundCustom = m_customBackground = false; + globalBackground = m_background = backgroundEnum; + hasGlobalBackground = m_hasBackground = true; } else if (!backgroundValue.isEmpty()) { QColor color(backgroundValue.constData()); if (color.isValid()) { - defaultBackgroundCustom = m_customBackground = true; - defaultBackground = m_background = color.rgba(); + globalBackgroundCustom = m_customBackground = true; + globalBackground = m_background = color.rgba(); + hasGlobalBackground = m_hasBackground = true; } else { qWarning().nospace().noquote() << "Material: unknown background value: " << backgroundValue; } } - defaultsInitialized = true; + globalsInitialized = true; } QQuickStyleAttached::init(); // TODO: lazy init? diff --git a/src/imports/controls/material/qquickmaterialstyle_p.h b/src/imports/controls/material/qquickmaterialstyle_p.h index d338e745..78ba88da 100644 --- a/src/imports/controls/material/qquickmaterialstyle_p.h +++ b/src/imports/controls/material/qquickmaterialstyle_p.h @@ -246,17 +246,27 @@ private: QColor buttonColor(bool highlighted) const; Shade themeShade() const; + // These reflect whether a color value was explicitly set on the specific + // item that this attached style object represents. bool m_explicitTheme; bool m_explicitPrimary; bool m_explicitAccent; bool m_explicitForeground; bool m_explicitBackground; + // These reflect whether the color value that was either inherited or + // explicitly set is in the form that QColor expects, rather than one of + // our pre-defined color enum values. bool m_customPrimary; bool m_customAccent; bool m_customForeground; bool m_customBackground; + // These will be true when this item has an explicit or inherited foreground/background + // color, or these colors were declared globally via settings (e.g. conf or env vars). + // Some color properties of the style will return different values depending on whether + // or not these are set. bool m_hasForeground; bool m_hasBackground; + // The actual values for this item, whether explicit, inherited or globally set. Theme m_theme; uint m_primary; uint m_accent; diff --git a/src/imports/controls/qtquickcontrols2plugin.cpp b/src/imports/controls/qtquickcontrols2plugin.cpp index 0844dbef..3cd3b8b2 100644 --- a/src/imports/controls/qtquickcontrols2plugin.cpp +++ b/src/imports/controls/qtquickcontrols2plugin.cpp @@ -41,6 +41,7 @@ #include <QtCore/private/qfileselector_p.h> #include <QtQuickControls2/qquickstyle.h> +#include <QtQuickControls2/private/qquickstyle_p.h> #include <QtQuickTemplates2/private/qquickabstractbutton_p.h> #include <QtQuickTemplates2/private/qquickbuttongroup_p.h> #include <QtQuickTemplates2/private/qquickcontainer_p.h> @@ -89,13 +90,14 @@ void QtQuickControls2Plugin::registerTypes(const char *uri) qmlRegisterType<QQuickContainer>(uri, 2, 0, "Container"); qmlRegisterType<QQuickControl>(uri, 2, 0, "Control"); - QQuickStyleSelector selector; - selector.setBaseUrl(typeUrl()); - + QQuickStylePrivate::init(typeUrl()); const QString style = QQuickStyle::name(); if (!style.isEmpty()) QFileSelectorPrivate::addStatics(QStringList() << style.toLower()); + QQuickStyleSelector selector; + selector.setBaseUrl(typeUrl()); + qmlRegisterType(selector.select(QStringLiteral("ApplicationWindow.qml")), uri, 2, 0, "ApplicationWindow"); qmlRegisterType(selector.select(QStringLiteral("BusyIndicator.qml")), uri, 2, 0, "BusyIndicator"); qmlRegisterType(selector.select(QStringLiteral("Button.qml")), uri, 2, 0, "Button"); diff --git a/src/imports/controls/universal/ComboBox.qml b/src/imports/controls/universal/ComboBox.qml index 0fe49520..e259d092 100644 --- a/src/imports/controls/universal/ComboBox.qml +++ b/src/imports/controls/universal/ComboBox.qml @@ -59,7 +59,7 @@ T.ComboBox { bottomPadding: padding - 5 delegate: ItemDelegate { - width: control.width + width: control.popup.width text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData highlighted: control.highlightedIndex === index hoverEnabled: control.hoverEnabled diff --git a/src/imports/controls/universal/qquickuniversalstyle.cpp b/src/imports/controls/universal/qquickuniversalstyle.cpp index 32c00de9..b33c27e8 100644 --- a/src/imports/controls/universal/qquickuniversalstyle.cpp +++ b/src/imports/controls/universal/qquickuniversalstyle.cpp @@ -141,15 +141,22 @@ static QQuickUniversalStyle::Theme qquickuniversal_effective_theme(QQuickUnivers return theme; } -static QQuickUniversalStyle::Theme DefaultTheme = QQuickUniversalStyle::Light; -static QRgb DefaultAccent = qquickuniversal_accent_color(QQuickUniversalStyle::Cobalt); -static QRgb DefaultForeground = qquickuniversal_light_color(QQuickUniversalStyle::BaseHigh); -static QRgb DefaultBackground = qquickuniversal_light_color(QQuickUniversalStyle::AltHigh); +// If no value was inherited from a parent or explicitly set, the "global" values are used. +// The initial, default values of the globals are hard-coded here, but the environment +// variables and .conf file override them if specified. +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(DefaultTheme), - m_accent(DefaultAccent), m_foreground(DefaultForeground), m_background(DefaultBackground) + m_hasForeground(HasGlobalForeground), m_hasBackground(HasGlobalBackground), m_theme(GlobalTheme), + m_accent(GlobalAccent), m_foreground(GlobalForeground), m_background(GlobalBackground) { init(); } @@ -209,7 +216,7 @@ void QQuickUniversalStyle::resetTheme() m_explicitTheme = false; QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(parentStyle()); - inheritTheme(universal ? universal->theme() : DefaultTheme); + inheritTheme(universal ? universal->theme() : GlobalTheme); } QVariant QQuickUniversalStyle::accent() const @@ -259,7 +266,7 @@ void QQuickUniversalStyle::resetAccent() m_explicitAccent = false; QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(parentStyle()); - inheritAccent(universal ? universal->m_accent : DefaultAccent); + inheritAccent(universal ? universal->m_accent : GlobalAccent); } QVariant QQuickUniversalStyle::foreground() const @@ -314,7 +321,7 @@ void QQuickUniversalStyle::resetForeground() m_hasForeground = false; m_explicitForeground = false; QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(parentStyle()); - inheritForeground(universal ? universal->m_foreground : DefaultForeground, universal ? universal->m_hasForeground : false); + inheritForeground(universal ? universal->m_foreground : GlobalForeground, universal ? universal->m_hasForeground : false); } QVariant QQuickUniversalStyle::background() const @@ -369,7 +376,7 @@ void QQuickUniversalStyle::resetBackground() m_hasBackground = false; m_explicitBackground = false; QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(parentStyle()); - inheritBackground(universal ? universal->m_background : DefaultBackground, universal ? universal->m_hasBackground : false); + inheritBackground(universal ? universal->m_background : GlobalBackground, universal ? universal->m_hasBackground : false); } QColor QQuickUniversalStyle::color(Color color) const @@ -531,26 +538,26 @@ static QByteArray resolveSetting(const QByteArray &env, const QSharedPointer<QSe void QQuickUniversalStyle::init() { - static bool defaultsInitialized = false; - if (!defaultsInitialized) { + static bool globalsInitialized = false; + if (!globalsInitialized) { QSharedPointer<QSettings> settings = QQuickStyleAttached::settings(QStringLiteral("Universal")); bool ok = false; QByteArray themeValue = resolveSetting("QT_QUICK_CONTROLS_UNIVERSAL_THEME", settings, QStringLiteral("Theme")); Theme themeEnum = toEnumValue<Theme>(themeValue, &ok); if (ok) - DefaultTheme = m_theme = qquickuniversal_effective_theme(themeEnum); + 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<Color>(accentValue, &ok); if (ok) { - DefaultAccent = m_accent = qquickuniversal_accent_color(accentEnum); + GlobalAccent = m_accent = qquickuniversal_accent_color(accentEnum); } else if (!accentValue.isEmpty()) { QColor color(accentValue.constData()); if (color.isValid()) - DefaultAccent = m_accent = color.rgba(); + GlobalAccent = m_accent = color.rgba(); else qWarning().nospace().noquote() << "Universal: unknown accent value: " << accentValue; } @@ -558,28 +565,34 @@ void QQuickUniversalStyle::init() QByteArray foregroundValue = resolveSetting("QT_QUICK_CONTROLS_UNIVERSAL_FOREGROUND", settings, QStringLiteral("Foreground")); Color foregroundEnum = toEnumValue<Color>(foregroundValue, &ok); if (ok) { - DefaultForeground = m_foreground = qquickuniversal_accent_color(foregroundEnum); + GlobalForeground = m_foreground = qquickuniversal_accent_color(foregroundEnum); + HasGlobalForeground = m_hasForeground = true; } else if (!foregroundValue.isEmpty()) { QColor color(foregroundValue.constData()); - if (color.isValid()) - DefaultForeground = m_foreground = color.rgba(); - else + if (color.isValid()) { + GlobalForeground = m_foreground = color.rgba(); + 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) { - DefaultBackground = m_background = qquickuniversal_accent_color(backgroundEnum); + GlobalBackground = m_background = qquickuniversal_accent_color(backgroundEnum); + HasGlobalBackground = m_hasBackground = true; } else if (!backgroundValue.isEmpty()) { QColor color(backgroundValue.constData()); - if (color.isValid()) - DefaultBackground = m_background = color.rgba(); - else + if (color.isValid()) { + GlobalBackground = m_background = color.rgba(); + HasGlobalBackground = m_hasBackground = true; + } else { qWarning().nospace().noquote() << "Universal: unknown background value: " << backgroundValue; + } } - defaultsInitialized = true; + globalsInitialized = true; } QQuickStyleAttached::init(); // TODO: lazy init? diff --git a/src/imports/controls/universal/qquickuniversalstyle_p.h b/src/imports/controls/universal/qquickuniversalstyle_p.h index 19c346c8..0d3a6dab 100644 --- a/src/imports/controls/universal/qquickuniversalstyle_p.h +++ b/src/imports/controls/universal/qquickuniversalstyle_p.h @@ -214,12 +214,19 @@ 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 + // item that this attached style object represents. bool m_explicitTheme; bool m_explicitAccent; bool m_explicitForeground; bool m_explicitBackground; + // These will be true when this item has an explicit or inherited foreground/background + // color, or these colors were declared globally via settings (e.g. conf or env vars). + // Some color properties of the style will return different values depending on whether + // or not these are set. bool m_hasForeground; bool m_hasBackground; + // The actual values for this item, whether explicit, inherited or globally set. QQuickUniversalStyle::Theme m_theme; QRgb m_accent; QRgb m_foreground; |