diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-07-31 14:16:45 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-08-02 11:17:27 +0000 |
commit | 4bfffb22632b8e242d0a430507cf140e68983887 (patch) | |
tree | f0e08939a143f3a3aae0dad55b848ee3f8a14e52 /tests | |
parent | f29e45c082887303561b780f986a896d5aed9b0c (diff) |
tst_qquickwindow: Make touch tests pass with High DPI scaling
Rewrite the tests to use QTouchEvent::TouchPoint instead
of QWindowSystemInterface::TouchPoint and use the convenience
functions QWindowSystemInterfacePrivate to scale them.
Use the new API consisting of position and ellipsis instead
of the QRect based API.
Change-Id: I26f672ef77fe12ef5e9609b61567397bc0808b5e
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickwindow/tst_qquickwindow.cpp | 101 |
1 files changed, 61 insertions, 40 deletions
diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index daa5e53730..7ee9db61f8 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -871,23 +871,29 @@ void tst_qquickwindow::touchEvent_velocity() item->setPosition(QPointF(50, 50)); item->setSize(QSizeF(150, 150)); - QList<QWindowSystemInterface::TouchPoint> points; - QWindowSystemInterface::TouchPoint tp; - tp.id = 1; - tp.state = Qt::TouchPointPressed; - QPoint pos = window->mapToGlobal(item->mapToScene(QPointF(10, 10)).toPoint()); - tp.area = QRectF(pos, QSizeF(4, 4)); + QList<QTouchEvent::TouchPoint> points; + QTouchEvent::TouchPoint tp; + tp.setId(1); + tp.setState(Qt::TouchPointPressed); + const QPointF localPos = item->mapToScene(QPointF(10, 10)); + const QPointF screenPos = window->mapToGlobal(localPos.toPoint()); + tp.setPos(localPos); + tp.setScreenPos(screenPos); + tp.setEllipseDiameters(QSizeF(4, 4)); points << tp; - QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); + QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, + QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window)); QGuiApplication::processEvents(); QQuickTouchUtils::flush(window); QCOMPARE(item->touchEventCount, 1); - points[0].state = Qt::TouchPointMoved; - points[0].area.adjust(5, 5, 5, 5); + points[0].setState(Qt::TouchPointMoved); + points[0].setPos(localPos + QPointF(5, 5)); + points[0].setScreenPos(screenPos + QPointF(5, 5)); QVector2D velocity(1.5, 2.5); - points[0].velocity = velocity; - QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); + points[0].setVelocity(velocity); + QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, + QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window)); QGuiApplication::processEvents(); QQuickTouchUtils::flush(window); QCOMPARE(item->touchEventCount, 2); @@ -899,17 +905,20 @@ void tst_qquickwindow::touchEvent_velocity() QMatrix4x4 transformMatrix; transformMatrix.rotate(-90, 0, 0, 1); // counterclockwise QVector2D transformedVelocity = transformMatrix.mapVector(velocity).toVector2D(); - points[0].area.adjust(5, 5, 5, 5); - QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); + points[0].setPos(points[0].pos() + QPointF(5, 5)); + points[0].setScreenPos(points[0].screenPos() + QPointF(5, 5)); + QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, + QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window)); QGuiApplication::processEvents(); QQuickTouchUtils::flush(window); QCOMPARE(item->lastVelocity, transformedVelocity); - QPoint itemLocalPos = item->mapFromScene(window->mapFromGlobal(points[0].area.center().toPoint())).toPoint(); + QPoint itemLocalPos = item->mapFromScene(points[0].pos()).toPoint(); QPoint itemLocalPosFromEvent = item->lastEvent.touchPoints[0].pos().toPoint(); QCOMPARE(itemLocalPos, itemLocalPosFromEvent); - points[0].state = Qt::TouchPointReleased; - QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); + points[0].setState(Qt::TouchPointReleased); + QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, + QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window)); QGuiApplication::processEvents(); QQuickTouchUtils::flush(window); delete item; @@ -997,25 +1006,32 @@ void tst_qquickwindow::mouseFromTouch_basic() item->setSize(QSizeF(150, 150)); item->acceptTouchEvents = false; - QList<QWindowSystemInterface::TouchPoint> points; - QWindowSystemInterface::TouchPoint tp; - tp.id = 1; - tp.state = Qt::TouchPointPressed; - QPoint pos = window->mapToGlobal(item->mapToScene(QPointF(10, 10)).toPoint()); - tp.area = QRectF(pos, QSizeF(4, 4)); + QList<QTouchEvent::TouchPoint> points; + QTouchEvent::TouchPoint tp; + tp.setId(1); + tp.setState(Qt::TouchPointPressed); + const QPointF localPos = item->mapToScene(QPointF(10, 10)); + const QPointF screenPos = window->mapToGlobal(localPos.toPoint()); + tp.setPos(localPos); + tp.setScreenPos(screenPos); + tp.setEllipseDiameters(QSizeF(4, 4)); points << tp; - QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); + QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, + QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window)); QGuiApplication::processEvents(); QQuickTouchUtils::flush(window); - points[0].state = Qt::TouchPointMoved; - points[0].area.adjust(5, 5, 5, 5); + points[0].setState(Qt::TouchPointMoved); + points[0].setPos(localPos + QPointF(5, 5)); + points[0].setScreenPos(screenPos + QPointF(5, 5)); QVector2D velocity(1.5, 2.5); - points[0].velocity = velocity; - QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); + points[0].setVelocity(velocity); + QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, + QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window)); QGuiApplication::processEvents(); QQuickTouchUtils::flush(window); - points[0].state = Qt::TouchPointReleased; - QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); + points[0].setState(Qt::TouchPointReleased); + QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, + QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window)); QGuiApplication::processEvents(); QQuickTouchUtils::flush(window); @@ -1023,7 +1039,7 @@ void tst_qquickwindow::mouseFromTouch_basic() QCOMPARE(item->mousePressNum, 1); QCOMPARE(item->mouseMoveNum, 1); QCOMPARE(item->mouseReleaseNum, 1); - QCOMPARE(item->lastMousePos.toPoint(), item->mapFromScene(window->mapFromGlobal(points[0].area.center().toPoint())).toPoint()); + QCOMPARE(item->lastMousePos.toPoint(), item->mapFromScene(points[0].pos()).toPoint()); QCOMPARE(item->lastVelocityFromMouseMove, velocity); QVERIFY((item->lastMouseCapabilityFlags & QTouchDevice::Velocity) != 0); @@ -1032,22 +1048,27 @@ void tst_qquickwindow::mouseFromTouch_basic() QMatrix4x4 transformMatrix; transformMatrix.rotate(-90, 0, 0, 1); // counterclockwise QVector2D transformedVelocity = transformMatrix.mapVector(velocity).toVector2D(); - points[0].state = Qt::TouchPointPressed; - points[0].velocity = velocity; - points[0].area = QRectF(pos, QSizeF(4, 4)); - QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); + points[0].setState(Qt::TouchPointPressed); + points[0].setVelocity(velocity); + tp.setPos(localPos); + tp.setScreenPos(screenPos); + QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, + QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window)); QGuiApplication::processEvents(); QQuickTouchUtils::flush(window); - points[0].state = Qt::TouchPointMoved; - points[0].area.adjust(5, 5, 5, 5); - QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); + points[0].setState(Qt::TouchPointMoved); + points[0].setPos(localPos + QPointF(5, 5)); + points[0].setScreenPos(screenPos + QPointF(5, 5)); + QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, + QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window)); QGuiApplication::processEvents(); QQuickTouchUtils::flush(window); - QCOMPARE(item->lastMousePos.toPoint(), item->mapFromScene(window->mapFromGlobal(points[0].area.center().toPoint())).toPoint()); + QCOMPARE(item->lastMousePos.toPoint(), item->mapFromScene(points[0].pos()).toPoint()); QCOMPARE(item->lastVelocityFromMouseMove, transformedVelocity); - points[0].state = Qt::TouchPointReleased; - QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); + points[0].setState(Qt::TouchPointReleased); + QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, + QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window)); QCoreApplication::processEvents(); QQuickTouchUtils::flush(window); delete item; |