diff --git a/BasePlugin/MenuInterface.hh b/BasePlugin/MenuInterface.hh index e93a4b107612c5622549bd58fd87352bf1b63740..2787c6ad84090cf5bd34325f9d81ec1220bde5a0 100644 --- a/BasePlugin/MenuInterface.hh +++ b/BasePlugin/MenuInterface.hh @@ -48,27 +48,25 @@ #include #include -enum MenuActionType { - /// The Menu will be created directly inside the Menubar. - TOPLEVELMENU, +// typedef to support old interface +typedef QString MenuActionType; - /// The Menu will be added inside the File Menu - FILEMENU, +/// The Menu will be added inside the File Menu +#define FILEMENU tr("&File") - /// The Menu will be added inside the View Menu - VIEWMENU, +/// The Menu will be added inside the View Menu +#define VIEWMENU tr("&View") - /// The Menu will be added inside the Tools Menu - TOOLSMENU +/// The Menu will be added inside the Tools Menu +#define TOOLSMENU tr("&Tools") -}; /** \brief Interface for all plugins which provide entries to the main menubar * - * To add custom menus or action to the menubar and its submenus, you have to use this interface class. Create - * your own QMenu or QAction and emit addMenubarAction to add it to the menubar. You can connect the - * signals and slots for your menu or action inside the plugin.\n - * The placement of your menu in the global menubar is controlled by the MenuActionType. See MenuActionType for details. + * To add custom menus or actions to the menubar, you have to use this interface class. Create + * your own QMenu or QAction and emit addMenubarAction to add it to one of the menubar toplevel menus. + * You can also get a pointer to one existing toplevel menus or create a new one with the getMenubarMenu + * function. You can connect the signals and slots for your menu or action inside the plugin. */ class MenuInterface { @@ -78,9 +76,20 @@ public : virtual ~MenuInterface() {}; signals: + + /** \brief Get a existing toplevel menu pointer or create a new one + * + * Checks if a toplevel menu is present and creates one if needed \n + * + * @param _name Menu name (see FILEMENU/VIEWMENU/TOOLSMENU example defines) + * @param _menu The returned toplevel menu + * @param _create Should a new menu be created if id doesn't exist + */ + virtual void getMenubarMenu (QString /*_name*/, QMenu *& /*_menu*/, bool /*_create*/) {}; + /** \brief Adds an action to the menubar * - * Add an action to the menubar or one of its sub menus \n + * Add an action to one of the menubar toplevel menus \n * \n * Example : \n * QMenu *colorMenu = new QMenu(tr("&Colors")); \n @@ -90,10 +99,9 @@ signals: * to connect the required signals and slots to your plugin. * * @param _action Pointer to the new action - * @param _type Type of the Action ( See MenuActionType for Details ) + * @param _name Name of the menu */ - virtual void addMenubarAction(QAction* /*_action*/, MenuActionType /*_type*/ ) {}; - + virtual void addMenubarAction(QAction* /*_action*/, QString /*_name*/ ) {}; }; Q_DECLARE_INTERFACE(MenuInterface,"OpenFlipper.MenuInterface/1.0") diff --git a/Core/PluginLoader.cc b/Core/PluginLoader.cc index 48f2cbe226d8ffd8af253642eb7e8094187a1940..94b1874d341f1a0da729271bf46783de883b2d46 100644 --- a/Core/PluginLoader.cc +++ b/Core/PluginLoader.cc @@ -553,9 +553,12 @@ void Core::loadPlugin(QString filename, bool silent){ if ( menubarPlugin && OpenFlipper::Options::gui() ) { supported = supported + "Menubar "; - if ( checkSignal(plugin,"addMenubarAction(QAction*,MenuActionType)") ) - connect(plugin , SIGNAL(addMenubarAction(QAction*,MenuActionType)), - coreWidget_ , SLOT(slotAddMenubarAction(QAction*,MenuActionType)),Qt::DirectConnection); + if ( checkSignal(plugin,"addMenubarAction(QAction*,QString)") ) + connect(plugin , SIGNAL(addMenubarAction(QAction*,QString)), + coreWidget_ , SLOT(slotAddMenubarAction(QAction*,QString)),Qt::DirectConnection); + if ( checkSignal(plugin,"getMenubarMenu (QString,QMenu*&,bool)") ) + connect(plugin , SIGNAL(getMenubarMenu (QString,QMenu*&,bool)), + coreWidget_ , SLOT(slotGetMenubarMenu (QString,QMenu*&,bool)),Qt::DirectConnection); } //Check if the plugin supports ContextMenuInterface diff --git a/widgets/coreWidget/CoreWidget.hh b/widgets/coreWidget/CoreWidget.hh index 4fbc74125c4540864d47505f8af11fe9b2d85e74..580f79e8ad4ccbc718df1579c2856339382ccff0 100644 --- a/widgets/coreWidget/CoreWidget.hh +++ b/widgets/coreWidget/CoreWidget.hh @@ -483,7 +483,8 @@ public: //=========================================================================== private slots : - void slotAddMenubarAction( QAction* _action , MenuActionType _type ); + void slotAddMenubarAction( QAction* _action , QString _name ); + void slotGetMenubarMenu (QString _name, QMenu *& _menu, bool _create); private: @@ -499,6 +500,9 @@ public: /// First entry after all relevant parts of the File Menu QAction* fileMenuEnd_; + /// All available menus + QMap menus_; + /** @} */ //=========================================================================== diff --git a/widgets/coreWidget/MenuBar.cc b/widgets/coreWidget/MenuBar.cc index 023fb4186608c541a8a22395f053ee352dc79daf..acd47789445910c7e206d1f85300d603632a77f7 100644 --- a/widgets/coreWidget/MenuBar.cc +++ b/widgets/coreWidget/MenuBar.cc @@ -50,24 +50,33 @@ -void CoreWidget::slotAddMenubarAction( QAction* _action , MenuActionType _type ) { +void CoreWidget::slotAddMenubarAction( QAction* _action , QString _name ) { - switch (_type) { - case TOPLEVELMENU : - // Add it to the menubar as a top level Menu - menuBar()->insertAction(helpMenu_->menuAction() ,_action); - break; - case FILEMENU : - fileMenu_->insertSeparator(fileMenuEnd_); - fileMenu_->insertAction( fileMenuEnd_ , _action ); - break; - case VIEWMENU : - viewMenu_->addAction( _action ); - break; - case TOOLSMENU: - toolsMenu_->addAction( _action ); + if (!menus_.contains (_name)) + return; + + if (_name == FILEMENU) + { + fileMenu_->insertSeparator(fileMenuEnd_); + fileMenu_->insertAction( fileMenuEnd_ , _action ); } + else + menus_[_name]->addAction (_action); +} + +//============================================================================= +void CoreWidget::slotGetMenubarMenu (QString _name, QMenu *& _menu, bool _create) +{ + if (menus_.contains (_name)) + _menu = menus_[_name]; + else if (_create) + { + _menu = new QMenu(_name); + menus_[_name] = _menu; + menuBar()->insertAction(helpMenu_->menuAction() ,_menu->menuAction ()); + } else + _menu = NULL; } @@ -103,6 +112,7 @@ void CoreWidget::setupMenuBar() // ====================================================================== fileMenu_ = new QMenu(tr("&File")); menuBar()->addMenu(fileMenu_ ); + menus_[tr("&File")] = fileMenu_; //Clear all QAction* AC_clear_all = new QAction(tr("&Clear All"), this);; @@ -206,6 +216,7 @@ void CoreWidget::setupMenuBar() // ====================================================================== viewMenu_ = new QMenu(tr("&View")); menuBar()->addMenu(viewMenu_ ); + menus_[tr("&View")] = viewMenu_; slotUpdateGlobalDrawMenu(); viewMenu_->addMenu(globalDrawMenu_); @@ -405,6 +416,7 @@ void CoreWidget::setupMenuBar() toolsMenu_ = new QMenu(tr("&Tools")); menuBar()->addMenu(toolsMenu_ ); + menus_[tr("&Tools")] = toolsMenu_; QAction* sceneGraphAction = new QAction( "Show SceneGraph " ,toolsMenu_ ); sceneGraphAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"scenegraph.png") ); @@ -441,6 +453,7 @@ void CoreWidget::setupMenuBar() // ====================================================================== helpMenu_ = new QMenu(tr("&Help")); menuBar()->addMenu(helpMenu_); + menus_[tr("&Help")] = helpMenu_; //Open Help Browser QAction* AC_HelpBrowser = new QAction(tr("&Help"), this);