diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/controls/ApplicationWindow.qml | 4 | ||||
-rw-r--r-- | src/imports/controls/material/ApplicationWindow.qml | 5 | ||||
-rw-r--r-- | src/imports/controls/material/qquickmaterialstyle.cpp | 5 | ||||
-rw-r--r-- | src/imports/controls/material/qquickmaterialstyle_p.h | 2 | ||||
-rw-r--r-- | src/imports/controls/universal/ApplicationWindow.qml | 4 | ||||
-rw-r--r-- | src/templates/qquickapplicationwindow.cpp | 6 | ||||
-rw-r--r-- | src/templates/qquickoverlay.cpp | 49 | ||||
-rw-r--r-- | src/templates/qquickoverlay_p.h | 6 |
8 files changed, 79 insertions, 2 deletions
diff --git a/src/imports/controls/ApplicationWindow.qml b/src/imports/controls/ApplicationWindow.qml index 247752cb..5c43c956 100644 --- a/src/imports/controls/ApplicationWindow.qml +++ b/src/imports/controls/ApplicationWindow.qml @@ -42,4 +42,8 @@ T.ApplicationWindow { id: window color: "#ffffff" + + overlay.background: Rectangle { + color: "#7f28282a" + } } diff --git a/src/imports/controls/material/ApplicationWindow.qml b/src/imports/controls/material/ApplicationWindow.qml index bf8b62bc..bbaeac70 100644 --- a/src/imports/controls/material/ApplicationWindow.qml +++ b/src/imports/controls/material/ApplicationWindow.qml @@ -43,4 +43,9 @@ T.ApplicationWindow { id: window color: Material.backgroundColor + + overlay.background: Rectangle { + color: window.Material.backgroundDimColor + Behavior on opacity { NumberAnimation { duration: 100 } } + } } diff --git a/src/imports/controls/material/qquickmaterialstyle.cpp b/src/imports/controls/material/qquickmaterialstyle.cpp index 0cef6698..191db14f 100644 --- a/src/imports/controls/material/qquickmaterialstyle.cpp +++ b/src/imports/controls/material/qquickmaterialstyle.cpp @@ -730,6 +730,11 @@ QColor QQuickMaterialStyle::comboBoxColor() const return m_theme == Light ? "#ffffff" : backgroundColorDark; } +QColor QQuickMaterialStyle::backgroundDimColor() const +{ + return m_theme == Light ? "#99303030" : "#99fafafa"; +} + QColor QQuickMaterialStyle::color(QQuickMaterialStyle::Color color, QQuickMaterialStyle::Shade shade) const { int count = sizeof(colors) / sizeof(colors[0]); diff --git a/src/imports/controls/material/qquickmaterialstyle_p.h b/src/imports/controls/material/qquickmaterialstyle_p.h index 84601de5..9bfb8176 100644 --- a/src/imports/controls/material/qquickmaterialstyle_p.h +++ b/src/imports/controls/material/qquickmaterialstyle_p.h @@ -93,6 +93,7 @@ class QQuickMaterialStyle : public QQuickStyle Q_PROPERTY(QColor scrollBarPressedColor READ scrollBarPressedColor NOTIFY paletteChanged FINAL) Q_PROPERTY(QColor drawerBackgroundColor READ drawerBackgroundColor NOTIFY paletteChanged FINAL) Q_PROPERTY(QColor comboBoxColor READ comboBoxColor NOTIFY paletteChanged FINAL) + Q_PROPERTY(QColor backgroundDimColor READ backgroundDimColor NOTIFY paletteChanged FINAL) public: enum Theme { @@ -201,6 +202,7 @@ public: QColor scrollBarPressedColor() const; QColor drawerBackgroundColor() const; QColor comboBoxColor() const; + QColor backgroundDimColor() const; Q_INVOKABLE QColor color(Color color, Shade shade) const; diff --git a/src/imports/controls/universal/ApplicationWindow.qml b/src/imports/controls/universal/ApplicationWindow.qml index 773eec52..3113e748 100644 --- a/src/imports/controls/universal/ApplicationWindow.qml +++ b/src/imports/controls/universal/ApplicationWindow.qml @@ -44,6 +44,10 @@ T.ApplicationWindow { color: Universal.altHighColor + overlay.background: Rectangle { + color: window.Universal.baseLowColor + } + FocusRectangle { parent: window.activeFocusControl width: parent ? parent.width : 0 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; |