aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/handlers/qquickpointerhandler.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2025-10-14 13:20:45 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2025-11-11 19:27:24 +0100
commit81405bdeb45360809a97d12d2ad5ccbaf32af570 (patch)
treed8ee619cd0af888c58aee4c793ba42b255e15d9c /src/quick/handlers/qquickpointerhandler.cpp
parentb9e61c45f9d8d344732273e473738fb1082fcec7 (diff)
Reduce QTransform use in event delivery and cursor-finding functions
Pass localPos to deliverHoverEventRecursive, deliverHoverEventToItem and sendHoverEvent, so that deliverHoverEventRecursive() can merely transform from its own coordinate space to each child's space by calling itemToParentTransform(). That doesn't require up-the-tree recursion like mapFromScene() does. Apply the same trick to QQuickWindowPrivate::findCursorItemAndHandler(). Apply the same trick to QQuickPointerHandler::parentContains(local, scene): now QQuickPointerHandler::parentContains(QEventPoint) also calls that with both local and scene positions, which it already has, so this likely optimizes some use cases outside of the hover and cursor cases. But to make that work, we need to apply the same trick to QQuickDeliveryAgentPrivate::eventTargets() as well, and now it needs to localize the QEventPoint before calling the predicate. Usually, global position is QGuiApplicationPrivate::lastCursorPosition; but when no mouse events occur, only touch events, lastCursorPosition may remain offscreen. So we use the QEventPoint::globalPosition when possible; so it's useful to pass globalPos along to each of these hover functions, so that deliverHoverEventToItem() can construct the QMouseEvent with it, and sendHoverEvent() can construct the QHoverEvent with it. Also amends f5140d62082e9b06e0ca6c8e2175b5836286f52e: that looked rather CPU-intensive to call several mapping functions. The test is retained. Task-number: QTBUG-134099 Task-number: QTBUG-140340 Change-Id: I2c520d430e58ec7c00ada2207541b2936c7ae596 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/quick/handlers/qquickpointerhandler.cpp')
-rw-r--r--src/quick/handlers/qquickpointerhandler.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/quick/handlers/qquickpointerhandler.cpp b/src/quick/handlers/qquickpointerhandler.cpp
index 0435c44827..5968f3f848 100644
--- a/src/quick/handlers/qquickpointerhandler.cpp
+++ b/src/quick/handlers/qquickpointerhandler.cpp
@@ -555,7 +555,7 @@ QPointF QQuickPointerHandler::eventPos(const QEventPoint &point) const
*/
bool QQuickPointerHandler::parentContains(const QEventPoint &point) const
{
- return parentContains(point.scenePosition());
+ return parentContains(point.position(), point.scenePosition());
}
/*!
@@ -566,7 +566,7 @@ bool QQuickPointerHandler::parentContains(const QEventPoint &point) const
is not called.) As a precheck, it's also required that the window contains
\a scenePosition mapped to global coordinates, if parentItem() is in a window.
*/
-bool QQuickPointerHandler::parentContains(const QPointF &scenePosition) const
+bool QQuickPointerHandler::parentContains(const QPointF &localPosition, const QPointF &scenePosition) const
{
if (QQuickItem *par = parentItem()) {
if (par->window()) {
@@ -577,11 +577,11 @@ bool QQuickPointerHandler::parentContains(const QPointF &scenePosition) const
if (!windowGeometry.contains(screenPosition))
return false;
}
- QPointF p = par->mapFromScene(scenePosition);
qreal m = margin();
if (m > 0)
- return p.x() >= -m && p.y() >= -m && p.x() <= par->width() + m && p.y() <= par->height() + m;
- return par->contains(p);
+ return localPosition.x() >= -m && localPosition.y() >= -m &&
+ localPosition.x() <= par->width() + m && localPosition.y() <= par->height() + m;
+ return par->contains(localPosition);
} else if (parent() && parent()->inherits("QQuick3DModel")) {
// If the parent is from Qt Quick 3D, assume that
// bounds checking was already done, as part of picking.