summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2023-05-15 17:32:28 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-05-21 18:36:37 +0200
commit17c589df94a2245ee92d45839c2cba73566d7310 (patch)
tree9c9c5e9366be2ed065f3e2b3cff09b40cb27fc66 /tests/auto/gui/kernel
parent0328e4297e339de8a2acd84979c667936f6fadf8 (diff)
Shoehorn AccentColor into QPalette and keep existing 64bit resolve mask
It is necessary to add an AccentColor role to QPalette. QPalette currently has 21 color roles and 3 color groups, which require 63 bits to resolve. The resolve mask is implemented with a qint64, which doesn't provide spare bits for another color role. The color role NoRole is used as a default value, marking that a role has not (yet) been defined. The enum value does not represent a valid brush, even though it can theoretically be stored in QPalette's shared data. This patch adds the enum value AccentColor to QPalette::ColorRole, increasing the available color roles to 22. To keep the resolve mask at 63 bits, AccentColor is mapped to NoRole in static constexpr bitPosition. As the enum range would exceed 64 bits without this tweak, 3 additional bits are substracted in the respective static assertion. With NoRole having no bit in the resolve mask, the following adaptions have been implemented: - QPalette::resolve() is adapted to explicitly ignore NoRole. - QPalette::isBrushSet() always returns false for NoRole. - tst_QPalette::setAllPossibleBrushes() to verify the latter - operator== ignores NoRole (documentation updated) AccentColor is added in tst_QPalette::roleValues and enum documentation is adapted. In QPalette's default constructor, the AccentColor brush is defaulting to the Highlight brush, it this is available. Otherwise it is made 30% darker or lighter than the Base brush, depending on dark/light mode heuristics. QPalette's data stram functions have been extended from QDataStream Version Qt_6_6. If earlier versions are de-serialised, the AccentColor defaults to Highlight. An autotest function dataStream() has been added to tst_QPalette. The QDataStream Version Qt_6_6 has been bumped to 21. tst_QDataStream has been adapted to the new version and the new color Role. Change-Id: I98bbf9de95fb83bda921e9614a0db3a3c0ebdf75 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/gui/kernel')
-rw-r--r--tests/auto/gui/kernel/qpalette/tst_qpalette.cpp51
1 files changed, 49 insertions, 2 deletions
diff --git a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp
index 81036bee0a..bf9799724e 100644
--- a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp
+++ b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp
@@ -23,6 +23,7 @@ private Q_SLOTS:
void cannotCheckIfInvalidBrushSet();
void checkIfBrushForCurrentGroupSet();
void cacheKey();
+ void dataStream();
};
void tst_QPalette::roleValues_data()
@@ -51,9 +52,10 @@ void tst_QPalette::roleValues_data()
QTest::newRow("QPalette::ToolTipBase") << int(QPalette::ToolTipBase) << 18;
QTest::newRow("QPalette::ToolTipText") << int(QPalette::ToolTipText) << 19;
QTest::newRow("QPalette::PlaceholderText") << int(QPalette::PlaceholderText) << 20;
+ QTest::newRow("QPalette::AccentColor") << int(QPalette::AccentColor) << 21;
// Change this value as you add more roles.
- QTest::newRow("QPalette::NColorRoles") << int(QPalette::NColorRoles) << 21;
+ QTest::newRow("QPalette::NColorRoles") << int(QPalette::NColorRoles) << 22;
}
void tst_QPalette::roleValues()
@@ -236,8 +238,14 @@ void tst_QPalette::setAllPossibleBrushes()
}
for (int r = 0; r < QPalette::NColorRoles; ++r) {
+ const QPalette::ColorRole role = static_cast<QPalette::ColorRole>(r);
for (int g = 0; g < QPalette::NColorGroups; ++g) {
- QVERIFY(p.isBrushSet(QPalette::ColorGroup(g), QPalette::ColorRole(r)));
+ const QPalette::ColorGroup group = static_cast<QPalette::ColorGroup>(g);
+ // NoRole has no resolve bit => isBrushSet returns false
+ if (role == QPalette::NoRole)
+ QVERIFY(!p.isBrushSet(group, role));
+ else
+ QVERIFY(p.isBrushSet(group, role));
}
}
}
@@ -341,5 +349,44 @@ void tst_QPalette::cacheKey()
loggerShallowDetach.dismiss();
}
+void tst_QPalette::dataStream()
+{
+ const QColor highlight(42, 42, 42);
+ const QColor accent(13, 13, 13);
+ QPalette palette;
+ palette.setBrush(QPalette::Highlight, highlight);
+ palette.setBrush(QPalette::AccentColor, accent);
+
+ // When saved with Qt_6_5 or earlier, AccentColor defaults to Highlight
+ {
+ QByteArray b;
+ {
+ QDataStream stream(&b, QIODevice::WriteOnly);
+ stream.setVersion(QDataStream::Qt_6_5);
+ stream << palette;
+ }
+ QPalette test;
+ QDataStream stream (&b, QIODevice::ReadOnly);
+ stream.setVersion(QDataStream::Qt_6_5);
+ stream >> test;
+ QCOMPARE(test.accentColor().color(), highlight);
+ }
+
+ // When saved with Qt_6_6 or later, AccentColor is saved explicitly
+ {
+ QByteArray b;
+ {
+ QDataStream stream(&b, QIODevice::WriteOnly);
+ stream.setVersion(QDataStream::Qt_6_6);
+ stream << palette;
+ }
+ QPalette test;
+ QDataStream stream (&b, QIODevice::ReadOnly);
+ stream.setVersion(QDataStream::Qt_6_6);
+ stream >> test;
+ QCOMPARE(test.accentColor().color(), accent);
+ }
+}
+
QTEST_MAIN(tst_QPalette)
#include "tst_qpalette.moc"