diff options
Diffstat (limited to 'src/gui/kernel/qpalette.cpp')
-rw-r--r-- | src/gui/kernel/qpalette.cpp | 99 |
1 files changed, 28 insertions, 71 deletions
diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp index ac7a1a9fef..e308b796ab 100644 --- a/src/gui/kernel/qpalette.cpp +++ b/src/gui/kernel/qpalette.cpp @@ -1,8 +1,7 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only -#include "qpalette.h" -#include "qguiapplication.h" +#include "qpalette_p.h" #include "qguiapplication_p.h" #include "qdatastream.h" #include "qvariant.h" @@ -12,65 +11,11 @@ QT_BEGIN_NAMESPACE -static int qt_palette_count = 1; - -static constexpr QPalette::ResolveMask colorRoleOffset(QPalette::ColorGroup colorGroup) -{ - // Exclude NoRole; that bit is used for AccentColor - return (qToUnderlying(QPalette::NColorRoles) - 1) * qToUnderlying(colorGroup); -} - -static constexpr QPalette::ResolveMask bitPosition(QPalette::ColorGroup colorGroup, - QPalette::ColorRole colorRole) -{ - // Map AccentColor into NoRole for resolving purposes - if (colorRole == QPalette::AccentColor) - colorRole = QPalette::NoRole; - - return colorRole + colorRoleOffset(colorGroup); -} - -static_assert(bitPosition(QPalette::ColorGroup(QPalette::NColorGroups - 1), +static_assert(QPalettePrivate::bitPosition(QPalette::ColorGroup(QPalette::NColorGroups - 1), QPalette::ColorRole(QPalette::NColorRoles - 1)) < sizeof(QPalette::ResolveMask) * CHAR_BIT, "The resolve mask type is not wide enough to fit the entire bit mask."); -class QPalettePrivate -{ -public: - class Data : public QSharedData { - public: - // Every instance of Data has to have a unique serial number, even - // if it gets created by copying another - we wouldn't create a copy - // in the first place if the serial number should be the same! - Data(const Data &other) - : QSharedData(other) - { - for (int grp = 0; grp < int(QPalette::NColorGroups); grp++) { - for (int role = 0; role < int(QPalette::NColorRoles); role++) - br[grp][role] = other.br[grp][role]; - } - } - Data() = default; - - QBrush br[QPalette::NColorGroups][QPalette::NColorRoles]; - const int ser_no = qt_palette_count++; - }; - - QPalettePrivate(const QExplicitlySharedDataPointer<Data> &data) - : ref(1), data(data) - { } - QPalettePrivate() - : QPalettePrivate(QExplicitlySharedDataPointer<Data>(new Data)) - { } - - QAtomicInt ref; - QPalette::ResolveMask resolveMask = {0}; - static inline int qt_palette_private_count = 0; - int detach_no = ++qt_palette_private_count; - QExplicitlySharedDataPointer<Data> data; -}; - static QColor qt_mix_colors(QColor a, QColor b) { return QColor((a.red() + b.red()) / 2, (a.green() + b.green()) / 2, @@ -113,12 +58,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); } } } @@ -349,6 +294,15 @@ static void qt_palette_from_color(QPalette &pal, const QColor &button) */ /*! + \fn const QBrush & QPalette::accent() const + \since 6.6 + + Returns the accent brush of the current color group. + + \sa ColorRole, brush() +*/ + +/*! \fn const QBrush & QPalette::link() const Returns the unvisited link text brush of the current color group. @@ -548,8 +502,8 @@ 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 - A color that typically contrasts or compliments + \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. Styling of interactive components is a typical use case. @@ -840,7 +794,7 @@ void QPalette::setBrush(ColorGroup cg, ColorRole cr, const QBrush &b) cg = Active; } - const auto newResolveMask = d->resolveMask | ResolveMask(1) << bitPosition(cg, cr); + const auto newResolveMask = d->resolveMask | ResolveMask(1) << QPalettePrivate::bitPosition(cg, cr); const auto valueChanged = d->data->br[cg][cr] != b; if (valueChanged) { @@ -887,7 +841,7 @@ bool QPalette::isBrushSet(ColorGroup cg, ColorRole cr) const return false; } - return d->resolveMask & (ResolveMask(1) << bitPosition(cg, cr)); + return d->resolveMask & (ResolveMask(1) << QPalettePrivate::bitPosition(cg, cr)); } /*! @@ -996,7 +950,7 @@ static constexpr QPalette::ResolveMask allResolveMask() QPalette::ResolveMask mask = {0}; for (int role = 0; role < int(QPalette::NColorRoles); ++role) { for (int grp = 0; grp < int(QPalette::NColorGroups); ++grp) { - mask |= (QPalette::ResolveMask(1) << bitPosition(QPalette::ColorGroup(grp), QPalette::ColorRole(role))); + mask |= (QPalette::ResolveMask(1) << QPalettePrivate::bitPosition(QPalette::ColorGroup(grp), QPalette::ColorRole(role))); } } return mask; @@ -1004,7 +958,10 @@ static constexpr QPalette::ResolveMask allResolveMask() /*! Returns a new QPalette that is a union of this instance and \a other. - Color roles set in this instance take precedence. + Color roles set in this instance take precedence. Roles that are not + set in this instance will be taken from \a other. + + \sa isBrushSet */ QPalette QPalette::resolve(const QPalette &other) const { @@ -1022,12 +979,12 @@ 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; for (int grp = 0; grp < int(NColorGroups); ++grp) { - if (!(d->resolveMask & (ResolveMask(1) << bitPosition(ColorGroup(grp), ColorRole(role))))) { + if (!(d->resolveMask & (ResolveMask(1) << QPalettePrivate::bitPosition(ColorGroup(grp), ColorRole(role))))) { palette.d->data.detach(); palette.d->data->br[grp][role] = other.d->data->br[grp][role]; } @@ -1161,9 +1118,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)); } } @@ -1212,10 +1169,10 @@ void QPalette::setColorGroup(ColorGroup cg, const QBrush &windowText, const QBru for (int cr = Highlight; cr <= LinkVisited; ++cr) { if (cg == All) { for (int group = Active; group < NColorGroups; ++group) { - d->resolveMask &= ~(ResolveMask(1) << bitPosition(ColorGroup(group), ColorRole(cr))); + d->resolveMask &= ~(ResolveMask(1) << QPalettePrivate::bitPosition(ColorGroup(group), ColorRole(cr))); } } else { - d->resolveMask &= ~(ResolveMask(1) << bitPosition(ColorGroup(cg), ColorRole(cr))); + d->resolveMask &= ~(ResolveMask(1) << QPalettePrivate::bitPosition(ColorGroup(cg), ColorRole(cr))); } } } |