aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickmousearea
diff options
context:
space:
mode:
authorJens Bache-Wiig <jens.bache-wiig@digia.com>2013-08-22 17:20:52 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-13 17:51:48 +0200
commit406d6d33a6c0c5f99dfa31e2eb681b1fefcd5fe0 (patch)
treec365e466a5ba74a29ab1bc1f51aab6f407d105b9 /tests/auto/quick/qquickmousearea
parentee6cc22ebd0ec236454bc2112fe5f82e31299143 (diff)
Expose drag threshold in MouseArea
In several cases such as for creating a Slider, it is useful to have a 0 pixel threshold in order to initiate a drag operation. We have previously hardcoded this to a platform dependent (usually 10 pixel) value for MouseArea. Note that we have no way of indicating the version/revision number in a grouped property for documentation at the moment. In addition we deliberately had to remove the REVISION from the property because it is blocked by QTBUG-33179. However, since this is not a user-creatable type it should not cause any issues in practice. This patch adds MouseArea.drag.threshold in order to improve on this. Change-Id: Ia4871e64fab39e30c4494f00be99ad38cdd630df Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'tests/auto/quick/qquickmousearea')
-rw-r--r--tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
index de1c12097b..0c0b51d9c2 100644
--- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
+++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
@@ -86,6 +86,7 @@ private slots:
void resetDrag();
void dragging_data() { acceptedButton_data(); }
void dragging();
+ void dragThreshold();
void invalidDrag_data() { rejectedButton_data(); }
void invalidDrag();
void setDragOnPressed();
@@ -235,6 +236,20 @@ void tst_QQuickMouseArea::dragProperties()
drag->setFilterChildren(true);
QCOMPARE(filterChildrenSpy.count(), 1);
+
+ // threshold
+ QCOMPARE(int(drag->threshold()), qApp->styleHints()->startDragDistance());
+ QSignalSpy thresholdSpy(drag, SIGNAL(thresholdChanged()));
+ drag->setThreshold(0.0);
+ QCOMPARE(drag->threshold(), 0.0);
+ QCOMPARE(thresholdSpy.count(), 1);
+ drag->setThreshold(99);
+ QCOMPARE(thresholdSpy.count(), 2);
+ drag->setThreshold(99);
+ QCOMPARE(thresholdSpy.count(), 2);
+ drag->resetThreshold();
+ QCOMPARE(int(drag->threshold()), qApp->styleHints()->startDragDistance());
+ QCOMPARE(thresholdSpy.count(), 3);
}
void tst_QQuickMouseArea::resetDrag()
@@ -318,6 +333,61 @@ void tst_QQuickMouseArea::dragging()
QCOMPARE(blackRect->y(), 61.0);
}
+
+void tst_QQuickMouseArea::dragThreshold()
+{
+ QQuickView window;
+ QByteArray errorMessage;
+ QVERIFY2(initView(window, testFileUrl("dragging.qml"), true, &errorMessage), errorMessage.constData());
+
+ window.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+ QVERIFY(window.rootObject() != 0);
+
+ QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
+ QQuickDrag *drag = mouseRegion->drag();
+
+ drag->setThreshold(5);
+
+ mouseRegion->setAcceptedButtons(Qt::LeftButton);
+ QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect");
+ QVERIFY(blackRect != 0);
+ QVERIFY(blackRect == drag->target());
+ QVERIFY(!drag->active());
+ QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100));
+ QVERIFY(!drag->active());
+ QCOMPARE(blackRect->x(), 50.0);
+ QCOMPARE(blackRect->y(), 50.0);
+ QTest::mouseMove(&window, QPoint(100, 102), 50);
+ QVERIFY(!drag->active());
+ QTest::mouseMove(&window, QPoint(100, 100), 50);
+ QVERIFY(!drag->active());
+ QTest::mouseMove(&window, QPoint(100, 104), 50);
+ QTest::mouseMove(&window, QPoint(100, 105), 50);
+ QVERIFY(!drag->active());
+ QTest::mouseMove(&window, QPoint(100, 106), 50);
+ QTest::mouseMove(&window, QPoint(100, 108), 50);
+ QVERIFY(drag->active());
+ QTest::mouseMove(&window, QPoint(100, 116), 50);
+ QTest::mouseMove(&window, QPoint(100, 122), 50);
+ QTRY_VERIFY(drag->active());
+ QTRY_COMPARE(blackRect->x(), 50.0);
+ QTRY_COMPARE(blackRect->y(), 66.0);
+ QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(122,122));
+ QTRY_VERIFY(!drag->active());
+
+ // Immediate drag threshold
+ drag->setThreshold(0);
+ QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100));
+ QTest::mouseMove(&window, QPoint(100, 122), 50);
+ QVERIFY(!drag->active());
+ QTest::mouseMove(&window, QPoint(100, 123), 50);
+ QVERIFY(drag->active());
+ QTest::mouseMove(&window, QPoint(100, 124), 50);
+ QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(100, 124));
+ QTRY_VERIFY(!drag->active());
+ drag->resetThreshold();
+}
void tst_QQuickMouseArea::invalidDrag()
{
QFETCH(Qt::MouseButtons, acceptedButtons);