MauiKit Controls

basictheme.cpp
1/*
2 * SPDX-FileCopyrightText: 2017 by Marco Martin <mart@kde.org>
3 * SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
8#include "basictheme_p.h"
9
10#include <QFile>
11#include <QGuiApplication>
12#include <QPalette>
13
14#include "libs/style.h"
15#include "imagecolors.h"
16
17namespace Maui
18{
19 BasicThemeDefinition::BasicThemeDefinition(QObject *parent)
20 : QObject(parent)
21 ,m_imgColors(new ImageColors(this))
22 {
23
24 auto style = Style::instance();
25 connect(style, &Style::styleTypeChanged, [this, style](Style::StyleType type)
26 {
27 switch(type)
28 {
30 {
31 setLightColors();
32 break;
33 }
35 {
36 setDarkColors();
37 break;
38 }
40 {
41 setTrueBlackColors();
42 break;
43 }
45 {
46 setTrueBlackColors(true);
47 break;
48 }
50 {
51 m_imgColors->setSource(style->adaptiveColorSchemeSource());
52 break;
53 }
55 default:
56 {
57 setSystemPaletteColors();
58 break;
59 }
60 }
61
62 Q_EMIT this->changed();
63 });
64
65 connect(style, &Style::accentColorChanged, [this, style](QColor)
66 {
67 switch(style->styleType())
68 {
69 case Style::StyleType::Light:
70 {
71 setLightColors();
72 break;
73 }
75 {
76 setDarkColors();
77 break;
78 }
83 default:
84 {
85 break;
86 }
87 }
88
89 Q_EMIT this->changed();
90 });
91
92 connect(style, &Style::adaptiveColorSchemeSourceChanged, [this, style](QVariant source)
93 {
94 if(style->styleType() == Style::StyleType::Adaptive)
95 {
96 m_imgColors->setSource(source);
97 }
98 });
99
100 connect(m_imgColors, &ImageColors::paletteChanged, [this, style]()
101 {
102 if(style->styleType() == Style::StyleType::Adaptive)
103 {
104 setAdaptiveColors();
105 Q_EMIT this->changed();
106 }
107 });
108#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
109 connect(qGuiApp, &QGuiApplication::paletteChanged, [this, style](QPalette)
110 {
111 if(style->styleType() == Style::StyleType::Auto)
112 {
113 setSystemPaletteColors();
114 Q_EMIT this->changed();
115 }
116 });
117#else
118 connect(qGuiApp, &QGuiApplication::paletteChanged, [this, style](QPalette)
119 {
120 if(style->styleType() == Style::StyleType::Auto)
121 {
122 setSystemPaletteColors();
123 Q_EMIT this->changed();
124 }
125 });
126#endif
127 switch(style->styleType())
128 {
130 {
131 setLightColors();
132 break;
133 }
135 {
136 setDarkColors();
137 break;
138 }
140 {
141 m_imgColors->setSource(style->adaptiveColorSchemeSource());
142 break;
143 }
145 {
146 setTrueBlackColors();
147 break;
148 }
150 {
151 setTrueBlackColors(true);
152 break;
153 }
155 default:
156 {
157 setSystemPaletteColors();
158 break;
159 }
160 }
161 }
162
163 // const char *colorProperty = "KDE_COLOR_SCHEME_PATH";
164 void BasicThemeDefinition::setSystemPaletteColors()
165 {
166 auto palette = QGuiApplication::palette();
167
168 textColor = palette.color(QPalette::ColorRole::WindowText);
169 disabledTextColor = palette.color(QPalette::ColorRole::PlaceholderText);
170
171 highlightColor = palette.color(QPalette::ColorRole::Highlight);
172 highlightedTextColor = palette.color(QPalette::ColorRole::HighlightedText);
173
174 backgroundColor = palette.color(QPalette::ColorRole::Window);
175
176 ColorUtils cu;
177 const auto isDark = cu.brightnessForColor(backgroundColor) == ColorUtils::Dark;
178
179 activeBackgroundColor = highlightColor;
180 alternateBackgroundColor = isDark ? palette.color(QPalette::ColorRole::AlternateBase).lighter(104) : palette.color(QPalette::ColorRole::AlternateBase).darker(104);
181
182 hoverColor = palette.color(isDark ? QPalette::ColorRole::Midlight : QPalette::ColorRole::Mid);
183 focusColor = highlightColor;
184
185 activeTextColor = highlightColor;
186
187 buttonTextColor = palette.color(QPalette::ColorRole::ButtonText);
188 buttonBackgroundColor = palette.color(QPalette::ColorRole::Button);
189 buttonAlternateBackgroundColor = isDark ? buttonBackgroundColor.lighter(104) : buttonBackgroundColor.darker(104);
190 buttonHoverColor = palette.color(isDark ? QPalette::ColorRole::Midlight : QPalette::ColorRole::Mid);
191 buttonFocusColor = highlightColor;
192
193 viewTextColor = palette.color(QPalette::ColorRole::Text);
194 viewBackgroundColor = palette.color(QPalette::ColorRole::Base);
195 viewAlternateBackgroundColor = isDark ? viewBackgroundColor.lighter(104) : viewBackgroundColor.darker(104);
196 viewHoverColor = palette.color(isDark ? QPalette::ColorRole::Midlight : QPalette::ColorRole::Mid);
197 viewFocusColor = highlightColor;
198
199 selectionTextColor = palette.color(QPalette::ColorRole::HighlightedText);
200 selectionBackgroundColor = highlightColor;
201 selectionAlternateBackgroundColor = isDark ? highlightColor.lighter() : highlightColor.darker();
202 selectionHoverColor = isDark ? highlightColor.darker() : highlightColor.lighter();
203 selectionFocusColor = highlightColor;
204
205 bool useDefaultColors = true;
206// #ifndef Q_OS_ANDROID
207// if (qApp && qApp->property(colorProperty).isValid())
208// {
209// auto path = qApp->property(colorProperty).toString();
210// auto config = KSharedConfig::openConfig(path);
211//
212// auto active = KColorScheme(QPalette::Active, KColorScheme::Header, config);
213//
214// headerTextColor = active.foreground().color();
215// headerBackgroundColor = active.background().color();
216// headerAlternateBackgroundColor = active.background(KColorScheme::AlternateBackground).color();
217// headerHoverColor = active.decoration(KColorScheme::HoverColor).color();
218// headerFocusColor = active.decoration(KColorScheme::HoverColor).color();
219// useDefaultColors = false;
220// }
221// #endif
222
223 if(useDefaultColors)
224 {
225 headerTextColor = textColor;
226 headerBackgroundColor = palette.color(QPalette::ColorRole::Window);
227 headerAlternateBackgroundColor =palette.color(QPalette::ColorRole::AlternateBase);
228 headerHoverColor =palette.color(QPalette::ColorRole::Light);
229 headerFocusColor = highlightColor;
230 }
231
232
233 complementaryTextColor = palette.color(QPalette::ColorRole::BrightText);
234 complementaryBackgroundColor = palette.color(QPalette::ColorRole::Shadow);
235 complementaryAlternateBackgroundColor = palette.color(QPalette::ColorRole::Dark);
236 complementaryHoverColor = palette.color(QPalette::ColorRole::Mid);
237 complementaryFocusColor = highlightColor;
238
239 linkColor = palette.color(QPalette::ColorRole::Link);
240 linkBackgroundColor = palette.color(QPalette::ColorRole::Light);
241 visitedLinkColor = palette.color(QPalette::ColorRole::LinkVisited);
242 visitedLinkBackgroundColor = palette.color(QPalette::ColorRole::Light);
243
244 negativeTextColor = QColor{"#dac7cb"};
245 negativeBackgroundColor = QColor{"#DA4453"};
246 neutralTextColor = QColor{"#333"};
247 neutralBackgroundColor = QColor{"#F67400"};
248 positiveTextColor = QColor{"#333"};
249 positiveBackgroundColor = QColor{"#27AE60"};
250
251 tooltipTextColor = QColor{"#fafafa"};
252 tooltipBackgroundColor = QColor{"#333"};
253 tooltipAlternateBackgroundColor = tooltipBackgroundColor.darker();
254 tooltipHoverColor = QColor{"#000"};
255 tooltipFocusColor = QColor{"#000"};
256 }
257
258 void BasicThemeDefinition::setTrueBlackColors( bool inverted )
259 {
260 QColor color1{"#ffffff"};
261 QColor color2{"#000000"};
262
263 textColor = inverted ? color2 : color1;
264 disabledTextColor = textColor;
265
266 highlightColor = inverted ? color2 : color1;
267 highlightedTextColor = inverted ? color1 : color2;
268
269 backgroundColor = inverted ? color1 : color2;
270 activeBackgroundColor = highlightColor;
271 alternateBackgroundColor = backgroundColor;
272 hoverColor = backgroundColor;
273 focusColor = highlightColor;
274
275 activeTextColor = highlightColor;
276
277 buttonTextColor = textColor;
278 buttonBackgroundColor = backgroundColor;
279 buttonAlternateBackgroundColor = buttonBackgroundColor;
280 buttonHoverColor = buttonBackgroundColor;
281 buttonFocusColor = buttonBackgroundColor;
282
283 viewTextColor = textColor;
284 viewBackgroundColor = backgroundColor;
285 viewAlternateBackgroundColor = viewBackgroundColor;
286 viewHoverColor = viewBackgroundColor;
287 viewFocusColor = highlightColor;
288
289 selectionTextColor = highlightedTextColor;
290 selectionBackgroundColor = highlightColor;
291 selectionAlternateBackgroundColor = selectionBackgroundColor;
292 selectionHoverColor = selectionBackgroundColor;
293 selectionFocusColor = highlightColor;
294
295 complementaryTextColor = highlightedTextColor;
296 complementaryBackgroundColor = highlightColor;
297 complementaryAlternateBackgroundColor = complementaryBackgroundColor;
298 complementaryHoverColor = complementaryBackgroundColor;
299 complementaryFocusColor = highlightColor;
300
301 headerTextColor = textColor;
302 headerBackgroundColor = backgroundColor;
303 headerAlternateBackgroundColor = headerBackgroundColor;
304 headerHoverColor = headerBackgroundColor;
305 headerFocusColor = highlightColor;
306
307 linkColor = QColor{"#21b9ff"};
308 linkBackgroundColor = QColor{"#21b9ff"};
309 visitedLinkColor = QColor{"#ff17d4"};
310 visitedLinkBackgroundColor = QColor{"#ff17d4"};
311
312 negativeTextColor = QColor{"#DA4453"};
313 negativeBackgroundColor = backgroundColor;
314 neutralTextColor = QColor{"#F67400"};
315 neutralBackgroundColor = backgroundColor;
316 positiveTextColor = QColor{"#27AE60"};
317 positiveBackgroundColor = backgroundColor;
318
319 tooltipTextColor = textColor;
320 tooltipBackgroundColor = backgroundColor;
321 tooltipAlternateBackgroundColor = tooltipBackgroundColor;
322 tooltipHoverColor = tooltipBackgroundColor;
323 tooltipFocusColor = tooltipBackgroundColor;
324 }
325
326 void BasicThemeDefinition::setDarkColors()
327 {
328 ColorUtils cu;
329
330 textColor = DarkColor::textColor;
331 disabledTextColor = DarkColor::disabledTextColor;
332
333 highlightColor = Style::instance()->accentColor();
334 const auto isDark = cu.brightnessForColor(highlightColor) == ColorUtils::Dark;
335
336 highlightedTextColor = isDark ? QColor{"#eff0f1"} : QColor{"#232323"};
337
338 backgroundColor = cu.tintWithAlpha(DarkColor::backgroundColor, highlightColor, 0.02);
339 activeBackgroundColor = highlightColor;
340 alternateBackgroundColor = cu.tintWithAlpha(DarkColor::alternateBackgroundColor, highlightColor, 0.02);
341 hoverColor = cu.tintWithAlpha(DarkColor::hoverColor, highlightColor, 0.02);
342 focusColor = highlightColor;
343
344 activeTextColor = highlightColor;
345
346 buttonTextColor = textColor;
347 buttonBackgroundColor = cu.tintWithAlpha(DarkColor::buttonBackgroundColor, highlightColor, 0.02);
348 buttonAlternateBackgroundColor = cu.tintWithAlpha(DarkColor::buttonAlternateBackgroundColor, highlightColor, 0.02);
349 buttonHoverColor = cu.tintWithAlpha(DarkColor::buttonHoverColor, highlightColor, 0.02);
350 buttonFocusColor = highlightColor;
351
352 viewTextColor = textColor;
353 viewBackgroundColor = cu.tintWithAlpha(DarkColor::viewBackgroundColor, highlightColor, 0.02);
354 viewAlternateBackgroundColor = cu.tintWithAlpha(DarkColor::viewAlternateBackgroundColor, highlightColor, 0.02);
355 viewHoverColor = cu.tintWithAlpha(DarkColor::viewHoverColor, highlightColor, 0.02);
356 viewFocusColor = highlightColor;
357
358 selectionTextColor = QColor{"#fcfcfc"};
359 selectionBackgroundColor = highlightColor;
360 selectionAlternateBackgroundColor = selectionBackgroundColor.darker();
361 selectionHoverColor = selectionBackgroundColor.lighter();
362 selectionFocusColor = highlightColor;
363
364 complementaryTextColor = QColor{"#eff0f1"};
365 complementaryBackgroundColor = cu.tintWithAlpha(QColor{"#31363b"}, highlightColor, 0.03);
366 complementaryAlternateBackgroundColor = complementaryBackgroundColor.darker();
367 complementaryHoverColor = complementaryBackgroundColor.lighter();
368 complementaryFocusColor = highlightColor;
369
370 headerTextColor = textColor;
371 headerBackgroundColor = cu.tintWithAlpha(DarkColor::headerBackgroundColor, highlightColor, 0.04);
372 headerAlternateBackgroundColor = cu.tintWithAlpha(DarkColor::headerAlternateBackgroundColor, highlightColor, 0.02);
373 headerHoverColor = DarkColor::hoverColor;
374 headerFocusColor = highlightColor;
375
376 linkColor = QColor{"#21b9ff"};
377 linkBackgroundColor = QColor{"#21b9ff"};
378 visitedLinkColor = QColor{"#ff17d4"};
379 visitedLinkBackgroundColor = QColor{"#ff17d4"};
380
381 negativeTextColor = QColor{"#dac7cb"};
382 negativeBackgroundColor = QColor{"#DA4453"};
383 neutralTextColor = QColor{"#333"};
384 neutralBackgroundColor = QColor{"#F67400"};
385 positiveTextColor = QColor{"#333"};
386 positiveBackgroundColor = QColor{"#27AE60"};
387
388 tooltipTextColor = QColor{"#fafafa"};
389 tooltipBackgroundColor = QColor{"#333"};
390 tooltipAlternateBackgroundColor = tooltipBackgroundColor.darker();
391 tooltipHoverColor = QColor{"#000"};
392 tooltipFocusColor = QColor{"#000"};
393 }
394
395 void BasicThemeDefinition::setLightColors()
396 {
397 ColorUtils cu;
398
399 textColor = LightColor::textColor;
400 disabledTextColor = LightColor::disabledTextColor;
401
402 highlightColor = Style::instance()->accentColor();
403 // backgroundColor = QColor{"#efefef"};
404 const auto isDark = cu.brightnessForColor(highlightColor) == ColorUtils::Dark;
405 highlightedTextColor = isDark ? QColor{"#eff0f1"} : QColor{"#232323"};
406
407 backgroundColor = cu.tintWithAlpha(LightColor::backgroundColor, highlightColor, 0.02);
408 activeBackgroundColor = highlightColor;
409 alternateBackgroundColor = cu.tintWithAlpha(LightColor::alternateBackgroundColor, highlightColor, 0.02);
410 hoverColor = LightColor::hoverColor;
411 focusColor = highlightColor;
412
413 activeTextColor = highlightColor;
414
415 buttonTextColor = textColor;
416 buttonBackgroundColor = cu.tintWithAlpha(LightColor::buttonBackgroundColor, highlightColor, 0.03);
417 buttonAlternateBackgroundColor = LightColor::buttonAlternateBackgroundColor;
418 buttonHoverColor = cu.tintWithAlpha(LightColor::buttonHoverColor, highlightColor, 0.02);
419 buttonFocusColor = highlightColor;
420
421 viewTextColor = QColor{"#333333"};
422 viewBackgroundColor = cu.tintWithAlpha(LightColor::viewBackgroundColor, highlightColor, 0.02);
423 viewAlternateBackgroundColor =cu.tintWithAlpha(LightColor::viewAlternateBackgroundColor, highlightColor, 0.02);
424 viewHoverColor = cu.tintWithAlpha(LightColor::viewHoverColor, highlightColor, 0.02);
425 viewFocusColor = highlightColor;
426
427 selectionTextColor = QColor{"#eff0f1"};
428 selectionBackgroundColor = highlightColor;
429 selectionAlternateBackgroundColor = selectionBackgroundColor.darker(120);
430 selectionHoverColor = selectionBackgroundColor.lighter(120);
431 selectionFocusColor = highlightColor;
432
433 complementaryTextColor = QColor{"#eff0f1"};
434 complementaryBackgroundColor = cu.tintWithAlpha(QColor{"#31363b"}, highlightColor, 0.03);
435 complementaryAlternateBackgroundColor = complementaryBackgroundColor.darker(120);
436 complementaryHoverColor = complementaryBackgroundColor.lighter(120);
437 complementaryFocusColor = highlightColor;
438
439 headerTextColor = textColor;
440 headerBackgroundColor = cu.tintWithAlpha(LightColor::headerBackgroundColor, highlightColor, 0.04);
441 headerAlternateBackgroundColor = cu.tintWithAlpha(LightColor::headerAlternateBackgroundColor, highlightColor, 0.02);
442 headerHoverColor = LightColor::hoverColor;
443 headerFocusColor = highlightColor;
444
445 linkColor = QColor{"#21b9ff"};
446 linkBackgroundColor = QColor{"#21b9ff"};
447 visitedLinkColor = QColor{"#ff17d4"};
448 visitedLinkBackgroundColor = QColor{"#ff17d4"};
449
450 negativeTextColor = QColor{"#dac7cb"};
451 negativeBackgroundColor = QColor{"#DA4453"};
452 neutralTextColor = QColor{"#333"};
453 neutralBackgroundColor = QColor{"#F67400"};
454 positiveTextColor = QColor{"#333"};
455 positiveBackgroundColor = QColor{"#27AE60"};
456
457 tooltipTextColor = QColor{"#fafafa"};
458 tooltipBackgroundColor = QColor{"#333"};
459 tooltipAlternateBackgroundColor = tooltipBackgroundColor.darker();
460 tooltipHoverColor = QColor{"#000"};
461 tooltipFocusColor = QColor{"#000"};
462 }
463
464 void BasicThemeDefinition::setAdaptiveColors()
465 {
466 ColorUtils cu;
467
468 textColor = m_imgColors->foreground();
469 disabledTextColor = textColor.lighter(120);
470
471 highlightColor = m_imgColors->highlight();
472
473 const auto isDark = m_imgColors->paletteBrightness() == ColorUtils::Dark;
474 const auto bgColor = cu.tintWithAlpha(isDark ? DarkColor::backgroundColor : LightColor::backgroundColor, m_imgColors->background(), 0.1);
475 const auto btnColor = cu.tintWithAlpha(isDark ? DarkColor::buttonBackgroundColor : LightColor::buttonBackgroundColor, highlightColor, 0.06);
476
477 highlightedTextColor = cu.brightnessForColor(highlightColor) == ColorUtils::Dark ? m_imgColors->closestToWhite() : m_imgColors->closestToBlack();
478// backgroundColor = cu.tintWithAlpha(m_imgColors->background(), bgColor, 0.8);
479 backgroundColor = cu.tintWithAlpha(bgColor, highlightColor, 0.03);
480 activeBackgroundColor = highlightColor;
481 alternateBackgroundColor = cu.tintWithAlpha(isDark ? DarkColor::alternateBackgroundColor : LightColor::alternateBackgroundColor, highlightColor, 0.03);
482 hoverColor = cu.tintWithAlpha(isDark ? DarkColor::hoverColor : LightColor::hoverColor, highlightColor, 0.02);
483
484 focusColor = highlightColor;
485
486 activeTextColor = highlightColor;
487
488 buttonTextColor = textColor;
489 buttonBackgroundColor = btnColor;
490 buttonAlternateBackgroundColor = cu.tintWithAlpha(isDark ? DarkColor::buttonBackgroundColor : LightColor::buttonBackgroundColor, highlightColor, 0.03);
491 buttonHoverColor = cu.tintWithAlpha(isDark ? DarkColor::buttonHoverColor : LightColor::buttonHoverColor, highlightColor, 0.03);
492 buttonFocusColor = highlightColor;
493
494 viewTextColor = textColor;
495 viewBackgroundColor = cu.tintWithAlpha(isDark ? DarkColor::viewBackgroundColor : LightColor::viewBackgroundColor, highlightColor, 0.07);
496 viewAlternateBackgroundColor = cu.tintWithAlpha(isDark ? DarkColor::viewAlternateBackgroundColor : LightColor::viewAlternateBackgroundColor, highlightColor, 0.03);
497 viewHoverColor = cu.tintWithAlpha(isDark ? DarkColor::viewHoverColor : LightColor::viewHoverColor, highlightColor, 0.03);
498 viewFocusColor = highlightColor;
499
500 selectionTextColor = QColor{"#fcfcfc"};
501 selectionBackgroundColor = highlightColor;
502 selectionAlternateBackgroundColor = selectionBackgroundColor.darker();
503 selectionHoverColor = selectionBackgroundColor.lighter();
504 selectionFocusColor = highlightColor;
505
506 complementaryTextColor = QColor{"#eff0f1"};
507 complementaryBackgroundColor = cu.tintWithAlpha(QColor{"#31363b"}, highlightColor, 0.03);
508 complementaryAlternateBackgroundColor = complementaryBackgroundColor.darker();
509 complementaryHoverColor = complementaryBackgroundColor.lighter();
510 complementaryFocusColor = highlightColor;
511
512 headerTextColor = textColor;
513 headerBackgroundColor = cu.tintWithAlpha(bgColor, highlightColor, 0.05);
514 headerAlternateBackgroundColor = headerBackgroundColor.darker();
515 headerHoverColor = headerBackgroundColor.lighter();
516 headerFocusColor = highlightColor;
517
518 linkColor = QColor{"#2980B9"};
519 linkBackgroundColor = QColor{"#2980B9"};
520 visitedLinkColor = QColor{"#7F8C8D"};
521 visitedLinkBackgroundColor = QColor{"#2196F3"};
522
523 negativeTextColor = QColor{"#dac7cb"};
524 negativeBackgroundColor = QColor{"#DA4453"};
525 neutralTextColor = QColor{"#333"};
526 neutralBackgroundColor = QColor{"#F67400"};
527 positiveTextColor = QColor{"#333"};
528 positiveBackgroundColor = QColor{"#27AE60"};
529
530 tooltipTextColor = QColor{"#fafafa"};
531 tooltipBackgroundColor = QColor{"#333"};
532 tooltipAlternateBackgroundColor = tooltipBackgroundColor.darker();
533 tooltipHoverColor = QColor{"#000"};
534 tooltipFocusColor = QColor{"#000"};
535 }
536
537 void BasicThemeDefinition::syncToQml(PlatformTheme *object)
538 {
539 auto item = qobject_cast<QQuickItem *>(object->parent());
540 if (item && qmlAttachedPropertiesObject<PlatformTheme>(item, false) == object) {
541 Q_EMIT sync(item);
542 }
543 }
544
545 BasicThemeInstance::BasicThemeInstance(QObject *parent)
546 : QObject(parent)
547 {
548 }
549
550 BasicThemeDefinition &BasicThemeInstance::themeDefinition(QQmlEngine *engine)
551 {
552 if (m_themeDefinition) {
553 return *m_themeDefinition;
554 }
555
556 m_themeDefinition = std::make_unique<BasicThemeDefinition>();
557
558 connect(m_themeDefinition.get(), &BasicThemeDefinition::changed, this, &BasicThemeInstance::onDefinitionChanged);
559
560 return *m_themeDefinition;
561 }
562
563 void BasicThemeInstance::onDefinitionChanged()
564 {
565 for (auto watcher : std::as_const(watchers))
566 {
567 watcher->sync();
568 }
569 }
570
571 Q_GLOBAL_STATIC(BasicThemeInstance, basicThemeInstance)
572
573 BasicTheme::BasicTheme(QObject *parent)
574 : PlatformTheme(parent)
575 {
576 basicThemeInstance()->watchers.append(this);
577
578 sync();
579 }
580
581 BasicTheme::~BasicTheme()
582 {
583 basicThemeInstance()->watchers.removeOne(this);
584 }
585
586 void BasicTheme::sync()
587 {
588 auto &definition = basicThemeInstance()->themeDefinition(qmlEngine(parent()));
589
590 switch (colorSet()) {
591 case BasicTheme::Button:
592 setTextColor(tint(definition.buttonTextColor));
593 setBackgroundColor(tint(definition.buttonBackgroundColor));
594 setAlternateBackgroundColor(tint(definition.buttonAlternateBackgroundColor));
595 setHoverColor(tint(definition.buttonHoverColor));
596 setFocusColor(tint(definition.buttonFocusColor));
597 break;
598 case BasicTheme::View:
599 setTextColor(tint(definition.viewTextColor));
600 setBackgroundColor(tint(definition.viewBackgroundColor));
601 setAlternateBackgroundColor(tint(definition.viewAlternateBackgroundColor));
602 setHoverColor(tint(definition.viewHoverColor));
603 setFocusColor(tint(definition.viewFocusColor));
604 break;
605 case BasicTheme::Selection:
606 setTextColor(tint(definition.selectionTextColor));
607 setBackgroundColor(tint(definition.selectionBackgroundColor));
608 setAlternateBackgroundColor(tint(definition.selectionAlternateBackgroundColor));
609 setHoverColor(tint(definition.selectionHoverColor));
610 setFocusColor(tint(definition.selectionFocusColor));
611 break;
612 case BasicTheme::Tooltip:
613 setTextColor(tint(definition.tooltipTextColor));
614 setBackgroundColor(tint(definition.tooltipBackgroundColor));
615 setAlternateBackgroundColor(tint(definition.tooltipAlternateBackgroundColor));
616 setHoverColor(tint(definition.tooltipHoverColor));
617 setFocusColor(tint(definition.tooltipFocusColor));
618 break;
619 case BasicTheme::Complementary:
620 setTextColor(tint(definition.complementaryTextColor));
621 setBackgroundColor(tint(definition.complementaryBackgroundColor));
622 setAlternateBackgroundColor(tint(definition.complementaryAlternateBackgroundColor));
623 setHoverColor(tint(definition.complementaryHoverColor));
624 setFocusColor(tint(definition.complementaryFocusColor));
625 break;
626 case BasicTheme::Header:
627 setTextColor(tint(definition.headerTextColor));
628 setBackgroundColor(tint(definition.headerBackgroundColor));
629 setAlternateBackgroundColor(tint(definition.headerAlternateBackgroundColor));
630 setHoverColor(tint(definition.headerHoverColor));
631 setFocusColor(tint(definition.headerFocusColor));
632 break;
633 case BasicTheme::Window:
634 default:
635 setTextColor(tint(definition.textColor));
636 setBackgroundColor(tint(definition.backgroundColor));
637 setAlternateBackgroundColor(tint(definition.alternateBackgroundColor));
638 setHoverColor(tint(definition.hoverColor));
639 setFocusColor(tint(definition.focusColor));
640 break;
641 }
642
643 setDisabledTextColor(tint(definition.disabledTextColor));
644 setHighlightColor(tint(definition.highlightColor));
645 setHighlightedTextColor(tint(definition.highlightedTextColor));
646 setActiveTextColor(tint(definition.activeTextColor));
647 setActiveBackgroundColor(tint(definition.activeBackgroundColor));
648 setLinkColor(tint(definition.linkColor));
649 setLinkBackgroundColor(tint(definition.linkBackgroundColor));
650 setVisitedLinkColor(tint(definition.visitedLinkColor));
651 setVisitedLinkBackgroundColor(tint(definition.visitedLinkBackgroundColor));
652 setNegativeTextColor(tint(definition.negativeTextColor));
653 setNegativeBackgroundColor(tint(definition.negativeBackgroundColor));
654 setNeutralTextColor(tint(definition.neutralTextColor));
655 setNeutralBackgroundColor(tint(definition.neutralBackgroundColor));
656 setPositiveTextColor(tint(definition.positiveTextColor));
657 setPositiveBackgroundColor(tint(definition.positiveBackgroundColor));
658 }
659
660 bool BasicTheme::event(QEvent *event)
661 {
662 if (event->type() == PlatformThemeEvents::DataChangedEvent::type) {
663 sync();
664 }
665
666 if (event->type() == PlatformThemeEvents::ColorSetChangedEvent::type) {
667 sync();
668 }
669
670 if (event->type() == PlatformThemeEvents::ColorGroupChangedEvent::type) {
671 sync();
672 }
673
674 if (event->type() == PlatformThemeEvents::ColorChangedEvent::type) {
675 basicThemeInstance()->themeDefinition(qmlEngine(parent())).syncToQml(this);
676 }
677
678 if (event->type() == PlatformThemeEvents::FontChangedEvent::type) {
679 basicThemeInstance()->themeDefinition(qmlEngine(parent())).syncToQml(this);
680 }
681
682 return PlatformTheme::event(event);
683 }
684
685 QColor BasicTheme::tint(const QColor &color)
686 {
687 switch (colorGroup()) {
688 case PlatformTheme::Inactive:
689 return QColor::fromHsvF(color.hueF(), color.saturationF() * 0.5, color.valueF());
690 case PlatformTheme::Disabled:
691 return QColor::fromHsvF(color.hueF(), color.saturationF() * 0.5, color.valueF() * 0.8);
692 default:
693 return color;
694 }
695 }
696}
Q_INVOKABLE QColor tintWithAlpha(const QColor &targetColor, const QColor &tintColor, double alpha)
Q_INVOKABLE ColorUtils::Brightness brightnessForColor(const QColor &color)
StyleType
The different options for the color scheme style.
Definition style.h:270
@ TrueBlack
A fully black color palette with a full white accent color.
Definition style.h:295
@ Inverted
A fully white color palette with a true black accent color.
Definition style.h:300
@ Light
A light variant designed for Maui.
Definition style.h:274
@ Dark
A dark variant designed for Maui.
Definition style.h:279
@ Auto
Picks the colors from the system palette, usually from Plasma color-scheme files.
Definition style.h:290
@ Adaptive
Picks the color scheme based on an source input, such as an image.
Definition style.h:284
QColor accentColor
Sets the color to be used for highlighted, active, checked and such states of the UI elements.
Definition style.h:204
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
KGUIADDONS_EXPORT QColor tint(const QColor &base, const QColor &color, qreal amount=0.3)
QColor darker(int factor) const const
QColor fromHsvF(float h, float s, float v, float a)
float hueF() const const
QColor lighter(int factor) const const
float saturationF() const const
float valueF() const const
void paletteChanged(const QPalette &palette)
QPalette palette()
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.