• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • colors
kcolorscheme.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * Copyright (C) 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19#include "kcolorscheme.h"
20
21#include <kconfig.h>
22#include <kconfiggroup.h>
23#include <kglobal.h>
24#include <ksharedconfig.h>
25#include <kglobalsettings.h>
26#include <kcolorutils.h>
27
28#include <QtGui/QColor>
29#include <QtGui/QBrush>
30#include <QtGui/QWidget>
31
32//BEGIN StateEffects
33class StateEffects {
34public:
35 explicit StateEffects(QPalette::ColorGroup state, const KSharedConfigPtr&);
36 ~StateEffects() {} //{ delete chain; } not needed yet
37
38 QBrush brush(const QBrush &background) const;
39 QBrush brush(const QBrush &foreground, const QBrush &background) const;
40
41private:
42 enum Effects {
43 // Effects
44 Intensity = 0,
45 Color = 1,
46 Contrast = 2,
47 // Intensity
48 IntensityNoEffect = 0,
49 IntensityShade = 1,
50 IntensityDarken = 2,
51 IntensityLighten = 3,
52 // Color
53 ColorNoEffect = 0,
54 ColorDesaturate = 1,
55 ColorFade = 2,
56 ColorTint = 3,
57 // Contrast
58 ContrastNoEffect = 0,
59 ContrastFade = 1,
60 ContrastTint = 2
61 };
62
63 int _effects[3];
64 double _amount[3];
65 QColor _color;
66// StateEffects *_chain; not needed yet
67};
68
69StateEffects::StateEffects(QPalette::ColorGroup state, const KSharedConfigPtr &config)
70 : _color(0,0,0,0)//, _chain(0) not needed yet
71{
72 QString group;
73 if(state == QPalette::Disabled)
74 group = "ColorEffects:Disabled";
75 else if(state == QPalette::Inactive)
76 group = "ColorEffects:Inactive";
77
78 _effects[0] = 0;
79 _effects[1] = 0;
80 _effects[2] = 0;
81
82 // NOTE: keep this in sync with kdebase/workspace/kcontrol/colors/colorscm.cpp
83 if(! group.isEmpty()) {
84 KConfigGroup cfg(config, group);
85 const bool enabledByDefault = (state == QPalette::Disabled);
86 if (cfg.readEntry("Enable", enabledByDefault)) {
87 _effects[Intensity] = cfg.readEntry( "IntensityEffect",
88 (int)(state == QPalette::Disabled ? IntensityDarken : IntensityNoEffect));
89 _effects[Color] = cfg.readEntry( "ColorEffect",
90 (int)(state == QPalette::Disabled ? ColorNoEffect : ColorDesaturate));
91 _effects[Contrast] = cfg.readEntry( "ContrastEffect",
92 (int)(state == QPalette::Disabled ? ContrastFade : ContrastTint));
93 _amount[Intensity] = cfg.readEntry( "IntensityAmount", state == QPalette::Disabled ? 0.10 : 0.0 );
94 _amount[Color] = cfg.readEntry( "ColorAmount", state == QPalette::Disabled ? 0.0 : -0.9 );
95 _amount[Contrast] = cfg.readEntry( "ContrastAmount", state == QPalette::Disabled ? 0.65 : 0.25 );
96 if (_effects[Color] > ColorNoEffect)
97 _color = cfg.readEntry( "Color", state == QPalette::Disabled ? QColor(56, 56, 56) : QColor(112, 111, 110));
98 }
99 }
100}
101
102QBrush StateEffects::brush(const QBrush &background) const
103{
104 QColor color = background.color(); // TODO - actually work on brushes
105 switch (_effects[Intensity]) {
106 case IntensityShade:
107 color = KColorUtils::shade(color, _amount[Intensity]);
108 break;
109 case IntensityDarken:
110 color = KColorUtils::darken(color, _amount[Intensity]);
111 break;
112 case IntensityLighten:
113 color = KColorUtils::lighten(color, _amount[Intensity]);
114 break;
115 }
116 switch (_effects[Color]) {
117 case ColorDesaturate:
118 color = KColorUtils::darken(color, 0.0, 1.0 - _amount[Color]);
119 break;
120 case ColorFade:
121 color = KColorUtils::mix(color, _color, _amount[Color]);
122 break;
123 case ColorTint:
124 color = KColorUtils::tint(color, _color, _amount[Color]);
125 break;
126 }
127 return QBrush(color);
128}
129
130QBrush StateEffects::brush(const QBrush &foreground, const QBrush &background) const
131{
132 QColor color = foreground.color(); // TODO - actually work on brushes
133 QColor bg = background.color();
134 // Apply the foreground effects
135 switch (_effects[Contrast]) {
136 case ContrastFade:
137 color = KColorUtils::mix(color, bg, _amount[Contrast]);
138 break;
139 case ContrastTint:
140 color = KColorUtils::tint(color, bg, _amount[Contrast]);
141 break;
142 }
143 // Now apply global effects
144 return brush(color);
145}
146//END StateEffects
147
148//BEGIN default colors
149struct SetDefaultColors {
150 int NormalBackground[3];
151 int AlternateBackground[3];
152 int NormalText[3];
153 int InactiveText[3];
154 int ActiveText[3];
155 int LinkText[3];
156 int VisitedText[3];
157 int NegativeText[3];
158 int NeutralText[3];
159 int PositiveText[3];
160};
161
162struct DecoDefaultColors {
163 int Hover[3];
164 int Focus[3];
165};
166
167SetDefaultColors defaultViewColors = {
168 { 255, 255, 255 }, // Background
169 { 248, 247, 246 }, // Alternate
170 { 31, 28, 27 }, // Normal
171 { 137, 136, 135 }, // Inactive
172 { 146, 76, 157 }, // Active
173 { 0, 87, 174 }, // Link
174 { 100, 74, 155 }, // Visited
175 { 191, 3, 3 }, // Negative
176 { 176, 128, 0 }, // Neutral
177 { 0, 110, 40 } // Positive
178};
179
180
181SetDefaultColors defaultWindowColors = {
182 { 214, 210, 208 }, // Background
183 { 218, 217, 216 }, // Alternate
184 { 34, 31, 30 }, // Normal
185 { 137, 136, 135 }, // Inactive
186 { 146, 76, 157 }, // Active
187 { 0, 87, 174 }, // Link
188 { 100, 74, 155 }, // Visited
189 { 191, 3, 3 }, // Negative
190 { 176, 128, 0 }, // Neutral
191 { 0, 110, 40 } // Positive
192};
193
194
195SetDefaultColors defaultButtonColors = {
196 { 223, 220, 217 }, // Background
197 { 224, 223, 222 }, // Alternate
198 { 34, 31, 30 }, // Normal
199 { 137, 136, 135 }, // Inactive
200 { 146, 76, 157 }, // Active
201 { 0, 87, 174 }, // Link
202 { 100, 74, 155 }, // Visited
203 { 191, 3, 3 }, // Negative
204 { 176, 128, 0 }, // Neutral
205 { 0, 110, 40 } // Positive
206};
207
208
209SetDefaultColors defaultSelectionColors = {
210 { 67, 172, 232 }, // Background
211 { 62, 138, 204 }, // Alternate
212 { 255, 255, 255 }, // Normal
213 { 199, 226, 248 }, // Inactive
214 { 108, 36, 119 }, // Active
215 { 0, 49, 110 }, // Link
216 { 69, 40, 134 }, // Visited
217 { 156, 14, 14 }, // Negative
218 { 255, 221, 0 }, // Neutral
219 { 128, 255, 128 } // Positive
220};
221
222
223SetDefaultColors defaultTooltipColors = {
224 { 24, 21, 19 }, // Background
225 { 196, 224, 255 }, // Alternate
226 { 231, 253, 255 }, // Normal
227 { 137, 136, 135 }, // Inactive
228 { 255, 128, 224 }, // Active
229 { 88, 172, 255 }, // Link
230 { 150, 111, 232 }, // Visited
231 { 191, 3, 3 }, // Negative
232 { 176, 128, 0 }, // Neutral
233 { 0, 110, 40 } // Positive
234};
235
236DecoDefaultColors defaultDecorationColors = {
237 { 110, 214, 255 }, // Hover
238 { 58, 167, 221 }, // Focus
239};
240//END default colors
241
242//BEGIN KColorSchemePrivate
243class KColorSchemePrivate : public QSharedData
244{
245public:
246 explicit KColorSchemePrivate(const KSharedConfigPtr&, QPalette::ColorGroup, const char*, SetDefaultColors);
247 explicit KColorSchemePrivate(const KSharedConfigPtr&, QPalette::ColorGroup, const char*, SetDefaultColors, const QBrush&);
248 ~KColorSchemePrivate() {}
249
250 QBrush background(KColorScheme::BackgroundRole) const;
251 QBrush foreground(KColorScheme::ForegroundRole) const;
252 QBrush decoration(KColorScheme::DecorationRole) const;
253 qreal contrast() const;
254private:
255 struct {
256 QBrush fg[8], bg[8], deco[2];
257 } _brushes;
258 qreal _contrast;
259
260 void init(const KSharedConfigPtr&, QPalette::ColorGroup, const char*, SetDefaultColors);
261};
262
263#define DEFAULT(c) QColor( c[0], c[1], c[2] )
264#define SET_DEFAULT(a) DEFAULT( defaults.a )
265#define DECO_DEFAULT(a) DEFAULT( defaultDecorationColors.a )
266
267KColorSchemePrivate::KColorSchemePrivate(const KSharedConfigPtr &config,
268 QPalette::ColorGroup state,
269 const char *group,
270 SetDefaultColors defaults)
271{
272 KConfigGroup cfg( config, group );
273 _contrast = KGlobalSettings::contrastF( config );
274
275 // loaded-from-config colors (no adjustment)
276 _brushes.bg[0] = cfg.readEntry( "BackgroundNormal", SET_DEFAULT(NormalBackground) );
277 _brushes.bg[1] = cfg.readEntry( "BackgroundAlternate", SET_DEFAULT(AlternateBackground) );
278
279 // the rest
280 init(config, state, group, defaults);
281}
282
283KColorSchemePrivate::KColorSchemePrivate(const KSharedConfigPtr &config,
284 QPalette::ColorGroup state,
285 const char *group,
286 SetDefaultColors defaults,
287 const QBrush &tint)
288{
289 KConfigGroup cfg( config, group );
290 _contrast = KGlobalSettings::contrastF( config );
291
292 // loaded-from-config colors
293 _brushes.bg[0] = cfg.readEntry( "BackgroundNormal", SET_DEFAULT(NormalBackground) );
294 _brushes.bg[1] = cfg.readEntry( "BackgroundAlternate", SET_DEFAULT(AlternateBackground) );
295
296 // adjustment
297 _brushes.bg[0] = KColorUtils::tint(_brushes.bg[0].color(), tint.color(), 0.4);
298 _brushes.bg[1] = KColorUtils::tint(_brushes.bg[1].color(), tint.color(), 0.4);
299
300 // the rest
301 init(config, state, group, defaults);
302}
303
304void KColorSchemePrivate::init(const KSharedConfigPtr &config,
305 QPalette::ColorGroup state,
306 const char *group,
307 SetDefaultColors defaults)
308{
309 KConfigGroup cfg( config, group );
310
311 // loaded-from-config colors
312 _brushes.fg[0] = cfg.readEntry( "ForegroundNormal", SET_DEFAULT(NormalText) );
313 _brushes.fg[1] = cfg.readEntry( "ForegroundInactive", SET_DEFAULT(InactiveText) );
314 _brushes.fg[2] = cfg.readEntry( "ForegroundActive", SET_DEFAULT(ActiveText) );
315 _brushes.fg[3] = cfg.readEntry( "ForegroundLink", SET_DEFAULT(LinkText) );
316 _brushes.fg[4] = cfg.readEntry( "ForegroundVisited", SET_DEFAULT(VisitedText) );
317 _brushes.fg[5] = cfg.readEntry( "ForegroundNegative", SET_DEFAULT(NegativeText) );
318 _brushes.fg[6] = cfg.readEntry( "ForegroundNeutral", SET_DEFAULT(NeutralText) );
319 _brushes.fg[7] = cfg.readEntry( "ForegroundPositive", SET_DEFAULT(PositiveText) );
320
321 _brushes.deco[0] = cfg.readEntry( "DecorationHover", DECO_DEFAULT(Hover) );
322 _brushes.deco[1] = cfg.readEntry( "DecorationFocus", DECO_DEFAULT(Focus) );
323
324 // apply state adjustments
325 if (state != QPalette::Active) {
326 StateEffects effects(state, config);
327 for (int i=0; i<8; i++) {
328 _brushes.fg[i] = effects.brush(_brushes.fg[i], _brushes.bg[0]);
329 }
330 _brushes.deco[0] = effects.brush(_brushes.deco[0], _brushes.bg[0]);
331 _brushes.deco[1] = effects.brush(_brushes.deco[1], _brushes.bg[0]);
332 _brushes.bg[0] = effects.brush(_brushes.bg[0]);
333 _brushes.bg[1] = effects.brush(_brushes.bg[1]);
334 }
335
336 // calculated backgrounds
337 _brushes.bg[2] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[2].color() );
338 _brushes.bg[3] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[3].color() );
339 _brushes.bg[4] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[4].color() );
340 _brushes.bg[5] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[5].color() );
341 _brushes.bg[6] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[6].color() );
342 _brushes.bg[7] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[7].color() );
343}
344
345QBrush KColorSchemePrivate::background(KColorScheme::BackgroundRole role) const
346{
347 switch (role) {
348 case KColorScheme::AlternateBackground:
349 return _brushes.bg[1];
350 case KColorScheme::ActiveBackground:
351 return _brushes.bg[2];
352 case KColorScheme::LinkBackground:
353 return _brushes.bg[3];
354 case KColorScheme::VisitedBackground:
355 return _brushes.bg[4];
356 case KColorScheme::NegativeBackground:
357 return _brushes.bg[5];
358 case KColorScheme::NeutralBackground:
359 return _brushes.bg[6];
360 case KColorScheme::PositiveBackground:
361 return _brushes.bg[7];
362 default:
363 return _brushes.bg[0];
364 }
365}
366
367QBrush KColorSchemePrivate::foreground(KColorScheme::ForegroundRole role) const
368{
369 switch (role) {
370 case KColorScheme::InactiveText:
371 return _brushes.fg[1];
372 case KColorScheme::ActiveText:
373 return _brushes.fg[2];
374 case KColorScheme::LinkText:
375 return _brushes.fg[3];
376 case KColorScheme::VisitedText:
377 return _brushes.fg[4];
378 case KColorScheme::NegativeText:
379 return _brushes.fg[5];
380 case KColorScheme::NeutralText:
381 return _brushes.fg[6];
382 case KColorScheme::PositiveText:
383 return _brushes.fg[7];
384 default:
385 return _brushes.fg[0];
386 }
387}
388
389QBrush KColorSchemePrivate::decoration(KColorScheme::DecorationRole role) const
390{
391 switch (role) {
392 case KColorScheme::FocusColor:
393 return _brushes.deco[1];
394 default:
395 return _brushes.deco[0];
396 }
397}
398
399qreal KColorSchemePrivate::contrast() const
400{
401 return _contrast;
402}
403//END KColorSchemePrivate
404
405//BEGIN KColorScheme
406KColorScheme::KColorScheme(const KColorScheme &other) : d(other.d)
407{
408}
409
410KColorScheme& KColorScheme::operator=(const KColorScheme& other)
411{
412 d = other.d;
413 return *this;
414}
415
416KColorScheme::~KColorScheme()
417{
418}
419
420KColorScheme::KColorScheme(QPalette::ColorGroup state, ColorSet set, KSharedConfigPtr config)
421{
422 if (!config)
423 config = KGlobal::config();
424
425 switch (set) {
426 case Window:
427 d = new KColorSchemePrivate(config, state, "Colors:Window", defaultWindowColors);
428 break;
429 case Button:
430 d = new KColorSchemePrivate(config, state, "Colors:Button", defaultButtonColors);
431 break;
432 case Selection: {
433 KConfigGroup group(config, "ColorEffects:Inactive");
434 // NOTE: keep this in sync with kdebase/workspace/kcontrol/colors/colorscm.cpp
435 bool inactiveSelectionEffect = group.readEntry("ChangeSelectionColor", group.readEntry("Enable", true));
436 // if enabled, inactiver/disabled uses Window colors instead, ala gtk
437 // ...except tinted with the Selection:NormalBackground color so it looks more like selection
438 if (state == QPalette::Active || (state == QPalette::Inactive && !inactiveSelectionEffect))
439 d = new KColorSchemePrivate(config, state, "Colors:Selection", defaultSelectionColors);
440 else if (state == QPalette::Inactive)
441 d = new KColorSchemePrivate(config, state, "Colors:Window", defaultWindowColors,
442 KColorScheme(QPalette::Active, Selection, config).background());
443 else // disabled (...and still want this branch when inactive+disabled exists)
444 d = new KColorSchemePrivate(config, state, "Colors:Window", defaultWindowColors);
445 } break;
446 case Tooltip:
447 d = new KColorSchemePrivate(config, state, "Colors:Tooltip", defaultTooltipColors);
448 break;
449 default:
450 d = new KColorSchemePrivate(config, state, "Colors:View", defaultViewColors);
451 }
452}
453
454QBrush KColorScheme::background(BackgroundRole role) const
455{
456 return d->background(role);
457}
458
459QBrush KColorScheme::foreground(ForegroundRole role) const
460{
461 return d->foreground(role);
462}
463
464QBrush KColorScheme::decoration(DecorationRole role) const
465{
466 return d->decoration(role);
467}
468
469QColor KColorScheme::shade(ShadeRole role) const
470{
471 return shade(background().color(), role, d->contrast());
472}
473
474QColor KColorScheme::shade(const QColor &color, ShadeRole role)
475{
476 return shade(color, role, KGlobalSettings::contrastF());
477}
478
479QColor KColorScheme::shade(const QColor &color, ShadeRole role, qreal contrast, qreal chromaAdjust)
480{
481 // nan -> 1.0
482 contrast = (1.0 > contrast ? (-1.0 < contrast ? contrast : -1.0) : 1.0);
483 qreal y = KColorUtils::luma(color), yi = 1.0 - y;
484
485 // handle very dark colors (base, mid, dark, shadow == midlight, light)
486 if (y < 0.006) {
487 switch (role) {
488 case KColorScheme::LightShade:
489 return KColorUtils::shade(color, 0.05 + 0.95 * contrast, chromaAdjust);
490 case KColorScheme::MidShade:
491 return KColorUtils::shade(color, 0.01 + 0.20 * contrast, chromaAdjust);
492 case KColorScheme::DarkShade:
493 return KColorUtils::shade(color, 0.02 + 0.40 * contrast, chromaAdjust);
494 default:
495 return KColorUtils::shade(color, 0.03 + 0.60 * contrast, chromaAdjust);
496 }
497 }
498
499 // handle very light colors (base, midlight, light == mid, dark, shadow)
500 if (y > 0.93) {
501 switch (role) {
502 case KColorScheme::MidlightShade:
503 return KColorUtils::shade(color, -0.02 - 0.20 * contrast, chromaAdjust);
504 case KColorScheme::DarkShade:
505 return KColorUtils::shade(color, -0.06 - 0.60 * contrast, chromaAdjust);
506 case KColorScheme::ShadowShade:
507 return KColorUtils::shade(color, -0.10 - 0.90 * contrast, chromaAdjust);
508 default:
509 return KColorUtils::shade(color, -0.04 - 0.40 * contrast, chromaAdjust);
510 }
511 }
512
513 // handle everything else
514 qreal lightAmount = (0.05 + y * 0.55) * (0.25 + contrast * 0.75);
515 qreal darkAmount = ( - y ) * (0.55 + contrast * 0.35);
516 switch (role) {
517 case KColorScheme::LightShade:
518 return KColorUtils::shade(color, lightAmount, chromaAdjust);
519 case KColorScheme::MidlightShade:
520 return KColorUtils::shade(color, (0.15 + 0.35 * yi) * lightAmount, chromaAdjust);
521 case KColorScheme::MidShade:
522 return KColorUtils::shade(color, (0.35 + 0.15 * y) * darkAmount, chromaAdjust);
523 case KColorScheme::DarkShade:
524 return KColorUtils::shade(color, darkAmount, chromaAdjust);
525 default:
526 return KColorUtils::darken(KColorUtils::shade(color, darkAmount, chromaAdjust), 0.5 + 0.3 * y);
527 }
528}
529
530void KColorScheme::adjustBackground(QPalette &palette, BackgroundRole newRole, QPalette::ColorRole color,
531 ColorSet set, KSharedConfigPtr config) {
532 palette.setBrush(QPalette::Active, color, KColorScheme(QPalette::Active, set, config).background(newRole));
533 palette.setBrush(QPalette::Inactive, color, KColorScheme(QPalette::Inactive, set, config).background(newRole));
534 palette.setBrush(QPalette::Disabled, color, KColorScheme(QPalette::Disabled, set, config).background(newRole));
535}
536
537void KColorScheme::adjustForeground(QPalette &palette, ForegroundRole newRole, QPalette::ColorRole color,
538 ColorSet set, KSharedConfigPtr config) {
539 palette.setBrush(QPalette::Active, color, KColorScheme(QPalette::Active, set, config).foreground(newRole));
540 palette.setBrush(QPalette::Inactive, color, KColorScheme(QPalette::Inactive, set, config).foreground(newRole));
541 palette.setBrush(QPalette::Disabled, color, KColorScheme(QPalette::Disabled, set, config).foreground(newRole));
542}
543//END KColorScheme
544
545//BEGIN KStatefulBrush
546class KStatefulBrushPrivate : public QBrush // for now, just be a QBrush
547{
548 public:
549 KStatefulBrushPrivate() : QBrush() {}
550 KStatefulBrushPrivate(const QBrush &brush) : QBrush(brush) {} // not explicit
551};
552
553KStatefulBrush::KStatefulBrush()
554{
555 d = new KStatefulBrushPrivate[3];
556}
557
558KStatefulBrush::KStatefulBrush(KColorScheme::ColorSet set, KColorScheme::ForegroundRole role,
559 KSharedConfigPtr config)
560{
561 d = new KStatefulBrushPrivate[3];
562 d[0] = KColorScheme(QPalette::Active, set, config).foreground(role);
563 d[1] = KColorScheme(QPalette::Disabled, set, config).foreground(role);
564 d[2] = KColorScheme(QPalette::Inactive, set, config).foreground(role);
565}
566
567KStatefulBrush::KStatefulBrush(KColorScheme::ColorSet set, KColorScheme::BackgroundRole role,
568 KSharedConfigPtr config)
569{
570 d = new KStatefulBrushPrivate[3];
571 d[0] = KColorScheme(QPalette::Active, set, config).background(role);
572 d[1] = KColorScheme(QPalette::Disabled, set, config).background(role);
573 d[2] = KColorScheme(QPalette::Inactive, set, config).background(role);
574}
575
576KStatefulBrush::KStatefulBrush(KColorScheme::ColorSet set, KColorScheme::DecorationRole role,
577 KSharedConfigPtr config)
578{
579 d = new KStatefulBrushPrivate[3];
580 d[0] = KColorScheme(QPalette::Active, set, config).decoration(role);
581 d[1] = KColorScheme(QPalette::Disabled, set, config).decoration(role);
582 d[2] = KColorScheme(QPalette::Inactive, set, config).decoration(role);
583}
584
585KStatefulBrush::KStatefulBrush(const QBrush &brush, KSharedConfigPtr config)
586{
587 if (!config)
588 config = KGlobal::config();
589 d = new KStatefulBrushPrivate[3];
590 d[0] = brush;
591 d[1] = StateEffects(QPalette::Disabled, config).brush(brush);
592 d[2] = StateEffects(QPalette::Inactive, config).brush(brush);
593}
594
595KStatefulBrush::KStatefulBrush(const QBrush &brush, const QBrush &background,
596 KSharedConfigPtr config)
597{
598 if (!config)
599 config = KGlobal::config();
600 d = new KStatefulBrushPrivate[3];
601 d[0] = brush;
602 d[1] = StateEffects(QPalette::Disabled, config).brush(brush, background);
603 d[2] = StateEffects(QPalette::Inactive, config).brush(brush, background);
604}
605
606KStatefulBrush::KStatefulBrush(const KStatefulBrush &other)
607{
608 d = new KStatefulBrushPrivate[3];
609 d[0] = other.d[0];
610 d[1] = other.d[1];
611 d[2] = other.d[2];
612}
613
614KStatefulBrush::~KStatefulBrush()
615{
616 delete[] d;
617}
618
619KStatefulBrush& KStatefulBrush::operator=(const KStatefulBrush &other)
620{
621 d[0] = other.d[0];
622 d[1] = other.d[1];
623 d[2] = other.d[2];
624 return *this;
625}
626
627QBrush KStatefulBrush::brush(QPalette::ColorGroup state) const
628{
629 switch (state) {
630 case QPalette::Inactive:
631 return d[2];
632 case QPalette::Disabled:
633 return d[1];
634 default:
635 return d[0];
636 }
637}
638
639QBrush KStatefulBrush::brush(const QPalette &pal) const
640{
641 return brush(pal.currentColorGroup());
642}
643
644QBrush KStatefulBrush::brush(const QWidget *widget) const
645{
646 if (widget)
647 return brush(widget->palette());
648 else
649 return QBrush();
650}
651//END KStatefulBrush
652
653// kate: space-indent on; indent-width 4; replace-tabs on; auto-insert-doxygen on;
KColorScheme
A set of methods used to work with colors.
Definition: kcolorscheme.h:71
KColorScheme::adjustForeground
static void adjustForeground(QPalette &, ForegroundRole newRole=NormalText, QPalette::ColorRole color=QPalette::Text, ColorSet set=View, KSharedConfigPtr=KSharedConfigPtr())
Adjust a QPalette by replacing the specified QPalette::ColorRole with the requested foreground color ...
Definition: kcolorscheme.cpp:537
KColorScheme::ForegroundRole
ForegroundRole
This enumeration describes the foreground color being selected from the given set.
Definition: kcolorscheme.h:199
KColorScheme::ActiveText
@ ActiveText
Third color; for example items which are new, active, requesting attention, etc.
Definition: kcolorscheme.h:215
KColorScheme::VisitedText
@ VisitedText
Fifth color; used for (visited) links.
Definition: kcolorscheme.h:229
KColorScheme::LinkText
@ LinkText
Fourth color; use for (unvisited) links.
Definition: kcolorscheme.h:221
KColorScheme::NeutralText
@ NeutralText
Seventh color; for example, warnings, secure/encrypted content.
Definition: kcolorscheme.h:238
KColorScheme::InactiveText
@ InactiveText
Second color; for example, comments, items which are old, inactive or disabled.
Definition: kcolorscheme.h:210
KColorScheme::NegativeText
@ NegativeText
Sixth color; for example, errors, untrusted content, deletions, etc.
Definition: kcolorscheme.h:234
KColorScheme::PositiveText
@ PositiveText
Eigth color; for example, additions, success messages, trusted content.
Definition: kcolorscheme.h:243
KColorScheme::ShadeRole
ShadeRole
This enumeration describes the color shade being selected from the given set.
Definition: kcolorscheme.h:275
KColorScheme::MidlightShade
@ MidlightShade
The midlight color is in between base() and light().
Definition: kcolorscheme.h:284
KColorScheme::DarkShade
@ DarkShade
The dark color is in between mid() and shadow().
Definition: kcolorscheme.h:292
KColorScheme::LightShade
@ LightShade
The light color is lighter than dark() or shadow() and contrasts with the base color.
Definition: kcolorscheme.h:280
KColorScheme::ShadowShade
@ ShadowShade
The shadow color is darker than light() or midlight() and contrasts the base color.
Definition: kcolorscheme.h:297
KColorScheme::MidShade
@ MidShade
The mid color is in between base() and dark().
Definition: kcolorscheme.h:288
KColorScheme::BackgroundRole
BackgroundRole
This enumeration describes the background color being selected from the given set.
Definition: kcolorscheme.h:130
KColorScheme::PositiveBackground
@ PositiveBackground
Eigth color; for example, success messages, trusted content.
Definition: kcolorscheme.h:180
KColorScheme::NeutralBackground
@ NeutralBackground
Seventh color; for example, warnings, secure/encrypted content.
Definition: kcolorscheme.h:176
KColorScheme::AlternateBackground
@ AlternateBackground
Alternate background; for example, for use in lists.
Definition: kcolorscheme.h:141
KColorScheme::VisitedBackground
@ VisitedBackground
Fifth color; corresponds to visited links.
Definition: kcolorscheme.h:168
KColorScheme::ActiveBackground
@ ActiveBackground
Third color; for example, items which are new, active, requesting attention, etc.
Definition: kcolorscheme.h:151
KColorScheme::NegativeBackground
@ NegativeBackground
Sixth color; for example, errors, untrusted content, etc.
Definition: kcolorscheme.h:172
KColorScheme::LinkBackground
@ LinkBackground
Fourth color; corresponds to (unvisited) links.
Definition: kcolorscheme.h:160
KColorScheme::ColorSet
ColorSet
This enumeration describes the color set for which a color is being selected.
Definition: kcolorscheme.h:81
KColorScheme::Tooltip
@ Tooltip
Tooltips.
Definition: kcolorscheme.h:118
KColorScheme::Window
@ Window
Non-editable window elements; for example, menus.
Definition: kcolorscheme.h:93
KColorScheme::Selection
@ Selection
Selected items in views.
Definition: kcolorscheme.h:109
KColorScheme::Button
@ Button
Buttons and button-like controls.
Definition: kcolorscheme.h:101
KColorScheme::KColorScheme
KColorScheme(const KColorScheme &)
Construct a copy of another KColorScheme.
Definition: kcolorscheme.cpp:406
KColorScheme::background
QBrush background(BackgroundRole=NormalBackground) const
Retrieve the requested background brush.
Definition: kcolorscheme.cpp:454
KColorScheme::DecorationRole
DecorationRole
This enumeration describes the decoration color being selected from the given set.
Definition: kcolorscheme.h:255
KColorScheme::FocusColor
@ FocusColor
Color used to draw decorations for items which have input focus.
Definition: kcolorscheme.h:259
KColorScheme::operator=
KColorScheme & operator=(const KColorScheme &)
Standard assignment operator.
Definition: kcolorscheme.cpp:410
KColorScheme::adjustBackground
static void adjustBackground(QPalette &, BackgroundRole newRole=NormalBackground, QPalette::ColorRole color=QPalette::Base, ColorSet set=View, KSharedConfigPtr=KSharedConfigPtr())
Adjust a QPalette by replacing the specified QPalette::ColorRole with the requested background color ...
Definition: kcolorscheme.cpp:530
KColorScheme::decoration
QBrush decoration(DecorationRole) const
Retrieve the requested decoration brush.
Definition: kcolorscheme.cpp:464
KColorScheme::~KColorScheme
virtual ~KColorScheme()
Destructor.
Definition: kcolorscheme.cpp:416
KColorScheme::shade
QColor shade(ShadeRole) const
Retrieve the requested shade color, using KColorScheme::background(KColorScheme::NormalBackground) as...
Definition: kcolorscheme.cpp:469
KColorScheme::foreground
QBrush foreground(ForegroundRole=NormalText) const
Retrieve the requested foreground brush.
Definition: kcolorscheme.cpp:459
KConfigGroup
KConfigGroup::readEntry
QString readEntry(const char *key, const char *aDefault=0) const
KGlobalSettings::contrastF
static qreal contrastF(const KSharedConfigPtr &config=KSharedConfigPtr())
Returns the contrast for borders as a floating point value.
Definition: kglobalsettings.cpp:366
KSharedPtr< KSharedConfig >
KStatefulBrush
A container for a "state-aware" brush.
Definition: kcolorscheme.h:442
KStatefulBrush::brush
QBrush brush(QPalette::ColorGroup) const
Retrieve the brush for the specified widget state.
Definition: kcolorscheme.cpp:627
KStatefulBrush::operator=
KStatefulBrush & operator=(const KStatefulBrush &)
Standard assignment operator.
Definition: kcolorscheme.cpp:619
KStatefulBrush::KStatefulBrush
KStatefulBrush()
Construct a "default" stateful brush.
Definition: kcolorscheme.cpp:553
KStatefulBrush::~KStatefulBrush
~KStatefulBrush()
Destructor.
Definition: kcolorscheme.cpp:614
QWidget
defaultSelectionColors
SetDefaultColors defaultSelectionColors
Definition: kcolorscheme.cpp:209
defaultWindowColors
SetDefaultColors defaultWindowColors
Definition: kcolorscheme.cpp:181
defaultDecorationColors
DecoDefaultColors defaultDecorationColors
Definition: kcolorscheme.cpp:236
defaultTooltipColors
SetDefaultColors defaultTooltipColors
Definition: kcolorscheme.cpp:223
DECO_DEFAULT
#define DECO_DEFAULT(a)
Definition: kcolorscheme.cpp:265
SET_DEFAULT
#define SET_DEFAULT(a)
Definition: kcolorscheme.cpp:264
defaultButtonColors
SetDefaultColors defaultButtonColors
Definition: kcolorscheme.cpp:195
defaultViewColors
SetDefaultColors defaultViewColors
Definition: kcolorscheme.cpp:167
kcolorscheme.h
kcolorutils.h
kconfig.h
kconfiggroup.h
kglobal.h
kglobalsettings.h
ksharedconfig.h
KColorUtils::darken
QColor darken(const QColor &, qreal amount=0.5, qreal chromaGain=1.0)
Adjust the luma of a color by changing its distance from black.
Definition: kcolorutils.cpp:63
KColorUtils::luma
qreal luma(const QColor &)
Calculate the luma of a color.
Definition: kcolorutils.cpp:37
KColorUtils::shade
QColor shade(const QColor &, qreal lumaAmount, qreal chromaAmount=0.0)
Adjust the luma and chroma components of a color.
Definition: kcolorutils.cpp:71
KColorUtils::mix
QColor mix(const QColor &c1, const QColor &c2, qreal bias=0.5)
Blend two colors into a new color by linear combination.
Definition: kcolorutils.cpp:110
KColorUtils::tint
QColor tint(const QColor &base, const QColor &color, qreal amount=0.3)
Create a new color by tinting one color with another.
Definition: kcolorutils.cpp:87
KColorUtils::lighten
QColor lighten(const QColor &, qreal amount=0.5, qreal chromaInverseGain=1.0)
Adjust the luma of a color by changing its distance from white.
Definition: kcolorutils.cpp:55
config
KSharedConfigPtr config()
group
group
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal