Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qiostheme.mm
Go to the documentation of this file.
1// Copyright (C) 2016 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 "qiostheme.h"
5
6#include <QtCore/QStringList>
7#include <QtCore/QVariant>
8#include <QtCore/private/qcore_mac_p.h>
9
10#include <QtGui/QFont>
11#include <QtGui/private/qcoregraphics_p.h>
12
13#include <QtGui/private/qcoretextfontdatabase_p.h>
14#include <QtGui/private/qappleiconengine_p.h>
15#include <QtGui/private/qguiapplication_p.h>
16#include <qpa/qplatformintegration.h>
17
18#include <UIKit/UIFont.h>
19#include <UIKit/UIInterface.h>
20
21#if !defined(Q_OS_TVOS) && !defined(Q_OS_VISIONOS)
22#include "qiosmenu.h"
23#endif
24
25#if !defined(Q_OS_TVOS)
26#include "qiosfiledialog.h"
27#include "qioscolordialog.h"
28#include "qiosfontdialog.h"
29#include "qiosmessagedialog.h"
30#include "qiosscreen.h"
31#include "quiwindow.h"
32#endif
33
35
36const char *QIOSTheme::name = "ios";
37
39{
41
42 m_contentSizeCategoryObserver = QMacNotificationObserver(nil,
43 UIContentSizeCategoryDidChangeNotification, [] {
44 qCDebug(lcQpaFonts) << "Contents size category changed to" << UIApplication.sharedApplication.preferredContentSizeCategory;
46 });
47}
48
52
53QPalette QIOSTheme::s_systemPalette;
54
56{
58 s_systemPalette = qt_fusionPalette();
59
60 s_systemPalette.setBrush(QPalette::Window, qt_mac_toQBrush(UIColor.systemGroupedBackgroundColor.CGColor));
61 s_systemPalette.setBrush(QPalette::Active, QPalette::WindowText, qt_mac_toQBrush(UIColor.labelColor.CGColor));
62
63 s_systemPalette.setBrush(QPalette::Base, qt_mac_toQBrush(UIColor.secondarySystemGroupedBackgroundColor.CGColor));
64 s_systemPalette.setBrush(QPalette::Active, QPalette::Text, qt_mac_toQBrush(UIColor.labelColor.CGColor));
65
66 s_systemPalette.setBrush(QPalette::Button, qt_mac_toQBrush(UIColor.secondarySystemBackgroundColor.CGColor));
67 s_systemPalette.setBrush(QPalette::Active, QPalette::ButtonText, qt_mac_toQBrush(UIColor.labelColor.CGColor));
68
69 s_systemPalette.setBrush(QPalette::Active, QPalette::BrightText, qt_mac_toQBrush(UIColor.lightTextColor.CGColor));
70 s_systemPalette.setBrush(QPalette::Active, QPalette::PlaceholderText, qt_mac_toQBrush(UIColor.placeholderTextColor.CGColor));
71
72 s_systemPalette.setBrush(QPalette::Active, QPalette::Link, qt_mac_toQBrush(UIColor.linkColor.CGColor));
73 s_systemPalette.setBrush(QPalette::Active, QPalette::LinkVisited, qt_mac_toQBrush(UIColor.linkColor.CGColor));
74
75 s_systemPalette.setBrush(QPalette::Highlight, QColor(11, 70, 150, 60));
76 s_systemPalette.setBrush(QPalette::HighlightedText, qt_mac_toQBrush(UIColor.labelColor.CGColor));
77
78 if (@available(ios 15.0, *))
79 s_systemPalette.setBrush(QPalette::Accent, qt_mac_toQBrush(UIColor.tintColor.CGColor));
80}
81
83{
85 return &s_systemPalette;
86 return 0;
87}
88
89#if !defined(Q_OS_TVOS) && !defined(Q_OS_VISIONOS)
94
99#endif
100
102{
103 switch (type) {
104 case FileDialog:
105 case MessageDialog:
106 case ColorDialog:
107 case FontDialog:
109 default:
110 return false;
111 }
112}
113
115{
116 switch (type) {
117#ifndef Q_OS_TVOS
118 case FileDialog:
119 return new QIOSFileDialog();
120 break;
121 case MessageDialog:
122 return new QIOSMessageDialog();
123 break;
124 case ColorDialog:
125 return new QIOSColorDialog();
126 break;
127 case FontDialog:
128 return new QIOSFontDialog();
129 break;
130#endif
131 default:
132 return 0;
133 }
134}
135
137{
138 switch (hint) {
140 return QStringList(QStringLiteral("Fusion"));
141 case KeyboardScheme:
142 return QVariant(int(MacKeyboardScheme));
143 default:
145 }
146}
147
149{
150#if defined(Q_OS_VISIONOS)
151 // On visionOS the concept of light or dark mode does not
152 // apply, as the UI is constantly changing based on what
153 // the lighting conditions are outside the headset, but
154 // the OS reports itself as always being in dark mode.
156#else
157 if (s_colorSchemeOverride != Qt::ColorScheme::Unknown)
158 return s_colorSchemeOverride;
159
160 // Set the appearance based on the QUIWindow
161 // Fallback to the UIScreen if no window is created yet
162 UIUserInterfaceStyle appearance = UIScreen.mainScreen.traitCollection.userInterfaceStyle;
163 NSArray<UIWindow *> *windows = qt_apple_sharedApplication().windows;
164 for (UIWindow *window in windows) {
165 if ([window isKindOfClass:[QUIWindow class]]) {
166 appearance = static_cast<QUIWindow*>(window).traitCollection.userInterfaceStyle;
167 break;
168 }
169 }
170
171 return appearance == UIUserInterfaceStyleDark
174#endif
175}
176
178{
179#if defined(Q_OS_VISIONOS)
180 Q_UNUSED(scheme);
181#else
182 s_colorSchemeOverride = scheme;
183
184 const NSArray<UIWindow *> *windows = qt_apple_sharedApplication().windows;
185 for (UIWindow *window in windows) {
186 // don't apply a theme to windows we don't own
187 if (qt_objc_cast<QUIWindow*>(window))
189 }
190#endif
191}
192
194{
195 const UIUserInterfaceStyle style = []{
196 switch (s_colorSchemeOverride) {
198 return UIUserInterfaceStyleDark;
200 return UIUserInterfaceStyleLight;
202 return UIUserInterfaceStyleUnspecified;
203 }
204 }();
205
206 window.overrideUserInterfaceStyle = style;
207}
208
210{
211 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
212 const auto *coreTextFontDatabase = static_cast<QCoreTextFontDatabase *>(platformIntegration->fontDatabase());
213 return coreTextFontDatabase->themeFont(type);
214}
215
217{
218 return new QAppleIconEngine(iconName);
219}
220
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
QFont * themeFont(QPlatformTheme::Font) const
\reentrant
Definition qfont.h:22
static QPlatformIntegration * platformIntegration()
QIconEngine * createIconEngine(const QString &iconName) const override
Factory function for the QIconEngine used by QIcon::fromTheme().
Definition qiostheme.mm:216
QPlatformMenu * createPlatformMenu() const override
Definition qiostheme.mm:95
const QFont * font(Font type=SystemFont) const override
Definition qiostheme.mm:209
static const char * name
Definition qiostheme.h:40
QVariant themeHint(ThemeHint hint) const override
Definition qiostheme.mm:136
void requestColorScheme(Qt::ColorScheme scheme) override
Definition qiostheme.mm:177
static void initializeSystemPalette()
Definition qiostheme.mm:55
Qt::ColorScheme colorScheme() const override
Definition qiostheme.mm:148
bool usePlatformNativeDialog(DialogType type) const override
Definition qiostheme.mm:101
QPlatformMenuItem * createPlatformMenuItem() const override
Definition qiostheme.mm:90
static void applyTheme(UIWindow *window)
Definition qiostheme.mm:193
const QPalette * palette(Palette type=SystemPalette) const override
Definition qiostheme.mm:82
QPlatformDialogHelper * createPlatformDialogHelper(DialogType type) const override
Definition qiostheme.mm:114
The QIconEngine class provides an abstract base class for QIcon renderers.
Definition qiconengine.h:15
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
@ HighlightedText
Definition qpalette.h:53
@ BrightText
Definition qpalette.h:52
@ ButtonText
Definition qpalette.h:52
@ WindowText
Definition qpalette.h:51
@ Highlight
Definition qpalette.h:53
@ PlaceholderText
Definition qpalette.h:58
@ LinkVisited
Definition qpalette.h:54
The QPlatformDialogHelper class allows for platform-specific customization of dialogs.
static void repopulateFontDatabase()
Requests that the platform font database should be repopulated.
virtual QVariant themeHint(ThemeHint hint) const
ThemeHint
This enum describes the available theme hints.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
ColorScheme
Definition qnamespace.h:50
#define Q_DECL_IMPORT
QList< QString > QStringList
Constructs a string list that contains the given string, str.
bool qt_apple_isApplicationExtension()
Definition qcore_mac.mm:424
AppleApplication * qt_apple_sharedApplication()
Definition qcore_mac.mm:431
QBrush qt_mac_toQBrush(CGColorRef color)
#define qCDebug(category,...)
GLenum type
GLuint in
Q_GUI_EXPORT QPalette qt_fusionPalette()
#define QStringLiteral(str)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
#define Q_UNUSED(x)
aWidget window() -> setWindowTitle("New Window Title")
[2]