aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp
diff options
context:
space:
mode:
authorJan Arve Sæther <jan-arve.saether@qt.io>2023-07-11 15:15:09 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2023-07-11 20:55:49 +0200
commitf33146ed0abb67cfd82b491ba63e7279da9d95b5 (patch)
treeddc0be161578c50ff55959facb55db07d2a3f18b /tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp
parentcb206c3ad614ae366507598642028d69d43bd041 (diff)
Fix pointer delivery to child items of items with clip:true
QQuickDeliveryAgentPrivate::pointerTargets() can visit a lot of items and their handlers, before actual event delivery really starts. One optimization in place since 6adc36115f4fc658fb907ee8af3013f2609ae761 is that if an item is clipped, and the point is outside its bounds, we can be sure that it's also irrelevant to the item's children, because the parts of any children that may be under that point are clipped away and invisible. At the time that was written, QQuickItem::contains() was only doing a simple bounding-rect check. Since then, bf74a908cb0591c2adc024a6f93d566c7348c125 added containmentMask; and we should also keep in mind the precedence of the PointerHandler.margin property (currently, TapHandler.margin does not expand the sensitive area beyond a clipped Rectangle, or beyond the containmentMask either). So it seems we now need to check clipRect().contains() explicitly: a child item may be outside its parent's containmentMask, and containmentMask does not affect clipping, so one would expect to still be able to interact with the child. The current definition of clipRect() is from 9b62f4c27ac3fb3dc563c7f4657094c14d752bac. It's virtual, but documented as "the region intended to remain visible if clip is true". Fixes: QTBUG-115179 Pick-to: 5.15 6.2 6.5 6.6 Change-Id: I6ae8f492b99725459cdff2a89ac8508da5167102 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp')
-rw-r--r--tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp b/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp
index 8c73d0d296..c63572c83c 100644
--- a/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp
+++ b/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp
@@ -233,6 +233,7 @@ private slots:
void reparenting();
void grabberSceneChange_data();
void grabberSceneChange();
+ void clip();
protected:
bool eventFilter(QObject *, QEvent *event) override
@@ -800,6 +801,63 @@ void tst_PointerHandlers::grabberSceneChange()
QTest::mouseMove(window, p1 + QPoint(5, 5));
}
+void tst_PointerHandlers::clip()
+{
+ QScopedPointer<QQuickView> windowPtr;
+ createView(windowPtr, "clip.qml");
+ QQuickView * window = windowPtr.data();
+ QVERIFY(window);
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ EventHandler *handler = window->contentItem()->findChild<EventHandler*>("eventHandler");
+ EventHandler *circleHandler = window->contentItem()->findChild<EventHandler*>("circle eventHandler");
+
+ QCOMPARE(handler->pressEventCount, 0);
+ QCOMPARE(circleHandler->pressEventCount, 0);
+ QCOMPARE(handler->releaseEventCount, 0);
+ QCOMPARE(circleHandler->releaseEventCount, 0);
+
+ const QPoint rectPt = QPoint(1, 1);
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, rectPt);
+ QCOMPARE(handler->pressEventCount, 1);
+ QCOMPARE(circleHandler->pressEventCount, 0);
+
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, rectPt);
+ QCOMPARE(handler->releaseEventCount, 1);
+ QCOMPARE(circleHandler->releaseEventCount, 0);
+
+
+ handler->pressEventCount = 0;
+ circleHandler->pressEventCount = 0;
+ handler->releaseEventCount = 0;
+ circleHandler->releaseEventCount = 0;
+
+ const QPoint rectAndCirclePt = QPoint(49 ,49);
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, rectAndCirclePt);
+ QCOMPARE(handler->pressEventCount, 1);
+ QCOMPARE(circleHandler->pressEventCount, 1);
+
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, rectAndCirclePt);
+ QCOMPARE(handler->releaseEventCount, 1);
+ QCOMPARE(circleHandler->releaseEventCount, 1);
+
+
+ handler->pressEventCount = 0;
+ circleHandler->pressEventCount = 0;
+ handler->releaseEventCount = 0;
+ circleHandler->releaseEventCount = 0;
+
+ const QPoint circlePt = QPoint(51 ,51);
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, circlePt);
+ QCOMPARE(handler->pressEventCount, 0);
+ QCOMPARE(circleHandler->pressEventCount, 1);
+
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, circlePt);
+ QCOMPARE(handler->releaseEventCount, 0);
+ QCOMPARE(circleHandler->releaseEventCount, 1);
+}
+
QTEST_MAIN(tst_PointerHandlers)
#include "tst_qquickpointerhandler.moc"