diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-08-31 17:32:28 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-09-02 07:26:41 +0000 |
commit | f59e5d7bbd17c79ca2f06d79897212a5fc9b6ee7 (patch) | |
tree | 9a59d22c80b1adf2e014a6b9ca3709a2ad142459 /src/quicktemplates2 | |
parent | 0e01d1d979fd747671512b2c4e987d1f8cb3c019 (diff) |
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 <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r-- | src/quicktemplates2/qquickoverlay.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
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<QQuickPopup *> stackingOrderPopups() const; @@ -106,7 +107,7 @@ static QQuickItem *createDimmer(QQmlComponent *component, QQuickPopup *popup, QQ context->setContextObject(popup); QQuickItem *item = qobject_cast<QQuickItem*>(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<QQuickPopup *>(q->sender()); + if (!popup) + return; + + destroyOverlay(popup); + if (popup->dim()) + createOverlay(popup); +} + QVector<QQuickPopup *> QQuickOverlayPrivate::stackingOrderPopups() const { const QList<QQuickItem *> 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<QQuickDrawer *>(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<QQuickDrawer *>(popup); if (drawer) { |