diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-04-05 15:00:59 +0200 |
---|---|---|
committer | Jan Arve Sæther <jan-arve.saether@qt.io> | 2019-04-05 14:31:56 +0000 |
commit | 0c02691f7ba646e782b04347fde3d75f9582b317 (patch) | |
tree | dd8b7c690a86a03faaa0831dff934ee8629cc1dd /tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp | |
parent | aba6cea90e023c99ac55b0e8dcdeae0af8305ef2 (diff) | |
download | qtdeclarative-0c02691f7ba646e782b04347fde3d75f9582b317.tar.gz |
If DragHandler is dragged within its margin, don't jump
Not being pressed inside the target is a necessary but not sufficient
reason to reset m_pressTargetPos to the center of the target. The
intention was rather to make the target jump into position when the
parent was a different item: e.g. if a Slider has a DragHandler whose
target is the slider's knob, you can start dragging anywhere on the
whole Slider but you want the knob to jump to the cursor position when
the drag begins.
While we're at it, both branches of the if in onGrabChanged()
are checking that target() isn't null, so we can move that check out.
Fixes: QTBUG-74966
Change-Id: I05be11d27422b070d941b9e43d4e1157e071c3a5
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp')
-rw-r--r-- | tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp b/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp index eb210c2112..cc8c567e5c 100644 --- a/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp @@ -55,6 +55,7 @@ private slots: void defaultPropertyValues(); void touchDrag(); void mouseDrag(); + void dragFromMargin(); void touchDragMulti(); void touchDragMultiSliders_data(); void touchDragMultiSliders(); @@ -251,6 +252,38 @@ void tst_DragHandler::mouseDrag() QCOMPARE(centroidChangedSpy.count(), 5); } +void tst_DragHandler::dragFromMargin() // QTBUG-74966 +{ + const int dragThreshold = QGuiApplication::styleHints()->startDragDistance(); + QScopedPointer<QQuickView> windowPtr; + createView(windowPtr, "dragMargin.qml"); + QQuickView * window = windowPtr.data(); + + QQuickItem *draggableItem = window->rootObject()->childItems().first(); + QVERIFY(draggableItem); + QQuickDragHandler *dragHandler = draggableItem->findChild<QQuickDragHandler*>(); + QVERIFY(dragHandler); + + QPointF originalPos = draggableItem->position(); + QPointF scenePressPos = originalPos - QPointF(10, 0); + QPoint p1 = scenePressPos.toPoint(); + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, p1); + QVERIFY(!dragHandler->active()); + QCOMPARE(dragHandler->centroid().scenePosition(), scenePressPos); + QCOMPARE(dragHandler->centroid().scenePressPosition(), scenePressPos); + p1 += QPoint(dragThreshold * 2, 0); + QTest::mouseMove(window, p1); + QTRY_VERIFY(dragHandler->active()); + QCOMPARE(dragHandler->centroid().scenePressPosition(), scenePressPos); + QCOMPARE(dragHandler->centroid().sceneGrabPosition(), p1); + QCOMPARE(dragHandler->translation().x(), 0.0); // hmm that's odd + QCOMPARE(dragHandler->translation().y(), 0.0); + QCOMPARE(draggableItem->position(), originalPos + QPointF(dragThreshold * 2, 0)); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, p1); + QTRY_VERIFY(!dragHandler->active()); + QCOMPARE(dragHandler->centroid().pressedButtons(), Qt::NoButton); +} + void tst_DragHandler::touchDragMulti() { const int dragThreshold = QGuiApplication::styleHints()->startDragDistance(); |