[2] | 1 | /****************************************************************************
|
---|
| 2 | ** $Id: qstylefactory.cpp 174 2007-11-06 22:27:57Z dmik $
|
---|
| 3 | **
|
---|
| 4 | ** Implementation of QStyleFactory class
|
---|
| 5 | **
|
---|
| 6 | ** Created : 001103
|
---|
| 7 | **
|
---|
| 8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
|
---|
| 9 | **
|
---|
| 10 | ** This file is part of the widgets module of the Qt GUI Toolkit.
|
---|
| 11 | **
|
---|
| 12 | ** This file may be distributed under the terms of the Q Public License
|
---|
| 13 | ** as defined by Trolltech AS of Norway and appearing in the file
|
---|
| 14 | ** LICENSE.QPL included in the packaging of this file.
|
---|
| 15 | **
|
---|
| 16 | ** This file may be distributed and/or modified under the terms of the
|
---|
| 17 | ** GNU General Public License version 2 as published by the Free Software
|
---|
| 18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 19 | ** packaging of this file.
|
---|
| 20 | **
|
---|
| 21 | ** Licensees holding valid Qt Enterprise Edition licenses may use this
|
---|
| 22 | ** file in accordance with the Qt Commercial License Agreement provided
|
---|
| 23 | ** with the Software.
|
---|
| 24 | **
|
---|
| 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
| 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
| 27 | **
|
---|
| 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
| 29 | ** information about Qt Commercial License Agreements.
|
---|
| 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
---|
| 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
| 32 | **
|
---|
| 33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
| 34 | ** not clear to you.
|
---|
| 35 | **
|
---|
| 36 | **********************************************************************/
|
---|
| 37 |
|
---|
| 38 | #include "qstyleinterface_p.h" // up here for GCC 2.7.* compatibility
|
---|
| 39 | #include "qstylefactory.h"
|
---|
| 40 |
|
---|
| 41 | #ifndef QT_NO_STYLE
|
---|
| 42 |
|
---|
| 43 | #include "qapplication.h"
|
---|
| 44 | #include "qwindowsstyle.h"
|
---|
| 45 | #include "qmotifstyle.h"
|
---|
| 46 | #include "qcdestyle.h"
|
---|
| 47 | #include "qmotifplusstyle.h"
|
---|
| 48 | #include "qplatinumstyle.h"
|
---|
| 49 | #include "qsgistyle.h"
|
---|
| 50 | #include "qcompactstyle.h"
|
---|
| 51 | #ifndef QT_NO_STYLE_WINDOWSXP
|
---|
| 52 | #include "qwindowsxpstyle.h"
|
---|
| 53 | #endif
|
---|
[174] | 54 | #ifndef QT_NO_STYLE_WARP4
|
---|
| 55 | #include "qwarp4style.h"
|
---|
| 56 | #endif
|
---|
[2] | 57 | #ifndef QT_NO_STYLE_AQUA
|
---|
| 58 | #include "qaquastyle.h"
|
---|
| 59 | #endif
|
---|
| 60 | #ifndef QT_NO_STYLE_POCKETPC
|
---|
| 61 | #include "qpocketpcstyle_wce.h"
|
---|
| 62 | #endif
|
---|
| 63 |
|
---|
| 64 | #if !defined( QT_NO_STYLE_MAC ) && defined( Q_WS_MAC )
|
---|
| 65 | QCString p2qstring(const unsigned char *c); //qglobal.cpp
|
---|
| 66 | #include "qt_mac.h"
|
---|
| 67 | #include "qmacstyle_mac.h"
|
---|
| 68 | #endif
|
---|
| 69 | #include <stdlib.h>
|
---|
| 70 |
|
---|
| 71 | #include <private/qpluginmanager_p.h>
|
---|
| 72 | #ifndef QT_NO_COMPONENT
|
---|
| 73 | class QStyleFactoryPrivate : public QObject
|
---|
| 74 | {
|
---|
| 75 | public:
|
---|
| 76 | QStyleFactoryPrivate();
|
---|
| 77 | ~QStyleFactoryPrivate();
|
---|
| 78 |
|
---|
| 79 | static QPluginManager<QStyleFactoryInterface> *manager;
|
---|
| 80 | };
|
---|
| 81 |
|
---|
| 82 | static QStyleFactoryPrivate *instance = 0;
|
---|
| 83 | QPluginManager<QStyleFactoryInterface> *QStyleFactoryPrivate::manager = 0;
|
---|
| 84 |
|
---|
| 85 | QStyleFactoryPrivate::QStyleFactoryPrivate()
|
---|
| 86 | : QObject( qApp )
|
---|
| 87 | {
|
---|
| 88 | manager = new QPluginManager<QStyleFactoryInterface>( IID_QStyleFactory, QApplication::libraryPaths(), "/styles", FALSE );
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | QStyleFactoryPrivate::~QStyleFactoryPrivate()
|
---|
| 92 | {
|
---|
| 93 | delete manager;
|
---|
| 94 | manager = 0;
|
---|
| 95 |
|
---|
| 96 | instance = 0;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | #endif //QT_NO_COMPONENT
|
---|
| 100 |
|
---|
| 101 | /*!
|
---|
| 102 | \class QStyleFactory qstylefactory.h
|
---|
| 103 | \brief The QStyleFactory class creates QStyle objects.
|
---|
| 104 |
|
---|
| 105 | The style factory creates a QStyle object for a given key with
|
---|
| 106 | QStyleFactory::create(key).
|
---|
| 107 |
|
---|
| 108 | The styles are either built-in or dynamically loaded from a style
|
---|
| 109 | plugin (see \l QStylePlugin).
|
---|
| 110 |
|
---|
| 111 | QStyleFactory::keys() returns a list of valid keys, typically
|
---|
| 112 | including "windows", "motif", "cde", "motifplus", "platinum",
|
---|
| 113 | "sgi" and "compact". Depending on the platform, "windowsxp",
|
---|
[174] | 114 | "warp4", "aqua" or "macintosh" may be available.
|
---|
[2] | 115 | */
|
---|
| 116 |
|
---|
| 117 | /*!
|
---|
| 118 | Creates a QStyle object that matches \a key. This is either a
|
---|
| 119 | built-in style, or a style from a style plugin.
|
---|
| 120 |
|
---|
| 121 | \sa keys()
|
---|
| 122 | */
|
---|
| 123 | QStyle *QStyleFactory::create( const QString& key )
|
---|
| 124 | {
|
---|
| 125 | QStyle *ret = 0;
|
---|
| 126 | QString style = key.lower();
|
---|
| 127 | #ifndef QT_NO_STYLE_WINDOWS
|
---|
| 128 | if ( style == "windows" )
|
---|
| 129 | ret = new QWindowsStyle;
|
---|
| 130 | else
|
---|
| 131 | #endif
|
---|
| 132 | #ifndef QT_NO_STYLE_WINDOWSXP
|
---|
| 133 | if ( style == "windowsxp" )
|
---|
| 134 | ret = new QWindowsXPStyle;
|
---|
| 135 | else
|
---|
| 136 | #endif
|
---|
[174] | 137 | #ifndef QT_NO_STYLE_WARP4
|
---|
| 138 | if ( style == "warp4" )
|
---|
| 139 | ret = new QWarp4Style;
|
---|
| 140 | else
|
---|
| 141 | #endif
|
---|
[2] | 142 | #ifndef QT_NO_STYLE_MOTIF
|
---|
| 143 | if ( style == "motif" )
|
---|
| 144 | ret = new QMotifStyle;
|
---|
| 145 | else
|
---|
| 146 | #endif
|
---|
| 147 | #ifndef QT_NO_STYLE_CDE
|
---|
| 148 | if ( style == "cde" )
|
---|
| 149 | ret = new QCDEStyle;
|
---|
| 150 | else
|
---|
| 151 | #endif
|
---|
| 152 | #ifndef QT_NO_STYLE_MOTIFPLUS
|
---|
| 153 | if ( style == "motifplus" )
|
---|
| 154 | ret = new QMotifPlusStyle;
|
---|
| 155 | else
|
---|
| 156 | #endif
|
---|
| 157 | #ifndef QT_NO_STYLE_PLATINUM
|
---|
| 158 | if ( style == "platinum" )
|
---|
| 159 | ret = new QPlatinumStyle;
|
---|
| 160 | else
|
---|
| 161 | #endif
|
---|
| 162 | #ifndef QT_NO_STYLE_SGI
|
---|
| 163 | if ( style == "sgi")
|
---|
| 164 | ret = new QSGIStyle;
|
---|
| 165 | else
|
---|
| 166 | #endif
|
---|
| 167 | #ifndef QT_NO_STYLE_COMPACT
|
---|
| 168 | if ( style == "compact" )
|
---|
| 169 | ret = new QCompactStyle;
|
---|
| 170 | else
|
---|
| 171 | #endif
|
---|
| 172 | #ifndef QT_NO_STYLE_AQUA
|
---|
| 173 | if ( style == "aqua" )
|
---|
| 174 | ret = new QAquaStyle;
|
---|
[174] | 175 | else
|
---|
[2] | 176 | #endif
|
---|
| 177 | #ifndef QT_NO_STYLE_POCKETPC
|
---|
| 178 | if ( style == "pocketpc" )
|
---|
[174] | 179 | ret = new QPocketPCStyle;
|
---|
| 180 | else
|
---|
[2] | 181 | #endif
|
---|
| 182 | #if !defined( QT_NO_STYLE_MAC ) && defined( Q_WS_MAC )
|
---|
| 183 | if( style.left(9) == "macintosh" )
|
---|
[174] | 184 | ret = new QMacStyle;
|
---|
| 185 | else
|
---|
[2] | 186 | #endif
|
---|
| 187 | { } // Keep these here - they make the #ifdefery above work
|
---|
| 188 |
|
---|
| 189 | #ifndef QT_NO_COMPONENT
|
---|
| 190 | if(!ret) {
|
---|
| 191 | if ( !instance )
|
---|
| 192 | instance = new QStyleFactoryPrivate;
|
---|
| 193 |
|
---|
| 194 | QInterfacePtr<QStyleFactoryInterface> iface;
|
---|
| 195 | QStyleFactoryPrivate::manager->queryInterface( style, &iface );
|
---|
| 196 |
|
---|
| 197 | if ( iface )
|
---|
| 198 | ret = iface->create( style );
|
---|
| 199 | }
|
---|
| 200 | if(ret)
|
---|
| 201 | ret->setName(key);
|
---|
| 202 | #endif
|
---|
| 203 | return ret;
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | #ifndef QT_NO_STRINGLIST
|
---|
| 207 | /*!
|
---|
| 208 | Returns the list of keys this factory can create styles for.
|
---|
| 209 |
|
---|
| 210 | \sa create()
|
---|
| 211 | */
|
---|
| 212 | QStringList QStyleFactory::keys()
|
---|
| 213 | {
|
---|
| 214 | QStringList list;
|
---|
| 215 | #ifndef QT_NO_COMPONENT
|
---|
| 216 | if ( !instance )
|
---|
| 217 | instance = new QStyleFactoryPrivate;
|
---|
| 218 |
|
---|
| 219 | list = QStyleFactoryPrivate::manager->featureList();
|
---|
| 220 | #endif //QT_NO_COMPONENT
|
---|
| 221 |
|
---|
| 222 | #ifndef QT_NO_STYLE_WINDOWS
|
---|
| 223 | if ( !list.contains( "Windows" ) )
|
---|
| 224 | list << "Windows";
|
---|
| 225 | #endif
|
---|
| 226 | #ifndef QT_NO_STYLE_WINDOWSXP
|
---|
| 227 | if ( !list.contains( "WindowsXP" ) && QWindowsXPStyle::resolveSymbols() )
|
---|
| 228 | list << "WindowsXP";
|
---|
| 229 | #endif
|
---|
[174] | 230 | #ifndef QT_NO_STYLE_WARP4
|
---|
| 231 | if ( !list.contains( "Warp4" ) )
|
---|
| 232 | list << "Warp4";
|
---|
| 233 | #endif
|
---|
[2] | 234 | #ifndef QT_NO_STYLE_MOTIF
|
---|
| 235 | if ( !list.contains( "Motif" ) )
|
---|
| 236 | list << "Motif";
|
---|
| 237 | #endif
|
---|
| 238 | #ifndef QT_NO_STYLE_CDE
|
---|
| 239 | if ( !list.contains( "CDE" ) )
|
---|
| 240 | list << "CDE";
|
---|
| 241 | #endif
|
---|
| 242 | #ifndef QT_NO_STYLE_MOTIFPLUS
|
---|
| 243 | if ( !list.contains( "MotifPlus" ) )
|
---|
| 244 | list << "MotifPlus";
|
---|
| 245 | #endif
|
---|
| 246 | #ifndef QT_NO_STYLE_PLATINUM
|
---|
| 247 | if ( !list.contains( "Platinum" ) )
|
---|
| 248 | list << "Platinum";
|
---|
| 249 | #endif
|
---|
| 250 | #ifndef QT_NO_STYLE_SGI
|
---|
| 251 | if ( !list.contains( "SGI" ) )
|
---|
| 252 | list << "SGI";
|
---|
| 253 | #endif
|
---|
| 254 | #ifndef QT_NO_STYLE_COMPACT
|
---|
| 255 | if ( !list.contains( "Compact" ) )
|
---|
| 256 | list << "Compact";
|
---|
| 257 | #endif
|
---|
| 258 | #ifndef QT_NO_STYLE_AQUA
|
---|
| 259 | if ( !list.contains( "Aqua" ) )
|
---|
| 260 | list << "Aqua";
|
---|
| 261 | #endif
|
---|
| 262 | #if !defined( QT_NO_STYLE_MAC ) && defined( Q_WS_MAC )
|
---|
| 263 | QString mstyle = "Macintosh";
|
---|
| 264 | Collection c = NewCollection();
|
---|
| 265 | if (c) {
|
---|
| 266 | GetTheme(c);
|
---|
| 267 | Str255 str;
|
---|
| 268 | long int s = 256;
|
---|
| 269 | if(!GetCollectionItem(c, kThemeNameTag, 0, &s, &str))
|
---|
| 270 | mstyle += " (" + p2qstring(str) + ")";
|
---|
| 271 | }
|
---|
| 272 | if (!list.contains(mstyle))
|
---|
| 273 | list << mstyle;
|
---|
| 274 | DisposeCollection(c);
|
---|
| 275 | #endif
|
---|
| 276 |
|
---|
| 277 | return list;
|
---|
| 278 | }
|
---|
| 279 | #endif
|
---|
| 280 | #endif // QT_NO_STYLE
|
---|