aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorOlivier JG <olivier.de.gaalon@kdab.com>2016-12-07 11:57:03 -0600
committerOlivier de Gaalon <olivier.de.gaalon@kdab.com>2016-12-16 18:28:44 +0000
commit17a1c12a4520c4ae756e7dd5c08b2386ef84673a (patch)
treebbad701738b98f890b9327c9c7ed6c3631fb39c6 /tests/auto
parent0e80d28aa5892d6bbb4d0017b1bc9a33489f4176 (diff)
Add pressAndHoldInterval to MouseArea
Introduce pressAndHoldInterval to allow setting the pressAndHold delay per-MouseArea. [ChangeLog][QtQml][MouseArea] Introduce pressAndHoldInterval property, which controls the elapsed time before pressAndHold is emitted. Task-Id: QTBUG-47662 Change-Id: Ic2173335033a6ed0d4b652333020f030de63a8e7 Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/quick/qquickmousearea/data/pressAndHold.qml12
-rw-r--r--tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp45
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickmousearea/data/pressAndHold.qml b/tests/auto/quick/qquickmousearea/data/pressAndHold.qml
new file mode 100644
index 0000000000..bde195965e
--- /dev/null
+++ b/tests/auto/quick/qquickmousearea/data/pressAndHold.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.9
+
+Item {
+ width: 100
+ height: 100
+
+ MouseArea {
+ id: mouseArea
+ objectName: "mouseArea"
+ anchors.fill: parent
+ }
+}
diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
index e1f903123b..c8351b9e18 100644
--- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
+++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
@@ -127,6 +127,8 @@ private slots:
void containsPress();
void ignoreBySource();
void notPressedAfterStolenGrab();
+ void pressAndHold_data();
+ void pressAndHold();
private:
int startDragDistance() const {
@@ -2098,6 +2100,49 @@ void tst_QQuickMouseArea::notPressedAfterStolenGrab()
QVERIFY(!ma->pressed());
}
+void tst_QQuickMouseArea::pressAndHold_data()
+{
+ QTest::addColumn<int>("pressAndHoldInterval");
+ QTest::addColumn<int>("waitTime");
+
+ QTest::newRow("default") << -1 << QGuiApplication::styleHints()->mousePressAndHoldInterval();
+ QTest::newRow("short") << 500 << 500;
+ QTest::newRow("long") << 1000 << 1000;
+}
+
+void tst_QQuickMouseArea::pressAndHold()
+{
+ QFETCH(int, pressAndHoldInterval);
+ QFETCH(int, waitTime);
+
+ QQuickView window;
+ QByteArray errorMessage;
+ QVERIFY2(initView(window, testFileUrl("pressAndHold.qml"), true, &errorMessage), errorMessage.constData());
+ window.show();
+ window.requestActivate();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+ QQuickItem *root = window.rootObject();
+ QVERIFY(root != 0);
+
+ QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea*>("mouseArea");
+ QVERIFY(mouseArea != 0);
+
+ QSignalSpy pressAndHoldSpy(mouseArea, &QQuickMouseArea::pressAndHold);
+
+ if (pressAndHoldInterval > -1)
+ mouseArea->setPressAndHoldInterval(pressAndHoldInterval);
+ else
+ mouseArea->resetPressAndHoldInterval();
+
+ QElapsedTimer t;
+ t.start();
+ QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(50, 50));
+ QVERIFY(pressAndHoldSpy.wait());
+ // should be off by no more than 20% of waitTime
+ QVERIFY(qAbs(t.elapsed() - waitTime) < (waitTime * 0.2));
+ QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(50, 50));
+}
+
QTEST_MAIN(tst_QQuickMouseArea)
#include "tst_qquickmousearea.moc"