diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-04-28 15:35:35 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-04-28 14:34:01 +0000 |
commit | c3ddc2e8124b7b03279d6d3a1b76858cc7763af1 (patch) | |
tree | 6f0ba388651bd7273bb774b3b34700b182d90792 /tests/auto/drawer/tst_drawer.cpp | |
parent | b3370f3c5b3ec7993c5f5ff835714c9c7a42dd17 (diff) |
QQuickDrawer: fix flicking inside drawers
The pressPoint must be stored before rejecting a press event,
to be able to calculate correctly when to steal/grab move.
Change-Id: I4c9225fdaf730800fec30b3f37a2a0fe773e8b03
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/drawer/tst_drawer.cpp')
-rw-r--r-- | tests/auto/drawer/tst_drawer.cpp | 88 |
1 files changed, 66 insertions, 22 deletions
diff --git a/tests/auto/drawer/tst_drawer.cpp b/tests/auto/drawer/tst_drawer.cpp index 7fd4f0d9..eda00158 100644 --- a/tests/auto/drawer/tst_drawer.cpp +++ b/tests/auto/drawer/tst_drawer.cpp @@ -44,6 +44,7 @@ #include <QtGui/qguiapplication.h> #include <QtGui/qpa/qwindowsysteminterface.h> #include <QtQuick/private/qquickwindow_p.h> +#include <QtQuick/private/qquickflickable_p.h> #include <QtQuickTemplates2/private/qquickapplicationwindow_p.h> #include <QtQuickTemplates2/private/qquickoverlay_p.h> #include <QtQuickTemplates2/private/qquickpopup_p_p.h> @@ -89,6 +90,20 @@ private slots: void interactive_data(); void interactive(); + + void flicking(); + +private: + struct TouchDeviceDeleter + { + static inline void cleanup(QTouchDevice *device) + { + QWindowSystemInterface::unregisterTouchDevice(device); + delete device; + } + }; + + QScopedPointer<QTouchDevice, TouchDeviceDeleter> touchDevice; }; @@ -96,6 +111,10 @@ void tst_Drawer::initTestCase() { QQmlDataTest::initTestCase(); qputenv("QML_NO_TOUCH_COMPRESSION", "1"); + + touchDevice.reset(new QTouchDevice); + touchDevice->setType(QTouchDevice::TouchScreen); + QWindowSystemInterface::registerTouchDevice(touchDevice.data()); } void tst_Drawer::visible_data() @@ -749,36 +768,23 @@ void tst_Drawer::touch() QVERIFY(drawerOpenedSpy.isValid()); QVERIFY(drawerClosedSpy.isValid()); - struct TouchDeviceDeleter - { - static inline void cleanup(QTouchDevice *device) - { - QWindowSystemInterface::unregisterTouchDevice(device); - delete device; - } - }; - - QScopedPointer<QTouchDevice, TouchDeviceDeleter> device(new QTouchDevice); - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device.data()); - // drag to open - QTest::touchEvent(window, device.data()).press(0, QPoint(0, 100)); - QTest::touchEvent(window, device.data()).move(0, QPoint(50, 100)); - QTest::touchEvent(window, device.data()).move(0, QPoint(150, 100)); + QTest::touchEvent(window, touchDevice.data()).press(0, QPoint(0, 100)); + QTest::touchEvent(window, touchDevice.data()).move(0, QPoint(50, 100)); + QTest::touchEvent(window, touchDevice.data()).move(0, QPoint(150, 100)); QTRY_COMPARE(drawer->position(), 0.5); - QTest::touchEvent(window, device.data()).release(0, QPoint(150, 100)); + QTest::touchEvent(window, touchDevice.data()).release(0, QPoint(150, 100)); QVERIFY(drawerOpenedSpy.wait()); QCOMPARE(drawer->position(), 1.0); // drag to close - QTest::touchEvent(window, device.data()).press(0, QPoint(300, 100)); - QTest::touchEvent(window, device.data()).move(0, QPoint(300 - drawer->dragMargin(), 100)); + QTest::touchEvent(window, touchDevice.data()).press(0, QPoint(300, 100)); + QTest::touchEvent(window, touchDevice.data()).move(0, QPoint(300 - drawer->dragMargin(), 100)); for (int x = 300; x > 100; x -= 10) - QTest::touchEvent(window, device.data()).move(0, QPoint(x, 100)); - QTest::touchEvent(window, device.data()).move(0, QPoint(100, 100)); + QTest::touchEvent(window, touchDevice.data()).move(0, QPoint(x, 100)); + QTest::touchEvent(window, touchDevice.data()).move(0, QPoint(100, 100)); QTRY_COMPARE(drawer->position(), 0.5); - QTest::touchEvent(window, device.data()).release(0, QPoint(100, 100)); + QTest::touchEvent(window, touchDevice.data()).release(0, QPoint(100, 100)); QVERIFY(drawerClosedSpy.wait()); QCOMPARE(drawer->position(), 0.0); } @@ -873,6 +879,44 @@ void tst_Drawer::interactive() QCOMPARE(aboutToHideSpy.count(), 0); } +void tst_Drawer::flicking() +{ + QQuickApplicationHelper helper(this, QStringLiteral("flicking.qml")); + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickDrawer *drawer = window->property("drawer").value<QQuickDrawer *>(); + QVERIFY(drawer); + + QQuickFlickable *flickable = window->property("flickable").value<QQuickFlickable *>(); + QVERIFY(flickable); + + QSignalSpy drawerOpenedSpy(drawer, SIGNAL(opened())); + QVERIFY(drawerOpenedSpy.isValid()); + + drawer->open(); + QVERIFY(drawerOpenedSpy.wait()); + + // mouse + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(200, 200)); + for (int y = 200; y > 100; y -= 10) + QTest::mouseMove(window, QPoint(200, y), 1); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(200, 100)); + QVERIFY(flickable->isFlicking()); + + // reset + flickable->setContentY(0); + QVERIFY(!flickable->isFlicking()); + + // touch + QTest::touchEvent(window, touchDevice.data()).press(0, QPoint(200, 200)); + for (int y = 200; y > 100; y -= 10) + QTest::touchEvent(window, touchDevice.data()).move(0, QPoint(200, y)); + QTest::touchEvent(window, touchDevice.data()).release(0, QPoint(200, 100)); + QVERIFY(flickable->isFlicking()); +} + QTEST_MAIN(tst_Drawer) #include "tst_drawer.moc" |