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
qquickiostheme.mm
Go to the documentation of this file.
1// Copyright (C) 2022 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// Qt-Security score:significant reason:default
4
6
7#if defined(Q_OS_APPLE)
8#include <QtGui/private/qcoregraphics_p.h>
9#endif
10
11#ifdef Q_OS_IOS
12#include <UIKit/UIInterface.h>
13#include <UIKit/UITraitCollection.h>
14#endif
15
16#include <QtGui/qguiapplication.h>
17#include <QtGui/qstylehints.h>
18#include <QtQuickTemplates2/private/qquicktheme_p.h>
19#include <QtQuickControls2/private/qquickstyle_p.h>
20
22
23void QQuickIOSTheme::initialize(QQuickTheme *theme)
24{
25 QPalette systemPalette;
26
27 QColor window;
28 QColor base;
29 QColor text;
30 QColor disabledText;
31 QColor placeholderText;
32 QColor button;
33 QColor disabledButton;
34 QColor white;
35 QColor lightGray;
36 QColor gray;
37 QColor darkGray;
38
39 bool isDarkSystemTheme = QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark;
40#ifdef Q_OS_IOS
41 UIUserInterfaceStyle style = isDarkSystemTheme ? UIUserInterfaceStyleDark : UIUserInterfaceStyleLight;
42 UITraitCollection *traitCollection = [UITraitCollection traitCollectionWithUserInterfaceStyle:style];
43
44 window = qt_mac_toQColor([UIColor.systemGroupedBackgroundColor resolvedColorWithTraitCollection:traitCollection].CGColor);
45 base = qt_mac_toQColor([UIColor.secondarySystemGroupedBackgroundColor resolvedColorWithTraitCollection:traitCollection].CGColor);
46 text = qt_mac_toQColor([UIColor.labelColor resolvedColorWithTraitCollection:traitCollection].CGColor);
47 disabledText = qt_mac_toQColor([UIColor.tertiaryLabelColor resolvedColorWithTraitCollection:traitCollection].CGColor);
48 placeholderText = qt_mac_toQColor([UIColor.placeholderTextColor resolvedColorWithTraitCollection:traitCollection].CGColor);
49 button = qt_mac_toQColor([UIColor.systemBlueColor resolvedColorWithTraitCollection:traitCollection].CGColor);
50 disabledButton = qt_mac_toQColor([UIColor.tertiarySystemFillColor resolvedColorWithTraitCollection:traitCollection].CGColor);
51 white = qt_mac_toQColor([UIColor.whiteColor resolvedColorWithTraitCollection:traitCollection].CGColor);
52 lightGray = qt_mac_toQColor([UIColor.systemGray6Color resolvedColorWithTraitCollection:traitCollection].CGColor);
53 gray = qt_mac_toQColor([UIColor.opaqueSeparatorColor resolvedColorWithTraitCollection:traitCollection].CGColor);
54 darkGray = qt_mac_toQColor([UIColor.systemGrayColor resolvedColorWithTraitCollection:traitCollection].CGColor);
55#else
56 window = isDarkSystemTheme ? QColor(qRgba(0, 0, 0, 255)) : QColor(qRgba(242, 242, 247, 255));
57 base = isDarkSystemTheme ? QColor(qRgba(28, 28, 30, 255)) : QColor(Qt::white);
58 text = isDarkSystemTheme ? QColor(Qt::white) : QColor(Qt::black);
59 disabledText = isDarkSystemTheme ? QColor(qRgba(60, 60, 67, 76)) : QColor(qRgba(235, 235, 245, 76));
60 placeholderText = isDarkSystemTheme ? QColor(qRgba(235, 235, 245, 76)) : QColor(qRgba(60, 60, 67, 77));
61 button = isDarkSystemTheme ? QColor(qRgba(10, 132, 255, 255)) : QColor(qRgba(0, 122, 255, 255));
62 disabledButton = isDarkSystemTheme ? QColor(qRgba(118, 118, 128, 61)) : QColor(qRgba(118, 118, 128, 31));
63 white = QColor(Qt::white);
64 lightGray = isDarkSystemTheme ? QColor(qRgba(28, 28, 30, 255)) : QColor(qRgba(242, 242, 247, 255));
65 gray = isDarkSystemTheme ? QColor(qRgba(56, 56, 58, 255)) : QColor(qRgba(198, 198, 200, 2555));
66 darkGray = QColor(qRgba(142, 142, 147, 255));
67#endif
68 systemPalette.setColor(QPalette::Window, window);
69 systemPalette.setColor(QPalette::Base, base);
70
71 systemPalette.setColor(QPalette::WindowText, text);
72 systemPalette.setColor(QPalette::Disabled, QPalette::WindowText, disabledText);
73 systemPalette.setColor(QPalette::Text, text);
74 systemPalette.setColor(QPalette::Disabled, QPalette::Text, disabledText);
75 systemPalette.setColor(QPalette::PlaceholderText, placeholderText);
76
77 systemPalette.setColor(QPalette::Button, button);
78 systemPalette.setColor(QPalette::Disabled, QPalette::Button, disabledButton);
79 systemPalette.setColor(QPalette::ButtonText, white);
80 systemPalette.setColor(QPalette::Disabled, QPalette::ButtonText, disabledText);
81
82 systemPalette.setColor(QPalette::ToolTipText, text);
83 systemPalette.setColor(QPalette::Disabled, QPalette::ToolTipText, disabledText);
84
85 systemPalette.setColor(QPalette::Highlight, button.lighter(115));
86
87 systemPalette.setColor(QPalette::Light, lightGray);
88 systemPalette.setColor(QPalette::Mid, gray);
89 systemPalette.setColor(QPalette::Dark, darkGray);
90
91 theme->setPalette(QQuickTheme::System, systemPalette);
92}
93
94QT_END_NAMESPACE
static void initialize(QQuickTheme *theme)