1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the plugins of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qiostheme.h"
41
42#include <QtCore/QStringList>
43#include <QtCore/QVariant>
44#include <QtCore/private/qcore_mac_p.h>
45
46#include <QtGui/QFont>
47#include <QtGui/private/qcoregraphics_p.h>
48
49#include <QtFontDatabaseSupport/private/qcoretextfontdatabase_p.h>
50#include <QtGui/private/qguiapplication_p.h>
51#include <qpa/qplatformintegration.h>
52
53#include <UIKit/UIFont.h>
54#include <UIKit/UIInterface.h>
55
56#ifndef Q_OS_TVOS
57#include "qiosmenu.h"
58#include "qiosfiledialog.h"
59#include "qiosmessagedialog.h"
60#endif
61
62QT_BEGIN_NAMESPACE
63
64const char *QIOSTheme::name = "ios";
65
66QIOSTheme::QIOSTheme()
67{
68    initializeSystemPalette();
69}
70
71QIOSTheme::~QIOSTheme()
72{
73    qDeleteAll(m_fonts);
74}
75
76QPalette QIOSTheme::s_systemPalette;
77
78void QIOSTheme::initializeSystemPalette()
79{
80    Q_DECL_IMPORT QPalette qt_fusionPalette(void);
81    s_systemPalette = qt_fusionPalette();
82
83    if (@available(ios 13.0, *)) {
84        s_systemPalette.setBrush(QPalette::Window, qt_mac_toQBrush(UIColor.systemGroupedBackgroundColor.CGColor));
85        s_systemPalette.setBrush(QPalette::Active, QPalette::WindowText, qt_mac_toQBrush(UIColor.labelColor.CGColor));
86
87        s_systemPalette.setBrush(QPalette::Base, qt_mac_toQBrush(UIColor.secondarySystemGroupedBackgroundColor.CGColor));
88        s_systemPalette.setBrush(QPalette::Active, QPalette::Text, qt_mac_toQBrush(UIColor.labelColor.CGColor));
89
90        s_systemPalette.setBrush(QPalette::Button, qt_mac_toQBrush(UIColor.secondarySystemBackgroundColor.CGColor));
91        s_systemPalette.setBrush(QPalette::Active, QPalette::ButtonText, qt_mac_toQBrush(UIColor.labelColor.CGColor));
92
93        s_systemPalette.setBrush(QPalette::Active, QPalette::BrightText, qt_mac_toQBrush(UIColor.lightTextColor.CGColor));
94        s_systemPalette.setBrush(QPalette::Active, QPalette::PlaceholderText, qt_mac_toQBrush(UIColor.placeholderTextColor.CGColor));
95
96        s_systemPalette.setBrush(QPalette::Active, QPalette::Link, qt_mac_toQBrush(UIColor.linkColor.CGColor));
97        s_systemPalette.setBrush(QPalette::Active, QPalette::LinkVisited, qt_mac_toQBrush(UIColor.linkColor.CGColor));
98
99        s_systemPalette.setBrush(QPalette::Highlight, QColor(11, 70, 150, 60));
100        s_systemPalette.setBrush(QPalette::HighlightedText, qt_mac_toQBrush(UIColor.labelColor.CGColor));
101    } else {
102        s_systemPalette.setBrush(QPalette::Highlight, QColor(204, 221, 237));
103        s_systemPalette.setBrush(QPalette::HighlightedText, Qt::black);
104    }
105}
106
107const QPalette *QIOSTheme::palette(QPlatformTheme::Palette type) const
108{
109    if (type == QPlatformTheme::SystemPalette)
110        return &s_systemPalette;
111    return 0;
112}
113
114QPlatformMenuItem* QIOSTheme::createPlatformMenuItem() const
115{
116#ifdef Q_OS_TVOS
117    return 0;
118#else
119    return new QIOSMenuItem();
120#endif
121}
122
123QPlatformMenu* QIOSTheme::createPlatformMenu() const
124{
125#ifdef Q_OS_TVOS
126    return 0;
127#else
128    return new QIOSMenu();
129#endif
130}
131
132bool QIOSTheme::usePlatformNativeDialog(QPlatformTheme::DialogType type) const
133{
134    switch (type) {
135    case FileDialog:
136    case MessageDialog:
137        return !qt_apple_isApplicationExtension();
138    default:
139        return false;
140    }
141}
142
143QPlatformDialogHelper *QIOSTheme::createPlatformDialogHelper(QPlatformTheme::DialogType type) const
144{
145    switch (type) {
146#ifndef Q_OS_TVOS
147    case FileDialog:
148        return new QIOSFileDialog();
149        break;
150    case MessageDialog:
151        return new QIOSMessageDialog();
152        break;
153#endif
154    default:
155        return 0;
156    }
157}
158
159QVariant QIOSTheme::themeHint(ThemeHint hint) const
160{
161    switch (hint) {
162    case QPlatformTheme::StyleNames:
163        return QStringList(QStringLiteral("fusion"));
164    case KeyboardScheme:
165        return QVariant(int(MacKeyboardScheme));
166    default:
167        return QPlatformTheme::themeHint(hint);
168    }
169}
170
171const QFont *QIOSTheme::font(Font type) const
172{
173    if (m_fonts.isEmpty()) {
174        QCoreTextFontDatabase *ctfd = static_cast<QCoreTextFontDatabase *>(QGuiApplicationPrivate::platformIntegration()->fontDatabase());
175        m_fonts = ctfd->themeFonts();
176    }
177
178    return m_fonts.value(type, 0);
179}
180
181QT_END_NAMESPACE
182