aboutsummaryrefslogtreecommitdiffstats
path: root/src/templates/qquickoverlay.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-12-15 14:54:02 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-12-15 22:21:55 +0000
commit946e834578c6ca0a591324b5d5fd21e291cfca0b (patch)
tree2190024dcd45eebc2c43b5c0f2d53b718bac9caa /src/templates/qquickoverlay.cpp
parent116db644615c84f8d59b4e4b9c074b2167dd9a2c (diff)
Add Overlay::background that is shown when any modal popup is open
Change-Id: Idc2a5bbb5cf7a08ff21731537a378b1dd8050833 Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src/templates/qquickoverlay.cpp')
-rw-r--r--src/templates/qquickoverlay.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/templates/qquickoverlay.cpp b/src/templates/qquickoverlay.cpp
index 73e0a39d..467c3b52 100644
--- a/src/templates/qquickoverlay.cpp
+++ b/src/templates/qquickoverlay.cpp
@@ -37,6 +37,7 @@
#include "qquickoverlay_p.h"
#include "qquickpopup_p.h"
#include <QtQml/qqmlinfo.h>
+#include <QtQml/qqmlproperty.h>
#include <QtQuick/private/qquickitem_p.h>
QT_BEGIN_NAMESPACE
@@ -48,11 +49,22 @@ class QQuickOverlayPrivate : public QQuickItemPrivate
public:
QQuickOverlayPrivate();
+ void resizeBackground();
+
+ QQuickItem *background;
QHash<QQuickItem *, QQuickPopup *> popups;
int modalPopups;
};
+void QQuickOverlayPrivate::resizeBackground()
+{
+ Q_Q(QQuickOverlay);
+ background->setWidth(q->width());
+ background->setHeight(q->height());
+}
+
QQuickOverlayPrivate::QQuickOverlayPrivate() :
+ background(Q_NULLPTR),
modalPopups(0)
{
}
@@ -65,6 +77,31 @@ QQuickOverlay::QQuickOverlay(QQuickItem *parent)
setVisible(false);
}
+
+QQuickItem *QQuickOverlay::background() const
+{
+ Q_D(const QQuickOverlay);
+ return d->background;
+}
+
+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();
+ }
+}
+
void QQuickOverlay::itemChange(ItemChange change, const ItemChangeData &data)
{
Q_D(QQuickOverlay);
@@ -102,6 +139,18 @@ void QQuickOverlay::itemChange(ItemChange change, const ItemChangeData &data)
--d->modalPopups;
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);
+}
+
+void QQuickOverlay::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+{
+ Q_D(QQuickOverlay);
+ QQuickItem::geometryChanged(newGeometry, oldGeometry);
+ if (d->background)
+ d->resizeBackground();
}
void QQuickOverlay::keyPressEvent(QKeyEvent *event)