From c69c1f32b0b42adb670c08653282a86cc411b239 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 16 Nov 2016 12:26:34 +0100 Subject: Restore AbstractButton::checkable In 7a8f055, we hid the checkable property from QQuickAbstractButton and exposed it only in QQuickButton and QQuickMenuItem. The reasoning was that QQuickCheckBox, QQuickRadioButton, QQuickSwitch and their delegate counterparts are inherently checkable, so having the checkable property available in QML didn't seem to make sense. While this still holds true, there are other factors to take into consideration. AbstractButton is meant to be a generic base class for all types of buttons, but the lack of a checkable property makes it unusable as a base class for custom QML-based checkable buttons. If we want to a hide the checkable property from CheckBox, RadioButton, and Switch to avoid having it popup in the auto-completion list, we can probably do it in a less disruptive way via tooling. [ChangeLog][Controls][AbstractButton] The checkable property has been made accessible from QML. Previously it was only exposed for Button and MenuItem, but it is now available for any AbstractButton to make it possible to create custom QML-based checkable buttons. Task-number: QTBUG-51554 Change-Id: I19e29fc87cd15811c43c9b9ebb29701d66cde72f Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickabstractbutton.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/quicktemplates2/qquickabstractbutton.cpp') diff --git a/src/quicktemplates2/qquickabstractbutton.cpp b/src/quicktemplates2/qquickabstractbutton.cpp index e7c34065..2615608f 100644 --- a/src/quicktemplates2/qquickabstractbutton.cpp +++ b/src/quicktemplates2/qquickabstractbutton.cpp @@ -330,6 +330,8 @@ void QQuickAbstractButton::setPressed(bool isPressed) \qmlproperty bool QtQuick.Controls::AbstractButton::checked This property holds whether the button is checked. + + \sa checkable */ bool QQuickAbstractButton::isChecked() const { @@ -352,11 +354,21 @@ void QQuickAbstractButton::setChecked(bool checked) emit checkedChanged(); } -// We define these in QQuickAbstractButton without exposing checkable as a -// property, and instead expose it as a property in QQuickButton. -// QQuickRadioButton, QQuickSwitch and QQuickCheckBox are checkable by default, -// but if we removed the checkable code from here, they'd each have to -// duplicate it. +/*! + \qmlproperty bool QtQuick.Controls::AbstractButton::checkable + + This property holds whether the button is checkable. + + A checkable button toggles between checked (on) and unchecked (off) when + the user clicks on it or presses the space bar while the button has active + focus. + + Setting \l checked to \c true forces this property to \c true. + + The default value is \c false. + + \sa checked +*/ bool QQuickAbstractButton::isCheckable() const { Q_D(const QQuickAbstractButton); @@ -372,6 +384,7 @@ void QQuickAbstractButton::setCheckable(bool checkable) d->checkable = checkable; setAccessibleProperty("checkable", checkable); checkableChange(); + emit checkableChanged(); } /*! -- cgit v1.2.3 From aa1a8444991aee671981a99d1e08c5e1cb02c94a Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 15 Nov 2016 14:41:34 +0100 Subject: QQuickAbstractButton: fix auto-repeat Don't cancel auto-repeat on the tiniest mouse/touch move, but keep repeating until moved outside the button. The test has been changed so that the exact amount of repeats does not matter, as long as it repeats. This is because waits are not reliable in a busy CI environment. Sometimes waits can take longer, timer events get queued, and we get an unexpected burst of repeats. Change-Id: Ic473e04c4d15a0826c8adf460c69507e64590d99 Task-number: QTBUG-57085 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickabstractbutton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/quicktemplates2/qquickabstractbutton.cpp') diff --git a/src/quicktemplates2/qquickabstractbutton.cpp b/src/quicktemplates2/qquickabstractbutton.cpp index d922cfb1..75854d04 100644 --- a/src/quicktemplates2/qquickabstractbutton.cpp +++ b/src/quicktemplates2/qquickabstractbutton.cpp @@ -527,7 +527,7 @@ void QQuickAbstractButton::mouseMoveEvent(QMouseEvent *event) QQuickControl::mouseMoveEvent(event); setPressed(d->keepPressed || contains(event->pos())); - if (d->autoRepeat) + if (!d->pressed && d->autoRepeat) d->stopPressRepeat(); else if (d->holdTimer > 0 && (!d->pressed || QLineF(d->pressPoint, event->localPos()).length() > QGuiApplication::styleHints()->startDragDistance())) d->stopPressAndHold(); -- cgit v1.2.3