Rename accent color in QPalette
Accent color role has been renamed according to name rule of other color roles in QPalette. Fixes: QTBUG-116107 Pick-to: 6.6 Change-Id: I70ac98a1e97afbdc7ea5f8d79f808c307e170712 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
This commit is contained in:
parent
7c55651ff2
commit
90980a54e8
@ -13,15 +13,15 @@ QT_BEGIN_NAMESPACE
|
||||
|
||||
constexpr QPalette::ResolveMask QPalettePrivate::colorRoleOffset(QPalette::ColorGroup colorGroup)
|
||||
{
|
||||
// Exclude NoRole; that bit is used for AccentColor
|
||||
// Exclude NoRole; that bit is used for Accent
|
||||
return (qToUnderlying(QPalette::NColorRoles) - 1) * qToUnderlying(colorGroup);
|
||||
}
|
||||
|
||||
constexpr QPalette::ResolveMask QPalettePrivate::bitPosition(QPalette::ColorGroup colorGroup,
|
||||
QPalette::ColorRole colorRole)
|
||||
{
|
||||
// Map AccentColor into NoRole for resolving purposes
|
||||
if (colorRole == QPalette::AccentColor)
|
||||
// Map Accent into NoRole for resolving purposes
|
||||
if (colorRole == QPalette::Accent)
|
||||
colorRole = QPalette::NoRole;
|
||||
|
||||
return colorRole + colorRoleOffset(colorGroup);
|
||||
@ -74,12 +74,12 @@ static void qt_ensure_default_accent_color(QPalette &pal)
|
||||
// Act only for color groups where no accent color is set
|
||||
for (int i = 0; i < QPalette::NColorGroups; ++i) {
|
||||
const QPalette::ColorGroup group = static_cast<QPalette::ColorGroup>(i);
|
||||
if (!pal.isBrushSet(group, QPalette::AccentColor)) {
|
||||
if (!pal.isBrushSet(group, QPalette::Accent)) {
|
||||
// Default to highlight if available, otherwise use a shade of base
|
||||
const QBrush accentBrush = pal.isBrushSet(group, QPalette::Highlight)
|
||||
? pal.brush(group, QPalette::Highlight)
|
||||
: pal.brush(group, QPalette::Base).color().lighter(lighter);
|
||||
pal.setBrush(group, QPalette::AccentColor, accentBrush);
|
||||
pal.setBrush(group, QPalette::Accent, accentBrush);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -509,7 +509,7 @@ static void qt_palette_from_color(QPalette &pal, const QColor &button)
|
||||
item. By default, the highlight color is
|
||||
Qt::darkBlue.
|
||||
|
||||
\value [since 6.6] AccentColor
|
||||
\value [since 6.6] Accent
|
||||
A color that typically contrasts or complements
|
||||
Base, Window and Button colors. It usually represents
|
||||
the users' choice of desktop personalisation.
|
||||
@ -983,7 +983,7 @@ QPalette QPalette::resolve(const QPalette &other) const
|
||||
palette.detach();
|
||||
|
||||
for (int role = 0; role < int(NColorRoles); ++role) {
|
||||
// Don't resolve NoRole, its bits are needed for AccentColor (see bitPosition)
|
||||
// Don't resolve NoRole, its bits are needed for Accent (see bitPosition)
|
||||
if (role == NoRole)
|
||||
continue;
|
||||
|
||||
@ -1122,9 +1122,9 @@ QDataStream &operator>>(QDataStream &s, QPalette &p)
|
||||
p.setBrush(group, (QPalette::ColorRole)role, tmp);
|
||||
}
|
||||
|
||||
// AccentColor defaults to Highlight for stream versions that don't have it.
|
||||
// Accent defaults to Highlight for stream versions that don't have it.
|
||||
if (s.version() < QDataStream::Qt_6_6)
|
||||
p.setBrush(group, QPalette::AccentColor, p.brush(group, QPalette::Highlight));
|
||||
p.setBrush(group, QPalette::Accent, p.brush(group, QPalette::Highlight));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -55,8 +55,8 @@ public:
|
||||
NoRole,
|
||||
ToolTipBase, ToolTipText,
|
||||
PlaceholderText,
|
||||
AccentColor,
|
||||
NColorRoles = AccentColor + 1,
|
||||
Accent,
|
||||
NColorRoles = Accent + 1,
|
||||
};
|
||||
Q_ENUM(ColorRole)
|
||||
|
||||
@ -99,7 +99,7 @@ public:
|
||||
inline const QBrush &link() const { return brush(Link); }
|
||||
inline const QBrush &linkVisited() const { return brush(LinkVisited); }
|
||||
inline const QBrush &placeholderText() const { return brush(PlaceholderText); }
|
||||
inline const QBrush &accentColor() const { return brush(AccentColor); }
|
||||
inline const QBrush &accent() const { return brush(Accent); }
|
||||
|
||||
bool operator==(const QPalette &p) const;
|
||||
inline bool operator!=(const QPalette &p) const { return !(operator==(p)); }
|
||||
|
@ -395,9 +395,9 @@ Q_GUI_EXPORT QPalette qt_fusionPalette()
|
||||
fusionPalette.setBrush(QPalette::Inactive, QPalette::Highlight, highlight);
|
||||
fusionPalette.setBrush(QPalette::Disabled, QPalette::Highlight, disabledHighlight);
|
||||
|
||||
fusionPalette.setBrush(QPalette::Active, QPalette::AccentColor, highlight);
|
||||
fusionPalette.setBrush(QPalette::Inactive, QPalette::AccentColor, highlight);
|
||||
fusionPalette.setBrush(QPalette::Disabled, QPalette::AccentColor, disabledHighlight);
|
||||
fusionPalette.setBrush(QPalette::Active, QPalette::Accent, highlight);
|
||||
fusionPalette.setBrush(QPalette::Inactive, QPalette::Accent, highlight);
|
||||
fusionPalette.setBrush(QPalette::Disabled, QPalette::Accent, disabledHighlight);
|
||||
|
||||
fusionPalette.setBrush(QPalette::PlaceholderText, placeholder);
|
||||
|
||||
|
@ -47,7 +47,7 @@ static const QCssKnownValue properties[NumProperties - 1] = {
|
||||
{ "-qt-style-features", QtStyleFeatures },
|
||||
{ "-qt-table-type", QtTableType },
|
||||
{ "-qt-user-state", QtUserState },
|
||||
{ "accent-color", QtAccentColor },
|
||||
{ "accent-color", QtAccent },
|
||||
{ "alternate-background-color", QtAlternateBackground },
|
||||
{ "background", Background },
|
||||
{ "background-attachment", BackgroundAttachment },
|
||||
@ -1347,7 +1347,7 @@ bool ValueExtractor::extractPalette(QBrush *foreground,
|
||||
QBrush *selectedBackground,
|
||||
QBrush *alternateBackground,
|
||||
QBrush *placeHolderTextForeground,
|
||||
QBrush *accentColor)
|
||||
QBrush *accent)
|
||||
{
|
||||
bool hit = false;
|
||||
for (int i = 0; i < declarations.size(); ++i) {
|
||||
@ -1358,7 +1358,7 @@ bool ValueExtractor::extractPalette(QBrush *foreground,
|
||||
case QtSelectionBackground: *selectedBackground = decl.brushValue(pal); break;
|
||||
case QtAlternateBackground: *alternateBackground = decl.brushValue(pal); break;
|
||||
case QtPlaceHolderTextColor: *placeHolderTextForeground = decl.brushValue(pal); break;
|
||||
case QtAccentColor: *accentColor = decl.brushValue(pal); break;
|
||||
case QtAccent: *accent = decl.brushValue(pal); break;
|
||||
default: continue;
|
||||
}
|
||||
hit = true;
|
||||
|
@ -166,7 +166,7 @@ enum Property {
|
||||
WordSpacing,
|
||||
TextDecorationColor,
|
||||
QtPlaceHolderTextColor,
|
||||
QtAccentColor,
|
||||
QtAccent,
|
||||
NumProperties
|
||||
};
|
||||
|
||||
@ -826,7 +826,7 @@ struct Q_GUI_EXPORT ValueExtractor
|
||||
bool extractOutline(int *borders, QBrush *colors, BorderStyle *Styles, QSize *radii, int *offsets);
|
||||
bool extractPalette(QBrush *foreground, QBrush *selectedForeground, QBrush *selectedBackground,
|
||||
QBrush *alternateBackground, QBrush *placeHolderTextForeground,
|
||||
QBrush *accentColor);
|
||||
QBrush *accent);
|
||||
int extractStyleFeatures();
|
||||
bool extractImage(QIcon *icon, Qt::Alignment *a, QSize *size);
|
||||
bool extractIcon(QIcon *icon, QSize *size);
|
||||
|
@ -95,7 +95,7 @@ static QPalette *qt_mac_createSystemPalette()
|
||||
palette->setColor(QPalette::Disabled, QPalette::PlaceholderText, qc);
|
||||
|
||||
qc = qt_mac_toQColor([NSColor controlAccentColor]);
|
||||
palette->setColor(QPalette::AccentColor, qc);
|
||||
palette->setColor(QPalette::Accent, qc);
|
||||
|
||||
return palette;
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ void QIOSTheme::initializeSystemPalette()
|
||||
s_systemPalette.setBrush(QPalette::HighlightedText, qt_mac_toQBrush(UIColor.labelColor.CGColor));
|
||||
|
||||
if (@available(ios 15.0, *))
|
||||
s_systemPalette.setBrush(QPalette::AccentColor, qt_mac_toQBrush(UIColor.tintColor.CGColor));
|
||||
s_systemPalette.setBrush(QPalette::Accent, qt_mac_toQBrush(UIColor.tintColor.CGColor));
|
||||
}
|
||||
|
||||
const QPalette *QIOSTheme::palette(QPlatformTheme::Palette type) const
|
||||
|
@ -277,7 +277,7 @@ static void populateLightSystemBasePalette(QPalette &result)
|
||||
result.setColor(QPalette::Midlight, getSysColor(COLOR_3DLIGHT));
|
||||
result.setColor(QPalette::Shadow, getSysColor(COLOR_3DDKSHADOW));
|
||||
result.setColor(QPalette::HighlightedText, getSysColor(COLOR_HIGHLIGHTTEXT));
|
||||
result.setColor(QPalette::AccentColor, accent);
|
||||
result.setColor(QPalette::Accent, accent);
|
||||
|
||||
result.setColor(QPalette::Link, linkColor);
|
||||
result.setColor(QPalette::LinkVisited, accentDarkest);
|
||||
@ -351,7 +351,7 @@ static void populateDarkSystemBasePalette(QPalette &result)
|
||||
result.setColor(QPalette::All, QPalette::ToolTipBase, buttonColor);
|
||||
result.setColor(QPalette::All, QPalette::ToolTipText, foreground.darker(120));
|
||||
result.setColor(QPalette::All, QPalette::PlaceholderText, placeHolderColor(foreground));
|
||||
result.setColor(QPalette::All, QPalette::AccentColor, accent);
|
||||
result.setColor(QPalette::All, QPalette::Accent, accent);
|
||||
}
|
||||
|
||||
static inline QPalette toolTipPalette(const QPalette &systemPalette, bool light)
|
||||
@ -591,7 +591,7 @@ QPalette QWindowsTheme::systemPalette(Qt::ColorScheme colorScheme)
|
||||
result.color(QPalette::Inactive, QPalette::Window));
|
||||
result.setColor(QPalette::Inactive, QPalette::HighlightedText,
|
||||
result.color(QPalette::Inactive, QPalette::Text));
|
||||
result.setColor(QPalette::Inactive, QPalette::AccentColor,
|
||||
result.setColor(QPalette::Inactive, QPalette::Accent,
|
||||
result.color(QPalette::Inactive, QPalette::Window));
|
||||
}
|
||||
|
||||
@ -606,7 +606,7 @@ QPalette QWindowsTheme::systemPalette(Qt::ColorScheme colorScheme)
|
||||
result.setColor(QPalette::Disabled, QPalette::ButtonText, disabled);
|
||||
result.setColor(QPalette::Disabled, QPalette::Highlight, result.color(QPalette::Highlight));
|
||||
result.setColor(QPalette::Disabled, QPalette::HighlightedText, result.color(QPalette::HighlightedText));
|
||||
result.setColor(QPalette::Disabled, QPalette::AccentColor, disabled);
|
||||
result.setColor(QPalette::Disabled, QPalette::Accent, disabled);
|
||||
result.setColor(QPalette::Disabled, QPalette::Base, result.window().color());
|
||||
return result;
|
||||
}
|
||||
|
@ -1345,7 +1345,7 @@
|
||||
\row
|
||||
\li \b{\c accent-color}
|
||||
\li \l{#Brush}{Brush} \br
|
||||
\li The property sets the \c AccentColor, which is used to emphasize
|
||||
\li The property sets the \c Accent, which is used to emphasize
|
||||
interactive UI elements.
|
||||
If this property is not set, it defaults to the \c highlight color.
|
||||
|
||||
@ -3056,7 +3056,7 @@
|
||||
\row
|
||||
\li \b{PaletteRole} \target PaletteRole
|
||||
\li \c alternate-base \br
|
||||
| \c accentColor \br
|
||||
| \c accent \br
|
||||
| \c base \br
|
||||
| \c bright-text \br
|
||||
| \c button \br
|
||||
|
@ -439,13 +439,13 @@ struct QStyleSheetPaletteData : public QSharedData
|
||||
const QBrush &selectedBackground,
|
||||
const QBrush &alternateBackground,
|
||||
const QBrush &placeHolderTextForeground,
|
||||
const QBrush &accentColor)
|
||||
const QBrush &accent)
|
||||
: foreground(foreground)
|
||||
, selectionForeground(selectedForeground)
|
||||
, selectionBackground(selectedBackground)
|
||||
, alternateBackground(alternateBackground)
|
||||
, placeholderForeground(placeHolderTextForeground)
|
||||
, accentColor(accentColor)
|
||||
, accent(accent)
|
||||
{ }
|
||||
|
||||
QBrush foreground;
|
||||
@ -453,7 +453,7 @@ struct QStyleSheetPaletteData : public QSharedData
|
||||
QBrush selectionBackground;
|
||||
QBrush alternateBackground;
|
||||
QBrush placeholderForeground;
|
||||
QBrush accentColor;
|
||||
QBrush accent;
|
||||
};
|
||||
|
||||
struct QStyleSheetGeometryData : public QSharedData
|
||||
@ -970,11 +970,11 @@ QRenderRule::QRenderRule(const QList<Declaration> &declarations, const QObject *
|
||||
QBrush selectedBackground;
|
||||
QBrush alternateBackground;
|
||||
QBrush placeHolderTextForeground;
|
||||
QBrush accentColor;
|
||||
QBrush accent;
|
||||
if (v.extractPalette(&foreground, &selectedForeground, &selectedBackground,
|
||||
&alternateBackground, &placeHolderTextForeground, &accentColor)) {
|
||||
&alternateBackground, &placeHolderTextForeground, &accent)) {
|
||||
pal = new QStyleSheetPaletteData(foreground, selectedForeground, selectedBackground,
|
||||
alternateBackground, placeHolderTextForeground, accentColor);
|
||||
alternateBackground, placeHolderTextForeground, accent);
|
||||
}
|
||||
|
||||
QIcon imgIcon;
|
||||
@ -1514,8 +1514,8 @@ void QRenderRule::configurePalette(QPalette *p, QPalette::ColorGroup cg, const Q
|
||||
p->setBrush(cg, QPalette::AlternateBase, pal->alternateBackground);
|
||||
if (pal->placeholderForeground.style() != Qt::NoBrush)
|
||||
p->setBrush(cg, QPalette::PlaceholderText, pal->placeholderForeground);
|
||||
if (pal->accentColor.style() != Qt::NoBrush)
|
||||
p->setBrush(cg, QPalette::AccentColor, pal->accentColor);
|
||||
if (pal->accent.style() != Qt::NoBrush)
|
||||
p->setBrush(cg, QPalette::Accent, pal->accent);
|
||||
}
|
||||
|
||||
bool QRenderRule::hasModification() const
|
||||
|
@ -295,7 +295,7 @@ static int NColorRoles[] = {
|
||||
QPalette::PlaceholderText + 1, // Qt_5_12
|
||||
QPalette::PlaceholderText + 1, // Qt_5_13, Qt_5_14, Qt_5_15
|
||||
QPalette::PlaceholderText + 1, // Qt_6_0
|
||||
QPalette::AccentColor + 1, // Qt_6_6
|
||||
QPalette::Accent + 1, // Qt_6_6
|
||||
0 // add the correct value for Qt_5_14 here later
|
||||
};
|
||||
|
||||
@ -2393,7 +2393,7 @@ void tst_QDataStream::setVersion()
|
||||
*/
|
||||
|
||||
// revise the test if new color roles or color groups are added
|
||||
QCOMPARE(QPalette::NColorRoles, QPalette::AccentColor + 1);
|
||||
QCOMPARE(QPalette::NColorRoles, QPalette::Accent + 1);
|
||||
QCOMPARE(static_cast<int>(QPalette::NColorGroups), 3);
|
||||
|
||||
QByteArray ba2;
|
||||
|
@ -52,7 +52,7 @@ 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;
|
||||
QTest::newRow("QPalette::Accent") << int(QPalette::Accent) << 21;
|
||||
|
||||
// Change this value as you add more roles.
|
||||
QTest::newRow("QPalette::NColorRoles") << int(QPalette::NColorRoles) << 22;
|
||||
@ -355,9 +355,9 @@ void tst_QPalette::dataStream()
|
||||
const QColor accent(13, 13, 13);
|
||||
QPalette palette;
|
||||
palette.setBrush(QPalette::Highlight, highlight);
|
||||
palette.setBrush(QPalette::AccentColor, accent);
|
||||
palette.setBrush(QPalette::Accent, accent);
|
||||
|
||||
// When saved with Qt_6_5 or earlier, AccentColor defaults to Highlight
|
||||
// When saved with Qt_6_5 or earlier, Accent defaults to Highlight
|
||||
{
|
||||
QByteArray b;
|
||||
{
|
||||
@ -369,10 +369,10 @@ void tst_QPalette::dataStream()
|
||||
QDataStream stream (&b, QIODevice::ReadOnly);
|
||||
stream.setVersion(QDataStream::Qt_6_5);
|
||||
stream >> test;
|
||||
QCOMPARE(test.accentColor().color(), highlight);
|
||||
QCOMPARE(test.accent().color(), highlight);
|
||||
}
|
||||
|
||||
// When saved with Qt_6_6 or later, AccentColor is saved explicitly
|
||||
// When saved with Qt_6_6 or later, Accent is saved explicitly
|
||||
{
|
||||
QByteArray b;
|
||||
{
|
||||
@ -384,7 +384,7 @@ void tst_QPalette::dataStream()
|
||||
QDataStream stream (&b, QIODevice::ReadOnly);
|
||||
stream.setVersion(QDataStream::Qt_6_6);
|
||||
stream >> test;
|
||||
QCOMPARE(test.accentColor().color(), accent);
|
||||
QCOMPARE(test.accent().color(), accent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1548,9 +1548,9 @@ void tst_QCssParser::gradient()
|
||||
QBrush selectedBackground;
|
||||
QBrush alternateBackground;
|
||||
QBrush placeHolderTextForeground;
|
||||
QBrush accentColor;
|
||||
QBrush accent;
|
||||
QVERIFY(ve.extractPalette(&foreground, &selectedForeground, &selectedBackground,
|
||||
&alternateBackground, &placeHolderTextForeground, &accentColor));
|
||||
&alternateBackground, &placeHolderTextForeground, &accent));
|
||||
|
||||
if (type == "linear") {
|
||||
QCOMPARE(selectedBackground.style(), Qt::LinearGradientPattern);
|
||||
|
@ -106,7 +106,7 @@ private slots:
|
||||
void QTBUG36933_brokenPseudoClassLookup();
|
||||
void styleSheetChangeBeforePolish();
|
||||
void placeholderColor();
|
||||
void accentColor();
|
||||
void accent();
|
||||
void enumPropertySelector_data();
|
||||
void enumPropertySelector();
|
||||
//at the end because it mess with the style.
|
||||
@ -2363,13 +2363,13 @@ void tst_QStyleSheetStyle::placeholderColor()
|
||||
QCOMPARE(le1.palette().placeholderText().color(), QColor(phSpec));
|
||||
}
|
||||
|
||||
void tst_QStyleSheetStyle::accentColor()
|
||||
void tst_QStyleSheetStyle::accent()
|
||||
{
|
||||
QLineEdit lineEdit;
|
||||
const QColor universe(42, 42, 42);
|
||||
lineEdit.setStyleSheet(QString("QLineEdit { accent-color: %1; }").arg(universe.name()));
|
||||
lineEdit.ensurePolished();
|
||||
QCOMPARE(lineEdit.palette().accentColor().color(), universe);
|
||||
QCOMPARE(lineEdit.palette().accent().color(), universe);
|
||||
}
|
||||
|
||||
void tst_QStyleSheetStyle::enumPropertySelector_data()
|
||||
|
Loading…
Reference in New Issue
Block a user