| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: qstyleplugin.cpp 2 2005-11-16 15:49:26Z dmik $
|
|---|
| 3 | **
|
|---|
| 4 | ** Implementation of QSqlDriverPlugin class
|
|---|
| 5 | **
|
|---|
| 6 | ** Created : 010920
|
|---|
| 7 | **
|
|---|
| 8 | ** Copyright (C) 2001 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 or Qt Professional Edition
|
|---|
| 22 | ** licenses may use this file in accordance with the Qt Commercial License
|
|---|
| 23 | ** Agreement provided 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 "qstyleplugin.h"
|
|---|
| 39 |
|
|---|
| 40 | #ifndef QT_NO_STYLE
|
|---|
| 41 | #ifndef QT_NO_COMPONENT
|
|---|
| 42 |
|
|---|
| 43 | #include "qstyleinterface_p.h"
|
|---|
| 44 | #include "qobjectcleanuphandler.h"
|
|---|
| 45 | #include "qstyle.h"
|
|---|
| 46 |
|
|---|
| 47 | /*!
|
|---|
| 48 | \class QStylePlugin qstyleplugin.h
|
|---|
| 49 | \brief The QStylePlugin class provides an abstract base for custom QStyle plugins.
|
|---|
| 50 |
|
|---|
| 51 | \ingroup plugins
|
|---|
| 52 |
|
|---|
| 53 | The style plugin is a simple plugin interface that makes it easy
|
|---|
| 54 | to create custom styles that can be loaded dynamically into
|
|---|
| 55 | applications with a QStyleFactory.
|
|---|
| 56 |
|
|---|
| 57 | Writing a style plugin is achieved by subclassing this base class,
|
|---|
| 58 | reimplementing the pure virtual functions keys() and create(), and
|
|---|
| 59 | exporting the class with the \c Q_EXPORT_PLUGIN macro. See the
|
|---|
| 60 | \link plugins-howto.html plugins documentation\endlink for an
|
|---|
| 61 | example.
|
|---|
| 62 | */
|
|---|
| 63 |
|
|---|
| 64 | /*!
|
|---|
| 65 | \fn QStringList QStylePlugin::keys() const
|
|---|
| 66 |
|
|---|
| 67 | Returns the list of style keys this plugin supports.
|
|---|
| 68 |
|
|---|
| 69 | These keys are usually the class names of the custom styles that
|
|---|
| 70 | are implemented in the plugin.
|
|---|
| 71 |
|
|---|
| 72 | \sa create()
|
|---|
| 73 | */
|
|---|
| 74 |
|
|---|
| 75 | /*!
|
|---|
| 76 | \fn QStyle* QStylePlugin::create( const QString& key )
|
|---|
| 77 |
|
|---|
| 78 | Creates and returns a QStyle object for the style key \a key. The
|
|---|
| 79 | style key is usually the class name of the required style.
|
|---|
| 80 |
|
|---|
| 81 | \sa keys()
|
|---|
| 82 | */
|
|---|
| 83 |
|
|---|
| 84 | class QStylePluginPrivate : public QStyleFactoryInterface, public QLibraryInterface
|
|---|
| 85 | {
|
|---|
| 86 | public:
|
|---|
| 87 | QStylePluginPrivate( QStylePlugin *p )
|
|---|
| 88 | : plugin( p )
|
|---|
| 89 | {
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | virtual ~QStylePluginPrivate();
|
|---|
| 93 |
|
|---|
| 94 | QRESULT queryInterface( const QUuid &iid, QUnknownInterface **iface );
|
|---|
| 95 | Q_REFCOUNT;
|
|---|
| 96 |
|
|---|
| 97 | QStringList featureList() const;
|
|---|
| 98 | QStyle *create( const QString &key );
|
|---|
| 99 |
|
|---|
| 100 | bool init();
|
|---|
| 101 | void cleanup();
|
|---|
| 102 | bool canUnload() const;
|
|---|
| 103 |
|
|---|
| 104 | private:
|
|---|
| 105 | QStylePlugin *plugin;
|
|---|
| 106 | QObjectCleanupHandler styles;
|
|---|
| 107 | };
|
|---|
| 108 |
|
|---|
| 109 | QRESULT QStylePluginPrivate::queryInterface( const QUuid &iid, QUnknownInterface **iface )
|
|---|
| 110 | {
|
|---|
| 111 | *iface = 0;
|
|---|
| 112 |
|
|---|
| 113 | if ( iid == IID_QUnknown )
|
|---|
| 114 | *iface = (QStyleFactoryInterface*)this;
|
|---|
| 115 | else if ( iid == IID_QFeatureList )
|
|---|
| 116 | *iface = (QFeatureListInterface*)this;
|
|---|
| 117 | else if ( iid == IID_QStyleFactory )
|
|---|
| 118 | *iface = (QStyleFactoryInterface*)this;
|
|---|
| 119 | else if ( iid == IID_QLibrary )
|
|---|
| 120 | *iface = (QLibraryInterface*) this;
|
|---|
| 121 | else
|
|---|
| 122 | return QE_NOINTERFACE;
|
|---|
| 123 |
|
|---|
| 124 | (*iface)->addRef();
|
|---|
| 125 | return QS_OK;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | QStylePluginPrivate::~QStylePluginPrivate()
|
|---|
| 129 | {
|
|---|
| 130 | delete plugin;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | QStringList QStylePluginPrivate::featureList() const
|
|---|
| 134 | {
|
|---|
| 135 | return plugin->keys();
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | QStyle *QStylePluginPrivate::create( const QString &key )
|
|---|
| 139 | {
|
|---|
| 140 | QStyle *st = plugin->create( key );
|
|---|
| 141 | styles.add( st );
|
|---|
| 142 | return st;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | bool QStylePluginPrivate::init()
|
|---|
| 146 | {
|
|---|
| 147 | return TRUE;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | void QStylePluginPrivate::cleanup()
|
|---|
| 151 | {
|
|---|
| 152 | styles.clear();
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | bool QStylePluginPrivate::canUnload() const
|
|---|
| 156 | {
|
|---|
| 157 | return styles.isEmpty();
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 | /*!
|
|---|
| 162 | Constructs a style plugin. This is invoked automatically by the
|
|---|
| 163 | \c Q_EXPORT_PLUGIN macro.
|
|---|
| 164 | */
|
|---|
| 165 | QStylePlugin::QStylePlugin()
|
|---|
| 166 | : QGPlugin( (QStyleFactoryInterface*)(d = new QStylePluginPrivate( this )) )
|
|---|
| 167 | {
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | /*!
|
|---|
| 171 | Destroys the style plugin.
|
|---|
| 172 |
|
|---|
| 173 | You never have to call this explicitly. Qt destroys a plugin
|
|---|
| 174 | automatically when it is no longer used.
|
|---|
| 175 | */
|
|---|
| 176 | QStylePlugin::~QStylePlugin()
|
|---|
| 177 | {
|
|---|
| 178 | // don't delete d, as this is deleted by d
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | #endif // QT_NO_COMPONENT
|
|---|
| 182 | #endif // QT_NO_STYLE
|
|---|