4#include "private/qohosplatformtheme_p.h"
11#include <QtCore/private/qcore_ohos_p.h>
12#include <QtCore/private/qohoscommon_p.h>
13#include <QtCore/private/qohoslogger_p.h>
14#include <QtGui/private/qguiapplication_p.h>
15#include <QtGui/private/qhighdpiscaling_p.h>
16#include <QtGui/private/qabstractfileiconengine_p.h>
17#include <initializer_list>
19#include <qohosjsmain.h>
20#include <qohosjsutils.h>
21#include <qohosqpaenums.h>
22#include <qohosutils.h>
23#include <qpa/qplatformfontdatabase.h>
24#include <qpa/qplatformintegration.h>
34 auto disabledColor = color;
35 disabledColor.setAlphaF(qBound(0.0, color.alphaF() * 0.4, 1.0));
42 const auto alpha = overlay.alphaF();
44 return QColor::fromRgbF(
45 overlay.redF() * alpha + surface.redF() * (1.0 - alpha),
46 overlay.greenF() * alpha + surface.greenF() * (1.0 - alpha),
47 overlay.blueF() * alpha + surface.blueF() * (1.0 - alpha));
78 const auto activeWindow = QColor(
"#FFFFFFFF");
79 const auto activeButtonText = QColor(
"#0A59F7");
80 const auto textPrimary = QColor(
"#FF182431");
83 .activeWindow = activeWindow,
84 .inactiveWindow = makeInactiveOrDisabledFromColor(activeWindow),
85 .activeButtonText = activeButtonText,
86 .inactiveButtonText = makeInactiveOrDisabledFromColor(activeButtonText),
87 .activeHighlight = accentColor,
88 .inactiveHighlight = makeInactiveOrDisabledFromColor(accentColor),
89 .clickEffect = QColor(
"#1A000000"),
90 .hover = QColor(
"#0D000000"),
91 .foregroundContrary = QColor(
"#FFFFFF"),
92 .highlighted = accentColor,
93 .inactiveHighlighted = makeInactiveOrDisabledFromColor(accentColor),
94 .textPrimary = textPrimary,
95 .inactiveTextPrimary = textPrimary,
96 .disabledTextPrimary = makeInactiveOrDisabledFromColor(textPrimary),
97 .inactiveText = makeInactiveOrDisabledFromColor(textPrimary),
98 .componentNormal = QColor(
"#19182431"),
99 .componentActivated = QColor(
"#007DFF"),
100 .indicatorArrow = QColor(
"#E5182431"),
101 .scrollBarSlider = QColor(
"#182431"),
102 .switchBgOff = QColor(
"#33FFFFFF"),
103 .switchOutlineOff = QColor(
"#66182431"),
104 .window = QColor(
"#FFF1F3F5"),
110 const auto activeWindow = QColor(
"#18181A");
111 const auto activeButtonText = QColor(
"#3F97E9");
112 const auto textPrimary = QColor(
"#DBFFFFFF");
115 .activeWindow = activeWindow,
116 .inactiveWindow = makeInactiveOrDisabledFromColor(activeWindow),
117 .activeButtonText = activeButtonText,
118 .inactiveButtonText = makeInactiveOrDisabledFromColor(activeButtonText),
119 .activeHighlight = accentColor,
120 .inactiveHighlight = makeInactiveOrDisabledFromColor(accentColor),
121 .clickEffect = QColor(
"#26FFFFFF"),
122 .hover = QColor(
"#19FFFFFF"),
123 .foregroundContrary = QColor(
"#E5E5E5"),
124 .highlighted = accentColor,
125 .inactiveHighlighted = makeInactiveOrDisabledFromColor(accentColor),
126 .textPrimary = textPrimary,
127 .inactiveTextPrimary = textPrimary,
128 .disabledTextPrimary = makeInactiveOrDisabledFromColor(textPrimary),
129 .inactiveText = makeInactiveOrDisabledFromColor(textPrimary),
130 .componentNormal = QColor(
"#19FFFFFF"),
131 .componentActivated = QColor(
"#3F97E9"),
132 .indicatorArrow = QColor(
"#DBFFFFFF"),
133 .scrollBarSlider = QColor(
"#FFFFFF"),
134 .switchBgOff = QColor(
"#33000000"),
135 .switchOutlineOff = QColor(
"#66FFFFFF"),
136 .window = QColor(
"#FF000000"),
150 const auto activeButton = QColor(
"#0C182431");
153 .activeButton = activeButton,
154 .inactiveButton = makeInactiveOrDisabledFromColor(activeButton),
155 .focusedOutline = accentColor,
156 .enabledDefaultButtonText = QColor(
"#FFFFFFFF"),
162 const auto activeButton = QColor(
"#19FFFFFF");
165 .activeButton = activeButton,
166 .inactiveButton = makeInactiveOrDisabledFromColor(activeButton),
167 .focusedOutline = accentColor,
168 .enabledDefaultButtonText = QColor(
"#E5E5E5"),
180 .windowButtonBackground = QColor(
"#FFD0CFD5"),
187 .windowButtonBackground = QColor(
"#FFD0CFD5"),
201 .activeWindowFrame = QColor(
"#FFE4E4E4"),
202 .textHint = QColor(
"#99182431"),
203 .textTertiary = QColor(
"#66182431"),
210 .activeWindowFrame = QColor(
"#FF000000"),
211 .textHint = QColor(
"#99FFFFFF"),
212 .textTertiary = QColor(
"#66FFFFFF"),
225 .listSeparator = QColor(
"#1A000000"),
226 .inactiveText = makeInactiveOrDisabledFromColor(palettes.textPrimary),
233 .listSeparator = QColor(
"#33FFFFFF"),
234 .inactiveText = makeInactiveOrDisabledFromColor(palettes.textPrimary),
247 const auto inactiveWindowText = QColor(
"#99182431");
250 .activeWindowText = accentColor,
251 .inactiveWindowText = inactiveWindowText,
252 .disabledWindowText = makeInactiveOrDisabledFromColor(inactiveWindowText),
258 const auto inactiveWindowText = QColor(
"#99FFFFFF");
261 .activeWindowText = accentColor,
262 .inactiveWindowText = inactiveWindowText,
263 .disabledWindowText = makeInactiveOrDisabledFromColor(inactiveWindowText),
275 const auto textEditBackground = QColor(
"#0C182431");
277 .textEditBackground = textEditBackground,
278 .inactiveTextEditBackground = makeInactiveOrDisabledFromColor(textEditBackground),
284 const auto textEditBackground = QColor(
"#19FFFFFF");
286 .textEditBackground = textEditBackground,
287 .inactiveTextEditBackground = makeInactiveOrDisabledFromColor(textEditBackground),
299 .buttonBackground = QColor(
"#0C000000"),
306 .buttonBackground = QColor(
"#33FFFFFF"),
320 .background = QColor(
"#00000000"),
321 .groupBoxFrame = QColor(
"#66000000"),
322 .shadowXS = QColor(
"#19000000"),
329 .background = QColor(
"#00000000"),
330 .groupBoxFrame = QColor(
"#66FFFFFF"),
331 .shadowXS = QColor(
"#19FFFFFF"),
343 .activeButton = QColor(
"#FFFFFFFF"),
350 .activeButton = QColor(
"#FF18181A"),
363 .toolTipBorder = QColor(
"#1A000000"),
364 .toolTipBase = QColor(
"#FFFFFFFF"),
371 .toolTipBorder = QColor(
"#1AFFFFFF"),
372 .toolTipBase = QColor(
"#404040"),
393 const auto palettes = makePalettesColorsLight(accentColor);
396 .palettes = palettes,
397 .button = makeButtonPaletteColorsLight(accentColor),
398 .toolButton = makeToolButtonPaletteColorsLight(),
399 .system = makeSystemButtonPaletteColorsLight(),
400 .menu = makeMenuPaletteColorsLight(palettes),
401 .tabBar = makeTabBarPaletteColorsLight(accentColor),
402 .textLineEdit = makeTextLineEditPaletteColorsLight(),
403 .comboBox = makeComboBoxPaletteColorsLight(),
404 .groupBox = makeGroupboxPaletteColorsLight(),
405 .header = makeHeaderPaletteColorsLight(),
406 .toolTip = makeTooltipPaletteColorsLight(),
412 const auto palettes = makePalettesColorsDark(accentColor);
415 .palettes = palettes,
416 .button = makeButtonPaletteColorsDark(accentColor),
417 .toolButton = makeToolButtonPaletteColorsDark(),
418 .system = makeSystemButtonPaletteColorsDark(),
419 .menu = makeMenuPaletteColorsDark(palettes),
420 .tabBar = makeTabBarPaletteColorsDark(accentColor),
421 .textLineEdit = makeTextLineEditPaletteColorsDark(),
422 .comboBox = makeComboBoxPaletteColorsDark(),
423 .groupBox = makeGroupboxPaletteColorsDark(),
424 .header = makeHeaderPaletteColorsDark(),
425 .toolTip = makeTooltipPaletteColorsDark(),
432 case Qt::ColorScheme::Light:
return makeAllPalettesColorsLight(accentColor);
433 case Qt::ColorScheme::Dark:
return makeAllPalettesColorsDark(accentColor);
438 qOhosReportFatalErrorAndAbort(
439 "%s: got unsupported ColorScheme: %d", Q_FUNC_INFO,
static_cast<
int>(scheme));
446 const QPalette &basePalette, std::initializer_list<std::tuple<QPalette::ColorGroup, QPalette::ColorRole,
const QColor &>> brushEntries)
448 auto palette = basePalette;
450 for (
const auto &brushEntry : brushEntries) {
452 std::get<QPalette::ColorGroup>(brushEntry),
453 std::get<QPalette::ColorRole>(brushEntry),
454 std::get<
const QColor &>(brushEntry));
462 const auto &colors = palettesColors.palettes;
463 const auto button = makeOverlayCompositedOnSurface(
464 palettesColors.button.activeButton, colors.activeWindow);
466 QPalette palette(button, colors.activeWindow);
468 const auto textVersions = {
469 std::make_pair(QPalette::Active, colors.textPrimary),
470 std::make_pair(QPalette::Inactive, colors.inactiveTextPrimary),
471 std::make_pair(QPalette::Disabled, colors.disabledTextPrimary)};
473 for (
const auto &groupAndText : textVersions) {
474 palette.setColor(groupAndText.first, QPalette::WindowText, groupAndText.second);
475 palette.setColor(groupAndText.first, QPalette::Text, groupAndText.second);
476 palette.setColor(groupAndText.first, QPalette::ButtonText, groupAndText.second);
478 palette.setColor(QPalette::BrightText, colors.foregroundContrary);
486 makeBasePalette(palettesColors),
488 {QPalette::Active, QPalette::AlternateBase, palettesColors.palettes.componentActivated},
490 {QPalette::Active, QPalette::Button, palettesColors.button.activeButton},
491 {QPalette::Disabled, QPalette::Button, palettesColors.button.inactiveButton},
492 {QPalette::Inactive, QPalette::Button, palettesColors.button.inactiveButton},
494 {QPalette::Active, QPalette::ButtonText, palettesColors.palettes.activeButtonText},
495 {QPalette::Disabled, QPalette::ButtonText, palettesColors.palettes.inactiveButtonText},
496 {QPalette::Inactive, QPalette::ButtonText, palettesColors.palettes.inactiveButtonText},
498 {QPalette::All, QPalette::BrightText, palettesColors.button.enabledDefaultButtonText},
500 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
501 {QPalette::Active, QPalette::Dark, palettesColors.palettes.clickEffect},
503 {QPalette::Active, QPalette::Highlight, palettesColors.button.focusedOutline},
504 {QPalette::Active, QPalette::WindowText, palettesColors.palettes.indicatorArrow}
511 makeButtonPalette(palettesColors),
513 {QPalette::Active, QPalette::AlternateBase, palettesColors.toolButton.windowButtonBackground},
520 makeBasePalette(palettesColors),
522 {QPalette::Active, QPalette::Window, palettesColors.palettes.activeWindow},
523 {QPalette::Disabled, QPalette::Window, palettesColors.palettes.activeWindow},
524 {QPalette::Inactive, QPalette::Window, palettesColors.palettes.activeWindow},
526 {QPalette::Active, QPalette::WindowText, palettesColors.palettes.textPrimary},
527 {QPalette::Disabled, QPalette::WindowText, palettesColors.palettes.disabledTextPrimary},
528 {QPalette::Inactive, QPalette::WindowText, palettesColors.palettes.inactiveTextPrimary},
530 {QPalette::Active, QPalette::Text, palettesColors.palettes.textPrimary},
531 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.disabledTextPrimary},
532 {QPalette::Inactive, QPalette::Text, palettesColors.palettes.inactiveTextPrimary},
534 {QPalette::Active, QPalette::Base, palettesColors.palettes.window},
535 {QPalette::Disabled, QPalette::Base, palettesColors.palettes.window},
536 {QPalette::Inactive, QPalette::Base, palettesColors.palettes.window},
538 {QPalette::Active, QPalette::AlternateBase, palettesColors.palettes.textPrimary},
540 {QPalette::Active, QPalette::Highlight, palettesColors.palettes.highlighted},
542 {QPalette::All, QPalette::PlaceholderText, palettesColors.system.textHint},
543 {QPalette::Disabled, QPalette::PlaceholderText, palettesColors.system.textTertiary},
545 {QPalette::Active, QPalette::Midlight, palettesColors.palettes.scrollBarSlider},
547 {QPalette::Active, QPalette::Mid, palettesColors.palettes.componentNormal}
554 makeBasePalette(palettesColors),
556 {QPalette::Inactive, QPalette::Base, palettesColors.palettes.switchBgOff},
557 {QPalette::Inactive, QPalette::Button, palettesColors.palettes.switchOutlineOff},
558 {QPalette::Active, QPalette::Button, palettesColors.palettes.highlighted},
559 {QPalette::Active, QPalette::Highlight, palettesColors.palettes.highlighted},
560 {QPalette::Active, QPalette::WindowText, palettesColors.palettes.highlighted},
561 {QPalette::Inactive, QPalette::WindowText, palettesColors.palettes.inactiveText},
562 {QPalette::Disabled, QPalette::WindowText, palettesColors.palettes.inactiveHighlighted},
563 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
564 {QPalette::Active, QPalette::Dark, palettesColors.palettes.clickEffect},
571 makeBasePalette(palettesColors),
573 {QPalette::Active, QPalette::AlternateBase, palettesColors.palettes.componentActivated},
574 {QPalette::All, QPalette::Base, palettesColors.palettes.window},
575 {QPalette::All, QPalette::Window, palettesColors.palettes.window},
576 {QPalette::Active, QPalette::Text, palettesColors.palettes.highlighted},
577 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.inactiveText},
578 {QPalette::Inactive, QPalette::Text, palettesColors.palettes.inactiveHighlighted},
579 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
580 {QPalette::Active, QPalette::Dark, palettesColors.palettes.clickEffect},
581 {QPalette::Active, QPalette::WindowText, palettesColors.palettes.indicatorArrow},
582 {QPalette::All, QPalette::Button, palettesColors.comboBox.buttonBackground}
589 makeBasePalette(palettesColors),
591 {QPalette::Active, QPalette::Window, palettesColors.palettes.activeWindow},
592 {QPalette::Inactive, QPalette::Base, palettesColors.palettes.switchBgOff},
593 {QPalette::Inactive, QPalette::Button, palettesColors.palettes.switchOutlineOff},
594 {QPalette::Active, QPalette::Button, palettesColors.palettes.highlighted},
596 {QPalette::Active, QPalette::Text, palettesColors.palettes.textPrimary},
597 {QPalette::Disabled, QPalette::Text, palettesColors.menu.inactiveText},
598 {QPalette::Inactive, QPalette::Text, palettesColors.menu.inactiveText},
600 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
601 {QPalette::Active, QPalette::Dark, palettesColors.palettes.clickEffect},
603 {QPalette::Active, QPalette::Mid, palettesColors.menu.listSeparator}
610 makeBasePalette(palettesColors),
612 {QPalette::Active, QPalette::ButtonText, palettesColors.palettes.textPrimary},
613 {QPalette::Disabled, QPalette::ButtonText, palettesColors.menu.inactiveText},
614 {QPalette::Inactive, QPalette::ButtonText, palettesColors.menu.inactiveText},
621 makeBasePalette(palettesColors),
623 {QPalette::Active, QPalette::WindowText, palettesColors.tabBar.activeWindowText},
624 {QPalette::Inactive, QPalette::WindowText, palettesColors.tabBar.inactiveWindowText},
625 {QPalette::Disabled, QPalette::WindowText, palettesColors.tabBar.disabledWindowText},
627 {QPalette::Active, QPalette::Window, palettesColors.palettes.activeWindow},
628 {QPalette::Inactive, QPalette::Window, palettesColors.palettes.inactiveWindow},
629 {QPalette::Disabled, QPalette::Window, palettesColors.palettes.inactiveWindow},
631 {QPalette::Active, QPalette::Highlight, palettesColors.palettes.activeHighlight},
632 {QPalette::Inactive, QPalette::Highlight, palettesColors.palettes.inactiveHighlight},
633 {QPalette::Disabled, QPalette::Highlight, palettesColors.palettes.inactiveHighlight},
640 makeSystemPalette(palettesColors),
642 {QPalette::Active, QPalette::AlternateBase, palettesColors.palettes.componentActivated},
643 {QPalette::All, QPalette::Base, palettesColors.textLineEdit.textEditBackground},
644 {QPalette::Disabled, QPalette::Base, palettesColors.textLineEdit.inactiveTextEditBackground},
645 {QPalette::All, QPalette::Text, palettesColors.palettes.textPrimary},
646 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.disabledTextPrimary},
653 makeTextLineEditPalette(palettesColors),
655 {QPalette::All, QPalette::Base, palettesColors.palettes.activeWindow},
662 makeBasePalette(palettesColors),
664 {QPalette::Active, QPalette::Button, palettesColors.palettes.highlighted},
665 {QPalette::Inactive, QPalette::Button, palettesColors.palettes.switchOutlineOff},
666 {QPalette::Active, QPalette::Base, palettesColors.system.activeWindowFrame},
667 {QPalette::Inactive, QPalette::Base, palettesColors.palettes.switchBgOff},
668 {QPalette::Active, QPalette::AlternateBase, palettesColors.groupBox.groupBoxFrame},
669 {QPalette::Active, QPalette::Window, palettesColors.groupBox.background},
670 {QPalette::Inactive, QPalette::Window, palettesColors.groupBox.background},
671 {QPalette::Active, QPalette::Window, palettesColors.palettes.window},
672 {QPalette::Disabled, QPalette::Window, palettesColors.palettes.window},
673 {QPalette::Active, QPalette::Text, palettesColors.palettes.highlighted},
674 {QPalette::Inactive, QPalette::Text, palettesColors.palettes.highlighted},
675 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.inactiveHighlighted},
676 {QPalette::Current, QPalette::Text, palettesColors.palettes.highlighted},
677 {QPalette::Disabled, QPalette::WindowText, palettesColors.palettes.inactiveHighlighted},
678 {QPalette::Active, QPalette::ButtonText, palettesColors.palettes.textPrimary},
679 {QPalette::Disabled, QPalette::ButtonText, palettesColors.palettes.inactiveHighlighted},
680 {QPalette::Active, QPalette::Dark, palettesColors.palettes.clickEffect},
681 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
682 {QPalette::Active, QPalette::Shadow, palettesColors.groupBox.shadowXS},
683 {QPalette::Active, QPalette::Midlight, palettesColors.palettes.scrollBarSlider},
684 {QPalette::Active, QPalette::Mid, palettesColors.palettes.componentNormal}
691 makeBasePalette(palettesColors),
693 {QPalette::Active, QPalette::Button, palettesColors.header.activeButton},
694 {QPalette::Inactive, QPalette::Button, palettesColors.header.activeButton},
695 {QPalette::Disabled, QPalette::Button, palettesColors.palettes.inactiveWindow},
697 {QPalette::Current, QPalette::ButtonText, palettesColors.palettes.activeButtonText},
698 {QPalette::Active, QPalette::ButtonText, palettesColors.palettes.activeButtonText},
699 {QPalette::Inactive, QPalette::ButtonText, palettesColors.palettes.activeButtonText},
700 {QPalette::Disabled, QPalette::ButtonText, palettesColors.palettes.inactiveButtonText},
707 makeSystemPalette(palettesColors),
709 {QPalette::Active, QPalette::Base, palettesColors.palettes.window},
710 {QPalette::Inactive, QPalette::Base, palettesColors.palettes.window},
711 {QPalette::Disabled, QPalette::Base, palettesColors.palettes.window},
713 {QPalette::Active, QPalette::AlternateBase, palettesColors.palettes.activeWindow},
714 {QPalette::Inactive, QPalette::AlternateBase, palettesColors.palettes.activeWindow},
715 {QPalette::Disabled, QPalette::AlternateBase, palettesColors.palettes.inactiveWindow},
716 {QPalette::Current, QPalette::AlternateBase, palettesColors.palettes.activeWindow},
718 {QPalette::Active, QPalette::Highlight, palettesColors.palettes.activeHighlight},
719 {QPalette::Inactive, QPalette::Highlight, palettesColors.palettes.activeHighlight},
720 {QPalette::Disabled, QPalette::Highlight, palettesColors.palettes.inactiveHighlight},
722 {QPalette::Active, QPalette::Window, palettesColors.palettes.activeWindow},
723 {QPalette::Inactive, QPalette::Window, palettesColors.palettes.activeWindow},
724 {QPalette::Disabled, QPalette::Window, palettesColors.palettes.inactiveWindow},
726 {QPalette::Active, QPalette::Text, palettesColors.palettes.activeHighlight},
727 {QPalette::Inactive, QPalette::Text, palettesColors.palettes.activeHighlight},
728 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.inactiveHighlight},
730 {QPalette::Active, QPalette::HighlightedText, palettesColors.palettes.activeWindow},
731 {QPalette::Inactive, QPalette::HighlightedText, palettesColors.palettes.activeWindow},
732 {QPalette::Disabled, QPalette::HighlightedText, palettesColors.palettes.inactiveWindow},
734 {QPalette::Active, QPalette::Dark, palettesColors.palettes.activeWindow},
735 {QPalette::Inactive, QPalette::Dark, palettesColors.palettes.activeWindow},
736 {QPalette::Disabled, QPalette::Dark, palettesColors.palettes.inactiveWindow},
737 {QPalette::Current, QPalette::Dark, palettesColors.palettes.activeWindow},
738 {QPalette::All, QPalette::Dark, palettesColors.palettes.activeWindow},
740 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
741 {QPalette::Inactive, QPalette::Light, palettesColors.palettes.activeWindow},
742 {QPalette::Disabled, QPalette::Light, palettesColors.palettes.inactiveWindow},
744 {QPalette::Active, QPalette::Mid, palettesColors.palettes.activeWindow},
745 {QPalette::Inactive, QPalette::Mid, palettesColors.palettes.activeWindow},
746 {QPalette::Disabled, QPalette::Mid, palettesColors.palettes.inactiveWindow},
747 {QPalette::Current, QPalette::Mid, palettesColors.palettes.activeWindow},
748 {QPalette::All, QPalette::Mid, palettesColors.palettes.activeWindow},
755 makeBasePalette(palettesColors),
757 {QPalette::Active, QPalette::WindowText, palettesColors.palettes.textPrimary},
758 {QPalette::Disabled, QPalette::WindowText, palettesColors.palettes.disabledTextPrimary},
759 {QPalette::Inactive, QPalette::WindowText, palettesColors.palettes.inactiveTextPrimary},
761 {QPalette::Active, QPalette::Text, palettesColors.palettes.textPrimary},
762 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.disabledTextPrimary},
763 {QPalette::Inactive, QPalette::Text, palettesColors.palettes.inactiveTextPrimary},
770 makeBasePalette(palettesColors),
772 {QPalette::All, QPalette::Base, palettesColors.toolTip.toolTipBorder},
773 {QPalette::All, QPalette::ToolTipBase, palettesColors.toolTip.toolTipBase},
774 {QPalette::All, QPalette::ToolTipText, palettesColors.palettes.highlighted},
780 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
781 font.setPointSize(16);
788 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
789 font.setPointSize(12);
797 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
798 font.setPointSize(20);
806 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
807 font.setPointSize(16);
814 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
815 font.setPointSize(16);
822 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
823 font.setPointSize(16);
830 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
831 font.setPointSize(14);
839 {QPlatformTheme::DockWidgetTitleFont, makeTitleFont()},
840 {QPlatformTheme::GroupBoxTitleFont, makeGroupBoxTitleFont()},
841 {QPlatformTheme::ListViewFont, makeListViewFont()},
842 {QPlatformTheme::MenuBarFont, makeMenuFont()},
843 {QPlatformTheme::MenuFont, makeMenuFont()},
844 {QPlatformTheme::MenuItemFont, makeMenuFont()},
845 {QPlatformTheme::PushButtonFont, makePushButtonFont()},
846 {QPlatformTheme::SystemFont, makeSystemFont()},
847 {QPlatformTheme::TipLabelFont, makeTipLabelFont()},
853 const AllPalletesColors palettesColors = makeAllPalettesColors(scheme, accentColor);
855 {QPlatformTheme::ButtonPalette, makeButtonPalette(palettesColors)},
856 {QPlatformTheme::CheckBoxPalette, makeCheckBoxOrRadioButtonPalette(palettesColors)},
857 {QPlatformTheme::ComboBoxPalette, makeComboBoxPalette(palettesColors)},
858 {QPlatformTheme::GroupBoxPalette, makeGroupBoxPalette(palettesColors)},
859 {QPlatformTheme::HeaderPalette, makeHeaderPalette(palettesColors)},
860 {QPlatformTheme::ItemViewPalette, makeItemViewPalette(palettesColors)},
861 {QPlatformTheme::LabelPalette, makeLabelPalette(palettesColors)},
862 {QPlatformTheme::MenuPalette, makeMenuPalette(palettesColors)},
863 {QPlatformTheme::MenuBarPalette, makeMenuBarPalette(palettesColors)},
864 {QPlatformTheme::RadioButtonPalette, makeCheckBoxOrRadioButtonPalette(palettesColors)},
865 {QPlatformTheme::SystemPalette, makeSystemPalette(palettesColors)},
866 {QPlatformTheme::TabBarPalette, makeTabBarPalette(palettesColors)},
867 {QPlatformTheme::TextEditPalette, makeTextEditPalette(palettesColors)},
868 {QPlatformTheme::TextLineEditPalette, makeTextLineEditPalette(palettesColors)},
869 {QPlatformTheme::ToolButtonPalette, makeToolButtonPalette(palettesColors)},
870 {QPlatformTheme::ToolTipPalette, makeToolTipPalette(palettesColors)},
875 Qt::ColorScheme scheme)
878 case Qt::ColorScheme::Unknown:
880 case Qt::ColorScheme::Light:
882 case Qt::ColorScheme::Dark:
889 std::optional<
bool> darkModeFlag)
891 if (darkModeFlag.has_value()) {
892 if (!darkModeFlag.value_or(
false))
893 return Qt::ColorScheme::Light;
895 return Qt::ColorScheme::Dark;
897 return Qt::ColorScheme::Unknown;
907 return optColorMode.value_or(fallbackColorMode);
913 qCWarning(QtForOhos,
"%s: cannot set a color mode in 'no UI child mode'", Q_FUNC_INFO);
917 QOhosJsThreadGateway::runAndWait(
918 [&](QOhosJsState &jsState) {
919 auto optQAbility = jsState.defaultQAbility();
921 qCWarning(QtForOhos,
"%s: cannot set a color mode without a UIAbility", Q_FUNC_INFO);
925 const auto jsColorMode = jsState.mapOhosEnumToJs(colorMode);
926 optQAbility->eval(
"context.getApplicationContext().setColorMode(*)", {jsColorMode});
947 auto optQAbility = jsState.defaultQAbility();
951 const auto argb =
static_cast<uint32_t>(
952 optQAbility->eval<QNapi::Number>(
953 "context.resourceManager.getColorByNameSync(*)",
954 {
"ohos_id_color_emphasize"}));
955 return QColor::fromRgba(argb);
965 return colorMode == other.colorMode && accentColor == other.accentColor;
970 return !(*
this == other);
975 QOhosConsumer<OhosThemeConfig> valueChangedHandler)
978 [](QOhosJsState &jsState) {
979 auto optQAbility = jsState.defaultQAbility();
981 return OhosThemeConfig{};
983 return OhosThemeConfig{
984 .colorMode = mapOhosConfigurationColorModeFromJs(
985 jsState, optQAbility->eval<QNapi::Number>(
"context.config.colorMode")),
986 .accentColor = readAccentColor(jsState),
989 [](QOhosJsState &jsState,
const QNapi::Object &config) {
990 return OhosThemeConfig{
991 .colorMode = mapOhosConfigurationColorModeFromJs(jsState, config.get<QNapi::Number>(
"colorMode")),
992 .accentColor = readAccentColor(jsState),
995 std::move(valueChangedHandler));
1000 std::string undocumentedParamsPropertyName(
"params");
1001 auto optParams = QNapi::getOptionalPropOrEmpty<QNapi::Value>(resource, undocumentedParamsPropertyName);
1002 if (optParams.IsEmpty()) {
1004 "%s: expected '%s' property not found in resource object, ignore getting pixmap",
1005 Q_FUNC_INFO, undocumentedParamsPropertyName.c_str());
1006 return std::nullopt;
1008 if (!optParams.IsArray()) {
1010 "%s: '%s' property is not an array, ignore getting pixmap",
1011 Q_FUNC_INFO, undocumentedParamsPropertyName.c_str());
1012 return std::nullopt;
1015 auto params = QNapi::getArrayElements<std::vector<std::string>, QNapi::String>(
1016 QNapi::checkedCast<QNapi::Array>(optParams));
1017 if (params.empty()) {
1019 "%s: '%s' property is empty, ignore getting pixmap",
1020 Q_FUNC_INFO, undocumentedParamsPropertyName.c_str());
1021 return std::nullopt;
1024 const auto resourceIdentifier = params.front();
1025 const auto lastSeparatorPosition = resourceIdentifier.rfind(
'.');
1026 if (lastSeparatorPosition == std::string::npos) {
1028 "%s: '%s' property has unknown resource name, ignore getting pixmap",
1029 Q_FUNC_INFO, undocumentedParamsPropertyName.c_str());
1030 return std::nullopt;
1033 const auto simpleName = resourceIdentifier.substr(lastSeparatorPosition + 1);
1034 auto resourceContentBuffer = jsState.eval<QNapi::TypedArrayOf<std::uint8_t>>(
1035 "@ohos.resourceManager.getSysResourceManager().getMediaByNameSync(*)", {simpleName});
1038 bool pixmapLoadResult = pixmap.loadFromData(
1039 static_cast<
const uchar *>(resourceContentBuffer.Data()), resourceContentBuffer.ByteLength());
1041 if (pixmapLoadResult) {
1044 qOhosPrintfWarning(
"%s: cannot load pixmap", Q_FUNC_INFO);
1045 return std::nullopt;
1050 QOhosJsState &jsState,
const std::string &filenameExtension)
1052 std::string ohosDotFilenameExtension =
"." + filenameExtension;
1053 auto uniformDataType = jsState.eval<QNapi::String>(
1054 "@ohos.data.uniformTypeDescriptor.getUniformDataTypeByFilenameExtension(*)",
1055 {ohosDotFilenameExtension});
1057 auto resourceValue = jsState.eval(
1058 "@kit.FileManagerServiceKit.fileManagerService.getFileIconSync(*)", {uniformDataType});
1059 if (resourceValue.IsObject()) {
1060 return tryGetFilePixmapByResourceObject(jsState, QNapi::checkedCast<QNapi::Object>(resourceValue));
1062 qOhosPrintfWarning(
"%s: got unhandled resource result type, ignore it", Q_FUNC_INFO);
1063 return std::nullopt;
1083 auto fileNameSuffix = fileInfo().suffix();
1084 auto optPixmap = QOhosJsThreadGateway::eval(
1085 [&](QOhosJsState &jsState) {
1086 return tryGetFilePixmapByFilenameExtension(jsState, fileNameSuffix.toStdString());
1090 return optPixmap.has_value()
1091 ? optPixmap.value().scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation)
1104 auto themeConfigDataSource = std::make_shared<QOhosSupplier<OhosThemeConfig>>(
1105 makeOhosThemeConfigDataSource(
1106 [
this](
const auto &) {
1108 QWindowSystemInterface::handleThemeChange<QWindowSystemInterface::SynchronousDelivery>();
1111 m_ohosConfigDarkModeFlagSupplier = [themeConfigDataSource]() {
1112 return mapOhosConfigurationColorModeToDarkModeFlag((*themeConfigDataSource)().colorMode);
1115 m_ohosAccentColorSupplier = [themeConfigDataSource]() {
1116 return (*themeConfigDataSource)().accentColor;
1124 std::optional<
bool> isDarkMode = mapOhosThemeFromColorScheme(scheme);
1125 setOhosConfigColorMode(
1126 isDarkMode.has_value()
1127 ? isDarkMode.value()
1135 return mapOhosThemeToColorScheme(m_ohosConfigDarkModeFlagSupplier());
1140 if (
const auto currentColorScheme = colorScheme(); currentColorScheme != Qt::ColorScheme::Unknown)
1141 m_themePalette = makePalettesMap(currentColorScheme, m_ohosAccentColorSupplier());
1146 auto _dbg = make_QCScopedDebug(
"QOhosPlatformTheme::createPlatformDialogHelper");
1147 return QOhosDialogs::createHelper(type);
1152 auto _dbg = make_QCScopedDebug(
"QOhosPlatformTheme::usePlatformNativeDialog");
1153 return (type == QOhosPlatformTheme::FileDialog);
1160 return QStringList(QString::fromUtf8(ohosThemeName));
1161 case MouseDoubleClickDistance:
1162 case TouchDoubleTapDistance:
1164 auto *primaryScreen = qGuiApp->primaryScreen();
1165 auto *platformScreen = primaryScreen !=
nullptr
1168 return platformScreen !=
nullptr
1169 ? QHighDpi::fromNativePixels(
1171 mouseDoubleClickDistance, platformScreen->pixelScalingCoefficient()),
1173 : mouseDoubleClickDistance;
1175 case MouseDoubleClickInterval:
1177 case WheelScrollLines:
1178 return m_wheelScrollLines;
1179 case MenuBarFocusOnAltPressRelease:
1181 case PreferFileIconFromTheme:
1184 return QPlatformTheme::themeHint(hint);
1190 if (
const auto it = m_themePalette.find(type); it != m_themePalette.end())
1192 return QPlatformTheme::palette(type);
1197 const auto fonts = m_fontsSupplier();
1198 const auto fontIter = fonts->find(type);
1199 return fontIter != fonts->end()
1201 : QPlatformTheme::font(type);
1206 m_wheelScrollLines = wheelScrollLines;
1211 return makeQOhosSystemTrayIcon().release();
1216 return !fileInfo.suffix().isEmpty()
1217 ? QIcon(
new QOhosFileIconEngine(fileInfo, iconOptions))
1218 : QPlatformTheme::fileIcon(fileInfo, iconOptions);
1223 return tryCreateQOhosIconEngine(iconName);
QPixmap filePixmap(const QSize &size, QIcon::Mode mode, QIcon::State) override
QOhosFileIconEngine(const QFileInfo &info, QPlatformTheme::IconOptions opts)
Combined button and popup list for selecting options.
AllPalletesColors makeAllPalettesColorsLight(const QColor &accentColor)
SystemPaletteColors makeSystemButtonPaletteColorsDark()
QPalette makeLabelPalette(const AllPalletesColors &palettesColors)
QPalette makeCheckBoxOrRadioButtonPalette(const AllPalletesColors &palettesColors)
ComboBoxPaletteColors makeComboBoxPaletteColorsLight()
ComboBoxPaletteColors makeComboBoxPaletteColorsDark()
QPalette makeSystemPalette(const AllPalletesColors &palettesColors)
SystemPaletteColors makeSystemButtonPaletteColorsLight()
QColor makeInactiveOrDisabledFromColor(const QColor &color)
QHash< QPlatformTheme::Palette, QPalette > makePalettesMap(Qt::ColorScheme scheme, const QColor &accentColor)
QPalette makeTextEditPalette(const AllPalletesColors &palettesColors)
QColor readAccentColor(QOhosJsState &jsState)
TooltipPaletteColors makeTooltipPaletteColorsDark()
QPalette makePalette(const QPalette &basePalette, std::initializer_list< std::tuple< QPalette::ColorGroup, QPalette::ColorRole, const QColor & > > brushEntries)
std::optional< QPixmap > tryGetFilePixmapByResourceObject(QOhosJsState &jsState, QNapi::Object resource)
PalettesColors makePalettesColorsLight(const QColor &accentColor)
AllPalletesColors makeAllPalettesColorsDark(const QColor &accentColor)
void setOhosConfigColorMode(OhosConfigurationColorMode colorMode)
ButtonPaletteColors makeButtonPaletteColorsDark(const QColor &accentColor)
std::optional< bool > mapOhosConfigurationColorModeToDarkModeFlag(OhosConfigurationColorMode colorMode)
QPalette makeBasePalette(const AllPalletesColors &palettesColors)
MenuPaletteColors makeMenuPaletteColorsDark(const PalettesColors &palettes)
QColor makeOverlayCompositedOnSurface(const QColor &overlay, const QColor &surface)
TooltipPaletteColors makeTooltipPaletteColorsLight()
QtOhosQpa::enums::ohos::app::ability::ConfigurationConstant::ColorMode OhosConfigurationColorMode
QFont makeGroupBoxTitleFont()
ToolButtonPaletteColors makeToolButtonPaletteColorsDark()
GroupboxPaletteColors makeGroupboxPaletteColorsDark()
std::optional< QPixmap > tryGetFilePixmapByFilenameExtension(QOhosJsState &jsState, const std::string &filenameExtension)
TabBarPaletteColors makeTabBarPaletteColorsLight(const QColor &accentColor)
QPalette makeHeaderPalette(const AllPalletesColors &palettesColors)
QHash< QPlatformTheme::Font, QFont > makeFontsMap()
AllPalletesColors makeAllPalettesColors(Qt::ColorScheme scheme, const QColor &accentColor)
MenuPaletteColors makeMenuPaletteColorsLight(const PalettesColors &palettes)
OhosConfigurationColorMode mapOhosConfigurationColorModeFromJs(QOhosJsState &jsState, QNapi::Number colorModeJsEnum)
QPalette makeItemViewPalette(const AllPalletesColors &palettesColors)
constexpr int mouseDoubleClickInterval
constexpr int mouseDoubleClickDistance
Qt::ColorScheme mapOhosThemeToColorScheme(std::optional< bool > darkModeFlag)
PalettesColors makePalettesColorsDark(const QColor &accentColor)
QPalette makeTabBarPalette(const AllPalletesColors &palettesColors)
ToolButtonPaletteColors makeToolButtonPaletteColorsLight()
TextLineEditPaletteColors makeTextLineEditPaletteColorsLight()
QPalette makeMenuBarPalette(const AllPalletesColors &palettesColors)
QOhosSupplier< OhosThemeConfig > makeOhosThemeConfigDataSource(QOhosConsumer< OhosThemeConfig > valueChangedHandler)
std::optional< bool > mapOhosThemeFromColorScheme(Qt::ColorScheme scheme)
HeaderPaletteColors makeHeaderPaletteColorsDark()
TabBarPaletteColors makeTabBarPaletteColorsDark(const QColor &accentColor)
QPalette makeComboBoxPalette(const AllPalletesColors &palettesColors)
TextLineEditPaletteColors makeTextLineEditPaletteColorsDark()
ButtonPaletteColors makeButtonPaletteColorsLight(const QColor &accentColor)
QPalette makeMenuPalette(const AllPalletesColors &palettesColors)
HeaderPaletteColors makeHeaderPaletteColorsLight()
QPalette makeGroupBoxPalette(const AllPalletesColors &palettesColors)
QPalette makeButtonPalette(const AllPalletesColors &palettesColors)
QPalette makeTextLineEditPalette(const AllPalletesColors &palettesColors)
QPalette makeToolTipPalette(const AllPalletesColors &palettesColors)
GroupboxPaletteColors makeGroupboxPaletteColorsLight()
QFont makePushButtonFont()
QPalette makeToolButtonPalette(const AllPalletesColors &palettesColors)
bool isOhosNoUiChildMode()
SystemPaletteColors system
GroupboxPaletteColors groupBox
ComboBoxPaletteColors comboBox
HeaderPaletteColors header
ToolButtonPaletteColors toolButton
ButtonPaletteColors button
TabBarPaletteColors tabBar
TooltipPaletteColors toolTip
TextLineEditPaletteColors textLineEdit
bool operator!=(const OhosThemeConfig &other) const
bool operator==(const OhosThemeConfig &other) const
OhosConfigurationColorMode colorMode
QColor inactiveTextPrimary
QColor foregroundContrary
QColor disabledTextPrimary
QColor componentActivated
QColor inactiveButtonText
QColor inactiveHighlighted
QColor disabledWindowText
QColor inactiveWindowText
QColor inactiveTextEditBackground
QColor textEditBackground