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 00078 _effects[0] = 0; 00079 _effects[1] = 0; 00080 _effects[2] = 0; 00081 00082 // NOTE: keep this in sync with kdebase/workspace/kcontrol/colors/colorscm.cpp 00083 if(! group.isEmpty()) { 00084 KConfigGroup cfg(config, group); 00085 const bool enabledByDefault = (state == QPalette::Disabled); 00086 if (cfg.readEntry("Enable", enabledByDefault)) { 00087 _effects[Intensity] = cfg.readEntry( "IntensityEffect", 00088 (int)(state == QPalette::Disabled ? IntensityDarken : IntensityNoEffect)); 00089 _effects[Color] = cfg.readEntry( "ColorEffect", 00090 (int)(state == QPalette::Disabled ? ColorNoEffect : ColorFade)); 00091 _effects[Contrast] = cfg.readEntry( "ContrastEffect", 00092 (int)(state == QPalette::Disabled ? ContrastFade : ContrastTint)); 00093 _amount[Intensity] = cfg.readEntry( "IntensityAmount", state == QPalette::Disabled ? 0.10 : 0.0 ); 00094 _amount[Color] = cfg.readEntry( "ColorAmount", state == QPalette::Disabled ? 0.0 : 0.025 ); 00095 _amount[Contrast] = cfg.readEntry( "ContrastAmount", state == QPalette::Disabled ? 0.65 : 0.10 ); 00096 if (_effects[Color] > ColorNoEffect) 00097 _color = cfg.readEntry( "Color", state == QPalette::Disabled ? QColor(56, 56, 56) : QColor(112, 111, 110)); 00098 } 00099 } 00100 } 00101 00102 QBrush StateEffects::brush(const QBrush &background) const 00103 { 00104 QColor color = background.color(); // TODO - actually work on brushes 00105 switch (_effects[Intensity]) { 00106 case IntensityShade: 00107 color = KColorUtils::shade(color, _amount[Intensity]); 00108 break; 00109 case IntensityDarken: 00110 color = KColorUtils::darken(color, _amount[Intensity]); 00111 break; 00112 case IntensityLighten: 00113 color = KColorUtils::lighten(color, _amount[Intensity]); 00114 break; 00115 } 00116 switch (_effects[Color]) { 00117 case ColorDesaturate: 00118 color = KColorUtils::darken(color, 0.0, 1.0 - _amount[Color]); 00119 break; 00120 case ColorFade: 00121 color = KColorUtils::mix(color, _color, _amount[Color]); 00122 break; 00123 case ColorTint: 00124 color = KColorUtils::tint(color, _color, _amount[Color]); 00125 break; 00126 } 00127 return QBrush(color); 00128 } 00129 00130 QBrush StateEffects::brush(const QBrush &foreground, const QBrush &background) const 00131 { 00132 QColor color = foreground.color(); // TODO - actually work on brushes 00133 QColor bg = background.color(); 00134 // Apply the foreground effects 00135 switch (_effects[Contrast]) { 00136 case ContrastFade: 00137 color = KColorUtils::mix(color, bg, _amount[Contrast]); 00138 break; 00139 case ContrastTint: 00140 color = KColorUtils::tint(color, bg, _amount[Contrast]); 00141 break; 00142 } 00143 // Now apply global effects 00144 return brush(color); 00145 } 00146 //END StateEffects 00147 00148 //BEGIN default colors 00149 struct SetDefaultColors { 00150 int NormalBackground[3]; 00151 int AlternateBackground[3]; 00152 int NormalText[3]; 00153 int InactiveText[3]; 00154 int ActiveText[3]; 00155 int LinkText[3]; 00156 int VisitedText[3]; 00157 int NegativeText[3]; 00158 int NeutralText[3]; 00159 int PositiveText[3]; 00160 }; 00161 00162 struct DecoDefaultColors { 00163 int Hover[3]; 00164 int Focus[3]; 00165 }; 00166 00167 SetDefaultColors defaultViewColors = { 00168 { 255, 255, 255 }, // Background 00169 { 248, 247, 246 }, // Alternate 00170 { 24, 22, 21 }, // Normal 00171 { 137, 136, 135 }, // Inactive 00172 { 255, 128, 224 }, // Active 00173 { 0, 87, 174 }, // Link 00174 { 100, 74, 155 }, // Visited 00175 { 191, 3, 3 }, // Negative 00176 { 176, 128, 0 }, // Neutral 00177 { 0, 110, 40 } // Positive 00178 }; 00179 00180 00181 SetDefaultColors defaultWindowColors = { 00182 { 213, 209, 207 }, // Background 00183 { 218, 217, 216 }, // Alternate 00184 { 27, 25, 24 }, // Normal 00185 { 137, 136, 135 }, // Inactive 00186 { 255, 128, 224 }, // Active 00187 { 0, 87, 174 }, // Link 00188 { 100, 74, 155 }, // Visited 00189 { 191, 3, 3 }, // Negative 00190 { 176, 128, 0 }, // Neutral 00191 { 0, 110, 40 } // Positive 00192 }; 00193 00194 00195 SetDefaultColors defaultButtonColors = { 00196 { 207, 204, 201 }, // Background 00197 { 224, 223, 222 }, // Alternate 00198 { 27, 25, 24 }, // Normal 00199 { 137, 136, 135 }, // Inactive 00200 { 255, 128, 224 }, // Active 00201 { 0, 87, 174 }, // Link 00202 { 100, 74, 155 }, // Visited 00203 { 191, 3, 3 }, // Negative 00204 { 176, 128, 0 }, // Neutral 00205 { 0, 110, 40 } // Positive 00206 }; 00207 00208 00209 SetDefaultColors defaultSelectionColors = { 00210 { 67, 172, 232 }, // Background 00211 { 62, 138, 204 }, // Alternate 00212 { 255, 255, 255 }, // Normal 00213 { 165, 193, 228 }, // Inactive 00214 { 255, 128, 224 }, // Active 00215 { 0, 49, 110 }, // Link 00216 { 69, 40, 134 }, // Visited 00217 { 156, 14, 14 }, // Negative 00218 { 255, 221, 0 }, // Neutral 00219 { 128, 255, 128 } // Positive 00220 }; 00221 00222 00223 SetDefaultColors defaultTooltipColors = { 00224 { 190, 223, 255 }, // Background 00225 { 196, 224, 255 }, // Alternate 00226 { 37, 35, 33 }, // Normal 00227 { 137, 136, 135 }, // Inactive 00228 { 255, 128, 224 }, // Active 00229 { 0, 87, 174 }, // Link 00230 { 100, 74, 155 }, // Visited 00231 { 191, 3, 3 }, // Negative 00232 { 176, 128, 0 }, // Neutral 00233 { 0, 110, 40 } // Positive 00234 }; 00235 00236 DecoDefaultColors defaultDecorationColors = { 00237 { 110, 214, 255 }, // Hover 00238 { 58, 167, 221 }, // Focus 00239 }; 00240 //END default colors 00241 00242 //BEGIN KColorSchemePrivate 00243 class KColorSchemePrivate : public QSharedData 00244 { 00245 public: 00246 explicit KColorSchemePrivate(const KSharedConfigPtr&, QPalette::ColorGroup, const char*, SetDefaultColors); 00247 explicit KColorSchemePrivate(const KSharedConfigPtr&, QPalette::ColorGroup, const char*, SetDefaultColors, const QBrush&); 00248 ~KColorSchemePrivate() {} 00249 00250 QBrush background(KColorScheme::BackgroundRole) const; 00251 QBrush foreground(KColorScheme::ForegroundRole) const; 00252 QBrush decoration(KColorScheme::DecorationRole) const; 00253 qreal contrast() const; 00254 private: 00255 struct { 00256 QBrush fg[8], bg[8], deco[2]; 00257 } _brushes; 00258 qreal _contrast; 00259 00260 void init(const KSharedConfigPtr&, QPalette::ColorGroup, const char*, SetDefaultColors); 00261 }; 00262 00263 #define DEFAULT(c) QColor( c[0], c[1], c[2] ) 00264 #define SET_DEFAULT(a) DEFAULT( defaults.a ) 00265 #define DECO_DEFAULT(a) DEFAULT( defaultDecorationColors.a ) 00266 00267 KColorSchemePrivate::KColorSchemePrivate(const KSharedConfigPtr &config, 00268 QPalette::ColorGroup state, 00269 const char *group, 00270 SetDefaultColors defaults) 00271 { 00272 KConfigGroup cfg( config, group ); 00273 _contrast = KGlobalSettings::contrastF( config ); 00274 00275 // loaded-from-config colors (no adjustment) 00276 _brushes.bg[0] = cfg.readEntry( "BackgroundNormal", SET_DEFAULT(NormalBackground) ); 00277 _brushes.bg[1] = cfg.readEntry( "BackgroundAlternate", SET_DEFAULT(AlternateBackground) ); 00278 00279 // the rest 00280 init(config, state, group, defaults); 00281 } 00282 00283 KColorSchemePrivate::KColorSchemePrivate(const KSharedConfigPtr &config, 00284 QPalette::ColorGroup state, 00285 const char *group, 00286 SetDefaultColors defaults, 00287 const QBrush &tint) 00288 { 00289 KConfigGroup cfg( config, group ); 00290 _contrast = KGlobalSettings::contrastF( config ); 00291 00292 // loaded-from-config colors 00293 _brushes.bg[0] = cfg.readEntry( "BackgroundNormal", SET_DEFAULT(NormalBackground) ); 00294 _brushes.bg[1] = cfg.readEntry( "BackgroundAlternate", SET_DEFAULT(AlternateBackground) ); 00295 00296 // adjustment 00297 _brushes.bg[0] = KColorUtils::tint(_brushes.bg[0].color(), tint.color(), 0.4); 00298 _brushes.bg[1] = KColorUtils::tint(_brushes.bg[1].color(), tint.color(), 0.4); 00299 00300 // the rest 00301 init(config, state, group, defaults); 00302 } 00303 00304 void KColorSchemePrivate::init(const KSharedConfigPtr &config, 00305 QPalette::ColorGroup state, 00306 const char *group, 00307 SetDefaultColors defaults) 00308 { 00309 KConfigGroup cfg( config, group ); 00310 00311 // loaded-from-config colors 00312 _brushes.fg[0] = cfg.readEntry( "ForegroundNormal", SET_DEFAULT(NormalText) ); 00313 _brushes.fg[1] = cfg.readEntry( "ForegroundInactive", SET_DEFAULT(InactiveText) ); 00314 _brushes.fg[2] = cfg.readEntry( "ForegroundActive", SET_DEFAULT(ActiveText) ); 00315 _brushes.fg[3] = cfg.readEntry( "ForegroundLink", SET_DEFAULT(LinkText) ); 00316 _brushes.fg[4] = cfg.readEntry( "ForegroundVisited", SET_DEFAULT(VisitedText) ); 00317 _brushes.fg[5] = cfg.readEntry( "ForegroundNegative", SET_DEFAULT(NegativeText) ); 00318 _brushes.fg[6] = cfg.readEntry( "ForegroundNeutral", SET_DEFAULT(NeutralText) ); 00319 _brushes.fg[7] = cfg.readEntry( "ForegroundPositive", SET_DEFAULT(PositiveText) ); 00320 00321 _brushes.deco[0] = cfg.readEntry( "DecorationHover", DECO_DEFAULT(Hover) ); 00322 _brushes.deco[1] = cfg.readEntry( "DecorationFocus", DECO_DEFAULT(Focus) ); 00323 00324 // apply state adjustments 00325 if (state != QPalette::Active) { 00326 StateEffects effects(state, config); 00327 for (int i=0; i<8; i++) { 00328 _brushes.fg[i] = effects.brush(_brushes.fg[i], _brushes.bg[0]); 00329 } 00330 _brushes.deco[0] = effects.brush(_brushes.deco[0], _brushes.bg[0]); 00331 _brushes.deco[1] = effects.brush(_brushes.deco[1], _brushes.bg[0]); 00332 _brushes.bg[0] = effects.brush(_brushes.bg[0]); 00333 _brushes.bg[1] = effects.brush(_brushes.bg[1]); 00334 } 00335 00336 // calculated backgrounds 00337 _brushes.bg[2] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[2].color() ); 00338 _brushes.bg[3] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[3].color() ); 00339 _brushes.bg[4] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[4].color() ); 00340 _brushes.bg[5] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[5].color() ); 00341 _brushes.bg[6] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[6].color() ); 00342 _brushes.bg[7] = KColorUtils::tint( _brushes.bg[0].color(), _brushes.fg[7].color() ); 00343 } 00344 00345 QBrush KColorSchemePrivate::background(KColorScheme::BackgroundRole role) const 00346 { 00347 switch (role) { 00348 case KColorScheme::AlternateBackground: 00349 return _brushes.bg[1]; 00350 case KColorScheme::ActiveBackground: 00351 return _brushes.bg[2]; 00352 case KColorScheme::LinkBackground: 00353 return _brushes.bg[3]; 00354 case KColorScheme::VisitedBackground: 00355 return _brushes.bg[4]; 00356 case KColorScheme::NegativeBackground: 00357 return _brushes.bg[5]; 00358 case KColorScheme::NeutralBackground: 00359 return _brushes.bg[6]; 00360 case KColorScheme::PositiveBackground: 00361 return _brushes.bg[7]; 00362 default: 00363 return _brushes.bg[0]; 00364 } 00365 } 00366 00367 QBrush KColorSchemePrivate::foreground(KColorScheme::ForegroundRole role) const 00368 { 00369 switch (role) { 00370 case KColorScheme::InactiveText: 00371 return _brushes.fg[1]; 00372 case KColorScheme::ActiveText: 00373 return _brushes.fg[2]; 00374 case KColorScheme::LinkText: 00375 return _brushes.fg[3]; 00376 case KColorScheme::VisitedText: 00377 return _brushes.fg[4]; 00378 case KColorScheme::NegativeText: 00379 return _brushes.fg[5]; 00380 case KColorScheme::NeutralText: 00381 return _brushes.fg[6]; 00382 case KColorScheme::PositiveText: 00383 return _brushes.fg[7]; 00384 default: 00385 return _brushes.fg[0]; 00386 } 00387 } 00388 00389 QBrush KColorSchemePrivate::decoration(KColorScheme::DecorationRole role) const 00390 { 00391 switch (role) { 00392 case KColorScheme::FocusColor: 00393 return _brushes.deco[1]; 00394 default: 00395 return _brushes.deco[0]; 00396 } 00397 } 00398 00399 qreal KColorSchemePrivate::contrast() const 00400 { 00401 return _contrast; 00402 } 00403 //END KColorSchemePrivate 00404 00405 //BEGIN KColorScheme 00406 KColorScheme::KColorScheme(const KColorScheme &other) : d(other.d) 00407 { 00408 } 00409 00410 KColorScheme& KColorScheme::operator=(const KColorScheme& other) 00411 { 00412 d = other.d; 00413 return *this; 00414 } 00415 00416 KColorScheme::~KColorScheme() 00417 { 00418 } 00419 00420 KColorScheme::KColorScheme(QPalette::ColorGroup state, ColorSet set, KSharedConfigPtr config) 00421 { 00422 if (!config) 00423 config = KGlobal::config(); 00424 00425 switch (set) { 00426 case Window: 00427 d = new KColorSchemePrivate(config, state, "Colors:Window", defaultWindowColors); 00428 break; 00429 case Button: 00430 d = new KColorSchemePrivate(config, state, "Colors:Button", defaultButtonColors); 00431 break; 00432 case Selection: { 00433 KConfigGroup group(config, "ColorEffects:Inactive"); 00434 // NOTE: keep this in sync with kdebase/workspace/kcontrol/colors/colorscm.cpp 00435 bool inactiveSelectionEffect = group.readEntry("ChangeSelectionColor", group.readEntry("Enable", true)); 00436 // if enabled, inactiver/disabled uses Window colors instead, ala gtk 00437 // ...except tinted with the Selection:NormalBackground color so it looks more like selection 00438 if (state == QPalette::Active || (state == QPalette::Inactive && !inactiveSelectionEffect)) 00439 d = new KColorSchemePrivate(config, state, "Colors:Selection", defaultSelectionColors); 00440 else if (state == QPalette::Inactive) 00441 d = new KColorSchemePrivate(config, state, "Colors:Window", defaultWindowColors, 00442 KColorScheme(QPalette::Active, Selection, config).background()); 00443 else // disabled (...and still want this branch when inactive+disabled exists) 00444 d = new KColorSchemePrivate(config, state, "Colors:Window", defaultWindowColors); 00445 } break; 00446 case Tooltip: 00447 d = new KColorSchemePrivate(config, state, "Colors:Tooltip", defaultTooltipColors); 00448 break; 00449 default: 00450 d = new KColorSchemePrivate(config, state, "Colors:View", defaultViewColors); 00451 } 00452 } 00453 00454 QBrush KColorScheme::background(BackgroundRole role) const 00455 { 00456 return d->background(role); 00457 } 00458 00459 QBrush KColorScheme::foreground(ForegroundRole role) const 00460 { 00461 return d->foreground(role); 00462 } 00463 00464 QBrush KColorScheme::decoration(DecorationRole role) const 00465 { 00466 return d->decoration(role); 00467 } 00468 00469 QColor KColorScheme::shade(ShadeRole role) const 00470 { 00471 return shade(background().color(), role, d->contrast()); 00472 } 00473 00474 QColor KColorScheme::shade(const QColor &color, ShadeRole role) 00475 { 00476 return shade(color, role, KGlobalSettings::contrastF()); 00477 } 00478 00479 QColor KColorScheme::shade(const QColor &color, ShadeRole role, qreal contrast, qreal chromaAdjust) 00480 { 00481 // nan -> 1.0 00482 contrast = (1.0 > contrast ? (-1.0 < contrast ? contrast : -1.0) : 1.0); 00483 qreal y = KColorUtils::luma(color), yi = 1.0 - y; 00484 00485 // handle very dark colors (base, mid, dark, shadow == midlight, light) 00486 if (y < 0.006) { 00487 switch (role) { 00488 case KColorScheme::LightShade: 00489 return KColorUtils::shade(color, 0.05 + 0.95 * contrast, chromaAdjust); 00490 case KColorScheme::MidShade: 00491 return KColorUtils::shade(color, 0.01 + 0.20 * contrast, chromaAdjust); 00492 case KColorScheme::DarkShade: 00493 return KColorUtils::shade(color, 0.02 + 0.40 * contrast, chromaAdjust); 00494 default: 00495 return KColorUtils::shade(color, 0.03 + 0.60 * contrast, chromaAdjust); 00496 } 00497 } 00498 00499 // handle very light colors (base, midlight, light == mid, dark, shadow) 00500 if (y > 0.93) { 00501 switch (role) { 00502 case KColorScheme::MidlightShade: 00503 return KColorUtils::shade(color, -0.02 - 0.20 * contrast, chromaAdjust); 00504 case KColorScheme::DarkShade: 00505 return KColorUtils::shade(color, -0.06 - 0.60 * contrast, chromaAdjust); 00506 case KColorScheme::ShadowShade: 00507 return KColorUtils::shade(color, -0.10 - 0.90 * contrast, chromaAdjust); 00508 default: 00509 return KColorUtils::shade(color, -0.04 - 0.40 * contrast, chromaAdjust); 00510 } 00511 } 00512 00513 // handle everything else 00514 qreal lightAmount = (0.05 + y * 0.55) * (0.25 + contrast * 0.75); 00515 qreal darkAmount = ( - y ) * (0.55 + contrast * 0.35); 00516 switch (role) { 00517 case KColorScheme::LightShade: 00518 return KColorUtils::shade(color, lightAmount, chromaAdjust); 00519 case KColorScheme::MidlightShade: 00520 return KColorUtils::shade(color, (0.15 + 0.35 * yi) * lightAmount, chromaAdjust); 00521 case KColorScheme::MidShade: 00522 return KColorUtils::shade(color, (0.35 + 0.15 * y) * darkAmount, chromaAdjust); 00523 case KColorScheme::DarkShade: 00524 return KColorUtils::shade(color, darkAmount, chromaAdjust); 00525 default: 00526 return KColorUtils::darken(KColorUtils::shade(color, darkAmount, chromaAdjust), 0.5 + 0.3 * y); 00527 } 00528 } 00529 00530 void KColorScheme::adjustBackground(QPalette &palette, BackgroundRole newRole, QPalette::ColorRole color, 00531 ColorSet set, KSharedConfigPtr config) { 00532 palette.setBrush(QPalette::Active, color, KColorScheme(QPalette::Active, set, config).background(newRole)); 00533 palette.setBrush(QPalette::Inactive, color, KColorScheme(QPalette::Inactive, set, config).background(newRole)); 00534 palette.setBrush(QPalette::Disabled, color, KColorScheme(QPalette::Disabled, set, config).background(newRole)); 00535 } 00536 00537 void KColorScheme::adjustForeground(QPalette &palette, ForegroundRole newRole, QPalette::ColorRole color, 00538 ColorSet set, KSharedConfigPtr config) { 00539 palette.setBrush(QPalette::Active, color, KColorScheme(QPalette::Active, set, config).foreground(newRole)); 00540 palette.setBrush(QPalette::Inactive, color, KColorScheme(QPalette::Inactive, set, config).foreground(newRole)); 00541 palette.setBrush(QPalette::Disabled, color, KColorScheme(QPalette::Disabled, set, config).foreground(newRole)); 00542 } 00543 //END KColorScheme 00544 00545 //BEGIN KStatefulBrush 00546 class KStatefulBrushPrivate : public QBrush // for now, just be a QBrush 00547 { 00548 public: 00549 KStatefulBrushPrivate() : QBrush() {} 00550 KStatefulBrushPrivate(const QBrush &brush) : QBrush(brush) {} // not explicit 00551 }; 00552 00553 KStatefulBrush::KStatefulBrush() 00554 { 00555 d = new KStatefulBrushPrivate[3]; 00556 } 00557 00558 KStatefulBrush::KStatefulBrush(KColorScheme::ColorSet set, KColorScheme::ForegroundRole role, 00559 KSharedConfigPtr config) 00560 { 00561 d = new KStatefulBrushPrivate[3]; 00562 d[0] = KColorScheme(QPalette::Active, set, config).foreground(role); 00563 d[1] = KColorScheme(QPalette::Disabled, set, config).foreground(role); 00564 d[2] = KColorScheme(QPalette::Inactive, set, config).foreground(role); 00565 } 00566 00567 KStatefulBrush::KStatefulBrush(KColorScheme::ColorSet set, KColorScheme::BackgroundRole role, 00568 KSharedConfigPtr config) 00569 { 00570 d = new KStatefulBrushPrivate[3]; 00571 d[0] = KColorScheme(QPalette::Active, set, config).background(role); 00572 d[1] = KColorScheme(QPalette::Disabled, set, config).background(role); 00573 d[2] = KColorScheme(QPalette::Inactive, set, config).background(role); 00574 } 00575 00576 KStatefulBrush::KStatefulBrush(KColorScheme::ColorSet set, KColorScheme::DecorationRole role, 00577 KSharedConfigPtr config) 00578 { 00579 d = new KStatefulBrushPrivate[3]; 00580 d[0] = KColorScheme(QPalette::Active, set, config).decoration(role); 00581 d[1] = KColorScheme(QPalette::Disabled, set, config).decoration(role); 00582 d[2] = KColorScheme(QPalette::Inactive, set, config).decoration(role); 00583 } 00584 00585 KStatefulBrush::KStatefulBrush(const QBrush &brush, KSharedConfigPtr config) 00586 { 00587 if (!config) 00588 config = KGlobal::config(); 00589 d = new KStatefulBrushPrivate[3]; 00590 d[0] = brush; 00591 d[1] = StateEffects(QPalette::Disabled, config).brush(brush); 00592 d[2] = StateEffects(QPalette::Inactive, config).brush(brush); 00593 } 00594 00595 KStatefulBrush::KStatefulBrush(const QBrush &brush, const QBrush &background, 00596 KSharedConfigPtr config) 00597 { 00598 if (!config) 00599 config = KGlobal::config(); 00600 d = new KStatefulBrushPrivate[3]; 00601 d[0] = brush; 00602 d[1] = StateEffects(QPalette::Disabled, config).brush(brush, background); 00603 d[2] = StateEffects(QPalette::Inactive, config).brush(brush, background); 00604 } 00605 00606 KStatefulBrush::KStatefulBrush(const KStatefulBrush &other) 00607 { 00608 d = new KStatefulBrushPrivate[3]; 00609 d[0] = other.d[0]; 00610 d[1] = other.d[1]; 00611 d[2] = other.d[2]; 00612 } 00613 00614 KStatefulBrush::~KStatefulBrush() 00615 { 00616 delete[] d; 00617 } 00618 00619 KStatefulBrush& KStatefulBrush::operator=(const KStatefulBrush &other) 00620 { 00621 d[0] = other.d[0]; 00622 d[1] = other.d[1]; 00623 d[2] = other.d[2]; 00624 return *this; 00625 } 00626 00627 QBrush KStatefulBrush::brush(QPalette::ColorGroup state) const 00628 { 00629 switch (state) { 00630 case QPalette::Inactive: 00631 return d[2]; 00632 case QPalette::Disabled: 00633 return d[1]; 00634 default: 00635 return d[0]; 00636 } 00637 } 00638 00639 QBrush KStatefulBrush::brush(const QPalette &pal) const 00640 { 00641 return brush(pal.currentColorGroup()); 00642 } 00643 00644 QBrush KStatefulBrush::brush(const QWidget *widget) const 00645 { 00646 if (widget) 00647 return brush(widget->palette()); 00648 else 00649 return QBrush(); 00650 } 00651 //END KStatefulBrush 00652 00653 // kate: space-indent on; indent-width 4; replace-tabs on; auto-insert-doxygen on;
KDE 4.6 API Reference