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>
18#include <qohosjsmain.h>
19#include <qohosjsutils.h>
20#include <qohosqpaenums.h>
21#include <qohosutils.h>
22#include <qpa/qplatformfontdatabase.h>
23#include <qpa/qplatformintegration.h>
33 auto disabledColor = color;
34 disabledColor.setAlphaF(qBound(0.0, color.alphaF() * 0.4, 1.0));
41 const auto alpha = overlay.alphaF();
43 return QColor::fromRgbF(
44 overlay.redF() * alpha + surface.redF() * (1.0 - alpha),
45 overlay.greenF() * alpha + surface.greenF() * (1.0 - alpha),
46 overlay.blueF() * alpha + surface.blueF() * (1.0 - alpha));
77 const auto activeWindow = QColor(
"#FFFFFFFF");
78 const auto activeButtonText = QColor(
"#0A59F7");
79 const auto textPrimary = QColor(
"#FF182431");
82 .activeWindow = activeWindow,
83 .inactiveWindow = makeInactiveOrDisabledFromColor(activeWindow),
84 .activeButtonText = activeButtonText,
85 .inactiveButtonText = makeInactiveOrDisabledFromColor(activeButtonText),
86 .activeHighlight = accentColor,
87 .inactiveHighlight = makeInactiveOrDisabledFromColor(accentColor),
88 .clickEffect = QColor(
"#1A000000"),
89 .hover = QColor(
"#0D000000"),
90 .foregroundContrary = QColor(
"#FFFFFF"),
91 .highlighted = accentColor,
92 .inactiveHighlighted = makeInactiveOrDisabledFromColor(accentColor),
93 .textPrimary = textPrimary,
94 .inactiveTextPrimary = textPrimary,
95 .disabledTextPrimary = makeInactiveOrDisabledFromColor(textPrimary),
96 .inactiveText = makeInactiveOrDisabledFromColor(textPrimary),
97 .componentNormal = QColor(
"#19182431"),
98 .componentActivated = QColor(
"#007DFF"),
99 .indicatorArrow = QColor(
"#E5182431"),
100 .scrollBarSlider = QColor(
"#182431"),
101 .switchBgOff = QColor(
"#33FFFFFF"),
102 .switchOutlineOff = QColor(
"#66182431"),
103 .window = QColor(
"#FFF1F3F5"),
109 const auto activeWindow = QColor(
"#18181A");
110 const auto activeButtonText = QColor(
"#3F97E9");
111 const auto textPrimary = QColor(
"#DBFFFFFF");
114 .activeWindow = activeWindow,
115 .inactiveWindow = makeInactiveOrDisabledFromColor(activeWindow),
116 .activeButtonText = activeButtonText,
117 .inactiveButtonText = makeInactiveOrDisabledFromColor(activeButtonText),
118 .activeHighlight = accentColor,
119 .inactiveHighlight = makeInactiveOrDisabledFromColor(accentColor),
120 .clickEffect = QColor(
"#26FFFFFF"),
121 .hover = QColor(
"#19FFFFFF"),
122 .foregroundContrary = QColor(
"#E5E5E5"),
123 .highlighted = accentColor,
124 .inactiveHighlighted = makeInactiveOrDisabledFromColor(accentColor),
125 .textPrimary = textPrimary,
126 .inactiveTextPrimary = textPrimary,
127 .disabledTextPrimary = makeInactiveOrDisabledFromColor(textPrimary),
128 .inactiveText = makeInactiveOrDisabledFromColor(textPrimary),
129 .componentNormal = QColor(
"#19FFFFFF"),
130 .componentActivated = QColor(
"#3F97E9"),
131 .indicatorArrow = QColor(
"#DBFFFFFF"),
132 .scrollBarSlider = QColor(
"#FFFFFF"),
133 .switchBgOff = QColor(
"#33000000"),
134 .switchOutlineOff = QColor(
"#66FFFFFF"),
135 .window = QColor(
"#FF000000"),
149 const auto activeButton = QColor(
"#0C182431");
152 .activeButton = activeButton,
153 .inactiveButton = makeInactiveOrDisabledFromColor(activeButton),
154 .focusedOutline = accentColor,
155 .enabledDefaultButtonText = QColor(
"#FFFFFFFF"),
161 const auto activeButton = QColor(
"#19FFFFFF");
164 .activeButton = activeButton,
165 .inactiveButton = makeInactiveOrDisabledFromColor(activeButton),
166 .focusedOutline = accentColor,
167 .enabledDefaultButtonText = QColor(
"#E5E5E5"),
179 .windowButtonBackground = QColor(
"#FFD0CFD5"),
186 .windowButtonBackground = QColor(
"#FFD0CFD5"),
200 .activeWindowFrame = QColor(
"#FFE4E4E4"),
201 .textHint = QColor(
"#99182431"),
202 .textTertiary = QColor(
"#66182431"),
209 .activeWindowFrame = QColor(
"#FF000000"),
210 .textHint = QColor(
"#99FFFFFF"),
211 .textTertiary = QColor(
"#66FFFFFF"),
224 .listSeparator = QColor(
"#1A000000"),
225 .inactiveText = makeInactiveOrDisabledFromColor(palettes.textPrimary),
232 .listSeparator = QColor(
"#33FFFFFF"),
233 .inactiveText = makeInactiveOrDisabledFromColor(palettes.textPrimary),
246 const auto inactiveWindowText = QColor(
"#99182431");
249 .activeWindowText = accentColor,
250 .inactiveWindowText = inactiveWindowText,
251 .disabledWindowText = makeInactiveOrDisabledFromColor(inactiveWindowText),
257 const auto inactiveWindowText = QColor(
"#99FFFFFF");
260 .activeWindowText = accentColor,
261 .inactiveWindowText = inactiveWindowText,
262 .disabledWindowText = makeInactiveOrDisabledFromColor(inactiveWindowText),
274 const auto textEditBackground = QColor(
"#0C182431");
276 .textEditBackground = textEditBackground,
277 .inactiveTextEditBackground = makeInactiveOrDisabledFromColor(textEditBackground),
283 const auto textEditBackground = QColor(
"#19FFFFFF");
285 .textEditBackground = textEditBackground,
286 .inactiveTextEditBackground = makeInactiveOrDisabledFromColor(textEditBackground),
298 .buttonBackground = QColor(
"#0C000000"),
305 .buttonBackground = QColor(
"#33FFFFFF"),
319 .background = QColor(
"#00000000"),
320 .groupBoxFrame = QColor(
"#66000000"),
321 .shadowXS = QColor(
"#19000000"),
328 .background = QColor(
"#00000000"),
329 .groupBoxFrame = QColor(
"#66FFFFFF"),
330 .shadowXS = QColor(
"#19FFFFFF"),
342 .activeButton = QColor(
"#FFFFFFFF"),
349 .activeButton = QColor(
"#FF18181A"),
362 .toolTipBorder = QColor(
"#1A000000"),
363 .toolTipBase = QColor(
"#FFFFFFFF"),
370 .toolTipBorder = QColor(
"#1AFFFFFF"),
371 .toolTipBase = QColor(
"#404040"),
392 const auto palettes = makePalettesColorsLight(accentColor);
395 .palettes = palettes,
396 .button = makeButtonPaletteColorsLight(accentColor),
397 .toolButton = makeToolButtonPaletteColorsLight(),
398 .system = makeSystemButtonPaletteColorsLight(),
399 .menu = makeMenuPaletteColorsLight(palettes),
400 .tabBar = makeTabBarPaletteColorsLight(accentColor),
401 .textLineEdit = makeTextLineEditPaletteColorsLight(),
402 .comboBox = makeComboBoxPaletteColorsLight(),
403 .groupBox = makeGroupboxPaletteColorsLight(),
404 .header = makeHeaderPaletteColorsLight(),
405 .toolTip = makeTooltipPaletteColorsLight(),
411 const auto palettes = makePalettesColorsDark(accentColor);
414 .palettes = palettes,
415 .button = makeButtonPaletteColorsDark(accentColor),
416 .toolButton = makeToolButtonPaletteColorsDark(),
417 .system = makeSystemButtonPaletteColorsDark(),
418 .menu = makeMenuPaletteColorsDark(palettes),
419 .tabBar = makeTabBarPaletteColorsDark(accentColor),
420 .textLineEdit = makeTextLineEditPaletteColorsDark(),
421 .comboBox = makeComboBoxPaletteColorsDark(),
422 .groupBox = makeGroupboxPaletteColorsDark(),
423 .header = makeHeaderPaletteColorsDark(),
424 .toolTip = makeTooltipPaletteColorsDark(),
431 case Qt::ColorScheme::Light:
return makeAllPalettesColorsLight(accentColor);
432 case Qt::ColorScheme::Dark:
return makeAllPalettesColorsDark(accentColor);
437 qOhosReportFatalErrorAndAbort(
438 "%s: got unsupported ColorScheme: %d", Q_FUNC_INFO,
static_cast<
int>(scheme));
445 const QPalette &basePalette, std::initializer_list<std::tuple<QPalette::ColorGroup, QPalette::ColorRole,
const QColor &>> brushEntries)
447 auto palette = basePalette;
449 for (
const auto &brushEntry : brushEntries) {
451 std::get<QPalette::ColorGroup>(brushEntry),
452 std::get<QPalette::ColorRole>(brushEntry),
453 std::get<
const QColor &>(brushEntry));
461 const auto &colors = palettesColors.palettes;
462 const auto button = makeOverlayCompositedOnSurface(
463 palettesColors.button.activeButton, colors.activeWindow);
465 QPalette palette(button, colors.activeWindow);
467 const auto textVersions = {
468 std::make_pair(QPalette::Active, colors.textPrimary),
469 std::make_pair(QPalette::Inactive, colors.inactiveTextPrimary),
470 std::make_pair(QPalette::Disabled, colors.disabledTextPrimary)};
472 for (
const auto &groupAndText : textVersions) {
473 palette.setColor(groupAndText.first, QPalette::WindowText, groupAndText.second);
474 palette.setColor(groupAndText.first, QPalette::Text, groupAndText.second);
475 palette.setColor(groupAndText.first, QPalette::ButtonText, groupAndText.second);
477 palette.setColor(QPalette::BrightText, colors.foregroundContrary);
485 makeBasePalette(palettesColors),
487 {QPalette::Active, QPalette::AlternateBase, palettesColors.palettes.componentActivated},
489 {QPalette::Active, QPalette::Button, palettesColors.button.activeButton},
490 {QPalette::Disabled, QPalette::Button, palettesColors.button.inactiveButton},
491 {QPalette::Inactive, QPalette::Button, palettesColors.button.inactiveButton},
493 {QPalette::Active, QPalette::ButtonText, palettesColors.palettes.activeButtonText},
494 {QPalette::Disabled, QPalette::ButtonText, palettesColors.palettes.inactiveButtonText},
495 {QPalette::Inactive, QPalette::ButtonText, palettesColors.palettes.inactiveButtonText},
497 {QPalette::All, QPalette::BrightText, palettesColors.button.enabledDefaultButtonText},
499 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
500 {QPalette::Active, QPalette::Dark, palettesColors.palettes.clickEffect},
502 {QPalette::Active, QPalette::Highlight, palettesColors.button.focusedOutline},
503 {QPalette::Active, QPalette::WindowText, palettesColors.palettes.indicatorArrow}
510 makeButtonPalette(palettesColors),
512 {QPalette::Active, QPalette::AlternateBase, palettesColors.toolButton.windowButtonBackground},
519 makeBasePalette(palettesColors),
521 {QPalette::Active, QPalette::Window, palettesColors.palettes.activeWindow},
522 {QPalette::Disabled, QPalette::Window, palettesColors.palettes.inactiveWindow},
523 {QPalette::Inactive, QPalette::Window, palettesColors.palettes.inactiveWindow},
525 {QPalette::Active, QPalette::WindowText, palettesColors.palettes.textPrimary},
526 {QPalette::Disabled, QPalette::WindowText, palettesColors.palettes.disabledTextPrimary},
527 {QPalette::Inactive, QPalette::WindowText, palettesColors.palettes.inactiveTextPrimary},
529 {QPalette::Active, QPalette::Text, palettesColors.palettes.textPrimary},
530 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.disabledTextPrimary},
531 {QPalette::Inactive, QPalette::Text, palettesColors.palettes.inactiveTextPrimary},
533 {QPalette::Active, QPalette::Base, palettesColors.palettes.window},
534 {QPalette::Disabled, QPalette::Base, palettesColors.palettes.window},
535 {QPalette::Inactive, QPalette::Base, palettesColors.palettes.window},
537 {QPalette::Active, QPalette::AlternateBase, palettesColors.palettes.textPrimary},
539 {QPalette::Active, QPalette::Highlight, palettesColors.palettes.highlighted},
541 {QPalette::All, QPalette::PlaceholderText, palettesColors.system.textHint},
542 {QPalette::Disabled, QPalette::PlaceholderText, palettesColors.system.textTertiary},
544 {QPalette::Active, QPalette::Midlight, palettesColors.palettes.scrollBarSlider},
546 {QPalette::Active, QPalette::Mid, palettesColors.palettes.componentNormal}
553 makeBasePalette(palettesColors),
555 {QPalette::Inactive, QPalette::Base, palettesColors.palettes.switchBgOff},
556 {QPalette::Inactive, QPalette::Button, palettesColors.palettes.switchOutlineOff},
557 {QPalette::Active, QPalette::Button, palettesColors.palettes.highlighted},
558 {QPalette::Active, QPalette::Highlight, palettesColors.palettes.highlighted},
559 {QPalette::Active, QPalette::WindowText, palettesColors.palettes.highlighted},
560 {QPalette::Inactive, QPalette::WindowText, palettesColors.palettes.inactiveText},
561 {QPalette::Disabled, QPalette::WindowText, palettesColors.palettes.inactiveHighlighted},
562 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
563 {QPalette::Active, QPalette::Dark, palettesColors.palettes.clickEffect},
570 makeBasePalette(palettesColors),
572 {QPalette::Active, QPalette::AlternateBase, palettesColors.palettes.componentActivated},
573 {QPalette::All, QPalette::Base, palettesColors.palettes.window},
574 {QPalette::All, QPalette::Window, palettesColors.palettes.window},
575 {QPalette::Active, QPalette::Text, palettesColors.palettes.highlighted},
576 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.inactiveText},
577 {QPalette::Inactive, QPalette::Text, palettesColors.palettes.inactiveHighlighted},
578 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
579 {QPalette::Active, QPalette::Dark, palettesColors.palettes.clickEffect},
580 {QPalette::Active, QPalette::WindowText, palettesColors.palettes.indicatorArrow},
581 {QPalette::All, QPalette::Button, palettesColors.comboBox.buttonBackground}
588 makeBasePalette(palettesColors),
590 {QPalette::Active, QPalette::Window, palettesColors.palettes.activeWindow},
591 {QPalette::Inactive, QPalette::Base, palettesColors.palettes.switchBgOff},
592 {QPalette::Inactive, QPalette::Button, palettesColors.palettes.switchOutlineOff},
593 {QPalette::Active, QPalette::Button, palettesColors.palettes.highlighted},
595 {QPalette::Active, QPalette::Text, palettesColors.palettes.textPrimary},
596 {QPalette::Disabled, QPalette::Text, palettesColors.menu.inactiveText},
597 {QPalette::Inactive, QPalette::Text, palettesColors.menu.inactiveText},
599 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
600 {QPalette::Active, QPalette::Dark, palettesColors.palettes.clickEffect},
602 {QPalette::Active, QPalette::Mid, palettesColors.menu.listSeparator}
609 makeBasePalette(palettesColors),
611 {QPalette::Active, QPalette::ButtonText, palettesColors.palettes.textPrimary},
612 {QPalette::Disabled, QPalette::ButtonText, palettesColors.menu.inactiveText},
613 {QPalette::Inactive, QPalette::ButtonText, palettesColors.menu.inactiveText},
620 makeBasePalette(palettesColors),
622 {QPalette::Active, QPalette::WindowText, palettesColors.tabBar.activeWindowText},
623 {QPalette::Inactive, QPalette::WindowText, palettesColors.tabBar.inactiveWindowText},
624 {QPalette::Disabled, QPalette::WindowText, palettesColors.tabBar.disabledWindowText},
626 {QPalette::Active, QPalette::Window, palettesColors.palettes.activeWindow},
627 {QPalette::Inactive, QPalette::Window, palettesColors.palettes.inactiveWindow},
628 {QPalette::Disabled, QPalette::Window, palettesColors.palettes.inactiveWindow},
630 {QPalette::Active, QPalette::Highlight, palettesColors.palettes.activeHighlight},
631 {QPalette::Inactive, QPalette::Highlight, palettesColors.palettes.inactiveHighlight},
632 {QPalette::Disabled, QPalette::Highlight, palettesColors.palettes.inactiveHighlight},
639 makeSystemPalette(palettesColors),
641 {QPalette::Active, QPalette::AlternateBase, palettesColors.palettes.componentActivated},
642 {QPalette::All, QPalette::Base, palettesColors.textLineEdit.textEditBackground},
643 {QPalette::Disabled, QPalette::Base, palettesColors.textLineEdit.inactiveTextEditBackground},
644 {QPalette::All, QPalette::Text, palettesColors.palettes.textPrimary},
645 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.disabledTextPrimary},
652 makeTextLineEditPalette(palettesColors),
654 {QPalette::All, QPalette::Base, palettesColors.palettes.activeWindow},
661 makeBasePalette(palettesColors),
663 {QPalette::Active, QPalette::Button, palettesColors.palettes.highlighted},
664 {QPalette::Inactive, QPalette::Button, palettesColors.palettes.switchOutlineOff},
665 {QPalette::Active, QPalette::Base, palettesColors.system.activeWindowFrame},
666 {QPalette::Inactive, QPalette::Base, palettesColors.palettes.switchBgOff},
667 {QPalette::Active, QPalette::AlternateBase, palettesColors.groupBox.groupBoxFrame},
668 {QPalette::Active, QPalette::Window, palettesColors.groupBox.background},
669 {QPalette::Inactive, QPalette::Window, palettesColors.groupBox.background},
670 {QPalette::Active, QPalette::Window, palettesColors.palettes.window},
671 {QPalette::Disabled, QPalette::Window, palettesColors.palettes.window},
672 {QPalette::Active, QPalette::Text, palettesColors.palettes.highlighted},
673 {QPalette::Inactive, QPalette::Text, palettesColors.palettes.highlighted},
674 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.inactiveHighlighted},
675 {QPalette::Current, QPalette::Text, palettesColors.palettes.highlighted},
676 {QPalette::Disabled, QPalette::WindowText, palettesColors.palettes.inactiveHighlighted},
677 {QPalette::Active, QPalette::ButtonText, palettesColors.palettes.textPrimary},
678 {QPalette::Disabled, QPalette::ButtonText, palettesColors.palettes.inactiveHighlighted},
679 {QPalette::Active, QPalette::Dark, palettesColors.palettes.clickEffect},
680 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
681 {QPalette::Active, QPalette::Shadow, palettesColors.groupBox.shadowXS},
682 {QPalette::Active, QPalette::Midlight, palettesColors.palettes.scrollBarSlider},
683 {QPalette::Active, QPalette::Mid, palettesColors.palettes.componentNormal}
690 makeBasePalette(palettesColors),
692 {QPalette::Active, QPalette::Button, palettesColors.header.activeButton},
693 {QPalette::Inactive, QPalette::Button, palettesColors.header.activeButton},
694 {QPalette::Disabled, QPalette::Button, palettesColors.palettes.inactiveWindow},
696 {QPalette::Current, QPalette::ButtonText, palettesColors.palettes.activeButtonText},
697 {QPalette::Active, QPalette::ButtonText, palettesColors.palettes.activeButtonText},
698 {QPalette::Inactive, QPalette::ButtonText, palettesColors.palettes.activeButtonText},
699 {QPalette::Disabled, QPalette::ButtonText, palettesColors.palettes.inactiveButtonText},
706 makeSystemPalette(palettesColors),
708 {QPalette::Active, QPalette::Base, palettesColors.palettes.window},
709 {QPalette::Inactive, QPalette::Base, palettesColors.palettes.window},
710 {QPalette::Disabled, QPalette::Base, palettesColors.palettes.window},
712 {QPalette::Active, QPalette::AlternateBase, palettesColors.palettes.activeWindow},
713 {QPalette::Inactive, QPalette::AlternateBase, palettesColors.palettes.activeWindow},
714 {QPalette::Disabled, QPalette::AlternateBase, palettesColors.palettes.inactiveWindow},
715 {QPalette::Current, QPalette::AlternateBase, palettesColors.palettes.activeWindow},
717 {QPalette::Active, QPalette::Highlight, palettesColors.palettes.activeHighlight},
718 {QPalette::Inactive, QPalette::Highlight, palettesColors.palettes.activeHighlight},
719 {QPalette::Disabled, QPalette::Highlight, palettesColors.palettes.inactiveHighlight},
721 {QPalette::Active, QPalette::Window, palettesColors.palettes.activeWindow},
722 {QPalette::Inactive, QPalette::Window, palettesColors.palettes.activeWindow},
723 {QPalette::Disabled, QPalette::Window, palettesColors.palettes.inactiveWindow},
725 {QPalette::Active, QPalette::Text, palettesColors.palettes.activeHighlight},
726 {QPalette::Inactive, QPalette::Text, palettesColors.palettes.activeHighlight},
727 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.inactiveHighlight},
729 {QPalette::Active, QPalette::HighlightedText, palettesColors.palettes.activeWindow},
730 {QPalette::Inactive, QPalette::HighlightedText, palettesColors.palettes.activeWindow},
731 {QPalette::Disabled, QPalette::HighlightedText, palettesColors.palettes.inactiveWindow},
733 {QPalette::Active, QPalette::Dark, palettesColors.palettes.activeWindow},
734 {QPalette::Inactive, QPalette::Dark, palettesColors.palettes.activeWindow},
735 {QPalette::Disabled, QPalette::Dark, palettesColors.palettes.inactiveWindow},
736 {QPalette::Current, QPalette::Dark, palettesColors.palettes.activeWindow},
737 {QPalette::All, QPalette::Dark, palettesColors.palettes.activeWindow},
739 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
740 {QPalette::Inactive, QPalette::Light, palettesColors.palettes.activeWindow},
741 {QPalette::Disabled, QPalette::Light, palettesColors.palettes.inactiveWindow},
743 {QPalette::Active, QPalette::Mid, palettesColors.palettes.activeWindow},
744 {QPalette::Inactive, QPalette::Mid, palettesColors.palettes.activeWindow},
745 {QPalette::Disabled, QPalette::Mid, palettesColors.palettes.inactiveWindow},
746 {QPalette::Current, QPalette::Mid, palettesColors.palettes.activeWindow},
747 {QPalette::All, QPalette::Mid, palettesColors.palettes.activeWindow},
754 makeBasePalette(palettesColors),
756 {QPalette::Active, QPalette::WindowText, palettesColors.palettes.textPrimary},
757 {QPalette::Disabled, QPalette::WindowText, palettesColors.palettes.disabledTextPrimary},
758 {QPalette::Inactive, QPalette::WindowText, palettesColors.palettes.inactiveTextPrimary},
760 {QPalette::Active, QPalette::Text, palettesColors.palettes.textPrimary},
761 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.disabledTextPrimary},
762 {QPalette::Inactive, QPalette::Text, palettesColors.palettes.inactiveTextPrimary},
769 makeBasePalette(palettesColors),
771 {QPalette::All, QPalette::Base, palettesColors.toolTip.toolTipBorder},
772 {QPalette::All, QPalette::ToolTipBase, palettesColors.toolTip.toolTipBase},
773 {QPalette::All, QPalette::ToolTipText, palettesColors.palettes.highlighted},
779 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
780 font.setPointSize(12);
788 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
789 font.setPointSize(20);
797 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
798 font.setPointSize(16);
805 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
806 font.setPointSize(16);
813 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
814 font.setPointSize(16);
821 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
822 font.setPointSize(14);
829 const AllPalletesColors palettesColors = makeAllPalettesColors(scheme, accentColor);
831 {QPlatformTheme::ButtonPalette, makeButtonPalette(palettesColors)},
832 {QPlatformTheme::CheckBoxPalette, makeCheckBoxOrRadioButtonPalette(palettesColors)},
833 {QPlatformTheme::ComboBoxPalette, makeComboBoxPalette(palettesColors)},
834 {QPlatformTheme::GroupBoxPalette, makeGroupBoxPalette(palettesColors)},
835 {QPlatformTheme::HeaderPalette, makeHeaderPalette(palettesColors)},
836 {QPlatformTheme::ItemViewPalette, makeItemViewPalette(palettesColors)},
837 {QPlatformTheme::LabelPalette, makeLabelPalette(palettesColors)},
838 {QPlatformTheme::MenuPalette, makeMenuPalette(palettesColors)},
839 {QPlatformTheme::MenuBarPalette, makeMenuBarPalette(palettesColors)},
840 {QPlatformTheme::RadioButtonPalette, makeCheckBoxOrRadioButtonPalette(palettesColors)},
841 {QPlatformTheme::SystemPalette, makeSystemPalette(palettesColors)},
842 {QPlatformTheme::TabBarPalette, makeTabBarPalette(palettesColors)},
843 {QPlatformTheme::TextEditPalette, makeTextEditPalette(palettesColors)},
844 {QPlatformTheme::TextLineEditPalette, makeTextLineEditPalette(palettesColors)},
845 {QPlatformTheme::ToolButtonPalette, makeToolButtonPalette(palettesColors)},
846 {QPlatformTheme::ToolTipPalette, makeToolTipPalette(palettesColors)},
851 Qt::ColorScheme scheme)
854 case Qt::ColorScheme::Unknown:
856 case Qt::ColorScheme::Light:
858 case Qt::ColorScheme::Dark:
865 std::optional<
bool> darkModeFlag)
867 if (darkModeFlag.has_value()) {
868 if (!darkModeFlag.value_or(
false))
869 return Qt::ColorScheme::Light;
871 return Qt::ColorScheme::Dark;
873 return Qt::ColorScheme::Unknown;
883 return optColorMode.value_or(fallbackColorMode);
889 qCWarning(QtForOhos,
"%s: cannot set a color mode in 'no UI child mode'", Q_FUNC_INFO);
893 QOhosJsThreadGateway::runAndWait(
894 [&](QOhosJsState &jsState) {
895 auto optQAbility = jsState.defaultQAbility();
897 qCWarning(QtForOhos,
"%s: cannot set a color mode without a UIAbility", Q_FUNC_INFO);
901 const auto jsColorMode = jsState.mapOhosEnumToJs(colorMode);
902 optQAbility->eval(
"context.getApplicationContext().setColorMode(*)", {jsColorMode});
908 QOhosConsumer<OhosConfigurationColorMode> valueChangedHandler)
911 [](QOhosJsState &jsState) {
912 auto optQAbility = jsState.defaultQAbility();
914 ? mapOhosConfigurationColorModeFromJs(
915 jsState, optQAbility->eval<QNapi::Number>(
"context.config.colorMode"))
916 : OhosConfigurationColorMode::COLOR_MODE_NOT_SET;
918 [](QOhosJsState &jsState,
const QNapi::Object &config) {
919 return mapOhosConfigurationColorModeFromJs(jsState, config.get<QNapi::Number>(
"colorMode"));
921 std::move(valueChangedHandler));
940 auto optQAbility = jsState.defaultQAbility();
944 const auto argb =
static_cast<uint32_t>(
945 optQAbility->eval<QNapi::Number>(
946 "context.resourceManager.getColorByNameSync(*)",
947 {
"ohos_id_color_emphasize"}));
948 return QColor::fromRgba(argb);
953 return QtOhos::makeOhosConfigValueDataSource<QColor>(
955 [](QOhosJsState &jsState,
const QNapi::Object &) {
956 return readAccentColor(jsState);
958 std::move(accentColorChangedHandler));
963 std::string undocumentedParamsPropertyName(
"params");
964 auto optParams = QNapi::getOptionalPropOrEmpty<QNapi::Value>(resource, undocumentedParamsPropertyName);
965 if (optParams.IsEmpty()) {
967 "%s: expected '%s' property not found in resource object, ignore getting pixmap",
968 Q_FUNC_INFO, undocumentedParamsPropertyName.c_str());
971 if (!optParams.IsArray()) {
973 "%s: '%s' property is not an array, ignore getting pixmap",
974 Q_FUNC_INFO, undocumentedParamsPropertyName.c_str());
978 auto params = QNapi::getArrayElements<std::vector<std::string>, QNapi::String>(
979 QNapi::checkedCast<QNapi::Array>(optParams));
980 if (params.empty()) {
982 "%s: '%s' property is empty, ignore getting pixmap",
983 Q_FUNC_INFO, undocumentedParamsPropertyName.c_str());
987 const auto resourceIdentifier = params.front();
988 const auto lastSeparatorPosition = resourceIdentifier.rfind(
'.');
989 if (lastSeparatorPosition == std::string::npos) {
991 "%s: '%s' property has unknown resource name, ignore getting pixmap",
992 Q_FUNC_INFO, undocumentedParamsPropertyName.c_str());
996 const auto simpleName = resourceIdentifier.substr(lastSeparatorPosition + 1);
997 auto resourceContentBuffer = jsState.eval<QNapi::TypedArrayOf<std::uint8_t>>(
998 "@ohos.resourceManager.getSysResourceManager().getMediaByNameSync(*)", {simpleName});
1001 bool pixmapLoadResult = pixmap.loadFromData(
1002 static_cast<
const uchar *>(resourceContentBuffer.Data()), resourceContentBuffer.ByteLength());
1004 if (pixmapLoadResult) {
1007 qOhosPrintfWarning(
"%s: cannot load pixmap", Q_FUNC_INFO);
1008 return std::nullopt;
1013 QOhosJsState &jsState,
const std::string &filenameExtension)
1015 std::string ohosDotFilenameExtension =
"." + filenameExtension;
1016 auto uniformDataType = jsState.eval<QNapi::String>(
1017 "@ohos.data.uniformTypeDescriptor.getUniformDataTypeByFilenameExtension(*)",
1018 {ohosDotFilenameExtension});
1020 auto resourceValue = jsState.eval(
1021 "@kit.FileManagerServiceKit.fileManagerService.getFileIconSync(*)", {uniformDataType});
1022 if (resourceValue.IsObject()) {
1023 return tryGetFilePixmapByResourceObject(jsState, QNapi::checkedCast<QNapi::Object>(resourceValue));
1025 qOhosPrintfWarning(
"%s: got unhandled resource result type, ignore it", Q_FUNC_INFO);
1026 return std::nullopt;
1046 auto fileNameSuffix = fileInfo().suffix();
1047 auto optPixmap = QOhosJsThreadGateway::eval(
1048 [&](QOhosJsState &jsState) {
1049 return tryGetFilePixmapByFilenameExtension(jsState, fileNameSuffix.toStdString());
1053 return optPixmap.has_value()
1054 ? optPixmap.value().scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation)
1074 auto colorModeDataSource = makeOhosConfigColorModeDataSource(
1077 QWindowSystemInterface::handleThemeChange<QWindowSystemInterface::SynchronousDelivery>();
1079 m_ohosConfigDarkModeFlagSupplier = [colorModeDataSource = std::move(colorModeDataSource)]() {
1080 return mapOhosConfigurationColorModeToDarkModeFlag(colorModeDataSource());
1083 m_ohosAccentColorSupplier = makeOhosAccentColorDataSource(
1084 [
this](
const auto &) {
1086 QWindowSystemInterface::handleThemeChange<QWindowSystemInterface::SynchronousDelivery>();
1094 std::optional<
bool> isDarkMode = mapOhosThemeFromColorScheme(scheme);
1095 setOhosConfigColorMode(
1096 isDarkMode.has_value()
1097 ? isDarkMode.value()
1105 return mapOhosThemeToColorScheme(m_ohosConfigDarkModeFlagSupplier());
1110 if (
const auto currentColorScheme = colorScheme(); currentColorScheme != Qt::ColorScheme::Unknown)
1111 m_themePalette = makePalettesMap(currentColorScheme, m_ohosAccentColorSupplier());
1116 auto _dbg = make_QCScopedDebug(
"QOhosPlatformTheme::createPlatformDialogHelper");
1117 return QOhosDialogs::createHelper(type);
1122 auto _dbg = make_QCScopedDebug(
"QOhosPlatformTheme::usePlatformNativeDialog");
1123 return (type == QOhosPlatformTheme::FileDialog);
1130 return QStringList(QString::fromUtf8(ohosThemeName));
1131 case MouseDoubleClickDistance:
1132 case TouchDoubleTapDistance:
1134 auto *primaryScreen = qGuiApp->primaryScreen();
1135 auto *platformScreen = primaryScreen !=
nullptr
1138 return platformScreen !=
nullptr
1139 ? QHighDpi::fromNativePixels(
1141 mouseDoubleClickDistance, platformScreen->pixelScalingCoefficient()),
1143 : mouseDoubleClickDistance;
1145 case MouseDoubleClickInterval:
1147 case WheelScrollLines:
1148 return m_wheelScrollLines;
1149 case MenuBarFocusOnAltPressRelease:
1151 case PreferFileIconFromTheme:
1154 return QPlatformTheme::themeHint(hint);
1160 if (
const auto it = m_themePalette.find(type); it != m_themePalette.end())
1162 return QPlatformTheme::palette(type);
1167 const auto fontIter = m_fonts.find(type);
1168 return fontIter != m_fonts.end()
1170 : QPlatformTheme::font(type);
1175 m_wheelScrollLines = wheelScrollLines;
1180 return makeQOhosSystemTrayIcon().release();
1185 return !fileInfo.suffix().isEmpty()
1186 ? QIcon(
new QOhosFileIconEngine(fileInfo, iconOptions))
1187 : QPlatformTheme::fileIcon(fileInfo, iconOptions);
1192 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)
QOhosSupplier< OhosConfigurationColorMode > makeOhosConfigColorModeDataSource(QOhosConsumer< OhosConfigurationColorMode > valueChangedHandler)
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()
QOhosSupplier< QColor > makeOhosAccentColorDataSource(QOhosConsumer< QColor > accentColorChangedHandler)
GroupboxPaletteColors makeGroupboxPaletteColorsDark()
std::optional< QPixmap > tryGetFilePixmapByFilenameExtension(QOhosJsState &jsState, const std::string &filenameExtension)
TabBarPaletteColors makeTabBarPaletteColorsLight(const QColor &accentColor)
QPalette makeHeaderPalette(const AllPalletesColors &palettesColors)
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)
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
QColor inactiveTextPrimary
QColor foregroundContrary
QColor disabledTextPrimary
QColor componentActivated
QColor inactiveButtonText
QColor inactiveHighlighted
QColor disabledWindowText
QColor inactiveWindowText
QColor inactiveTextEditBackground
QColor textEditBackground