aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-06-11 14:19:17 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-06-11 20:47:45 +0000
commit44e5f7f29c29811534ca02359fe5b4fbe1f54990 (patch)
tree1234e9e93bdce8fd51ad09744ddc60f499cdaf73
parent3f7dab18b0eb992037c47a42fee8794528a6fb5a (diff)
Use Inactive color group in inactive windows
A palette has three color groups (Active, Inactive, Disabled), but we only listened to changes of the enabled state, and always used the Active color group for an enabled item. In order for the Inactive color group to take effect, we need to also trigger the update when the "active" property changes. Instead of connecting yet another signal, deliver WindowActivate/Deactivate to as well, and forward from contentItem to all children which can then update the current color group. Add a test case. Fixes: QTBUG-93752 Change-Id: I4f2b6121e822115aaa5c4faaa5d402932dacc67b Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> (cherry picked from commit 3675f2b235f32e05cf6d754e81e0e8f8ddd59752) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quick/items/qquickitem.cpp7
-rw-r--r--src/quick/items/qquickpaletteproviderprivatebase_p.h11
-rw-r--r--src/quick/items/qquickwindow.cpp4
-rw-r--r--tests/auto/quick/qquickitem2/data/colorgroup.qml34
-rw-r--r--tests/auto/quick/qquickitem2/tst_qquickitem.cpp44
5 files changed, 97 insertions, 3 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index 7fe057ad70..5b8048c303 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -8505,6 +8505,13 @@ bool QQuickItem::event(QEvent *ev)
for (QQuickItem *item : d->childItems)
QCoreApplication::sendEvent(item, ev);
break;
+ case QEvent::WindowActivate:
+ case QEvent::WindowDeactivate:
+ if (d->palette())
+ d->setCurrentColorGroup();
+ for (QQuickItem *item : d->childItems)
+ QCoreApplication::sendEvent(item, ev);
+ break;
default:
return QObject::event(ev);
}
diff --git a/src/quick/items/qquickpaletteproviderprivatebase_p.h b/src/quick/items/qquickpaletteproviderprivatebase_p.h
index b1b5958329..9399462130 100644
--- a/src/quick/items/qquickpaletteproviderprivatebase_p.h
+++ b/src/quick/items/qquickpaletteproviderprivatebase_p.h
@@ -49,7 +49,7 @@
#include <QtQuick/private/qquickpalette_p.h>
#include <QtQuick/private/qquickabstractpaletteprovider_p.h>
-
+#include <QtGui/qwindow.h>
#include <QtQml/private/qlazilyallocated_p.h>
QT_BEGIN_NAMESPACE
@@ -150,6 +150,9 @@ public:
*/
virtual void updateChildrenPalettes(const QPalette &parentPalette);
+protected:
+ void setCurrentColorGroup();
+
private:
using PalettePtr = std::unique_ptr<QQuickPalette>;
using Self = QQuickPaletteProviderPrivateBase<I, Impl>;
@@ -160,7 +163,6 @@ private:
QQuickPalette *windowPalette() const;
- void setCurrentColorGroup();
void connectItem();
@@ -336,7 +338,10 @@ void QQuickPaletteProviderPrivateBase<I, Impl>::setCurrentColorGroup()
if constexpr (!isRootWindow<I>()) {
if (paletteData()) {
const bool enabled = itemWithPalette()->isEnabled();
- paletteData()->setCurrentGroup(enabled ? QPalette::Active : QPalette::Disabled);
+ const auto window = itemWithPalette()->window();
+ const bool active = window ? window->isActive() : true;
+ paletteData()->setCurrentGroup(enabled ? (active ? QPalette::Active : QPalette::Inactive)
+ : QPalette::Disabled);
}
}
}
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index e6bfde66ae..85df4a66b3 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -1512,6 +1512,10 @@ bool QQuickWindow::event(QEvent *e)
case QEvent::WindowDeactivate:
if (auto da = d->deliveryAgentPrivate())
da->handleWindowDeactivate(this);
+ Q_FALLTHROUGH();
+ case QEvent::WindowActivate:
+ if (d->contentItem)
+ QCoreApplication::sendEvent(d->contentItem, e);
break;
default:
break;
diff --git a/tests/auto/quick/qquickitem2/data/colorgroup.qml b/tests/auto/quick/qquickitem2/data/colorgroup.qml
new file mode 100644
index 0000000000..25782c9a52
--- /dev/null
+++ b/tests/auto/quick/qquickitem2/data/colorgroup.qml
@@ -0,0 +1,34 @@
+import QtQuick
+
+Item {
+ width: 300
+ height: 300
+ visible: true
+
+ palette.active.base: "blue"
+ palette.inactive.base: "red"
+ palette.disabled.base: "gray"
+
+ Rectangle {
+ id: background
+ objectName: "background"
+
+ anchors.centerIn: parent
+ width: parent.width / 2
+ height: parent.height / 2
+
+ color: palette.base
+
+ Rectangle {
+ id: foreground
+ objectName: "foreground"
+
+ anchors.centerIn: parent
+ width: parent.width / 2
+ height: parent.height / 2
+
+ color: palette.base
+ border.color: "black"
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
index b5e2f5e141..622a278411 100644
--- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
+++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
@@ -34,6 +34,7 @@
#include <QtQuick/qquickview.h>
#include <QtGui/private/qinputmethod_p.h>
#include <QtQuick/private/qquickloader_p.h>
+#include <QtQuick/private/qquickpalette_p.h>
#include <QtQuick/private/qquickrectangle_p.h>
#include <QtQuick/private/qquicktextinput_p.h>
#include <QtQuick/private/qquickitemchangelistener_p.h>
@@ -133,6 +134,7 @@ private slots:
void isAncestorOf();
void grab();
+ void colorGroup();
private:
QQmlEngine engine;
@@ -3716,6 +3718,48 @@ void tst_QQuickItem::isAncestorOf()
QVERIFY(!sub2.isAncestorOf(&sub2));
}
+/*
+ Verify that a nested item's palette responds to changes of the enabled state
+ and of the window's activation state by switching the current color group.
+*/
+void tst_QQuickItem::colorGroup()
+{
+ QQuickView view;
+
+ view.setSource(testFileUrl("colorgroup.qml"));
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+
+ QQuickItem *root = qobject_cast<QQuickItem *>(view.rootObject());
+ QQuickItem *background = root->findChild<QQuickItem *>("background");
+ QVERIFY(background);
+ QQuickItem *foreground = root->findChild<QQuickItem *>("foreground");
+ QVERIFY(foreground);
+
+ QQuickPalette *palette = foreground->property("palette").value<QQuickPalette*>();
+ QVERIFY(palette);
+ view.show();
+ QVERIFY(QTest::qWaitForWindowActive(&view));
+
+ QCOMPARE(palette->currentColorGroup(), QPalette::Active);
+ QCOMPARE(foreground->property("color").value<QColor>(), palette->active()->base());
+
+ background->setEnabled(false);
+ QCOMPARE(palette->currentColorGroup(), QPalette::Disabled);
+ QCOMPARE(foreground->property("color").value<QColor>(), palette->disabled()->base());
+
+ QWindow activationThief;
+ activationThief.show();
+ activationThief.requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(&activationThief));
+ QCOMPARE(palette->currentColorGroup(), QPalette::Disabled);
+ QCOMPARE(foreground->property("color").value<QColor>(), palette->disabled()->base());
+
+ background->setEnabled(true);
+ QCOMPARE(palette->currentColorGroup(), QPalette::Inactive);
+ QCOMPARE(foreground->property("color").value<QColor>(), palette->inactive()->base());
+}
+
QTEST_MAIN(tst_QQuickItem)
#include "tst_qquickitem.moc"