diff options
Diffstat (limited to 'src/templates/qquickoverlay.cpp')
-rw-r--r-- | src/templates/qquickoverlay.cpp | 103 |
1 files changed, 35 insertions, 68 deletions
diff --git a/src/templates/qquickoverlay.cpp b/src/templates/qquickoverlay.cpp index dd9d2c5d..acee3187 100644 --- a/src/templates/qquickoverlay.cpp +++ b/src/templates/qquickoverlay.cpp @@ -109,7 +109,7 @@ void QQuickOverlayPrivate::resizeBackground() } QQuickOverlayPrivate::QQuickOverlayPrivate() : - background(Q_NULLPTR), + background(nullptr), modalPopups(0) { } @@ -132,19 +132,20 @@ QQuickItem *QQuickOverlay::background() const void QQuickOverlay::setBackground(QQuickItem *background) { Q_D(QQuickOverlay); - if (d->background != background) { - delete d->background; - d->background = background; - if (background) { - background->setOpacity(0.0); - background->setParentItem(this); - if (qFuzzyIsNull(background->z())) - background->setZ(-1); - if (isComponentComplete()) - d->resizeBackground(); - } - emit backgroundChanged(); + if (d->background == background) + return; + + delete d->background; + d->background = background; + if (background) { + background->setOpacity(0.0); + background->setParentItem(this); + if (qFuzzyIsNull(background->z())) + background->setZ(-1); + if (isComponentComplete()) + d->resizeBackground(); } + emit backgroundChanged(); } void QQuickOverlay::itemChange(ItemChange change, const ItemChangeData &data) @@ -152,7 +153,7 @@ void QQuickOverlay::itemChange(ItemChange change, const ItemChangeData &data) Q_D(QQuickOverlay); QQuickItem::itemChange(change, data); - QQuickPopup *popup = Q_NULLPTR; + QQuickPopup *popup = nullptr; if (change == ItemChildAddedChange || change == ItemChildRemovedChange) { QQuickDrawer *drawer = qobject_cast<QQuickDrawer *>(data.item); if (drawer) { @@ -196,52 +197,26 @@ void QQuickOverlay::geometryChanged(const QRectF &newGeometry, const QRectF &old d->resizeBackground(); } -void QQuickOverlay::keyPressEvent(QKeyEvent *event) -{ - Q_D(QQuickOverlay); - event->setAccepted(d->modalPopups > 0); -} - -void QQuickOverlay::keyReleaseEvent(QKeyEvent *event) +bool QQuickOverlay::event(QEvent *event) { Q_D(QQuickOverlay); - event->setAccepted(d->modalPopups > 0); -} - -void QQuickOverlay::mousePressEvent(QMouseEvent *event) -{ - Q_D(QQuickOverlay); - event->setAccepted(d->modalPopups > 0); - emit pressed(); - - for (int i = d->popups.count() - 1; i >= 0; --i) { - if (QQuickPopupPrivate::get(d->popups.at(i))->tryClose(this, event)) - break; + switch (event->type()) { + case QEvent::MouseButtonPress: + emit pressed(); + break; + case QEvent::MouseButtonRelease: + emit released(); + break; + default: + break; } -} -void QQuickOverlay::mouseMoveEvent(QMouseEvent *event) -{ - Q_D(QQuickOverlay); - event->setAccepted(d->modalPopups > 0); -} - -void QQuickOverlay::mouseReleaseEvent(QMouseEvent *event) -{ - Q_D(QQuickOverlay); - event->setAccepted(d->modalPopups > 0); - emit released(); - - for (int i = d->popups.count() - 1; i >= 0; --i) { - if (QQuickPopupPrivate::get(d->popups.at(i))->tryClose(this, event)) - break; + for (auto it = d->popups.rbegin(), end = d->popups.rend(); it != end; ++it) { + if ((*it)->overlayEvent(this, event)) + return true; } -} -void QQuickOverlay::wheelEvent(QWheelEvent *event) -{ - Q_D(QQuickOverlay); - event->setAccepted(d->modalPopups > 0); + return QQuickItem::event(event); } bool QQuickOverlay::childMouseEventFilter(QQuickItem *item, QEvent *event) @@ -255,26 +230,18 @@ bool QQuickOverlay::childMouseEventFilter(QQuickItem *item, QEvent *event) while (item->parentItem() != this) item = item->parentItem(); - bool modalBlocked = false; - const QQuickItemPrivate *priv = QQuickItemPrivate::get(this); - const QList<QQuickItem *> &sortedChildren = priv->paintOrderChildItems(); - for (int i = sortedChildren.count() - 1; i >= 0; --i) { - QQuickItem *popupItem = sortedChildren[i]; + const QList<QQuickItem *> sortedChildren = d->paintOrderChildItems(); + for (auto it = sortedChildren.rbegin(), end = sortedChildren.rend(); it != end; ++it) { + QQuickItem *popupItem = *it; if (popupItem == item) break; QQuickPopup *popup = qobject_cast<QQuickPopup *>(popupItem->parent()); - if (popup) { - QQuickPopup::ClosePolicy policy = popup->closePolicy(); - if (policy.testFlag(QQuickPopup::OnPressOutside) || policy.testFlag(QQuickPopup::OnPressOutsideParent)) - popup->close(); - - if (!modalBlocked && popup->isModal()) - modalBlocked = true; - } + if (popup && popup->overlayEvent(item, event)) + return true; } - return modalBlocked; + return false; } QT_END_NAMESPACE |