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 Change-Id: Iebb9d15d56f5d72d7ec68b7a0babdf5825b92665 Reviewed-by: Paul Wicking <paul.wicking@qt.io> (cherry picked from commit ebf733c6fb5503a48a0723d7c6b86a8e1bc60363) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
7b690681d3
commit
69b1b91e0d
@ -60,6 +60,34 @@ static QColor qt_mix_colors(QColor a, QColor b)
|
|||||||
(a.blue() + b.blue()) / 2, (a.alpha() + b.alpha()) / 2);
|
(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)
|
static void qt_palette_from_color(QPalette &pal, const QColor &button)
|
||||||
{
|
{
|
||||||
int h, s, v;
|
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,
|
pal.setColorGroup(QPalette::Disabled, buttonBrushDark, buttonBrush, buttonBrushLight150,
|
||||||
buttonBrushDark, buttonBrushDark150, buttonBrushDark,
|
buttonBrushDark, buttonBrushDark150, buttonBrushDark,
|
||||||
whiteBrush, buttonBrush, buttonBrush);
|
whiteBrush, buttonBrush, buttonBrush);
|
||||||
|
|
||||||
|
qt_placeholder_from_text(pal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -569,6 +599,8 @@ QPalette::QPalette(const QBrush &windowText, const QBrush &button,
|
|||||||
init();
|
init();
|
||||||
setColorGroup(All, windowText, button, light, dark, mid, text, bright_text,
|
setColorGroup(All, windowText, button, light, dark, mid, text, bright_text,
|
||||||
base, window);
|
base, window);
|
||||||
|
|
||||||
|
qt_placeholder_from_text(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -624,6 +656,8 @@ QPalette::QPalette(const QColor &button, const QColor &window)
|
|||||||
setColorGroup(Disabled, disabledForeground, buttonBrush, buttonBrushLight150,
|
setColorGroup(Disabled, disabledForeground, buttonBrush, buttonBrushLight150,
|
||||||
buttonBrushDark, buttonBrushDark150, disabledForeground,
|
buttonBrushDark, buttonBrushDark150, disabledForeground,
|
||||||
whiteBrush, baseBrush, windowBrush);
|
whiteBrush, baseBrush, windowBrush);
|
||||||
|
|
||||||
|
qt_placeholder_from_text(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user