aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-09-19 15:19:40 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-09-19 16:36:55 +0000
commit935974e174d87f9bf10a56d14bb73ade726d827a (patch)
tree03bfc3f55da39c4c2202c9295a09623400bfdd77 /src
parentfbe806c544a45c83f091109e04fab5d86620183f (diff)
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 <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quicktemplates2/qquickabstractbutton.cpp6
-rw-r--r--src/quicktemplates2/qquickabstractbutton_p_p.h1
-rw-r--r--src/quicktemplates2/qquickswitch.cpp2
3 files changed, 6 insertions, 3 deletions
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);