aboutsummaryrefslogtreecommitdiffstats
path: root/src/templates
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
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')
-rw-r--r--src/templates/qquickapplicationwindow.cpp6
-rw-r--r--src/templates/qquickoverlay.cpp49
-rw-r--r--src/templates/qquickoverlay_p.h6
3 files changed, 59 insertions, 2 deletions
diff --git a/src/templates/qquickapplicationwindow.cpp b/src/templates/qquickapplicationwindow.cpp
index f21a1a63..db451810 100644
--- a/src/templates/qquickapplicationwindow.cpp
+++ b/src/templates/qquickapplicationwindow.cpp
@@ -337,10 +337,12 @@ QQuickItem *QQuickApplicationWindow::activeFocusControl() const
}
/*!
+ \qmlpropertygroup Qt.labs.controls::ApplicationWindow::overlay
\qmlproperty Item Qt.labs.controls::ApplicationWindow::overlay
- \readonly
+ \qmlproperty Item Qt.labs.controls::ApplicationWindow::overlay.background
- This property holds the window overlay item. Popups are automatically
+ This property holds the window overlay item and its background that implements the
+ background dimming when any modal popups are open. Popups are automatically
reparented to the overlay.
\sa Popup
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)
diff --git a/src/templates/qquickoverlay_p.h b/src/templates/qquickoverlay_p.h
index 3f13e845..8af1372b 100644
--- a/src/templates/qquickoverlay_p.h
+++ b/src/templates/qquickoverlay_p.h
@@ -58,16 +58,22 @@ class QQuickOverlayPrivate;
class Q_LABSTEMPLATES_EXPORT QQuickOverlay : public QQuickItem
{
Q_OBJECT
+ Q_PROPERTY(QQuickItem *background READ background WRITE setBackground NOTIFY backgroundChanged FINAL)
public:
explicit QQuickOverlay(QQuickItem *parent = Q_NULLPTR);
+ QQuickItem *background() const;
+ void setBackground(QQuickItem *background);
+
Q_SIGNALS:
+ void backgroundChanged();
void pressed();
void released();
protected:
void itemChange(ItemChange change, const ItemChangeData &data) Q_DECL_OVERRIDE;
+ void geometryChanged(const QRectF &oldGeometry, const QRectF &newGeometry) Q_DECL_OVERRIDE;
void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE;