aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeokha Ko <seokha.ko@qt.io>2022-09-02 18:10:08 +0900
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-09-14 04:28:22 +0000
commit5c29007f859ec5bd66cbaa0708f111bd36aaaf78 (patch)
tree09ac36999e8192c45dd43f9dffe87301e98c1dfc
parent3c38cee25e8056fddbfcc245d3ddd8a9d46b9116 (diff)
PinchArea: Keep the touch/mouse grab when pinch activated
Keep the touch/mouse grab when pinch activated to prevent childMouseEventFilter of parent from stealing the event Amends 10800723ab6dacf1203986a6b0815dec45528ef4 Fixes: QTBUG-105058 Change-Id: I6589b7d9cc5cc51ffe5dcaac137d1608604db572 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> (cherry picked from commit 4461dfc06b4b1b4bd97a0972ca10a1ab4d53a4c3) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quick/items/qquickpincharea.cpp4
-rw-r--r--tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp56
2 files changed, 60 insertions, 0 deletions
diff --git a/src/quick/items/qquickpincharea.cpp b/src/quick/items/qquickpincharea.cpp
index 74f00c22b9..37458542d3 100644
--- a/src/quick/items/qquickpincharea.cpp
+++ b/src/quick/items/qquickpincharea.cpp
@@ -442,6 +442,7 @@ void QQuickPinchArea::updatePinch(QTouchEvent *event, bool filtering)
if (d->touchPoints.count() < 2) {
// A pinch gesture is not occurring, so stealing the grab is permitted.
setKeepTouchGrab(false);
+ setKeepMouseGrab(false);
// During filtering, there's no need to hold a grab for one point,
// because filtering happens for every event anyway.
// But if we receive the event via direct delivery, and give up the grab,
@@ -465,6 +466,7 @@ void QQuickPinchArea::updatePinch(QTouchEvent *event, bool filtering)
pe.setStartPoint2(mapFromScene(d->sceneStartPoint2));
pe.setPoint1(mapFromScene(d->lastPoint1));
pe.setPoint2(mapFromScene(d->lastPoint2));
+ setKeepTouchGrab(false);
setKeepMouseGrab(false);
emit pinchFinished(&pe);
d->pinchStartDist = 0;
@@ -502,6 +504,8 @@ void QQuickPinchArea::updatePinch(QTouchEvent *event, bool filtering)
d->initPinch = true;
event->setExclusiveGrabber(touchPoint1, this);
event->setExclusiveGrabber(touchPoint2, this);
+ setKeepTouchGrab(true);
+ setKeepMouseGrab(true);
}
if (d->pinchActivated && !d->pinchRejected) {
const int dragThreshold = QGuiApplication::styleHints()->startDragDistance();
diff --git a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp
index 25836cac68..17e225f1e2 100644
--- a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp
+++ b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp
@@ -58,6 +58,7 @@ private slots:
void dragTransformedPinchArea_data();
void dragTransformedPinchArea();
void pinchAreaKeepsDragInView();
+ void pinchInPathView();
private:
QQuickView *createView();
@@ -732,6 +733,61 @@ void tst_QQuickPinchArea::pinchAreaKeepsDragInView()
QCOMPARE(pathView->offset(), 0);
}
+void tst_QQuickPinchArea::pinchInPathView()
+{
+ QQuickView view;
+ view.setSource(testFileUrl("pinchAreaInPathView.qml"));
+ QVERIFY(view.rootObject());
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+
+ QQuickPathView *pathView = qobject_cast<QQuickPathView*>(view.rootObject());
+ QVERIFY(pathView);
+ QCOMPARE(pathView->count(), 3);
+
+ const QQuickItem *pinchDelegateItem = pathView->itemAtIndex(0);
+ QQuickPinchArea *pinchArea = pinchDelegateItem->property("pinchArea").value<QQuickPinchArea*>();
+ QVERIFY(pinchArea);
+
+ // press
+ QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(&view, device);
+ QPoint point1Start = { 10, 10 };
+ QPoint point2Start = { 100, 100 };
+ const int dragThreshold = qApp->styleHints()->startDragDistance();
+ pinchSequence.press(0, point1Start, &view)
+ .press(1, point2Start, &view)
+ .commit();
+ QQuickTouchUtils::flush(&view);
+ QTest::qWait(20);
+
+ // move
+ QPoint moveDistance = QPoint(dragThreshold * 3, dragThreshold * 3);
+ QPoint point2End = point2Start + moveDistance;
+ pinchSequence.stationary(0)
+ .move(1, point2End, &view)
+ .commit();
+ QQuickTouchUtils::flush(&view);
+ QTest::qWait(20);
+
+ point2End += moveDistance;
+ pinchSequence.stationary(0)
+ .move(1, point2End, &view)
+ .commit();
+ QQuickTouchUtils::flush(&view);
+ QTest::qWait(20);
+
+ QCOMPARE(pinchArea->pinch()->active(), true);
+ QVERIFY2(pinchDelegateItem->scale() > 1.0, qPrintable(QString::number(pinchDelegateItem->scale())));
+ // PathView shouldn't have moved.
+ QCOMPARE(pathView->offset(), 0);
+
+ // release pinch.
+ pinchSequence.release(0, point1Start, &view).release(1, point2End, &view).commit();
+ QQuickTouchUtils::flush(&view);
+ QCOMPARE(pinchArea->pinch()->active(), false);
+ QCOMPARE(pathView->offset(), 0);
+}
+
QQuickView *tst_QQuickPinchArea::createView()
{
QQuickView *window = new QQuickView(nullptr);