diff options
Diffstat (limited to 'src/quick/util/qquickdeliveryagent.cpp')
-rw-r--r-- | src/quick/util/qquickdeliveryagent.cpp | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/src/quick/util/qquickdeliveryagent.cpp b/src/quick/util/qquickdeliveryagent.cpp index a38ac410d4..10ce45e2cf 100644 --- a/src/quick/util/qquickdeliveryagent.cpp +++ b/src/quick/util/qquickdeliveryagent.cpp @@ -626,6 +626,21 @@ void QQuickDeliveryAgentPrivate::updateFocusItemTransform() } /*! \internal + If called during event delivery, returns the agent that is delivering the + event, without checking whether \a item is reachable from there. + Otherwise returns QQuickItemPrivate::deliveryAgent() (the delivery agent for + the narrowest subscene containing \a item), or \c null if \a item is \c null. +*/ +QQuickDeliveryAgent *QQuickDeliveryAgentPrivate::currentOrItemDeliveryAgent(const QQuickItem *item) +{ + if (currentEventDeliveryAgent) + return currentEventDeliveryAgent; + if (item) + return QQuickItemPrivate::get(const_cast<QQuickItem *>(item))->deliveryAgent(); + return nullptr; +} + +/*! \internal QQuickDeliveryAgent delivers events to a tree of Qt Quick Items, beginning with the given root item, which is usually QQuickWindow::rootItem() but may alternatively be embedded into a Qt Quick 3D scene or something else. @@ -650,8 +665,20 @@ QQuickItem *QQuickDeliveryAgent::rootItem() const } /*! \internal + Returns the object that was set in setSceneTransform(): a functor that + transforms from scene coordinates in the parent scene to scene coordinates + within this DA's subscene, or \c null if none was set. +*/ +QQuickDeliveryAgent::Transform *QQuickDeliveryAgent::sceneTransform() const +{ + Q_D(const QQuickDeliveryAgent); + return d->sceneTransform; +} + +/*! \internal QQuickDeliveryAgent takes ownership of the given \a transform, which - encapsulates the ability to transform viewport coordinates to rootItem coordinates. + encapsulates the ability to transform parent scene coordinates to rootItem + (subscene) coordinates. */ void QQuickDeliveryAgent::setSceneTransform(QQuickDeliveryAgent::Transform *transform) { @@ -904,12 +931,16 @@ bool QQuickDeliveryAgentPrivate::sendHoverEvent(QEvent::Type type, QQuickItem *i Qt::KeyboardModifiers modifiers, ulong timestamp, bool accepted) { - const QTransform transform = QQuickItemPrivate::get(item)->windowToItemTransform(); - - //create copy of event + auto itemPrivate = QQuickItemPrivate::get(item); + const QTransform transform = itemPrivate->windowToItemTransform(); QHoverEvent hoverEvent(type, transform.map(scenePos), transform.map(lastScenePos), modifiers); hoverEvent.setTimestamp(timestamp); hoverEvent.setAccepted(accepted); + const QTransform transformToGlobal = itemPrivate->windowToGlobalTransform(); + QMutableEventPoint &point = QMutableEventPoint::from(hoverEvent.point(0)); + point.setScenePosition(scenePos); + point.setGlobalPosition(transformToGlobal.map(scenePos)); + point.setGlobalLastPosition(transformToGlobal.map(lastScenePos)); hasFiltered.clear(); if (sendFilteredMouseEvent(&hoverEvent, item, item->parentItem())) @@ -1339,10 +1370,10 @@ void QQuickDeliveryAgentPrivate::handleMouseEvent(QMouseEvent *event) #if QT_CONFIG(cursor) QQuickWindowPrivate::get(rootItem->window())->updateCursor(event->scenePosition()); #endif + const QPointF last = lastMousePosition.isNull() ? event->scenePosition() : lastMousePosition; + lastMousePosition = event->scenePosition(); + qCDebug(lcHoverTrace) << q << "mouse pos" << last << "->" << lastMousePosition; if (!event->points().count() || !event->exclusiveGrabber(event->point(0))) { - QPointF last = lastMousePosition.isNull() ? event->scenePosition() : lastMousePosition; - lastMousePosition = event->scenePosition(); - qCDebug(lcHoverTrace) << q << "mouse pos" << last << "->" << lastMousePosition << event; bool accepted = event->isAccepted(); bool delivered = deliverHoverEvent(rootItem, event->scenePosition(), last, event->modifiers(), event->timestamp(), accepted); if (!delivered) { @@ -1386,7 +1417,7 @@ void QQuickDeliveryAgentPrivate::flushFrameSynchronousEvents(QQuickWindow *win) if (frameSynchronousHoverEnabled && !win->mouseGrabberItem() && !lastMousePosition.isNull() && QQuickWindowPrivate::get(win)->dirtyItemList) { bool accepted = false; - qCDebug(lcHoverTrace) << q << "delivering frame-sync hover to root"; + qCDebug(lcHoverTrace) << q << "delivering frame-sync hover to root @" << lastMousePosition; bool delivered = deliverHoverEvent(rootItem, lastMousePosition, lastMousePosition, QGuiApplication::keyboardModifiers(), 0, accepted); if (!delivered) clearHover(); // take care of any exits @@ -1493,10 +1524,12 @@ void QQuickDeliveryAgentPrivate::onGrabChanged(QObject *grabber, QPointingDevice void QQuickDeliveryAgentPrivate::ensureDeviceConnected(const QPointingDevice *dev) { + Q_Q(QQuickDeliveryAgent); if (knownPointingDevices.contains(dev)) return; knownPointingDevices.append(dev); connect(dev, &QPointingDevice::grabChanged, this, &QQuickDeliveryAgentPrivate::onGrabChanged); + QObject::connect(dev, &QObject::destroyed, q, [this, dev] {this->knownPointingDevices.removeAll(dev);}); } void QQuickDeliveryAgentPrivate::deliverPointerEvent(QPointerEvent *event) |