aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickcombobox.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-11-04 12:54:38 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2016-11-09 11:43:49 +0000
commit372c5b44e5bc2730c3557cf56bffc5496ab020f3 (patch)
tree02ff1d36bdbd9bb6544fa5f21728dcfa5f9b404e /src/quicktemplates2/qquickcombobox.cpp
parentbefe5e0dca3b5af7ffa48b0f66794b083d43656f (diff)
Add QQuickComboBox::down
This allows us to replace all "control.pressed || popup.visible" expressions with "control.down", and takes us one step closer to deferred popop execution as mentioned in the previous commit. In order to be able to defer the popup execution, we must get rid of such explicit references to the popup. Change-Id: Ifa7ecf8201912d3ec1bca232e2cf600e3886715e Reviewed-by: J-P Nurmi <jpnurmi@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickcombobox.cpp')
-rw-r--r--src/quicktemplates2/qquickcombobox.cpp88
1 files changed, 82 insertions, 6 deletions
diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp
index 3aa67688..298a795f 100644
--- a/src/quicktemplates2/qquickcombobox.cpp
+++ b/src/quicktemplates2/qquickcombobox.cpp
@@ -165,14 +165,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();
@@ -187,6 +186,8 @@ public:
void createDelegateModel();
bool flat;
+ bool down;
+ bool hasDown;
bool pressed;
bool ownModel;
bool hasDisplayText;
@@ -204,6 +205,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();
@@ -237,6 +255,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);
@@ -484,9 +512,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
{
@@ -502,6 +573,11 @@ void QQuickComboBox::setPressed(bool pressed)
d->pressed = pressed;
emit pressedChanged();
+
+ if (!d->hasDown) {
+ setDown(d->pressed || d->isPopupVisible());
+ d->hasDown = false;
+ }
}
/*!
@@ -733,12 +809,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();