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
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
118 switch(style->styleType())
119 {
121 {
122 setLightColors();
123 break;
124 }
126 {
127 setDarkColors();
128 break;
129 }
131 {
132 m_imgColors->setSource(style->adaptiveColorSchemeSource());
133 break;
134 }
136 {
137 setTrueBlackColors();
138 break;
139 }
141 {
142 setTrueBlackColors(true);
143 break;
144 }
146 default:
147 {
148 setSystemPaletteColors();
149 break;
150 }
151 }
152 }
153
154 // const char *colorProperty = "KDE_COLOR_SCHEME_PATH";
155 void BasicThemeDefinition::setSystemPaletteColors()
156 {
157 auto palette = QGuiApplication::palette();
158
159 textColor = palette.color(QPalette::ColorRole::WindowText);
160 disabledTextColor = palette.color(QPalette::ColorRole::PlaceholderText);
161
162 highlightColor = palette.color(QPalette::ColorRole::Highlight);
163 highlightedTextColor = palette.color(QPalette::ColorRole::HighlightedText);
164
165 backgroundColor = palette.color(QPalette::ColorRole::Window);
166
167 ColorUtils cu;
168 const auto isDark = cu.brightnessForColor(backgroundColor) == ColorUtils::Dark;
169
170 activeBackgroundColor = highlightColor;
171 alternateBackgroundColor = isDark ? palette.color(QPalette::ColorRole::AlternateBase).lighter(104) : palette.color(QPalette::ColorRole::AlternateBase).darker(104);
172
173 hoverColor = palette.color(isDark ? QPalette::ColorRole::Midlight : QPalette::ColorRole::Mid);
174 focusColor = highlightColor;
175
176 activeTextColor = highlightColor;
177
178 buttonTextColor = palette.color(QPalette::ColorRole::ButtonText);
179 buttonBackgroundColor = palette.color(QPalette::ColorRole::Button);
180 buttonAlternateBackgroundColor = isDark ? buttonBackgroundColor.lighter(104) : buttonBackgroundColor.darker(104);
181 buttonHoverColor = palette.color(isDark ? QPalette::ColorRole::Midlight : QPalette::ColorRole::Mid);
182 buttonFocusColor = highlightColor;
183
184 viewTextColor = palette.color(QPalette::ColorRole::Text);
185 viewBackgroundColor = palette.color(QPalette::ColorRole::Base);
186 viewAlternateBackgroundColor = isDark ? viewBackgroundColor.lighter(104) : viewBackgroundColor.darker(104);
187 viewHoverColor = palette.color(isDark ? QPalette::ColorRole::Midlight : QPalette::ColorRole::Mid);
188 viewFocusColor = highlightColor;
189
190 selectionTextColor = palette.color(QPalette::ColorRole::HighlightedText);
191 selectionBackgroundColor = highlightColor;
192 selectionAlternateBackgroundColor = isDark ? highlightColor.lighter() : highlightColor.darker();
193 selectionHoverColor = isDark ? highlightColor.darker() : highlightColor.lighter();
194 selectionFocusColor = highlightColor;
195
196 bool useDefaultColors = true;
197// #ifndef Q_OS_ANDROID
198// if (qApp && qApp->property(colorProperty).isValid())
199// {
200// auto path = qApp->property(colorProperty).toString();
201// auto config = KSharedConfig::openConfig(path);
202//
203// auto active = KColorScheme(QPalette::Active, KColorScheme::Header, config);
204//
205// headerTextColor = active.foreground().color();
206// headerBackgroundColor = active.background().color();
207// headerAlternateBackgroundColor = active.background(KColorScheme::AlternateBackground).color();
208// headerHoverColor = active.decoration(KColorScheme::HoverColor).color();
209// headerFocusColor = active.decoration(KColorScheme::HoverColor).color();
210// useDefaultColors = false;
211// }
212// #endif
213
214 if(useDefaultColors)
215 {
216 headerTextColor = textColor;
217 headerBackgroundColor = palette.color(QPalette::ColorRole::Window);
218 headerAlternateBackgroundColor =palette.color(QPalette::ColorRole::AlternateBase);
219 headerHoverColor =palette.color(QPalette::ColorRole::Light);
220 headerFocusColor = highlightColor;
221 }
222
223
224 complementaryTextColor = palette.color(QPalette::ColorRole::BrightText);
225 complementaryBackgroundColor = palette.color(QPalette::ColorRole::Shadow);
226 complementaryAlternateBackgroundColor = palette.color(QPalette::ColorRole::Dark);
227 complementaryHoverColor = palette.color(QPalette::ColorRole::Mid);
228 complementaryFocusColor = highlightColor;
229
230 linkColor = palette.color(QPalette::ColorRole::Link);
231 linkBackgroundColor = palette.color(QPalette::ColorRole::Light);
232 visitedLinkColor = palette.color(QPalette::ColorRole::LinkVisited);
233 visitedLinkBackgroundColor = palette.color(QPalette::ColorRole::Light);
234
235 negativeTextColor = QColor{"#dac7cb"};
236 negativeBackgroundColor = QColor{"#DA4453"};
237 neutralTextColor = QColor{"#333"};
238 neutralBackgroundColor = QColor{"#F67400"};
239 positiveTextColor = QColor{"#333"};
240 positiveBackgroundColor = QColor{"#27AE60"};
241
242 tooltipTextColor = QColor{"#fafafa"};
243 tooltipBackgroundColor = QColor{"#333"};
244 tooltipAlternateBackgroundColor = tooltipBackgroundColor.darker();
245 tooltipHoverColor = QColor{"#000"};
246 tooltipFocusColor = QColor{"#000"};
247 }
248
249 void BasicThemeDefinition::setTrueBlackColors( bool inverted )
250 {
251 QColor color1{"#ffffff"};
252 QColor color2{"#000000"};
253
254 textColor = inverted ? color2 : color1;
255 disabledTextColor = textColor;
256
257 highlightColor = inverted ? color2 : color1;
258 highlightedTextColor = inverted ? color1 : color2;
259
260 backgroundColor = inverted ? color1 : color2;
261 activeBackgroundColor = highlightColor;
262 alternateBackgroundColor = backgroundColor;
263 hoverColor = backgroundColor;
264 focusColor = highlightColor;
265
266 activeTextColor = highlightColor;
267
268 buttonTextColor = textColor;
269 buttonBackgroundColor = backgroundColor;
270 buttonAlternateBackgroundColor = buttonBackgroundColor;
271 buttonHoverColor = buttonBackgroundColor;
272 buttonFocusColor = buttonBackgroundColor;
273
274 viewTextColor = textColor;
275 viewBackgroundColor = backgroundColor;
276 viewAlternateBackgroundColor = viewBackgroundColor;
277 viewHoverColor = viewBackgroundColor;
278 viewFocusColor = highlightColor;
279
280 selectionTextColor = highlightedTextColor;
281 selectionBackgroundColor = highlightColor;
282 selectionAlternateBackgroundColor = selectionBackgroundColor;
283 selectionHoverColor = selectionBackgroundColor;
284 selectionFocusColor = highlightColor;
285
286 complementaryTextColor = highlightedTextColor;
287 complementaryBackgroundColor = highlightColor;
288 complementaryAlternateBackgroundColor = complementaryBackgroundColor;
289 complementaryHoverColor = complementaryBackgroundColor;
290 complementaryFocusColor = highlightColor;
291
292 headerTextColor = textColor;
293 headerBackgroundColor = backgroundColor;
294 headerAlternateBackgroundColor = headerBackgroundColor;
295 headerHoverColor = headerBackgroundColor;
296 headerFocusColor = highlightColor;
297
298 linkColor = QColor{"#21b9ff"};
299 linkBackgroundColor = QColor{"#21b9ff"};
300 visitedLinkColor = QColor{"#ff17d4"};
301 visitedLinkBackgroundColor = QColor{"#ff17d4"};
302
303 negativeTextColor = QColor{"#DA4453"};
304 negativeBackgroundColor = backgroundColor;
305 neutralTextColor = QColor{"#F67400"};
306 neutralBackgroundColor = backgroundColor;
307 positiveTextColor = QColor{"#27AE60"};
308 positiveBackgroundColor = backgroundColor;
309
310 tooltipTextColor = textColor;
311 tooltipBackgroundColor = backgroundColor;
312 tooltipAlternateBackgroundColor = tooltipBackgroundColor;
313 tooltipHoverColor = tooltipBackgroundColor;
314 tooltipFocusColor = tooltipBackgroundColor;
315 }
316
317 void BasicThemeDefinition::setDarkColors()
318 {
319 ColorUtils cu;
320
321 textColor = DarkColor::textColor;
322 disabledTextColor = DarkColor::disabledTextColor;
323
324 highlightColor = Style::instance()->accentColor();
325 const auto isDark = cu.brightnessForColor(highlightColor) == ColorUtils::Dark;
326
327 highlightedTextColor = isDark ? QColor{"#eff0f1"} : QColor{"#232323"};
328
329 backgroundColor = cu.tintWithAlpha(DarkColor::backgroundColor, highlightColor, 0.02);
330 activeBackgroundColor = highlightColor;
331 alternateBackgroundColor = cu.tintWithAlpha(DarkColor::alternateBackgroundColor, highlightColor, 0.02);
332 hoverColor = cu.tintWithAlpha(DarkColor::hoverColor, highlightColor, 0.02);
333 focusColor = highlightColor;
334
335 activeTextColor = highlightColor;
336
337 buttonTextColor = textColor;
338 buttonBackgroundColor = cu.tintWithAlpha(DarkColor::buttonBackgroundColor, highlightColor, 0.02);
339 buttonAlternateBackgroundColor = cu.tintWithAlpha(DarkColor::buttonAlternateBackgroundColor, highlightColor, 0.02);
340 buttonHoverColor = cu.tintWithAlpha(DarkColor::buttonHoverColor, highlightColor, 0.02);
341 buttonFocusColor = highlightColor;
342
343 viewTextColor = textColor;
344 viewBackgroundColor = cu.tintWithAlpha(DarkColor::viewBackgroundColor, highlightColor, 0.02);
345 viewAlternateBackgroundColor = cu.tintWithAlpha(DarkColor::viewAlternateBackgroundColor, highlightColor, 0.02);
346 viewHoverColor = cu.tintWithAlpha(DarkColor::viewHoverColor, highlightColor, 0.02);
347 viewFocusColor = highlightColor;
348
349 selectionTextColor = QColor{"#fcfcfc"};
350 selectionBackgroundColor = highlightColor;
351 selectionAlternateBackgroundColor = selectionBackgroundColor.darker();
352 selectionHoverColor = selectionBackgroundColor.lighter();
353 selectionFocusColor = highlightColor;
354
355 complementaryTextColor = QColor{"#eff0f1"};
356 complementaryBackgroundColor = cu.tintWithAlpha(QColor{"#31363b"}, highlightColor, 0.03);
357 complementaryAlternateBackgroundColor = complementaryBackgroundColor.darker();
358 complementaryHoverColor = complementaryBackgroundColor.lighter();
359 complementaryFocusColor = highlightColor;
360
361 headerTextColor = textColor;
362 headerBackgroundColor = cu.tintWithAlpha(DarkColor::headerBackgroundColor, highlightColor, 0.04);
363 headerAlternateBackgroundColor = cu.tintWithAlpha(DarkColor::headerAlternateBackgroundColor, highlightColor, 0.02);
364 headerHoverColor = DarkColor::hoverColor;
365 headerFocusColor = highlightColor;
366
367 linkColor = QColor{"#21b9ff"};
368 linkBackgroundColor = QColor{"#21b9ff"};
369 visitedLinkColor = QColor{"#ff17d4"};
370 visitedLinkBackgroundColor = QColor{"#ff17d4"};
371
372 negativeTextColor = QColor{"#dac7cb"};
373 negativeBackgroundColor = QColor{"#DA4453"};
374 neutralTextColor = QColor{"#333"};
375 neutralBackgroundColor = QColor{"#F67400"};
376 positiveTextColor = QColor{"#333"};
377 positiveBackgroundColor = QColor{"#27AE60"};
378
379 tooltipTextColor = QColor{"#fafafa"};
380 tooltipBackgroundColor = QColor{"#333"};
381 tooltipAlternateBackgroundColor = tooltipBackgroundColor.darker();
382 tooltipHoverColor = QColor{"#000"};
383 tooltipFocusColor = QColor{"#000"};
384 }
385
386 void BasicThemeDefinition::setLightColors()
387 {
388 ColorUtils cu;
389
390 textColor = LightColor::textColor;
391 disabledTextColor = LightColor::disabledTextColor;
392
393 highlightColor = Style::instance()->accentColor();
394 // backgroundColor = QColor{"#efefef"};
395 const auto isDark = cu.brightnessForColor(highlightColor) == ColorUtils::Dark;
396 highlightedTextColor = isDark ? QColor{"#eff0f1"} : QColor{"#232323"};
397
398 backgroundColor = cu.tintWithAlpha(LightColor::backgroundColor, highlightColor, 0.02);
399 activeBackgroundColor = highlightColor;
400 alternateBackgroundColor = cu.tintWithAlpha(LightColor::alternateBackgroundColor, highlightColor, 0.02);
401
402 hoverColor = LightColor::hoverColor;
403 focusColor = highlightColor;
404
405 activeTextColor = highlightColor;
406
407 buttonTextColor = textColor;
408 buttonBackgroundColor = cu.tintWithAlpha(LightColor::buttonBackgroundColor, highlightColor, 0.03);
409 buttonAlternateBackgroundColor = LightColor::buttonAlternateBackgroundColor;
410 buttonHoverColor = cu.tintWithAlpha(LightColor::buttonHoverColor, highlightColor, 0.02);
411 buttonFocusColor = highlightColor;
412
413 viewTextColor = QColor{"#333333"};
414 viewBackgroundColor = cu.tintWithAlpha(LightColor::viewBackgroundColor, highlightColor, 0.02);
415 viewAlternateBackgroundColor =cu.tintWithAlpha(LightColor::viewAlternateBackgroundColor, highlightColor, 0.02);
416 viewHoverColor = cu.tintWithAlpha(LightColor::viewHoverColor, highlightColor, 0.02);
417 viewFocusColor = highlightColor;
418
419 selectionTextColor = QColor{"#eff0f1"};
420 selectionBackgroundColor = highlightColor;
421 selectionAlternateBackgroundColor = selectionBackgroundColor.darker(120);
422 selectionHoverColor = selectionBackgroundColor.lighter(120);
423 selectionFocusColor = highlightColor;
424
425 complementaryTextColor = QColor{"#eff0f1"};
426 complementaryBackgroundColor = cu.tintWithAlpha(QColor{"#31363b"}, highlightColor, 0.03);
427 complementaryAlternateBackgroundColor = complementaryBackgroundColor.darker(120);
428 complementaryHoverColor = complementaryBackgroundColor.lighter(120);
429 complementaryFocusColor = highlightColor;
430
431 headerTextColor = textColor;
432 headerBackgroundColor = cu.tintWithAlpha(LightColor::headerBackgroundColor, highlightColor, 0.04);
433 headerAlternateBackgroundColor = cu.tintWithAlpha(LightColor::headerAlternateBackgroundColor, highlightColor, 0.02);
434 headerHoverColor = LightColor::hoverColor;
435 headerFocusColor = highlightColor;
436
437 linkColor = QColor{"#21b9ff"};
438 linkBackgroundColor = QColor{"#21b9ff"};
439 visitedLinkColor = QColor{"#ff17d4"};
440 visitedLinkBackgroundColor = QColor{"#ff17d4"};
441
442 negativeTextColor = QColor{"#dac7cb"};
443 negativeBackgroundColor = QColor{"#DA4453"};
444 neutralTextColor = QColor{"#333"};
445 neutralBackgroundColor = QColor{"#F67400"};
446 positiveTextColor = QColor{"#333"};
447 positiveBackgroundColor = QColor{"#27AE60"};
448
449 tooltipTextColor = QColor{"#fafafa"};
450 tooltipBackgroundColor = QColor{"#333"};
451 tooltipAlternateBackgroundColor = tooltipBackgroundColor.darker();
452 tooltipHoverColor = QColor{"#000"};
453 tooltipFocusColor = QColor{"#000"};
454 }
455
456 void BasicThemeDefinition::setAdaptiveColors()
457 {
458 ColorUtils cu;
459
460 textColor = m_imgColors->foreground();
461 disabledTextColor = textColor.lighter(120);
462
463 highlightColor = m_imgColors->highlight();
464
465 const auto isDark = m_imgColors->paletteBrightness() == ColorUtils::Dark;
466 const auto bgColor = cu.tintWithAlpha(isDark ? DarkColor::backgroundColor : LightColor::backgroundColor, m_imgColors->background(), 0.1);
467 const auto btnColor = cu.tintWithAlpha(isDark ? DarkColor::buttonBackgroundColor : LightColor::buttonBackgroundColor, highlightColor, 0.06);
468
469 highlightedTextColor = cu.brightnessForColor(highlightColor) == ColorUtils::Dark ? m_imgColors->closestToWhite() : m_imgColors->closestToBlack();
470// backgroundColor = cu.tintWithAlpha(m_imgColors->background(), bgColor, 0.8);
471 backgroundColor = cu.tintWithAlpha(bgColor, highlightColor, 0.03);
472 activeBackgroundColor = highlightColor;
473 alternateBackgroundColor = cu.tintWithAlpha(backgroundColor, highlightColor, 0.02);
474
475 hoverColor = cu.tintWithAlpha(isDark ? DarkColor::hoverColor : LightColor::hoverColor, highlightColor, 0.02);
476
477 focusColor = highlightColor;
478
479 activeTextColor = highlightColor;
480
481 buttonTextColor = textColor;
482 buttonBackgroundColor = btnColor;
483 buttonAlternateBackgroundColor = cu.tintWithAlpha(isDark ? DarkColor::buttonBackgroundColor : LightColor::buttonBackgroundColor, highlightColor, 0.03);
484 buttonHoverColor = cu.tintWithAlpha(isDark ? DarkColor::buttonHoverColor : LightColor::buttonHoverColor, highlightColor, 0.03);
485 buttonFocusColor = highlightColor;
486
487 viewTextColor = textColor;
488 viewBackgroundColor = cu.tintWithAlpha(isDark ? DarkColor::viewBackgroundColor : LightColor::viewBackgroundColor, highlightColor, 0.07);
489 viewAlternateBackgroundColor = cu.tintWithAlpha(isDark ? DarkColor::viewAlternateBackgroundColor : LightColor::viewAlternateBackgroundColor, highlightColor, 0.03);
490 viewHoverColor = cu.tintWithAlpha(isDark ? DarkColor::viewHoverColor : LightColor::viewHoverColor, highlightColor, 0.03);
491 viewFocusColor = highlightColor;
492
493 selectionTextColor = QColor{"#fcfcfc"};
494 selectionBackgroundColor = highlightColor;
495 selectionAlternateBackgroundColor = selectionBackgroundColor.darker();
496 selectionHoverColor = selectionBackgroundColor.lighter();
497 selectionFocusColor = highlightColor;
498
499 complementaryTextColor = QColor{"#eff0f1"};
500 complementaryBackgroundColor = cu.tintWithAlpha(QColor{"#31363b"}, highlightColor, 0.03);
501 complementaryAlternateBackgroundColor = complementaryBackgroundColor.darker();
502 complementaryHoverColor = complementaryBackgroundColor.lighter();
503 complementaryFocusColor = highlightColor;
504
505 headerTextColor = textColor;
506 headerBackgroundColor = cu.tintWithAlpha(bgColor, highlightColor, 0.05);
507 headerAlternateBackgroundColor = headerBackgroundColor.darker();
508 headerAlternateBackgroundColor = cu.tintWithAlpha(bgColor, highlightColor, 0.02);
509
510 headerHoverColor = headerBackgroundColor.lighter();
511 headerFocusColor = highlightColor;
512
513 linkColor = QColor{"#2980B9"};
514 linkBackgroundColor = QColor{"#2980B9"};
515 visitedLinkColor = QColor{"#7F8C8D"};
516 visitedLinkBackgroundColor = QColor{"#2196F3"};
517
518 negativeTextColor = QColor{"#dac7cb"};
519 negativeBackgroundColor = QColor{"#DA4453"};
520 neutralTextColor = QColor{"#333"};
521 neutralBackgroundColor = QColor{"#F67400"};
522 positiveTextColor = QColor{"#333"};
523 positiveBackgroundColor = QColor{"#27AE60"};
524
525 tooltipTextColor = QColor{"#fafafa"};
526 tooltipBackgroundColor = QColor{"#333"};
527 tooltipAlternateBackgroundColor = tooltipBackgroundColor.darker();
528 tooltipHoverColor = QColor{"#000"};
529 tooltipFocusColor = QColor{"#000"};
530 }
531
532 void BasicThemeDefinition::syncToQml(PlatformTheme *object)
533 {
534 auto item = qobject_cast<QQuickItem *>(object->parent());
535 if (item && qmlAttachedPropertiesObject<PlatformTheme>(item, false) == object) {
536 Q_EMIT sync(item);
537 }
538 }
539
540 BasicThemeInstance::BasicThemeInstance(QObject *parent)
541 : QObject(parent)
542 {
543 }
544
545 BasicThemeDefinition &BasicThemeInstance::themeDefinition(QQmlEngine *engine)
546 {
547 if (m_themeDefinition) {
548 return *m_themeDefinition;
549 }
550
551 m_themeDefinition = std::make_unique<BasicThemeDefinition>();
552
553 connect(m_themeDefinition.get(), &BasicThemeDefinition::changed, this, &BasicThemeInstance::onDefinitionChanged);
554
555 return *m_themeDefinition;
556 }
557
558 void BasicThemeInstance::onDefinitionChanged()
559 {
560 for (auto watcher : std::as_const(watchers))
561 {
562 watcher->sync();
563 }
564 }
565
566 Q_GLOBAL_STATIC(BasicThemeInstance, basicThemeInstance)
567
568 BasicTheme::BasicTheme(QObject *parent)
569 : PlatformTheme(parent)
570 {
571 basicThemeInstance()->watchers.append(this);
572
573 sync();
574 }
575
576 BasicTheme::~BasicTheme()
577 {
578 basicThemeInstance()->watchers.removeOne(this);
579 }
580
581 void BasicTheme::sync()
582 {
583 auto &definition = basicThemeInstance()->themeDefinition(qmlEngine(parent()));
584
585 switch (colorSet()) {
586 case BasicTheme::Button:
587 setTextColor(tint(definition.buttonTextColor));
588 setBackgroundColor(tint(definition.buttonBackgroundColor));
589 setAlternateBackgroundColor(tint(definition.buttonAlternateBackgroundColor));
590 setHoverColor(tint(definition.buttonHoverColor));
591 setFocusColor(tint(definition.buttonFocusColor));
592 break;
593 case BasicTheme::View:
594 setTextColor(tint(definition.viewTextColor));
595 setBackgroundColor(tint(definition.viewBackgroundColor));
596 setAlternateBackgroundColor(tint(definition.viewAlternateBackgroundColor));
597 setHoverColor(tint(definition.viewHoverColor));
598 setFocusColor(tint(definition.viewFocusColor));
599 break;
600 case BasicTheme::Selection:
601 setTextColor(tint(definition.selectionTextColor));
602 setBackgroundColor(tint(definition.selectionBackgroundColor));
603 setAlternateBackgroundColor(tint(definition.selectionAlternateBackgroundColor));
604 setHoverColor(tint(definition.selectionHoverColor));
605 setFocusColor(tint(definition.selectionFocusColor));
606 break;
607 case BasicTheme::Tooltip:
608 setTextColor(tint(definition.tooltipTextColor));
609 setBackgroundColor(tint(definition.tooltipBackgroundColor));
610 setAlternateBackgroundColor(tint(definition.tooltipAlternateBackgroundColor));
611 setHoverColor(tint(definition.tooltipHoverColor));
612 setFocusColor(tint(definition.tooltipFocusColor));
613 break;
614 case BasicTheme::Complementary:
615 setTextColor(tint(definition.complementaryTextColor));
616 setBackgroundColor(tint(definition.complementaryBackgroundColor));
617 setAlternateBackgroundColor(tint(definition.complementaryAlternateBackgroundColor));
618 setHoverColor(tint(definition.complementaryHoverColor));
619 setFocusColor(tint(definition.complementaryFocusColor));
620 break;
621 case BasicTheme::Header:
622 setTextColor(tint(definition.headerTextColor));
623 setBackgroundColor(tint(definition.headerBackgroundColor));
624 setAlternateBackgroundColor(tint(definition.headerAlternateBackgroundColor));
625 setHoverColor(tint(definition.headerHoverColor));
626 setFocusColor(tint(definition.headerFocusColor));
627 break;
628 case BasicTheme::Window:
629 default:
630 setTextColor(tint(definition.textColor));
631 setBackgroundColor(tint(definition.backgroundColor));
632 setAlternateBackgroundColor(tint(definition.alternateBackgroundColor));
633 setHoverColor(tint(definition.hoverColor));
634 setFocusColor(tint(definition.focusColor));
635 break;
636 }
637
638 setDisabledTextColor(tint(definition.disabledTextColor));
639 setHighlightColor(tint(definition.highlightColor));
640 setHighlightedTextColor(tint(definition.highlightedTextColor));
641 setActiveTextColor(tint(definition.activeTextColor));
642 setActiveBackgroundColor(tint(definition.activeBackgroundColor));
643 setLinkColor(tint(definition.linkColor));
644 setLinkBackgroundColor(tint(definition.linkBackgroundColor));
645 setVisitedLinkColor(tint(definition.visitedLinkColor));
646 setVisitedLinkBackgroundColor(tint(definition.visitedLinkBackgroundColor));
647 setNegativeTextColor(tint(definition.negativeTextColor));
648 setNegativeBackgroundColor(tint(definition.negativeBackgroundColor));
649 setNeutralTextColor(tint(definition.neutralTextColor));
650 setNeutralBackgroundColor(tint(definition.neutralBackgroundColor));
651 setPositiveTextColor(tint(definition.positiveTextColor));
652 setPositiveBackgroundColor(tint(definition.positiveBackgroundColor));
653 }
654
655 bool BasicTheme::event(QEvent *event)
656 {
657 if (event->type() == PlatformThemeEvents::DataChangedEvent::type) {
658 sync();
659 }
660
661 if (event->type() == PlatformThemeEvents::ColorSetChangedEvent::type) {
662 sync();
663 }
664
665 if (event->type() == PlatformThemeEvents::ColorGroupChangedEvent::type) {
666 sync();
667 }
668
669 if (event->type() == PlatformThemeEvents::ColorChangedEvent::type) {
670 basicThemeInstance()->themeDefinition(qmlEngine(parent())).syncToQml(this);
671 }
672
673 if (event->type() == PlatformThemeEvents::FontChangedEvent::type) {
674 basicThemeInstance()->themeDefinition(qmlEngine(parent())).syncToQml(this);
675 }
676
677 return PlatformTheme::event(event);
678 }
679
680 QColor BasicTheme::tint(const QColor &color)
681 {
682 switch (colorGroup()) {
683 case PlatformTheme::Inactive:
684 return QColor::fromHsvF(color.hueF(), color.saturationF() * 0.5, color.valueF());
685 case PlatformTheme::Disabled:
686 return QColor::fromHsvF(color.hueF(), color.saturationF() * 0.5, color.valueF() * 0.8);
687 default:
688 return color;
689 }
690 }
691}
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 Jul 19 2024 12:00:22 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.