From f59e5d7bbd17c79ca2f06d79897212a5fc9b6ee7 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 31 Aug 2016 17:32:28 +0200 Subject: Popup: respect dynamic dim & modal changes What comes to the visual background dimming, popups did not respect dynamic 'dim' or 'modal' property changes. This was half-intentional, because it was thought an unrealistic use-case to toggle these while the popup is visible. As a result, the background dimming was missing if a popup was made visible in a declarative way, and either 'dim' or 'modal' was evaluated after the popup was already visible. Task-number: QTBUG-54797 Change-Id: Icfb171e619540fef2d91908867b702790cde6c32 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickoverlay.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/quicktemplates2/qquickoverlay.cpp') diff --git a/src/quicktemplates2/qquickoverlay.cpp b/src/quicktemplates2/qquickoverlay.cpp index 850de875..5dd92a26 100644 --- a/src/quicktemplates2/qquickoverlay.cpp +++ b/src/quicktemplates2/qquickoverlay.cpp @@ -57,6 +57,7 @@ public: void createOverlay(QQuickPopup *popup); void destroyOverlay(QQuickPopup *popup); void resizeOverlay(QQuickPopup *popup); + void toggleOverlay(); QVector stackingOrderPopups() const; @@ -106,7 +107,7 @@ static QQuickItem *createDimmer(QQmlComponent *component, QQuickPopup *popup, QQ context->setContextObject(popup); QQuickItem *item = qobject_cast(component->beginCreate(context)); if (item) { - item->setOpacity(0.0); + item->setOpacity(popup->isVisible() ? 1.0 : 0.0); item->setParentItem(parent); item->stackBefore(popup->popupItem()); item->setZ(popup->z()); @@ -150,6 +151,18 @@ void QQuickOverlayPrivate::resizeOverlay(QQuickPopup *popup) } } +void QQuickOverlayPrivate::toggleOverlay() +{ + Q_Q(QQuickOverlay); + QQuickPopup *popup = qobject_cast(q->sender()); + if (!popup) + return; + + destroyOverlay(popup); + if (popup->dim()) + createOverlay(popup); +} + QVector QQuickOverlayPrivate::stackingOrderPopups() const { const QList children = paintOrderChildItems(); @@ -233,6 +246,8 @@ void QQuickOverlay::itemChange(ItemChange change, const ItemChangeData &data) d->popups.append(popup); if (popup->dim()) d->createOverlay(popup); + QObjectPrivate::connect(popup, &QQuickPopup::dimChanged, d, &QQuickOverlayPrivate::toggleOverlay); + QObjectPrivate::connect(popup, &QQuickPopup::modalChanged, d, &QQuickOverlayPrivate::toggleOverlay); QQuickDrawer *drawer = qobject_cast(popup); if (drawer) { @@ -247,6 +262,8 @@ void QQuickOverlay::itemChange(ItemChange change, const ItemChangeData &data) } else if (change == ItemChildRemovedChange) { d->popups.removeOne(popup); d->destroyOverlay(popup); + QObjectPrivate::disconnect(popup, &QQuickPopup::dimChanged, d, &QQuickOverlayPrivate::toggleOverlay); + QObjectPrivate::disconnect(popup, &QQuickPopup::modalChanged, d, &QQuickOverlayPrivate::toggleOverlay); QQuickDrawer *drawer = qobject_cast(popup); if (drawer) { -- cgit v1.2.3