diff options
Diffstat (limited to 'src/gui/kernel/qpalette.cpp')
-rw-r--r-- | src/gui/kernel/qpalette.cpp | 98 |
1 files changed, 52 insertions, 46 deletions
diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp index 2b6a7e643f..4abbcd5e65 100644 --- a/src/gui/kernel/qpalette.cpp +++ b/src/gui/kernel/qpalette.cpp @@ -35,14 +35,25 @@ class QPalettePrivate public: class Data : public QSharedData { public: - Data() : ser_no(qt_palette_count++) { } + // 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; + const int ser_no = qt_palette_count++; }; QPalettePrivate(const QExplicitlySharedDataPointer<Data> &data) - : ref(1), detach_no(0), data(data) + : ref(1), data(data) { } QPalettePrivate() : QPalettePrivate(QExplicitlySharedDataPointer<Data>(new Data)) @@ -50,7 +61,8 @@ public: QAtomicInt ref; QPalette::ResolveMask resolveMask = {0}; - int detach_no; + static inline int qt_palette_private_count = 0; + int detach_no = ++qt_palette_private_count; QExplicitlySharedDataPointer<Data> data; }; @@ -60,6 +72,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 +122,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 +611,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 +668,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); } /*! @@ -818,8 +864,9 @@ void QPalette::detach() if (!d->ref.deref()) delete d; d = x; + } else { + d->detach_no = ++QPalettePrivate::qt_palette_private_count; } - ++d->detach_no; } /*! @@ -1163,47 +1210,6 @@ void QPalette::setColorGroup(ColorGroup cg, const QBrush &foreground, const QBru setBrush(cg, ToolTipText, toolTipText); } -Q_GUI_EXPORT QPalette qt_fusionPalette() -{ - QColor backGround(239, 239, 239); - QColor light = backGround.lighter(150); - QColor mid(backGround.darker(130)); - QColor midLight = mid.lighter(110); - QColor base = Qt::white; - QColor disabledBase(backGround); - QColor dark = backGround.darker(150); - QColor darkDisabled = QColor(209, 209, 209).darker(110); - QColor text = Qt::black; - QColor hightlightedText = Qt::white; - QColor disabledText = QColor(190, 190, 190); - QColor button = backGround; - QColor shadow = dark.darker(135); - QColor disabledShadow = shadow.lighter(150); - QColor placeholder = text; - placeholder.setAlpha(128); - - QPalette fusionPalette(Qt::black,backGround,light,dark,mid,text,base); - fusionPalette.setBrush(QPalette::Midlight, midLight); - fusionPalette.setBrush(QPalette::Button, button); - fusionPalette.setBrush(QPalette::Shadow, shadow); - fusionPalette.setBrush(QPalette::HighlightedText, hightlightedText); - - fusionPalette.setBrush(QPalette::Disabled, QPalette::Text, disabledText); - fusionPalette.setBrush(QPalette::Disabled, QPalette::WindowText, disabledText); - fusionPalette.setBrush(QPalette::Disabled, QPalette::ButtonText, disabledText); - fusionPalette.setBrush(QPalette::Disabled, QPalette::Base, disabledBase); - fusionPalette.setBrush(QPalette::Disabled, QPalette::Dark, darkDisabled); - fusionPalette.setBrush(QPalette::Disabled, QPalette::Shadow, disabledShadow); - - fusionPalette.setBrush(QPalette::Active, QPalette::Highlight, QColor(48, 140, 198)); - fusionPalette.setBrush(QPalette::Inactive, QPalette::Highlight, QColor(48, 140, 198)); - fusionPalette.setBrush(QPalette::Disabled, QPalette::Highlight, QColor(145, 145, 145)); - - fusionPalette.setBrush(QPalette::PlaceholderText, placeholder); - - return fusionPalette; -} - #ifndef QT_NO_DEBUG_STREAM static QString groupsToString(const QPalette &p, QPalette::ColorRole cr) { |