| 1 | /**************************************************************************** | 
|---|
| 2 | ** $Id: qwidgetplugin.cpp 2 2005-11-16 15:49:26Z dmik $ | 
|---|
| 3 | ** | 
|---|
| 4 | ** Implementation of QWidgetPlugin class | 
|---|
| 5 | ** | 
|---|
| 6 | ** Created : 010920 | 
|---|
| 7 | ** | 
|---|
| 8 | ** Copyright (C) 2001-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 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 "qwidgetplugin.h" | 
|---|
| 39 |  | 
|---|
| 40 | #ifndef QT_NO_WIDGETPLUGIN | 
|---|
| 41 | #include "qwidgetinterface_p.h" | 
|---|
| 42 | #include "qobjectcleanuphandler.h" | 
|---|
| 43 | #include "qwidget.h" | 
|---|
| 44 | #include "qwidgetlist.h" | 
|---|
| 45 |  | 
|---|
| 46 | /*! | 
|---|
| 47 | \class QWidgetPlugin qwidgetplugin.h | 
|---|
| 48 | \brief The QWidgetPlugin class provides an abstract base for custom QWidget plugins. | 
|---|
| 49 |  | 
|---|
| 50 | \ingroup plugins | 
|---|
| 51 |  | 
|---|
| 52 | The widget plugin is a simple plugin interface that makes it easy | 
|---|
| 53 | to create custom widgets that can be included in forms using \link | 
|---|
| 54 | designer-manual.book Qt Designer\endlink and used by applications. | 
|---|
| 55 |  | 
|---|
| 56 | Writing a widget plugin is achieved by subclassing this base | 
|---|
| 57 | class, reimplementing the pure virtual functions keys(), create(), | 
|---|
| 58 | group(), iconSet(), includeFile(), toolTip(), whatsThis() and | 
|---|
| 59 | isContainer(), and exporting the class with the \c Q_EXPORT_PLUGIN | 
|---|
| 60 | macro. | 
|---|
| 61 |  | 
|---|
| 62 | See the \link designer-manual.book Qt Designer manual's\endlink, | 
|---|
| 63 | 'Creating Custom Widgets' section in the 'Creating Custom Widgets' | 
|---|
| 64 | chapter, for a complete example of a QWidgetPlugin. | 
|---|
| 65 |  | 
|---|
| 66 | See also the \link plugins-howto.html Plugins | 
|---|
| 67 | documentation\endlink and the \l{QWidgetFactory} class that is | 
|---|
| 68 | supplied with \link designer-manual.book Qt Designer\endlink. | 
|---|
| 69 | */ | 
|---|
| 70 |  | 
|---|
| 71 | class QWidgetPluginPrivate : public QWidgetFactoryInterface, | 
|---|
| 72 | public QWidgetContainerInterfacePrivate, | 
|---|
| 73 | private QLibraryInterface | 
|---|
| 74 | { | 
|---|
| 75 | public: | 
|---|
| 76 | QWidgetPluginPrivate( QWidgetPlugin *p ) | 
|---|
| 77 | : plugin( p ) | 
|---|
| 78 | { | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | virtual ~QWidgetPluginPrivate(); | 
|---|
| 82 |  | 
|---|
| 83 | QRESULT queryInterface( const QUuid &iid, QUnknownInterface **iface ); | 
|---|
| 84 | Q_REFCOUNT; | 
|---|
| 85 |  | 
|---|
| 86 | QStringList featureList() const; | 
|---|
| 87 | QWidget *create( const QString &key, QWidget *parent, const char *name ); | 
|---|
| 88 | QString group( const QString &widget ) const; | 
|---|
| 89 | QIconSet iconSet( const QString &widget ) const; | 
|---|
| 90 | QString includeFile( const QString &widget ) const; | 
|---|
| 91 | QString toolTip( const QString &widget ) const; | 
|---|
| 92 | QString whatsThis( const QString &widget ) const; | 
|---|
| 93 | bool isContainer( const QString &widget ) const; | 
|---|
| 94 | QWidget* containerOfWidget( const QString &key, QWidget *widget ) const; | 
|---|
| 95 | bool isPassiveInteractor( const QString &key, QWidget *widget ) const; | 
|---|
| 96 | bool supportsPages( const QString &key ) const; | 
|---|
| 97 | QWidget *addPage( const QString &key, QWidget *container, const QString &name, int index ) const; | 
|---|
| 98 | void insertPage( const QString &key, QWidget *container, | 
|---|
| 99 | const QString &name, int index, QWidget *page ) const; | 
|---|
| 100 | void Page( const QString &key, QWidget *container, | 
|---|
| 101 | const QString &name, int index, QWidget *page ) const; | 
|---|
| 102 | void removePage( const QString &key, QWidget *container, int index ) const; | 
|---|
| 103 | void movePage( const QString &key, QWidget *container, int fromIndex, int toIndex ) const; | 
|---|
| 104 | int count( const QString &key, QWidget *container ) const; | 
|---|
| 105 | int currentIndex( const QString &key, QWidget *container ) const; | 
|---|
| 106 | QString pageLabel( const QString &key, QWidget *container, int index ) const; | 
|---|
| 107 | QWidget *page( const QString &key, QWidget *container, int index ) const; | 
|---|
| 108 | void renamePage( const QString &key, QWidget *container, int index, const QString &newName ) const; | 
|---|
| 109 | QWidgetList pages( const QString &key, QWidget *container ) const; | 
|---|
| 110 | QString createCode( const QString &key, const QString &container, | 
|---|
| 111 | const QString &page, const QString &pageName ) const; | 
|---|
| 112 |  | 
|---|
| 113 | bool init(); | 
|---|
| 114 | void cleanup(); | 
|---|
| 115 | bool canUnload() const; | 
|---|
| 116 |  | 
|---|
| 117 | private: | 
|---|
| 118 | QWidgetPlugin *plugin; | 
|---|
| 119 | QObjectCleanupHandler widgets; | 
|---|
| 120 | }; | 
|---|
| 121 |  | 
|---|
| 122 | QRESULT QWidgetPluginPrivate::queryInterface( const QUuid &iid, QUnknownInterface **iface ) | 
|---|
| 123 | { | 
|---|
| 124 | *iface = 0; | 
|---|
| 125 |  | 
|---|
| 126 | if ( iid == IID_QUnknown ) | 
|---|
| 127 | *iface = (QWidgetFactoryInterface*)this; | 
|---|
| 128 | else if ( iid == IID_QFeatureList ) | 
|---|
| 129 | *iface = (QFeatureListInterface*)this; | 
|---|
| 130 | else if ( iid == IID_QWidgetFactory ) | 
|---|
| 131 | *iface = (QWidgetFactoryInterface*)this; | 
|---|
| 132 | else if ( iid == IID_QLibrary ) | 
|---|
| 133 | *iface = (QLibraryInterface*)this; | 
|---|
| 134 | else if ( iid == IID_QWidgetContainer ) | 
|---|
| 135 | *iface = (QWidgetContainerInterfacePrivate*)this; | 
|---|
| 136 | else | 
|---|
| 137 | return QE_NOINTERFACE; | 
|---|
| 138 |  | 
|---|
| 139 | (*iface)->addRef(); | 
|---|
| 140 | return QS_OK; | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 | /*! | 
|---|
| 144 | \fn QStringList QWidgetPlugin::keys() const | 
|---|
| 145 |  | 
|---|
| 146 | Returns the list of widget keys this plugin supports. | 
|---|
| 147 |  | 
|---|
| 148 | These keys must be the class names of the custom widgets that are | 
|---|
| 149 | implemented in the plugin. | 
|---|
| 150 |  | 
|---|
| 151 | \sa create() | 
|---|
| 152 | */ | 
|---|
| 153 |  | 
|---|
| 154 | /*! | 
|---|
| 155 | \fn QWidget *QWidgetPlugin::create( const QString &, QWidget *, const char * ) | 
|---|
| 156 |  | 
|---|
| 157 | Creates and returns a QWidget object for the widget key \a key. | 
|---|
| 158 | The widget key is the class name of the required widget. The \a | 
|---|
| 159 | name and \a parent arguments are passed to the custom widget's | 
|---|
| 160 | constructor. | 
|---|
| 161 |  | 
|---|
| 162 | \sa keys() | 
|---|
| 163 | */ | 
|---|
| 164 |  | 
|---|
| 165 | QWidgetPluginPrivate::~QWidgetPluginPrivate() | 
|---|
| 166 | { | 
|---|
| 167 | delete plugin; | 
|---|
| 168 | } | 
|---|
| 169 |  | 
|---|
| 170 | QStringList QWidgetPluginPrivate::featureList() const | 
|---|
| 171 | { | 
|---|
| 172 | return plugin->keys(); | 
|---|
| 173 | } | 
|---|
| 174 |  | 
|---|
| 175 | QWidget *QWidgetPluginPrivate::create( const QString &key, QWidget *parent, const char *name ) | 
|---|
| 176 | { | 
|---|
| 177 | QWidget *w = plugin->create( key, parent, name ); | 
|---|
| 178 | widgets.add( w ); | 
|---|
| 179 | return w; | 
|---|
| 180 | } | 
|---|
| 181 |  | 
|---|
| 182 | QString QWidgetPluginPrivate::group( const QString &widget ) const | 
|---|
| 183 | { | 
|---|
| 184 | return plugin->group( widget ); | 
|---|
| 185 | } | 
|---|
| 186 |  | 
|---|
| 187 | QIconSet QWidgetPluginPrivate::iconSet( const QString &widget ) const | 
|---|
| 188 | { | 
|---|
| 189 | return plugin->iconSet( widget ); | 
|---|
| 190 | } | 
|---|
| 191 |  | 
|---|
| 192 | QString QWidgetPluginPrivate::includeFile( const QString &widget ) const | 
|---|
| 193 | { | 
|---|
| 194 | return plugin->includeFile( widget ); | 
|---|
| 195 | } | 
|---|
| 196 |  | 
|---|
| 197 | QString QWidgetPluginPrivate::toolTip( const QString &widget ) const | 
|---|
| 198 | { | 
|---|
| 199 | return plugin->toolTip( widget ); | 
|---|
| 200 | } | 
|---|
| 201 |  | 
|---|
| 202 | QString QWidgetPluginPrivate::whatsThis( const QString &widget ) const | 
|---|
| 203 | { | 
|---|
| 204 | return plugin->whatsThis( widget ); | 
|---|
| 205 | } | 
|---|
| 206 |  | 
|---|
| 207 | bool QWidgetPluginPrivate::isContainer( const QString &widget ) const | 
|---|
| 208 | { | 
|---|
| 209 | return plugin->isContainer( widget ); | 
|---|
| 210 | } | 
|---|
| 211 |  | 
|---|
| 212 | bool QWidgetPluginPrivate::init() | 
|---|
| 213 | { | 
|---|
| 214 | return TRUE; | 
|---|
| 215 | } | 
|---|
| 216 |  | 
|---|
| 217 | void QWidgetPluginPrivate::cleanup() | 
|---|
| 218 | { | 
|---|
| 219 | widgets.clear(); | 
|---|
| 220 | } | 
|---|
| 221 |  | 
|---|
| 222 | bool QWidgetPluginPrivate::canUnload() const | 
|---|
| 223 | { | 
|---|
| 224 | return widgets.isEmpty(); | 
|---|
| 225 | } | 
|---|
| 226 |  | 
|---|
| 227 | QWidget* QWidgetPluginPrivate::containerOfWidget( const QString &key, QWidget *widget ) const | 
|---|
| 228 | { | 
|---|
| 229 | QWidgetContainerPlugin *p = (QWidgetContainerPlugin*)plugin->qt_cast( "QWidgetContainerPlugin" ); | 
|---|
| 230 | if ( p ) | 
|---|
| 231 | return p->containerOfWidget( key, widget ); | 
|---|
| 232 | return widget; | 
|---|
| 233 | } | 
|---|
| 234 |  | 
|---|
| 235 | int QWidgetPluginPrivate::count( const QString &key, QWidget *container ) const | 
|---|
| 236 | { | 
|---|
| 237 | QWidgetContainerPlugin *p = (QWidgetContainerPlugin*)plugin->qt_cast( "QWidgetContainerPlugin" ); | 
|---|
| 238 | if ( p ) | 
|---|
| 239 | return p->count( key, container ); | 
|---|
| 240 | return 0; | 
|---|
| 241 | } | 
|---|
| 242 |  | 
|---|
| 243 | int QWidgetPluginPrivate::currentIndex( const QString &key, QWidget *container ) const | 
|---|
| 244 | { | 
|---|
| 245 | QWidgetContainerPlugin *p = (QWidgetContainerPlugin*)plugin->qt_cast( "QWidgetContainerPlugin" ); | 
|---|
| 246 | if ( p ) | 
|---|
| 247 | return p->currentIndex( key, container ); | 
|---|
| 248 | return -1; | 
|---|
| 249 | } | 
|---|
| 250 |  | 
|---|
| 251 | QString QWidgetPluginPrivate::pageLabel( const QString &key, QWidget *container, int index ) const | 
|---|
| 252 | { | 
|---|
| 253 | QWidgetContainerPlugin *p = (QWidgetContainerPlugin*)plugin->qt_cast( "QWidgetContainerPlugin" ); | 
|---|
| 254 | if ( p ) | 
|---|
| 255 | return p->pageLabel( key, container, index ); | 
|---|
| 256 | return QString::null; | 
|---|
| 257 | } | 
|---|
| 258 |  | 
|---|
| 259 | QWidget *QWidgetPluginPrivate::page( const QString &key, QWidget *container, int index ) const | 
|---|
| 260 | { | 
|---|
| 261 | QWidgetContainerPlugin *p = (QWidgetContainerPlugin*)plugin->qt_cast( "QWidgetContainerPlugin" ); | 
|---|
| 262 | if ( p ) | 
|---|
| 263 | return p->page( key, container, index ); | 
|---|
| 264 | return 0; | 
|---|
| 265 | } | 
|---|
| 266 |  | 
|---|
| 267 | bool QWidgetPluginPrivate::isPassiveInteractor( const QString &key, QWidget *widget ) const | 
|---|
| 268 | { | 
|---|
| 269 | QWidgetContainerPlugin *p = (QWidgetContainerPlugin*)plugin->qt_cast( "QWidgetContainerPlugin" ); | 
|---|
| 270 | if ( p ) | 
|---|
| 271 | return p->isPassiveInteractor( key, widget ); | 
|---|
| 272 | return FALSE; | 
|---|
| 273 | } | 
|---|
| 274 |  | 
|---|
| 275 | bool QWidgetPluginPrivate::supportsPages( const QString &key ) const | 
|---|
| 276 | { | 
|---|
| 277 | QWidgetContainerPlugin *p = (QWidgetContainerPlugin*)plugin->qt_cast( "QWidgetContainerPlugin" ); | 
|---|
| 278 | if ( p ) | 
|---|
| 279 | return p->supportsPages( key ); | 
|---|
| 280 | return 0; | 
|---|
| 281 | } | 
|---|
| 282 |  | 
|---|
| 283 | QWidget *QWidgetPluginPrivate::addPage( const QString &key, QWidget *container, | 
|---|
| 284 | const QString &name, int index ) const | 
|---|
| 285 | { | 
|---|
| 286 | QWidgetContainerPlugin *p = (QWidgetContainerPlugin*)plugin->qt_cast( "QWidgetContainerPlugin" ); | 
|---|
| 287 | if ( p ) | 
|---|
| 288 | return p->addPage( key, container, name, index ); | 
|---|
| 289 | return 0; | 
|---|
| 290 | } | 
|---|
| 291 |  | 
|---|
| 292 | void QWidgetPluginPrivate::insertPage( const QString &key, QWidget *container, | 
|---|
| 293 | const QString &name, int index, QWidget *page ) const | 
|---|
| 294 | { | 
|---|
| 295 | QWidgetContainerPlugin *p = (QWidgetContainerPlugin*)plugin->qt_cast( "QWidgetContainerPlugin" ); | 
|---|
| 296 | if ( p ) | 
|---|
| 297 | p->insertPage( key, container, name, index, page ); | 
|---|
| 298 | } | 
|---|
| 299 |  | 
|---|
| 300 | void QWidgetPluginPrivate::removePage( const QString &key, QWidget *container, int index ) const | 
|---|
| 301 | { | 
|---|
| 302 | QWidgetContainerPlugin *p = (QWidgetContainerPlugin*)plugin->qt_cast( "QWidgetContainerPlugin" ); | 
|---|
| 303 | if ( p ) | 
|---|
| 304 | p->removePage( key, container, index ); | 
|---|
| 305 | } | 
|---|
| 306 |  | 
|---|
| 307 | void QWidgetPluginPrivate::movePage( const QString &key, QWidget *container, | 
|---|
| 308 | int fromIndex, int toIndex ) const | 
|---|
| 309 | { | 
|---|
| 310 | QWidgetContainerPlugin *p = (QWidgetContainerPlugin*)plugin->qt_cast( "QWidgetContainerPlugin" ); | 
|---|
| 311 | if ( p ) | 
|---|
| 312 | p->movePage( key, container, fromIndex, toIndex ); | 
|---|
| 313 | } | 
|---|
| 314 |  | 
|---|
| 315 | void QWidgetPluginPrivate::renamePage( const QString &key, QWidget *container, | 
|---|
| 316 | int index, const QString &newName ) const | 
|---|
| 317 | { | 
|---|
| 318 | QWidgetContainerPlugin *p = (QWidgetContainerPlugin*)plugin->qt_cast( "QWidgetContainerPlugin" ); | 
|---|
| 319 | if ( p ) | 
|---|
| 320 | p->renamePage( key, container, index, newName ); | 
|---|
| 321 | } | 
|---|
| 322 |  | 
|---|
| 323 | QWidgetList QWidgetPluginPrivate::pages( const QString &key, QWidget *container ) const | 
|---|
| 324 | { | 
|---|
| 325 | QWidgetContainerPlugin *p = (QWidgetContainerPlugin*)plugin->qt_cast( "QWidgetContainerPlugin" ); | 
|---|
| 326 | if ( p ) | 
|---|
| 327 | return p->pages( key, container ); | 
|---|
| 328 | return QWidgetList(); | 
|---|
| 329 | } | 
|---|
| 330 |  | 
|---|
| 331 | QString QWidgetPluginPrivate::createCode( const QString &key, const QString &container, | 
|---|
| 332 | const QString &page, const QString &pageName ) const | 
|---|
| 333 | { | 
|---|
| 334 | QWidgetContainerPlugin *p = (QWidgetContainerPlugin*)plugin->qt_cast( "QWidgetContainerPlugin" ); | 
|---|
| 335 | if ( p ) | 
|---|
| 336 | return p->createCode( key, container, page, pageName ); | 
|---|
| 337 | return QString::null; | 
|---|
| 338 | } | 
|---|
| 339 |  | 
|---|
| 340 | /*! | 
|---|
| 341 | Constructs a widget plugin. This is invoked automatically by the | 
|---|
| 342 | \c Q_EXPORT_PLUGIN macro. | 
|---|
| 343 | */ | 
|---|
| 344 | QWidgetPlugin::QWidgetPlugin() | 
|---|
| 345 | : QGPlugin( (QWidgetFactoryInterface*)(d = new QWidgetPluginPrivate( this )) ) | 
|---|
| 346 | { | 
|---|
| 347 | } | 
|---|
| 348 |  | 
|---|
| 349 | /*! | 
|---|
| 350 | Destroys the widget plugin. | 
|---|
| 351 |  | 
|---|
| 352 | You never have to call this explicitly. Qt destroys a plugin | 
|---|
| 353 | automatically when it is no longer used. | 
|---|
| 354 | */ | 
|---|
| 355 | QWidgetPlugin::~QWidgetPlugin() | 
|---|
| 356 | { | 
|---|
| 357 | // don't delete d, as this is deleted by d | 
|---|
| 358 | } | 
|---|
| 359 |  | 
|---|
| 360 | /*! | 
|---|
| 361 | Returns the group (toolbar name) that the custom widget of class | 
|---|
| 362 | \a key should be part of when \e{Qt Designer} loads it. | 
|---|
| 363 |  | 
|---|
| 364 | The default implementation returns QString::null. | 
|---|
| 365 | */ | 
|---|
| 366 | QString QWidgetPlugin::group( const QString & ) const | 
|---|
| 367 | { | 
|---|
| 368 | return QString::null; | 
|---|
| 369 | } | 
|---|
| 370 |  | 
|---|
| 371 | /*! | 
|---|
| 372 | Returns the iconset that \e{Qt Designer} should use to represent | 
|---|
| 373 | the custom widget of class \a key in the toolbar. | 
|---|
| 374 |  | 
|---|
| 375 | The default implementation returns an null iconset. | 
|---|
| 376 | */ | 
|---|
| 377 | QIconSet QWidgetPlugin::iconSet( const QString & ) const | 
|---|
| 378 | { | 
|---|
| 379 | return QIconSet(); | 
|---|
| 380 | } | 
|---|
| 381 |  | 
|---|
| 382 | /*! | 
|---|
| 383 | Returns the name of the include file that \e{Qt Designer} and \c | 
|---|
| 384 | uic should use to include the custom widget of class \a key in | 
|---|
| 385 | generated code. | 
|---|
| 386 |  | 
|---|
| 387 | The default implementation returns QString::null. | 
|---|
| 388 | */ | 
|---|
| 389 | QString QWidgetPlugin::includeFile( const QString & ) const | 
|---|
| 390 | { | 
|---|
| 391 | return QString::null; | 
|---|
| 392 | } | 
|---|
| 393 |  | 
|---|
| 394 | /*! | 
|---|
| 395 | Returns the text of the tooltip that \e{Qt Designer} should use | 
|---|
| 396 | for the custom widget of class \a key's toolbar button. | 
|---|
| 397 |  | 
|---|
| 398 | The default implementation returns QString::null. | 
|---|
| 399 | */ | 
|---|
| 400 | QString QWidgetPlugin::toolTip( const QString & ) const | 
|---|
| 401 | { | 
|---|
| 402 | return QString::null; | 
|---|
| 403 | } | 
|---|
| 404 |  | 
|---|
| 405 | /*! | 
|---|
| 406 | Returns the text of the whatsThis text that \e{Qt Designer} should | 
|---|
| 407 | use when the user requests whatsThis help for the custom widget of | 
|---|
| 408 | class \a key. | 
|---|
| 409 |  | 
|---|
| 410 | The default implementation returns QString::null. | 
|---|
| 411 | */ | 
|---|
| 412 | QString QWidgetPlugin::whatsThis( const QString & ) const | 
|---|
| 413 | { | 
|---|
| 414 | return QString::null; | 
|---|
| 415 | } | 
|---|
| 416 |  | 
|---|
| 417 | /*! | 
|---|
| 418 | Returns TRUE if the custom widget of class \a key can contain | 
|---|
| 419 | other widgets, e.g. like QFrame; otherwise returns FALSE. | 
|---|
| 420 |  | 
|---|
| 421 | The default implementation returns FALSE. | 
|---|
| 422 | */ | 
|---|
| 423 | bool QWidgetPlugin::isContainer( const QString & ) const | 
|---|
| 424 | { | 
|---|
| 425 | return FALSE; | 
|---|
| 426 | } | 
|---|
| 427 |  | 
|---|
| 428 |  | 
|---|
| 429 | /*! | 
|---|
| 430 | \class QWidgetContainerPlugin qwidgetplugin.h | 
|---|
| 431 | \brief The QWidgetContainerPlugin class provides an abstract base | 
|---|
| 432 | for complex custom container QWidget plugins. | 
|---|
| 433 |  | 
|---|
| 434 | \internal | 
|---|
| 435 |  | 
|---|
| 436 | \ingroup plugins | 
|---|
| 437 |  | 
|---|
| 438 | The widget container plugin is a subclass of QWidgetPlugin and | 
|---|
| 439 | extends the interface with functions necessary for supporting | 
|---|
| 440 | complex container widgets via plugins. These container widgets are | 
|---|
| 441 | widgets that have one or multiple sub widgets which act as the | 
|---|
| 442 | widget's containers. If the widget has multiple container | 
|---|
| 443 | subwidgets, they are referred to as "pages", and only one can be | 
|---|
| 444 | active at a time. Examples of complex container widgets include: | 
|---|
| 445 | QTabWidget, QWidgetStack and QToolBox. | 
|---|
| 446 |  | 
|---|
| 447 | Writing a complex container widget plugin is achieved by | 
|---|
| 448 | subclassing this base class. First by reimplementing | 
|---|
| 449 | QWidgetPlugin's pure virtual functions keys(), create(), group(), | 
|---|
| 450 | iconSet(), includeFile(), toolTip(), whatsThis() and | 
|---|
| 451 | isContainer(), and exporting the class with the \c Q_EXPORT_PLUGIN | 
|---|
| 452 | macro. In addition containerOfWidget(), isPassiveInteractor() and | 
|---|
| 453 | supportsPages() must be reimplemented. If the widget | 
|---|
| 454 | supportsPages(), count(), currentIndex(), pageLabel(), page(), | 
|---|
| 455 | pages() and createCode() must be implemented. If the widget | 
|---|
| 456 | supportsPages() and you want to allow the containers pages to be | 
|---|
| 457 | modified, you must also reimplement addPage(), insertPage(), | 
|---|
| 458 | removePage(), movePage() and renamePage(). | 
|---|
| 459 |  | 
|---|
| 460 | \sa QWidgetPlugin | 
|---|
| 461 | */ | 
|---|
| 462 |  | 
|---|
| 463 | /*! | 
|---|
| 464 | Constructs a complex container widget plugin. This is invoked | 
|---|
| 465 | automatically by the \c Q_EXPORT_PLUGIN macro. | 
|---|
| 466 | */ | 
|---|
| 467 |  | 
|---|
| 468 | QWidgetContainerPlugin::QWidgetContainerPlugin() | 
|---|
| 469 | : QWidgetPlugin() | 
|---|
| 470 | { | 
|---|
| 471 | } | 
|---|
| 472 |  | 
|---|
| 473 | /*! | 
|---|
| 474 | Destroys the complex container widget plugin. | 
|---|
| 475 |  | 
|---|
| 476 | You never have to call this explicitly. Qt destroys a plugin | 
|---|
| 477 | automatically when it is no longer used. | 
|---|
| 478 | */ | 
|---|
| 479 |  | 
|---|
| 480 | QWidgetContainerPlugin::~QWidgetContainerPlugin() | 
|---|
| 481 | { | 
|---|
| 482 | } | 
|---|
| 483 |  | 
|---|
| 484 | /*! | 
|---|
| 485 | Operates on the plugin's \a key class. | 
|---|
| 486 |  | 
|---|
| 487 | Returns the current \a container's custom widget. If the custom | 
|---|
| 488 | widget is a tab widget, this function takes the \a container as | 
|---|
| 489 | input and returns the widget's current page. | 
|---|
| 490 |  | 
|---|
| 491 | The default implementation returns \a container. | 
|---|
| 492 | */ | 
|---|
| 493 |  | 
|---|
| 494 | QWidget* QWidgetContainerPlugin::containerOfWidget( const QString &, | 
|---|
| 495 | QWidget *container ) const | 
|---|
| 496 | { | 
|---|
| 497 | return container; | 
|---|
| 498 | } | 
|---|
| 499 |  | 
|---|
| 500 | /*! | 
|---|
| 501 | Operates on the plugin's \a key class. | 
|---|
| 502 |  | 
|---|
| 503 | Returns the \a container custom widget's number of pages. If the | 
|---|
| 504 | custom widget is a tab widget, this function returns the number of | 
|---|
| 505 | tabs. | 
|---|
| 506 |  | 
|---|
| 507 | The default implementation returns 0. | 
|---|
| 508 | */ | 
|---|
| 509 |  | 
|---|
| 510 | int QWidgetContainerPlugin::count( const QString &, QWidget * ) const | 
|---|
| 511 | { | 
|---|
| 512 | return 0; | 
|---|
| 513 | } | 
|---|
| 514 |  | 
|---|
| 515 | /*! | 
|---|
| 516 | Operates on the plugin's \a key class. | 
|---|
| 517 |  | 
|---|
| 518 | Returns the \a container custom widget's current page index. If | 
|---|
| 519 | the custom widget is a tab widget, this function returns the | 
|---|
| 520 | current tab's index. | 
|---|
| 521 |  | 
|---|
| 522 | The default implementation returns -1. | 
|---|
| 523 | */ | 
|---|
| 524 |  | 
|---|
| 525 | int QWidgetContainerPlugin::currentIndex( const QString &, QWidget * ) const | 
|---|
| 526 | { | 
|---|
| 527 | return -1; | 
|---|
| 528 | } | 
|---|
| 529 |  | 
|---|
| 530 | /*! | 
|---|
| 531 | Operates on the plugin's \a key class. | 
|---|
| 532 |  | 
|---|
| 533 | Returns the \a container custom widget's label at position \a | 
|---|
| 534 | index. If the custom widget is a tab widget, this function returns | 
|---|
| 535 | the current tab's label. | 
|---|
| 536 |  | 
|---|
| 537 | The default implementation returns a null string. | 
|---|
| 538 | */ | 
|---|
| 539 |  | 
|---|
| 540 | QString QWidgetContainerPlugin::pageLabel( const QString &, QWidget *, int ) const | 
|---|
| 541 | { | 
|---|
| 542 | return QString::null; | 
|---|
| 543 | } | 
|---|
| 544 |  | 
|---|
| 545 | /*! | 
|---|
| 546 | Operates on the plugin's \a key class. | 
|---|
| 547 |  | 
|---|
| 548 | Returns the \a container custom widget's page at position \a | 
|---|
| 549 | index. If the custom widget is a tab widget, this function returns | 
|---|
| 550 | the tab at index position \e index. | 
|---|
| 551 |  | 
|---|
| 552 |  | 
|---|
| 553 | The default implementation returns 0. | 
|---|
| 554 | */ | 
|---|
| 555 |  | 
|---|
| 556 | QWidget *QWidgetContainerPlugin::page( const QString &, QWidget *, int ) const | 
|---|
| 557 | { | 
|---|
| 558 | return 0; | 
|---|
| 559 | } | 
|---|
| 560 |  | 
|---|
| 561 | /*! | 
|---|
| 562 | Operates on the plugin's \a key class. | 
|---|
| 563 |  | 
|---|
| 564 | Returns TRUE if the \a container custom widget is a passive | 
|---|
| 565 | interactor for class \e key; otherwise returns FALSE. The \a | 
|---|
| 566 | container is a child widget of the actual custom widget. | 
|---|
| 567 |  | 
|---|
| 568 | Usually, when a custom widget is used in \e{Qt Designer}'s design | 
|---|
| 569 | mode, no widget receives any mouse or key events, since \e{Qt | 
|---|
| 570 | Designer} filters and processes them itself. If one or more | 
|---|
| 571 | widgets of a custom widget still need to receive such events, for | 
|---|
| 572 | example, because the widget needs to change pages, this function | 
|---|
| 573 | must return TRUE for the widget. In such cases \e{Qt Designer} | 
|---|
| 574 | will not filter out key and mouse events destined for the widget. | 
|---|
| 575 |  | 
|---|
| 576 | If the custom widget is a tab widget, the tab bar is the passive | 
|---|
| 577 | interactor, since that's what the user will use to change pages. | 
|---|
| 578 |  | 
|---|
| 579 | The default implementation returns FALSE. | 
|---|
| 580 | */ | 
|---|
| 581 |  | 
|---|
| 582 | bool QWidgetContainerPlugin::isPassiveInteractor( const QString &, | 
|---|
| 583 | QWidget *container ) const | 
|---|
| 584 | { | 
|---|
| 585 | Q_UNUSED( container ) | 
|---|
| 586 | return FALSE; | 
|---|
| 587 | } | 
|---|
| 588 |  | 
|---|
| 589 | /*! | 
|---|
| 590 | Operates on the plugin's \a key class. | 
|---|
| 591 |  | 
|---|
| 592 | Returns TRUE if the widget supports pages; otherwise returns | 
|---|
| 593 | FALSE. If the custom widget is a tab widget this function should | 
|---|
| 594 | return TRUE. | 
|---|
| 595 |  | 
|---|
| 596 | The default implementation returns FALSE. | 
|---|
| 597 | */ | 
|---|
| 598 |  | 
|---|
| 599 | bool QWidgetContainerPlugin::supportsPages( const QString & ) const | 
|---|
| 600 | { | 
|---|
| 601 | return FALSE; | 
|---|
| 602 | } | 
|---|
| 603 |  | 
|---|
| 604 | /*! | 
|---|
| 605 | Operates on the plugin's \a key class. | 
|---|
| 606 |  | 
|---|
| 607 | This function is called when a new page with the given \a name | 
|---|
| 608 | should be added to the \a container custom widget at position \a | 
|---|
| 609 | index. | 
|---|
| 610 |  | 
|---|
| 611 | The default implementation does nothing. | 
|---|
| 612 | */ | 
|---|
| 613 |  | 
|---|
| 614 | QWidget* QWidgetContainerPlugin::addPage( const QString &, QWidget *, | 
|---|
| 615 | const QString &, int ) const | 
|---|
| 616 | { | 
|---|
| 617 | return 0; | 
|---|
| 618 | } | 
|---|
| 619 |  | 
|---|
| 620 | /*! | 
|---|
| 621 | Operates on the plugin's \a key class. | 
|---|
| 622 |  | 
|---|
| 623 | This function is called when a new page, \a page, with the given | 
|---|
| 624 | \a name should be added to the \a container custom widget at | 
|---|
| 625 | position \a index. | 
|---|
| 626 |  | 
|---|
| 627 | The default implementation does nothing. | 
|---|
| 628 | */ | 
|---|
| 629 |  | 
|---|
| 630 | void QWidgetContainerPlugin::insertPage( const QString &, QWidget *, | 
|---|
| 631 | const QString &, int, QWidget * ) const | 
|---|
| 632 | { | 
|---|
| 633 | } | 
|---|
| 634 |  | 
|---|
| 635 | /*! | 
|---|
| 636 | Operates on the plugin's \a key class. | 
|---|
| 637 |  | 
|---|
| 638 | This function is called when the page at position \a index should | 
|---|
| 639 | be removed from the \a container custom widget. | 
|---|
| 640 |  | 
|---|
| 641 | The default implementation does nothing. | 
|---|
| 642 | */ | 
|---|
| 643 |  | 
|---|
| 644 | void QWidgetContainerPlugin::removePage( const QString &, QWidget *, int ) const | 
|---|
| 645 | { | 
|---|
| 646 | } | 
|---|
| 647 |  | 
|---|
| 648 | /*! | 
|---|
| 649 | Operates on the plugin's \a key class. | 
|---|
| 650 |  | 
|---|
| 651 | This function is called when the page at position \a fromIndex should | 
|---|
| 652 | be moved to position \a toIndex in the \a container custom widget. | 
|---|
| 653 |  | 
|---|
| 654 | The default implementation does nothing. | 
|---|
| 655 | */ | 
|---|
| 656 |  | 
|---|
| 657 | void QWidgetContainerPlugin::movePage( const QString &, QWidget *, int, int ) const | 
|---|
| 658 | { | 
|---|
| 659 | } | 
|---|
| 660 |  | 
|---|
| 661 | /*! | 
|---|
| 662 | Operates on the plugin's \a key class. | 
|---|
| 663 |  | 
|---|
| 664 | This function is called when the page at position \a index should | 
|---|
| 665 | be renamed (have its label changed) to \a newName in the \a | 
|---|
| 666 | container custom widget. | 
|---|
| 667 |  | 
|---|
| 668 | The default implementation does nothing. | 
|---|
| 669 | */ | 
|---|
| 670 |  | 
|---|
| 671 | void QWidgetContainerPlugin::renamePage( const QString &, QWidget *, | 
|---|
| 672 | int, const QString & ) const | 
|---|
| 673 | { | 
|---|
| 674 | } | 
|---|
| 675 |  | 
|---|
| 676 | /*! | 
|---|
| 677 | Operates on the plugin's \a key class. | 
|---|
| 678 |  | 
|---|
| 679 | This function should return a list of the \a container custom | 
|---|
| 680 | widget's pages. | 
|---|
| 681 | */ | 
|---|
| 682 |  | 
|---|
| 683 | QWidgetList QWidgetContainerPlugin::pages( const QString &, QWidget * ) const | 
|---|
| 684 | { | 
|---|
| 685 | return QWidgetList(); | 
|---|
| 686 | } | 
|---|
| 687 |  | 
|---|
| 688 | /*! | 
|---|
| 689 | Operates on the plugin's \a key class. | 
|---|
| 690 |  | 
|---|
| 691 | This function is called from \e{Qt Designer}'s User Interface | 
|---|
| 692 | Compiler \c uic, when generating C++ code for inserting a page in | 
|---|
| 693 | the \a container custom widget. The name of the page widget which | 
|---|
| 694 | should be inserted at the end of the container is \a page, and the | 
|---|
| 695 | label of the page should be \a pageName. | 
|---|
| 696 |  | 
|---|
| 697 | If the custom widget was a QTabWidget, the implementation of this | 
|---|
| 698 | function should return: | 
|---|
| 699 |  | 
|---|
| 700 | \code | 
|---|
| 701 | return widget + "->addTab( " + page + ", \"" + pageName + "\" )"; | 
|---|
| 702 | \endcode | 
|---|
| 703 |  | 
|---|
| 704 | Warning: If the code returned by this function contains invalid | 
|---|
| 705 | C++ syntax, the generated \c uic code will not compile. | 
|---|
| 706 | */ | 
|---|
| 707 |  | 
|---|
| 708 | QString QWidgetContainerPlugin::createCode( const QString &, const QString &, | 
|---|
| 709 | const QString &, const QString & ) const | 
|---|
| 710 | { | 
|---|
| 711 | return QString::null; | 
|---|
| 712 | } | 
|---|
| 713 |  | 
|---|
| 714 | #endif //QT_NO_WIDGETPLUGIN | 
|---|