summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qpalette.cpp
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2022-07-29 20:40:01 +0200
committerAxel Spoerl <axel.spoerl@qt.io>2022-08-01 12:07:08 +0200
commitebf733c6fb5503a48a0723d7c6b86a8e1bc60363 (patch)
tree0f30a78ea6c4ca829058c0b0120b3e669958c80e /src/gui/kernel/qpalette.cpp
parent4fdadd2348eb2c952650fbd8b9e5d18ed41405dc (diff)
Derive PlaceholderText color from Text color in QPalette
Until Qt 5.15, PlaceholderText color was automatically derived from the Text color, dimmed by 50% (set alpha to 128, assuming the text color is fully opaque). This method has been adapted in the static qt_fusionPalette() method. No other static method to populate palettes defines a PlaceholderText color. As a consequence, the Text color is used to render placeholder text characters. This patch adds a static method, that sets missing PlaceholderText colors by deriving them from the corresponding Text color. It takes a dim factor by which the opacity is reduced versus the corresponding Text color. Fixes: QTBUG-105049 Pick-to: 6.4 6.3 6.2 Change-Id: Iebb9d15d56f5d72d7ec68b7a0babdf5825b92665 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/gui/kernel/qpalette.cpp')
-rw-r--r--src/gui/kernel/qpalette.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp
index 2b6a7e643f..396bd46ea6 100644
--- a/src/gui/kernel/qpalette.cpp
+++ b/src/gui/kernel/qpalette.cpp
@@ -60,6 +60,34 @@ static QColor qt_mix_colors(QColor a, QColor b)
(a.blue() + b.blue()) / 2, (a.alpha() + b.alpha()) / 2);
}
+/*!
+ \internal
+
+ Derive undefined \l PlaceholderText colors from \l Text colors.
+ Unless already set, PlaceholderText colors will be derived from their Text pendents.
+ Colors of existing PlaceHolderText brushes will not be replaced.
+
+ \a alpha represents the dim factor as a percentage. By default, a PlaceHolderText color
+ becomes a 50% more transparent version of the corresponding Text color.
+*/
+static void qt_placeholder_from_text(QPalette &pal, int alpha = 50)
+{
+ if (alpha < 0 or alpha > 100)
+ return;
+
+ for (int cg = 0; cg < int(QPalette::NColorGroups); ++cg) {
+ const QPalette::ColorGroup group = QPalette::ColorGroup(cg);
+
+ // skip if the brush has been set already
+ if (!pal.isBrushSet(group, QPalette::PlaceholderText)) {
+ QColor c = pal.color(group, QPalette::Text);
+ const int a = (c.alpha() * alpha) / 100;
+ c.setAlpha(a);
+ pal.setColor(group, QPalette::PlaceholderText, c);
+ }
+ }
+}
+
static void qt_palette_from_color(QPalette &pal, const QColor &button)
{
int h, s, v;
@@ -82,6 +110,8 @@ static void qt_palette_from_color(QPalette &pal, const QColor &button)
pal.setColorGroup(QPalette::Disabled, buttonBrushDark, buttonBrush, buttonBrushLight150,
buttonBrushDark, buttonBrushDark150, buttonBrushDark,
whiteBrush, buttonBrush, buttonBrush);
+
+ qt_placeholder_from_text(pal);
}
/*!
@@ -569,6 +599,8 @@ QPalette::QPalette(const QBrush &windowText, const QBrush &button,
init();
setColorGroup(All, windowText, button, light, dark, mid, text, bright_text,
base, window);
+
+ qt_placeholder_from_text(*this);
}
@@ -624,6 +656,8 @@ QPalette::QPalette(const QColor &button, const QColor &window)
setColorGroup(Disabled, disabledForeground, buttonBrush, buttonBrushLight150,
buttonBrushDark, buttonBrushDark150, disabledForeground,
whiteBrush, baseBrush, windowBrush);
+
+ qt_placeholder_from_text(*this);
}
/*!