From d86ce847d67e1486e5b95c1b060d84f4947e75b1 Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Fri, 18 Feb 2011 13:45:34 +0200 Subject: [PATCH] Changed: #1206 Added menu manager. Update core and example plugin. --- .../src/extension_system/iplugin_manager.h | 64 +++++++++++++ .../src/extension_system/plugin_manager.cpp | 2 - .../src/plugins/core/CMakeLists.txt | 8 +- .../src/plugins/core/core_global.h | 30 ++++++ .../src/plugins/core/core_plugin.cpp | 38 +++----- .../src/plugins/core/core_plugin.h | 33 ------- .../src/plugins/core/icore_listener.h | 11 ++- .../src/plugins/core/imenu_manager.h | 62 ++++++++++++ .../src/plugins/core/ioptions_page.h | 12 ++- .../src/plugins/core/main_window.cpp | 40 +++++--- .../src/plugins/core/main_window.h | 5 + .../src/plugins/core/menu_manager.cpp | 94 +++++++++++++++++++ .../src/plugins/core/menu_manager.h | 59 ++++++++++++ .../core/search_paths_settings_page.cpp | 2 +- .../plugins/core/search_paths_settings_page.h | 4 +- .../src/plugins/core/settings_dialog.cpp | 2 +- .../src/plugins/example/CMakeLists.txt | 6 +- .../plugins/example/example_settings_page.cpp | 2 +- .../plugins/example/example_settings_page.h | 3 +- .../src/plugins/example/plugin1.cpp | 17 ++++ .../src/plugins/example/simple_viewer.h | 5 +- 21 files changed, 405 insertions(+), 94 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_global.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/core/imenu_manager.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/core/menu_manager.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/core/menu_manager.h diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_manager.h b/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_manager.h index 0cde19d0a..0d568cd2b 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_manager.h +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_manager.h @@ -20,6 +20,8 @@ #ifndef IPLUGINMANAGER_H #define IPLUGINMANAGER_H +#include "plugin_spec.h" + #include #include #include @@ -59,6 +61,68 @@ public: virtual void setSettings(QSettings *settings) = 0; virtual QSettings *settings() const = 0; + // Auxiliary operations + template + QList getObjects() const + { + QList all = allObjects(); + QList objects; + Q_FOREACH(QObject *obj, all) + { + T *tObj = qobject_cast(obj); + if (tObj) + objects.append(tObj); + } + return objects; + } + + template + T *getObject() const + { + QList all = allObjects(); + T *result = 0; + Q_FOREACH(QObject *obj, all) + { + T *tObj = qobject_cast(obj); + if (tObj) + { + result = tObj; + break; + } + } + return result; + } + + QObject *objectByName(const QString &name) const + { + QList all = allObjects(); + QObject *result = 0; + Q_FOREACH (QObject *qobj, all) + { + if (qobj->objectName() == name) + { + result = qobj; + break; + } + } + return result; + } + + ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const + { + QList all = plugins(); + ExtensionSystem::IPluginSpec *result = 0; + Q_FOREACH (ExtensionSystem::IPluginSpec *spec, all) + { + if (spec->name() == name) + { + result = spec; + break; + } + } + return result; + } + Q_SIGNALS: void objectAdded(QObject *obj); void aboutToRemoveObject(QObject *obj); diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_manager.cpp b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_manager.cpp index 921f14fbe..22ffe8aec 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_manager.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_manager.cpp @@ -23,8 +23,6 @@ #include -#include "plugin_spec.h" - namespace ExtensionSystem { diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/CMakeLists.txt index 2ff8e894d..4bbf7ea63 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/CMakeLists.txt @@ -9,8 +9,12 @@ SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin. ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h) SET(OVQT_CORE_PLUGIN_HDR + imenu_manager.h + icore_listener.h + ioptions_page.h core_plugin.h main_window.h + menu_manager.h settings_dialog.h search_paths_settings_page.h plugin_view_dialog.h) @@ -34,7 +38,7 @@ SOURCE_GROUP(QtGeneratedMocSrc FILES ${OVQT_CORE_PLUGIN_MOC_SRC}) SOURCE_GROUP("Core Plugin" FILES ${SRC}) SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC}) -ADD_LIBRARY(ovqt_plugin_core MODULE ${SRC} ${OVQT_CORE_PLUGIN_MOC_SRC} ${OVQT_EXT_SYS_SRC} ${OVQT_CORE_PLUGIN_RC_SRCS} ${OVQT_CORE_PLUGIN_UI_HDRS}) +ADD_LIBRARY(ovqt_plugin_core SHARED ${SRC} ${OVQT_CORE_PLUGIN_MOC_SRC} ${OVQT_EXT_SYS_SRC} ${OVQT_CORE_PLUGIN_RC_SRCS} ${OVQT_CORE_PLUGIN_UI_HDRS}) TARGET_LINK_LIBRARIES(ovqt_plugin_core nelmisc ${QT_LIBRARIES}) @@ -42,6 +46,6 @@ NL_DEFAULT_PROPS(ovqt_plugin_core "NeL, Tools, 3D: Object Viewer Qt Plugin: Core NL_ADD_RUNTIME_FLAGS(ovqt_plugin_core) NL_ADD_LIB_SUFFIX(ovqt_plugin_core) -ADD_DEFINITIONS(${LIBXML2_DEFINITIONS} -DQT_PLUGIN -DQT_SHARED ${QT_DEFINITIONS}) +ADD_DEFINITIONS(-DCORE_LIBRARY ${LIBXML2_DEFINITIONS} -DQT_PLUGIN -DQT_SHARED ${QT_DEFINITIONS}) INSTALL(TARGETS ovqt_plugin_core LIBRARY DESTINATION lib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib COMPONENT tools3d) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_global.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_global.h new file mode 100644 index 000000000..48fe0ece9 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_global.h @@ -0,0 +1,30 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef CORE_GLOBAL_H +#define CORE_GLOBAL_H + +#include + +#if defined(CORE_LIBRARY) +# define CORE_EXPORT Q_DECL_EXPORT +#else +# define CORE_EXPORT Q_DECL_IMPORT +#endif + +#endif // CORE_GLOBAL_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.cpp index 5b6904421..664fae7c6 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.cpp @@ -56,21 +56,13 @@ bool CorePlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStr _plugMan = pluginManager; _oldOVQT = false; - addAutoReleasedObject(new CSearchPathsSettingsPage(this)); - return true; -} - -void CorePlugin::extensionsInitialized() -{ - _pluginView = new ExtensionSystem::CPluginView(_plugMan); - // for old ovqt - QMainWindow *wnd = qobject_cast(objectByName("CMainWindow")); + QMainWindow *wnd = qobject_cast(_plugMan->objectByName("CMainWindow")); if (wnd) { _pluginView = new ExtensionSystem::CPluginView(_plugMan); - QMenu *toolsMenu = qobject_cast(objectByName("ovqt.Menu.Tools")); - QMenu *helpMenu = qobject_cast(objectByName("ovqt.Menu.Help")); + QMenu *toolsMenu = qobject_cast(_plugMan->objectByName("ovqt.Menu.Tools")); + QMenu *helpMenu = qobject_cast(_plugMan->objectByName("ovqt.Menu.Help")); nlassert(toolsMenu); nlassert(helpMenu); @@ -103,6 +95,14 @@ void CorePlugin::extensionsInitialized() } _mainWindow->show(); } + + addAutoReleasedObject(new CSearchPathsSettingsPage(this)); + return true; +} + +void CorePlugin::extensionsInitialized() +{ + _pluginView = new ExtensionSystem::CPluginView(_plugMan); } void CorePlugin::shutdown() @@ -162,20 +162,4 @@ void CorePlugin::addAutoReleasedObject(QObject *obj) _autoReleaseObjects.prepend(obj); } -QObject* CorePlugin::objectByName(const QString &name) const -{ - Q_FOREACH (QObject *qobj, _plugMan->allObjects()) - if (qobj->objectName() == name) - return qobj; - return 0; -} - -ExtensionSystem::IPluginSpec *CorePlugin::pluginByName(const QString &name) const -{ - Q_FOREACH (ExtensionSystem::IPluginSpec *spec, _plugMan->plugins()) - if (spec->name() == name) - return spec; - return 0; -} - Q_EXPORT_PLUGIN(CorePlugin) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.h index 26dae9934..53940016e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.h @@ -61,44 +61,11 @@ public: void addAutoReleasedObject(QObject *obj); - QObject *objectByName(const QString &name) const; - ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const; ExtensionSystem::IPluginManager *pluginManager() const { return _plugMan; } - template - QList getObjects() const - { - QList all = _plugMan->allObjects(); - QList objects; - Q_FOREACH(QObject *obj, all) - { - T *tObj = qobject_cast(obj); - if (tObj) - objects.append(tObj); - } - return objects; - } - - template - T *getObject() const - { - QList all = _plugMan->allObjects(); - T *result = 0; - Q_FOREACH(QObject *obj, all) - { - T *tObj = qobject_cast(obj); - if (tObj) - { - result = tObj; - break; - } - } - return result; - } - protected: NLMISC::CLibraryContext *_LibContext; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icore_listener.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icore_listener.h index c37ba3366..c27e40242 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icore_listener.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icore_listener.h @@ -19,9 +19,15 @@ #ifndef ICORE_LISTENER_H #define ICORE_LISTENER_H +// Project includes +#include "core_global.h" + +// Qt includes #include +QT_BEGIN_NAMESPACE class QWidget; +QT_END_NAMESPACE namespace Core { @@ -40,9 +46,11 @@ PluginManager->addObject(yourImplementingObject); Don't forget to remove the object again at deconstruction (e.g. in the destructor of your plugin) */ -class ICoreListener +class CORE_EXPORT ICoreListener: public QObject { + Q_OBJECT public: + ICoreListener(QObject *parent = 0): QObject(parent) {} virtual ~ICoreListener() {} /// Return false from the implemented method if you want to prevent the event. @@ -51,6 +59,5 @@ public: } // namespace Core -Q_DECLARE_INTERFACE(Core::ICoreListener, "dev.ryzom.com.ICoreListener/0.1") #endif // ICORE_LISTENER_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/imenu_manager.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/imenu_manager.h new file mode 100644 index 000000000..be80dbbc4 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/imenu_manager.h @@ -0,0 +1,62 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef IMENU_MANAGER_H +#define IMENU_MANAGER_H + +#include "core_global.h" + +#include +#include + +QT_BEGIN_NAMESPACE +class QMenu; +class QAction; +class QString; +class QMenuBar; +QT_END_NAMESPACE + +namespace Core +{ +/* +@interface IMenuManager +@brief The IMenuManager is an interface for providing a registration of menus and menu item. +@details The IMenuManager provides centralized access to menus and menu items. +All menus and menu items should be registered in the IMenuManager. +*/ +class CORE_EXPORT IMenuManager : public QObject +{ + Q_OBJECT +public: + IMenuManager(QObject *parent = 0): QObject(parent) {} + virtual ~IMenuManager() {} + + virtual void registerMenu(QMenu *menu, const QString &id) = 0; + virtual void registerAction(QAction *action, const QString &id) = 0; + + virtual QMenu *menu(const QString &id) const = 0; + virtual QAction *action(const QString &id) const = 0; + + virtual void unregisterMenu(const QString &id) = 0; + virtual void unregisterAction(const QString &id) = 0; + + virtual QMenuBar *menuBar() const = 0; +}; + +} // namespace Core + +#endif // IMENU_MANAGER_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/ioptions_page.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/ioptions_page.h index 2d780bc2d..74692833a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/ioptions_page.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/ioptions_page.h @@ -19,9 +19,15 @@ #ifndef IOPTIONS_PAGE_H #define IOPTIONS_PAGE_H +// Project includes +#include "core_global.h" + +// Qt includes #include +QT_BEGIN_NAMESPACE class QWidget; +QT_END_NAMESPACE namespace Core { @@ -31,9 +37,11 @@ namespace Core @details You need to subclass this interface and put an instance of your subclass into the plugin manager object pool. */ -class IOptionsPage +class CORE_EXPORT IOptionsPage: public QObject { + Q_OBJECT public: + IOptionsPage(QObject *parent = 0): QObject(parent) {} virtual ~IOptionsPage() {} /// id() is a unique identifier for referencing this page @@ -61,6 +69,4 @@ public: } // namespace Core -Q_DECLARE_INTERFACE(Core::IOptionsPage, "dev.ryzom.com.IOptionsPage/1.0") - #endif // IOPTIONS_PAGE_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.cpp index 0aa82e187..9aa7611c3 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.cpp @@ -17,6 +17,7 @@ // Project includes #include "main_window.h" +#include "menu_manager.h" #include "core_plugin.h" #include "iapp_page.h" #include "icore_listener.h" @@ -34,7 +35,11 @@ namespace Core CMainWindow::CMainWindow(CorePlugin *corePlugin, QWidget *parent) : QMainWindow(parent), - _lastDir(".") + _pluginManager(0), + _corePlugin(0), + _menuManager(0), + _lastDir("."), + _settings(0) { _corePlugin = corePlugin; _pluginManager = _corePlugin->pluginManager(); @@ -42,11 +47,15 @@ CMainWindow::CMainWindow(CorePlugin *corePlugin, QWidget *parent) setObjectName(Constants::MAIN_WINDOW); + _menuManager = new MenuManager(this); + _menuManager->setMenuBar(menuBar()); + _pluginManager->addObject(_menuManager); + _tabWidget = new QTabWidget(this); _tabWidget->setTabPosition(QTabWidget::South); setCentralWidget(_tabWidget); - QList listAppPages = _corePlugin->getObjects(); + QList listAppPages = _pluginManager->getObjects(); Q_FOREACH(IAppPage *appPage, listAppPages) { @@ -72,7 +81,11 @@ CMainWindow::CMainWindow(CorePlugin *corePlugin, QWidget *parent) CMainWindow::~CMainWindow() { - delete _pluginView; +} + +IMenuManager *CMainWindow::menuManager() const +{ + return _menuManager; } void CMainWindow::checkObject(QObject *obj) @@ -102,7 +115,7 @@ void CMainWindow::about() void CMainWindow::closeEvent(QCloseEvent *event) { - QList listeners = _corePlugin->getObjects(); + QList listeners = _pluginManager->getObjects(); Q_FOREACH(ICoreListener *listener, listeners) { if (!listener->closeMainWindow()) @@ -113,8 +126,7 @@ void CMainWindow::closeEvent(QCloseEvent *event) } writeSettings(); - - QMainWindow::closeEvent(event); + event->accept(); } void CMainWindow::addAppPage(IAppPage *appPage) @@ -133,46 +145,52 @@ void CMainWindow::createActions() _openAction->setIcon(QIcon(":/images/open-file.png")); _openAction->setShortcut(QKeySequence::Open); _openAction->setStatusTip(tr("Open an existing file")); + menuManager()->registerAction(_openAction, Constants::OPEN); // connect(_openAction, SIGNAL(triggered()), this, SLOT(open())); _exitAction = new QAction(tr("E&xit"), this); _exitAction->setShortcut(tr("Ctrl+Q")); _exitAction->setStatusTip(tr("Exit the application")); + menuManager()->registerAction(_exitAction, Constants::EXIT); connect(_exitAction, SIGNAL(triggered()), this, SLOT(close())); _settingsAction = new QAction(tr("&Settings"), this); _settingsAction->setIcon(QIcon(":/images/preferences.png")); _settingsAction->setStatusTip(tr("Open the settings dialog")); + menuManager()->registerAction(_settingsAction, Constants::SETTINGS); connect(_settingsAction, SIGNAL(triggered()), this, SLOT(showOptionsDialog())); _aboutAction = new QAction(tr("&About"), this); _aboutAction->setStatusTip(tr("Show the application's About box")); + menuManager()->registerAction(_aboutAction, Constants::ABOUT); connect(_aboutAction, SIGNAL(triggered()), this, SLOT(about())); _aboutQtAction = new QAction(tr("About &Qt"), this); _aboutQtAction->setStatusTip(tr("Show the Qt library's About box")); + menuManager()->registerAction(_aboutQtAction, Constants::ABOUT_QT); connect(_aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); _pluginViewAction = new QAction(tr("About &Plugins"), this); _pluginViewAction->setStatusTip(tr("Show the plugin view dialog")); + menuManager()->registerAction(_pluginViewAction, Constants::ABOUT_PLUGINS); connect(_pluginViewAction, SIGNAL(triggered()), _pluginView, SLOT(show())); } void CMainWindow::createMenus() { _fileMenu = menuBar()->addMenu(tr("&File")); - _fileMenu->setObjectName(Constants::M_FILE); + menuManager()->registerMenu(_fileMenu, Constants::M_FILE); _fileMenu->addSeparator(); _fileMenu->addAction(_exitAction); _editMenu = menuBar()->addMenu(tr("&Edit")); - _editMenu->setObjectName(Constants::M_EDIT); + menuManager()->registerMenu(_editMenu, Constants::M_EDIT); _viewMenu = menuBar()->addMenu(tr("&View")); - _viewMenu->setObjectName(Constants::M_VIEW); + menuManager()->registerMenu(_viewMenu, Constants::M_VIEW); _toolsMenu = menuBar()->addMenu(tr("&Tools")); - _toolsMenu->setObjectName(Constants::M_TOOLS); + menuManager()->registerMenu(_toolsMenu, Constants::M_TOOLS); _toolsMenu->addSeparator(); @@ -182,7 +200,7 @@ void CMainWindow::createMenus() menuBar()->addSeparator(); _helpMenu = menuBar()->addMenu(tr("&Help")); - _helpMenu->setObjectName(Constants::M_HELP); + menuManager()->registerMenu(_helpMenu, Constants::M_HELP); _helpMenu->addAction(_aboutAction); _helpMenu->addAction(_aboutQtAction); _helpMenu->addAction(_pluginViewAction); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.h index 4b807dd04..e0b030b87 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.h @@ -33,6 +33,8 @@ namespace Core class CSettingsDialog; class CorePlugin; class IAppPage; +class IMenuManager; +class MenuManager; class CMainWindow : public QMainWindow { @@ -42,6 +44,8 @@ public: CMainWindow(CorePlugin *corePlugin, QWidget *parent = 0); ~CMainWindow(); + IMenuManager *menuManager() const; + private Q_SLOTS: void checkObject(QObject *obj); bool showOptionsDialog(const QString &group = QString(), @@ -65,6 +69,7 @@ private: ExtensionSystem::IPluginManager *_pluginManager; ExtensionSystem::CPluginView *_pluginView; CorePlugin *_corePlugin; + MenuManager *_menuManager; QPalette _originalPalette; QString _lastDir; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/menu_manager.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/menu_manager.cpp new file mode 100644 index 000000000..dbd738b28 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/menu_manager.cpp @@ -0,0 +1,94 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Project includes +#include "menu_manager.h" + +// NeL includes +#include + +// Qt includes +#include +#include +#include + +namespace Core +{ +MenuManager::MenuManager(QObject *parent) + : IMenuManager(parent), + _menuBar(0) +{ +} + +MenuManager::~MenuManager() +{ + _menuMap.clear(); +} + +void MenuManager::registerMenu(QMenu *menu, const QString &id) +{ + menu->setObjectName(id); + _menuMap.insert(id, menu); +} + +void MenuManager::registerAction(QAction *action, const QString &id) +{ + action->setObjectName(id); + _actionMap.insert(id, action); +} + +QMenu *MenuManager::menu(const QString &id) const +{ + QMenu *result = 0; + if (_menuMap.count(id) == 0) + nlwarning("QMenu %s not found", id.toStdString().c_str()); + else + result = _menuMap.value(id); + return result; +} + +QAction *MenuManager::action(const QString &id) const +{ + QAction *result = 0; + if (_actionMap.count(id) == 0) + nlwarning("QAction %s not found", id.toStdString().c_str()); + else + result = _actionMap.value(id); + return result; +} + +void MenuManager::unregisterMenu(const QString &id) +{ + _menuMap.remove(id); +} + +void MenuManager::unregisterAction(const QString &id) +{ + _actionMap.remove(id); +} + +QMenuBar *MenuManager::menuBar() const +{ + return _menuBar; +} + +void MenuManager::setMenuBar(QMenuBar *menuBar) +{ + _menuBar = menuBar; +} + +} /* namespace Core */ \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/menu_manager.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/menu_manager.h new file mode 100644 index 000000000..aab603355 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/menu_manager.h @@ -0,0 +1,59 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef MENU_MANAGER_H +#define MENU_MANAGER_H + +// Project includes +#include "imenu_manager.h" + +// Qt includes +#include + +namespace Core +{ + +class MenuManager : public IMenuManager +{ + Q_OBJECT + +public: + MenuManager(QObject *parent = 0); + virtual ~MenuManager(); + + virtual void registerMenu(QMenu *menu, const QString &id); + virtual void registerAction(QAction *action, const QString &id); + + virtual QMenu *menu(const QString &id) const; + virtual QAction *action(const QString &id) const; + + virtual void unregisterMenu(const QString &id); + virtual void unregisterAction(const QString &id); + + virtual QMenuBar *menuBar() const; + void setMenuBar(QMenuBar *menuBar); +private: + QMenuBar *_menuBar; + typedef QHash IdMenuMap; + IdMenuMap _menuMap; + typedef QHash IdActionMap; + IdActionMap _actionMap; +}; + +} // namespace Core + +#endif // MENU_MANAGER_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/search_paths_settings_page.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/search_paths_settings_page.cpp index 51449c4a5..585fb2089 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/search_paths_settings_page.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/search_paths_settings_page.cpp @@ -28,7 +28,7 @@ namespace Core { CSearchPathsSettingsPage::CSearchPathsSettingsPage(QObject *parent) - : QObject(parent), + : IOptionsPage(parent), _currentPage(0) { } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/search_paths_settings_page.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/search_paths_settings_page.h index bafad8f40..cbea4239c 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/search_paths_settings_page.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/search_paths_settings_page.h @@ -32,10 +32,10 @@ namespace Core /** @class CSearchPathsSettingsPage */ -class CSearchPathsSettingsPage : public QObject, public Core::IOptionsPage +class CSearchPathsSettingsPage : public Core::IOptionsPage { Q_OBJECT - Q_INTERFACES(Core::IOptionsPage) + public: CSearchPathsSettingsPage(QObject *parent = 0); ~CSearchPathsSettingsPage() {} diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/settings_dialog.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/settings_dialog.cpp index c1a1fca40..3cee8edc7 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/settings_dialog.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/settings_dialog.cpp @@ -62,7 +62,7 @@ CSettingsDialog::CSettingsDialog(CorePlugin *corePlugin, QMap categories; - QList pages = corePlugin->getObjects(); + QList pages = _plugMan->getObjects(); int index = 0; Q_FOREACH(IOptionsPage *page, pages) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/CMakeLists.txt index d14b42806..6a49f1e41 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/CMakeLists.txt @@ -13,9 +13,7 @@ SET(OVQT_PLUG_EXAMPLE_HDR plugin1.h qnel_widget.h simple_viewer.h example_settings_page.h - ${CMAKE_CURRENT_SOURCE_DIR}/../core/iapp_page.h - ${CMAKE_CURRENT_SOURCE_DIR}/../core/icore_listener.h - ${CMAKE_CURRENT_SOURCE_DIR}/../core/ioptions_page.h) + ${CMAKE_CURRENT_SOURCE_DIR}/../core/iapp_page.h) SET(OVQT_PLUG_EXAMPLE_UIS example_settings_page.ui) @@ -33,7 +31,7 @@ SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC}) ADD_LIBRARY(ovqt_plugin_example MODULE ${SRC} ${OVQT_PLUG_EXAMPLE_MOC_SRC} ${OVQT_EXT_SYS_SRC} ${OVQT_PLUG_EXAMPLE_UI_HDRS}) -TARGET_LINK_LIBRARIES(ovqt_plugin_example nelmisc nel3d ${QT_LIBRARIES}) +TARGET_LINK_LIBRARIES(ovqt_plugin_example ovqt_plugin_core nelmisc nel3d ${QT_LIBRARIES}) NL_DEFAULT_PROPS(ovqt_plugin_example "NeL, Tools, 3D: Object Viewer Qt Plugin: Example") NL_ADD_RUNTIME_FLAGS(ovqt_plugin_example) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/example_settings_page.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/example_settings_page.cpp index 40576ab60..0cb885163 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/example_settings_page.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/example_settings_page.cpp @@ -28,7 +28,7 @@ namespace Plugin { CExampleSettingsPage::CExampleSettingsPage(QObject *parent) - : QObject(parent), + : IOptionsPage(parent), _currentPage(NULL) { } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/example_settings_page.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/example_settings_page.h index e6baa85df..64dd940f8 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/example_settings_page.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/example_settings_page.h @@ -32,10 +32,9 @@ namespace Plugin /** @class CExampleSettingsPage */ -class CExampleSettingsPage : public QObject, public Core::IOptionsPage +class CExampleSettingsPage : public Core::IOptionsPage { Q_OBJECT - Q_INTERFACES(Core::IOptionsPage) public: CExampleSettingsPage(QObject *parent = 0); virtual ~CExampleSettingsPage() {} diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.cpp index ba9df39c2..50c7e6eef 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.cpp @@ -3,6 +3,8 @@ #include "example_settings_page.h" #include "simple_viewer.h" #include "../core/iapp_page.h" +#include "../core/core_constants.h" +#include "../core/imenu_manager.h" #include "../../extension_system/iplugin_spec.h" // NeL includes @@ -41,6 +43,21 @@ bool MyPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStrin void MyPlugin::extensionsInitialized() { + Core::IMenuManager *menuManager = 0; + menuManager = _plugMan->getObject(); + if (menuManager == 0) + nlinfo("error menu manager"); + else + { + QAction *exampleAction1 = new QAction("Example1", this); + QAction *exampleAction2 = new QAction("Example2", this); + QAction *aboutQtAction = menuManager->action(Core::Constants::ABOUT_QT); + QMenu *helpMenu = menuManager->menu(Core::Constants::M_HELP); + helpMenu->insertAction(aboutQtAction, exampleAction1); + helpMenu->addSeparator(); + helpMenu->addAction(exampleAction2); + menuManager->menuBar()->addMenu("ExampleMenu"); + } } void MyPlugin::setNelContext(NLMISC::INelContext *nelContext) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.h index cb3c1cf87..bbff7e9e0 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.h @@ -39,12 +39,11 @@ public: virtual ~CSimpleViewer() {} }; -class CCoreListener : public QObject, public Core::ICoreListener +class CCoreListener : public Core::ICoreListener { Q_OBJECT - Q_INTERFACES(Core::ICoreListener) public: - CCoreListener(QObject *parent = 0): QObject(parent) {} + CCoreListener(QObject *parent = 0): ICoreListener(parent) {} virtual ~CCoreListener() {} virtual bool closeMainWindow() const;