if (eventStates != Qt::TouchPointStationary) {
QTouchEvent touchEvent(eventType);
- // touchEvent.setWidget(q); // ### refactor: what is the consequence of not setting the widget?
- touchEvent.setDeviceType(event->deviceType());
+ touchEvent.setWindow(event->window());
+ touchEvent.setTarget(item);
+ touchEvent.setDevice(event->device());
touchEvent.setModifiers(event->modifiers());
touchEvent.setTouchPointStates(eventStates);
touchEvent.setTouchPoints(eventPoints);
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 };
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();
}
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);
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);
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,
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,
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
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,
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);
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);
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);
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());
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());
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);
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
class tst_QQuickMultiPointTouchArea: public QObject
{
Q_OBJECT
+public:
+ tst_QQuickMultiPointTouchArea() : device(0) { }
private slots:
- void initTestCase() {}
+ void initTestCase() {
+ if (!device) {
+ device = new QTouchDevice;
+ device->setType(QTouchDevice::TouchScreen);
+ QWindowSystemInterface::registerTouchDevice(device);
+ }
+ }
void cleanupTestCase() {}
void properties();
private:
QQuickView *createAndShowView(const QString &file);
+ QTouchDevice *device;
};
void tst_QQuickMultiPointTouchArea::properties()
QPoint p4(80,100);
QPoint p5(100,100);
- QTest::QTouchEventSequence sequence = QTest::touchEvent(canvas);
+ QTest::QTouchEventSequence sequence = QTest::touchEvent(canvas, device);
sequence.press(0, p1).press(1, p2).commit();
QPoint p4(80,180);
QPoint p5(100,180);
- QTest::QTouchEventSequence sequence = QTest::touchEvent(canvas);
+ QTest::QTouchEventSequence sequence = QTest::touchEvent(canvas, device);
sequence.press(0, p1).commit();
QPoint p2(40,100);
QPoint p3(60,180);
- QTest::QTouchEventSequence sequence = QTest::touchEvent(canvas);
+ QTest::QTouchEventSequence sequence = QTest::touchEvent(canvas, device);
sequence.press(0, p1).commit();
QPoint p2(40,100);
//moving one point vertically
- QTest::touchEvent(canvas).press(0, p1);
+ QTest::touchEvent(canvas, device).press(0, p1);
QTest::mousePress(canvas, Qt::LeftButton, 0, p1);
p1 += QPoint(0,15);
- QTest::touchEvent(canvas).move(0, p1);
+ QTest::touchEvent(canvas, device).move(0, p1);
QTest::mouseMove(canvas, p1);
p1 += QPoint(0,15);
- QTest::touchEvent(canvas).move(0, p1);
+ QTest::touchEvent(canvas, device).move(0, p1);
QTest::mouseMove(canvas, p1);
p1 += QPoint(0,15);
- QTest::touchEvent(canvas).move(0, p1);
+ QTest::touchEvent(canvas, device).move(0, p1);
QTest::mouseMove(canvas, p1);
p1 += QPoint(0,15);
- QTest::touchEvent(canvas).move(0, p1);
+ QTest::touchEvent(canvas, device).move(0, p1);
QTest::mouseMove(canvas, p1);
QVERIFY(flickable->contentY() < 0);
QCOMPARE(point11->isValid(), false);
QCOMPARE(point12->isValid(), false);
- QTest::touchEvent(canvas).release(0, p1);
+ QTest::touchEvent(canvas, device).release(0, p1);
QTest::mouseRelease(canvas,Qt::LeftButton, 0, p1);
QTest::qWait(50);
//moving two points vertically
p1 = QPoint(20,100);
- QTest::touchEvent(canvas).press(0, p1).press(1, p2);
+ QTest::touchEvent(canvas, device).press(0, p1).press(1, p2);
QTest::mousePress(canvas, Qt::LeftButton, 0, p1);
QCOMPARE(point11->isValid(), true);
QCOMPARE(point12->isValid(), true);
p1 += QPoint(0,15); p2 += QPoint(0,15);
- QTest::touchEvent(canvas).move(0, p1).move(1, p2);
+ QTest::touchEvent(canvas, device).move(0, p1).move(1, p2);
QTest::mouseMove(canvas, p1);
p1 += QPoint(0,15); p2 += QPoint(0,15);
- QTest::touchEvent(canvas).move(0, p1).move(1, p2);
+ QTest::touchEvent(canvas, device).move(0, p1).move(1, p2);
QTest::mouseMove(canvas, p1);
p1 += QPoint(0,15); p2 += QPoint(0,15);
- QTest::touchEvent(canvas).move(0, p1).move(1, p2);
+ QTest::touchEvent(canvas, device).move(0, p1).move(1, p2);
QTest::mouseMove(canvas, p1);
p1 += QPoint(0,15); p2 += QPoint(0,15);
- QTest::touchEvent(canvas).move(0, p1).move(1, p2);
+ QTest::touchEvent(canvas, device).move(0, p1).move(1, p2);
QTest::mouseMove(canvas, p1);
QVERIFY(flickable->contentY() < 0);
QCOMPARE(point11->isValid(), false);
QCOMPARE(point12->isValid(), false);
- QTest::touchEvent(canvas).release(0, p1).release(1, p2);
+ QTest::touchEvent(canvas, device).release(0, p1).release(1, p2);
QTest::mouseRelease(canvas,Qt::LeftButton, 0, p1);
QTest::qWait(50);
//moving two points horizontally, then one point vertically
p1 = QPoint(20,100);
p2 = QPoint(40,100);
- QTest::touchEvent(canvas).press(0, p1).press(1, p2);
+ QTest::touchEvent(canvas, device).press(0, p1).press(1, p2);
QTest::mousePress(canvas, Qt::LeftButton, 0, p1);
QCOMPARE(point11->isValid(), true);
QCOMPARE(point12->isValid(), true);
p1 += QPoint(15,0); p2 += QPoint(15,0);
- QTest::touchEvent(canvas).move(0, p1).move(1, p2);
+ QTest::touchEvent(canvas, device).move(0, p1).move(1, p2);
QTest::mouseMove(canvas, p1);
p1 += QPoint(15,0); p2 += QPoint(15,0);
- QTest::touchEvent(canvas).move(0, p1).move(1, p2);
+ QTest::touchEvent(canvas, device).move(0, p1).move(1, p2);
QTest::mouseMove(canvas, p1);
p1 += QPoint(15,0); p2 += QPoint(15,0);
- QTest::touchEvent(canvas).move(0, p1).move(1, p2);
+ QTest::touchEvent(canvas, device).move(0, p1).move(1, p2);
QTest::mouseMove(canvas, p1);
p1 += QPoint(15,0); p2 += QPoint(15,0);
- QTest::touchEvent(canvas).move(0, p1).move(1, p2);
+ QTest::touchEvent(canvas, device).move(0, p1).move(1, p2);
QTest::mouseMove(canvas, p1);
p1 += QPoint(0,15); p2 += QPoint(0,15);
- QTest::touchEvent(canvas).move(0, p1).move(1, p2);
+ QTest::touchEvent(canvas, device).move(0, p1).move(1, p2);
QTest::mouseMove(canvas, p1);
p1 += QPoint(0,15); p2 += QPoint(0,15);
- QTest::touchEvent(canvas).move(0, p1).move(1, p2);
+ QTest::touchEvent(canvas, device).move(0, p1).move(1, p2);
QTest::mouseMove(canvas, p1);
p1 += QPoint(0,15); p2 += QPoint(0,15);
- QTest::touchEvent(canvas).move(0, p1).move(1, p2);
+ QTest::touchEvent(canvas, device).move(0, p1).move(1, p2);
QTest::mouseMove(canvas, p1);
p1 += QPoint(0,15); p2 += QPoint(0,15);
- QTest::touchEvent(canvas).move(0, p1).move(1, p2);
+ QTest::touchEvent(canvas, device).move(0, p1).move(1, p2);
QTest::mouseMove(canvas, p1);
QVERIFY(flickable->contentY() == 0);
QCOMPARE(point11->isValid(), true);
QCOMPARE(point12->isValid(), true);
- QTest::touchEvent(canvas).release(0, p1).release(1, p2);
+ QTest::touchEvent(canvas, device).release(0, p1).release(1, p2);
QTest::mouseRelease(canvas,Qt::LeftButton, 0, p1);
QTest::qWait(50);
class tst_QQuickPinchArea: public QObject
{
Q_OBJECT
+public:
+ tst_QQuickPinchArea() : device(0) { }
private slots:
void initTestCase();
void cleanupTestCase();
private:
QQuickView *createView();
+ QTouchDevice *device;
};
void tst_QQuickPinchArea::initTestCase()
{
+ if (!device) {
+ device = new QTouchDevice;
+ device->setType(QTouchDevice::TouchScreen);
+ QWindowSystemInterface::registerTouchDevice(device);
+ }
}
void tst_QQuickPinchArea::cleanupTestCase()
QPoint p1(80, 80);
QPoint p2(100, 100);
- QTest::touchEvent(canvas).press(0, p1, canvas);
- QTest::touchEvent(canvas).stationary(0).press(1, p2, canvas);
+ QTest::touchEvent(canvas, device).press(0, p1, canvas);
+ QTest::touchEvent(canvas, device).stationary(0).press(1, p2, canvas);
p1 -= QPoint(10,10);
p2 += QPoint(10,10);
- QTest::touchEvent(canvas).move(0, p1,canvas).move(1, p2,canvas);
+ QTest::touchEvent(canvas, device).move(0, p1,canvas).move(1, p2,canvas);
QCOMPARE(root->property("scale").toReal(), 1.0);
p1 -= QPoint(10,10);
p2 += QPoint(10,10);
- QTest::touchEvent(canvas).move(0, p1,canvas).move(1, p2,canvas);
+ QTest::touchEvent(canvas, device).move(0, p1,canvas).move(1, p2,canvas);
QCOMPARE(root->property("scale").toReal(), 1.5);
QCOMPARE(root->property("center").toPointF(), QPointF(40, 40)); // blackrect is at 50,50
// scale beyond bound
p1 -= QPoint(50,50);
p2 += QPoint(50,50);
- QTest::touchEvent(canvas).move(0, p1, canvas).move(1, p2, canvas);
+ QTest::touchEvent(canvas, device).move(0, p1, canvas).move(1, p2, canvas);
QCOMPARE(blackRect->scale(), 2.0);
- QTest::touchEvent(canvas).release(0, p1, canvas).release(1, p2, canvas);
+ QTest::touchEvent(canvas, device).release(0, p1, canvas).release(1, p2, canvas);
delete canvas;
}
QPoint p1(80, 80);
QPoint p2(100, 100);
- QTest::touchEvent(canvas).press(0, p1, canvas);
- QTest::touchEvent(canvas).stationary(0).press(1, p2, canvas);
+ QTest::touchEvent(canvas, device).press(0, p1, canvas);
+ QTest::touchEvent(canvas, device).stationary(0).press(1, p2, canvas);
p1 += QPoint(10,10);
p2 += QPoint(10,10);
- QTest::touchEvent(canvas).move(0, p1, canvas).move(1, p2, canvas);
+ QTest::touchEvent(canvas, device).move(0, p1, canvas).move(1, p2, canvas);
QCOMPARE(root->property("scale").toReal(), 1.0);
p1 += QPoint(10,10);
p2 += QPoint(10,10);
- QTest::touchEvent(canvas).move(0, p1, canvas).move(1, p2, canvas);
+ QTest::touchEvent(canvas, device).move(0, p1, canvas).move(1, p2, canvas);
QCOMPARE(root->property("center").toPointF(), QPointF(60, 60)); // blackrect is at 50,50
// pan x beyond bound
p1 += QPoint(100,100);
p2 += QPoint(100,100);
- QTest::touchEvent(canvas).move(0, p1, canvas).move(1, p2, canvas);
+ QTest::touchEvent(canvas, device).move(0, p1, canvas).move(1, p2, canvas);
QCOMPARE(blackRect->x(), 140.0);
QCOMPARE(blackRect->y(), 160.0);
- QTest::touchEvent(canvas).release(0, p1, canvas).release(1, p2, canvas);
+ QTest::touchEvent(canvas, device).release(0, p1, canvas).release(1, p2, canvas);
delete canvas;
}
QPoint p1(80, 80);
QPoint p2(100, 100);
- QTest::touchEvent(canvas).press(0, p1, canvas);
- QTest::touchEvent(canvas).stationary(0).press(1, p2, canvas);
+ QTest::touchEvent(canvas, device).press(0, p1, canvas);
+ QTest::touchEvent(canvas, device).stationary(0).press(1, p2, canvas);
p1 -= QPoint(10,10);
p2 += QPoint(10,10);
- QTest::touchEvent(canvas).move(0, p1, canvas).move(1, p2, canvas);
+ QTest::touchEvent(canvas, device).move(0, p1, canvas).move(1, p2, canvas);
QCOMPARE(root->property("scale").toReal(), 1.0);
p1 -= QPoint(10,10);
p2 += QPoint(10,10);
- QTest::touchEvent(canvas).move(0, p1, canvas).move(1, p2, canvas);
+ QTest::touchEvent(canvas, device).move(0, p1, canvas).move(1, p2, canvas);
QCOMPARE(startedSpy.count(), 1);
QCOMPARE(startedSpy.count(), 1);
QCOMPARE(finishedSpy.count(), 0);
- QTest::touchEvent(canvas).stationary(0).release(1, p2, canvas);
+ QTest::touchEvent(canvas, device).stationary(0).release(1, p2, canvas);
QCOMPARE(startedSpy.count(), 1);
QCOMPARE(finishedSpy.count(), 0);
QCOMPARE(canvas->rootObject()->property("pointCount").toInt(), 1);
- QTest::touchEvent(canvas).stationary(0).press(1, p2, canvas);
+ QTest::touchEvent(canvas, device).stationary(0).press(1, p2, canvas);
p1 -= QPoint(10,10);
p2 += QPoint(10,10);
- QTest::touchEvent(canvas).move(0, p1, canvas).move(1, p2, canvas);
+ QTest::touchEvent(canvas, device).move(0, p1, canvas).move(1, p2, canvas);
// Lifting and retouching results in onPinchStarted being called again
QCOMPARE(startedSpy.count(), 2);
QCOMPARE(canvas->rootObject()->property("pointCount").toInt(), 2);
- QTest::touchEvent(canvas).release(0, p1, canvas).release(1, p2, canvas);
+ QTest::touchEvent(canvas, device).release(0, p1, canvas).release(1, p2, canvas);
QCOMPARE(startedSpy.count(), 2);
QCOMPARE(finishedSpy.count(), 1);