aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quickcontrols/qquickattachedpropertypropagator.cpp48
-rw-r--r--tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml39
2 files changed, 66 insertions, 21 deletions
diff --git a/src/quickcontrols/qquickattachedpropertypropagator.cpp b/src/quickcontrols/qquickattachedpropertypropagator.cpp
index 855f48ad0a..251e81b164 100644
--- a/src/quickcontrols/qquickattachedpropertypropagator.cpp
+++ b/src/quickcontrols/qquickattachedpropertypropagator.cpp
@@ -227,6 +227,7 @@ public:
void setAttachedParent(QQuickAttachedPropertyPropagator *parent);
void itemWindowChanged(QQuickWindow *window);
+ void transientParentWindowChanged(QWindow *newTransientParent);
void itemParentChanged(QQuickItem *item, QQuickItem *parent) override;
QList<QQuickAttachedPropertyPropagator *> attachedChildren;
@@ -235,22 +236,37 @@ public:
void QQuickAttachedPropertyPropagatorPrivate::attachTo(QObject *object)
{
- QQuickItem *item = findAttachedItem(object);
- if (item) {
+ if (QQuickItem *item = findAttachedItem(object)) {
connect(item, &QQuickItem::windowChanged, this, &QQuickAttachedPropertyPropagatorPrivate::itemWindowChanged);
QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Parent);
+ } else if (auto *window = qobject_cast<QQuickWindow *>(object)) {
+ QObjectPrivate::connect(window, &QWindow::transientParentChanged, this,
+ &QQuickAttachedPropertyPropagatorPrivate::transientParentWindowChanged);
}
}
void QQuickAttachedPropertyPropagatorPrivate::detachFrom(QObject *object)
{
- QQuickItem *item = findAttachedItem(object);
- if (item) {
+ if (QQuickItem *item = findAttachedItem(object)) {
disconnect(item, &QQuickItem::windowChanged, this, &QQuickAttachedPropertyPropagatorPrivate::itemWindowChanged);
QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Parent);
+ } else if (auto *window = qobject_cast<QQuickWindow *>(object)) {
+ QObjectPrivate::disconnect(window, &QWindow::transientParentChanged,
+ this, &QQuickAttachedPropertyPropagatorPrivate::transientParentWindowChanged);
}
}
+static QString debugName(QQuickAttachedPropertyPropagator *attached)
+{
+ QString string;
+ QDebug stream(&string);
+ if (!attached)
+ stream << "(null)";
+ else
+ stream.nospace().noquote() << attached << " (which is attached to " << attached->parent() << ')';
+ return string;
+}
+
/*!
\internal
@@ -276,14 +292,14 @@ void QQuickAttachedPropertyPropagatorPrivate::setAttachedParent(QQuickAttachedPr
return;
QQuickAttachedPropertyPropagator *oldParent = attachedParent;
- qCDebug(lcAttached) << "setAttachedParent called on" << q->parent();
+ qCDebug(lcAttached).noquote() << "setAttachedParent called on" << debugName(q) << "with parent" << debugName(parent);
if (attachedParent) {
- qCDebug(lcAttached) << "- removing ourselves as an attached child of" << attachedParent->parent() << attachedParent;
+ qCDebug(lcAttached).noquote() << "- removing ourselves as an attached child of" << debugName(attachedParent);
QQuickAttachedPropertyPropagatorPrivate::get(attachedParent)->attachedChildren.removeOne(q);
}
attachedParent = parent;
if (parent) {
- qCDebug(lcAttached) << "- adding ourselves as an attached child of" << parent->parent() << parent;
+ qCDebug(lcAttached).noquote() << "- adding ourselves as an attached child of" << debugName(parent);
QQuickAttachedPropertyPropagatorPrivate::get(parent)->attachedChildren.append(q);
}
q->attachedParentChange(parent, oldParent);
@@ -293,13 +309,24 @@ void QQuickAttachedPropertyPropagatorPrivate::itemWindowChanged(QQuickWindow *wi
{
Q_Q(QQuickAttachedPropertyPropagator);
QQuickAttachedPropertyPropagator *attachedParent = nullptr;
- qCDebug(lcAttached) << "window of" << q->parent() << "changed to" << window;
+ qCDebug(lcAttached).noquote() << "window of" << debugName(q) << "changed to" << window;
attachedParent = findAttachedParent(q->metaObject(), q->parent());
if (!attachedParent)
attachedParent = attachedObject(q->metaObject(), window);
setAttachedParent(attachedParent);
}
+void QQuickAttachedPropertyPropagatorPrivate::transientParentWindowChanged(QWindow *newTransientParent)
+{
+ Q_Q(QQuickAttachedPropertyPropagator);
+ QQuickAttachedPropertyPropagator *attachedParent = nullptr;
+ qCDebug(lcAttached).noquote() << "transient parent window of" << q << "changed to" << newTransientParent;
+ attachedParent = findAttachedParent(q->metaObject(), q->parent());
+ if (!attachedParent)
+ attachedParent = attachedObject(q->metaObject(), newTransientParent);
+ setAttachedParent(attachedParent);
+}
+
void QQuickAttachedPropertyPropagatorPrivate::itemParentChanged(QQuickItem *item, QQuickItem *parent)
{
Q_Q(QQuickAttachedPropertyPropagator);
@@ -383,14 +410,15 @@ QQuickAttachedPropertyPropagator *QQuickAttachedPropertyPropagator::attachedPare
void QQuickAttachedPropertyPropagator::initialize()
{
Q_D(QQuickAttachedPropertyPropagator);
+ qCDebug(lcAttached) << "initialize called for" << parent() << "- looking for attached parent...";
QQuickAttachedPropertyPropagator *attachedParent = findAttachedParent(metaObject(), parent());
if (attachedParent)
d->setAttachedParent(attachedParent);
const QList<QQuickAttachedPropertyPropagator *> attachedChildren = findAttachedChildren(metaObject(), parent());
- qCDebug(lcAttached) << "initialize called for" << parent() << "- found" << attachedChildren.size() << "attached children";
+ qCDebug(lcAttached) << "- found" << attachedChildren.size() << "attached children:";
for (QQuickAttachedPropertyPropagator *child : attachedChildren) {
- qCDebug(lcAttached) << "-" << child->parent();
+ qCDebug(lcAttached) << " -" << child->parent();
QQuickAttachedPropertyPropagatorPrivate::get(child)->setAttachedParent(this);
}
}
diff --git a/tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml b/tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml
index 4fb19c7c0f..6d7fbffa64 100644
--- a/tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml
+++ b/tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml
@@ -51,17 +51,6 @@ TestCase {
}
Component {
- id: styledWindowComponent
- Window {
- Material.theme: Material.Dark
- Material.primary: Material.Brown
- Material.accent: Material.Green
- Material.background: Material.Yellow
- Material.foreground: Material.Grey
- }
- }
-
- Component {
id: buttonLoaderComponent
Loader {
active: false
@@ -1277,4 +1266,32 @@ TestCase {
// false => true => false.
compare(buttonActiveFocusSpy.count, 2)
}
+
+ Component {
+ id: childWindowComponent
+
+ ApplicationWindow {
+ objectName: "parentWindow"
+ property alias childWindow: childWindow
+
+ Material.theme: Material.Dark
+ Material.primary: Material.Brown
+ Material.accent: Material.Green
+ Material.background: Material.Yellow
+ Material.foreground: Material.Grey
+
+ ApplicationWindow {
+ id: childWindow
+ objectName: "childWindow"
+ }
+ }
+ }
+
+ function test_windowBackgroundColorPropagation() {
+ let parentWindow = createTemporaryObject(childWindowComponent, testCase)
+ verify(parentWindow)
+
+ let childWindow = parentWindow.childWindow
+ compare(childWindow.Material.theme, Material.Dark)
+ }
}