aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickabstractbutton.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@theqtcompany.com>2016-04-12 16:19:58 +0200
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-04-15 14:45:47 +0000
commiteae24fccc57437170e2ba01b894fa24fe65292be (patch)
treedfbd1450c237df8c2cd08838d2f054ef029ceea8 /src/quicktemplates2/qquickabstractbutton.cpp
parent0fe0283308199a6bf4a155627cddd524638c7063 (diff)
Add QQuickAbstractButton::down
This property will determine whether or not the button is visually pressed. Having such a distinction allows users more control over their controls. The patch also fixes the problem with ComboBox where pressing on the ComboBox when it's open would cause a delegate in the popup to show as being pressed. Unless explicitly set, this property follows the value of the pressed property. To return to the default value, set it to undefined. Change-Id: I29ecf325ed2ede125613f0c878b0427937599866 Task-number: QTBUG-51005 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/quicktemplates2/qquickabstractbutton.cpp')
-rw-r--r--src/quicktemplates2/qquickabstractbutton.cpp52
1 files changed, 50 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquickabstractbutton.cpp b/src/quicktemplates2/qquickabstractbutton.cpp
index fdcc6fc0..ec6b3d63 100644
--- a/src/quicktemplates2/qquickabstractbutton.cpp
+++ b/src/quicktemplates2/qquickabstractbutton.cpp
@@ -106,7 +106,8 @@ static const int AUTO_REPEAT_INTERVAL = 100;
*/
QQuickAbstractButtonPrivate::QQuickAbstractButtonPrivate() :
- pressed(false), checked(false), checkable(false), highlighted(false), autoExclusive(false), autoRepeat(false), wasHeld(false),
+ down(false), explicitDown(false), pressed(false), checked(false), checkable(false),
+ highlighted(false), autoExclusive(false), autoRepeat(false), wasHeld(false),
holdTimer(0), delayTimer(0), repeatTimer(0), repeatButton(Qt::NoButton), indicator(nullptr), group(nullptr)
{
}
@@ -256,9 +257,51 @@ void QQuickAbstractButton::setText(const QString &text)
}
/*!
+ \qmlproperty bool Qt.labs.controls::AbstractButton::down
+
+ This property holds whether the button is visually down.
+
+ Unless explicitly set, this property follows the value of \l pressed. To
+ return to the default value, set this property to \c undefined.
+
+ \sa pressed
+*/
+bool QQuickAbstractButton::isDown() const
+{
+ Q_D(const QQuickAbstractButton);
+ return d->down;
+}
+
+void QQuickAbstractButton::setDown(bool down)
+{
+ Q_D(QQuickAbstractButton);
+ d->explicitDown = true;
+
+ if (d->down == down)
+ return;
+
+ d->down = down;
+ emit downChanged();
+}
+
+void QQuickAbstractButton::resetDown()
+{
+ Q_D(QQuickAbstractButton);
+ if (!d->explicitDown)
+ return;
+
+ setDown(d->pressed);
+ d->explicitDown = false;
+}
+
+/*!
\qmlproperty bool Qt.labs.controls::AbstractButton::pressed
+ \readonly
- This property holds whether the button is pressed.
+ This property holds whether the button is physically pressed. A button can
+ be pressed by either touch or key events.
+
+ \sa down
*/
bool QQuickAbstractButton::isPressed() const
{
@@ -275,6 +318,11 @@ void QQuickAbstractButton::setPressed(bool isPressed)
d->pressed = isPressed;
setAccessibleProperty("pressed", isPressed);
emit pressedChanged();
+
+ if (!d->explicitDown) {
+ setDown(d->pressed);
+ d->explicitDown = false;
+ }
}
/*!