Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/styles/qstylefactory.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
25 | ** | - | ||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
29 | ** | - | ||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||
31 | ** | - | ||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||
33 | - | |||||||||||||
34 | #include "qstylefactory.h" | - | ||||||||||||
35 | #include "qstyleplugin.h" | - | ||||||||||||
36 | #include "private/qfactoryloader_p.h" | - | ||||||||||||
37 | #include "qmutex.h" | - | ||||||||||||
38 | - | |||||||||||||
39 | #include "qapplication.h" | - | ||||||||||||
40 | #include "qwindowsstyle_p.h" | - | ||||||||||||
41 | #ifndef QT_NO_STYLE_FUSION | - | ||||||||||||
42 | #include "qfusionstyle_p.h" | - | ||||||||||||
43 | #ifndef QT_NO_STYLE_ANDROID | - | ||||||||||||
44 | #include "qandroidstyle_p.h" | - | ||||||||||||
45 | #endif | - | ||||||||||||
46 | #endif | - | ||||||||||||
47 | #ifndef QT_NO_STYLE_GTK | - | ||||||||||||
48 | #include "qgtkstyle_p.h" | - | ||||||||||||
49 | #endif | - | ||||||||||||
50 | #ifndef QT_NO_STYLE_WINDOWSXP | - | ||||||||||||
51 | #include "qwindowsxpstyle_p.h" | - | ||||||||||||
52 | #endif | - | ||||||||||||
53 | #ifndef QT_NO_STYLE_WINDOWSVISTA | - | ||||||||||||
54 | #include "qwindowsvistastyle_p.h" | - | ||||||||||||
55 | #endif | - | ||||||||||||
56 | #ifndef QT_NO_STYLE_WINDOWSCE | - | ||||||||||||
57 | #include "qwindowscestyle_p.h" | - | ||||||||||||
58 | #endif | - | ||||||||||||
59 | #ifndef QT_NO_STYLE_WINDOWSMOBILE | - | ||||||||||||
60 | #include "qwindowsmobilestyle_p.h" | - | ||||||||||||
61 | #endif | - | ||||||||||||
62 | - | |||||||||||||
63 | #if !defined(QT_NO_STYLE_MAC) && defined(Q_OS_MAC) | - | ||||||||||||
64 | # include "qmacstyle_mac_p.h" | - | ||||||||||||
65 | #endif | - | ||||||||||||
66 | - | |||||||||||||
67 | QT_BEGIN_NAMESPACE | - | ||||||||||||
68 | - | |||||||||||||
69 | #ifndef QT_NO_LIBRARY | - | ||||||||||||
70 | Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, never executed: end of block never executed: guard.store(QtGlobalStatic::Destroyed); never executed: return &holder.value;
| 0 | ||||||||||||
71 | (QStyleFactoryInterface_iid, QLatin1String("/styles"), Qt::CaseInsensitive)) | - | ||||||||||||
72 | #endif | - | ||||||||||||
73 | - | |||||||||||||
74 | /*! | - | ||||||||||||
75 | \class QStyleFactory | - | ||||||||||||
76 | \brief The QStyleFactory class creates QStyle objects. | - | ||||||||||||
77 | - | |||||||||||||
78 | \ingroup appearance | - | ||||||||||||
79 | \inmodule QtWidgets | - | ||||||||||||
80 | - | |||||||||||||
81 | The QStyle class is an abstract base class that encapsulates the | - | ||||||||||||
82 | look and feel of a GUI. QStyleFactory creates a QStyle object | - | ||||||||||||
83 | using the create() function and a key identifying the style. The | - | ||||||||||||
84 | styles are either built-in or dynamically loaded from a style | - | ||||||||||||
85 | plugin (see QStylePlugin). | - | ||||||||||||
86 | - | |||||||||||||
87 | The valid keys can be retrieved using the keys() | - | ||||||||||||
88 | function. Typically they include "windows" and "fusion". | - | ||||||||||||
89 | Depending on the platform, "windowsxp", "windowsvista", "gtk" | - | ||||||||||||
90 | and "macintosh" may be available. | - | ||||||||||||
91 | Note that keys are case insensitive. | - | ||||||||||||
92 | - | |||||||||||||
93 | \sa QStyle | - | ||||||||||||
94 | */ | - | ||||||||||||
95 | - | |||||||||||||
96 | /*! | - | ||||||||||||
97 | Creates and returns a QStyle object that matches the given \a key, or | - | ||||||||||||
98 | returns 0 if no matching style is found. | - | ||||||||||||
99 | - | |||||||||||||
100 | Both built-in styles and styles from style plugins are queried for a | - | ||||||||||||
101 | matching style. | - | ||||||||||||
102 | - | |||||||||||||
103 | \note The keys used are case insensitive. | - | ||||||||||||
104 | - | |||||||||||||
105 | \sa keys() | - | ||||||||||||
106 | */ | - | ||||||||||||
107 | QStyle *QStyleFactory::create(const QString& key) | - | ||||||||||||
108 | { | - | ||||||||||||
109 | QStyle *ret = 0; | - | ||||||||||||
110 | QString style = key.toLower(); | - | ||||||||||||
111 | #ifndef QT_NO_STYLE_WINDOWS | - | ||||||||||||
112 | if (style == QLatin1String("windows"))
| 0 | ||||||||||||
113 | ret = new QWindowsStyle; never executed: ret = new QWindowsStyle; | 0 | ||||||||||||
114 | else | - | ||||||||||||
115 | #endif | - | ||||||||||||
116 | #ifndef QT_NO_STYLE_WINDOWSCE | - | ||||||||||||
117 | if (style == QLatin1String("windowsce")) | - | ||||||||||||
118 | ret = new QWindowsCEStyle; | - | ||||||||||||
119 | else | - | ||||||||||||
120 | #endif | - | ||||||||||||
121 | #ifndef QT_NO_STYLE_WINDOWSMOBILE | - | ||||||||||||
122 | if (style == QLatin1String("windowsmobile")) | - | ||||||||||||
123 | ret = new QWindowsMobileStyle; | - | ||||||||||||
124 | else | - | ||||||||||||
125 | #endif | - | ||||||||||||
126 | #ifndef QT_NO_STYLE_WINDOWSXP | - | ||||||||||||
127 | if (style == QLatin1String("windowsxp")) | - | ||||||||||||
128 | ret = new QWindowsXPStyle; | - | ||||||||||||
129 | else | - | ||||||||||||
130 | #endif | - | ||||||||||||
131 | #ifndef QT_NO_STYLE_WINDOWSVISTA | - | ||||||||||||
132 | if (style == QLatin1String("windowsvista")) | - | ||||||||||||
133 | ret = new QWindowsVistaStyle; | - | ||||||||||||
134 | else | - | ||||||||||||
135 | #endif | - | ||||||||||||
136 | #ifndef QT_NO_STYLE_FUSION | - | ||||||||||||
137 | if (style == QLatin1String("fusion"))
| 0 | ||||||||||||
138 | ret = new QFusionStyle; never executed: ret = new QFusionStyle; | 0 | ||||||||||||
139 | else | - | ||||||||||||
140 | #endif | - | ||||||||||||
141 | #ifndef QT_NO_STYLE_ANDROID | - | ||||||||||||
142 | if (style == QLatin1String("android")) | - | ||||||||||||
143 | ret = new QAndroidStyle; | - | ||||||||||||
144 | else | - | ||||||||||||
145 | #endif | - | ||||||||||||
146 | #ifndef QT_NO_STYLE_GTK | - | ||||||||||||
147 | if (style == QLatin1String("gtk") || style == QLatin1String("gtk+"))
| 0 | ||||||||||||
148 | ret = new QGtkStyle; never executed: ret = new QGtkStyle; | 0 | ||||||||||||
149 | else | - | ||||||||||||
150 | #endif | - | ||||||||||||
151 | #ifndef QT_NO_STYLE_MAC | - | ||||||||||||
152 | if (style.startsWith(QLatin1String("macintosh"))) { | - | ||||||||||||
153 | ret = new QMacStyle; | - | ||||||||||||
154 | # ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||
155 | if (style == QLatin1String("macintosh")) | - | ||||||||||||
156 | style += QLatin1String(" (aqua)"); | - | ||||||||||||
157 | # endif | - | ||||||||||||
158 | } else | - | ||||||||||||
159 | #endif | - | ||||||||||||
160 | { } // Keep these here - they make the #ifdefery above work never executed: end of block | 0 | ||||||||||||
161 | #ifndef QT_NO_LIBRARY | - | ||||||||||||
162 | if (!ret)
| 0 | ||||||||||||
163 | ret = qLoadPlugin<QStyle, QStylePlugin>(loader(), style); never executed: ret = qLoadPlugin<QStyle, QStylePlugin>(loader(), style); | 0 | ||||||||||||
164 | #endif | - | ||||||||||||
165 | if(ret)
| 0 | ||||||||||||
166 | ret->setObjectName(style); never executed: ret->setObjectName(style); | 0 | ||||||||||||
167 | return ret; never executed: return ret; | 0 | ||||||||||||
168 | } | - | ||||||||||||
169 | - | |||||||||||||
170 | /*! | - | ||||||||||||
171 | Returns the list of valid keys, i.e. the keys this factory can | - | ||||||||||||
172 | create styles for. | - | ||||||||||||
173 | - | |||||||||||||
174 | \sa create() | - | ||||||||||||
175 | */ | - | ||||||||||||
176 | QStringList QStyleFactory::keys() | - | ||||||||||||
177 | { | - | ||||||||||||
178 | QStringList list; | - | ||||||||||||
179 | #ifndef QT_NO_LIBRARY | - | ||||||||||||
180 | typedef QMultiMap<int, QString> PluginKeyMap; | - | ||||||||||||
181 | - | |||||||||||||
182 | const PluginKeyMap keyMap = loader()->keyMap(); | - | ||||||||||||
183 | const PluginKeyMap::const_iterator cend = keyMap.constEnd(); | - | ||||||||||||
184 | for (PluginKeyMap::const_iterator it = keyMap.constBegin(); it != cend; ++it)
| 0 | ||||||||||||
185 | list.append(it.value()); never executed: list.append(it.value()); | 0 | ||||||||||||
186 | #endif | - | ||||||||||||
187 | #ifndef QT_NO_STYLE_WINDOWS | - | ||||||||||||
188 | if (!list.contains(QLatin1String("Windows")))
| 0 | ||||||||||||
189 | list << QLatin1String("Windows"); never executed: list << QLatin1String("Windows"); | 0 | ||||||||||||
190 | #endif | - | ||||||||||||
191 | #ifndef QT_NO_STYLE_WINDOWSCE | - | ||||||||||||
192 | if (!list.contains(QLatin1String("WindowsCE"))) | - | ||||||||||||
193 | list << QLatin1String("WindowsCE"); | - | ||||||||||||
194 | #endif | - | ||||||||||||
195 | #ifndef QT_NO_STYLE_WINDOWSMOBILE | - | ||||||||||||
196 | if (!list.contains(QLatin1String("WindowsMobile"))) | - | ||||||||||||
197 | list << QLatin1String("WindowsMobile"); | - | ||||||||||||
198 | #endif | - | ||||||||||||
199 | #ifndef QT_NO_STYLE_WINDOWSXP | - | ||||||||||||
200 | if (!list.contains(QLatin1String("WindowsXP")) && | - | ||||||||||||
201 | (QSysInfo::WindowsVersion >= QSysInfo::WV_XP && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based))) | - | ||||||||||||
202 | list << QLatin1String("WindowsXP"); | - | ||||||||||||
203 | #endif | - | ||||||||||||
204 | #ifndef QT_NO_STYLE_WINDOWSVISTA | - | ||||||||||||
205 | if (!list.contains(QLatin1String("WindowsVista")) && | - | ||||||||||||
206 | (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based))) | - | ||||||||||||
207 | list << QLatin1String("WindowsVista"); | - | ||||||||||||
208 | #endif | - | ||||||||||||
209 | #ifndef QT_NO_STYLE_ANDROID | - | ||||||||||||
210 | if (!list.contains(QLatin1String("Android"))) | - | ||||||||||||
211 | list << QLatin1String("Android"); | - | ||||||||||||
212 | #endif | - | ||||||||||||
213 | #ifndef QT_NO_STYLE_GTK | - | ||||||||||||
214 | if (!list.contains(QLatin1String("GTK+")))
| 0 | ||||||||||||
215 | list << QLatin1String("GTK+"); never executed: list << QLatin1String("GTK+"); | 0 | ||||||||||||
216 | #endif | - | ||||||||||||
217 | #ifndef QT_NO_STYLE_FUSION | - | ||||||||||||
218 | if (!list.contains(QLatin1String("Fusion")))
| 0 | ||||||||||||
219 | list << QLatin1String("Fusion"); never executed: list << QLatin1String("Fusion"); | 0 | ||||||||||||
220 | #endif | - | ||||||||||||
221 | #ifndef QT_NO_STYLE_MAC | - | ||||||||||||
222 | QString mstyle = QLatin1String("Macintosh"); | - | ||||||||||||
223 | # ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||
224 | mstyle += QLatin1String(" (aqua)"); | - | ||||||||||||
225 | # endif | - | ||||||||||||
226 | if (!list.contains(mstyle)) | - | ||||||||||||
227 | list << mstyle; | - | ||||||||||||
228 | #endif | - | ||||||||||||
229 | return list; never executed: return list; | 0 | ||||||||||||
230 | } | - | ||||||||||||
231 | - | |||||||||||||
232 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |