diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-09-20 10:02:44 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-09-20 11:50:39 +0000 |
commit | 7b9c4db132d03a24b63d1fb9f3d85c82b63089db (patch) | |
tree | c4cf2a7b35cc328eb8990b8676e0612059b880ff /src/quicktemplates2/qquickswitchdelegate.cpp | |
parent | b3983692680a91023dc5f22608b4e84b46fae883 (diff) |
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 <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickswitchdelegate.cpp')
-rw-r--r-- | src/quicktemplates2/qquickswitchdelegate.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
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)); } |