10#include "kiconcolors.h"
11#include <KColorScheme>
13static QString STYLESHEET_TEMPLATE()
16 return QStringLiteral(
".ColorScheme-Text { color:%1; }\
17.ColorScheme-Background{ color:%2; }\
18.ColorScheme-Highlight{ color:%3; }\
19.ColorScheme-HighlightedText{ color:%4; }\
20.ColorScheme-PositiveText{ color:%5; }\
21.ColorScheme-NeutralText{ color:%6; }\
22.ColorScheme-NegativeText{ color:%7; }\
23.ColorScheme-ActiveText{ color:%8; }\
24.ColorScheme-Complement{ color:%9; }\
25.ColorScheme-Contrast{ color:%10; }\
26.ColorScheme-Accent{ color:%11; }\
41 QColor highlightedText;
47 static std::optional<QPalette> lastPalette;
48 static std::optional<KColorScheme> lastColorScheme;
51std::optional<QPalette> KIconColorsPrivate::lastPalette;
52std::optional<KColorScheme> KIconColorsPrivate::lastColorScheme;
66 if (d_ptr != other.d_ptr) {
73 : d_ptr(new KIconColorsPrivate)
77 d->background = color;
79 d->highlightedText = color;
80 d->positiveText = color;
81 d->neutralText = color;
82 d->negativeText = color;
84 d->activeText = color;
88 : d_ptr(new KIconColorsPrivate)
97 if (!d->lastColorScheme || !d->lastPalette || palette != d->lastPalette) {
98 d->lastPalette = palette;
108KIconColors::~KIconColors()
112qreal luma(
const QColor &color) {
113 return (0.299 * color.
red() + 0.587 * color.
green() + 0.114 * color.
blue()) / 255;
126 QColor accentColor = d->accent;
131 const qreal tintRatio = 0.85;
132 const qreal r = accentColor.
redF() * tintRatio + d->highlightedText.redF() * (1.0 - tintRatio);
133 const qreal g = accentColor.
greenF() * tintRatio + d->highlightedText.greenF() * (1.0 - tintRatio);
134 const qreal b = accentColor.
blueF() * tintRatio + d->highlightedText.blueF() * (1.0 - tintRatio);
138 return STYLESHEET_TEMPLATE()
147 .arg(complement.
name())
148 .arg(contrast.
name())
149 .arg(accentColor.
name());
152QColor KIconColors::highlight()
const
158QColor KIconColors::highlightedText()
const
161 return d->highlightedText;
164QColor KIconColors::accent()
const
170QColor KIconColors::background()
const
173 return d->background;
176QColor KIconColors::text()
const
182QColor KIconColors::negativeText()
const
185 return d->negativeText;
188QColor KIconColors::positiveText()
const
191 return d->positiveText;
194QColor KIconColors::neutralText()
const
197 return d->neutralText;
200QColor KIconColors::activeText()
const
203 return d->activeText;
206void KIconColors::setText(
const QColor &color)
212void KIconColors::setBackground(
const QColor &color)
215 d->background = color;
218void KIconColors::setHighlight(
const QColor &color)
221 d->highlight = color;
224void KIconColors::setHighlightedText(
const QColor &color)
227 d->highlightedText = color;
230void KIconColors::setAccent(
const QColor &color)
236void KIconColors::setNegativeText(
const QColor &color)
239 d->negativeText = color;
242void KIconColors::setNeutralText(
const QColor &color)
245 d->neutralText = color;
248void KIconColors::setPositiveText(
const QColor &color)
251 d->positiveText = color;
254void KIconColors::setActiveText(
const QColor &color)
257 d->activeText = color;
Sepecifies which colors will be used when recoloring icons as its stylesheet.
KIconColors()
Will fill the colors based on the default QPalette() constructor.
QString stylesheet(KIconLoader::States state) const
States
Defines the possible states of an icon.
@ SelectedState
Icon is selected.
const QColor & color() const const
float alphaF() const const
float blueF() const const
float greenF() const const
QString name(NameFormat format) const const
void setRgbF(float r, float g, float b, float a)
const QBrush & accent() const const
const QBrush & highlight() const const
const QBrush & highlightedText() const const
const QBrush & window() const const
const QBrush & windowText() const const