diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-05-11 11:01:33 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-14 05:36:33 +0200 |
commit | 15db94ac656b6c398756b3e0eb982183bb6036bb (patch) | |
tree | 9ca077e6d7aa94cc6ce20fd9789b19d188e43263 /tests/auto/quick/qquickmousearea | |
parent | d3ec26ea2e22d350a1adc58fbc6903a32c9dea3a (diff) |
Fix setting drag properties in mousePress.
Cache the dragX and dragY properties after the onPressed
signal has been emitted to allow for deferred creation of the drag
object or changes to the axis property in the handler.
Change-Id: If154e661359c82e957fcf0cbc11ccc1f75bee919
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto/quick/qquickmousearea')
-rw-r--r-- | tests/auto/quick/qquickmousearea/data/setDragOnPressed.qml | 18 | ||||
-rw-r--r-- | tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp | 49 |
2 files changed, 67 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickmousearea/data/setDragOnPressed.qml b/tests/auto/quick/qquickmousearea/data/setDragOnPressed.qml new file mode 100644 index 0000000000..fc57319d75 --- /dev/null +++ b/tests/auto/quick/qquickmousearea/data/setDragOnPressed.qml @@ -0,0 +1,18 @@ +import QtQuick 2.0 + +MouseArea { + width: 200; height: 200 + + Item { + id: dragTarget + objectName: "target" + x: 50; y: 50 + width: 100; height: 100 + } + + onPressed: { + drag.target = dragTarget + drag.axis = Drag.XAxis + } + onReleased: drag.target = null +} diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp index 476ce8144a..2457ba727a 100644 --- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp +++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp @@ -59,6 +59,7 @@ private slots: void dragProperties(); void resetDrag(); void dragging(); + void setDragOnPressed(); void updateMouseAreaPosOnClick(); void updateMouseAreaPosOnResize(); void noOnClickedWithPressAndHold(); @@ -255,6 +256,54 @@ void tst_QQuickMouseArea::dragging() delete canvas; } +void tst_QQuickMouseArea::setDragOnPressed() +{ + QQuickView *canvas = createView(); + + canvas->setSource(testFileUrl("setDragOnPressed.qml")); + canvas->show(); + canvas->requestActivateWindow(); + QTest::qWait(20); + QVERIFY(canvas->rootObject() != 0); + + QQuickMouseArea *mouseArea = qobject_cast<QQuickMouseArea *>(canvas->rootObject()); + QVERIFY(mouseArea); + + // target + QQuickItem *target = mouseArea->findChild<QQuickItem*>("target"); + QVERIFY(target); + + QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100)); + + QQuickDrag *drag = mouseArea->drag(); + QVERIFY(drag); + QVERIFY(!drag->active()); + + QCOMPARE(target->x(), 50.0); + QCOMPARE(target->y(), 50.0); + + // First move event triggers drag, second is acted upon. + // This is due to possibility of higher stacked area taking precedence. + + QTest::mouseMove(canvas, QPoint(111,102)); + QTest::qWait(50); + QTest::mouseMove(canvas, QPoint(122,122)); + QTest::qWait(50); + + QVERIFY(drag->active()); + QCOMPARE(target->x(), 72.0); + QCOMPARE(target->y(), 50.0); + + QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(122,122)); + QTest::qWait(50); + + QVERIFY(!drag->active()); + QCOMPARE(target->x(), 72.0); + QCOMPARE(target->y(), 50.0); + + delete canvas; +} + QQuickView *tst_QQuickMouseArea::createView() { QQuickView *canvas = new QQuickView(0); |