Introduce menubar plugin system

Merge-request: 916
Reviewed-by: Thierry Bastian <thierry.bastian@nokia.com>
(cherry picked from commit be0d346052d69693c2780e62401f3c0d4b0d89d4)
This commit is contained in:
Aurélien Gâteau 2011-04-14 10:00:27 +02:00 committed by Olivier Goffart
parent 1b573dd5ff
commit 03b0eb416f
4 changed files with 41 additions and 1 deletions

View File

@ -41,7 +41,9 @@
#ifndef QABSTRACTMENUBARIMPL_P_H
#define QABSTRACTMENUBARIMPL_P_H
#include <qfactoryinterface.h>
#include <qglobal.h>
#include <qplugin.h>
#ifndef QT_NO_MENUBAR
@ -54,6 +56,16 @@ class QMenuBar;
class QObject;
class QWidget;
class QAbstractMenuBarImpl;
struct QMenuBarImplFactoryInterface : public QFactoryInterface
{
virtual QAbstractMenuBarImpl* createImpl() = 0;
};
#define QMenuBarImplFactoryInterface_iid "com.nokia.qt.QMenuBarImplFactoryInterface"
Q_DECLARE_INTERFACE(QMenuBarImplFactoryInterface, QMenuBarImplFactoryInterface_iid)
/**
* The platform-specific implementation of a menubar
*/

View File

@ -55,6 +55,7 @@
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <qwhatsthis.h>
#include <qpluginloader.h>
#ifndef QT_NO_MENUBAR
@ -728,7 +729,8 @@ void QMenuBarPrivate::init()
Q_Q(QMenuBar);
q->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
q->setAttribute(Qt::WA_CustomWhatsThis);
impl = new QMenuBarImpl;
impl = qt_guiMenuBarImplFactory()->createImpl();
impl->init(q);
q->setBackgroundRole(QPalette::Button);

View File

@ -48,6 +48,8 @@
#include "qmenu.h"
#include "qmenubar.h"
#include <private/qfactoryloader_p.h>
QT_BEGIN_NAMESPACE
QMenuBarImpl::~QMenuBarImpl()
@ -239,6 +241,28 @@ bool QMenuBarImpl::menuBarEventFilter(QObject *, QEvent *)
return false;
}
struct QMenuBarImplFactory : public QMenuBarImplFactoryInterface
{
QAbstractMenuBarImpl* createImpl() { return new QMenuBarImpl; }
virtual QStringList keys() const { return QStringList(); }
};
QMenuBarImplFactoryInterface *qt_guiMenuBarImplFactory()
{
static QMenuBarImplFactoryInterface *factory = 0;
if (!factory) {
#ifndef QT_NO_LIBRARY
QFactoryLoader loader(QMenuBarImplFactoryInterface_iid, QLatin1String("/menubar"));
factory = qobject_cast<QMenuBarImplFactoryInterface *>(loader.instance(QLatin1String("default")));
#endif // QT_NO_LIBRARY
if(!factory) {
static QMenuBarImplFactory def;
factory = &def;
}
}
return factory;
}
QT_END_NAMESPACE
#endif // QT_NO_MENUBAR

View File

@ -175,6 +175,8 @@ private:
#endif
};
QMenuBarImplFactoryInterface *qt_guiMenuBarImplFactory();
QT_END_NAMESPACE
#endif // QT_NO_MENUBAR