From c0100e28cadf8260769eddcc7a0306d832fed92b Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 10 Feb 2012 13:43:00 +0200 Subject: Add basic TouchCancel handling to canvas. This makes sure that touchEvent() is properly called for all items in the scene that have an active touch. It does not handle the cancel event in any other special way. Change-Id: Id66527ced8cb63d0b29f25f37c139e6d6aec9ba0 Reviewed-by: Michael Brasser Reviewed-by: Martin Jones --- .../qtquick2/qquickcanvas/tst_qquickcanvas.cpp | 35 +++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp b/tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp index 4a238429bb..eac0d851d5 100644 --- a/tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp +++ b/tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp @@ -74,7 +74,8 @@ static QTouchEvent::TouchPoint makeTouchPoint(QQuickItem *item, const QPointF &p return tp; } -static TouchEventData makeTouchData(QEvent::Type type, QWindow *w, Qt::TouchPointStates states, const QList& touchPoints) +static TouchEventData makeTouchData(QEvent::Type type, QWindow *w, Qt::TouchPointStates states = 0, + const QList& touchPoints = QList()) { TouchEventData d = { type, 0, w, states, touchPoints }; return d; @@ -197,6 +198,7 @@ private slots: void touchEvent_basic(); void touchEvent_propagation(); void touchEvent_propagation_data(); + void touchEvent_cancel(); void clearCanvas(); @@ -475,6 +477,37 @@ void tst_qquickcanvas::touchEvent_propagation_data() QTest::newRow("opacity of 0") << true << true << 0.0; } +void tst_qquickcanvas::touchEvent_cancel() +{ + TestTouchItem::clearMousePressCounter(); + + QQuickCanvas *canvas = new QQuickCanvas; + canvas->resize(250, 250); + canvas->move(100, 100); + canvas->show(); + + TestTouchItem *item = new TestTouchItem(canvas->rootItem()); + item->setPos(QPointF(50, 50)); + item->setSize(QSizeF(150, 150)); + + QPointF pos(10, 10); + QTest::touchEvent(canvas, touchDevice).press(0, item->mapToScene(pos).toPoint(),canvas); + QCoreApplication::processEvents(); + + QTRY_COMPARE(item->lastEvent.touchPoints.count(), 1); + TouchEventData d = makeTouchData(QEvent::TouchBegin, canvas, Qt::TouchPointPressed, makeTouchPoint(item,pos)); + COMPARE_TOUCH_DATA(item->lastEvent, d); + item->reset(); + + QWindowSystemInterface::handleTouchCancelEvent(0, touchDevice); + QCoreApplication::processEvents(); + d = makeTouchData(QEvent::TouchCancel, canvas); + COMPARE_TOUCH_DATA(item->lastEvent, d); + + delete item; + delete canvas; +} + void tst_qquickcanvas::clearCanvas() { QQuickCanvas *canvas = new QQuickCanvas; -- cgit v1.2.3