diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-06-26 12:52:35 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-07-22 12:14:45 +0000 |
commit | 92032bee2923024d126bc20929f79abd459cae49 (patch) | |
tree | f14cd8401dc4ce9bb2b3b52e702ee21e350d35d2 /src/quicktemplates2 | |
parent | c0695b3911f99132e7de5df9a9fa676f2df33721 (diff) |
Fix overlay event processing order for popups
It should follow the stacking order of popups.
Change-Id: Id5664496c60e99bdf0aa4b2dc6a2c94dba2c756a
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r-- | src/quicktemplates2/qquickoverlay.cpp | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/src/quicktemplates2/qquickoverlay.cpp b/src/quicktemplates2/qquickoverlay.cpp index 2e19e02d..efbc2ce5 100644 --- a/src/quicktemplates2/qquickoverlay.cpp +++ b/src/quicktemplates2/qquickoverlay.cpp @@ -58,6 +58,8 @@ public: void destroyOverlay(QQuickPopup *popup); void resizeOverlay(QQuickPopup *popup); + QVector<QQuickPopup *> stackingOrderPopups() const; + QQmlComponent *modal; QQmlComponent *modeless; QVector<QQuickDrawer *> drawers; @@ -148,6 +150,22 @@ void QQuickOverlayPrivate::resizeOverlay(QQuickPopup *popup) } } +QVector<QQuickPopup *> QQuickOverlayPrivate::stackingOrderPopups() const +{ + const QList<QQuickItem *> children = paintOrderChildItems(); + + QVector<QQuickPopup *> popups; + popups.reserve(children.count()); + + for (auto it = children.crbegin(), end = children.crend(); it != end; ++it) { + QQuickPopup *popup = qobject_cast<QQuickPopup *>((*it)->parent()); + if (popup) + popups += popup; + } + + return popups; +} + QQuickOverlayPrivate::QQuickOverlayPrivate() : modal(nullptr), modeless(nullptr), @@ -254,22 +272,25 @@ bool QQuickOverlay::event(QEvent *event) { Q_D(QQuickOverlay); switch (event->type()) { - case QEvent::MouseButtonPress: + case QEvent::MouseButtonPress: { emit pressed(); - for (auto it = d->popups.crbegin(), end = d->popups.crend(); it != end; ++it) { - if ((*it)->overlayEvent(this, event)) { - d->mouseGrabberPopup = *it; + const auto popups = d->stackingOrderPopups(); + for (QQuickPopup *popup : popups) { + if (popup->overlayEvent(this, event)) { + d->mouseGrabberPopup = popup; return true; } } break; + } case QEvent::MouseMove: if (d->mouseGrabberPopup) { if (d->mouseGrabberPopup->overlayEvent(this, event)) return true; } else { - for (auto it = d->popups.crbegin(), end = d->popups.crend(); it != end; ++it) { - if ((*it)->overlayEvent(this, event)) + const auto popups = d->stackingOrderPopups(); + for (QQuickPopup *popup : popups) { + if (popup->overlayEvent(this, event)) return true; } } @@ -282,8 +303,9 @@ bool QQuickOverlay::event(QEvent *event) if (grabber->overlayEvent(this, event)) return true; } else { - for (auto it = d->popups.crbegin(), end = d->popups.crend(); it != end; ++it) { - if ((*it)->overlayEvent(this, event)) + const auto popups = d->stackingOrderPopups(); + for (QQuickPopup *popup : popups) { + if (popup->overlayEvent(this, event)) return true; } } @@ -306,14 +328,12 @@ bool QQuickOverlay::childMouseEventFilter(QQuickItem *item, QEvent *event) while (item->parentItem() != this) item = item->parentItem(); - const QList<QQuickItem *> sortedChildren = d->paintOrderChildItems(); - for (auto it = sortedChildren.rbegin(), end = sortedChildren.rend(); it != end; ++it) { - QQuickItem *popupItem = *it; - if (popupItem == item) + const auto popups = d->stackingOrderPopups(); + for (QQuickPopup *popup : popups) { + if (popup->popupItem() == item) break; - QQuickPopup *popup = qobject_cast<QQuickPopup *>(popupItem->parent()); - if (popup && popup->overlayEvent(item, event)) + if (popup->overlayEvent(item, event)) return true; } |