diff options
author | Filippo Cucchetto <f.cucchetto@asem.it> | 2016-04-14 10:48:25 +0200 |
---|---|---|
committer | Filippo Cucchetto <filippocucchetto@gmail.com> | 2016-04-19 16:12:17 +0000 |
commit | e1400b5b4d8311769ad3b9f631479ee2b0271197 (patch) | |
tree | 7ec3196d596f72c81aa48110d7977df83dfa3016 | |
parent | fc22938dfc7b4c09f76913ac62e1f8ba345eccaf (diff) |
Fixed MouseArea threshold with preventStealing
When preventStealing is true both keepMouseGrab() and
d->stealMouse are true. This in turn enable the dragging immediately
since the condition "keepMouseGrab() && d->stealMouse && !d->drag->active()"
is true.
Conversely when preventStealing is false the dragging is enabled in the
next move event since keepMouseGrab() and d->stealMouse are set true
inside the last "if" "!keepMouseGrab() && ...check threshold..".
This patch adds a new boolean flag for storing if we detected a drag motion
(so we exceeded the threshold) and enable the dragging iff this flag is true.
With this change:
- if preventStealing is true (and so keepMouseGrab() and d->stealMouse) the
additional d->overThresHold prevent the start of dragging. At the same time
the last if (!keepMouseGrab()) cannot be executed since keepMouseGrab is true
and we still check for the threshold being exceeded.
- if preventStealing is false, we still check for exceeding the threshold and
if this happen we enter in the last "if" since !keepMousegrab() && d->overThreshold
is true taking the mouseGrab as without this patch
Task-number: QTBUG-52534
Change-Id: I2b14d3048b6f8223c90ce5e2fd26e7ca706cb56a
Reviewed-by: Michael Brasser <michael.brasser@live.com>
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
-rw-r--r-- | src/quick/items/qquickmousearea.cpp | 21 | ||||
-rw-r--r-- | src/quick/items/qquickmousearea_p_p.h | 1 | ||||
-rw-r--r-- | tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp | 11 |
3 files changed, 25 insertions, 8 deletions
diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp index ef053abbd1..d66e55aa12 100644 --- a/src/quick/items/qquickmousearea.cpp +++ b/src/quick/items/qquickmousearea.cpp @@ -52,7 +52,7 @@ DEFINE_BOOL_CONFIG_OPTION(qmlVisualTouchDebugging, QML_VISUAL_TOUCH_DEBUGGING) QQuickMouseAreaPrivate::QQuickMouseAreaPrivate() : enabled(true), scrollGestureEnabled(true), hovered(false), longPress(false), moved(false), stealMouse(false), doubleClick(false), preventStealing(false), - propagateComposedEvents(false), pressed(0) + propagateComposedEvents(false), overThreshold(false), pressed(0) #ifndef QT_NO_DRAGANDDROP , drag(0) #endif @@ -715,7 +715,7 @@ void QQuickMouseArea::mouseMoveEvent(QMouseEvent *event) curLocalPos = event->windowPos(); } - if (keepMouseGrab() && d->stealMouse && !d->drag->active()) + if (keepMouseGrab() && d->stealMouse && d->overThreshold && !d->drag->active()) d->drag->setActive(true); QPointF startPos = d->drag->target()->parentItem() @@ -741,16 +741,19 @@ void QQuickMouseArea::mouseMoveEvent(QMouseEvent *event) if (d->drag->active()) d->drag->target()->setPosition(dragPos); - if (!keepMouseGrab() - && (QQuickWindowPrivate::dragOverThreshold(dragPos.x() - startPos.x(), Qt::XAxis, event, d->drag->threshold()) - || QQuickWindowPrivate::dragOverThreshold(dragPos.y() - startPos.y(), Qt::YAxis, event, d->drag->threshold()))) { - setKeepMouseGrab(true); - d->stealMouse = true; - + if (!d->overThreshold && (QQuickWindowPrivate::dragOverThreshold(dragPos.x() - startPos.x(), Qt::XAxis, event, d->drag->threshold()) + || QQuickWindowPrivate::dragOverThreshold(dragPos.y() - startPos.y(), Qt::YAxis, event, d->drag->threshold()))) + { + d->overThreshold = true; if (d->drag->smoothed()) d->startScene = event->windowPos(); } + if (!keepMouseGrab() && d->overThreshold) { + setKeepMouseGrab(true); + d->stealMouse = true; + } + d->moved = true; } #endif @@ -767,6 +770,7 @@ void QQuickMouseArea::mouseReleaseEvent(QMouseEvent *event) { Q_D(QQuickMouseArea); d->stealMouse = false; + d->overThreshold = false; if (!d->enabled && !d->pressed) { QQuickItem::mouseReleaseEvent(event); } else { @@ -875,6 +879,7 @@ void QQuickMouseArea::ungrabMouse() d->pressed = 0; d->stealMouse = false; d->doubleClick = false; + d->overThreshold = false; setKeepMouseGrab(false); #ifndef QT_NO_DRAGANDDROP diff --git a/src/quick/items/qquickmousearea_p_p.h b/src/quick/items/qquickmousearea_p_p.h index 014729b651..f63c5f6092 100644 --- a/src/quick/items/qquickmousearea_p_p.h +++ b/src/quick/items/qquickmousearea_p_p.h @@ -86,6 +86,7 @@ public: bool doubleClick : 1; bool preventStealing : 1; bool propagateComposedEvents : 1; + bool overThreshold : 1; Qt::MouseButtons pressed; #ifndef QT_NO_DRAGANDDROP QQuickDrag *drag; diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp index 82c053d76a..9cdfd21f9c 100644 --- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp +++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp @@ -79,6 +79,7 @@ private slots: void dragging_data() { acceptedButton_data(); } void dragging(); void dragSmoothed(); + void dragThreshold_data(); void dragThreshold(); void invalidDrag_data() { rejectedButton_data(); } void invalidDrag(); @@ -375,8 +376,17 @@ void tst_QQuickMouseArea::dragSmoothed() QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(100, 122)); } +void tst_QQuickMouseArea::dragThreshold_data() +{ + QTest::addColumn<bool>("preventStealing"); + QTest::newRow("without preventStealing") << false; + QTest::newRow("with preventStealing") << true; +} + void tst_QQuickMouseArea::dragThreshold() { + QFETCH(bool, preventStealing); + QQuickView window; QByteArray errorMessage; QVERIFY2(initView(window, testFileUrl("dragging.qml"), true, &errorMessage), errorMessage.constData()); @@ -386,6 +396,7 @@ void tst_QQuickMouseArea::dragThreshold() QVERIFY(window.rootObject() != 0); QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion"); + mouseRegion->setPreventStealing(preventStealing); QQuickDrag *drag = mouseRegion->drag(); drag->setThreshold(5); |