Introduce menubar plugin system
authorAurélien Gâteau <agateau@kde.org>
Tue, 14 Jun 2011 16:04:26 +0000 (18:04 +0200)
committerQt by Nokia <qt-info@nokia.com>
Wed, 31 Aug 2011 11:12:43 +0000 (13:12 +0200)
Merge-request: 1254
Reviewed-by: Gabriel de Dietrich <gabriel.dietrich-de@nokia.com>
(cherry picked from commit 31ff55bbeb84f10e75e997c75a63deda83e62507)

Change-Id: I0644514299c16cabe19d1e6d024dd652b2d7bc4e
Reviewed-on: http://codereview.qt.nokia.com/3933
Reviewed-by: Gabriel de Dietrich <gabriel.dietrich-de@nokia.com>
src/gui/widgets/qabstractplatformmenubar_p.h
src/gui/widgets/qmenubar.cpp
src/gui/widgets/qmenubar_x11.cpp
src/gui/widgets/qmenubar_x11_p.h

index 86e212b..cb4e5cb 100644 (file)
@@ -41,7 +41,9 @@
 #ifndef QABSTRACTPLATFORMMENUBAR_P_H
 #define QABSTRACTPLATFORMMENUBAR_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 QAbstractPlatformMenuBar;
+
+struct QPlatformMenuBarFactoryInterface : public QFactoryInterface
+{
+    virtual QAbstractPlatformMenuBar *create() = 0;
+};
+
+#define QPlatformMenuBarFactoryInterface_iid "com.nokia.qt.QPlatformMenuBarFactoryInterface"
+Q_DECLARE_INTERFACE(QPlatformMenuBarFactoryInterface, QPlatformMenuBarFactoryInterface_iid)
+
 /*!
     The platform-specific implementation of a menubar
 */
index ff09b6e..018d9f0 100644 (file)
@@ -55,6 +55,9 @@
 #include <qtoolbar.h>
 #include <qtoolbutton.h>
 #include <qwhatsthis.h>
+#ifdef Q_WS_X11
+#include <qpluginloader.h>
+#endif
 
 #ifndef QT_NO_MENUBAR
 
@@ -761,7 +764,7 @@ void QMenuBarPrivate::init()
     }
 #endif
 #ifdef Q_WS_X11
-    platformMenuBar = new QX11MenuBar;
+    platformMenuBar = qt_guiPlatformMenuBarFactory()->create();
     platformMenuBar->init(q);
 #endif
 
index ca227a6..37c085f 100644 (file)
@@ -48,6 +48,8 @@
 #include "qmenu.h"
 #include "qmenubar.h"
 
+#include <private/qfactoryloader_p.h>
+
 QT_BEGIN_NAMESPACE
 
 QX11MenuBar::~QX11MenuBar()
@@ -109,6 +111,28 @@ bool QX11MenuBar::menuBarEventFilter(QObject *, QEvent *)
     return false;
 }
 
+struct QX11MenuBarFactory : public QPlatformMenuBarFactoryInterface
+{
+    QAbstractPlatformMenuBar *create() { return new QX11MenuBar; }
+    virtual QStringList keys() const { return QStringList(); }
+};
+
+QPlatformMenuBarFactoryInterface *qt_guiPlatformMenuBarFactory()
+{
+    static QPlatformMenuBarFactoryInterface *factory = 0;
+    if (!factory) {
+#ifndef QT_NO_LIBRARY
+        QFactoryLoader loader(QPlatformMenuBarFactoryInterface_iid, QLatin1String("/menubar"));
+        factory = qobject_cast<QPlatformMenuBarFactoryInterface *>(loader.instance(QLatin1String("default")));
+#endif // QT_NO_LIBRARY
+        if(!factory) {
+            static QX11MenuBarFactory def;
+            factory = &def;
+        }
+    }
+    return factory;
+}
+
 QT_END_NAMESPACE
 
 #endif // QT_NO_MENUBAR
index dbe0223..1c43b04 100644 (file)
@@ -77,6 +77,8 @@ private:
     int nativeMenuBar : 3;  // Only has values -1, 0, and 1
 };
 
+QPlatformMenuBarFactoryInterface *qt_guiPlatformMenuBarFactory();
+
 QT_END_NAMESPACE
 
 #endif // QT_NO_MENUBAR