summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp')
-rw-r--r--tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp267
1 files changed, 128 insertions, 139 deletions
diff --git a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
index cc86e866f6..37ddcb8962 100644
--- a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
+++ b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the $MODULE$ of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtGui/QCursor>
#include <QtGui/QScreen>
@@ -34,12 +9,18 @@
#include <QtWidgets/QGraphicsWidget>
#include <QtWidgets/QWidget>
#include <QTest>
+#include <QSet>
+#include <QVarLengthArray>
#include <qpa/qwindowsysteminterface.h>
#include <qpa/qwindowsysteminterface_p.h>
#include <private/qevent_p.h>
#include <QtGui/private/qeventpoint_p.h>
#include <private/qhighdpiscaling_p.h>
#include <private/qpointingdevice_p.h>
+#include <private/qguiapplication_p.h>
+#include <qpa/qplatformintegration.h>
+
+#include <QtCore/qpointer.h>
Q_LOGGING_CATEGORY(lcTests, "qt.gui.tests")
@@ -69,6 +50,24 @@ public:
deleteInTouchBegin = deleteInTouchUpdate = deleteInTouchEnd = false;
}
+ void paintEvent(QPaintEvent *) override
+ {
+ QPainter painter(this);
+ painter.drawRect(rect());
+ painter.setPen(Qt::darkGray);
+ painter.drawText(rect(), Qt::AlignHCenter | Qt::AlignCenter, objectName());
+ static const QString pointFormat = QString::fromUtf8("\360\237\226\227 %1, %2");
+ painter.setPen(Qt::darkGreen);
+ for (const auto &pt : std::as_const(touchBeginPoints))
+ painter.drawText(pt.position(), pointFormat.arg(pt.position().toPoint().x()).arg(pt.position().toPoint().y()));
+ painter.setPen(Qt::darkYellow);
+ for (const auto &pt : std::as_const(touchUpdatePoints))
+ painter.drawText(pt.position(), pointFormat.arg(pt.position().toPoint().x()).arg(pt.position().toPoint().y()));
+ painter.setPen(Qt::darkRed);
+ for (const auto &pt : std::as_const(touchEndPoints))
+ painter.drawText(pt.position(), pointFormat.arg(pt.position().toPoint().x()).arg(pt.position().toPoint().y()));
+ }
+
bool event(QEvent *event) override
{
lastNormalizedPositions.clear();
@@ -82,13 +81,15 @@ public:
auto touchEvent = static_cast<QTouchEvent *>(event);
touchBeginPoints = touchEvent->points();
Q_ASSERT(touchBeginPoints.first().device() == touchEvent->pointingDevice());
- for (const QEventPoint &pt : qAsConst(touchBeginPoints))
+ for (const QEventPoint &pt : std::as_const(touchBeginPoints))
lastNormalizedPositions << pt.normalizedPosition();
timestamp = touchEvent->timestamp();
deviceFromEvent = touchEvent->pointingDevice();
event->setAccepted(acceptTouchBegin);
if (deleteInTouchBegin)
delete this;
+ else
+ update();
break;
}
case QEvent::TouchUpdate: {
@@ -98,13 +99,15 @@ public:
seenTouchUpdate = seenTouchBegin && !seenTouchEnd;
auto touchEvent = static_cast<QTouchEvent *>(event);
touchUpdatePoints = touchEvent->points();
- for (const QEventPoint &pt : qAsConst(touchUpdatePoints))
+ for (const QEventPoint &pt : std::as_const(touchUpdatePoints))
lastNormalizedPositions << pt.normalizedPosition();
timestamp = touchEvent->timestamp();
deviceFromEvent = touchEvent->pointingDevice();
event->setAccepted(acceptTouchUpdate);
if (deleteInTouchUpdate)
delete this;
+ else
+ update();
break;
}
case QEvent::TouchEnd: {
@@ -114,13 +117,15 @@ public:
seenTouchEnd = seenTouchBegin && !seenTouchEnd;
auto touchEvent = static_cast<QTouchEvent *>(event);
touchEndPoints = touchEvent->points();
- for (const QEventPoint &pt : qAsConst(touchEndPoints))
+ for (const QEventPoint &pt : std::as_const(touchEndPoints))
lastNormalizedPositions << pt.normalizedPosition();
timestamp = touchEvent->timestamp();
deviceFromEvent = touchEvent->pointingDevice();
event->setAccepted(acceptTouchEnd);
if (deleteInTouchEnd)
delete this;
+ else
+ update();
break;
}
default:
@@ -366,9 +371,11 @@ void tst_QTouchEvent::state()
QVERIFY(!touchEvent3.isBeginEvent());
QVERIFY(!touchEvent3.isUpdateEvent());
QVERIFY(touchEvent3.isEndEvent());
+#if QT_DEPRECATED_SINCE(6, 0)
QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED // test Qt 5 compatibility wrappers
QCOMPARE(touchEvent3.touchPoints(), touchEvent3.points());
QT_WARNING_POP
+#endif
}
void tst_QTouchEvent::touchDisabledByDefault()
@@ -729,7 +736,7 @@ void tst_QTouchEvent::basicRawEventTranslation()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(!touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchBeginPoints.count(), 1);
+ QCOMPARE(touchWidget.touchBeginPoints.size(), 1);
QCOMPARE(touchWidget.timestamp, timestamp);
QEventPoint touchBeginPoint = touchWidget.touchBeginPoints.first();
QCOMPARE(touchBeginPoint.id(), 0);
@@ -759,7 +766,7 @@ void tst_QTouchEvent::basicRawEventTranslation()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchUpdatePoints.count(), 1);
+ QCOMPARE(touchWidget.touchUpdatePoints.size(), 1);
QEventPoint touchUpdatePoint = touchWidget.touchUpdatePoints.first();
QCOMPARE(touchUpdatePoint.id(), 0);
QCOMPARE(touchUpdatePoint.state(), rawTouchPoint.state());
@@ -787,7 +794,7 @@ void tst_QTouchEvent::basicRawEventTranslation()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchEndPoints.count(), 1);
+ QCOMPARE(touchWidget.touchEndPoints.size(), 1);
QEventPoint touchEndPoint = touchWidget.touchEndPoints.first();
QCOMPARE(touchEndPoint.id(), 0);
QCOMPARE(touchEndPoint.state(), rawTouchPoint.state());
@@ -810,9 +817,11 @@ void tst_QTouchEvent::basicRawEventTranslation()
void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
{
tst_QTouchEventWidget touchWidget;
+ touchWidget.setObjectName("parent touch widget");
touchWidget.setWindowTitle(QTest::currentTestFunction());
touchWidget.setAttribute(Qt::WA_AcceptTouchEvents);
- touchWidget.setGeometry(100, 100, 400, 300);
+ const QPoint topLeft = QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(100, 100);
+ touchWidget.setGeometry({topLeft, QSize(400, 300)});
tst_QTouchEventWidget leftWidget(&touchWidget);
leftWidget.setObjectName("leftWidget");
@@ -826,24 +835,25 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
touchWidget.show();
QVERIFY(QTest::qWaitForWindowExposed(&touchWidget));
+ if (touchWidget.geometry().topLeft() != topLeft) {
+ qCDebug(lcTests) << "tried to set position 100, 100 on screen; got geometry"
+ << touchWidget.geometry() << "frame" << touchWidget.frameGeometry();
+ QSKIP("failed to position the widget window on this platform");
+ }
- QPointF leftPos = leftWidget.rect().center();
- QPointF rightPos = rightWidget.rect().center();
- QPointF centerPos = touchWidget.rect().center();
- QPointF leftScreenPos = leftWidget.mapToGlobal(leftPos.toPoint());
- QPointF rightScreenPos = rightWidget.mapToGlobal(rightPos.toPoint());
- QPointF centerScreenPos = touchWidget.mapToGlobal(centerPos.toPoint());
+ QPoint leftPos = leftWidget.rect().center();
+ QPoint rightPos = rightWidget.rect().center();
+ QPoint centerPos = touchWidget.rect().center();
+ QPoint leftScenePos = leftWidget.mapToParent(leftPos);
+ QPoint rightScenePos = rightWidget.mapToParent(rightPos);
+ QPoint leftScreenPos = leftWidget.mapToGlobal(leftPos);
+ QPoint rightScreenPos = rightWidget.mapToGlobal(rightPos);
+ QPoint centerScreenPos = touchWidget.mapToGlobal(centerPos);
// generate TouchBegins on both leftWidget and rightWidget
- ulong timestamp = 0;
- auto rawTouchPoints = QList<QEventPoint>()
- << QEventPoint(0, QEventPoint::State::Pressed, QPointF(), leftScreenPos)
- << QEventPoint(1, QEventPoint::State::Pressed, QPointF(), rightScreenPos);
- QWindow *window = touchWidget.windowHandle();
- QList<QWindowSystemInterface::TouchPoint> nativeTouchPoints =
- QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window);
- QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints);
- QCoreApplication::processEvents();
+ auto touchSequence = QTest::touchEvent(touchWidget.windowHandle(), touchScreenDevice);
+ touchSequence.press(0, leftScenePos).press(1, rightScenePos);
+ QVERIFY(touchSequence.commit()); // verify acceptance
QVERIFY(!touchWidget.seenTouchBegin);
QVERIFY(!touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
@@ -853,14 +863,14 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QVERIFY(rightWidget.seenTouchBegin);
QVERIFY(!rightWidget.seenTouchUpdate);
QVERIFY(!rightWidget.seenTouchEnd);
- QCOMPARE(leftWidget.touchBeginPoints.count(), 1);
- QCOMPARE(rightWidget.touchBeginPoints.count(), 1);
+ QCOMPARE(leftWidget.touchBeginPoints.size(), 1);
+ QCOMPARE(rightWidget.touchBeginPoints.size(), 1);
const int touchPointId0 = 0;
const int touchPointId1 = touchPointId0 + 1;
{
- QEventPoint leftTouchPoint = leftWidget.touchBeginPoints.first();
+ const QEventPoint &leftTouchPoint = leftWidget.touchBeginPoints.first();
QCOMPARE(leftTouchPoint.id(), touchPointId0);
- QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state());
+ QCOMPARE(leftTouchPoint.state(), QEventPoint::Pressed);
QCOMPARE(leftTouchPoint.position(), leftPos);
QCOMPARE(leftTouchPoint.pressPosition(), leftPos);
QCOMPARE(leftTouchPoint.lastPosition(), leftPos);
@@ -870,15 +880,12 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QCOMPARE(leftTouchPoint.globalPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos);
- QCOMPARE(leftTouchPoint.position(), leftPos);
- QCOMPARE(leftTouchPoint.scenePosition(), leftScreenPos);
- QCOMPARE(leftTouchPoint.globalPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.ellipseDiameters(), QSizeF(0, 0));
QCOMPARE(leftTouchPoint.pressure(), qreal(1.));
- QEventPoint rightTouchPoint = rightWidget.touchBeginPoints.first();
+ const QEventPoint &rightTouchPoint = rightWidget.touchBeginPoints.first();
QCOMPARE(rightTouchPoint.id(), touchPointId1);
- QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state());
+ QCOMPARE(rightTouchPoint.state(), QEventPoint::Pressed);
QCOMPARE(rightTouchPoint.position(), rightPos);
QCOMPARE(rightTouchPoint.pressPosition(), rightPos);
QCOMPARE(rightTouchPoint.lastPosition(), rightPos);
@@ -888,20 +895,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QCOMPARE(rightTouchPoint.globalPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos);
- QCOMPARE(rightTouchPoint.position(), rightPos);
- QCOMPARE(rightTouchPoint.scenePosition(), rightScreenPos);
- QCOMPARE(rightTouchPoint.globalPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.ellipseDiameters(), QSizeF(0, 0));
QCOMPARE(rightTouchPoint.pressure(), qreal(1.));
}
- rawTouchPoints.clear();
- rawTouchPoints << QEventPoint(0, QEventPoint::State::Updated, QPointF(), centerScreenPos)
- << QEventPoint(1, QEventPoint::State::Updated, QPointF(), centerScreenPos);
- nativeTouchPoints =
- QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window);
- QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints);
- QCoreApplication::processEvents();
+ // an unlikely event with the two touchpoints moving exactly on top of each other
+ touchSequence.move(0, centerPos).move(1, centerPos);
+ QVERIFY(touchSequence.commit()); // verify acceptance
QVERIFY(!touchWidget.seenTouchBegin);
QVERIFY(!touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
@@ -911,13 +911,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QVERIFY(rightWidget.seenTouchBegin);
QVERIFY(rightWidget.seenTouchUpdate);
QVERIFY(!rightWidget.seenTouchEnd);
- QCOMPARE(leftWidget.touchUpdatePoints.count(), 1);
- QCOMPARE(rightWidget.touchUpdatePoints.count(), 1);
+ QCOMPARE(leftWidget.touchUpdatePoints.size(), 1);
+ QCOMPARE(rightWidget.touchUpdatePoints.size(), 1);
{
- QEventPoint leftTouchPoint = leftWidget.touchUpdatePoints.first();
+ const QEventPoint &leftTouchPoint = leftWidget.touchUpdatePoints.first();
QCOMPARE(leftTouchPoint.id(), touchPointId0);
- QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state());
- QCOMPARE(leftTouchPoint.position(), QPointF(leftWidget.mapFromParent(centerPos.toPoint())));
+ QCOMPARE(leftTouchPoint.state(), QEventPoint::Updated);
+ QCOMPARE(leftTouchPoint.position(), QPointF(leftWidget.mapFromParent(centerPos)));
QCOMPARE(leftTouchPoint.pressPosition(), leftPos);
QCOMPARE(leftTouchPoint.lastPosition(), leftPos);
QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos);
@@ -926,16 +926,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos);
- QCOMPARE(leftTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint()));
- QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos);
- QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(leftTouchPoint.ellipseDiameters(), QSizeF(0, 0));
QCOMPARE(leftTouchPoint.pressure(), qreal(1.));
- QEventPoint rightTouchPoint = rightWidget.touchUpdatePoints.first();
+ const QEventPoint &rightTouchPoint = rightWidget.touchUpdatePoints.first();
QCOMPARE(rightTouchPoint.id(), touchPointId1);
- QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state());
- QCOMPARE(rightTouchPoint.position(), QPointF(rightWidget.mapFromParent(centerPos.toPoint())));
+ QCOMPARE(rightTouchPoint.state(), QEventPoint::Updated);
+ QCOMPARE(rightTouchPoint.position(), QPointF(rightWidget.mapFromParent(centerPos)));
QCOMPARE(rightTouchPoint.pressPosition(), rightPos);
QCOMPARE(rightTouchPoint.lastPosition(), rightPos);
QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos);
@@ -944,21 +941,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos);
- QCOMPARE(rightTouchPoint.position(), rightWidget.mapFromParent(centerPos.toPoint()));
- QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos);
- QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(rightTouchPoint.ellipseDiameters(), QSizeF(0, 0));
QCOMPARE(rightTouchPoint.pressure(), qreal(1.));
}
// generate TouchEnds on both leftWidget and rightWidget
- rawTouchPoints.clear();
- rawTouchPoints << QEventPoint(0, QEventPoint::State::Released, QPointF(), centerScreenPos)
- << QEventPoint(1, QEventPoint::State::Released, QPointF(), centerScreenPos);
- nativeTouchPoints =
- QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window);
- QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints);
- QCoreApplication::processEvents();
+ touchSequence.release(0, centerPos).release(1, centerPos);
+ QVERIFY(touchSequence.commit()); // verify acceptance
QVERIFY(!touchWidget.seenTouchBegin);
QVERIFY(!touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
@@ -968,13 +957,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QVERIFY(rightWidget.seenTouchBegin);
QVERIFY(rightWidget.seenTouchUpdate);
QVERIFY(rightWidget.seenTouchEnd);
- QCOMPARE(leftWidget.touchEndPoints.count(), 1);
- QCOMPARE(rightWidget.touchEndPoints.count(), 1);
+ QCOMPARE(leftWidget.touchEndPoints.size(), 1);
+ QCOMPARE(rightWidget.touchEndPoints.size(), 1);
{
- QEventPoint leftTouchPoint = leftWidget.touchEndPoints.first();
+ const QEventPoint &leftTouchPoint = leftWidget.touchEndPoints.first();
QCOMPARE(leftTouchPoint.id(), touchPointId0);
- QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state());
- QCOMPARE(leftTouchPoint.position(), QPointF(leftWidget.mapFromParent(centerPos.toPoint())));
+ QCOMPARE(leftTouchPoint.state(), QEventPoint::Released);
+ QCOMPARE(leftTouchPoint.position(), QPointF(leftWidget.mapFromParent(centerPos)));
QCOMPARE(leftTouchPoint.pressPosition(), leftPos);
QCOMPARE(leftTouchPoint.lastPosition(), leftPos);
QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos);
@@ -983,16 +972,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos);
- QCOMPARE(leftTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint()));
- QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos);
- QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(leftTouchPoint.ellipseDiameters(), QSizeF(0, 0));
QCOMPARE(leftTouchPoint.pressure(), qreal(0.));
- QEventPoint rightTouchPoint = rightWidget.touchEndPoints.first();
+ const QEventPoint &rightTouchPoint = rightWidget.touchEndPoints.first();
QCOMPARE(rightTouchPoint.id(), touchPointId1);
- QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state());
- QCOMPARE(rightTouchPoint.position(), QPointF(rightWidget.mapFromParent(centerPos.toPoint())));
+ QCOMPARE(rightTouchPoint.state(), QEventPoint::Released);
+ QCOMPARE(rightTouchPoint.position(), QPointF(rightWidget.mapFromParent(centerPos)));
QCOMPARE(rightTouchPoint.pressPosition(), rightPos);
QCOMPARE(rightTouchPoint.lastPosition(), rightPos);
QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos);
@@ -1001,9 +987,6 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos);
- QCOMPARE(rightTouchPoint.position(), rightWidget.mapFromParent(centerPos.toPoint()));
- QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos);
- QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(rightTouchPoint.ellipseDiameters(), QSizeF(0, 0));
QCOMPARE(rightTouchPoint.pressure(), qreal(0.));
}
@@ -1033,7 +1016,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(!touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchBeginPoints.count(), 1);
+ QCOMPARE(touchWidget.touchBeginPoints.size(), 1);
QCOMPARE(touchWidget.timestamp, timestamp);
QEventPoint touchBeginPoint = touchWidget.touchBeginPoints.first();
QCOMPARE(touchBeginPoint.id(), 1);
@@ -1048,7 +1031,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
QWindowSystemInterface::handleTouchEvent(window, ++timestamp, secondaryTouchScreenDevice, nativeTouchPoints);
QCoreApplication::processEvents();
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchBeginPoints.count(), 1);
+ QCOMPARE(touchWidget.touchBeginPoints.size(), 1);
QCOMPARE(touchWidget.timestamp, timestamp);
touchBeginPoint = touchWidget.touchBeginPoints[0];
QCOMPARE(touchBeginPoint.id(), 10);
@@ -1063,7 +1046,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
QWindowSystemInterface::handleTouchEvent(window, ++timestamp, secondaryTouchScreenDevice, nativeTouchPoints);
QCoreApplication::processEvents();
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchBeginPoints.count(), 1);
+ QCOMPARE(touchWidget.touchBeginPoints.size(), 1);
QCOMPARE(touchWidget.timestamp, timestamp);
touchBeginPoint = touchWidget.touchBeginPoints[0];
QCOMPARE(touchBeginPoint.id(), 11);
@@ -1079,7 +1062,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchUpdatePoints.count(), 1);
+ QCOMPARE(touchWidget.touchUpdatePoints.size(), 1);
QEventPoint touchUpdatePoint = touchWidget.touchUpdatePoints.first();
QCOMPARE(touchUpdatePoint.id(), 1);
QCOMPARE(touchUpdatePoint.state(), QEventPoint::State::Updated);
@@ -1094,7 +1077,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchEndPoints.count(), 1);
+ QCOMPARE(touchWidget.touchEndPoints.size(), 1);
QEventPoint touchEndPoint = touchWidget.touchEndPoints.first();
QCOMPARE(touchEndPoint.id(), 1);
QCOMPARE(touchEndPoint.state(), QEventPoint::State::Released);
@@ -1119,7 +1102,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchUpdatePoints.count(), 2);
+ QCOMPARE(touchWidget.touchUpdatePoints.size(), 2);
QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 10);
QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 11);
@@ -1134,7 +1117,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchEndPoints.count(), 1);
+ QCOMPARE(touchWidget.touchEndPoints.size(), 1);
touchEndPoint = touchWidget.touchEndPoints.first();
QCOMPARE(touchEndPoint.id(), 11);
QCOMPARE(touchEndPoint.state(), QEventPoint::State::Released);
@@ -1150,6 +1133,9 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QSKIP("The macOS mouse cursor interferes with this test can cannot be moved away");
#endif
+ if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))
+ QSKIP("QWindow::requestActivate() is not supported.");
+
tst_QTouchEventWidget touchWidget;
touchWidget.setObjectName("touchWidget");
touchWidget.setWindowTitle(QTest::currentTestFunction());
@@ -1168,7 +1154,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
rightWidget.setGeometry(300, 100, 100, 100);
touchWidget.show();
- QVERIFY(QTest::qWaitForWindowExposed(&touchWidget));
+ QVERIFY(QTest::qWaitForWindowActive(&touchWidget));
const QPointF leftPos = leftWidget.rect().center();
const QPointF rightPos = rightWidget.rect().center();
@@ -1206,8 +1192,9 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QVERIFY(!rightWidget.seenTouchBegin);
QVERIFY(!rightWidget.seenTouchUpdate);
QVERIFY(!rightWidget.seenTouchEnd);
- QCOMPARE(leftWidget.touchBeginPoints.count(), 2);
- QCOMPARE(rightWidget.touchBeginPoints.count(), 0);
+ QCOMPARE(leftWidget.touchBeginPoints.size(), 2);
+ QCOMPARE(rightWidget.touchBeginPoints.size(), 0);
+ QCOMPARE(leftWidget.lastNormalizedPositions.size(), 2);
{
QEventPoint leftTouchPoint = leftWidget.touchBeginPoints.at(0);
qCDebug(lcTests) << "lastNormalizedPositions after press" << leftWidget.lastNormalizedPositions;
@@ -1223,7 +1210,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QCOMPARE(leftTouchPoint.globalPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos);
- QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.2) < 0.05); // 0.198, might depend on window frame size
+ QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.2), 0.05); // 0.198, might depend on window frame size
QCOMPARE(leftTouchPoint.position(), leftPos);
QCOMPARE(leftTouchPoint.scenePosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalPosition(), leftScreenPos);
@@ -1243,7 +1230,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QCOMPARE(rightTouchPoint.globalPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos);
- QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.8) < 0.05); // 0.798, might depend on window frame size
+ QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.8), 0.05); // 0.798, might depend on window frame size
QCOMPARE(rightTouchPoint.scenePosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.ellipseDiameters(), QSizeF(0, 0));
@@ -1268,8 +1255,9 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QVERIFY(!rightWidget.seenTouchBegin);
QVERIFY(!rightWidget.seenTouchUpdate);
QVERIFY(!rightWidget.seenTouchEnd);
- QCOMPARE(leftWidget.touchUpdatePoints.count(), 2);
- QCOMPARE(rightWidget.touchUpdatePoints.count(), 0);
+ QCOMPARE(leftWidget.touchUpdatePoints.size(), 2);
+ QCOMPARE(rightWidget.touchUpdatePoints.size(), 0);
+ QCOMPARE(leftWidget.lastNormalizedPositions.size(), 2);
{
QEventPoint leftTouchPoint = leftWidget.touchUpdatePoints.at(0);
qCDebug(lcTests) << "lastNormalizedPositions after update" << leftWidget.lastNormalizedPositions;
@@ -1285,7 +1273,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos);
- QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.5) < 0.05); // 0.498, might depend on window frame size
+ QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.5), 0.05); // 0.498, might depend on window frame size
QCOMPARE(leftTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint()));
QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos);
QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos);
@@ -1305,7 +1293,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos);
- QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.5) < 0.05); // 0.498, might depend on window frame size
+ QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.5), 0.05); // 0.498, might depend on window frame size
QCOMPARE(rightTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint()));
QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos);
QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos);
@@ -1330,8 +1318,9 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QVERIFY(!rightWidget.seenTouchBegin);
QVERIFY(!rightWidget.seenTouchUpdate);
QVERIFY(!rightWidget.seenTouchEnd);
- QCOMPARE(leftWidget.touchEndPoints.count(), 2);
- QCOMPARE(rightWidget.touchEndPoints.count(), 0);
+ QCOMPARE(leftWidget.touchEndPoints.size(), 2);
+ QCOMPARE(rightWidget.touchEndPoints.size(), 0);
+ QCOMPARE(leftWidget.lastNormalizedPositions.size(), 2);
{
QEventPoint leftTouchPoint = leftWidget.touchEndPoints.at(0);
qCDebug(lcTests) << "lastNormalizedPositions after release" << leftWidget.lastNormalizedPositions;
@@ -1348,7 +1337,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos);
- QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.5) < 0.05); // 0.498, might depend on window frame size
+ QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.5), 0.05); // 0.498, might depend on window frame size
QCOMPARE(leftTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint()));
QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos);
QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos);
@@ -1368,7 +1357,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos);
- QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.5) < 0.05); // 0.498, might depend on window frame size
+ QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.5), 0.05); // 0.498, might depend on window frame size
QCOMPARE(rightTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint()));
QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos);
QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos);
@@ -1414,16 +1403,16 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(!touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchBeginPoints.count(), 2);
+ QCOMPARE(touchWidget.touchBeginPoints.size(), 2);
- for (int i = 0; i < touchWidget.touchBeginPoints.count(); ++i) {
+ for (int i = 0; i < touchWidget.touchBeginPoints.size(); ++i) {
QEventPoint touchBeginPoint = touchWidget.touchBeginPoints.at(i);
QCOMPARE(touchBeginPoint.id(), i);
QCOMPARE(touchBeginPoint.state(), rawTouchPoints[i].state());
}
// moving the point should translate to TouchUpdate
- for (int i = 0; i < rawTouchPoints.count(); ++i) {
+ for (int i = 0; i < rawTouchPoints.size(); ++i) {
auto &p = rawTouchPoints[i];
QMutableEventPoint::setState(p, QEventPoint::State::Updated);
QMutableEventPoint::setGlobalPosition(p, p.globalPosition() + delta);
@@ -1435,7 +1424,7 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchUpdatePoints.count(), 2);
+ QCOMPARE(touchWidget.touchUpdatePoints.size(), 2);
QCOMPARE(touchWidget.touchUpdatePoints.at(0).id(), 0);
QCOMPARE(touchWidget.touchUpdatePoints.at(1).id(), 1);
@@ -1450,7 +1439,7 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QCOMPARE(touchWidget.seenTouchEnd, false);
- QCOMPARE(touchWidget.touchUpdatePoints.count(), 2);
+ QCOMPARE(touchWidget.touchUpdatePoints.size(), 2);
QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 0);
QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 1);
@@ -1464,7 +1453,7 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchUpdatePoints.count(), 2);
+ QCOMPARE(touchWidget.touchUpdatePoints.size(), 2);
QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 0);
QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 42);
@@ -1478,7 +1467,7 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchUpdatePoints.count(), 2);
+ QCOMPARE(touchWidget.touchUpdatePoints.size(), 2);
QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 0);
QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 42);
}
@@ -1842,25 +1831,25 @@ void tst_QTouchEvent::testQGuiAppDelivery()
// Now the real thing.
QWindowSystemInterface::handleTouchEvent(&w, touchScreenDevice, points); // TouchBegin
QCoreApplication::processEvents();
- QCOMPARE(filter.d.count(), 1);
+ QCOMPARE(filter.d.size(), 1);
QCOMPARE(filter.d.contains(touchScreenDevice), true);
- QCOMPARE(filter.d.value(touchScreenDevice).points.count(), 1);
+ QCOMPARE(filter.d.value(touchScreenDevice).points.size(), 1);
QCOMPARE(filter.d.value(touchScreenDevice).lastSeenType, QEvent::TouchBegin);
points[0].state = QEventPoint::State::Updated;
QWindowSystemInterface::handleTouchEvent(&w, touchScreenDevice, points); // TouchUpdate
QCoreApplication::processEvents();
- QCOMPARE(filter.d.count(), 1);
+ QCOMPARE(filter.d.size(), 1);
QCOMPARE(filter.d.contains(touchScreenDevice), true);
- QCOMPARE(filter.d.value(touchScreenDevice).points.count(), 2);
+ QCOMPARE(filter.d.value(touchScreenDevice).points.size(), 2);
QCOMPARE(filter.d.value(touchScreenDevice).lastSeenType, QEvent::TouchUpdate);
points[0].state = QEventPoint::State::Released;
QWindowSystemInterface::handleTouchEvent(&w, touchScreenDevice, points); // TouchEnd
QCoreApplication::processEvents();
- QCOMPARE(filter.d.count(), 1);
+ QCOMPARE(filter.d.size(), 1);
QCOMPARE(filter.d.contains(touchScreenDevice), true);
- QCOMPARE(filter.d.value(touchScreenDevice).points.count(), 3);
+ QCOMPARE(filter.d.value(touchScreenDevice).points.size(), 3);
QCOMPARE(filter.d.value(touchScreenDevice).lastSeenType, QEvent::TouchEnd);
}
@@ -1903,8 +1892,8 @@ void tst_QTouchEvent::testMultiDevice()
QCOMPARE(filter.d.value(touchScreenDevice).lastSeenType, QEvent::TouchBegin);
QCOMPARE(filter.d.value(deviceTwo).lastSeenType, QEvent::TouchBegin);
- QCOMPARE(filter.d.value(touchScreenDevice).points.count(), 1);
- QCOMPARE(filter.d.value(deviceTwo).points.count(), 2);
+ QCOMPARE(filter.d.value(touchScreenDevice).points.size(), 1);
+ QCOMPARE(filter.d.value(deviceTwo).points.size(), 2);
QCOMPARE(filter.d.value(touchScreenDevice).points.at(0).globalPosition(), area0.center());
// This fails because QGuiApplicationPrivate::processTouchEvent() sends synth-mouse events
@@ -1959,7 +1948,7 @@ void tst_QTouchEvent::grabbers()
// Ensure that grabbers are persistent between events, within the stored touchpoints
QCOMPARE(devPriv->pointById(0)->exclusiveGrabber, grabExclusive ? &w : nullptr);
- QCOMPARE(devPriv->pointById(0)->passiveGrabbers.count(), grabPassive ? 1 : 0);
+ QCOMPARE(devPriv->pointById(0)->passiveGrabbers.size(), grabPassive ? 1 : 0);
if (grabPassive)
QCOMPARE(devPriv->pointById(0)->passiveGrabbers.first(), &w);