summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Uwe Broulik <[email protected]>2025-01-23 09:03:45 +0100
committerKai Uwe Broulik <[email protected]>2025-03-04 14:27:23 +0000
commit9194366923e409243617c34b640e82b54a2e7e05 (patch)
treec2e9dfc0f50ad6ff0bf6c82e0c8a9954b98e2219
parent93694e99c214a5166fc842f92659e42260230dce (diff)
QCssParser: Add missing palette roles
Qt CSS allows to read palette colors by using "palette(role)" but the supported roles haven't been updated since at least Qt 5.12, therefore placeholder-text and accent are not recognized. An "accent-color" property has been added to *set* the accent color on an object when it was introduced but it wasn't possible to *read* the accent color, even though it was documented to work. For sake of completeness, add tooltip-base and tooltip-text as well. Also amend the comment in QPalette to mention QCss and add a static_assert so this doesn't happen again. Pick-to: 6.9 6.9.0 6.8 Change-Id: I59ed09dc91fa18ca0356857c8ddb43946b309035 Reviewed-by: Axel Spoerl <[email protected]>
-rw-r--r--src/gui/kernel/qpalette.h3
-rw-r--r--src/gui/text/qcssparser.cpp15
-rw-r--r--src/gui/text/qcssparser_p.h7
-rw-r--r--src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc3
-rw-r--r--tests/auto/gui/text/qcssparser/tst_qcssparser.cpp1
5 files changed, 23 insertions, 6 deletions
diff --git a/src/gui/kernel/qpalette.h b/src/gui/kernel/qpalette.h
index a6162e10903..965518116cf 100644
--- a/src/gui/kernel/qpalette.h
+++ b/src/gui/kernel/qpalette.h
@@ -45,7 +45,8 @@ public:
operator QVariant() const;
// Do not change the order, the serialization format depends on it
- // Ensure these values are kept in sync with QQuickColorGroup's properties.
+ // Ensure these values are kept in sync with QQuickColorGroup's properties
+ // and QCss::KnownValue!
enum ColorGroup { Active, Disabled, Inactive, NColorGroups, Current, All, Normal = Active };
Q_ENUM(ColorGroup)
enum ColorRole { WindowText, Button, Light, Midlight, Dark, Mid,
diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp
index 794e400c34b..87818b00107 100644
--- a/src/gui/text/qcssparser.cpp
+++ b/src/gui/text/qcssparser.cpp
@@ -161,6 +161,7 @@ static const QCssKnownValue properties[NumProperties - 1] = {
};
static const QCssKnownValue values[NumKnownValues - 1] = {
+ { "accent", Value_Accent },
{ "active", Value_Active },
{ "alternate-base", Value_AlternateBase },
{ "always", Value_Always },
@@ -204,6 +205,7 @@ static const QCssKnownValue values[NumKnownValues - 1] = {
{ "midlight", Value_Midlight },
{ "miterjoin", Value_MiterJoin},
{ "native", Value_Native },
+ { "no-role", Value_NoRole },
{ "none", Value_None },
{ "normal", Value_Normal },
{ "nowrap", Value_NoWrap },
@@ -212,6 +214,7 @@ static const QCssKnownValue values[NumKnownValues - 1] = {
{ "on", Value_On },
{ "outset", Value_Outset },
{ "overline", Value_Overline },
+ { "placeholder-text", Value_PlaceholderText },
{ "pre", Value_Pre },
{ "pre-line", Value_PreLine },
{ "pre-wrap", Value_PreWrap },
@@ -230,6 +233,8 @@ static const QCssKnownValue values[NumKnownValues - 1] = {
{ "super", Value_Super },
{ "svgmiterjoin", Value_SvgMiterJoin},
{ "text", Value_Text },
+ { "tooltip-base", Value_ToolTipBase },
+ { "tooltip-text", Value_ToolTipText },
{ "top", Value_Top },
{ "transparent", Value_Transparent },
{ "underline", Value_Underline },
@@ -244,10 +249,10 @@ static const QCssKnownValue values[NumKnownValues - 1] = {
};
//Map id to strings as they appears in the 'values' array above
-static const short indexOfId[NumKnownValues] = { 0, 44, 51, 45, 52, 53, 60, 37, 28, 78, 79, 27, 46, 6, 71, 50,
- 31, 65, 66, 29, 55, 69, 7, 11, 42, 62, 20, 14, 18, 19, 21, 23, 54, 26, 49, 75, 39, 3, 2, 43, 70, 17, 12,
- 63, 15, 34, 72, 35, 73, 61, 74, 36, 64, 22, 56, 41, 5, 57, 67, 77, 9, 30, 40, 13, 38, 68, 8, 10, 4, 76,
- 59, 24, 25, 32, 33, 1, 16, 0, 58, 48, 47 };
+static const short indexOfId[NumKnownValues] = { 0, 46, 54, 47, 55, 56, 63, 38, 29, 83, 84, 28, 48, 7, 76, 52,
+ 32, 68, 69, 30, 58, 74, 8, 12, 43, 65, 21, 15, 19, 20, 22, 24, 57, 27, 51, 80, 40, 4, 3, 45, 75, 18, 13,
+ 66, 16, 35, 77, 36, 78, 64, 79, 37, 67, 23, 59, 42, 6, 60, 70, 82, 10, 31, 41, 14, 39, 71, 9, 11, 5, 81,
+ 62, 25, 26, 33, 34, 2, 44, 72, 73, 53, 0, 17, 1, 61, 50, 49 };
QString Value::toString() const
{
@@ -731,6 +736,8 @@ static ColorData parseColorValue(QCss::Value v)
const QString &identifier = lst.at(0);
if ((identifier.compare("palette"_L1, Qt::CaseInsensitive)) == 0) {
+ static_assert((Value_LastColorRole - Value_FirstColorRole + 1) == QPalette::ColorRole::NColorRoles);
+
int role = findKnownValue(lst.at(1).trimmed(), values, NumKnownValues);
if (role >= Value_FirstColorRole && role <= Value_LastColorRole)
return (QPalette::ColorRole)(role-Value_FirstColorRole);
diff --git a/src/gui/text/qcssparser_p.h b/src/gui/text/qcssparser_p.h
index 22f71e0e8c2..30678299245 100644
--- a/src/gui/text/qcssparser_p.h
+++ b/src/gui/text/qcssparser_p.h
@@ -258,7 +258,12 @@ enum KnownValue {
Value_Link,
Value_LinkVisited,
Value_AlternateBase,
- Value_LastColorRole = Value_AlternateBase,
+ Value_NoRole,
+ Value_ToolTipBase,
+ Value_ToolTipText,
+ Value_PlaceholderText,
+ Value_Accent,
+ Value_LastColorRole = Value_Accent,
Value_Disabled,
Value_Active,
diff --git a/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc b/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc
index 0c9f6789d4e..4a5978566ed 100644
--- a/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc
+++ b/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc
@@ -3451,8 +3451,11 @@
| \c link-visited \br
| \c mid \br
| \c midlight \br
+ | \c placeholder-text \br
| \c shadow \br
| \c text \br
+ | \c tooltip-base \br
+ | \c tooltip-text \br
| \c window \br
| \c window-text \br
\li These values correspond the \l{QPalette::ColorRole}{Color roles}
diff --git a/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp b/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp
index c90cba5b4fc..3da46e413db 100644
--- a/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp
+++ b/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp
@@ -899,6 +899,7 @@ void tst_QCssParser::colorValue_data()
QTest::newRow("invalid7") << "color: hsla(1, a, 1, 21)" << QColor();
QTest::newRow("role") << "color: palette(base)" << qApp->palette().color(QPalette::Base);
QTest::newRow("role2") << "color: palette( window-text ) " << qApp->palette().color(QPalette::WindowText);
+ QTest::newRow("role3") << "color: palette(accent)" << qApp->palette().color(QPalette::Accent);
QTest::newRow("transparent") << "color: transparent" << QColor(Qt::transparent);
QTest::newRow("rgb-invalid") << "color: rgb(10, 20, 30, 40)" << QColor();