Changeset View
Changeset View
Standalone View
Standalone View
src/kcolorscheme.cpp
Show First 20 Lines • Show All 274 Lines • ▼ Show 20 Line(s) | |||||
275 | //BEGIN KColorSchemePrivate | 275 | //BEGIN KColorSchemePrivate | ||
276 | class KColorSchemePrivate : public QSharedData | 276 | class KColorSchemePrivate : public QSharedData | ||
277 | { | 277 | { | ||
278 | public: | 278 | public: | ||
279 | explicit KColorSchemePrivate(const KSharedConfigPtr &, QPalette::ColorGroup, const char *, const SetDefaultColors &); | 279 | explicit KColorSchemePrivate(const KSharedConfigPtr &, QPalette::ColorGroup, const char *, const SetDefaultColors &); | ||
280 | explicit KColorSchemePrivate(const KSharedConfigPtr &, QPalette::ColorGroup, const char *, const SetDefaultColors &, const QBrush &); | 280 | explicit KColorSchemePrivate(const KSharedConfigPtr &, QPalette::ColorGroup, const char *, const SetDefaultColors &, const QBrush &); | ||
281 | ~KColorSchemePrivate() {} | 281 | ~KColorSchemePrivate() {} | ||
282 | 282 | | |||
283 | void loadAccentIntoBackground(const KSharedConfigPtr &, const char *, const SetDefaultColors &); | ||||
284 | void dropAccentColors(const KSharedConfigPtr &, const char *, const SetDefaultColors &); | ||||
285 | | ||||
283 | QBrush background(KColorScheme::BackgroundRole) const; | 286 | QBrush background(KColorScheme::BackgroundRole) const; | ||
284 | QBrush foreground(KColorScheme::ForegroundRole) const; | 287 | QBrush foreground(KColorScheme::ForegroundRole) const; | ||
285 | QBrush decoration(KColorScheme::DecorationRole) const; | 288 | QBrush decoration(KColorScheme::DecorationRole) const; | ||
286 | qreal contrast() const; | 289 | qreal contrast() const; | ||
287 | private: | 290 | private: | ||
288 | struct { | 291 | struct { | ||
289 | QBrush fg[KColorScheme::NForegroundRoles]; | 292 | QBrush fg[KColorScheme::NForegroundRoles]; | ||
290 | QBrush bg[KColorScheme::NBackgroundRoles]; | 293 | QBrush bg[KColorScheme::NBackgroundRoles]; | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 335 | _brushes.bg[KColorScheme::NormalBackground] = | |||
333 | KColorUtils::tint(_brushes.bg[KColorScheme::NormalBackground].color(), tint.color(), 0.4); | 336 | KColorUtils::tint(_brushes.bg[KColorScheme::NormalBackground].color(), tint.color(), 0.4); | ||
334 | _brushes.bg[KColorScheme::AlternateBackground] = | 337 | _brushes.bg[KColorScheme::AlternateBackground] = | ||
335 | KColorUtils::tint(_brushes.bg[KColorScheme::AlternateBackground].color(), tint.color(), 0.4); | 338 | KColorUtils::tint(_brushes.bg[KColorScheme::AlternateBackground].color(), tint.color(), 0.4); | ||
336 | 339 | | |||
337 | // the rest | 340 | // the rest | ||
338 | init(config, state, group, defaults); | 341 | init(config, state, group, defaults); | ||
339 | } | 342 | } | ||
340 | 343 | | |||
344 | void KColorSchemePrivate::loadAccentIntoBackground(const KSharedConfigPtr &config, | ||||
345 | const char *group, | ||||
346 | const SetDefaultColors &defaults) | ||||
347 | { | ||||
348 | KConfigGroup cfg(config, group); | ||||
349 | KConfigGroup accent(KSharedConfig::openConfig(), "Accent"); | ||||
350 | | ||||
351 | _brushes.bg[KColorScheme::NormalBackground] = accent.readEntry("Background", cfg.readEntry("BackgroundNormal", SET_DEFAULT(NormalBackground))); | ||||
352 | _brushes.bg[KColorScheme::AlternateBackground] = accent.readEntry("Background", cfg.readEntry("BackgroundAlternate", SET_DEFAULT(AlternateBackground))); | ||||
353 | } | ||||
354 | | ||||
355 | void KColorSchemePrivate::dropAccentColors(const KSharedConfigPtr &config, | ||||
356 | const char *group, | ||||
357 | const SetDefaultColors &defaults) | ||||
358 | { | ||||
359 | KConfigGroup cfg(config, group); | ||||
360 | | ||||
361 | _brushes.fg[KColorScheme::ActiveText] = cfg.readEntry("ForegroundActive", SET_DEFAULT(ActiveText)); | ||||
362 | _brushes.fg[KColorScheme::LinkText] = cfg.readEntry("ForegroundLink", SET_DEFAULT(LinkText)); | ||||
363 | | ||||
364 | _brushes.deco[KColorScheme::FocusColor] = cfg.readEntry("DecorationFocus", DECO_DEFAULT(Focus)); | ||||
365 | _brushes.deco[KColorScheme::HoverColor] = cfg.readEntry("DecorationHover", DECO_DEFAULT(Hover)); | ||||
366 | | ||||
367 | _brushes.bg[KColorScheme::NormalBackground] = cfg.readEntry("BackgroundNormal", SET_DEFAULT(NormalBackground)); | ||||
368 | _brushes.bg[KColorScheme::AlternateBackground] = cfg.readEntry("BackgroundAlternate", SET_DEFAULT(AlternateBackground)); | ||||
369 | } | ||||
370 | | ||||
341 | void KColorSchemePrivate::init(const KSharedConfigPtr &config, | 371 | void KColorSchemePrivate::init(const KSharedConfigPtr &config, | ||
342 | QPalette::ColorGroup state, | 372 | QPalette::ColorGroup state, | ||
343 | const char *group, | 373 | const char *group, | ||
344 | const SetDefaultColors &defaults) | 374 | const SetDefaultColors &defaults) | ||
345 | { | 375 | { | ||
346 | KConfigGroup cfg(config, group); | 376 | KConfigGroup cfg(config, group); | ||
377 | KConfigGroup accent(KSharedConfig::openConfig(), "Accent"); | ||||
347 | 378 | | |||
348 | // loaded-from-config colors | 379 | // loaded-from-config colors | ||
349 | _brushes.fg[KColorScheme::NormalText] = cfg.readEntry("ForegroundNormal", SET_DEFAULT(NormalText)); | 380 | _brushes.fg[KColorScheme::NormalText] = cfg.readEntry("ForegroundNormal", SET_DEFAULT(NormalText)); | ||
350 | _brushes.fg[KColorScheme::InactiveText] = cfg.readEntry("ForegroundInactive", SET_DEFAULT(InactiveText)); | 381 | _brushes.fg[KColorScheme::InactiveText] = cfg.readEntry("ForegroundInactive", SET_DEFAULT(InactiveText)); | ||
351 | _brushes.fg[KColorScheme::ActiveText] = cfg.readEntry("ForegroundActive", SET_DEFAULT(ActiveText)); | 382 | _brushes.fg[KColorScheme::ActiveText] = accent.readEntry("Foreground", cfg.readEntry("ForegroundActive", SET_DEFAULT(ActiveText))); | ||
352 | _brushes.fg[KColorScheme::LinkText] = cfg.readEntry("ForegroundLink", SET_DEFAULT(LinkText)); | 383 | _brushes.fg[KColorScheme::LinkText] = accent.readEntry("Foreground", cfg.readEntry("ForegroundLink", SET_DEFAULT(LinkText))); | ||
353 | _brushes.fg[KColorScheme::VisitedText] = cfg.readEntry("ForegroundVisited", SET_DEFAULT(VisitedText)); | 384 | _brushes.fg[KColorScheme::VisitedText] = cfg.readEntry("ForegroundVisited", SET_DEFAULT(VisitedText)); | ||
354 | _brushes.fg[KColorScheme::NegativeText] = cfg.readEntry("ForegroundNegative", SET_DEFAULT(NegativeText)); | 385 | _brushes.fg[KColorScheme::NegativeText] = cfg.readEntry("ForegroundNegative", SET_DEFAULT(NegativeText)); | ||
355 | _brushes.fg[KColorScheme::NeutralText] = cfg.readEntry("ForegroundNeutral", SET_DEFAULT(NeutralText)); | 386 | _brushes.fg[KColorScheme::NeutralText] = cfg.readEntry("ForegroundNeutral", SET_DEFAULT(NeutralText)); | ||
356 | _brushes.fg[KColorScheme::PositiveText] = cfg.readEntry("ForegroundPositive", SET_DEFAULT(PositiveText)); | 387 | _brushes.fg[KColorScheme::PositiveText] = cfg.readEntry("ForegroundPositive", SET_DEFAULT(PositiveText)); | ||
357 | 388 | | |||
358 | _brushes.deco[KColorScheme::FocusColor] = cfg.readEntry("DecorationFocus", DECO_DEFAULT(Focus)); | 389 | _brushes.deco[KColorScheme::FocusColor] = accent.readEntry("Foreground", cfg.readEntry("DecorationFocus", DECO_DEFAULT(Focus))); | ||
359 | _brushes.deco[KColorScheme::HoverColor] = cfg.readEntry("DecorationHover", DECO_DEFAULT(Hover)); | 390 | _brushes.deco[KColorScheme::HoverColor] = accent.readEntry("AccForegroundent", cfg.readEntry("DecorationHover", DECO_DEFAULT(Hover))); | ||
360 | 391 | | |||
361 | // apply state adjustments | 392 | // apply state adjustments | ||
362 | if (state != QPalette::Active) { | 393 | if (state != QPalette::Active) { | ||
363 | StateEffects effects(state, config); | 394 | StateEffects effects(state, config); | ||
364 | for (auto &fg : _brushes.fg) { | 395 | for (auto &fg : _brushes.fg) { | ||
365 | fg = effects.brush(fg, _brushes.bg[KColorScheme::NormalBackground]); | 396 | fg = effects.brush(fg, _brushes.bg[KColorScheme::NormalBackground]); | ||
366 | } | 397 | } | ||
367 | for (auto &deco : _brushes.deco) { | 398 | for (auto &deco : _brushes.deco) { | ||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | 475 | { | |||
456 | case Selection: { | 487 | case Selection: { | ||
457 | KConfigGroup group(config, "ColorEffects:Inactive"); | 488 | KConfigGroup group(config, "ColorEffects:Inactive"); | ||
458 | // NOTE: keep this in sync with kdebase/workspace/kcontrol/colors/colorscm.cpp | 489 | // NOTE: keep this in sync with kdebase/workspace/kcontrol/colors/colorscm.cpp | ||
459 | bool inactiveSelectionEffect = group.readEntry("ChangeSelectionColor", group.readEntry("Enable", true)); | 490 | bool inactiveSelectionEffect = group.readEntry("ChangeSelectionColor", group.readEntry("Enable", true)); | ||
460 | // if enabled, inactiver/disabled uses Window colors instead, ala gtk | 491 | // if enabled, inactiver/disabled uses Window colors instead, ala gtk | ||
461 | // ...except tinted with the Selection:NormalBackground color so it looks more like selection | 492 | // ...except tinted with the Selection:NormalBackground color so it looks more like selection | ||
462 | if (state == QPalette::Active || (state == QPalette::Inactive && !inactiveSelectionEffect)) { | 493 | if (state == QPalette::Active || (state == QPalette::Inactive && !inactiveSelectionEffect)) { | ||
463 | d = new KColorSchemePrivate(config, state, "Colors:Selection", defaultSelectionColors); | 494 | d = new KColorSchemePrivate(config, state, "Colors:Selection", defaultSelectionColors); | ||
464 | } else if (state == QPalette::Inactive) | 495 | d.data()->loadAccentIntoBackground(config, "Colors:Selection", defaultSelectionColors); | ||
496 | } else if (state == QPalette::Inactive) { | ||||
465 | d = new KColorSchemePrivate(config, state, "Colors:Window", defaultWindowColors, | 497 | d = new KColorSchemePrivate(config, state, "Colors:Window", defaultWindowColors, | ||
466 | KColorScheme(QPalette::Active, Selection, config).background()); | 498 | KColorScheme(QPalette::Active, Selection, config).background()); | ||
467 | else { // disabled (...and still want this branch when inactive+disabled exists) | 499 | d.data()->loadAccentIntoBackground(config, "Colors:Window", defaultWindowColors); | ||
500 | } else { // disabled (...and still want this branch when inactive+disabled exists) | ||||
468 | d = new KColorSchemePrivate(config, state, "Colors:Window", defaultWindowColors); | 501 | d = new KColorSchemePrivate(config, state, "Colors:Window", defaultWindowColors); | ||
502 | d.data()->loadAccentIntoBackground(config, "Colors:Window", defaultWindowColors); | ||||
469 | } | 503 | } | ||
470 | } break; | 504 | } break; | ||
471 | case Tooltip: | 505 | case Tooltip: | ||
472 | d = new KColorSchemePrivate(config, state, "Colors:Tooltip", defaultTooltipColors); | 506 | d = new KColorSchemePrivate(config, state, "Colors:Tooltip", defaultTooltipColors); | ||
473 | break; | 507 | break; | ||
474 | case Complementary: | 508 | case Complementary: | ||
475 | d = new KColorSchemePrivate(config, state, "Colors:Complementary", defaultComplementaryColors); | 509 | d = new KColorSchemePrivate(config, state, "Colors:Complementary", defaultComplementaryColors); | ||
476 | break; | 510 | break; | ||
477 | default: | 511 | default: | ||
478 | d = new KColorSchemePrivate(config, state, "Colors:View", defaultViewColors); | 512 | d = new KColorSchemePrivate(config, state, "Colors:View", defaultViewColors); | ||
479 | } | 513 | } | ||
480 | } | 514 | } | ||
481 | 515 | | |||
516 | void KColorScheme::dropAccentColors(QPalette::ColorGroup state, ColorSet set, KSharedConfigPtr config) | ||||
517 | { | ||||
518 | if (!config) { | ||||
519 | config = defaultConfig(); | ||||
520 | } | ||||
521 | | ||||
522 | switch (set) { | ||||
523 | case Window: | ||||
524 | d.data()->dropAccentColors(config, "Colors:Window", defaultWindowColors); | ||||
525 | break; | ||||
526 | case Button: | ||||
527 | d.data()->dropAccentColors(config, "Colors:Button", defaultWindowColors); | ||||
528 | break; | ||||
529 | case Selection: { | ||||
530 | KConfigGroup group(config, "ColorEffects:Inactive"); | ||||
531 | bool inactiveSelectionEffect = group.readEntry("ChangeSelectionColor", group.readEntry("Enable", true)); | ||||
532 | | ||||
533 | if (state == QPalette::Active || (state == QPalette::Inactive && !inactiveSelectionEffect)) { | ||||
534 | d.data()->dropAccentColors(config, "Colors:Window", defaultWindowColors); | ||||
535 | } else if (state == QPalette::Inactive) { | ||||
536 | d.data()->dropAccentColors(config, "Colors:Window", defaultWindowColors); | ||||
537 | } else { | ||||
538 | d.data()->dropAccentColors(config, "Colors:Window", defaultWindowColors); | ||||
539 | } | ||||
540 | } break; | ||||
541 | case Tooltip: | ||||
542 | d.data()->dropAccentColors(config, "Colors:Tooltip", defaultTooltipColors); | ||||
543 | break; | ||||
544 | case Complementary: | ||||
545 | d.data()->dropAccentColors(config, "Colors:Complementary", defaultComplementaryColors); | ||||
546 | break; | ||||
547 | default: | ||||
548 | d.data()->dropAccentColors(config, "Colors:View", defaultViewColors); | ||||
549 | } | ||||
550 | } | ||||
551 | | ||||
482 | // static | 552 | // static | ||
483 | int KColorScheme::contrast() | 553 | int KColorScheme::contrast() | ||
484 | { | 554 | { | ||
485 | KConfigGroup g(KSharedConfig::openConfig(), "KDE"); | 555 | KConfigGroup g(KSharedConfig::openConfig(), "KDE"); | ||
486 | return g.readEntry("contrast", 7); | 556 | return g.readEntry("contrast", 7); | ||
487 | } | 557 | } | ||
488 | 558 | | |||
489 | // static | 559 | // static | ||
▲ Show 20 Lines • Show All 252 Lines • Show Last 20 Lines |