Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qohosplatformtheme.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
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>
24#include <string>
25#include <tuple>
26
28
29namespace {
30
32{
33 auto disabledColor = color;
34 disabledColor.setAlphaF(qBound(0.0, color.alphaF() * 0.4, 1.0));
35
36 return disabledColor;
37}
38
64
65PalettesColors makePalettesColorsLight(const QColor &accentColor)
66{
67 const auto activeWindow = QColor("#FFFFFFFF");
68 const auto activeButtonText = QColor("#0A59F7");
69 const auto textPrimary = QColor("#FF182431");
70
71 return {
72 .activeWindow = activeWindow,
73 .inactiveWindow = makeInactiveOrDisabledFromColor(activeWindow),
74 .activeButtonText = activeButtonText,
75 .inactiveButtonText = makeInactiveOrDisabledFromColor(activeButtonText),
76 .activeHighlight = accentColor,
77 .inactiveHighlight = makeInactiveOrDisabledFromColor(accentColor),
78 .clickEffect = QColor("#1A000000"),
79 .hover = QColor("#0D000000"),
80 .foregroundContrary = QColor("#FFFFFF"),
81 .highlighted = accentColor,
82 .inactiveHighlighted = makeInactiveOrDisabledFromColor(accentColor),
83 .textPrimary = textPrimary,
84 .inactiveTextPrimary = textPrimary,
85 .disabledTextPrimary = makeInactiveOrDisabledFromColor(textPrimary),
86 .inactiveText = makeInactiveOrDisabledFromColor(textPrimary),
87 .componentNormal = QColor("#19182431"),
88 .componentActivated = QColor("#007DFF"),
89 .indicatorArrow = QColor("#E5182431"),
90 .scrollBarSlider = QColor("#182431"),
91 .switchBgOff = QColor("#33FFFFFF"),
92 .switchOutlineOff = QColor("#66182431"),
93 .window = QColor("#FFF1F3F5"),
94 };
95};
96
97PalettesColors makePalettesColorsDark(const QColor &accentColor)
98{
99 const auto activeWindow = QColor("#18181A");
100 const auto activeButtonText = QColor("#3F97E9");
101 const auto textPrimary = QColor("#DBFFFFFF");
102
103 return {
104 .activeWindow = activeWindow,
105 .inactiveWindow = makeInactiveOrDisabledFromColor(activeWindow),
106 .activeButtonText = activeButtonText,
107 .inactiveButtonText = makeInactiveOrDisabledFromColor(activeButtonText),
108 .activeHighlight = accentColor,
109 .inactiveHighlight = makeInactiveOrDisabledFromColor(accentColor),
110 .clickEffect = QColor("#26FFFFFF"),
111 .hover = QColor("#19FFFFFF"),
112 .foregroundContrary = QColor("#E5E5E5"),
113 .highlighted = accentColor,
114 .inactiveHighlighted = makeInactiveOrDisabledFromColor(accentColor),
115 .textPrimary = textPrimary,
116 .inactiveTextPrimary = textPrimary,
117 .disabledTextPrimary = makeInactiveOrDisabledFromColor(textPrimary),
118 .inactiveText = makeInactiveOrDisabledFromColor(textPrimary),
119 .componentNormal = QColor("#19FFFFFF"),
120 .componentActivated = QColor("#3F97E9"),
121 .indicatorArrow = QColor("#DBFFFFFF"),
122 .scrollBarSlider = QColor("#FFFFFF"),
123 .switchBgOff = QColor("#33000000"),
124 .switchOutlineOff = QColor("#66FFFFFF"),
125 .window = QColor("#FF000000"),
126 };
127}
128
136
138{
139 const auto activeButton = QColor("#0C182431");
140
141 return {
142 .activeButton = activeButton,
143 .inactiveButton = makeInactiveOrDisabledFromColor(activeButton),
144 .focusedOutline = accentColor,
145 .enabledDefaultButtonText = QColor("#FFFFFFFF"),
146 };
147};
148
150{
151 const auto activeButton = QColor("#19FFFFFF");
152
153 return {
154 .activeButton = activeButton,
155 .inactiveButton = makeInactiveOrDisabledFromColor(activeButton),
156 .focusedOutline = accentColor,
157 .enabledDefaultButtonText = QColor("#E5E5E5"),
158 };
159}
160
165
167{
168 return {
169 .windowButtonBackground = QColor("#FFD0CFD5"),
170 };
171};
172
174{
175 return {
176 .windowButtonBackground = QColor("#FFD0CFD5"),
177 };
178};
179
187
189{
190 return {
191 .activeWindowFrame = QColor("#FFE4E4E4"),
192 .inactiveWindowFrame = QColor("#FFF2F3F5"),
193 .textHint = QColor("#99182431"),
194 .textTertiary = QColor("#66182431"),
195 };
196};
197
199{
200 return {
201 .activeWindowFrame = QColor("#FF000000"),
202 .inactiveWindowFrame = QColor("#FF18181A"),
203 .textHint = QColor("#99FFFFFF"),
204 .textTertiary = QColor("#66FFFFFF"),
205 };
206}
207
213
215{
216 return {
217 .listSeparator = QColor("#1A000000"),
218 .inactiveText = makeInactiveOrDisabledFromColor(palettes.textPrimary),
219 };
220};
221
223{
224 return {
225 .listSeparator = QColor("#33FFFFFF"),
226 .inactiveText = makeInactiveOrDisabledFromColor(palettes.textPrimary),
227 };
228}
229
236
238{
239 const auto inactiveWindowText = QColor("#99182431");
240
241 return {
242 .activeWindowText = accentColor,
243 .inactiveWindowText = inactiveWindowText,
244 .disabledWindowText = makeInactiveOrDisabledFromColor(inactiveWindowText),
245 };
246};
247
249{
250 const auto inactiveWindowText = QColor("#99FFFFFF");
251
252 return {
253 .activeWindowText = accentColor,
254 .inactiveWindowText = inactiveWindowText,
255 .disabledWindowText = makeInactiveOrDisabledFromColor(inactiveWindowText),
256 };
257}
258
264
266{
267 const auto textEditBackground = QColor("#0C182431");
268 return {
269 .textEditBackground = textEditBackground,
270 .inactiveTextEditBackground = makeInactiveOrDisabledFromColor(textEditBackground),
271 };
272};
273
275{
276 const auto textEditBackground = QColor("#19FFFFFF");
277 return {
278 .textEditBackground = textEditBackground,
279 .inactiveTextEditBackground = makeInactiveOrDisabledFromColor(textEditBackground),
280 };
281}
282
289
291{
292 return {
293 .background = QColor("#00000000"),
294 .groupBoxFrame = QColor("#66000000"),
295 .shadowXS = QColor("#19000000"),
296 };
297};
298
300{
301 return {
302 .background = QColor("#00000000"),
303 .groupBoxFrame = QColor("#66FFFFFF"),
304 .shadowXS = QColor("#19FFFFFF"),
305 };
306}
307
312
314{
315 return {
316 .activeButton = QColor("#FFFFFFFF"),
317 };
318};
319
321{
322 return {
323 .activeButton = QColor("#FF18181A"),
324 };
325}
326
332
334{
335 return {
336 .toolTipBorder = QColor("#1A000000"),
337 .toolTipBase = QColor("#FFFFFFFF"),
338 };
339};
340
342{
343 return {
344 .toolTipBorder = QColor("#1AFFFFFF"),
345 .toolTipBase = QColor("#404040"),
346 };
347}
348
362
364{
365 const auto palettes = makePalettesColorsLight(accentColor);
366
367 return {
368 .palettes = palettes,
369 .button = makeButtonPaletteColorsLight(accentColor),
370 .toolButton = makeToolButtonPaletteColorsLight(),
371 .system = makeSystemButtonPaletteColorsLight(),
372 .menu = makeMenuPaletteColorsLight(palettes),
373 .tabBar = makeTabBarPaletteColorsLight(accentColor),
374 .textLineEdit = makeTextLineEditPaletteColorsLight(),
375 .groupBox = makeGroupboxPaletteColorsLight(),
376 .header = makeHeaderPaletteColorsLight(),
377 .toolTip = makeTooltipPaletteColorsLight(),
378 };
379}
380
382{
383 const auto palettes = makePalettesColorsDark(accentColor);
384
385 return {
386 .palettes = palettes,
387 .button = makeButtonPaletteColorsDark(accentColor),
388 .toolButton = makeToolButtonPaletteColorsDark(),
389 .system = makeSystemButtonPaletteColorsDark(),
390 .menu = makeMenuPaletteColorsDark(palettes),
391 .tabBar = makeTabBarPaletteColorsDark(accentColor),
392 .textLineEdit = makeTextLineEditPaletteColorsDark(),
393 .groupBox = makeGroupboxPaletteColorsDark(),
394 .header = makeHeaderPaletteColorsDark(),
395 .toolTip = makeTooltipPaletteColorsDark(),
396 };
397}
398
399AllPalletesColors makeAllPalettesColors(Qt::ColorScheme scheme, const QColor &accentColor)
400{
401 switch (scheme) {
402 case Qt::ColorScheme::Light: return makeAllPalettesColorsLight(accentColor);
403 case Qt::ColorScheme::Dark: return makeAllPalettesColorsDark(accentColor);
404 default:
405 break;
406 }
407
408 qOhosReportFatalErrorAndAbort(
409 "%s: got unsupported ColorScheme: %d", Q_FUNC_INFO, static_cast<int>(scheme));
410}
411
412constexpr int mouseDoubleClickDistance = 60;
413constexpr int mouseDoubleClickInterval = 300;
414
416 const QPalette &basePalette, std::initializer_list<std::tuple<QPalette::ColorGroup, QPalette::ColorRole, const QColor &>> brushEntries)
417{
418 auto palette = basePalette;
419
420 for (const auto &brushEntry : brushEntries) {
421 palette.setBrush(
422 std::get<QPalette::ColorGroup>(brushEntry),
423 std::get<QPalette::ColorRole>(brushEntry),
424 std::get<const QColor &>(brushEntry));
425 }
426
427 return palette;
428}
429
430QPalette makePalette(std::initializer_list<std::tuple<QPalette::ColorGroup, QPalette::ColorRole, const QColor &>> brushEntries)
431{
432 return makePalette(QPalette(), brushEntries);
433}
434
436{
437 return makePalette(
438 {
439 {QPalette::Active, QPalette::AlternateBase, palettesColors.palettes.componentActivated},
440
441 {QPalette::Active, QPalette::Button, palettesColors.button.activeButton},
442 {QPalette::Disabled, QPalette::Button, palettesColors.button.inactiveButton},
443 {QPalette::Inactive, QPalette::Button, palettesColors.button.inactiveButton},
444
445 {QPalette::Active, QPalette::ButtonText, palettesColors.palettes.activeButtonText},
446 {QPalette::Disabled, QPalette::ButtonText, palettesColors.palettes.inactiveButtonText},
447 {QPalette::Inactive, QPalette::ButtonText, palettesColors.palettes.inactiveButtonText},
448
449 {QPalette::All, QPalette::BrightText, palettesColors.button.enabledDefaultButtonText},
450
451 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
452 {QPalette::Active, QPalette::Dark, palettesColors.palettes.clickEffect},
453
454 {QPalette::Active, QPalette::Highlight, palettesColors.button.focusedOutline},
455 {QPalette::Active, QPalette::WindowText, palettesColors.palettes.indicatorArrow}
456 });
457}
458
460{
461 return makePalette(
462 makeButtonPalette(palettesColors),
463 {
464 {QPalette::Active, QPalette::AlternateBase, palettesColors.toolButton.windowButtonBackground},
465 });
466}
467
469{
470 return makePalette(
471 {
472 {QPalette::Active, QPalette::Window, palettesColors.palettes.activeWindow},
473 {QPalette::Disabled, QPalette::Window, palettesColors.palettes.inactiveWindow},
474 {QPalette::Inactive, QPalette::Window, palettesColors.palettes.inactiveWindow},
475
476 {QPalette::Active, QPalette::WindowText, palettesColors.palettes.textPrimary},
477 {QPalette::Disabled, QPalette::WindowText, palettesColors.palettes.disabledTextPrimary},
478 {QPalette::Inactive, QPalette::WindowText, palettesColors.palettes.inactiveTextPrimary},
479
480 {QPalette::Active, QPalette::Text, palettesColors.palettes.textPrimary},
481 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.disabledTextPrimary},
482 {QPalette::Inactive, QPalette::Text, palettesColors.palettes.inactiveTextPrimary},
483
484 {QPalette::Active, QPalette::Base, palettesColors.system.activeWindowFrame},
485 {QPalette::Disabled, QPalette::Base, palettesColors.system.inactiveWindowFrame},
486 {QPalette::Inactive, QPalette::Base, palettesColors.system.inactiveWindowFrame},
487
488 {QPalette::Active, QPalette::AlternateBase, palettesColors.palettes.textPrimary},
489
490 {QPalette::Active, QPalette::Highlight, palettesColors.palettes.highlighted},
491
492 {QPalette::All, QPalette::PlaceholderText, palettesColors.system.textHint},
493 {QPalette::Disabled, QPalette::PlaceholderText, palettesColors.system.textTertiary},
494
495 {QPalette::Active, QPalette::Midlight, palettesColors.palettes.scrollBarSlider},
496
497 {QPalette::Active, QPalette::Mid, palettesColors.palettes.componentNormal}
498 });
499}
500
502{
503 return makePalette(
504 {
505 {QPalette::Inactive, QPalette::Base, palettesColors.palettes.switchBgOff},
506 {QPalette::Inactive, QPalette::Button, palettesColors.palettes.switchOutlineOff},
507 {QPalette::Active, QPalette::Button, palettesColors.palettes.highlighted},
508 {QPalette::Active, QPalette::WindowText, palettesColors.palettes.highlighted},
509 {QPalette::Inactive, QPalette::WindowText, palettesColors.palettes.inactiveText},
510 {QPalette::Disabled, QPalette::WindowText, palettesColors.palettes.inactiveHighlighted},
511 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
512 {QPalette::Active, QPalette::Dark, palettesColors.palettes.clickEffect},
513 });
514}
515
517{
518 return makePalette(
519 {
520 {QPalette::Active, QPalette::AlternateBase, palettesColors.palettes.componentActivated},
521 {QPalette::All, QPalette::Base, palettesColors.palettes.window},
522 {QPalette::All, QPalette::Window, palettesColors.palettes.window},
523 {QPalette::Active, QPalette::Text, palettesColors.palettes.highlighted},
524 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.inactiveText},
525 {QPalette::Inactive, QPalette::Text, palettesColors.palettes.inactiveHighlighted},
526 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
527 {QPalette::Active, QPalette::Dark, palettesColors.palettes.clickEffect},
528 {QPalette::Active, QPalette::WindowText, palettesColors.palettes.indicatorArrow}
529 });
530}
531
533{
534 return makePalette(
535 {
536 {QPalette::Active, QPalette::Window, palettesColors.palettes.activeWindow},
537 {QPalette::Inactive, QPalette::Base, palettesColors.palettes.switchBgOff},
538 {QPalette::Inactive, QPalette::Button, palettesColors.palettes.switchOutlineOff},
539 {QPalette::Active, QPalette::Button, palettesColors.palettes.highlighted},
540
541 {QPalette::Active, QPalette::Text, palettesColors.palettes.textPrimary},
542 {QPalette::Disabled, QPalette::Text, palettesColors.menu.inactiveText},
543 {QPalette::Inactive, QPalette::Text, palettesColors.menu.inactiveText},
544
545 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
546 {QPalette::Active, QPalette::Dark, palettesColors.palettes.clickEffect},
547
548 {QPalette::Active, QPalette::Mid, palettesColors.menu.listSeparator}
549 });
550}
551
553{
554 return makePalette(
555 {
556 {QPalette::Active, QPalette::ButtonText, palettesColors.palettes.textPrimary},
557 {QPalette::Disabled, QPalette::ButtonText, palettesColors.menu.inactiveText},
558 {QPalette::Inactive, QPalette::ButtonText, palettesColors.menu.inactiveText},
559 });
560}
561
563{
564 return makePalette(
565 {
566 {QPalette::Active, QPalette::WindowText, palettesColors.tabBar.activeWindowText},
567 {QPalette::Inactive, QPalette::WindowText, palettesColors.tabBar.inactiveWindowText},
568 {QPalette::Disabled, QPalette::WindowText, palettesColors.tabBar.disabledWindowText},
569
570 {QPalette::Active, QPalette::Window, palettesColors.palettes.activeWindow},
571 {QPalette::Inactive, QPalette::Window, palettesColors.palettes.inactiveWindow},
572 {QPalette::Disabled, QPalette::Window, palettesColors.palettes.inactiveWindow},
573
574 {QPalette::Active, QPalette::Highlight, palettesColors.palettes.activeHighlight},
575 {QPalette::Inactive, QPalette::Highlight, palettesColors.palettes.inactiveHighlight},
576 {QPalette::Disabled, QPalette::Highlight, palettesColors.palettes.inactiveHighlight},
577 });
578}
579
581{
582 return makePalette(
583 makeSystemPalette(palettesColors),
584 {
585 {QPalette::Active, QPalette::AlternateBase, palettesColors.palettes.componentActivated},
586 {QPalette::All, QPalette::Base, palettesColors.textLineEdit.textEditBackground},
587 {QPalette::Disabled, QPalette::Base, palettesColors.textLineEdit.inactiveTextEditBackground},
588 {QPalette::All, QPalette::Text, palettesColors.palettes.textPrimary},
589 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.disabledTextPrimary},
590 });
591}
592
594{
595 return makePalette(
596 makeTextLineEditPalette(palettesColors),
597 {
598 {QPalette::All, QPalette::Base, palettesColors.palettes.activeWindow},
599 });
600}
601
603{
604 return makePalette(
605 {
606 {QPalette::Active, QPalette::Button, palettesColors.palettes.highlighted},
607 {QPalette::Inactive, QPalette::Button, palettesColors.palettes.switchOutlineOff},
608 {QPalette::Active, QPalette::Base, palettesColors.system.activeWindowFrame},
609 {QPalette::Inactive, QPalette::Base, palettesColors.palettes.switchBgOff},
610 {QPalette::Active, QPalette::AlternateBase, palettesColors.groupBox.groupBoxFrame},
611 {QPalette::Active, QPalette::Window, palettesColors.groupBox.background},
612 {QPalette::Inactive, QPalette::Window, palettesColors.groupBox.background},
613 {QPalette::Active, QPalette::Window, palettesColors.palettes.window},
614 {QPalette::Disabled, QPalette::Window, palettesColors.palettes.window},
615 {QPalette::Active, QPalette::Text, palettesColors.palettes.highlighted},
616 {QPalette::Inactive, QPalette::Text, palettesColors.palettes.highlighted},
617 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.inactiveHighlighted},
618 {QPalette::Current, QPalette::Text, palettesColors.palettes.highlighted},
619 {QPalette::Disabled, QPalette::WindowText, palettesColors.palettes.inactiveHighlighted},
620 {QPalette::Active, QPalette::ButtonText, palettesColors.palettes.textPrimary},
621 {QPalette::Disabled, QPalette::ButtonText, palettesColors.palettes.inactiveHighlighted},
622 {QPalette::Active, QPalette::Dark, palettesColors.palettes.clickEffect},
623 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
624 {QPalette::Active, QPalette::Shadow, palettesColors.groupBox.shadowXS},
625 {QPalette::Active, QPalette::Midlight, palettesColors.palettes.scrollBarSlider},
626 {QPalette::Active, QPalette::Mid, palettesColors.palettes.componentNormal}
627 });
628}
629
631{
632 return makePalette(
633 {
634 {QPalette::Active, QPalette::Button, palettesColors.header.activeButton},
635 {QPalette::Inactive, QPalette::Button, palettesColors.header.activeButton},
636 {QPalette::Disabled, QPalette::Button, palettesColors.palettes.inactiveWindow},
637
638 {QPalette::Current, QPalette::ButtonText, palettesColors.palettes.activeButtonText},
639 {QPalette::Active, QPalette::ButtonText, palettesColors.palettes.activeButtonText},
640 {QPalette::Inactive, QPalette::ButtonText, palettesColors.palettes.activeButtonText},
641 {QPalette::Disabled, QPalette::ButtonText, palettesColors.palettes.inactiveButtonText},
642 });
643}
644
646{
647 return makePalette(
648 {
649 {QPalette::Active, QPalette::Base, palettesColors.palettes.window},
650 {QPalette::Inactive, QPalette::Base, palettesColors.palettes.window},
651 {QPalette::Disabled, QPalette::Base, palettesColors.palettes.window},
652
653 {QPalette::Active, QPalette::AlternateBase, palettesColors.palettes.activeWindow},
654 {QPalette::Inactive, QPalette::AlternateBase, palettesColors.palettes.activeWindow},
655 {QPalette::Disabled, QPalette::AlternateBase, palettesColors.palettes.inactiveWindow},
656 {QPalette::Current, QPalette::AlternateBase, palettesColors.palettes.activeWindow},
657
658 {QPalette::Active, QPalette::Highlight, palettesColors.palettes.activeHighlight},
659 {QPalette::Inactive, QPalette::Highlight, palettesColors.palettes.activeHighlight},
660 {QPalette::Disabled, QPalette::Highlight, palettesColors.palettes.inactiveHighlight},
661
662 {QPalette::Active, QPalette::Window, palettesColors.palettes.activeWindow},
663 {QPalette::Inactive, QPalette::Window, palettesColors.palettes.activeWindow},
664 {QPalette::Disabled, QPalette::Window, palettesColors.palettes.inactiveWindow},
665
666 {QPalette::Active, QPalette::Text, palettesColors.palettes.activeHighlight},
667 {QPalette::Inactive, QPalette::Text, palettesColors.palettes.activeHighlight},
668 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.inactiveHighlight},
669
670 {QPalette::Active, QPalette::HighlightedText, palettesColors.palettes.activeWindow},
671 {QPalette::Inactive, QPalette::HighlightedText, palettesColors.palettes.activeWindow},
672 {QPalette::Disabled, QPalette::HighlightedText, palettesColors.palettes.inactiveWindow},
673
674 {QPalette::Active, QPalette::Dark, palettesColors.palettes.activeWindow},
675 {QPalette::Inactive, QPalette::Dark, palettesColors.palettes.activeWindow},
676 {QPalette::Disabled, QPalette::Dark, palettesColors.palettes.inactiveWindow},
677 {QPalette::Current, QPalette::Dark, palettesColors.palettes.activeWindow},
678 {QPalette::All, QPalette::Dark, palettesColors.palettes.activeWindow},
679
680 {QPalette::Active, QPalette::Light, palettesColors.palettes.hover},
681 {QPalette::Inactive, QPalette::Light, palettesColors.palettes.activeWindow},
682 {QPalette::Disabled, QPalette::Light, palettesColors.palettes.inactiveWindow},
683
684 {QPalette::Active, QPalette::Mid, palettesColors.palettes.activeWindow},
685 {QPalette::Inactive, QPalette::Mid, palettesColors.palettes.activeWindow},
686 {QPalette::Disabled, QPalette::Mid, palettesColors.palettes.inactiveWindow},
687 {QPalette::Current, QPalette::Mid, palettesColors.palettes.activeWindow},
688 {QPalette::All, QPalette::Mid, palettesColors.palettes.activeWindow},
689 });
690}
691
693{
694 return makePalette(
695 {
696 {QPalette::Active, QPalette::WindowText, palettesColors.palettes.highlighted},
697 {QPalette::Inactive, QPalette::WindowText, palettesColors.palettes.inactiveText},
698 {QPalette::Disabled, QPalette::WindowText, palettesColors.palettes.inactiveHighlighted},
699
700 {QPalette::Active, QPalette::Text, palettesColors.palettes.highlighted},
701 {QPalette::Disabled, QPalette::Text, palettesColors.palettes.inactiveText},
702 {QPalette::Inactive, QPalette::Text, palettesColors.palettes.inactiveHighlighted},
703 });
704}
705
707{
708 return makePalette(
709 {
710 {QPalette::All, QPalette::Base, palettesColors.toolTip.toolTipBorder},
711 {QPalette::All, QPalette::ToolTipBase, palettesColors.toolTip.toolTipBase},
712 {QPalette::All, QPalette::ToolTipText, palettesColors.palettes.highlighted},
713 });
714}
715
717{
718 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
719 font.setPointSize(12);
720 font.setBold(false);
721
722 return font;
723}
724
726{
727 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
728 font.setPointSize(20);
729 font.setBold(true);
730
731 return font;
732}
733
735{
736 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
737 font.setPointSize(16);
738
739 return font;
740}
741
743{
744 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
745 font.setPointSize(16);
746
747 return font;
748}
749
751{
752 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
753 font.setPointSize(16);
754
755 return font;
756}
757
759{
760 auto font = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont();
761 font.setPointSize(14);
762
763 return font;
764}
765
766QHash<QPlatformTheme::Palette, QPalette> makePalettesMap(Qt::ColorScheme scheme, const QColor &accentColor)
767{
768 const AllPalletesColors palettesColors = makeAllPalettesColors(scheme, accentColor);
769 return {
770 {QPlatformTheme::ButtonPalette, makeButtonPalette(palettesColors)},
771 {QPlatformTheme::CheckBoxPalette, makeCheckBoxOrRadioButtonPalette(palettesColors)},
772 {QPlatformTheme::ComboBoxPalette, makeComboBoxPalette(palettesColors)},
773 {QPlatformTheme::GroupBoxPalette, makeGroupBoxPalette(palettesColors)},
774 {QPlatformTheme::HeaderPalette, makeHeaderPalette(palettesColors)},
775 {QPlatformTheme::ItemViewPalette, makeItemViewPalette(palettesColors)},
776 {QPlatformTheme::LabelPalette, makeLabelPalette(palettesColors)},
777 {QPlatformTheme::MenuPalette, makeMenuPalette(palettesColors)},
778 {QPlatformTheme::MenuBarPalette, makeMenuBarPalette(palettesColors)},
779 {QPlatformTheme::RadioButtonPalette, makeCheckBoxOrRadioButtonPalette(palettesColors)},
780 {QPlatformTheme::SystemPalette, makeSystemPalette(palettesColors)},
781 {QPlatformTheme::TabBarPalette, makeTabBarPalette(palettesColors)},
782 {QPlatformTheme::TextEditPalette, makeTextEditPalette(palettesColors)},
783 {QPlatformTheme::TextLineEditPalette, makeTextLineEditPalette(palettesColors)},
784 {QPlatformTheme::ToolButtonPalette, makeToolButtonPalette(palettesColors)},
785 {QPlatformTheme::ToolTipPalette, makeToolTipPalette(palettesColors)},
786 };
787}
788
790 Qt::ColorScheme scheme)
791{
792 switch (scheme) {
793 case Qt::ColorScheme::Unknown:
794 return {};
795 case Qt::ColorScheme::Light:
796 return false;
797 case Qt::ColorScheme::Dark:
798 return true;
799 };
800 return {};
801}
802
804 std::optional<bool> darkModeFlag)
805{
806 if (darkModeFlag.has_value()) {
807 if (!darkModeFlag.value_or(false))
808 return Qt::ColorScheme::Light;
809 else
810 return Qt::ColorScheme::Dark;
811 } else {
812 return Qt::ColorScheme::Unknown;
813 }
814}
815
817
818OhosConfigurationColorMode mapOhosConfigurationColorModeFromJs(QOhosJsState &jsState, QNapi::Number colorModeJsEnum)
819{
820 constexpr auto fallbackColorMode = OhosConfigurationColorMode::COLOR_MODE_NOT_SET;
821 auto optColorMode = jsState.tryMapOhosEnumFromJs<OhosConfigurationColorMode>(colorModeJsEnum);
822 return optColorMode.value_or(fallbackColorMode);
823};
824
826{
828 qCWarning(QtForOhos, "%s: cannot set a color mode in 'no UI child mode'", Q_FUNC_INFO);
829 return;
830 }
831
832 QOhosJsThreadGateway::runAndWait(
833 [&](QOhosJsState &jsState) {
834 auto optQAbility = jsState.defaultQAbility();
835 if (!optQAbility) {
836 qCWarning(QtForOhos, "%s: cannot set a color mode without a UIAbility", Q_FUNC_INFO);
837 return;
838 }
839
840 const auto jsColorMode = jsState.mapOhosEnumToJs(colorMode);
841 optQAbility->eval("context.getApplicationContext().setColorMode(*)", {jsColorMode});
842 },
843 Q_FUNC_INFO);
844}
845
847 QOhosConsumer<OhosConfigurationColorMode> valueChangedHandler)
848{
849 return QtOhos::makeOhosConfigValueDataSource<OhosConfigurationColorMode>(
850 [](QOhosJsState &jsState) {
851 auto optQAbility = jsState.defaultQAbility();
852 return optQAbility
853 ? mapOhosConfigurationColorModeFromJs(
854 jsState, optQAbility->eval<QNapi::Number>("context.config.colorMode"))
855 : OhosConfigurationColorMode::COLOR_MODE_NOT_SET;
856 },
857 [](QOhosJsState &jsState, const QNapi::Object &config) {
858 return mapOhosConfigurationColorModeFromJs(jsState, config.get<QNapi::Number>("colorMode"));
859 },
860 std::move(valueChangedHandler));
861}
862
864{
865 switch (colorMode) {
867 return {};
869 return false;
871 return true;
872 }
873
874 return {};
875}
876
877QColor readAccentColor(QOhosJsState &jsState)
878{
879 auto optQAbility = jsState.defaultQAbility();
880 if (!optQAbility)
881 return {};
882
883 const auto argb = static_cast<uint32_t>(
884 optQAbility->eval<QNapi::Number>(
885 "context.resourceManager.getColorByNameSync(*)",
886 {"ohos_id_color_emphasize"}));
887 return QColor::fromRgba(argb);
888}
889
890QOhosSupplier<QColor> makeOhosAccentColorDataSource(QOhosConsumer<QColor> accentColorChangedHandler)
891{
892 return QtOhos::makeOhosConfigValueDataSource<QColor>(
893 readAccentColor,
894 [](QOhosJsState &jsState, const QNapi::Object &) {
895 return readAccentColor(jsState);
896 },
897 std::move(accentColorChangedHandler));
898}
899
900std::optional<QPixmap> tryGetFilePixmapByResourceObject(QOhosJsState &jsState, QNapi::Object resource)
901{
902 std::string undocumentedParamsPropertyName("params");
903 auto optParams = QNapi::getOptionalPropOrEmpty<QNapi::Value>(resource, undocumentedParamsPropertyName);
904 if (optParams.IsEmpty()) {
905 qOhosPrintfWarning(
906 "%s: expected '%s' property not found in resource object, ignore getting pixmap",
907 Q_FUNC_INFO, undocumentedParamsPropertyName.c_str());
908 return {};
909 }
910 if (!optParams.IsArray()) {
911 qOhosPrintfWarning(
912 "%s: '%s' property is not an array, ignore getting pixmap",
913 Q_FUNC_INFO, undocumentedParamsPropertyName.c_str());
914 return {};
915 }
916
917 auto params = QNapi::getArrayElements<std::vector<std::string>, QNapi::String>(
918 QNapi::checkedCast<QNapi::Array>(optParams));
919 if (params.empty()) {
920 qOhosPrintfWarning(
921 "%s: '%s' property is empty, ignore getting pixmap",
922 Q_FUNC_INFO, undocumentedParamsPropertyName.c_str());
923 return {};
924 }
925
926 const auto resourceIdentifier = params.front();
927 const auto lastSeparatorPosition = resourceIdentifier.rfind('.');
928 if (lastSeparatorPosition == std::string::npos) {
929 qOhosPrintfWarning(
930 "%s: '%s' property has unknown resource name, ignore getting pixmap",
931 Q_FUNC_INFO, undocumentedParamsPropertyName.c_str());
932 return {};
933 }
934
935 const auto simpleName = resourceIdentifier.substr(lastSeparatorPosition + 1);
936 auto resourceContentBuffer = jsState.eval<QNapi::TypedArrayOf<std::uint8_t>>(
937 "@ohos.resourceManager.getSysResourceManager().getMediaByNameSync(*)", {simpleName});
938
939 QPixmap pixmap;
940 bool pixmapLoadResult = pixmap.loadFromData(
941 static_cast<const uchar *>(resourceContentBuffer.Data()), resourceContentBuffer.ByteLength());
942
943 if (pixmapLoadResult) {
944 return pixmap;
945 } else {
946 qOhosPrintfWarning("%s: cannot load pixmap", Q_FUNC_INFO);
947 return {};
948 }
949}
950
952 QOhosJsState &jsState, const std::string &filenameExtension)
953{
954 std::string ohosDotFilenameExtension = "." + filenameExtension;
955 auto uniformDataType = jsState.eval<QNapi::String>(
956 "@ohos.data.uniformTypeDescriptor.getUniformDataTypeByFilenameExtension(*)",
957 {ohosDotFilenameExtension});
958
959 auto resourceValue = jsState.eval(
960 "@kit.FileManagerServiceKit.fileManagerService.getFileIconSync(*)", {uniformDataType});
961 if (resourceValue.IsObject()) {
962 return tryGetFilePixmapByResourceObject(jsState, QNapi::checkedCast<QNapi::Object>(resourceValue));
963 } else {
964 qOhosPrintfWarning("%s: got unhandled resource result type, ignore it", Q_FUNC_INFO);
965 return {};
966 }
967}
968
970{
971public:
972 explicit QOhosFileIconEngine(const QFileInfo &info, QPlatformTheme::IconOptions opts);
973
974protected:
975 QPixmap filePixmap(const QSize &size, QIcon::Mode mode, QIcon::State) override;
976};
977
978QOhosFileIconEngine::QOhosFileIconEngine(const QFileInfo &info, QPlatformTheme::IconOptions opts)
980{
981}
982
984{
985 auto fileNameSuffix = fileInfo().suffix();
986 auto optPixmap = QOhosJsThreadGateway::eval(
987 [&](QOhosJsState &jsState) {
988 return tryGetFilePixmapByFilenameExtension(jsState, fileNameSuffix.toStdString());
989 },
990 Q_FUNC_INFO);
991
992 return optPixmap.has_value()
993 ? optPixmap.value().scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation)
994 : QPixmap();
995}
996
997}
998
1000 : m_fonts(
1001 {
1010 })
1011 , m_wheelScrollLines(defaultWheelScrollLines)
1012{
1013 auto colorModeDataSource = makeOhosConfigColorModeDataSource(
1014 [this](auto) {
1015 refreshPalettes();
1016 QWindowSystemInterface::handleThemeChange<QWindowSystemInterface::SynchronousDelivery>();
1017 });
1018 m_ohosConfigDarkModeFlagSupplier = [colorModeDataSource = std::move(colorModeDataSource)]() {
1019 return mapOhosConfigurationColorModeToDarkModeFlag(colorModeDataSource());
1020 };
1021
1022 m_ohosAccentColorSupplier = makeOhosAccentColorDataSource(
1023 [this](const auto &) {
1024 refreshPalettes();
1025 QWindowSystemInterface::handleThemeChange<QWindowSystemInterface::SynchronousDelivery>();
1026 });
1027
1028 refreshPalettes();
1029}
1030
1031void QOhosPlatformTheme::requestColorScheme(Qt::ColorScheme scheme)
1032{
1033 std::optional<bool> isDarkMode = mapOhosThemeFromColorScheme(scheme);
1034 setOhosConfigColorMode(
1035 isDarkMode.has_value()
1036 ? isDarkMode.value()
1040}
1041
1043{
1044 return mapOhosThemeToColorScheme(m_ohosConfigDarkModeFlagSupplier());
1045}
1046
1047void QOhosPlatformTheme::refreshPalettes()
1048{
1049 if (const auto currentColorScheme = colorScheme(); currentColorScheme != Qt::ColorScheme::Unknown)
1050 m_themePalette = makePalettesMap(currentColorScheme, m_ohosAccentColorSupplier());
1051}
1052
1054{
1055 auto _dbg = make_QCScopedDebug("QOhosPlatformTheme::createPlatformDialogHelper");
1056 return QOhosDialogs::createHelper(type);
1057}
1058
1059bool QOhosPlatformTheme::usePlatformNativeDialog(QPlatformTheme::DialogType type) const
1060{
1061 auto _dbg = make_QCScopedDebug("QOhosPlatformTheme::usePlatformNativeDialog");
1062 return (type == QOhosPlatformTheme::FileDialog);
1063}
1064
1066{
1067 switch (hint) {
1068 case StyleNames:
1069 return QStringList(QString::fromUtf8(ohosThemeName));
1070 case MouseDoubleClickDistance:
1071 case TouchDoubleTapDistance:
1072 {
1073 auto *primaryScreen = qGuiApp->primaryScreen();
1074 auto *platformScreen = primaryScreen != nullptr
1075 ? static_cast<QOhosPlatformScreen *>(primaryScreen->handle())
1076 : nullptr;
1077 return platformScreen != nullptr
1078 ? QHighDpi::fromNativePixels(
1079 QHighDpi::toNative(
1080 mouseDoubleClickDistance, platformScreen->pixelScalingCoefficient()),
1081 platformScreen)
1082 : mouseDoubleClickDistance;
1083 }
1084 case MouseDoubleClickInterval:
1086 case WheelScrollLines:
1087 return m_wheelScrollLines;
1088 case MenuBarFocusOnAltPressRelease:
1089 return true;
1090 case PreferFileIconFromTheme:
1091 return true;
1092 default:
1093 return QPlatformTheme::themeHint(hint);
1094 }
1095}
1096
1097const QPalette *QOhosPlatformTheme::palette(Palette type) const
1098{
1099 if (const auto it = m_themePalette.find(type); it != m_themePalette.end())
1100 return &it.value();
1101 return QPlatformTheme::palette(type);
1102}
1103
1104const QFont *QOhosPlatformTheme::font(Font type) const
1105{
1106 const auto fontIter = m_fonts.find(type);
1107 return fontIter != m_fonts.end()
1108 ? &fontIter.value()
1109 : QPlatformTheme::font(type);
1110}
1111
1112void QOhosPlatformTheme::setWheelScrollLines(int wheelScrollLines)
1113{
1114 m_wheelScrollLines = wheelScrollLines;
1115}
1116
1118{
1119 return makeQOhosSystemTrayIcon().release();
1120}
1121
1122QIcon QOhosPlatformTheme::fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions iconOptions) const
1123{
1124 return !fileInfo.suffix().isEmpty()
1125 ? QIcon(new QOhosFileIconEngine(fileInfo, iconOptions))
1126 : QPlatformTheme::fileIcon(fileInfo, iconOptions);
1127}
1128
1129QIconEngine *QOhosPlatformTheme::createIconEngine(const QString &iconName) const
1130{
1131 return tryCreateQOhosIconEngine(iconName);
1132}
1133
1134QT_END_NAMESPACE
QIconEngine * createIconEngine(const QString &iconName) const override
Factory function for the QIconEngine used by QIcon::fromTheme().
void requestColorScheme(Qt::ColorScheme scheme) override
QIcon fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions iconOptions) const override
Return an icon for fileInfo, observing iconOptions.
Qt::ColorScheme colorScheme() const override
void setWheelScrollLines(int wheelScrollLines)
QPlatformDialogHelper * createPlatformDialogHelper(DialogType type) const override
const QFont * font(Font type) const override
const QPalette * palette(Palette type) const override
Return a color palette for type type.
QPlatformSystemTrayIcon * createPlatformSystemTrayIcon() const override
Factory function for QSystemTrayIcon.
static constexpr int defaultWheelScrollLines
QVariant themeHint(ThemeHint hint) const override
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)
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 makePalette(std::initializer_list< std::tuple< QPalette::ColorGroup, QPalette::ColorRole, const QColor & > > brushEntries)
MenuPaletteColors makeMenuPaletteColorsDark(const PalettesColors &palettes)
TooltipPaletteColors makeTooltipPaletteColorsLight()
QtOhosQpa::enums::ohos::app::ability::ConfigurationConstant::ColorMode OhosConfigurationColorMode
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()
QPalette makeToolButtonPalette(const AllPalletesColors &palettesColors)
bool isOhosNoUiChildMode()