From 7b9c4db132d03a24b63d1fb9f3d85c82b63089db Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 20 Sep 2016 10:02:44 +0200 Subject: Switch/Delegate: improve dragging behavior Don't start dragging the handle unless the initial press was at the indicator, or the drag has reached the indicator area. This prevents unnatural jumps when dragging far outside the indicator. Change-Id: I2b31b319a347ab489f2de5c044e42d908827b425 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickswitchdelegate.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/quicktemplates2/qquickswitchdelegate.cpp') diff --git a/src/quicktemplates2/qquickswitchdelegate.cpp b/src/quicktemplates2/qquickswitchdelegate.cpp index e22d163a..62b677e5 100644 --- a/src/quicktemplates2/qquickswitchdelegate.cpp +++ b/src/quicktemplates2/qquickswitchdelegate.cpp @@ -153,8 +153,16 @@ void QQuickSwitchDelegate::mouseMoveEvent(QMouseEvent *event) QQuickItemDelegate::mouseMoveEvent(event); const QPointF movePoint = event->localPos(); - if (!keepMouseGrab()) - setKeepMouseGrab(QQuickWindowPrivate::dragOverThreshold(movePoint.x() - d->pressPoint.x(), Qt::XAxis, event)); + if (!keepMouseGrab()) { + // don't start dragging the handle unless the initial press was at the indicator, + // or the drag has reached the indicator area. this prevents unnatural jumps when + // dragging far outside the indicator. + const qreal pressPos = d->positionAt(d->pressPoint); + const qreal movePos = d->positionAt(movePoint); + if ((pressPos >= 0.0 && pressPos <= 1.0) || (movePos >= 0.0 && movePos <= 1.0)) + setKeepMouseGrab(QQuickWindowPrivate::dragOverThreshold(movePoint.x() - d->pressPoint.x(), Qt::XAxis, event)); + } + if (keepMouseGrab()) setPosition(d->positionAt(movePoint)); } -- cgit v1.2.3