• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

kcolorscheme.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  * Copyright (C) 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this library; see the file COPYING.LIB.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 #include "kcolorscheme.h"
00020 
00021 #include <kconfig.h>
00022 #include <kconfiggroup.h>
00023 #include <kglobal.h>
00024 #include <ksharedconfig.h>
00025 #include <kglobalsettings.h>
00026 #include <kcolorutils.h>
00027 
00028 #include <QtGui/QColor>
00029 #include <QtGui/QBrush>
00030 #include <QtGui/QWidget>
00031 
00032 //BEGIN StateEffects
00033 class StateEffects {
00034 public:
00035     explicit StateEffects(QPalette::ColorGroup state, const KSharedConfigPtr&);
00036     ~StateEffects() {} //{ delete chain; } not needed yet
00037 
00038     QBrush brush(const QBrush &background) const;
00039     QBrush brush(const QBrush &foreground, const QBrush &background) const;
00040 
00041 private:
00042     enum Effects {
00043         // Effects
00044         Intensity = 0,
00045         Color = 1,
00046         Contrast = 2,
00047         // Intensity
00048         IntensityNoEffect = 0,
00049         IntensityShade = 1,
00050         IntensityDarken = 2,
00051         IntensityLighten = 3,
00052         // Color
00053         ColorNoEffect = 0,
00054         ColorDesaturate = 1,
00055         ColorFade = 2,
00056         ColorTint = 3,
00057         // Contrast
00058         ContrastNoEffect = 0,
00059         ContrastFade = 1,
00060         ContrastTint = 2
00061     };
00062 
00063     int _effects[3];
00064     double _amount[3];
00065     QColor _color;
00066 //     StateEffects *_chain; not needed yet
00067 };
00068 
00069 StateEffects::StateEffects(QPalette::ColorGroup state, const KSharedConfigPtr &config)
00070     : _color(0,0,0,0)//, _chain(0) not needed yet
00071 {
00072     QString group;
00073     if(state == QPalette::Disabled)
00074         group = "ColorEffects:Disabled";
00075     else if(state == QPalette::Inactive)
00076         group = "ColorEffects:Inactive";
00077     else {
00078         _effects[0] = 0;
00079         _effects[1] = 0;
00080         _effects[2] = 0;
00081     }
00082 
00083     // NOTE: keep this in sync with kdebase/workspace/kcontrol/colors/colorscm.cpp
00084     if(! group.isEmpty()) {
00085         KConfigGroup cfg(config, group);
00086         _effects[Intensity] = cfg.readEntry( "IntensityEffect",
00087                 (int)(state == QPalette::Disabled ?  IntensityDarken : IntensityNoEffect));
00088         _effects[Color]     = cfg.readEntry(     "ColorEffect", (int)ColorNoEffect );
00089         _effects[Contrast]  = cfg.readEntry(  "ContrastEffect",
00090                 (int)(state == QPalette::Disabled ?  ContrastFade : ContrastNoEffect));
00091         _amount[Intensity]  = cfg.readEntry( "IntensityAmount", state == QPalette::Disabled ? 0.10 : 0.0 );
00092         _amount[Color]      = cfg.readEntry(     "ColorAmount", 0.0 );
00093         _amount[Contrast]   = cfg.readEntry(  "ContrastAmount", state == QPalette::Disabled ? 0.65 : 0.0 );
00094         if (_effects[Color] > ColorNoEffect)
00095             _color = cfg.readEntry( "Color", QColor(112, 111, 110) );
00096     }
00097 }
00098 
00099 QBrush StateEffects::brush(const QBrush &background) const
00100 {
00101     QColor color = background.color(); // TODO - actually work on brushes
00102     switch (_effects[Intensity]) {
00103         case IntensityShade:
00104             color = KColorUtils::shade(color, _amount[Intensity]);
00105             break;
00106         case IntensityDarken:
00107             color = KColorUtils::darken(color, _amount[Intensity]);
00108             break;
00109         case IntensityLighten:
00110             color = KColorUtils::lighten(color, _amount[Intensity]);
00111             break;
00112     }
00113     switch (_effects[Color]) {
00114         case ColorDesaturate:
00115             color = KColorUtils::darken(color, 0.0, 1.0 - _amount[Color]);
00116             break;
00117         case ColorFade:
00118             color = KColorUtils::mix(color, _color, _amount[Color]);
00119             break;
00120         case ColorTint:
00121             color = KColorUtils::tint(color, _color, _amount[Color]);
00122             break;
00123     }
00124     return QBrush(color);
00125 }
00126 
00127 QBrush StateEffects::brush(const QBrush &foreground, const QBrush &background) const
00128 {
00129     QColor color = foreground.color(); // TODO - actually work on brushes
00130     QColor bg = background.color();
00131     // Apply the foreground effects
00132     switch (_effects[Contrast]) {
00133         case ContrastFade:
00134             color = KColorUtils::mix(color, bg, _amount[Contrast]);
00135             break;
00136         case ContrastTint:
00137             color = KColorUtils::tint(color, bg, _amount[Contrast]);
00138             break;
00139     }
00140     // Now apply global effects
00141     return brush(color);
00142 }
00143 //END StateEffects
00144 
00145 //BEGIN default colors
00146 struct SetDefaultColors {
00147     int NormalBackground[3];
00148     int AlternateBackground[3];
00149     int NormalText[3];
00150     int InactiveText[3];
00151     int ActiveText[3];
00152     int LinkText[3];
00153     int VisitedText[3];
00154     int NegativeText[3];
00155     int NeutralText[3];
00156     int PositiveText[3];
00157 };
00158 
00159 struct DecoDefaultColors {
00160     int Hover[3];
00161     int Focus[3];
00162 };
00163 
00164 SetDefaultColors defaultViewColors = {
00165     { 255, 255, 255 }, // Background
00166     { 248, 247, 246 }, // Alternate
00167     {  20,  19,  18 }, // Normal
00168     { 136, 135, 134 }, // Inactive
00169     { 255, 128, 224 }, // Active
00170     {   0,  87, 174 }, // Link
00171     { 100,  74, 155 }, // Visited
00172     { 191,   3,   3 }, // Negative
00173     { 176, 128,   0 }, // Neutral
00174     {   0, 110,  40 }  // Positive
00175 };
00176 
00177 SetDefaultColors defaultWindowColors = {
00178     { 224, 223, 222 }, // Background
00179     { 218, 217, 216 }, // Alternate
00180     {  20,  19,  18 }, // Normal
00181     { 136, 135, 134 }, // Inactive
00182     { 255, 128, 224 }, // Active
00183     {   0,  87, 174 }, // Link
00184     { 100,  74, 155 }, // Visited
00185     { 191,   3,   3 }, // Negative
00186     { 176, 128,   0 }, // Neutral
00187     {   0, 110,  40 }  // Positive
00188 };
00189 
00190 SetDefaultColors defaultButtonColors = {
00191     { 232, 231, 230 }, // Background
00192     { 224, 223, 222 }, // Alternate
00193     {  20,  19,  18 }, // Normal
00194     { 136, 135, 134 }, // Inactive
00195     { 255, 128, 224 }, // Active
00196     {   0,  87, 174 }, // Link
00197     { 100,  74, 155 }, // Visited
00198     { 191,   3,   3 }, // Negative
00199     { 176, 128,   0 }, // Neutral
00200     {   0, 110,  40 }  // Positive
00201 };
00202 
00203 SetDefaultColors defaultSelectionColors = {
00204     {  65, 139, 212 }, // Background
00205     {  62, 138, 204 }, // Alternate
00206     { 255, 255, 255 }, // Normal
00207     { 165, 193, 228 }, // Inactive
00208     { 255, 128, 224 }, // Active
00209     {   0,  49, 110 }, // Link
00210     {  69,  40, 134 }, // Visited
00211     { 156,  14,  14 }, // Negative
00212     { 255, 221,   0 }, // Neutral
00213     { 128, 255, 128 }  // Positive
00214 };
00215 
00216 SetDefaultColors defaultTooltipColors = {
00217     { 192, 218, 255 }, // Background
00218     { 196, 224, 255 }, // Alternate
00219     {  20,  19,  18 }, // Normal
00220     {  96, 112, 128 }, // Inactive
00221     { 255, 128, 224 }, // Active
00222     {   0,  87, 174 }, // Link
00223     { 100,  74, 155 }, // Visited
00224     { 191,   3,   3 }, // Negative
00225     { 176, 128,   0 }, // Neutral
00226     {   0, 110,  40 }  // Positive
00227 };
00228 
00229 
00230 DecoDefaultColors defaultDecorationColors = {
00231     { 119, 183, 255 }, // Hover
00232     {  43, 116, 199 }, // Focus
00233 };
00234 //END default colors
00235 
00236 //BEGIN KColorSchemePrivate
00237 class KColorSchemePrivate : public QSharedData
00238 {
00239 public:
00240     explicit KColorSchemePrivate(const KSharedConfigPtr&, QPalette::ColorGroup, const char*, SetDefaultColors);
00241     explicit KColorSchemePrivate(const KSharedConfigPtr&, QPalette::ColorGroup, const char*, SetDefaultColors, const QBrush&);
00242     ~KColorSchemePrivate() {}
00243 
00244     QBrush background(KColorScheme::BackgroundRole) const;
00245     QBrush foreground(KColorScheme::ForegroundRole) const;
00246     QBrush decoration(KColorScheme::DecorationRole) const;
00247     qreal contrast() const;
00248 private:
00249     struct {
00250         QBrush fg[8], bg[8], deco[2];
00251     } _brushes;
00252     qreal _contrast;
00253 
00254     void init(const KSharedConfigPtr&, QPalette::ColorGroup, const char*, SetDefaultColors);
00255 };
00256 
00257 #define DEFAULT(c) QColor( c[0], c[1], c[2] )
00258 #define  SET_DEFAULT(a) DEFAULT( defaults.a )
00259 #define DECO_DEFAULT(a) DEFAULT( defaultDecorationColors.a )
00260 
00261 KColorSchemePrivate::KColorSchemePrivate(const KSharedConfigPtr &config,
00262                                          QPalette::ColorGroup state,
00263                                          const char *group,
00264                                          SetDefaultColors defaults)
00265 {
00266     KConfigGroup cfg( config, group );
00267     _contrast = KGlobalSettings::contrastF( config );
00268 
00269     // loaded-from-config colors (no adjustment)
00270     _brushes.bg[0] = cfg.readEntry( "BackgroundNormal", SET_DEFAULT(NormalBackground) );
00271     _brushes.bg[1] = cfg.readEntry( "BackgroundAlternate", SET_DEFAULT(AlternateBackground) );
00272 
00273     // the rest
00274     init(config, state, group, defaults);
00275 }
00276 
00277 KColorSchemePrivate::KColorSchemePrivate(const KSharedConfigPtr &config,
00278                                          QPalette::ColorGroup state,
00279                                          const char *group,
00280                                          SetDefaultColors defaults,
00281                                          const QBrush &tint)
00282 {
00283     KConfigGroup cfg( config, group );
00284     _contrast = KGlobalSettings::contrastF( config );
00285 
00286     // loaded-from-config colors
00287     _brushes.bg[0] = cfg.readEntry( "BackgroundNormal", SET_DEFAULT(NormalBackground) );
00288     _brushes.bg[1] = cfg.readEntry( "BackgroundAlternate", SET_DEFAULT(AlternateBackground) );
00289 
00290     // adjustment
00291     _brushes.bg[0] = KColorUtils::tint(_brushes.bg[0].color(), tint.color(), 0.4);
00292     _brushes.bg[1] = KColorUtils::tint(_brushes.bg[1].color(), tint.color(), 0.4);
00293 
00294     // the rest
00295     init(config, state, group, defaults);
00296 }
00297 
00298 void KColorSchemePrivate::init(const KSharedConfigPtr &config,
00299                                QPalette::ColorGroup state,
00300                                const char *group,
00301                                SetDefaultColors defaults)
00302 {
00303     KConfigGroup cfg( config, group );
00304 
00305     // loaded-from-config colors
00306     _brushes.fg[0] = cfg.readEntry( "ForegroundNormal", SET_DEFAULT(NormalText) );
00307     _brushes.fg[1] = cfg.readEntry( "ForegroundInactive", SET_DEFAULT(InactiveText) );
00308     _brushes.fg[2] = cfg.readEntry( "ForegroundActive", SET_DEFAULT(ActiveText) );
00309     _brushes.fg[3] = cfg.readEntry( "ForegroundLink", SET_DEFAULT(LinkText) );
00310     _brushes.fg[4] = cfg.readEntry( "ForegroundVisited", SET_DEFAULT(VisitedText) );
00311     _brushes.fg[5] = cfg.readEntry( "ForegroundNegative", SET_DEFAULT(NegativeText) );
00312     _brushes.fg[6] = cfg.readEntry( "ForegroundNeutral", SET_DEFAULT(NeutralText) );
00313     _brushes.fg[7] = cfg.readEntry( "ForegroundPositive", SET_DEFAULT(PositiveText) );
00314 
00315     _brushes.deco[0] = cfg.readEntry( "DecorationHover", DECO_DEFAULT(Hover) );
00316     _brushes.deco[1] = cfg.readEntry( "DecorationFocus", DECO_DEFAULT(Focus) );
00317 
00318     // apply state adjustments
00319     if (state != QPalette::Active) {
00320         StateEffects effects(state, config);
00321         for (int i=0; i<8; i++) {
00322             _brushes.fg[i] = effects.brush(_brushes.fg[i], _brushes.bg[0]);
00323         }
00324         _brushes.deco[0] = effects.brush(_brushes.deco[0], _brushes.bg[0]);
00325         _brushes.deco[1] = effects.brush(_brushes.deco[1], _brushes.bg[0]);
00326         _brushes.bg[0] = effects.brush(_brushes.bg[0]);
00327         _brushes.bg[1] = effects.brush(_brushes.bg[1]);
00328     }
00329 
00330     // calculated backgrounds
00331     _brushes.bg[2] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[2].color() );
00332     _brushes.bg[3] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[3].color() );
00333     _brushes.bg[4] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[4].color() );
00334     _brushes.bg[5] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[5].color() );
00335     _brushes.bg[6] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[6].color() );
00336     _brushes.bg[7] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[7].color() );
00337 }
00338 
00339 QBrush KColorSchemePrivate::background(KColorScheme::BackgroundRole role) const
00340 {
00341     switch (role) {
00342         case KColorScheme::AlternateBackground:
00343             return _brushes.bg[1];
00344         case KColorScheme::ActiveBackground:
00345             return _brushes.bg[2];
00346         case KColorScheme::LinkBackground:
00347             return _brushes.bg[3];
00348         case KColorScheme::VisitedBackground:
00349             return _brushes.bg[4];
00350         case KColorScheme::NegativeBackground:
00351             return _brushes.bg[5];
00352         case KColorScheme::NeutralBackground:
00353             return _brushes.bg[6];
00354         case KColorScheme::PositiveBackground:
00355             return _brushes.bg[7];
00356         default:
00357             return _brushes.bg[0];
00358     }
00359 }
00360 
00361 QBrush KColorSchemePrivate::foreground(KColorScheme::ForegroundRole role) const
00362 {
00363     switch (role) {
00364         case KColorScheme::InactiveText:
00365             return _brushes.fg[1];
00366         case KColorScheme::ActiveText:
00367             return _brushes.fg[2];
00368         case KColorScheme::LinkText:
00369             return _brushes.fg[3];
00370         case KColorScheme::VisitedText:
00371             return _brushes.fg[4];
00372         case KColorScheme::NegativeText:
00373             return _brushes.fg[5];
00374         case KColorScheme::NeutralText:
00375             return _brushes.fg[6];
00376         case KColorScheme::PositiveText:
00377             return _brushes.fg[7];
00378         default:
00379             return _brushes.fg[0];
00380     }
00381 }
00382 
00383 QBrush KColorSchemePrivate::decoration(KColorScheme::DecorationRole role) const
00384 {
00385     switch (role) {
00386         case KColorScheme::FocusColor:
00387             return _brushes.deco[1];
00388         default:
00389             return _brushes.deco[0];
00390     }
00391 }
00392 
00393 qreal KColorSchemePrivate::contrast() const
00394 {
00395     return _contrast;
00396 }
00397 //END KColorSchemePrivate
00398 
00399 //BEGIN KColorScheme
00400 KColorScheme::KColorScheme(const KColorScheme &other) : d(other.d)
00401 {
00402 }
00403 
00404 KColorScheme& KColorScheme::operator=(const KColorScheme& other)
00405 {
00406     d = other.d;
00407     return *this;
00408 }
00409 
00410 KColorScheme::~KColorScheme()
00411 {
00412 }
00413 
00414 KColorScheme::KColorScheme(QPalette::ColorGroup state, ColorSet set, KSharedConfigPtr config)
00415 {
00416     if (!config)
00417         config = KGlobal::config();
00418 
00419     switch (set) {
00420         case Window:
00421             d = new KColorSchemePrivate(config, state, "Colors:Window", defaultWindowColors);
00422             break;
00423         case Button:
00424             d = new KColorSchemePrivate(config, state, "Colors:Button", defaultButtonColors);
00425             break;
00426         case Selection: {
00427             KConfigGroup group(config, "ColorEffects:Inactive");
00428             // NOTE: keep this in sync with kdebase/workspace/kcontrol/colors/colorscm.cpp
00429             bool inactiveSelectionEffect = group.readEntry("ChangeSelectionColor", group.readEntry("Enable", false));
00430             // if enabled, inactiver/disabled uses Window colors instead, ala gtk
00431             // ...except tinted with the Selection:NormalBackground color so it looks more like selection
00432             if (state == QPalette::Active || (state == QPalette::Inactive && !inactiveSelectionEffect))
00433                 d = new KColorSchemePrivate(config, state, "Colors:Selection", defaultSelectionColors);
00434             else if (state == QPalette::Inactive)
00435                 d = new KColorSchemePrivate(config, state, "Colors:Window", defaultWindowColors,
00436                                             KColorScheme(QPalette::Active, Selection, config).background());
00437             else // disabled (...and still want this branch when inactive+disabled exists)
00438                 d = new KColorSchemePrivate(config, state, "Colors:Window", defaultWindowColors);
00439             } break;
00440         case Tooltip:
00441             d = new KColorSchemePrivate(config, state, "Colors:Tooltip", defaultTooltipColors);
00442             break;
00443         default:
00444             d = new KColorSchemePrivate(config, state, "Colors:View", defaultViewColors);
00445     }
00446 }
00447 
00448 QBrush KColorScheme::background(BackgroundRole role) const
00449 {
00450     return d->background(role);
00451 }
00452 
00453 QBrush KColorScheme::foreground(ForegroundRole role) const
00454 {
00455     return d->foreground(role);
00456 }
00457 
00458 QBrush KColorScheme::decoration(DecorationRole role) const
00459 {
00460     return d->decoration(role);
00461 }
00462 
00463 QColor KColorScheme::shade(ShadeRole role) const
00464 {
00465     return shade(background().color(), role, d->contrast());
00466 }
00467 
00468 QColor KColorScheme::shade(const QColor &color, ShadeRole role)
00469 {
00470     return shade(color, role, KGlobalSettings::contrastF());
00471 }
00472 
00473 QColor KColorScheme::shade(const QColor &color, ShadeRole role, qreal contrast, qreal chromaAdjust)
00474 {
00475     // nan -> 1.0
00476     contrast = (1.0 > contrast ? (-1.0 < contrast ? contrast : -1.0) : 1.0);
00477     qreal y = KColorUtils::luma(color), yi = 1.0 - y;
00478 
00479     // handle very dark colors (base, mid, dark, shadow == midlight, light)
00480     if (y < 0.006) {
00481         switch (role) {
00482             case KColorScheme::LightShade:
00483                 return KColorUtils::shade(color, 0.05 + 0.95 * contrast, chromaAdjust);
00484             case KColorScheme::MidShade:
00485                 return KColorUtils::shade(color, 0.01 + 0.20 * contrast, chromaAdjust);
00486             case KColorScheme::DarkShade:
00487                 return KColorUtils::shade(color, 0.02 + 0.40 * contrast, chromaAdjust);
00488             default:
00489                 return KColorUtils::shade(color, 0.03 + 0.60 * contrast, chromaAdjust);
00490         }
00491     }
00492 
00493     // handle very light colors (base, midlight, light == mid, dark, shadow)
00494     if (y > 0.93) {
00495         switch (role) {
00496             case KColorScheme::MidlightShade:
00497                 return KColorUtils::shade(color, -0.02 - 0.20 * contrast, chromaAdjust);
00498             case KColorScheme::DarkShade:
00499                 return KColorUtils::shade(color, -0.06 - 0.60 * contrast, chromaAdjust);
00500             case KColorScheme::ShadowShade:
00501                 return KColorUtils::shade(color, -0.10 - 0.90 * contrast, chromaAdjust);
00502             default:
00503                 return KColorUtils::shade(color, -0.04 - 0.40 * contrast, chromaAdjust);
00504         }
00505     }
00506 
00507     // handle everything else
00508     qreal lightAmount = (0.05 + y * 0.55) * (0.25 + contrast * 0.75);
00509     qreal darkAmount =  (     - y       ) * (0.55 + contrast * 0.35);
00510     switch (role) {
00511         case KColorScheme::LightShade:
00512             return KColorUtils::shade(color, lightAmount, chromaAdjust);
00513         case KColorScheme::MidlightShade:
00514             return KColorUtils::shade(color, (0.15 + 0.35 * yi) * lightAmount, chromaAdjust);
00515         case KColorScheme::MidShade:
00516             return KColorUtils::shade(color, (0.35 + 0.15 * y) * darkAmount, chromaAdjust);
00517         case KColorScheme::DarkShade:
00518             return KColorUtils::shade(color, darkAmount, chromaAdjust);
00519         default:
00520             return KColorUtils::darken(KColorUtils::shade(color, darkAmount, chromaAdjust), 0.5 + 0.3 * y);
00521     }
00522 }
00523 
00524 void KColorScheme::adjustBackground(QPalette &palette, BackgroundRole newRole, QPalette::ColorRole color,
00525                                     ColorSet set, KSharedConfigPtr config) {
00526     palette.setBrush(QPalette::Active,   color, KColorScheme(QPalette::Active,   set, config).background(newRole));
00527     palette.setBrush(QPalette::Inactive, color, KColorScheme(QPalette::Inactive, set, config).background(newRole));
00528     palette.setBrush(QPalette::Disabled, color, KColorScheme(QPalette::Disabled, set, config).background(newRole));
00529 }
00530 
00531 void KColorScheme::adjustForeground(QPalette &palette, ForegroundRole newRole, QPalette::ColorRole color,
00532                                     ColorSet set, KSharedConfigPtr config) {
00533     palette.setBrush(QPalette::Active,   color, KColorScheme(QPalette::Active,   set, config).foreground(newRole));
00534     palette.setBrush(QPalette::Inactive, color, KColorScheme(QPalette::Inactive, set, config).foreground(newRole));
00535     palette.setBrush(QPalette::Disabled, color, KColorScheme(QPalette::Disabled, set, config).foreground(newRole));
00536 }
00537 //END KColorScheme
00538 
00539 //BEGIN KStatefulBrush
00540 class KStatefulBrushPrivate : public QBrush // for now, just be a QBrush
00541 {
00542     public:
00543         KStatefulBrushPrivate() : QBrush() {}
00544         KStatefulBrushPrivate(const QBrush &brush) : QBrush(brush) {} // not explicit
00545 };
00546 
00547 KStatefulBrush::KStatefulBrush()
00548 {
00549     d = new KStatefulBrushPrivate[3];
00550 }
00551 
00552 KStatefulBrush::KStatefulBrush(KColorScheme::ColorSet set, KColorScheme::ForegroundRole role,
00553                                KSharedConfigPtr config)
00554 {
00555     d = new KStatefulBrushPrivate[3];
00556     d[0] = KColorScheme(QPalette::Active,   set, config).foreground(role);
00557     d[1] = KColorScheme(QPalette::Disabled, set, config).foreground(role);
00558     d[2] = KColorScheme(QPalette::Inactive, set, config).foreground(role);
00559 }
00560 
00561 KStatefulBrush::KStatefulBrush(KColorScheme::ColorSet set, KColorScheme::BackgroundRole role,
00562                                KSharedConfigPtr config)
00563 {
00564     d = new KStatefulBrushPrivate[3];
00565     d[0] = KColorScheme(QPalette::Active,   set, config).background(role);
00566     d[1] = KColorScheme(QPalette::Disabled, set, config).background(role);
00567     d[2] = KColorScheme(QPalette::Inactive, set, config).background(role);
00568 }
00569 
00570 KStatefulBrush::KStatefulBrush(KColorScheme::ColorSet set, KColorScheme::DecorationRole role,
00571                                KSharedConfigPtr config)
00572 {
00573     d = new KStatefulBrushPrivate[3];
00574     d[0] = KColorScheme(QPalette::Active,   set, config).decoration(role);
00575     d[1] = KColorScheme(QPalette::Disabled, set, config).decoration(role);
00576     d[2] = KColorScheme(QPalette::Inactive, set, config).decoration(role);
00577 }
00578 
00579 KStatefulBrush::KStatefulBrush(const QBrush &brush, KSharedConfigPtr config)
00580 {
00581     if (!config)
00582         config = KGlobal::config();
00583     d = new KStatefulBrushPrivate[3];
00584     d[0] = brush;
00585     d[1] = StateEffects(QPalette::Disabled, config).brush(brush);
00586     d[2] = StateEffects(QPalette::Inactive, config).brush(brush);
00587 }
00588 
00589 KStatefulBrush::KStatefulBrush(const QBrush &brush, const QBrush &background,
00590                                KSharedConfigPtr config)
00591 {
00592     if (!config)
00593         config = KGlobal::config();
00594     d = new KStatefulBrushPrivate[3];
00595     d[0] = brush;
00596     d[1] = StateEffects(QPalette::Disabled, config).brush(brush, background);
00597     d[2] = StateEffects(QPalette::Inactive, config).brush(brush, background);
00598 }
00599 
00600 KStatefulBrush::KStatefulBrush(const KStatefulBrush &other)
00601 {
00602     d = new KStatefulBrushPrivate[3];
00603     d[0] = other.d[0];
00604     d[1] = other.d[1];
00605     d[2] = other.d[2];
00606 }
00607 
00608 KStatefulBrush::~KStatefulBrush()
00609 {
00610     delete[] d;
00611 }
00612 
00613 KStatefulBrush& KStatefulBrush::operator=(const KStatefulBrush &other)
00614 {
00615     d[0] = other.d[0];
00616     d[1] = other.d[1];
00617     d[2] = other.d[2];
00618     return *this;
00619 }
00620 
00621 QBrush KStatefulBrush::brush(QPalette::ColorGroup state) const
00622 {
00623     switch (state) {
00624         case QPalette::Inactive:
00625             return d[2];
00626         case QPalette::Disabled:
00627             return d[1];
00628         default:
00629             return d[0];
00630     }
00631 }
00632 
00633 QBrush KStatefulBrush::brush(const QPalette &pal) const
00634 {
00635     return brush(pal.currentColorGroup());
00636 }
00637 
00638 QBrush KStatefulBrush::brush(const QWidget *widget) const
00639 {
00640     if (widget)
00641         return brush(widget->palette());
00642     else
00643         return QBrush();
00644 }
00645 //END KStatefulBrush
00646 
00647 // kate: space-indent on; indent-width 4; replace-tabs on; auto-insert-doxygen on;

KDEUI

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal