Qt 4.8
qstylefactory.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module 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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
77 
78 #if !defined(QT_NO_STYLE_MAC) && defined(Q_WS_MAC)
80 # include "qmacstyle_mac.h"
82 #endif
83 
84 #ifndef QT_NO_LIBRARY
87 #endif
88 
125 {
126  QStyle *ret = 0;
127  QString style = key.toLower();
128 #ifndef QT_NO_STYLE_WINDOWS
129  if (style == QLatin1String("windows"))
130  ret = new QWindowsStyle;
131  else
132 #endif
133 #ifndef QT_NO_STYLE_WINDOWSCE
134  if (style == QLatin1String("windowsce"))
135  ret = new QWindowsCEStyle;
136  else
137 #endif
138 #ifndef QT_NO_STYLE_WINDOWSMOBILE
139  if (style == QLatin1String("windowsmobile"))
140  ret = new QWindowsMobileStyle;
141  else
142 #endif
143 #ifndef QT_NO_STYLE_WINDOWSXP
144  if (style == QLatin1String("windowsxp"))
145  ret = new QWindowsXPStyle;
146  else
147 #endif
148 #ifndef QT_NO_STYLE_WINDOWSVISTA
149  if (style == QLatin1String("windowsvista"))
150  ret = new QWindowsVistaStyle;
151  else
152 #endif
153 #ifndef QT_NO_STYLE_MOTIF
154  if (style == QLatin1String("motif"))
155  ret = new QMotifStyle;
156  else
157 #endif
158 #ifndef QT_NO_STYLE_CDE
159  if (style == QLatin1String("cde"))
160  ret = new QCDEStyle;
161  else
162 #endif
163 #ifndef QT_NO_STYLE_S60
164  if (style == QLatin1String("s60"))
165  ret = new QS60Style;
166  else
167 #endif
168 #ifndef QT_NO_STYLE_PLASTIQUE
169  if (style == QLatin1String("plastique"))
170  ret = new QPlastiqueStyle;
171  else
172 #endif
173 #ifndef QT_NO_STYLE_CLEANLOOKS
174  if (style == QLatin1String("cleanlooks"))
175  ret = new QCleanlooksStyle;
176  else
177 #endif
178 #ifndef QT_NO_STYLE_GTK
179  if (style == QLatin1String("gtk") || style == QLatin1String("gtk+"))
180  ret = new QGtkStyle;
181  else
182 #endif
183 #ifndef QT_NO_STYLE_MAC
184  if (style.startsWith(QLatin1String("macintosh"))) {
185  ret = new QMacStyle;
186 # ifdef Q_WS_MAC
187  if (style == QLatin1String("macintosh"))
188  style += QLatin1String(" (aqua)");
189 # endif
190  } else
191 #endif
192  { } // Keep these here - they make the #ifdefery above work
193 #if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
194  if(!ret) {
195  if (QStyleFactoryInterface *factory = qobject_cast<QStyleFactoryInterface*>(loader()->instance(style)))
196  ret = factory->create(style);
197  }
198 #endif
199  if(ret)
200  ret->setObjectName(style);
201  return ret;
202 }
203 
211 {
212 #if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
213  QStringList list = loader()->keys();
214 #else
215  QStringList list;
216 #endif
217 #ifndef QT_NO_STYLE_WINDOWS
218  if (!list.contains(QLatin1String("Windows")))
219  list << QLatin1String("Windows");
220 #endif
221 #ifndef QT_NO_STYLE_WINDOWSCE
222  if (!list.contains(QLatin1String("WindowsCE")))
223  list << QLatin1String("WindowsCE");
224 #endif
225 #ifndef QT_NO_STYLE_WINDOWSMOBILE
226  if (!list.contains(QLatin1String("WindowsMobile")))
227  list << QLatin1String("WindowsMobile");
228 #endif
229 #ifndef QT_NO_STYLE_WINDOWSXP
230  if (!list.contains(QLatin1String("WindowsXP")) &&
232  list << QLatin1String("WindowsXP");
233 #endif
234 #ifndef QT_NO_STYLE_WINDOWSVISTA
235  if (!list.contains(QLatin1String("WindowsVista")) &&
237  list << QLatin1String("WindowsVista");
238 #endif
239 #ifndef QT_NO_STYLE_MOTIF
240  if (!list.contains(QLatin1String("Motif")))
241  list << QLatin1String("Motif");
242 #endif
243 #ifndef QT_NO_STYLE_CDE
244  if (!list.contains(QLatin1String("CDE")))
245  list << QLatin1String("CDE");
246 #endif
247 #ifndef QT_NO_STYLE_S60
248  if (!list.contains(QLatin1String("S60")))
249  list << QLatin1String("S60");
250 #endif
251 #ifndef QT_NO_STYLE_PLASTIQUE
252  if (!list.contains(QLatin1String("Plastique")))
253  list << QLatin1String("Plastique");
254 #endif
255 #ifndef QT_NO_STYLE_GTK
256  if (!list.contains(QLatin1String("GTK+")))
257  list << QLatin1String("GTK+");
258 #endif
259 #ifndef QT_NO_STYLE_CLEANLOOKS
260  if (!list.contains(QLatin1String("Cleanlooks")))
261  list << QLatin1String("Cleanlooks");
262 #endif
263 #ifndef QT_NO_STYLE_MAC
264  QString mstyle = QLatin1String("Macintosh");
265 # ifdef Q_WS_MAC
266  mstyle += QLatin1String(" (aqua)");
267 # endif
268  if (!list.contains(mstyle))
269  list << mstyle;
270 #endif
271  return list;
272 }
273 
The QWindowsVistaStyle class provides a look and feel suitable for applications on Microsoft Windows ...
#define QStyleFactoryInterface_iid
Definition: qstyleplugin.h:61
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static QStyle * create(const QString &)
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
Definition: qglobal.h:92
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static const WinVersion WindowsVersion
the version of the Windows operating system on which the application is run (Windows only) ...
Definition: qglobal.h:1613
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QCDEStyle class provides a CDE look and feel.
Definition: qcdestyle.h:56
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static QStringList keys()
Returns the list of valid keys, i.e.
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
The QMotifStyle class provides Motif look and feel.
Definition: qmotifstyle.h:60
The QWindowsXPStyle class provides a Microsoft Windows XP-like look and feel.
The QCleanlooksStyle class provides a widget style similar to the Clearlooks style available in GNOME...
int key
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
The QPlastiqueStyle class provides a widget style similar to the Plastik style available in KDE...
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
Definition: qglobal.h:91
The QWindowsStyle class provides a Microsoft Windows-like look and feel.
Definition: qwindowsstyle.h:57
#define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)
Declares a global static variable with the specified type and name.
Definition: qglobal.h:1982
The QGtkStyle class provides a widget style rendered by GTK+.
Definition: qgtkstyle.h:61