aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2016-08-09 14:30:40 +0200
committerFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2016-08-09 14:32:05 +0200
commit990b750b6b7ceecc58699aee6736e036f4d49a25 (patch)
treeed3deac322d1c62b24fb56829c2e9c2edb337c77 /tests/auto/quick
parent89cfde8a024769c40e57c807f9b3bde5e91d3ffe (diff)
parent076640e0e7ac31574c41bd6298a89b0cb5d7f9a7 (diff)
Merge remote-tracking branch 'origin/wip/pointerhandler' into dev
This branch contains changes to the Mouse and Touch event delivery. It cleans up much of the existing code and adds a new class: QQuickPointerEvent (and two sub classes for touch and mouse at this point in time, tablet will be added eventually). The pointer event contains QQuickEventPoint instances. Thanks to the new pointer event class, we cache more data, reducing allocations and making delivery significantly easier. This lays the basis for a new way of pointer handling in Qt Quick which will use pointer events directly to have a more powerful abstraction over the basic events, while being more flexible. Change-Id: I30a90220f62314d504dd3b5e079b75fc6f4d2c74
Diffstat (limited to 'tests/auto/quick')
-rw-r--r--tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp10
-rw-r--r--tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp4
-rw-r--r--tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp1
-rw-r--r--tests/auto/quick/qquickwindow/tst_qquickwindow.cpp143
-rw-r--r--tests/auto/quick/touchmouse/data/touchpointdeliveryorder.qml39
-rw-r--r--tests/auto/quick/touchmouse/tst_touchmouse.cpp142
6 files changed, 311 insertions, 28 deletions
diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
index 9c627ad69c..adf0d282c5 100644
--- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
+++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
@@ -769,7 +769,7 @@ void tst_QQuickMouseArea::onMousePressRejected()
QVERIFY(!window.rootObject()->property("mr1_canceled").toBool());
QVERIFY(window.rootObject()->property("mr2_pressed").toBool());
QVERIFY(!window.rootObject()->property("mr2_released").toBool());
- QVERIFY(window.rootObject()->property("mr2_canceled").toBool());
+ QVERIFY(!window.rootObject()->property("mr2_canceled").toBool());
QTest::qWait(200);
@@ -1904,9 +1904,9 @@ void tst_QQuickMouseArea::ignoreBySource()
// MouseArea should grab the press because it's interested in non-synthesized mouse events
QPoint p = QPoint(80, 80);
QTest::mousePress(&window, Qt::LeftButton, 0, p);
- QVERIFY(window.mouseGrabberItem() == mouseArea);
+ QCOMPARE(window.mouseGrabberItem(), mouseArea);
// That was a real mouse event
- QVERIFY(root->property("lastEventSource").toInt() == Qt::MouseEventNotSynthesized);
+ QCOMPARE(root->property("lastEventSource").toInt(), int(Qt::MouseEventNotSynthesized));
// Flickable content should not move
p -= QPoint(startDragDistance() + 1, startDragDistance() + 1);
@@ -1919,12 +1919,14 @@ void tst_QQuickMouseArea::ignoreBySource()
QCOMPARE(flickable->contentY(), 0.);
QTest::mouseRelease(&window, Qt::LeftButton, 0, p);
+ QCOMPARE(window.mouseGrabberItem(), nullptr);
// Now try touch events and confirm that MouseArea ignores them, while Flickable does its thing
p = QPoint(80, 80);
QTest::touchEvent(&window, device).press(0, p, &window);
QQuickTouchUtils::flush(&window);
- QVERIFY(window.mouseGrabberItem() != mouseArea);
+ QCOMPARE(window.mouseGrabberItem(), flickable);
+
// That was a fake mouse event
QCOMPARE(root->property("lastEventSource").toInt(), int(Qt::MouseEventSynthesizedByQt));
p -= QPoint(startDragDistance() + 1, startDragDistance() + 1);
diff --git a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp
index c3981c466f..2872556a94 100644
--- a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp
+++ b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp
@@ -915,13 +915,13 @@ void tst_QQuickMultiPointTouchArea::mouseAsTouchpoint()
// Touch both, release one, manipulate other touchpoint with mouse
QTest::touchEvent(window.data(), device).press(1, touch1);
QQuickTouchUtils::flush(window.data());
- QTest::touchEvent(window.data(), device).press(2, touch2);
+ QTest::touchEvent(window.data(), device).move(1, touch1).press(2, touch2);
QQuickTouchUtils::flush(window.data());
QCOMPARE(touch1rect->property("x").toInt(), touch1.x());
QCOMPARE(touch1rect->property("y").toInt(), touch1.y());
QCOMPARE(touch2rect->property("x").toInt(), touch2.x());
QCOMPARE(touch2rect->property("y").toInt(), touch2.y());
- QTest::touchEvent(window.data(), device).release(1, touch1);
+ QTest::touchEvent(window.data(), device).release(1, touch1).move(2, touch2);
touch1.setY(20);
QTest::mousePress(window.data(), Qt::LeftButton, 0, touch1);
QQuickTouchUtils::flush(window.data());
diff --git a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp
index 1d7273f6df..c1a51fd659 100644
--- a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp
+++ b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp
@@ -511,6 +511,7 @@ void tst_QQuickPinchArea::cancel()
QCOMPARE(blackRect->scale(), 1.5);
QTouchEvent cancelEvent(QEvent::TouchCancel);
+ cancelEvent.setDevice(device);
QCoreApplication::sendEvent(window, &cancelEvent);
QQuickTouchUtils::flush(window);
diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
index d9bdf47041..acccac8eca 100644
--- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
+++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
@@ -157,6 +157,7 @@ public:
lastVelocity = lastVelocityFromMouseMove = QVector2D();
lastMousePos = QPointF();
lastMouseCapabilityFlags = 0;
+ touchEventCount = 0;
}
static void clearMousePressCounter()
@@ -302,6 +303,9 @@ private slots:
void touchEvent_reentrant();
void touchEvent_velocity();
+ void mergeTouchPointLists_data();
+ void mergeTouchPointLists();
+
void mouseFromTouch_basic();
void clearWindow();
@@ -362,6 +366,9 @@ private slots:
void testHoverChildMouseEventFilter();
void testHoverTimestamp();
+
+ void pointerEventTypeAndPointCount();
+
private:
QTouchDevice *touchDevice;
QTouchDevice *touchDeviceWithVelocity;
@@ -521,9 +528,8 @@ void tst_qquickwindow::touchEvent_basic()
// press single point
QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(),window);
- QTest::qWait(50);
-
- QCOMPARE(topItem->lastEvent.touchPoints.count(), 1);
+ QQuickTouchUtils::flush(window);
+ QTRY_COMPARE(topItem->lastEvent.touchPoints.count(), 1);
QVERIFY(middleItem->lastEvent.touchPoints.isEmpty());
QVERIFY(bottomItem->lastEvent.touchPoints.isEmpty());
@@ -531,9 +537,10 @@ void tst_qquickwindow::touchEvent_basic()
// would put the decorated window at that position rather than the window itself.
COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed, makeTouchPoint(topItem, pos)));
topItem->reset();
+ QTest::touchEvent(window, touchDevice).release(0, topItem->mapToScene(pos).toPoint(), window);
// press multiple points
- QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(),window)
+ QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(), window)
.press(1, bottomItem->mapToScene(pos).toPoint(), window);
QQuickTouchUtils::flush(window);
QCOMPARE(topItem->lastEvent.touchPoints.count(), 1);
@@ -543,6 +550,7 @@ void tst_qquickwindow::touchEvent_basic()
COMPARE_TOUCH_DATA(bottomItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed, makeTouchPoint(bottomItem, pos)));
topItem->reset();
bottomItem->reset();
+ QTest::touchEvent(window, touchDevice).release(0, topItem->mapToScene(pos).toPoint(), window).release(1, bottomItem->mapToScene(pos).toPoint(), window);
// touch point on top item moves to bottom item, but top item should still receive the event
QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(), window);
@@ -553,6 +561,7 @@ void tst_qquickwindow::touchEvent_basic()
COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchUpdate, window, Qt::TouchPointMoved,
makeTouchPoint(topItem, topItem->mapFromItem(bottomItem, pos), pos)));
topItem->reset();
+ QTest::touchEvent(window, touchDevice).release(0, bottomItem->mapToScene(pos).toPoint(), window);
// touch point on bottom item moves to top item, but bottom item should still receive the event
QTest::touchEvent(window, touchDevice).press(0, bottomItem->mapToScene(pos).toPoint(), window);
@@ -563,6 +572,7 @@ void tst_qquickwindow::touchEvent_basic()
COMPARE_TOUCH_DATA(bottomItem->lastEvent, makeTouchData(QEvent::TouchUpdate, window, Qt::TouchPointMoved,
makeTouchPoint(bottomItem, bottomItem->mapFromItem(topItem, pos), pos)));
bottomItem->reset();
+ QTest::touchEvent(window, touchDevice).release(0, bottomItem->mapToScene(pos).toPoint(), window);
// a single stationary press on an item shouldn't cause an event
QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(), window);
@@ -667,6 +677,7 @@ void tst_qquickwindow::touchEvent_propagation()
QVERIFY(bottomItem->lastEvent.touchPoints.isEmpty());
COMPARE_TOUCH_DATA(middleItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed,
makeTouchPoint(middleItem, middleItem->mapFromItem(topItem, pos))));
+ QTest::touchEvent(window, touchDevice).release(0, pointInTopItem, window);
// touch top and middle items, middle item should get both events
QTest::touchEvent(window, touchDevice).press(0, pointInTopItem, window)
@@ -678,6 +689,8 @@ void tst_qquickwindow::touchEvent_propagation()
COMPARE_TOUCH_DATA(middleItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed,
(QList<QTouchEvent::TouchPoint>() << makeTouchPoint(middleItem, middleItem->mapFromItem(topItem, pos))
<< makeTouchPoint(middleItem, pos) )));
+ QTest::touchEvent(window, touchDevice).release(0, pointInTopItem, window)
+ .release(1, pointInMiddleItem, window);
middleItem->reset();
// disable middleItem as well
@@ -702,6 +715,8 @@ void tst_qquickwindow::touchEvent_propagation()
bottomItem->acceptTouchEvents = acceptTouchEvents;
bottomItem->setEnabled(enableItem);
bottomItem->setVisible(showItem);
+ QTest::touchEvent(window, touchDevice).release(0, pointInTopItem, window)
+ .release(1, pointInMiddleItem, window);
// no events should be received
QTest::touchEvent(window, touchDevice).press(0, pointInTopItem, window)
@@ -711,7 +726,9 @@ void tst_qquickwindow::touchEvent_propagation()
QVERIFY(topItem->lastEvent.touchPoints.isEmpty());
QVERIFY(middleItem->lastEvent.touchPoints.isEmpty());
QVERIFY(bottomItem->lastEvent.touchPoints.isEmpty());
-
+ QTest::touchEvent(window, touchDevice).release(0, pointInTopItem, window)
+ .release(1, pointInMiddleItem, window)
+ .release(2, pointInBottomItem, window);
topItem->reset();
middleItem->reset();
bottomItem->reset();
@@ -737,6 +754,7 @@ void tst_qquickwindow::touchEvent_propagation()
COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed,
makeTouchPoint(topItem, pos)));
}
+ QTest::touchEvent(window, touchDevice).release(0, pointInTopItem, window);
delete topItem;
delete middleItem;
@@ -855,6 +873,8 @@ void tst_qquickwindow::touchEvent_velocity()
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
QGuiApplication::processEvents();
QQuickTouchUtils::flush(window);
+ QCOMPARE(item->touchEventCount, 1);
+
points[0].state = Qt::TouchPointMoved;
points[0].area.adjust(5, 5, 5, 5);
QVector2D velocity(1.5, 2.5);
@@ -887,6 +907,67 @@ void tst_qquickwindow::touchEvent_velocity()
delete item;
}
+void tst_qquickwindow::mergeTouchPointLists_data()
+{
+ QTest::addColumn<QVector<QQuickItem*>>("list1");
+ QTest::addColumn<QVector<QQuickItem*>>("list2");
+ QTest::addColumn<QVector<QQuickItem*>>("expected");
+ QTest::addColumn<bool>("showItem");
+
+ // FIXME: do not leak all these items
+ auto item1 = new QQuickItem();
+ auto item2 = new QQuickItem();
+ auto item3 = new QQuickItem();
+ auto item4 = new QQuickItem();
+ auto item5 = new QQuickItem();
+
+ QTest::newRow("empty") << QVector<QQuickItem*>() << QVector<QQuickItem*>() << QVector<QQuickItem*>();
+ QTest::newRow("single list left")
+ << (QVector<QQuickItem*>() << item1 << item2 << item3)
+ << QVector<QQuickItem*>()
+ << (QVector<QQuickItem*>() << item1 << item2 << item3);
+ QTest::newRow("single list right")
+ << QVector<QQuickItem*>()
+ << (QVector<QQuickItem*>() << item1 << item2 << item3)
+ << (QVector<QQuickItem*>() << item1 << item2 << item3);
+ QTest::newRow("two lists identical")
+ << (QVector<QQuickItem*>() << item1 << item2 << item3)
+ << (QVector<QQuickItem*>() << item1 << item2 << item3)
+ << (QVector<QQuickItem*>() << item1 << item2 << item3);
+ QTest::newRow("two lists 1")
+ << (QVector<QQuickItem*>() << item1 << item2 << item5)
+ << (QVector<QQuickItem*>() << item3 << item4 << item5)
+ << (QVector<QQuickItem*>() << item1 << item2 << item3 << item4 << item5);
+ QTest::newRow("two lists 2")
+ << (QVector<QQuickItem*>() << item1 << item2 << item5)
+ << (QVector<QQuickItem*>() << item3 << item4 << item5)
+ << (QVector<QQuickItem*>() << item1 << item2 << item3 << item4 << item5);
+ QTest::newRow("two lists 3")
+ << (QVector<QQuickItem*>() << item1 << item2 << item3)
+ << (QVector<QQuickItem*>() << item1 << item4 << item5)
+ << (QVector<QQuickItem*>() << item1 << item2 << item3 << item4 << item5);
+ QTest::newRow("two lists 4")
+ << (QVector<QQuickItem*>() << item1 << item3 << item4)
+ << (QVector<QQuickItem*>() << item2 << item3 << item5)
+ << (QVector<QQuickItem*>() << item1 << item2 << item3 << item4 << item5);
+ QTest::newRow("two lists 5")
+ << (QVector<QQuickItem*>() << item1 << item2 << item4)
+ << (QVector<QQuickItem*>() << item1 << item3 << item4)
+ << (QVector<QQuickItem*>() << item1 << item2 << item3 << item4);
+}
+
+void tst_qquickwindow::mergeTouchPointLists()
+{
+ QFETCH(QVector<QQuickItem*>, list1);
+ QFETCH(QVector<QQuickItem*>, list2);
+ QFETCH(QVector<QQuickItem*>, expected);
+
+ QQuickWindow win;
+ auto windowPrivate = QQuickWindowPrivate::get(&win);
+ auto targetList = windowPrivate->mergePointerTargets(list1, list2);
+ QCOMPARE(targetList, expected);
+}
+
void tst_qquickwindow::mouseFromTouch_basic()
{
// Turn off accepting touch events with acceptTouchEvents. This
@@ -2402,6 +2483,58 @@ void tst_qquickwindow::testHoverTimestamp()
QCOMPARE(hoverConsumer->hoverTimestamps.last(), 5UL);
}
+void tst_qquickwindow::pointerEventTypeAndPointCount()
+{
+ QPointF localPosition(33, 66);
+ QPointF scenePosition(133, 166);
+ QPointF screenPosition(333, 366);
+ QMouseEvent me(QEvent::MouseButtonPress, localPosition, scenePosition, screenPosition,
+ Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
+ QTouchEvent te(QEvent::TouchBegin, touchDevice, Qt::NoModifier, Qt::TouchPointPressed,
+ QList<QTouchEvent::TouchPoint>() << QTouchEvent::TouchPoint(1));
+
+
+ QQuickPointerMouseEvent pme;
+ pme.reset(&me);
+ QVERIFY(pme.isValid());
+ QCOMPARE(pme.asMouseEvent(localPosition), &me);
+ QVERIFY(pme.asPointerMouseEvent());
+ QVERIFY(!pme.asPointerTouchEvent());
+ QVERIFY(!pme.asPointerTabletEvent());
+// QVERIFY(!pe->asTabletEvent()); // TODO
+ QCOMPARE(pme.pointCount(), 1);
+ QCOMPARE(pme.point(0)->scenePos(), scenePosition);
+ QCOMPARE(pme.asMouseEvent(localPosition)->localPos(), localPosition);
+ QCOMPARE(pme.asMouseEvent(localPosition)->screenPos(), screenPosition);
+
+ QQuickPointerTouchEvent pte;
+ pte.reset(&te);
+ QVERIFY(pte.isValid());
+ QCOMPARE(pte.asTouchEvent(), &te);
+ QVERIFY(!pte.asPointerMouseEvent());
+ QVERIFY(pte.asPointerTouchEvent());
+ QVERIFY(!pte.asPointerTabletEvent());
+ QVERIFY(pte.asTouchEvent());
+// QVERIFY(!pte.asTabletEvent()); // TODO
+ QCOMPARE(pte.pointCount(), 1);
+ QCOMPARE(pte.touchPointById(1)->id(), 1);
+ QVERIFY(!pte.touchPointById(0));
+
+ te.setTouchPoints(QList<QTouchEvent::TouchPoint>() << QTouchEvent::TouchPoint(1) << QTouchEvent::TouchPoint(2));
+ pte.reset(&te);
+ QCOMPARE(pte.pointCount(), 2);
+ QCOMPARE(pte.touchPointById(1)->id(), 1);
+ QCOMPARE(pte.touchPointById(2)->id(), 2);
+ QVERIFY(!pte.touchPointById(0));
+
+ te.setTouchPoints(QList<QTouchEvent::TouchPoint>() << QTouchEvent::TouchPoint(2));
+ pte.reset(&te);
+ QCOMPARE(pte.pointCount(), 1);
+ QCOMPARE(pte.touchPointById(2)->id(), 2);
+ QVERIFY(!pte.touchPointById(1));
+ QVERIFY(!pte.touchPointById(0));
+}
+
QTEST_MAIN(tst_qquickwindow)
#include "tst_qquickwindow.moc"
diff --git a/tests/auto/quick/touchmouse/data/touchpointdeliveryorder.qml b/tests/auto/quick/touchmouse/data/touchpointdeliveryorder.qml
new file mode 100644
index 0000000000..9f67c226a0
--- /dev/null
+++ b/tests/auto/quick/touchmouse/data/touchpointdeliveryorder.qml
@@ -0,0 +1,39 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+Rectangle {
+ id: root
+
+ width: 600
+ height: 400
+
+ EventItem {
+ objectName: "background"
+ width: 600
+ height: 400
+ Rectangle { anchors.fill: parent; color: "lightsteelblue" }
+
+ EventItem {
+ objectName: "left"
+ width: 300
+ height: 300
+ Rectangle { anchors.fill: parent; color: "yellow" }
+ }
+
+ EventItem {
+ objectName: "right"
+ x: 300
+ width: 300
+ height: 300
+ Rectangle { anchors.fill: parent; color: "green" }
+ }
+
+ EventItem {
+ objectName: "middle"
+ x: 150
+ width: 300
+ height: 300
+ Rectangle { anchors.fill: parent; color: "blue" }
+ }
+ }
+}
diff --git a/tests/auto/quick/touchmouse/tst_touchmouse.cpp b/tests/auto/quick/touchmouse/tst_touchmouse.cpp
index dc70081f09..1ec24e35d5 100644
--- a/tests/auto/quick/touchmouse/tst_touchmouse.cpp
+++ b/tests/auto/quick/touchmouse/tst_touchmouse.cpp
@@ -33,12 +33,12 @@
#include <QtQuick/qquickview.h>
#include <QtQuick/qquickitem.h>
+#include <QtQuick/private/qquickevents_p_p.h>
#include <QtQuick/private/qquickmousearea_p.h>
#include <QtQuick/private/qquickmultipointtoucharea_p.h>
#include <QtQuick/private/qquickpincharea_p.h>
#include <QtQuick/private/qquickflickable_p.h>
-
-#include <private/qquickwindow_p.h>
+#include <QtQuick/private/qquickwindow_p.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlproperty.h>
@@ -65,15 +65,22 @@ struct Event
class EventItem : public QQuickItem
{
Q_OBJECT
+
+Q_SIGNALS:
+ void onTouchEvent(QQuickItem *receiver);
+
public:
EventItem(QQuickItem *parent = 0)
: QQuickItem(parent), acceptMouse(false), acceptTouch(false), filterTouch(false)
- {}
+ {
+ setAcceptedMouseButtons(Qt::LeftButton);
+ }
void touchEvent(QTouchEvent *event)
{
eventList.append(Event(event->type(), event->touchPoints()));
event->setAccepted(acceptTouch);
+ emit onTouchEvent(this);
}
void mousePressEvent(QMouseEvent *event)
{
@@ -154,6 +161,7 @@ private slots:
void tapOnDismissiveTopMouseAreaClicksBottomOne();
void touchGrabCausesMouseUngrab();
+ void touchPointDeliveryOrder();
void hoverEnabled();
@@ -211,15 +219,17 @@ void tst_TouchMouse::simpleTouchEvent()
p1 = QPoint(20, 20);
QTest::touchEvent(window, device).press(0, p1, window);
QQuickTouchUtils::flush(window);
- QCOMPARE(eventItem1->eventList.size(), 1);
+ // Get a touch and then mouse event offered
+ QCOMPARE(eventItem1->eventList.size(), 2);
QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin);
p1 += QPoint(10, 0);
QTest::touchEvent(window, device).move(0, p1, window);
QQuickTouchUtils::flush(window);
- QCOMPARE(eventItem1->eventList.size(), 1);
+ // Not accepted, no updates
+ QCOMPARE(eventItem1->eventList.size(), 2);
QTest::touchEvent(window, device).release(0, p1, window);
QQuickTouchUtils::flush(window);
- QCOMPARE(eventItem1->eventList.size(), 1);
+ QCOMPARE(eventItem1->eventList.size(), 2);
eventItem1->eventList.clear();
// Accept touch
@@ -285,17 +295,16 @@ void tst_TouchMouse::simpleTouchEvent()
p1 = QPoint(20, 20);
QTest::touchEvent(window, device).press(0, p1, window);
QQuickTouchUtils::flush(window);
- QCOMPARE(eventItem1->eventList.size(), 3);
+ QCOMPARE(eventItem1->eventList.size(), 2);
QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin);
QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonPress);
- QCOMPARE(eventItem1->eventList.at(2).type, QEvent::UngrabMouse);
p1 += QPoint(10, 0);
QTest::touchEvent(window, device).move(0, p1, window);
QQuickTouchUtils::flush(window);
- QCOMPARE(eventItem1->eventList.size(), 3);
+ QCOMPARE(eventItem1->eventList.size(), 2);
QTest::touchEvent(window, device).release(0, p1, window);
QQuickTouchUtils::flush(window);
- QCOMPARE(eventItem1->eventList.size(), 3);
+ QCOMPARE(eventItem1->eventList.size(), 2);
eventItem1->eventList.clear();
// wait to avoid getting a double click event
@@ -572,7 +581,8 @@ void tst_TouchMouse::buttonOnFlickable()
QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(window);
QCOMPARE(windowPriv->touchMouseId, 0);
- QCOMPARE(windowPriv->itemForTouchPointId[0], eventItem1);
+ auto pointerEvent = QQuickPointerDevice::touchDevices().at(0)->pointerEvent();
+ QCOMPARE(pointerEvent->point(0)->grabber(), eventItem1);
QCOMPARE(window->mouseGrabberItem(), eventItem1);
p1 += QPoint(0, -10);
@@ -593,7 +603,7 @@ void tst_TouchMouse::buttonOnFlickable()
QCOMPARE(window->mouseGrabberItem(), flickable);
QCOMPARE(windowPriv->touchMouseId, 0);
- QCOMPARE(windowPriv->itemForTouchPointId[0], flickable);
+ QCOMPARE(pointerEvent->point(0)->grabber(), flickable);
QVERIFY(flickable->isMovingVertically());
QTest::touchEvent(window, device).release(0, p3, window);
@@ -653,11 +663,12 @@ void tst_TouchMouse::buttonOnDelayedPressFlickable()
QCOMPARE(eventItem1->eventList.at(0).type, QEvent::MouseButtonPress);
QCOMPARE(filteredEventList.count(), 1);
- // eventItem1 should have the mouse grab, and have moved the itemForTouchPointId
+ // eventItem1 should have the mouse grab, and have moved the grab
// for the touchMouseId to the new grabber.
QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(window);
QCOMPARE(windowPriv->touchMouseId, 0);
- QCOMPARE(windowPriv->itemForTouchPointId[0], eventItem1);
+ auto pointerEvent = QQuickPointerDevice::touchDevices().at(0)->pointerEvent();
+ QCOMPARE(pointerEvent->point(0)->grabber(), eventItem1);
QCOMPARE(window->mouseGrabberItem(), eventItem1);
p1 += QPoint(0, -10);
@@ -676,7 +687,7 @@ void tst_TouchMouse::buttonOnDelayedPressFlickable()
// for the touchMouseId to the new grabber.
QCOMPARE(window->mouseGrabberItem(), flickable);
QCOMPARE(windowPriv->touchMouseId, 0);
- QCOMPARE(windowPriv->itemForTouchPointId[0], flickable);
+ QCOMPARE(pointerEvent->point(0)->grabber(), flickable);
QTest::touchEvent(window, device).release(0, p3, window);
QQuickTouchUtils::flush(window);
@@ -1090,8 +1101,6 @@ void tst_TouchMouse::mouseOnFlickableOnPinch()
pinchSequence.move(0, p, window).commit();
QQuickTouchUtils::flush(window);
- QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(window);
- qDebug() << "Mouse Grabber: " << window->mouseGrabberItem() << " itemForTouchPointId: " << windowPriv->itemForTouchPointId;
QCOMPARE(window->mouseGrabberItem(), flickable);
// Add a second finger, this should lead to stealing
@@ -1222,6 +1231,105 @@ void tst_TouchMouse::touchGrabCausesMouseUngrab()
delete window;
}
+void tst_TouchMouse::touchPointDeliveryOrder()
+{
+ // Touch points should be first delivered to the item under the primary finger
+ QScopedPointer<QQuickView> window(createView());
+
+ window->setSource(testFileUrl("touchpointdeliveryorder.qml"));
+ /*
+ The items are positioned from left to right:
+ | background |
+ | left |
+ | | right |
+ | middle |
+ 0 150 300 450 600
+ */
+ QPoint pLeft = QPoint(100, 100);
+ QPoint pRight = QPoint(500, 100);
+ QPoint pLeftMiddle = QPoint(200, 100);
+ QPoint pRightMiddle = QPoint(350, 100);
+
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window.data()));
+
+ QVector<QQuickItem*> events;
+ EventItem *background = window->rootObject()->findChild<EventItem*>("background");
+ EventItem *left = window->rootObject()->findChild<EventItem*>("left");
+ EventItem *middle = window->rootObject()->findChild<EventItem*>("middle");
+ EventItem *right = window->rootObject()->findChild<EventItem*>("right");
+ QVERIFY(background);
+ QVERIFY(left);
+ QVERIFY(middle);
+ QVERIFY(right);
+ connect(background, &EventItem::onTouchEvent, [&events](QQuickItem* receiver){ events.append(receiver); });
+ connect(left, &EventItem::onTouchEvent, [&events](QQuickItem* receiver){ events.append(receiver); });
+ connect(middle, &EventItem::onTouchEvent, [&events](QQuickItem* receiver){ events.append(receiver); });
+ connect(right, &EventItem::onTouchEvent, [&events](QQuickItem* receiver){ events.append(receiver); });
+
+ QTest::touchEvent(window.data(), device).press(0, pLeft, window.data());
+ QQuickTouchUtils::flush(window.data());
+
+ // Touch on left, then background
+ QCOMPARE(events.size(), 2);
+ QCOMPARE(events.at(0), left);
+ QCOMPARE(events.at(1), background);
+ events.clear();
+
+ // New press events are deliverd first, the stationary point was not accepted, thus it doesn't get delivered
+ QTest::touchEvent(window.data(), device).stationary(0).press(1, pRightMiddle, window.data());
+ QQuickTouchUtils::flush(window.data());
+ QCOMPARE(events.size(), 3);
+ QCOMPARE(events.at(0), middle);
+ QCOMPARE(events.at(1), right);
+ QCOMPARE(events.at(2), background);
+ events.clear();
+
+ QTest::touchEvent(window.data(), device).release(0, pLeft, window.data()).release(1, pRightMiddle, window.data());
+ QQuickTouchUtils::flush(window.data());
+ QCOMPARE(events.size(), 0); // no accepted events
+
+ // Two presses, the first point should come first
+ QTest::touchEvent(window.data(), device).press(0, pLeft, window.data()).press(1, pRight, window.data());
+ QQuickTouchUtils::flush(window.data());
+ QCOMPARE(events.size(), 3);
+ QCOMPARE(events.at(0), left);
+ QCOMPARE(events.at(1), right);
+ QCOMPARE(events.at(2), background);
+ QTest::touchEvent(window.data(), device).release(0, pLeft, window.data()).release(1, pRight, window.data());
+ events.clear();
+
+ // Again, pressing right first
+ QTest::touchEvent(window.data(), device).press(0, pRight, window.data()).press(1, pLeft, window.data());
+ QQuickTouchUtils::flush(window.data());
+ QCOMPARE(events.size(), 3);
+ QCOMPARE(events.at(0), right);
+ QCOMPARE(events.at(1), left);
+ QCOMPARE(events.at(2), background);
+ QTest::touchEvent(window.data(), device).release(0, pRight, window.data()).release(1, pLeft, window.data());
+ events.clear();
+
+ // Two presses, both hitting the middle item on top, then branching left and right, then bottom
+ // Each target should be offered the events exactly once, middle first, left must come before right (id 0)
+ QTest::touchEvent(window.data(), device).press(0, pLeftMiddle, window.data()).press(1, pRightMiddle, window.data());
+ QCOMPARE(events.size(), 4);
+ QCOMPARE(events.at(0), middle);
+ QCOMPARE(events.at(1), left);
+ QCOMPARE(events.at(2), right);
+ QCOMPARE(events.at(3), background);
+ QTest::touchEvent(window.data(), device).release(0, pLeftMiddle, window.data()).release(1, pRightMiddle, window.data());
+ events.clear();
+
+ QTest::touchEvent(window.data(), device).press(0, pRightMiddle, window.data()).press(1, pLeftMiddle, window.data());
+ qDebug() << events;
+ QCOMPARE(events.size(), 4);
+ QCOMPARE(events.at(0), middle);
+ QCOMPARE(events.at(1), right);
+ QCOMPARE(events.at(2), left);
+ QCOMPARE(events.at(3), background);
+ QTest::touchEvent(window.data(), device).release(0, pRightMiddle, window.data()).release(1, pLeftMiddle, window.data());
+}
+
void tst_TouchMouse::hoverEnabled()
{
// QTouchDevice *device = new QTouchDevice;