source: trunk/src/gui/styles/qstylefactory.cpp@ 441

Last change on this file since 441 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 7.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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
73QT_BEGIN_NAMESPACE
74
75#if !defined(QT_NO_STYLE_MAC) && defined(Q_WS_MAC)
76QT_BEGIN_INCLUDE_NAMESPACE
77# include "qmacstyle_mac.h"
78QT_END_INCLUDE_NAMESPACE
79#endif
80
81#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
82Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
83 (QStyleFactoryInterface_iid, QLatin1String("/styles"), Qt::CaseInsensitive))
84#endif
85
86/*!
87 \class QStyleFactory
88 \brief The QStyleFactory class creates QStyle objects.
89
90 \ingroup appearance
91
92 The QStyle class is an abstract base class that encapsulates the
93 look and feel of a GUI. QStyleFactory creates a QStyle object
94 using the create() function and a key identifying the style. The
95 styles are either built-in or dynamically loaded from a style
96 plugin (see QStylePlugin).
97
98 The valid keys can be retrieved using the keys()
99 function. Typically they include "windows", "motif", "cde",
100 "plastique" and "cleanlooks". Depending on the platform,
101 "windowsxp", "windowsvista" and "macintosh" may be available.
102 Note that keys are case insensitive.
103
104 \sa QStyle
105*/
106
107/*!
108 Creates and returns a QStyle object that matches the given \a key, or
109 returns 0 if no matching style is found.
110
111 Both built-in styles and styles from style plugins are queried for a
112 matching style.
113
114 \note The keys used are case insensitive.
115
116 \sa keys()
117*/
118QStyle *QStyleFactory::create(const QString& key)
119{
120 QStyle *ret = 0;
121 QString style = key.toLower();
122#ifndef QT_NO_STYLE_WINDOWS
123 if (style == QLatin1String("windows"))
124 ret = new QWindowsStyle;
125 else
126#endif
127#ifndef QT_NO_STYLE_WINDOWSCE
128 if (style == QLatin1String("windowsce"))
129 ret = new QWindowsCEStyle;
130 else
131#endif
132#ifndef QT_NO_STYLE_WINDOWSMOBILE
133 if (style == QLatin1String("windowsmobile"))
134 ret = new QWindowsMobileStyle;
135 else
136#endif
137#ifndef QT_NO_STYLE_WINDOWSXP
138 if (style == QLatin1String("windowsxp"))
139 ret = new QWindowsXPStyle;
140 else
141#endif
142#ifndef QT_NO_STYLE_WINDOWSVISTA
143 if (style == QLatin1String("windowsvista"))
144 ret = new QWindowsVistaStyle;
145 else
146#endif
147#ifndef QT_NO_STYLE_MOTIF
148 if (style == QLatin1String("motif"))
149 ret = new QMotifStyle;
150 else
151#endif
152#ifndef QT_NO_STYLE_CDE
153 if (style == QLatin1String("cde"))
154 ret = new QCDEStyle;
155 else
156#endif
157#ifndef QT_NO_STYLE_PLASTIQUE
158 if (style == QLatin1String("plastique"))
159 ret = new QPlastiqueStyle;
160 else
161#endif
162#ifndef QT_NO_STYLE_CLEANLOOKS
163 if (style == QLatin1String("cleanlooks"))
164 ret = new QCleanlooksStyle;
165 else
166#endif
167#ifndef QT_NO_STYLE_GTK
168 if (style == QLatin1String("gtk") || style == QLatin1String("gtk+"))
169 ret = new QGtkStyle;
170 else
171#endif
172#ifndef QT_NO_STYLE_MAC
173 if (style.left(9) == QLatin1String("macintosh")) {
174 ret = new QMacStyle;
175# ifdef Q_WS_MAC
176 if (style == QLatin1String("macintosh"))
177 style += QLatin1String(" (aqua)");
178# endif
179 } else
180#endif
181 { } // Keep these here - they make the #ifdefery above work
182#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
183 if(!ret) {
184 if (QStyleFactoryInterface *factory = qobject_cast<QStyleFactoryInterface*>(loader()->instance(style)))
185 ret = factory->create(style);
186 }
187#endif
188 if(ret)
189 ret->setObjectName(style);
190 return ret;
191}
192
193/*!
194 Returns the list of valid keys, i.e. the keys this factory can
195 create styles for.
196
197 \sa create()
198*/
199QStringList QStyleFactory::keys()
200{
201#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
202 QStringList list = loader()->keys();
203#else
204 QStringList list;
205#endif
206#ifndef QT_NO_STYLE_WINDOWS
207 if (!list.contains(QLatin1String("Windows")))
208 list << QLatin1String("Windows");
209#endif
210#ifndef QT_NO_STYLE_WINDOWSCE
211 if (!list.contains(QLatin1String("WindowsCE")))
212 list << QLatin1String("WindowsCE");
213#endif
214#ifndef QT_NO_STYLE_WINDOWSMOBILE
215 if (!list.contains(QLatin1String("WindowsMobile")))
216 list << QLatin1String("WindowsMobile");
217#endif
218#ifndef QT_NO_STYLE_WINDOWSXP
219 if (!list.contains(QLatin1String("WindowsXP")) &&
220 (QSysInfo::WindowsVersion >= QSysInfo::WV_XP && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based))
221 list << QLatin1String("WindowsXP");
222#endif
223#ifndef QT_NO_STYLE_WINDOWSVISTA
224 if (!list.contains(QLatin1String("WindowsVista")) &&
225 (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based))
226 list << QLatin1String("WindowsVista");
227#endif
228#ifndef QT_NO_STYLE_MOTIF
229 if (!list.contains(QLatin1String("Motif")))
230 list << QLatin1String("Motif");
231#endif
232#ifndef QT_NO_STYLE_CDE
233 if (!list.contains(QLatin1String("CDE")))
234 list << QLatin1String("CDE");
235#endif
236#ifndef QT_NO_STYLE_PLASTIQUE
237 if (!list.contains(QLatin1String("Plastique")))
238 list << QLatin1String("Plastique");
239#endif
240#ifndef QT_NO_STYLE_GTK
241 if (!list.contains(QLatin1String("GTK+")))
242 list << QLatin1String("GTK+");
243#endif
244#ifndef QT_NO_STYLE_CLEANLOOKS
245 if (!list.contains(QLatin1String("Cleanlooks")))
246 list << QLatin1String("Cleanlooks");
247#endif
248#ifndef QT_NO_STYLE_MAC
249 QString mstyle = QLatin1String("Macintosh");
250# ifdef Q_WS_MAC
251 mstyle += QLatin1String(" (aqua)");
252# endif
253 if (!list.contains(mstyle))
254 list << mstyle;
255#endif
256 return list;
257}
258
259QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.