|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qstylefactory.h" |
|
43 #include "qstyleplugin.h" |
|
44 #include "private/qfactoryloader_p.h" |
|
45 #include "qmutex.h" |
|
46 |
|
47 #include "qapplication.h" |
|
48 #include "qwindowsstyle.h" |
|
49 #include "qmotifstyle.h" |
|
50 #include "qcdestyle.h" |
|
51 #ifndef QT_NO_STYLE_PLASTIQUE |
|
52 #include "qplastiquestyle.h" |
|
53 #endif |
|
54 #ifndef QT_NO_STYLE_CLEANLOOKS |
|
55 #include "qcleanlooksstyle.h" |
|
56 #endif |
|
57 #ifndef QT_NO_STYLE_GTK |
|
58 #include "qgtkstyle.h" |
|
59 #endif |
|
60 #ifndef QT_NO_STYLE_WINDOWSXP |
|
61 #include "qwindowsxpstyle.h" |
|
62 #endif |
|
63 #ifndef QT_NO_STYLE_WINDOWSVISTA |
|
64 #include "qwindowsvistastyle.h" |
|
65 #endif |
|
66 #ifndef QT_NO_STYLE_WINDOWSCE |
|
67 #include "qwindowscestyle.h" |
|
68 #endif |
|
69 #ifndef QT_NO_STYLE_WINDOWSMOBILE |
|
70 #include "qwindowsmobilestyle.h" |
|
71 #endif |
|
72 #ifndef QT_NO_STYLE_S60 |
|
73 #include "qs60style.h" |
|
74 #endif |
|
75 |
|
76 QT_BEGIN_NAMESPACE |
|
77 |
|
78 #if !defined(QT_NO_STYLE_MAC) && defined(Q_WS_MAC) |
|
79 QT_BEGIN_INCLUDE_NAMESPACE |
|
80 # include "qmacstyle_mac.h" |
|
81 QT_END_INCLUDE_NAMESPACE |
|
82 #endif |
|
83 |
|
84 #if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) |
|
85 Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, |
|
86 (QStyleFactoryInterface_iid, QLatin1String("/styles"), Qt::CaseInsensitive)) |
|
87 #endif |
|
88 |
|
89 /*! |
|
90 \class QStyleFactory |
|
91 \brief The QStyleFactory class creates QStyle objects. |
|
92 |
|
93 \ingroup appearance |
|
94 |
|
95 The QStyle class is an abstract base class that encapsulates the |
|
96 look and feel of a GUI. QStyleFactory creates a QStyle object |
|
97 using the create() function and a key identifying the style. The |
|
98 styles are either built-in or dynamically loaded from a style |
|
99 plugin (see QStylePlugin). |
|
100 |
|
101 The valid keys can be retrieved using the keys() |
|
102 function. Typically they include "windows", "motif", "cde", |
|
103 "plastique" and "cleanlooks". Depending on the platform, |
|
104 "windowsxp", "windowsvista" and "macintosh" may be available. |
|
105 Note that keys are case insensitive. |
|
106 |
|
107 \sa QStyle |
|
108 */ |
|
109 |
|
110 /*! |
|
111 Creates and returns a QStyle object that matches the given \a key, or |
|
112 returns 0 if no matching style is found. |
|
113 |
|
114 Both built-in styles and styles from style plugins are queried for a |
|
115 matching style. |
|
116 |
|
117 \note The keys used are case insensitive. |
|
118 |
|
119 \sa keys() |
|
120 */ |
|
121 QStyle *QStyleFactory::create(const QString& key) |
|
122 { |
|
123 QStyle *ret = 0; |
|
124 QString style = key.toLower(); |
|
125 #ifndef QT_NO_STYLE_WINDOWS |
|
126 if (style == QLatin1String("windows")) |
|
127 ret = new QWindowsStyle; |
|
128 else |
|
129 #endif |
|
130 #ifndef QT_NO_STYLE_WINDOWSCE |
|
131 if (style == QLatin1String("windowsce")) |
|
132 ret = new QWindowsCEStyle; |
|
133 else |
|
134 #endif |
|
135 #ifndef QT_NO_STYLE_WINDOWSMOBILE |
|
136 if (style == QLatin1String("windowsmobile")) |
|
137 ret = new QWindowsMobileStyle; |
|
138 else |
|
139 #endif |
|
140 #ifndef QT_NO_STYLE_WINDOWSXP |
|
141 if (style == QLatin1String("windowsxp")) |
|
142 ret = new QWindowsXPStyle; |
|
143 else |
|
144 #endif |
|
145 #ifndef QT_NO_STYLE_WINDOWSVISTA |
|
146 if (style == QLatin1String("windowsvista")) |
|
147 ret = new QWindowsVistaStyle; |
|
148 else |
|
149 #endif |
|
150 #ifndef QT_NO_STYLE_MOTIF |
|
151 if (style == QLatin1String("motif")) |
|
152 ret = new QMotifStyle; |
|
153 else |
|
154 #endif |
|
155 #ifndef QT_NO_STYLE_CDE |
|
156 if (style == QLatin1String("cde")) |
|
157 ret = new QCDEStyle; |
|
158 else |
|
159 #endif |
|
160 #ifndef QT_NO_STYLE_S60 |
|
161 if (style == QLatin1String("s60")) |
|
162 ret = new QS60Style; |
|
163 else |
|
164 #endif |
|
165 #ifndef QT_NO_STYLE_PLASTIQUE |
|
166 if (style == QLatin1String("plastique")) |
|
167 ret = new QPlastiqueStyle; |
|
168 else |
|
169 #endif |
|
170 #ifndef QT_NO_STYLE_CLEANLOOKS |
|
171 if (style == QLatin1String("cleanlooks")) |
|
172 ret = new QCleanlooksStyle; |
|
173 else |
|
174 #endif |
|
175 #ifndef QT_NO_STYLE_GTK |
|
176 if (style == QLatin1String("gtk") || style == QLatin1String("gtk+")) |
|
177 ret = new QGtkStyle; |
|
178 else |
|
179 #endif |
|
180 #ifndef QT_NO_STYLE_MAC |
|
181 if (style.startsWith(QLatin1String("macintosh"))) { |
|
182 ret = new QMacStyle; |
|
183 # ifdef Q_WS_MAC |
|
184 if (style == QLatin1String("macintosh")) |
|
185 style += QLatin1String(" (aqua)"); |
|
186 # endif |
|
187 } else |
|
188 #endif |
|
189 { } // Keep these here - they make the #ifdefery above work |
|
190 #if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) |
|
191 if(!ret) { |
|
192 if (QStyleFactoryInterface *factory = qobject_cast<QStyleFactoryInterface*>(loader()->instance(style))) |
|
193 ret = factory->create(style); |
|
194 } |
|
195 #endif |
|
196 if(ret) |
|
197 ret->setObjectName(style); |
|
198 return ret; |
|
199 } |
|
200 |
|
201 /*! |
|
202 Returns the list of valid keys, i.e. the keys this factory can |
|
203 create styles for. |
|
204 |
|
205 \sa create() |
|
206 */ |
|
207 QStringList QStyleFactory::keys() |
|
208 { |
|
209 #if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) |
|
210 QStringList list = loader()->keys(); |
|
211 #else |
|
212 QStringList list; |
|
213 #endif |
|
214 #ifndef QT_NO_STYLE_WINDOWS |
|
215 if (!list.contains(QLatin1String("Windows"))) |
|
216 list << QLatin1String("Windows"); |
|
217 #endif |
|
218 #ifndef QT_NO_STYLE_WINDOWSCE |
|
219 if (!list.contains(QLatin1String("WindowsCE"))) |
|
220 list << QLatin1String("WindowsCE"); |
|
221 #endif |
|
222 #ifndef QT_NO_STYLE_WINDOWSMOBILE |
|
223 if (!list.contains(QLatin1String("WindowsMobile"))) |
|
224 list << QLatin1String("WindowsMobile"); |
|
225 #endif |
|
226 #ifndef QT_NO_STYLE_WINDOWSXP |
|
227 if (!list.contains(QLatin1String("WindowsXP")) && |
|
228 (QSysInfo::WindowsVersion >= QSysInfo::WV_XP && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)) |
|
229 list << QLatin1String("WindowsXP"); |
|
230 #endif |
|
231 #ifndef QT_NO_STYLE_WINDOWSVISTA |
|
232 if (!list.contains(QLatin1String("WindowsVista")) && |
|
233 (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)) |
|
234 list << QLatin1String("WindowsVista"); |
|
235 #endif |
|
236 #ifndef QT_NO_STYLE_MOTIF |
|
237 if (!list.contains(QLatin1String("Motif"))) |
|
238 list << QLatin1String("Motif"); |
|
239 #endif |
|
240 #ifndef QT_NO_STYLE_CDE |
|
241 if (!list.contains(QLatin1String("CDE"))) |
|
242 list << QLatin1String("CDE"); |
|
243 #endif |
|
244 #ifndef QT_NO_STYLE_S60 |
|
245 if (!list.contains(QLatin1String("S60"))) |
|
246 list << QLatin1String("S60"); |
|
247 #endif |
|
248 #ifndef QT_NO_STYLE_PLASTIQUE |
|
249 if (!list.contains(QLatin1String("Plastique"))) |
|
250 list << QLatin1String("Plastique"); |
|
251 #endif |
|
252 #ifndef QT_NO_STYLE_GTK |
|
253 if (!list.contains(QLatin1String("GTK+"))) |
|
254 list << QLatin1String("GTK+"); |
|
255 #endif |
|
256 #ifndef QT_NO_STYLE_CLEANLOOKS |
|
257 if (!list.contains(QLatin1String("Cleanlooks"))) |
|
258 list << QLatin1String("Cleanlooks"); |
|
259 #endif |
|
260 #ifndef QT_NO_STYLE_MAC |
|
261 QString mstyle = QLatin1String("Macintosh"); |
|
262 # ifdef Q_WS_MAC |
|
263 mstyle += QLatin1String(" (aqua)"); |
|
264 # endif |
|
265 if (!list.contains(mstyle)) |
|
266 list << mstyle; |
|
267 #endif |
|
268 return list; |
|
269 } |
|
270 |
|
271 QT_END_NAMESPACE |