diff options
author | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2011-12-08 12:46:47 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-09 21:23:00 +0100 |
commit | 99cf198b2b459333099e19ca777a563b96614a85 (patch) | |
tree | b4169762ff30c5ada7d9272c9b92cd334c279a82 /tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp | |
parent | 5456784005655ec9277832f0a07beda4e3d0a55f (diff) |
Set target and device for touch events.
The QWidget dependency is being removed from QTouchEvent and therefore
widget() will be removed. There will be QObject *target() instead.
deviceType() has been deprecated and is replaced by QTouchDevice
*device().
Change-Id: Ic07b2c620fbfc1ae2e5eff85c8fc7269c7d5e2a8
Reviewed-by: Laszlo Agocs <laszlo.p.agocs@nokia.com>
Diffstat (limited to 'tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp')
-rw-r--r-- | tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp | 58 |
1 files changed, 27 insertions, 31 deletions
diff --git a/tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp b/tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp index 60522b7d44..f8e3596683 100644 --- a/tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp +++ b/tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp @@ -73,18 +73,6 @@ static QTouchEvent::TouchPoint makeTouchPoint(QQuickItem *item, const QPointF &p return tp; } -static TouchEventData makeTouchData(QEvent::Type type, QWidget *w, Qt::TouchPointStates states, const QList<QTouchEvent::TouchPoint> &touchPoints) -{ - TouchEventData d = { type, w, 0, states, touchPoints }; - return d; -} - -static TouchEventData makeTouchData(QEvent::Type type, QWidget *w, Qt::TouchPointStates states, const QTouchEvent::TouchPoint &touchPoint) -{ - QList<QTouchEvent::TouchPoint> points; - points << touchPoint; - return makeTouchData(type, w, states, points); -} static TouchEventData makeTouchData(QEvent::Type type, QWindow *w, Qt::TouchPointStates states, const QList<QTouchEvent::TouchPoint>& touchPoints) { TouchEventData d = { type, 0, w, states, touchPoints }; @@ -148,7 +136,7 @@ protected: event->ignore(); return; } - lastEvent = makeTouchData(event->type(), event->widget(), event->touchPointStates(), event->touchPoints()); + lastEvent = makeTouchData(event->type(), event->window(), event->touchPointStates(), event->touchPoints()); event->accept(); } @@ -255,8 +243,12 @@ void tst_qquickcanvas::touchEvent_basic() QPointF pos(10, 10); + QTouchDevice *device = new QTouchDevice; + device->setType(QTouchDevice::TouchScreen); + QWindowSystemInterface::registerTouchDevice(device); + // press single point - QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint(),canvas); + QTest::touchEvent(canvas, device).press(0, topItem->mapToScene(pos).toPoint(),canvas); QTest::qWait(50); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); @@ -268,7 +260,7 @@ void tst_qquickcanvas::touchEvent_basic() topItem->reset(); // press multiple points - QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint(),canvas) + QTest::touchEvent(canvas, device).press(0, topItem->mapToScene(pos).toPoint(),canvas) .press(1, bottomItem->mapToScene(pos).toPoint(), canvas); QTest::qWait(50); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); @@ -280,9 +272,9 @@ void tst_qquickcanvas::touchEvent_basic() bottomItem->reset(); // touch point on top item moves to bottom item, but top item should still receive the event - QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint(), canvas); + QTest::touchEvent(canvas, device).press(0, topItem->mapToScene(pos).toPoint(), canvas); QTest::qWait(50); - QTest::touchEvent(canvas).move(0, bottomItem->mapToScene(pos).toPoint(), canvas); + QTest::touchEvent(canvas, device).move(0, bottomItem->mapToScene(pos).toPoint(), canvas); QTest::qWait(50); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchUpdate, canvas, Qt::TouchPointMoved, @@ -290,9 +282,9 @@ void tst_qquickcanvas::touchEvent_basic() topItem->reset(); // touch point on bottom item moves to top item, but bottom item should still receive the event - QTest::touchEvent(canvas).press(0, bottomItem->mapToScene(pos).toPoint(), canvas); + QTest::touchEvent(canvas, device).press(0, bottomItem->mapToScene(pos).toPoint(), canvas); QTest::qWait(50); - QTest::touchEvent(canvas).move(0, topItem->mapToScene(pos).toPoint(), canvas); + QTest::touchEvent(canvas, device).move(0, topItem->mapToScene(pos).toPoint(), canvas); QTest::qWait(50); QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1); COMPARE_TOUCH_DATA(bottomItem->lastEvent, makeTouchData(QEvent::TouchUpdate, canvas, Qt::TouchPointMoved, @@ -300,9 +292,9 @@ void tst_qquickcanvas::touchEvent_basic() bottomItem->reset(); // a single stationary press on an item shouldn't cause an event - QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint(), canvas); + QTest::touchEvent(canvas, device).press(0, topItem->mapToScene(pos).toPoint(), canvas); QTest::qWait(50); - QTest::touchEvent(canvas).stationary(0) + QTest::touchEvent(canvas, device).stationary(0) .press(1, bottomItem->mapToScene(pos).toPoint(), canvas); QTest::qWait(50); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); // received press only, not stationary @@ -314,9 +306,9 @@ void tst_qquickcanvas::touchEvent_basic() bottomItem->reset(); // move touch point from top item to bottom, and release - QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint(),canvas); + QTest::touchEvent(canvas, device).press(0, topItem->mapToScene(pos).toPoint(),canvas); QTest::qWait(50); - QTest::touchEvent(canvas).release(0, bottomItem->mapToScene(pos).toPoint(),canvas); + QTest::touchEvent(canvas, device).release(0, bottomItem->mapToScene(pos).toPoint(),canvas); QTest::qWait(50); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchEnd, canvas, Qt::TouchPointReleased, @@ -324,12 +316,12 @@ void tst_qquickcanvas::touchEvent_basic() topItem->reset(); // release while another point is pressed - QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint(),canvas) + QTest::touchEvent(canvas, device).press(0, topItem->mapToScene(pos).toPoint(),canvas) .press(1, bottomItem->mapToScene(pos).toPoint(), canvas); QTest::qWait(50); - QTest::touchEvent(canvas).move(0, bottomItem->mapToScene(pos).toPoint(), canvas); + QTest::touchEvent(canvas, device).move(0, bottomItem->mapToScene(pos).toPoint(), canvas); QTest::qWait(50); - QTest::touchEvent(canvas).release(0, bottomItem->mapToScene(pos).toPoint(), canvas) + QTest::touchEvent(canvas, device).release(0, bottomItem->mapToScene(pos).toPoint(), canvas) .stationary(1); QTest::qWait(50); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); @@ -353,6 +345,10 @@ void tst_qquickcanvas::touchEvent_propagation() QFETCH(bool, enableItem); QFETCH(qreal, itemOpacity); + QTouchDevice *device = new QTouchDevice; + device->setType(QTouchDevice::TouchScreen); + QWindowSystemInterface::registerTouchDevice(device); + QQuickCanvas *canvas = new QQuickCanvas; canvas->resize(250, 250); canvas->move(100, 100); @@ -383,7 +379,7 @@ void tst_qquickcanvas::touchEvent_propagation() topItem->setOpacity(itemOpacity); // single touch to top item, should be received by middle item - QTest::touchEvent(canvas).press(0, pointInTopItem, canvas); + QTest::touchEvent(canvas, device).press(0, pointInTopItem, canvas); QTest::qWait(50); QVERIFY(topItem->lastEvent.touchPoints.isEmpty()); QCOMPARE(middleItem->lastEvent.touchPoints.count(), 1); @@ -392,7 +388,7 @@ void tst_qquickcanvas::touchEvent_propagation() makeTouchPoint(middleItem, middleItem->mapFromItem(topItem, pos)))); // touch top and middle items, middle item should get both events - QTest::touchEvent(canvas).press(0, pointInTopItem, canvas) + QTest::touchEvent(canvas, device).press(0, pointInTopItem, canvas) .press(1, pointInMiddleItem, canvas); QTest::qWait(50); QVERIFY(topItem->lastEvent.touchPoints.isEmpty()); @@ -409,7 +405,7 @@ void tst_qquickcanvas::touchEvent_propagation() middleItem->setOpacity(itemOpacity); // touch top and middle items, bottom item should get all events - QTest::touchEvent(canvas).press(0, pointInTopItem, canvas) + QTest::touchEvent(canvas, device).press(0, pointInTopItem, canvas) .press(1, pointInMiddleItem, canvas); QTest::qWait(50); QVERIFY(topItem->lastEvent.touchPoints.isEmpty()); @@ -426,7 +422,7 @@ void tst_qquickcanvas::touchEvent_propagation() bottomItem->setOpacity(itemOpacity); // no events should be received - QTest::touchEvent(canvas).press(0, pointInTopItem, canvas) + QTest::touchEvent(canvas, device).press(0, pointInTopItem, canvas) .press(1, pointInMiddleItem, canvas) .press(2, pointInBottomItem, canvas); QTest::qWait(50); @@ -442,7 +438,7 @@ void tst_qquickcanvas::touchEvent_propagation() middleItem->acceptEvents = acceptEvents; middleItem->setEnabled(enableItem); middleItem->setOpacity(itemOpacity); - QTest::touchEvent(canvas).press(0, pointInTopItem, canvas); + QTest::touchEvent(canvas, device).press(0, pointInTopItem, canvas); QTest::qWait(50); if (!enableItem || itemOpacity == 0) { // middle item is disabled or has 0 opacity, bottom item receives the event |