diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-12-15 18:24:15 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-12-16 16:57:38 +0000 |
commit | 2b81cdd40cdd265a50f91b4775cf5638b987d69f (patch) | |
tree | b269b1aaa57a21b0ea10d34b4135e50c5d261ec0 /src/templates/qquickoverlay.cpp | |
parent | 9a65b10e827b9bb09911feb9bd06ed10312463fc (diff) |
Make Drawers use the overlay background dimming
Change-Id: I6ec68983b06918d60acc2d60164d70cac0e37fac
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/templates/qquickoverlay.cpp')
-rw-r--r-- | src/templates/qquickoverlay.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/templates/qquickoverlay.cpp b/src/templates/qquickoverlay.cpp index 467c3b52..646dfe1a 100644 --- a/src/templates/qquickoverlay.cpp +++ b/src/templates/qquickoverlay.cpp @@ -36,6 +36,7 @@ #include "qquickoverlay_p.h" #include "qquickpopup_p.h" +#include "qquickdrawer_p.h" #include <QtQml/qqmlinfo.h> #include <QtQml/qqmlproperty.h> #include <QtQuick/private/qquickitem_p.h> @@ -49,13 +50,32 @@ class QQuickOverlayPrivate : public QQuickItemPrivate public: QQuickOverlayPrivate(); + void updateBackground(); void resizeBackground(); QQuickItem *background; + QVector<QQuickDrawer *> drawers; QHash<QQuickItem *, QQuickPopup *> popups; int modalPopups; }; +void QQuickOverlayPrivate::updateBackground() +{ + if (!background) + return; + + qreal level = 0.0; + if (modalPopups > 0) { + level = 1.0; + } else { + foreach (QQuickDrawer *drawer, drawers) + level = qMax(level, drawer->position()); + } + + // use QQmlProperty instead of QQuickItem::setOpacity() to trigger QML Behaviors + QQmlProperty::write(background, QStringLiteral("opacity"), level); +} + void QQuickOverlayPrivate::resizeBackground() { Q_Q(QQuickOverlay); @@ -110,7 +130,19 @@ void QQuickOverlay::itemChange(ItemChange change, const ItemChangeData &data) QQuickItem *contentItem = const_cast<QQuickItem *>(data.item); QQuickPopup *popup = Q_NULLPTR; if (change == ItemChildAddedChange || change == ItemChildRemovedChange) { - popup = qobject_cast<QQuickPopup *>(contentItem->parent()); + QQuickDrawer *drawer = qobject_cast<QQuickDrawer *>(data.item); + if (drawer) { + if (change == ItemChildAddedChange) { + QObjectPrivate::connect(drawer, &QQuickDrawer::positionChanged, d, &QQuickOverlayPrivate::updateBackground); + d->drawers.append(drawer); + } else { + QObjectPrivate::disconnect(drawer, &QQuickDrawer::positionChanged, d, &QQuickOverlayPrivate::updateBackground); + d->drawers.removeOne(drawer); + } + d->updateBackground(); + } else { + popup = qobject_cast<QQuickPopup *>(contentItem->parent()); + } setVisible(!childItems().isEmpty()); } if (!popup) @@ -140,9 +172,7 @@ void QQuickOverlay::itemChange(ItemChange change, const ItemChangeData &data) d->popups.remove(contentItem); } - // use QQmlProperty instead of QQuickItem::setOpacity() to trigger QML Behaviors - if (d->background) - QQmlProperty::write(d->background, QStringLiteral("opacity"), d->modalPopups > 0 ? 1.0 : 0.0); + d->updateBackground(); } void QQuickOverlay::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |