From 935974e174d87f9bf10a56d14bb73ade726d827a Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 19 Sep 2016 15:19:40 +0200 Subject: Fix Switch to stay pressed as appropriate Switch is a special type of button that should stay pressed (similarly to Slider) even if the finger slips outside the bounds of the control. It was doing that only when dragged from the handle, not when dragged from the background. Change-Id: I462c66cfe2e67fc3c95215ffeafe3e5771174418 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickabstractbutton.cpp | 6 +++--- src/quicktemplates2/qquickabstractbutton_p_p.h | 1 + src/quicktemplates2/qquickswitch.cpp | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/quicktemplates2/qquickabstractbutton.cpp b/src/quicktemplates2/qquickabstractbutton.cpp index 220ec102..96adbf9a 100644 --- a/src/quicktemplates2/qquickabstractbutton.cpp +++ b/src/quicktemplates2/qquickabstractbutton.cpp @@ -105,7 +105,7 @@ static const int AUTO_REPEAT_INTERVAL = 100; */ QQuickAbstractButtonPrivate::QQuickAbstractButtonPrivate() : - down(false), explicitDown(false), pressed(false), checked(false), checkable(false), + down(false), explicitDown(false), pressed(false), keepPressed(false), checked(false), checkable(false), autoExclusive(false), autoRepeat(false), wasHeld(false), holdTimer(0), delayTimer(0), repeatTimer(0), repeatButton(Qt::NoButton), indicator(nullptr), group(nullptr) { @@ -525,7 +525,7 @@ void QQuickAbstractButton::mouseMoveEvent(QMouseEvent *event) { Q_D(QQuickAbstractButton); QQuickControl::mouseMoveEvent(event); - setPressed(contains(event->pos())); + setPressed(d->keepPressed || contains(event->pos())); if (d->autoRepeat) d->stopPressRepeat(); @@ -540,7 +540,7 @@ void QQuickAbstractButton::mouseReleaseEvent(QMouseEvent *event) bool wasPressed = d->pressed; setPressed(false); - if (contains(event->pos())) + if (d->keepPressed || contains(event->pos())) nextCheckState(); if (wasPressed) { diff --git a/src/quicktemplates2/qquickabstractbutton_p_p.h b/src/quicktemplates2/qquickabstractbutton_p_p.h index e690bbd0..8138a61d 100644 --- a/src/quicktemplates2/qquickabstractbutton_p_p.h +++ b/src/quicktemplates2/qquickabstractbutton_p_p.h @@ -82,6 +82,7 @@ public: bool down; bool explicitDown; bool pressed; + bool keepPressed; bool checked; bool checkable; bool autoExclusive; diff --git a/src/quicktemplates2/qquickswitch.cpp b/src/quicktemplates2/qquickswitch.cpp index 37ae53f0..7941bf69 100644 --- a/src/quicktemplates2/qquickswitch.cpp +++ b/src/quicktemplates2/qquickswitch.cpp @@ -184,6 +184,8 @@ bool QQuickSwitchPrivate::handleMouseUngrabEvent(QQuickItem *child) QQuickSwitch::QQuickSwitch(QQuickItem *parent) : QQuickAbstractButton(*(new QQuickSwitchPrivate), parent) { + Q_D(QQuickSwitch); + d->keepPressed = true; setCheckable(true); setFiltersChildMouseEvents(true); QObjectPrivate::connect(this, &QQuickAbstractButton::checkedChanged, d_func(), &QQuickSwitchPrivate::updatePosition); -- cgit v1.2.3