Reset touchPoint position after it was remaped

The position of touch points is modified in the function updateTouchData
when triggered from a filter. The position is never reset and thus wrong
in other parts of the code. This patch resets the position after the
required stuff in the offset coordinate system is done.

Fixes: QTBUG-105862
Change-Id: Idd12af0d509e46d0ac74fb920c70e9ec6411c255
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 99a48bef84)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Matthias Rauter 2023-06-06 16:31:02 +02:00 committed by Qt Cherry-pick Bot
parent 34c76c7c47
commit a7ec3a6291
3 changed files with 79 additions and 0 deletions

View File

@ -626,6 +626,8 @@ void QQuickMultiPointTouchArea::updateTouchData(QEvent *event, RemapEventPoints
}
if (numTouchPoints >= _minimumTouchPoints && numTouchPoints <= _maximumTouchPoints) {
for (QEventPoint &p : touchPoints) {
QPointF oldPos = p.position();
auto transformBack = qScopeGuard([&] { QMutableEventPoint::setPosition(p, oldPos); });
if (touchPointsFromEvent && remap == RemapEventPoints::ToLocal)
QMutableEventPoint::setPosition(p, mapFromScene(p.scenePosition()));
QEventPoint::State touchPointState = p.state();

View File

@ -0,0 +1,52 @@
import QtQuick
import QtTest
Item {
width: 300; height: 200
id: topLevelItem
MultiPointTouchArea {
objectName: "topMPTA"
anchors.fill: parent
Column {
width: parent.width
height: parent.height
Rectangle {
width: parent.width
height: 100
color: "green"
}
Rectangle {
id: rect
width: parent.width
height: 600
color: "red"
MultiPointTouchArea {
property var xPressed: 0
property var yPressed: 0
property var xReleased: 0
property var yReleased: 0
objectName: "bottomMPTA"
anchors.fill: parent
onPressed: (touchPoints) => {
for (let tp in touchPoints) {
let touch = touchPoints[tp]
xPressed = touch.x
yPressed = touch.y
}
}
onReleased: (touchPoints) => {
for (let tp in touchPoints) {
let touch = touchPoints[tp]
xReleased = touch.x
yReleased = touch.y
}
}
}
}
}
}
}

View File

@ -36,6 +36,7 @@ private slots:
void reuse();
void nonOverlapping();
void nested();
void nestedTouchPosCheck();
void inFlickable();
void inFlickable2();
void inFlickableWithPressDelay();
@ -560,6 +561,30 @@ void tst_QQuickMultiPointTouchArea::nested()
QQuickTouchUtils::flush(window.data());
}
void tst_QQuickMultiPointTouchArea::nestedTouchPosCheck()
{
QScopedPointer<QQuickView> window(createAndShowView("nestedTouchPosCheck.qml"));
QVERIFY(window->rootObject() != nullptr);
auto *bottomMPTA = window->rootObject()->findChild<QQuickMultiPointTouchArea *>("bottomMPTA");
QVERIFY(bottomMPTA != nullptr);
QTest::QTouchEventSequence sequence = QTest::touchEvent(window.data(), device);
sequence.press(0, QPoint(10, 110)).commit();
QQuickTouchUtils::flush(window.data());
sequence.release(0, QPoint(10, 110)).commit();
QQuickTouchUtils::flush(window.data());
QCOMPARE(bottomMPTA->property("xPressed").toInt(), 10);
QCOMPARE(bottomMPTA->property("yPressed").toInt(), 10);
QCOMPARE(bottomMPTA->property("xReleased").toInt(), 10);
QCOMPARE(bottomMPTA->property("yReleased").toInt(), 10);
}
void tst_QQuickMultiPointTouchArea::inFlickable()
{
QScopedPointer<QQuickView> window(createAndShowView("inFlickable.qml"));