diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-08-27 20:46:09 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-08-27 20:53:00 +0200 |
commit | df946a834f6c7d7b9513fb71dc2a93ff148d5a1f (patch) | |
tree | 215ffb3e3716db58360bcc1b09f36f49d5d2bf00 /src | |
parent | 2568869819863de6b1f303dfe470aedf38b841c3 (diff) | |
parent | 67f67f2cc6de160ddea4aa76afc56e86415ed99b (diff) |
Merge remote-tracking branch 'origin/5.8' into dev
Change-Id: I10fadb2673912436340b485d8a738e1ae65d629e
Diffstat (limited to 'src')
25 files changed, 292 insertions, 123 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; diff --git a/src/imports/platform/qquickplatformfiledialog.cpp b/src/imports/platform/qquickplatformfiledialog.cpp index 53f91b4c..6174fd99 100644 --- a/src/imports/platform/qquickplatformfiledialog.cpp +++ b/src/imports/platform/qquickplatformfiledialog.cpp @@ -308,6 +308,12 @@ void QQuickPlatformFileDialog::resetOptions() This property holds the filters that restrict the types of files that can be selected. + \code + FileDialog { + nameFilters: ["Text files (*.txt)", "HTML files (*.html *.htm)"] + } + \endcode + \note \b{*.*} is not a portable filter, because the historical assumption that the file extension determines the file type is not consistent on every operating system. It is possible to have a file with no dot in its name (for diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp index f432eded..bee837e9 100644 --- a/src/quickcontrols2/qquickstyle.cpp +++ b/src/quickcontrols2/qquickstyle.cpp @@ -35,6 +35,7 @@ ****************************************************************************/ #include "qquickstyle.h" +#include "qquickstyle_p.h" #include "qquickstyleattached_p.h" #include <QtCore/qdir.h> @@ -88,8 +89,6 @@ struct QQuickStyleSpec QString name() { - if (!resolved) - resolve(); return style.mid(style.lastIndexOf(QLatin1Char('/')) + 1); } @@ -110,7 +109,7 @@ struct QQuickStyleSpec resolve(); } - void resolve() + void resolve(const QUrl &baseUrl = QUrl()) { if (style.isEmpty()) style = QGuiApplicationPrivate::styleOverride; @@ -122,6 +121,13 @@ struct QQuickStyleSpec style = settings->value(QStringLiteral("Style")).toString(); } + if (baseUrl.isValid()) { + if (style.isEmpty()) + style = baseUrl.toString(QUrl::StripTrailingSlash) + QLatin1Char('/'); + else if (!style.contains(QLatin1Char('/'))) + style = baseUrl.toString(QUrl::StripTrailingSlash) + QLatin1Char('/') + style; + } + if (QGuiApplication::instance()) { if (!style.contains(QLatin1Char('/'))) { const QString targetPath = QStringLiteral("QtQuick/Controls.2"); @@ -158,6 +164,11 @@ struct QQuickStyleSpec Q_GLOBAL_STATIC(QQuickStyleSpec, styleSpec) +void QQuickStylePrivate::init(const QUrl &baseUrl) +{ + styleSpec()->resolve(baseUrl); +} + /*! Returns the name of the application style. diff --git a/src/quickcontrols2/qquickstyle_p.h b/src/quickcontrols2/qquickstyle_p.h new file mode 100644 index 00000000..594e71c8 --- /dev/null +++ b/src/quickcontrols2/qquickstyle_p.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKSTYLE_P_H +#define QQUICKSTYLE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qurl.h> +#include <QtQuickControls2/private/qtquickcontrols2global_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickStylePrivate +{ +public: + static void init(const QUrl &baseUrl); +}; + +QT_END_NAMESPACE + +#endif // QQUICKSTYLE_P_H diff --git a/src/quickcontrols2/qquickstyleplugin.cpp b/src/quickcontrols2/qquickstyleplugin.cpp index 7f6e1323..3a4a0952 100644 --- a/src/quickcontrols2/qquickstyleplugin.cpp +++ b/src/quickcontrols2/qquickstyleplugin.cpp @@ -60,6 +60,11 @@ void QQuickStylePlugin::initializeEngine(QQmlEngine *engine, const char *uri) Q_UNUSED(engine); Q_UNUSED(uri); + // make sure not to re-create the proxy theme if initializeEngine() + // is called multiple times, like in case of qml2puppet (QTBUG-54995) + if (!m_theme.isNull()) + return; + const QString style = name(); if (!style.isEmpty() && style.compare(QQuickStyle::name(), Qt::CaseInsensitive) == 0) { m_theme.reset(createTheme()); diff --git a/src/quickcontrols2/quickcontrols2.pri b/src/quickcontrols2/quickcontrols2.pri index a86c9d12..8e4e0046 100644 --- a/src/quickcontrols2/quickcontrols2.pri +++ b/src/quickcontrols2/quickcontrols2.pri @@ -2,6 +2,7 @@ HEADERS += \ $$PWD/qquickcolorimageprovider_p.h \ $$PWD/qquickproxytheme_p.h \ $$PWD/qquickstyle.h \ + $$PWD/qquickstyle_p.h \ $$PWD/qquickstyleattached_p.h \ $$PWD/qquickstyleplugin_p.h \ $$PWD/qquickstyleselector_p.h \ diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp index fbc871f7..e2e6c84e 100644 --- a/src/quicktemplates2/qquickdrawer.cpp +++ b/src/quicktemplates2/qquickdrawer.cpp @@ -43,7 +43,6 @@ #include <QtQuick/private/qquickwindow_p.h> #include <QtQuick/private/qquickanimation_p.h> #include <QtQuick/private/qquicktransition_p.h> -#include <QtQuick/private/qquickitemchangelistener_p.h> QT_BEGIN_NAMESPACE @@ -115,7 +114,7 @@ QT_BEGIN_NAMESPACE \sa SwipeView, {Customizing Drawer}, {Navigation Controls}, {Popup Controls} */ -class QQuickDrawerPrivate : public QQuickPopupPrivate, public QQuickItemChangeListener +class QQuickDrawerPrivate : public QQuickPopupPrivate { Q_DECLARE_PUBLIC(QQuickDrawer) @@ -329,7 +328,7 @@ bool QQuickDrawerPrivate::handleMouseReleaseEvent(QQuickItem *item, QMouseEvent static QList<QQuickStateAction> prepareTransition(QQuickDrawer *drawer, QQuickTransition *transition, qreal to) { QList<QQuickStateAction> actions; - if (!transition) + if (!transition || !QQuickPopupPrivate::get(drawer)->window) return actions; qmlExecuteDeferred(transition); diff --git a/src/quicktemplates2/qquickmenu.cpp b/src/quicktemplates2/qquickmenu.cpp index ca18111c..b8522668 100644 --- a/src/quicktemplates2/qquickmenu.cpp +++ b/src/quicktemplates2/qquickmenu.cpp @@ -196,6 +196,7 @@ void QQuickMenuPrivate::itemSiblingOrderChanged(QQuickItem *) void QQuickMenuPrivate::itemDestroyed(QQuickItem *item) { + QQuickPopupPrivate::itemDestroyed(item); int index = contentModel->indexOf(item, nullptr); if (index != -1) removeItem(index, item); diff --git a/src/quicktemplates2/qquickmenu_p_p.h b/src/quicktemplates2/qquickmenu_p_p.h index 4137112d..4ca3c379 100644 --- a/src/quicktemplates2/qquickmenu_p_p.h +++ b/src/quicktemplates2/qquickmenu_p_p.h @@ -50,7 +50,6 @@ #include <QtCore/qvector.h> #include <QtCore/qpointer.h> -#include <QtQuick/private/qquickitemchangelistener_p.h> #include <QtQuickTemplates2/private/qquickpopup_p_p.h> @@ -58,7 +57,7 @@ QT_BEGIN_NAMESPACE class QQmlObjectModel; -class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickMenuPrivate : public QQuickPopupPrivate, public QQuickItemChangeListener +class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickMenuPrivate : public QQuickPopupPrivate { Q_DECLARE_PUBLIC(QQuickMenu) diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp index 14810c98..414ba782 100644 --- a/src/quicktemplates2/qquickpopup.cpp +++ b/src/quicktemplates2/qquickpopup.cpp @@ -115,8 +115,7 @@ static const QQuickItemPrivate::ChangeTypes AncestorChangeTypes = QQuickItemPriv | QQuickItemPrivate::Children; static const QQuickItemPrivate::ChangeTypes ItemChangeTypes = QQuickItemPrivate::Geometry - | QQuickItemPrivate::Parent - | QQuickItemPrivate::Destroyed; + | QQuickItemPrivate::Parent; QQuickPopupPrivate::QQuickPopupPrivate() : QObjectPrivate() @@ -551,14 +550,11 @@ void QQuickPopupPositioner::itemChildRemoved(QQuickItem *item, QQuickItem *child removeAncestorListeners(item); } -void QQuickPopupPositioner::itemDestroyed(QQuickItem *item) +void QQuickPopupPrivate::itemDestroyed(QQuickItem *item) { - Q_ASSERT(m_parentItem == item); - - m_parentItem = nullptr; - m_popup->parentItem = nullptr; - QQuickItemPrivate::get(item)->removeItemChangeListener(this, ItemChangeTypes); - removeAncestorListeners(item->parentItem()); + Q_Q(QQuickPopup); + if (item == parentItem) + q->setParentItem(nullptr); } void QQuickPopupPrivate::reposition() @@ -728,7 +724,10 @@ void QQuickPopupTransitionManager::transitionEnter() state = Enter; popup->prepareEnterTransition(); - transition(popup->enterActions, popup->enter, popup->q_func()); + if (popup->window) + transition(popup->enterActions, popup->enter, popup->q_func()); + else + finished(); } void QQuickPopupTransitionManager::transitionExit() @@ -738,7 +737,10 @@ void QQuickPopupTransitionManager::transitionExit() state = Exit; popup->prepareExitTransition(); - transition(popup->exitActions, popup->exit, popup->q_func()); + if (popup->window) + transition(popup->exitActions, popup->exit, popup->q_func()); + else + finished(); } void QQuickPopupTransitionManager::finished() @@ -768,8 +770,7 @@ QQuickPopup::QQuickPopup(QQuickPopupPrivate &dd, QObject *parent) QQuickPopup::~QQuickPopup() { Q_D(QQuickPopup); - d->setWindow(nullptr); - d->positioner.setParentItem(nullptr); + setParentItem(nullptr); delete d->popupItem; } @@ -1463,17 +1464,23 @@ void QQuickPopup::setParentItem(QQuickItem *parent) if (d->parentItem == parent) return; - if (d->parentItem) + if (d->parentItem) { QObjectPrivate::disconnect(d->parentItem, &QQuickItem::windowChanged, d, &QQuickPopupPrivate::setWindow); + QQuickItemPrivate::get(d->parentItem)->removeItemChangeListener(d, QQuickItemPrivate::Destroyed); + } d->parentItem = parent; if (d->positioner.parentItem()) d->positioner.setParentItem(parent); if (parent) { QObjectPrivate::connect(parent, &QQuickItem::windowChanged, d, &QQuickPopupPrivate::setWindow); + QQuickItemPrivate::get(d->parentItem)->addItemChangeListener(d, QQuickItemPrivate::Destroyed); + QQuickControlPrivate *p = QQuickControlPrivate::get(d->popupItem); p->resolveFont(); if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(parent->window())) p->updateLocale(window->locale(), false); // explicit=false + } else { + close(); } d->setWindow(parent ? parent->window() : nullptr); emit parentChanged(); diff --git a/src/quicktemplates2/qquickpopup_p_p.h b/src/quicktemplates2/qquickpopup_p_p.h index 342fecaf..4478c555 100644 --- a/src/quicktemplates2/qquickpopup_p_p.h +++ b/src/quicktemplates2/qquickpopup_p_p.h @@ -133,10 +133,9 @@ public: void setParentItem(QQuickItem *parent); protected: - void itemGeometryChanged(QQuickItem *, QQuickGeometryChange, const QRectF &); - void itemParentChanged(QQuickItem *, QQuickItem *parent); - void itemChildRemoved(QQuickItem *, QQuickItem *child); - void itemDestroyed(QQuickItem *item); + void itemGeometryChanged(QQuickItem *, QQuickGeometryChange, const QRectF &) override; + void itemParentChanged(QQuickItem *, QQuickItem *parent) override; + void itemChildRemoved(QQuickItem *, QQuickItem *child) override; private: void removeAncestorListeners(QQuickItem *item); @@ -148,7 +147,7 @@ private: QQuickPopupPrivate *m_popup; }; -class QQuickPopupPrivate : public QObjectPrivate +class QQuickPopupPrivate : public QObjectPrivate, public QQuickItemChangeListener { Q_DECLARE_PUBLIC(QQuickPopup) @@ -177,6 +176,7 @@ public: void setBottomMargin(qreal value, bool reset = false); void setWindow(QQuickWindow *window); + void itemDestroyed(QQuickItem *item) override; bool focus; bool modal; diff --git a/src/quicktemplates2/qquicktooltip.cpp b/src/quicktemplates2/qquicktooltip.cpp index 6b51de95..e49d68a4 100644 --- a/src/quicktemplates2/qquicktooltip.cpp +++ b/src/quicktemplates2/qquicktooltip.cpp @@ -320,19 +320,27 @@ public: QQuickToolTip *QQuickToolTipAttachedPrivate::instance(bool create) const { - static QPointer<QQuickToolTip> tip; + QQmlEngine *engine = qmlEngine(parent); + if (!engine) + return nullptr; + + static const char *name = "_q_QQuickToolTip"; + + QQuickToolTip *tip = engine->property(name).value<QQuickToolTip *>(); if (!tip && create) { // TODO: a cleaner way to create the instance? QQml(Meta)Type? - QQmlContext *context = qmlContext(parent); - if (context) { - QQmlComponent component(context->engine()); - component.setData("import QtQuick.Controls 2.1; ToolTip { }", QUrl()); - - QObject *object = component.create(context); - tip = qobject_cast<QQuickToolTip *>(object); - if (!tip) - delete object; - } + QQmlComponent component(engine); + component.setData("import QtQuick.Controls 2.1; ToolTip { }", QUrl()); + + QObject *object = component.create(); + if (object) + object->setParent(engine); + + tip = qobject_cast<QQuickToolTip *>(object); + if (!tip) + delete object; + else + engine->setProperty(name, QVariant::fromValue(object)); } return tip; } @@ -366,8 +374,8 @@ void QQuickToolTipAttached::setText(const QString &text) d->text = text; emit textChanged(); - if (QQuickToolTip *tip = d->instance(true)) - tip->setText(text); + if (isVisible()) + d->instance(true)->setText(text); } /*! @@ -392,6 +400,9 @@ void QQuickToolTipAttached::setDelay(int delay) d->delay = delay; emit delayChanged(); + + if (isVisible()) + d->instance(true)->setDelay(delay); } /*! @@ -416,6 +427,9 @@ void QQuickToolTipAttached::setTimeout(int timeout) d->timeout = timeout; emit timeoutChanged(); + + if (isVisible()) + d->instance(true)->setTimeout(timeout); } /*! |