aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/imports/controls/ComboBox.qml12
-rw-r--r--src/imports/controls/doc/snippets/screenshots/qtquickcontrols2-combobox-custom.qml4
-rw-r--r--src/imports/controls/material/ComboBox.qml6
-rw-r--r--src/imports/controls/universal/ComboBox.qml8
-rw-r--r--src/imports/templates/qtquicktemplates2plugin.cpp1
-rw-r--r--src/quickcontrols2/qquickstyle.cpp47
-rw-r--r--src/quickcontrols2/qquickstyle.h1
-rw-r--r--src/quickcontrols2/qquickstyle_p.h1
-rw-r--r--src/quicktemplates2/qquickcombobox.cpp94
-rw-r--r--src/quicktemplates2/qquickcombobox_p.h8
10 files changed, 154 insertions, 28 deletions
diff --git a/src/imports/controls/ComboBox.qml b/src/imports/controls/ComboBox.qml
index a4e0f784..4519838c 100644
--- a/src/imports/controls/ComboBox.qml
+++ b/src/imports/controls/ComboBox.qml
@@ -38,7 +38,7 @@ import QtQuick 2.8
import QtQuick.Window 2.2
import QtQuick.Controls 2.1
import QtQuick.Controls.impl 2.1
-import QtQuick.Templates 2.1 as T
+import QtQuick.Templates 2.2 as T
T.ComboBox {
id: control
@@ -54,7 +54,7 @@ T.ComboBox {
rightPadding: padding + (control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing)
delegate: ItemDelegate {
- width: control.popup.width
+ width: parent.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
@@ -90,7 +90,7 @@ T.ComboBox {
implicitHeight: 40
color: control.visualFocus ? (control.pressed ? Default.focusPressedColor : Default.focusLightColor) :
- (control.pressed || popup.visible ? Default.buttonPressedColor : Default.buttonColor)
+ (control.down ? Default.buttonPressedColor : Default.buttonColor)
border.color: Default.focusColor
border.width: control.visualFocus ? 2 : 0
visible: !control.flat || control.pressed
@@ -104,7 +104,6 @@ T.ComboBox {
bottomMargin: 6
contentItem: ListView {
- id: listview
clip: true
implicitHeight: contentHeight
model: control.popup.visible ? control.delegateModel : null
@@ -114,9 +113,8 @@ T.ComboBox {
Rectangle {
z: 10
- parent: listview
- width: listview.width
- height: listview.height
+ width: parent.width
+ height: parent.height
color: "transparent"
border.color: Default.frameLightColor
}
diff --git a/src/imports/controls/doc/snippets/screenshots/qtquickcontrols2-combobox-custom.qml b/src/imports/controls/doc/snippets/screenshots/qtquickcontrols2-combobox-custom.qml
index 12d56a56..f7d6792f 100644
--- a/src/imports/controls/doc/snippets/screenshots/qtquickcontrols2-combobox-custom.qml
+++ b/src/imports/controls/doc/snippets/screenshots/qtquickcontrols2-combobox-custom.qml
@@ -92,12 +92,12 @@ ComboBox {
popup: Popup {
y: control.height - 1
width: control.width
- implicitHeight: listview.contentHeight
+ implicitHeight: contentItem.implicitHeight
padding: 1
contentItem: ListView {
- id: listview
clip: true
+ implicitHeight: contentHeight
model: control.popup.visible ? control.delegateModel : null
currentIndex: control.highlightedIndex
diff --git a/src/imports/controls/material/ComboBox.qml b/src/imports/controls/material/ComboBox.qml
index aa96f946..fa287ac1 100644
--- a/src/imports/controls/material/ComboBox.qml
+++ b/src/imports/controls/material/ComboBox.qml
@@ -37,7 +37,7 @@
import QtQuick 2.8
import QtQuick.Window 2.2
import QtQuick.Controls 2.1
-import QtQuick.Templates 2.1 as T
+import QtQuick.Templates 2.2 as T
import QtQuick.Controls.Material 2.1
import QtQuick.Controls.Material.impl 2.1
@@ -60,9 +60,9 @@ T.ComboBox {
Material.foreground: flat ? undefined : Material.foreground
delegate: MenuItem {
- width: control.popup.width
+ width: parent.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
+ Material.foreground: control.currentIndex === index ? parent.Material.accent : parent.Material.foreground
highlighted: control.highlightedIndex === index
hoverEnabled: control.hoverEnabled
}
diff --git a/src/imports/controls/universal/ComboBox.qml b/src/imports/controls/universal/ComboBox.qml
index 536782c7..37e1997a 100644
--- a/src/imports/controls/universal/ComboBox.qml
+++ b/src/imports/controls/universal/ComboBox.qml
@@ -37,7 +37,7 @@
import QtQuick 2.8
import QtQuick.Window 2.2
import QtQuick.Controls 2.1
-import QtQuick.Templates 2.1 as T
+import QtQuick.Templates 2.2 as T
import QtQuick.Controls.Universal 2.1
T.ComboBox {
@@ -54,7 +54,7 @@ T.ComboBox {
rightPadding: padding + (control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing)
delegate: ItemDelegate {
- width: control.popup.width
+ width: parent.width
text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData
highlighted: control.highlightedIndex === index
hoverEnabled: control.hoverEnabled
@@ -90,10 +90,10 @@ T.ComboBox {
border.width: control.flat ? 0 : 2 // ComboBoxBorderThemeThickness
border.color: !control.enabled ? control.Universal.baseLowColor :
- control.pressed || popup.visible ? control.Universal.baseMediumLowColor :
+ control.down ? control.Universal.baseMediumLowColor :
control.hovered ? control.Universal.baseMediumColor : control.Universal.baseMediumLowColor
color: !control.enabled ? control.Universal.baseLowColor :
- control.pressed || popup.visible ? control.Universal.listMediumColor :
+ control.down ? control.Universal.listMediumColor :
control.flat && control.hovered ? control.Universal.listLowColor : control.Universal.altMediumLowColor
visible: !control.flat || control.pressed || control.hovered || control.visualFocus
diff --git a/src/imports/templates/qtquicktemplates2plugin.cpp b/src/imports/templates/qtquicktemplates2plugin.cpp
index b6385cb9..2f152d66 100644
--- a/src/imports/templates/qtquicktemplates2plugin.cpp
+++ b/src/imports/templates/qtquicktemplates2plugin.cpp
@@ -220,6 +220,7 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri)
qmlRegisterType<QQuickTumbler, 1>(uri, 2, 1, "Tumbler");
// QtQuick.Templates 2.2 (Qt 5.9)
+ qmlRegisterRevision<QQuickComboBox, 2>(uri, 2, 2);
qmlRegisterRevision<QQuickDial, 2>(uri, 2, 2);
qmlRegisterRevision<QQuickRangeSlider, 2>(uri, 2, 2);
qmlRegisterRevision<QQuickSlider, 2>(uri, 2, 2);
diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp
index f4fc1764..c8a3f19a 100644
--- a/src/quickcontrols2/qquickstyle.cpp
+++ b/src/quickcontrols2/qquickstyle.cpp
@@ -178,11 +178,9 @@ struct QQuickStyleSpec
if (QGuiApplication::instance()) {
if (!custom) {
- const QString targetPath = QStringLiteral("QtQuick/Controls.2");
- const QStringList importPaths = QQmlEngine().importPathList();
-
- for (const QString &importPath : importPaths) {
- QString stylePath = findStyle(importPath + QLatin1Char('/') + targetPath, style);
+ const QStringList stylePaths = QQuickStylePrivate::stylePaths();
+ for (const QString &path : stylePaths) {
+ QString stylePath = findStyle(path, style);
if (!stylePath.isEmpty()) {
style = stylePath;
resolved = true;
@@ -212,6 +210,20 @@ struct QQuickStyleSpec
Q_GLOBAL_STATIC(QQuickStyleSpec, styleSpec)
+QStringList QQuickStylePrivate::stylePaths()
+{
+ const QString targetPath = QStringLiteral("QtQuick/Controls.2");
+ const QStringList importPaths = QQmlEngine().importPathList();
+
+ QStringList paths;
+ for (const QString &importPath : importPaths) {
+ QDir dir(importPath);
+ if (dir.cd(targetPath))
+ paths += dir.absolutePath();
+ }
+ return paths;
+}
+
QString QQuickStylePrivate::fallbackStyle()
{
return styleSpec()->fallbackStyle;
@@ -307,4 +319,29 @@ void QQuickStyle::setFallbackStyle(const QString &style)
styleSpec()->setFallbackStyle(style, "QQuickStyle::setFallbackStyle()");
}
+/*!
+ \since 5.9
+ Returns the names of the available built-in styles.
+
+ \note The method must be called \b after creating an instance of QGuiApplication.
+*/
+QStringList QQuickStyle::availableStyles()
+{
+ QStringList styles;
+ if (!QGuiApplication::instance()) {
+ qWarning() << "ERROR: QQuickStyle::availableStyles() must be called after creating an instance of QGuiApplication.";
+ return styles;
+ }
+
+ const QStringList stylePaths = QQuickStylePrivate::stylePaths();
+ for (const QString &path : stylePaths) {
+ QDir dir(path);
+ styles += dir.entryList(QStringList(), QDir::Dirs | QDir::NoDotAndDotDot);
+ styles.removeAll(QStringLiteral("designer"));
+ }
+ styles.prepend(QStringLiteral("Default"));
+ styles.removeDuplicates();
+ return styles;
+}
+
QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickstyle.h b/src/quickcontrols2/qquickstyle.h
index d2e7faf1..4260411e 100644
--- a/src/quickcontrols2/qquickstyle.h
+++ b/src/quickcontrols2/qquickstyle.h
@@ -50,6 +50,7 @@ public:
static QString path();
static void setStyle(const QString &style);
static void setFallbackStyle(const QString &style);
+ static QStringList availableStyles();
};
QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickstyle_p.h b/src/quickcontrols2/qquickstyle_p.h
index cfe87fbb..a893d20a 100644
--- a/src/quickcontrols2/qquickstyle_p.h
+++ b/src/quickcontrols2/qquickstyle_p.h
@@ -56,6 +56,7 @@ QT_BEGIN_NAMESPACE
class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickStylePrivate
{
public:
+ static QStringList stylePaths();
static QString fallbackStyle();
static bool isCustomStyle();
static void init(const QUrl &baseUrl);
diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp
index a0fcbe8c..5f18fb40 100644
--- a/src/quicktemplates2/qquickcombobox.cpp
+++ b/src/quicktemplates2/qquickcombobox.cpp
@@ -170,14 +170,13 @@ class QQuickComboBoxPrivate : public QQuickControlPrivate
Q_DECLARE_PUBLIC(QQuickComboBox)
public:
- QQuickComboBoxPrivate() : flat(false), pressed(false), ownModel(false), hasDisplayText(false), hasCurrentIndex(false),
- highlightedIndex(-1), currentIndex(-1), delegateModel(nullptr),
- delegate(nullptr), indicator(nullptr), popup(nullptr) { }
+ QQuickComboBoxPrivate();
bool isPopupVisible() const;
void showPopup();
void hidePopup(bool accept);
void togglePopup(bool accept);
+ void popupVisibleChanged();
void itemClicked();
@@ -196,6 +195,8 @@ public:
void createDelegateModel();
bool flat;
+ bool down;
+ bool hasDown;
bool pressed;
bool ownModel;
bool hasDisplayText;
@@ -213,6 +214,23 @@ public:
QQuickPopup *popup;
};
+QQuickComboBoxPrivate::QQuickComboBoxPrivate()
+ : flat(false),
+ down(false),
+ hasDown(false),
+ pressed(false),
+ ownModel(false),
+ hasDisplayText(false),
+ hasCurrentIndex(false),
+ highlightedIndex(-1),
+ currentIndex(-1),
+ delegateModel(nullptr),
+ delegate(nullptr),
+ indicator(nullptr),
+ popup(nullptr)
+{
+}
+
bool QQuickComboBoxPrivate::isPopupVisible() const
{
return popup && popup->isVisible();
@@ -246,6 +264,16 @@ void QQuickComboBoxPrivate::togglePopup(bool accept)
showPopup();
}
+void QQuickComboBoxPrivate::popupVisibleChanged()
+{
+ Q_Q(QQuickComboBox);
+ updateHighlightedIndex();
+ if (!hasDown) {
+ q->setDown(pressed || isPopupVisible());
+ hasDown = false;
+ }
+}
+
void QQuickComboBoxPrivate::itemClicked()
{
Q_Q(QQuickComboBox);
@@ -258,6 +286,12 @@ void QQuickComboBoxPrivate::itemClicked()
void QQuickComboBoxPrivate::createdItem(int index, QObject *object)
{
+ QQuickItem *item = qobject_cast<QQuickItem *>(object);
+ if (popup && item && !item->parentItem()) {
+ item->setParentItem(popup->contentItem());
+ QQuickItemPrivate::get(item)->setCulled(true);
+ }
+
QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(object);
if (button) {
button->setFocusPolicy(Qt::NoFocus);
@@ -563,9 +597,52 @@ void QQuickComboBox::setFlat(bool flat)
}
/*!
+ \since QtQuick.Controls 2.2
+ \qmlproperty bool QtQuick.Controls::ComboBox::down
+
+ This property holds whether the combo box button is visually down.
+
+ Unless explicitly set, this property is \c true when either \c pressed
+ or \c popup.visible is \c true. To return to the default value, set this
+ property to \c undefined.
+
+ \sa pressed, popup
+*/
+bool QQuickComboBox::isDown() const
+{
+ Q_D(const QQuickComboBox);
+ return d->down;
+}
+
+void QQuickComboBox::setDown(bool down)
+{
+ Q_D(QQuickComboBox);
+ d->hasDown = true;
+
+ if (d->down == down)
+ return;
+
+ d->down = down;
+ emit downChanged();
+}
+
+void QQuickComboBox::resetDown()
+{
+ Q_D(QQuickComboBox);
+ if (!d->hasDown)
+ return;
+
+ setDown(d->pressed || d->isPopupVisible());
+ d->hasDown = false;
+}
+
+/*!
\qmlproperty bool QtQuick.Controls::ComboBox::pressed
- This property holds whether the combo box button is pressed.
+ This property holds whether the combo box button is physically pressed.
+ A button can be pressed by either touch or key events.
+
+ \sa down
*/
bool QQuickComboBox::isPressed() const
{
@@ -581,6 +658,11 @@ void QQuickComboBox::setPressed(bool pressed)
d->pressed = pressed;
emit pressedChanged();
+
+ if (!d->hasDown) {
+ setDown(d->pressed || d->isPopupVisible());
+ d->hasDown = false;
+ }
}
/*!
@@ -807,12 +889,12 @@ void QQuickComboBox::setPopup(QQuickPopup *popup)
return;
if (d->popup)
- QObjectPrivate::disconnect(d->popup, &QQuickPopup::visibleChanged, d, &QQuickComboBoxPrivate::updateHighlightedIndex);
+ QObjectPrivate::disconnect(d->popup, &QQuickPopup::visibleChanged, d, &QQuickComboBoxPrivate::popupVisibleChanged);
d->deleteDelegate(d->popup);
if (popup) {
QQuickPopupPrivate::get(popup)->allowVerticalFlip = true;
popup->setClosePolicy(QQuickPopup::CloseOnEscape | QQuickPopup::CloseOnPressOutsideParent);
- QObjectPrivate::connect(popup, &QQuickPopup::visibleChanged, d, &QQuickComboBoxPrivate::updateHighlightedIndex);
+ QObjectPrivate::connect(popup, &QQuickPopup::visibleChanged, d, &QQuickComboBoxPrivate::popupVisibleChanged);
}
d->popup = popup;
emit popupChanged();
diff --git a/src/quicktemplates2/qquickcombobox_p.h b/src/quicktemplates2/qquickcombobox_p.h
index 0e18a4d5..b1491ac5 100644
--- a/src/quicktemplates2/qquickcombobox_p.h
+++ b/src/quicktemplates2/qquickcombobox_p.h
@@ -63,7 +63,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickComboBox : public QQuickControl
Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged FINAL)
Q_PROPERTY(QQmlInstanceModel *delegateModel READ delegateModel NOTIFY delegateModelChanged FINAL)
Q_PROPERTY(bool flat READ isFlat WRITE setFlat NOTIFY flatChanged FINAL REVISION 1)
- Q_PROPERTY(bool pressed READ isPressed WRITE setPressed NOTIFY pressedChanged FINAL)
+ Q_PROPERTY(bool down READ isDown WRITE setDown RESET resetDown NOTIFY downChanged FINAL REVISION 2)
+ Q_PROPERTY(bool pressed READ isPressed WRITE setPressed NOTIFY pressedChanged FINAL) // ### Qt 6: should not be writable
Q_PROPERTY(int highlightedIndex READ highlightedIndex NOTIFY highlightedIndexChanged FINAL)
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL)
Q_PROPERTY(QString currentText READ currentText NOTIFY currentTextChanged FINAL)
@@ -86,6 +87,10 @@ public:
bool isFlat() const;
void setFlat(bool flat);
+ bool isDown() const;
+ void setDown(bool down);
+ void resetDown();
+
bool isPressed() const;
void setPressed(bool pressed);
@@ -124,6 +129,7 @@ Q_SIGNALS:
void modelChanged();
void delegateModelChanged();
Q_REVISION(1) void flatChanged();
+ Q_REVISION(2) void downChanged();
void pressedChanged();
void highlightedIndexChanged();
void currentIndexChanged();