aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quick/qquickflickable/tst_qquickflickable.cpp')
-rw-r--r--tests/auto/quick/qquickflickable/tst_qquickflickable.cpp216
1 files changed, 137 insertions, 79 deletions
diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
index a9019683c3..4ce2b7e3c6 100644
--- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
+++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
@@ -177,6 +177,7 @@ private slots:
void wheel();
void trackpad();
void nestedTrackpad();
+ void nestedSameDirectionTrackpad();
void movingAndFlicking();
void movingAndFlicking_data();
void movingAndDragging();
@@ -228,12 +229,14 @@ private slots:
void touchCancel();
private:
- void flickWithTouch(QQuickWindow *window, const QPoint &from, const QPoint &to);
QPointingDevice *touchDevice = QTest::createTouchDevice();
const QPointingDevice *mouseDevice = new QPointingDevice(
"test mouse", 1000, QInputDevice::DeviceType::Mouse, QPointingDevice::PointerType::Generic,
QInputDevice::Capability::Position | QInputDevice::Capability::Hover | QInputDevice::Capability::Scroll,
1, 5, QString(), QPointingDeviceUniqueId(), this);
+ QScopedPointer<QPointingDevice> touchpad = QScopedPointer<QPointingDevice>(
+ QTest::createTouchDevice(QInputDevice::DeviceType::TouchPad,
+ QInputDevice::Capability::Position | QInputDevice::Capability::PixelScroll));
};
void tst_qquickflickable::initTestCase()
@@ -392,6 +395,7 @@ void tst_qquickflickable::boundsBehavior()
void tst_qquickflickable::rebound()
{
+ auto device = mouseDevice;
QScopedPointer<QQuickView> window(new QQuickView);
window->setSource(testFileUrl("rebound.qml"));
QTRY_COMPARE(window->status(), QQuickView::Ready);
@@ -415,7 +419,7 @@ void tst_qquickflickable::rebound()
QSignalSpy hMoveSpy(flickable, SIGNAL(movingHorizontallyChanged()));
// flick and test the transition is run
- flick(window.data(), QPoint(20,20), QPoint(120,120), 200);
+ QQuickTest::pointerFlick(device, window.data(), 0, QPoint(20,20), QPoint(120,120), 200);
QTRY_COMPARE(window->rootObject()->property("transitionsStarted").toInt(), 2);
QCOMPARE(hMoveSpy.size(), 1);
@@ -445,8 +449,8 @@ void tst_qquickflickable::rebound()
// flick and trigger the transition multiple times
// (moving signals are emitted as soon as the first transition starts)
- flick(window.data(), QPoint(20,20), QPoint(120,120), 50); // both x and y will bounce back
- flick(window.data(), QPoint(20,120), QPoint(120,20), 50); // only x will bounce back
+ QQuickTest::pointerFlick(device, window.data(), 0, QPoint(20,20), QPoint(120,120), 50); // both x and y will bounce back
+ QQuickTest::pointerFlick(device, window.data(), 0, QPoint(20,120), QPoint(120,20), 50); // only x will bounce back
QVERIFY(flickable->isMoving());
QTRY_VERIFY(window->rootObject()->property("transitionsStarted").toInt() >= 1);
@@ -475,7 +479,7 @@ void tst_qquickflickable::rebound()
// (i.e. moving but transition->running = false)
window->rootObject()->setProperty("transitionEnabled", false);
- flick(window.data(), QPoint(20,20), QPoint(120,120), 200);
+ QQuickTest::pointerFlick(device, window.data(), 0, QPoint(20,20), QPoint(120,120), 200);
QCOMPARE(window->rootObject()->property("transitionsStarted").toInt(), 0);
QCOMPARE(hMoveSpy.size(), 1);
QCOMPARE(vMoveSpy.size(), 1);
@@ -628,6 +632,7 @@ void tst_qquickflickable::pressDelay()
// QTBUG-17361
void tst_qquickflickable::nestedPressDelay()
{
+ auto device = mouseDevice;
QScopedPointer<QQuickView> window(new QQuickView);
window->setSource(testFileUrl("nestedPressDelay.qml"));
QTRY_COMPARE(window->status(), QQuickView::Ready);
@@ -643,7 +648,7 @@ void tst_qquickflickable::nestedPressDelay()
QQuickFlickable *inner = window->rootObject()->findChild<QQuickFlickable*>("innerFlickable");
QVERIFY(inner != nullptr);
- moveAndPress(window.data(), QPoint(150, 150));
+ QQuickTest::pointerMoveAndPress(device, window.data(), 0, QPoint(150, 150));
// the MouseArea is not pressed immediately
QVERIFY(!outer->property("pressed").toBool());
QVERIFY(!inner->property("pressed").toBool());
@@ -667,7 +672,7 @@ void tst_qquickflickable::nestedPressDelay()
QTRY_VERIFY(!inner->property("moving").toBool());
// Dragging inner Flickable should work
- moveAndPress(window.data(), QPoint(80, 150));
+ QQuickTest::pointerMoveAndPress(device, window.data(), 0, QPoint(80, 150));
// the MouseArea is not pressed immediately
QVERIFY(!outer->property("pressed").toBool());
QVERIFY(!inner->property("pressed").toBool());
@@ -687,7 +692,7 @@ void tst_qquickflickable::nestedPressDelay()
QTRY_VERIFY(!inner->property("moving").toBool());
// Dragging the MouseArea in the inner Flickable should move the inner Flickable
- moveAndPress(window.data(), QPoint(150, 150));
+ QQuickTest::pointerMoveAndPress(device, window.data(), 0, QPoint(150, 150));
// the MouseArea is not pressed immediately
QVERIFY(!outer->property("pressed").toBool());
@@ -708,6 +713,7 @@ void tst_qquickflickable::nestedPressDelay()
void tst_qquickflickable::filterReplayedPress()
{
+ auto device = mouseDevice;
QScopedPointer<QQuickView> window(new QQuickView);
window->setSource(testFileUrl("nestedPressDelay.qml"));
QTRY_COMPARE(window->status(), QQuickView::Ready);
@@ -726,7 +732,7 @@ void tst_qquickflickable::filterReplayedPress()
QQuickItem *filteringMouseArea = outer->findChild<QQuickItem *>("filteringMouseArea");
QVERIFY(filteringMouseArea);
- moveAndPress(window.data(), QPoint(150, 150));
+ QQuickTest::pointerMoveAndPress(device, window.data(), 0, QPoint(150, 150));
// the MouseArea filtering the Flickable is pressed immediately.
QCOMPARE(filteringMouseArea->property("pressed").toBool(), true);
@@ -751,6 +757,7 @@ void tst_qquickflickable::filterReplayedPress()
// QTBUG-37316
void tst_qquickflickable::nestedClickThenFlick()
{
+ auto device = mouseDevice;
QScopedPointer<QQuickView> window(new QQuickView);
window->setSource(testFileUrl("nestedClickThenFlick.qml"));
QTRY_COMPARE(window->status(), QQuickView::Ready);
@@ -766,7 +773,7 @@ void tst_qquickflickable::nestedClickThenFlick()
QQuickFlickable *inner = window->rootObject()->findChild<QQuickFlickable*>("innerFlickable");
QVERIFY(inner != nullptr);
- moveAndPress(window.data(), QPoint(150, 150));
+ QQuickTest::pointerMoveAndPress(device, window.data(), 0, QPoint(150, 150));
// the MouseArea is not pressed immediately
QVERIFY(!outer->property("pressed").toBool());
@@ -777,7 +784,7 @@ void tst_qquickflickable::nestedClickThenFlick()
QVERIFY(!outer->property("pressed").toBool());
// Dragging inner Flickable should work
- moveAndPress(window.data(), QPoint(80, 150));
+ QQuickTest::pointerMoveAndPress(device, window.data(), 0, QPoint(80, 150));
// the MouseArea is not pressed immediately
QVERIFY(!outer->property("pressed").toBool());
@@ -1030,7 +1037,7 @@ void tst_qquickflickable::nestedTrackpad()
for (int i = 0; i < 10 && qFuzzyIsNull(innerFlickable->contentX()); ++i) {
QWheelEvent event(pos, window.mapToGlobal(pos), QPoint(-10,4), QPoint(-20,8),
Qt::NoButton, Qt::NoModifier, i ? Qt::ScrollUpdate : Qt::ScrollBegin, false,
- Qt::MouseEventSynthesizedBySystem);
+ Qt::MouseEventSynthesizedBySystem, touchpad.get());
event.setAccepted(false);
event.setTimestamp(timestamp++);
QGuiApplication::sendEvent(&window, &event);
@@ -1040,7 +1047,7 @@ void tst_qquickflickable::nestedTrackpad()
{
QWheelEvent event(pos, window.mapToGlobal(pos), QPoint(0,0), QPoint(0,0),
Qt::NoButton, Qt::NoModifier, Qt::ScrollEnd, false,
- Qt::MouseEventSynthesizedBySystem);
+ Qt::MouseEventSynthesizedBySystem, touchpad.get());
event.setAccepted(false);
event.setTimestamp(timestamp++);
QGuiApplication::sendEvent(&window, &event);
@@ -1054,7 +1061,7 @@ void tst_qquickflickable::nestedTrackpad()
for (int i = 0; i < 10 && qFuzzyIsNull(innerFlickable->contentY()); ++i) {
QWheelEvent event(pos, window.mapToGlobal(pos), QPoint(4,-10), QPoint(8,-20),
Qt::NoButton, Qt::NoModifier, i ? Qt::ScrollUpdate : Qt::ScrollBegin, false,
- Qt::MouseEventSynthesizedBySystem);
+ Qt::MouseEventSynthesizedBySystem, touchpad.get());
event.setAccepted(false);
event.setTimestamp(timestamp++);
QGuiApplication::sendEvent(&window, &event);
@@ -1064,7 +1071,7 @@ void tst_qquickflickable::nestedTrackpad()
{
QWheelEvent event(pos, window.mapToGlobal(pos), QPoint(0,0), QPoint(0,0),
Qt::NoButton, Qt::NoModifier, Qt::ScrollEnd, false,
- Qt::MouseEventSynthesizedBySystem);
+ Qt::MouseEventSynthesizedBySystem, touchpad.get());
event.setAccepted(false);
event.setTimestamp(timestamp++);
QGuiApplication::sendEvent(&window, &event);
@@ -1072,6 +1079,50 @@ void tst_qquickflickable::nestedTrackpad()
QTRY_COMPARE(outerMoveEndSpy.size(), 1);
}
+void tst_qquickflickable::nestedSameDirectionTrackpad() // QTBUG-124478
+{
+ QQuickView window;
+ QVERIFY(QQuickTest::showView(window, testFileUrl("nestedSameDirection.qml")));
+ QQuickFlickable *rootFlickable = qmlobject_cast<QQuickFlickable *>(window.rootObject());
+ QVERIFY(rootFlickable);
+ QQuickFlickable *flickable1 = rootFlickable->findChild<QQuickFlickable *>("nested1");
+ QVERIFY(flickable1);
+ QQuickFlickable *flickable2 = rootFlickable->findChild<QQuickFlickable *>("nested2");
+ QVERIFY(flickable2);
+
+ QVERIFY(rootFlickable->isAtYBeginning());
+ const QPoint pixelDelta(0, -100);
+ const QPointF pos(50, 50);
+ const int interval = 20;
+ quint64 timestamp = 1000;
+
+ auto sendTrackpadScroll = [pixelDelta, pos, &timestamp, &window, this,
+ interval](Qt::ScrollPhase phase) {
+ QWheelEvent ev(pos, window.mapToGlobal(pos), pixelDelta, pixelDelta, Qt::NoButton,
+ Qt::NoModifier, phase, false, Qt::MouseEventSynthesizedBySystem,
+ touchpad.get());
+ ev.setTimestamp(timestamp);
+ QGuiApplication::sendEvent(&window, &ev);
+ timestamp += interval; // for next time
+ };
+
+ // Send enough pixelDelta wheel events for flickable1 to reach its end.
+ sendTrackpadScroll(Qt::ScrollBegin);
+
+ for (int i = 1; i < 50; ++i) {
+ if (lcTests().isDebugEnabled())
+ QTest::qWait(interval);
+ sendTrackpadScroll(Qt::ScrollUpdate);
+ }
+
+ // We expect that the rootFlickable has moved, due to receiving some of the
+ // wheel events that were sent after flickable1 reached its end.
+ // Then flickable2 began to move as well, after it got under the mouse position.
+ QTRY_VERIFY(flickable1->isAtYEnd());
+ QCOMPARE(rootFlickable->isAtYBeginning(), false);
+ QCOMPARE(flickable2->isAtYBeginning(), false);
+}
+
void tst_qquickflickable::movingAndFlicking_data()
{
QTest::addColumn<bool>("verticalEnabled");
@@ -1101,6 +1152,7 @@ void tst_qquickflickable::movingAndFlicking()
QFETCH(bool, horizontalEnabled);
QFETCH(QPoint, flickToWithoutSnapBack);
QFETCH(QPoint, flickToWithSnapBack);
+ auto device = mouseDevice;
const QPoint flickFrom(50, 200); // centre
@@ -1129,7 +1181,7 @@ void tst_qquickflickable::movingAndFlicking()
QSignalSpy flickEndSpy(flickable, SIGNAL(flickEnded()));
// do a flick that keeps the view within the bounds
- flick(window.data(), flickFrom, flickToWithoutSnapBack, 200);
+ QQuickTest::pointerFlick(device, window.data(), 0, flickFrom, flickToWithoutSnapBack, 200);
QTRY_VERIFY(flickable->isMoving());
QCOMPARE(flickable->isMovingHorizontally(), horizontalEnabled);
@@ -1188,7 +1240,7 @@ void tst_qquickflickable::movingAndFlicking()
flickable->setContentX(0);
flickable->setContentY(0);
QTRY_VERIFY(!flickable->isMoving());
- flick(window.data(), flickFrom, flickToWithSnapBack, 10);
+ QQuickTest::pointerFlick(device, window.data(), 0, flickFrom, flickToWithSnapBack, 10);
QTRY_VERIFY(flickable->isMoving());
QCOMPARE(flickable->isMovingHorizontally(), horizontalEnabled);
@@ -1264,6 +1316,7 @@ void tst_qquickflickable::movingAndDragging()
QFETCH(bool, horizontalEnabled);
QFETCH(QPoint, moveByWithoutSnapBack);
QFETCH(QPoint, moveByWithSnapBack);
+ auto device = mouseDevice;
const QPoint moveFrom(50, 200); // centre
@@ -1292,7 +1345,7 @@ void tst_qquickflickable::movingAndDragging()
QSignalSpy moveEndSpy(flickable, SIGNAL(movementEnded()));
// start the drag
- moveAndPress(window.data(), moveFrom);
+ QQuickTest::pointerMoveAndPress(device, window.data(), 0, moveFrom);
QTest::mouseMove(window.data(), moveFrom + moveByWithoutSnapBack);
QTest::mouseMove(window.data(), moveFrom + moveByWithoutSnapBack*2);
QTest::mouseMove(window.data(), moveFrom + moveByWithoutSnapBack*3);
@@ -1368,7 +1421,7 @@ void tst_qquickflickable::movingAndDragging()
flickable->setContentX(0);
flickable->setContentY(0);
QTRY_VERIFY(!flickable->isMoving());
- moveAndPress(window.data(), moveFrom);
+ QQuickTest::pointerMoveAndPress(device, window.data(), 0, moveFrom);
QTest::mouseMove(window.data(), moveFrom + moveByWithSnapBack);
QTest::mouseMove(window.data(), moveFrom + moveByWithSnapBack*2);
QTest::mouseMove(window.data(), moveFrom + moveByWithSnapBack*3);
@@ -1439,6 +1492,7 @@ void tst_qquickflickable::movingAndDragging()
void tst_qquickflickable::flickOnRelease()
{
+ auto device = mouseDevice;
QScopedPointer<QQuickView> window(new QQuickView);
window->setSource(testFileUrl("flickable03.qml"));
window->show();
@@ -1455,7 +1509,7 @@ void tst_qquickflickable::flickOnRelease()
// underlying drivers will hopefully provide a pre-calculated velocity
// (based on more data than what the UI gets), thus making this use case
// working even with small movements.
- moveAndPress(window.data(), QPoint(50, 300));
+ QQuickTest::pointerMoveAndPress(device, window.data(), 0, QPoint(50, 300));
QTest::mouseMove(window.data(), QPoint(50, 10), 10);
QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(50, 10), 10);
@@ -1470,6 +1524,7 @@ void tst_qquickflickable::flickOnRelease()
void tst_qquickflickable::pressWhileFlicking()
{
+ auto device = mouseDevice;
QScopedPointer<QQuickView> window(new QQuickView);
window->setSource(testFileUrl("flickable03.qml"));
QTRY_COMPARE(window->status(), QQuickView::Ready);
@@ -1493,7 +1548,7 @@ void tst_qquickflickable::pressWhileFlicking()
// flick then press while it is still moving
// flicking == false, moving == true;
- flick(window.data(), QPoint(20,190), QPoint(20, 50), 200);
+ QQuickTest::pointerFlick(device, window.data(), 0, QPoint(20,190), QPoint(20, 50), 200);
QVERIFY(flickable->verticalVelocity() > 0.0);
QTRY_VERIFY(flickable->isFlicking());
QVERIFY(flickable->isFlickingVertically());
@@ -1529,6 +1584,7 @@ void tst_qquickflickable::pressWhileFlicking()
void tst_qquickflickable::dragWhileFlicking()
{
+ auto device = mouseDevice;
QQuickView window;
QVERIFY(QQuickTest::showView(window, testFileUrl("flickable03.qml")));
@@ -1545,7 +1601,7 @@ void tst_qquickflickable::dragWhileFlicking()
QSignalSpy flickEndSpy(flickable, &QQuickFlickable::flickEnded);
// flick first, let it keep moving
- flick(&window, QPoint(20,190), QPoint(20, 50), 200);
+ QQuickTest::pointerFlick(device, &window, 0, QPoint(20,190), QPoint(20, 50), 200);
QVERIFY(flickable->verticalVelocity() > 0.0);
QTRY_VERIFY(flickable->isFlicking());
QVERIFY(flickable->isFlickingVertically());
@@ -1564,21 +1620,21 @@ void tst_qquickflickable::dragWhileFlicking()
// then drag slowly while it's still flicking and moving
const int dragStepDelay = 100;
- QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(20, 70));
+ QQuickTest::pointerPress(device, &window, 0, QPoint(20, 70), Qt::LeftButton, Qt::NoModifier, 500);
QTRY_COMPARE(flickable->isFlicking(), false);
QCOMPARE(flickable->isFlickingVertically(), false);
QVERIFY(flickable->isMoving());
QVERIFY(flickable->isMovingVertically());
for (int y = 70; y > 50; y -= 5) {
- QTest::mouseMove(&window, QPoint(20, y), dragStepDelay);
+ QQuickTest::pointerMove(device, &window, 0, QPoint(20, y), dragStepDelay);
QVERIFY(flickable->isMoving());
QVERIFY(flickable->isMovingVertically());
// Flickable's timeline is real-time, so spoofing timestamps isn't enough
QTest::qWait(dragStepDelay);
}
- QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(20, 50), dragStepDelay);
+ QQuickTest::pointerRelease(device, &window, 0, QPoint(20, 50), Qt::LeftButton, Qt::NoModifier, dragStepDelay);
QCOMPARE(flickable->isFlicking(), false);
QCOMPARE(flickable->isFlickingVertically(), false);
@@ -1597,6 +1653,7 @@ void tst_qquickflickable::dragWhileFlicking()
void tst_qquickflickable::disabled()
{
+ auto device = mouseDevice;
QScopedPointer<QQuickView> window(new QQuickView);
window->setSource(testFileUrl("disabled.qml"));
window->show();
@@ -1606,7 +1663,7 @@ void tst_qquickflickable::disabled()
QQuickFlickable *flick = window->rootObject()->findChild<QQuickFlickable*>("flickable");
QVERIFY(flick != nullptr);
- moveAndPress(window.data(), QPoint(50, 90));
+ QQuickTest::pointerMoveAndPress(device, window.data(), 0, QPoint(50, 90));
QTest::mouseMove(window.data(), QPoint(50, 80));
QTest::mouseMove(window.data(), QPoint(50, 70));
@@ -1617,7 +1674,7 @@ void tst_qquickflickable::disabled()
QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(50, 60));
// verify that mouse clicks on other elements still work (QTBUG-20584)
- moveAndPress(window.data(), QPoint(50, 10));
+ QQuickTest::pointerMoveAndPress(device, window.data(), 0, QPoint(50, 10));
QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(50, 10));
QTRY_VERIFY(window->rootObject()->property("clicked").toBool());
@@ -1625,6 +1682,7 @@ void tst_qquickflickable::disabled()
void tst_qquickflickable::flickVelocity()
{
+ auto device = mouseDevice;
QScopedPointer<QQuickView> window(new QQuickView);
window->setSource(testFileUrl("flickable03.qml"));
QTRY_COMPARE(window->status(), QQuickView::Ready);
@@ -1638,12 +1696,12 @@ void tst_qquickflickable::flickVelocity()
QVERIFY(flickable != nullptr);
// flick up
- flick(window.data(), QPoint(20,190), QPoint(20, 50), 200);
+ QQuickTest::pointerFlick(device, window.data(), 0, QPoint(20,190), QPoint(20, 50), 200);
QVERIFY(flickable->verticalVelocity() > 0.0);
QTRY_COMPARE(flickable->verticalVelocity(), 0.0);
// flick down
- flick(window.data(), QPoint(20,10), QPoint(20, 140), 200);
+ QQuickTest::pointerFlick(device, window.data(), 0, QPoint(20,10), QPoint(20, 140), 200);
QTRY_VERIFY(flickable->verticalVelocity() < 0.0);
QTRY_COMPARE(flickable->verticalVelocity(), 0.0);
@@ -1656,13 +1714,13 @@ void tst_qquickflickable::flickVelocity()
QQuickFlickablePrivate *fp = QQuickFlickablePrivate::get(flickable);
bool boosted = false;
for (int i = 0; i < 6; ++i) {
- flick(window.data(), QPoint(20,390), QPoint(20, 50), 100);
+ QQuickTest::pointerFlick(device, window.data(), 0, QPoint(20,390), QPoint(20, 50), 100);
boosted |= fp->flickBoost > 1.0;
}
QVERIFY(boosted);
// Flick in opposite direction -> boost cancelled.
- flick(window.data(), QPoint(20,10), QPoint(20, 340), 200);
+ QQuickTest::pointerFlick(device, window.data(), 0, QPoint(20,10), QPoint(20, 340), 200);
QTRY_VERIFY(flickable->verticalVelocity() < 0.0);
QCOMPARE(fp->flickBoost, 1.0);
}
@@ -1752,6 +1810,7 @@ void tst_qquickflickable::cancelOnHide()
void tst_qquickflickable::cancelOnMouseGrab()
{
+ auto device = mouseDevice;
QScopedPointer<QQuickView> window(new QQuickView);
window->setSource(testFileUrl("cancel.qml"));
QTRY_COMPARE(window->status(), QQuickView::Ready);
@@ -1764,7 +1823,7 @@ void tst_qquickflickable::cancelOnMouseGrab()
QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject());
QVERIFY(flickable != nullptr);
- moveAndPress(window.data(), QPoint(10, 10));
+ QQuickTest::pointerMoveAndPress(device, window.data(), 0, QPoint(10, 10));
// drag out of bounds
QTest::mouseMove(window.data(), QPoint(50, 50));
QTest::mouseMove(window.data(), QPoint(100, 100));
@@ -1788,11 +1847,12 @@ void tst_qquickflickable::cancelOnMouseGrab()
QTRY_VERIFY(!flickable->isMoving());
QTRY_VERIFY(!flickable->isDragging());
- moveAndRelease(window.data(), QPoint(50, 10));
+ QQuickTest::pointerMoveAndRelease(device, window.data(), 0, QPoint(50, 10));
}
void tst_qquickflickable::clickAndDragWhenTransformed()
{
+ auto device = mouseDevice;
QScopedPointer<QQuickView> view(new QQuickView);
view->setSource(testFileUrl("transformedFlickable.qml"));
QTRY_COMPARE(view->status(), QQuickView::Ready);
@@ -1806,12 +1866,12 @@ void tst_qquickflickable::clickAndDragWhenTransformed()
QVERIFY(flickable != nullptr);
// click outside child rect
- moveAndPress(view.data(), QPoint(190, 190));
+ QQuickTest::pointerMoveAndPress(device, view.data(), 0, QPoint(190, 190));
QTRY_COMPARE(flickable->property("itemPressed").toBool(), false);
QTest::mouseRelease(view.data(), Qt::LeftButton, Qt::NoModifier, QPoint(190, 190));
// click inside child rect
- moveAndPress(view.data(), QPoint(200, 200));
+ QQuickTest::pointerMoveAndPress(device, view.data(), 0, QPoint(200, 200));
QTRY_COMPARE(flickable->property("itemPressed").toBool(), true);
QTest::mouseRelease(view.data(), Qt::LeftButton, Qt::NoModifier, QPoint(200, 200));
@@ -1819,16 +1879,16 @@ void tst_qquickflickable::clickAndDragWhenTransformed()
const int threshold = qApp->styleHints()->startDragDistance() * flickable->parentItem()->scale();
// drag outside bounds
- moveAndPress(view.data(), QPoint(160, 160));
+ QQuickTest::pointerMoveAndPress(device, view.data(), 0, QPoint(160, 160));
QTest::qWait(10);
QTest::mouseMove(view.data(), QPoint(160 + threshold * 2, 160));
QTest::mouseMove(view.data(), QPoint(160 + threshold * 3, 160));
QCOMPARE(flickable->isDragging(), false);
QCOMPARE(flickable->property("itemPressed").toBool(), false);
- moveAndRelease(view.data(), QPoint(180, 160));
+ QQuickTest::pointerMoveAndRelease(device, view.data(), 0, QPoint(180, 160));
// drag inside bounds
- moveAndPress(view.data(), QPoint(200, 140));
+ QQuickTest::pointerMoveAndPress(device, view.data(), 0, QPoint(200, 140));
QCOMPARE(flickable->keepMouseGrab(), false);
QTest::qWait(10);
// Flickable should get interested in dragging when the drag is beyond the
@@ -1842,7 +1902,7 @@ void tst_qquickflickable::clickAndDragWhenTransformed()
QTest::mouseMove(view.data(), QPoint(200 + threshold * 2, 140));
QCOMPARE(flickable->isDragging(), true); // it grabs only during the second drag past the threshold
QCOMPARE(flickable->property("itemPressed").toBool(), false);
- moveAndRelease(view.data(), QPoint(220, 140));
+ QQuickTest::pointerMoveAndRelease(device, view.data(), 0, QPoint(220, 140));
}
void tst_qquickflickable::flickTwiceUsingTouches()
@@ -1860,7 +1920,8 @@ void tst_qquickflickable::flickTwiceUsingTouches()
QVERIFY(flickable != nullptr);
QCOMPARE(flickable->contentY(), 0.0f);
- flickWithTouch(window.data(), QPoint(100, 400), QPoint(100, 240));
+
+ QQuickTest::pointerFlick(touchDevice, window.data(), 1, QPoint(100, 400), QPoint(100, 240), 100);
qreal contentYAfterFirstFlick = flickable->contentY();
qDebug() << "contentYAfterFirstFlick " << contentYAfterFirstFlick;
@@ -1868,7 +1929,7 @@ void tst_qquickflickable::flickTwiceUsingTouches()
// Wait until view stops moving
QTRY_VERIFY(!flickable->isMoving());
- flickWithTouch(window.data(), QPoint(100, 400), QPoint(100, 240));
+ QQuickTest::pointerFlick(touchDevice, window.data(), 1, QPoint(100, 400), QPoint(100, 240), 100);
// In the original bug, that second flick would cause Flickable to halt immediately
qreal contentYAfterSecondFlick = flickable->contentY();
@@ -1876,20 +1937,6 @@ void tst_qquickflickable::flickTwiceUsingTouches()
QTRY_VERIFY(contentYAfterSecondFlick > (contentYAfterFirstFlick + 80.0f));
}
-void tst_qquickflickable::flickWithTouch(QQuickWindow *window, const QPoint &from, const QPoint &to)
-{
- QTest::touchEvent(window, touchDevice).press(0, from, window);
- QQuickTouchUtils::flush(window);
-
- QPoint diff = to - from;
- for (int i = 1; i <= 8; ++i) {
- QTest::touchEvent(window, touchDevice).move(0, from + i*diff/8, window);
- QQuickTouchUtils::flush(window);
- }
- QTest::touchEvent(window, touchDevice).release(0, to, window);
- QQuickTouchUtils::flush(window);
-}
-
void tst_qquickflickable::nestedStopAtBounds_data()
{
QTest::addColumn<bool>("transpose");
@@ -1927,6 +1974,7 @@ void tst_qquickflickable::nestedStopAtBounds()
QFETCH(bool, innerFiltering);
QFETCH(int, pressDelay);
QFETCH(bool, waitForPressDelay);
+ auto device = mouseDevice;
QQuickView view;
view.setSource(testFileUrl("nestedStopAtBounds.qml"));
@@ -1971,7 +2019,7 @@ void tst_qquickflickable::nestedStopAtBounds()
int &axis = transpose ? position.ry() : position.rx();
// drag toward the aligned boundary. Outer flickable dragged.
- moveAndPress(&view, position);
+ QQuickTest::pointerMoveAndPress(device, &view, 0, position);
if (waitForPressDelay) {
QVERIFY(innerFiltering); // pressed will never be true if the mouse area isn't enabled.
QTRY_VERIFY(mouseArea->pressed());
@@ -1997,7 +2045,7 @@ void tst_qquickflickable::nestedStopAtBounds()
outer->setContentY(50);
// drag away from the aligned boundary. Inner flickable dragged.
- moveAndPress(&view, position);
+ QQuickTest::pointerMoveAndPress(device, &view, 0, position);
axis += invert ? -threshold * 2 : threshold * 2;
QTest::mouseMove(&view, position);
axis += invert ? -threshold : threshold;
@@ -2020,7 +2068,7 @@ void tst_qquickflickable::nestedStopAtBounds()
inner->setContentHeight(inner->height() - margin);
// Drag inner with equal size and contentSize
- moveAndPress(&view, position);
+ QQuickTest::pointerMoveAndPress(device, &view, 0, position);
axis += invert ? -threshold * 2 : threshold * 2;
QTest::mouseMove(&view, position);
axis += invert ? -threshold : threshold;
@@ -2043,7 +2091,7 @@ void tst_qquickflickable::nestedStopAtBounds()
inner->setContentHeight(inner->height() - 100);
// Drag inner with size greater than contentSize
- moveAndPress(&view, position);
+ QQuickTest::pointerMoveAndPress(device, &view, 0, position);
axis += invert ? -threshold * 2 : threshold * 2;
QTest::mouseMove(&view, position);
axis += invert ? -threshold : threshold;
@@ -2081,6 +2129,7 @@ void tst_qquickflickable::stopAtBounds()
QFETCH(bool, transpose);
QFETCH(bool, invert);
QFETCH(bool, pixelAligned);
+ auto device = mouseDevice;
QQuickView view;
view.setSource(testFileUrl("stopAtBounds.qml"));
@@ -2107,7 +2156,7 @@ void tst_qquickflickable::stopAtBounds()
int &axis = transpose ? position.ry() : position.rx();
// drag away from the aligned boundary. View should not move
- moveAndPress(&view, position);
+ QQuickTest::pointerMoveAndPress(device, &view, 0, position);
QTest::qWait(10);
for (int i = 0; i < 3; ++i) {
axis += invert ? -threshold : threshold;
@@ -2167,9 +2216,9 @@ void tst_qquickflickable::stopAtBounds()
QSignalSpy flickSignal(flickable, SIGNAL(flickingChanged()));
if (invert)
- flick(&view, QPoint(20,20), QPoint(120,120), 100);
+ QQuickTest::pointerFlick(device, &view, 0, QPoint(20,20), QPoint(120,120), 100);
else
- flick(&view, QPoint(120,120), QPoint(20,20), 100);
+ QQuickTest::pointerFlick(device, &view, 0, QPoint(120,120), QPoint(20,20), 100);
QVERIFY(flickSignal.size() > 0);
if (transpose) {
@@ -2200,7 +2249,7 @@ void tst_qquickflickable::nestedMouseAreaUsingTouch()
QVERIFY(flickable != nullptr);
QCOMPARE(flickable->contentY(), 50.0f);
- flickWithTouch(window.data(), QPoint(100, 300), QPoint(100, 200));
+ QQuickTest::pointerFlick(touchDevice, window.data(), 1, QPoint(100, 300), QPoint(100, 200), 100);
// flickable should not have moved
QCOMPARE(flickable->contentY(), 50.0);
@@ -2225,7 +2274,7 @@ void tst_qquickflickable::nestedMouseAreaPropagateComposedEvents()
QVERIFY(flickable != nullptr);
QCOMPARE(flickable->contentY(), 50.0f);
- flickWithTouch(window.data(), QPoint(100, 300), QPoint(100, 200));
+ QQuickTest::pointerFlick(touchDevice, window.data(), 1, QPoint(100, 300), QPoint(100, 200), 100);
// flickable should have moved
QVERIFY(!qFuzzyCompare(flickable->contentY(), 50.0));
@@ -2293,6 +2342,7 @@ void tst_qquickflickable::nestedSliderUsingTouch()
// QTBUG-31328
void tst_qquickflickable::pressDelayWithLoader()
{
+ auto device = mouseDevice;
QScopedPointer<QQuickView> window(new QQuickView);
window->setSource(testFileUrl("pressDelayWithLoader.qml"));
QTRY_COMPARE(window->status(), QQuickView::Ready);
@@ -2303,7 +2353,7 @@ void tst_qquickflickable::pressDelayWithLoader()
QVERIFY(window->rootObject() != nullptr);
// do not crash
- moveAndPress(window.data(), QPoint(150, 150));
+ QQuickTest::pointerMoveAndPress(device, window.data(), 0, QPoint(150, 150));
QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(150, 150));
}
@@ -2389,6 +2439,7 @@ void tst_qquickflickable::ratios_smallContent()
// QTBUG-48018
void tst_qquickflickable::contentXYNotTruncatedToInt()
{
+ auto device = mouseDevice;
QScopedPointer<QQuickView> window(new QQuickView);
window->setSource(testFileUrl("contentXY.qml"));
QTRY_COMPARE(window->status(), QQuickView::Ready);
@@ -2401,7 +2452,7 @@ void tst_qquickflickable::contentXYNotTruncatedToInt()
QVERIFY(flickable);
flickable->setContentX(1e10);
- flick(window.data(), QPoint(200, 100), QPoint(100, 100), 50);
+ QQuickTest::pointerFlick(device, window.data(), 0, QPoint(200, 100), QPoint(100, 100), 50);
// make sure we are not clipped at 2^31
QVERIFY(flickable->contentX() > qreal(1e10));
@@ -2409,6 +2460,7 @@ void tst_qquickflickable::contentXYNotTruncatedToInt()
void tst_qquickflickable::keepGrab()
{
+ auto device = mouseDevice;
QScopedPointer<QQuickView> window(new QQuickView);
window->setSource(testFileUrl("keepGrab.qml"));
QTRY_COMPARE(window->status(), QQuickView::Ready);
@@ -2425,7 +2477,7 @@ void tst_qquickflickable::keepGrab()
ma->setPreventStealing(true);
QPoint pos(250, 250);
- moveAndPress(window.data(), pos);
+ QQuickTest::pointerMoveAndPress(device, window.data(), 0, pos);
for (int i = 0; i < 6; ++i) {
pos += QPoint(10, 10);
QTest::mouseMove(window.data(), pos);
@@ -2440,7 +2492,7 @@ void tst_qquickflickable::keepGrab()
ma->setPreventStealing(false);
pos = QPoint(250, 250);
- moveAndPress(window.data(), pos);
+ QQuickTest::pointerMoveAndPress(device, window.data(), 0, pos);
for (int i = 0; i < 6; ++i) {
pos += QPoint(10, 10);
QTest::mouseMove(window.data(), pos);
@@ -2460,6 +2512,7 @@ void tst_qquickflickable::overshoot()
QFETCH(QQuickFlickable::BoundsBehavior, boundsBehavior);
QFETCH(int, boundsMovement);
QFETCH(bool, pixelAligned);
+ auto device = mouseDevice;
QScopedPointer<QQuickView> window(new QQuickView);
window->setSource(testFileUrl("overshoot.qml"));
@@ -2516,7 +2569,7 @@ void tst_qquickflickable::overshoot()
QMetaObject::invokeMethod(flickable, "reset");
// flick past the beginning
- flick(window.data(), QPoint(10, 10), QPoint(50, 50), 50);
+ QQuickTest::pointerFlick(device, window.data(), 0, QPoint(10, 10), QPoint(50, 50), 50);
QTRY_VERIFY(!flickable->property("flicking").toBool());
if ((boundsMovement == QQuickFlickable::FollowBoundsBehavior) && (boundsBehavior & QQuickFlickable::OvershootBounds)) {
@@ -2585,7 +2638,7 @@ void tst_qquickflickable::overshoot()
QMetaObject::invokeMethod(flickable, "reset");
// flick past the end
- flick(window.data(), QPoint(50, 50), QPoint(10, 10), 50);
+ QQuickTest::pointerFlick(device, window.data(), 0, QPoint(50, 50), QPoint(10, 10), 50);
QTRY_VERIFY(!flickable->property("flicking").toBool());
if ((boundsMovement == QQuickFlickable::FollowBoundsBehavior) && (boundsBehavior & QQuickFlickable::OvershootBounds)) {
@@ -2728,6 +2781,7 @@ void tst_qquickflickable::synchronousDrag_data()
void tst_qquickflickable::synchronousDrag()
{
QFETCH(bool, synchronousDrag);
+ auto device = mouseDevice;
QScopedPointer<QQuickView> scopedWindow(new QQuickView);
QQuickView *window = scopedWindow.data();
@@ -2752,7 +2806,7 @@ void tst_qquickflickable::synchronousDrag()
QCOMPARE(flickable->contentY(), 0.0f);
// Drag via mouse
- moveAndPress(window, p1);
+ QQuickTest::pointerMoveAndPress(device, window, 0, p1);
QTest::mouseMove(window, p2);
QTest::mouseMove(window, p3);
QTest::mouseMove(window, p4);
@@ -2835,6 +2889,7 @@ void tst_qquickflickable::parallelTouch() // QTBUG-30840
void tst_qquickflickable::ignoreNonLeftMouseButtons() // QTBUG-96909
{
QFETCH(Qt::MouseButton, otherButton);
+ auto device = mouseDevice;
const int threshold = qApp->styleHints()->startDragDistance();
QQuickView view;
view.setSource(testFileUrl("dragon.qml"));
@@ -2845,30 +2900,30 @@ void tst_qquickflickable::ignoreNonLeftMouseButtons() // QTBUG-96909
// Drag with left button
QPoint p1(100, 100);
- moveAndPress(&view, p1);
+ QQuickTest::pointerMoveAndPress(device, &view, 0, p1);
for (int i = 0; i < 8; ++i) {
p1 -= QPoint(threshold, threshold);
- QTest::mouseMove(&view, p1, 50);
+ QQuickTest::pointerMove(device, &view, 0, p1, 50);
}
QVERIFY(flickable->isDragging());
QCOMPARE(dragSpy.size(), 1);
// Press other button too, then release left button: dragging changes to false
- QTest::mousePress(&view, otherButton);
- QTest::mouseRelease(&view, Qt::LeftButton);
+ QQuickTest::pointerPress(device, &view, 0, p1, otherButton);
+ QQuickTest::pointerRelease(device, &view, 0, p1, Qt::LeftButton);
QTRY_COMPARE(flickable->isDragging(), false);
QCOMPARE(dragSpy.size(), 2);
// Drag further with the other button held: Flickable ignores it
for (int i = 0; i < 8; ++i) {
p1 -= QPoint(threshold, threshold);
- QTest::mouseMove(&view, p1, 50);
+ QQuickTest::pointerMove(device, &view, 0, p1, 50);
}
QCOMPARE(flickable->isDragging(), false);
QCOMPARE(dragSpy.size(), 2);
// Release other button: nothing happens
- QTest::mouseRelease(&view, otherButton);
+ QQuickTest::pointerRelease(device, &view, 0, p1, otherButton);
QCOMPARE(dragSpy.size(), 2);
}
@@ -2937,6 +2992,7 @@ void tst_qquickflickable::flickWhenRotated() // QTBUG-99639
QFETCH(qreal, rootRotation);
QFETCH(qreal, flickableRotation);
QFETCH(qreal, scale);
+ auto device = mouseDevice;
QQuickView window;
QVERIFY(QQuickTest::showView(window, testFileUrl("rotatedFlickable.qml")));
@@ -2953,7 +3009,7 @@ void tst_qquickflickable::flickWhenRotated() // QTBUG-99639
// Flick in Y direction in Flickable's coordinate system and check how much it moved
const QPointF startPoint = flickable->mapToGlobal(QPoint(20, 180));
const QPointF endPoint = flickable->mapToGlobal(QPoint(20, 40));
- flick(&window, window.mapFromGlobal(startPoint).toPoint(), window.mapFromGlobal(endPoint).toPoint(), 100);
+ QQuickTest::pointerFlick(device, &window, 0, window.mapFromGlobal(startPoint).toPoint(), window.mapFromGlobal(endPoint).toPoint(), 100);
QTRY_VERIFY(flickable->isMoving());
QTRY_VERIFY(!flickable->isMoving());
qCDebug(lcTests) << "flicking from" << startPoint << "to" << endPoint << ": ended at contentY" << flickable->contentY();
@@ -3098,6 +3154,8 @@ void tst_qquickflickable::setContentPositionWhileDragging() // QTBUG-104966
QFETCH(bool, isHorizontal);
QFETCH(int, newPos);
QFETCH(int, newExtent);
+ auto device = mouseDevice;
+
QQuickView window;
QVERIFY(QQuickTest::showView(window, testFileUrl("contentPosWhileDragging.qml")));
QQuickViewTestUtils::centerOnScreen(&window);
@@ -3118,7 +3176,7 @@ void tst_qquickflickable::setContentPositionWhileDragging() // QTBUG-104966
// Drag the mouse until we have surpassed the mouse drag threshold and a drag is initiated
// by checking for flickable->isDragging()
QPoint pos = flickableCenterPos;
- QQuickViewTestUtils::moveAndPress(&window, pos);
+ QQuickTest::pointerMoveAndPress(device, &window, 0, pos);
int j = 1;
QVERIFY(!flickable->isDragging());
while (!flickable->isDragging()) {