diff options
Diffstat (limited to 'src/quick/handlers')
-rw-r--r-- | src/quick/handlers/qquickhoverhandler.cpp | 51 | ||||
-rw-r--r-- | src/quick/handlers/qquickpointerhandler.cpp | 5 | ||||
-rw-r--r-- | src/quick/handlers/qquickpointerhandler_p_p.h | 1 |
3 files changed, 44 insertions, 13 deletions
diff --git a/src/quick/handlers/qquickhoverhandler.cpp b/src/quick/handlers/qquickhoverhandler.cpp index 2a2208c567..072ca626a6 100644 --- a/src/quick/handlers/qquickhoverhandler.cpp +++ b/src/quick/handlers/qquickhoverhandler.cpp @@ -40,35 +40,58 @@ class QQuickHoverHandlerPrivate : public QQuickSinglePointHandlerPrivate public: void onEnabledChanged() override; + void onParentChanged(QQuickItem *oldParent, QQuickItem *newParent) override; + + void updateHasHoverInChild(QQuickItem *item, bool hasHover); }; void QQuickHoverHandlerPrivate::onEnabledChanged() { Q_Q(QQuickHoverHandler); - if (auto parent = q->parentItem()) { - QQuickItemPrivate *itemPriv = QQuickItemPrivate::get(parent); - itemPriv->setHasHoverInChild(enabled); - // The DA needs to resolve which items and handlers should now be hovered or unhovered. - // Marking the parent item dirty ensures that flushFrameSynchronousEvents() will be called from the render loop, - // even if this change is not in response to a mouse event and no item has already marked itself dirty. - itemPriv->dirty(QQuickItemPrivate::Content); - } + if (auto parent = q->parentItem()) + updateHasHoverInChild(parent, enabled); if (!enabled) q->setHovered(false); + + QQuickSinglePointHandlerPrivate::onEnabledChanged(); +} + +void QQuickHoverHandlerPrivate::onParentChanged(QQuickItem *oldParent, QQuickItem *newParent) +{ + if (oldParent) + updateHasHoverInChild(oldParent, false); + if (newParent) + updateHasHoverInChild(newParent, true); + + QQuickSinglePointHandlerPrivate::onParentChanged(oldParent, newParent); +} + +void QQuickHoverHandlerPrivate::updateHasHoverInChild(QQuickItem *item, bool hasHover) +{ + QQuickItemPrivate *itemPriv = QQuickItemPrivate::get(item); + itemPriv->setHasHoverInChild(hasHover); + // The DA needs to resolve which items and handlers should now be hovered or unhovered. + // Marking the parent item dirty ensures that flushFrameSynchronousEvents() will be called from the render loop, + // even if this change is not in response to a mouse event and no item has already marked itself dirty. + itemPriv->dirty(QQuickItemPrivate::Content); } QQuickHoverHandler::QQuickHoverHandler(QQuickItem *parent) : QQuickSinglePointHandler(*(new QQuickHoverHandlerPrivate), parent) { + Q_D(QQuickHoverHandler); // Tell QQuickPointerDeviceHandler::wantsPointerEvent() to ignore button state - d_func()->acceptedButtons = Qt::NoButton; + d->acceptedButtons = Qt::NoButton; + if (parent) + d->updateHasHoverInChild(parent, true); } QQuickHoverHandler::~QQuickHoverHandler() { + Q_D(QQuickHoverHandler); if (auto parent = parentItem()) - QQuickItemPrivate::get(parent)->setHasHoverInChild(false); + d->updateHasHoverInChild(parent, false); } /*! @@ -105,9 +128,13 @@ bool QQuickHoverHandler::event(QEvent *event) void QQuickHoverHandler::componentComplete() { + Q_D(QQuickHoverHandler); QQuickSinglePointHandler::componentComplete(); - if (auto par = parentItem()) - QQuickItemPrivate::get(par)->setHasHoverInChild(true); + + if (d->enabled) { + if (auto parent = parentItem()) + d->updateHasHoverInChild(parent, true); + } } bool QQuickHoverHandler::wantsPointerEvent(QPointerEvent *event) diff --git a/src/quick/handlers/qquickpointerhandler.cpp b/src/quick/handlers/qquickpointerhandler.cpp index 96f87d6943..a851334b0e 100644 --- a/src/quick/handlers/qquickpointerhandler.cpp +++ b/src/quick/handlers/qquickpointerhandler.cpp @@ -597,15 +597,18 @@ QQuickItem *QQuickPointerHandler::parentItem() const void QQuickPointerHandler::setParentItem(QQuickItem *p) { + Q_D(QQuickPointerHandler); if (QObject::parent() == p) return; qCDebug(lcHandlerParent) << "reparenting handler" << this << ":" << parent() << "->" << p; - if (auto *oldParent = static_cast<QQuickItem *>(QObject::parent())) + auto *oldParent = static_cast<QQuickItem *>(QObject::parent()); + if (oldParent) QQuickItemPrivate::get(oldParent)->removePointerHandler(this); setParent(p); if (p) QQuickItemPrivate::get(p)->addPointerHandler(this); + d->onParentChanged(oldParent, p); emit parentChanged(); } diff --git a/src/quick/handlers/qquickpointerhandler_p_p.h b/src/quick/handlers/qquickpointerhandler_p_p.h index fa4ab737db..aa09f4edb7 100644 --- a/src/quick/handlers/qquickpointerhandler_p_p.h +++ b/src/quick/handlers/qquickpointerhandler_p_p.h @@ -38,6 +38,7 @@ public: bool dragOverThreshold(QVector2D delta) const; bool dragOverThreshold(const QEventPoint &point) const; + virtual void onParentChanged(QQuickItem * /*oldParent*/, QQuickItem * /*newParent*/) {} virtual void onEnabledChanged() {} static QVector<QObject *> &deviceDeliveryTargets(const QInputDevice *device); |