Commit 0195fb5c authored by Jan Möbius's avatar Jan Möbius
Browse files

Dennis: Menubar extensions

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@6584 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 35e76115
...@@ -48,27 +48,25 @@ ...@@ -48,27 +48,25 @@
#include <QMenuBar> #include <QMenuBar>
#include <OpenFlipper/common/Types.hh> #include <OpenFlipper/common/Types.hh>
enum MenuActionType { // typedef to support old interface
/// The Menu will be created directly inside the Menubar. typedef QString MenuActionType;
TOPLEVELMENU,
/// The Menu will be added inside the File Menu /// The Menu will be added inside the File Menu
FILEMENU, #define FILEMENU tr("&File")
/// The Menu will be added inside the View Menu /// The Menu will be added inside the View Menu
VIEWMENU, #define VIEWMENU tr("&View")
/// The Menu will be added inside the Tools Menu /// The Menu will be added inside the Tools Menu
TOOLSMENU #define TOOLSMENU tr("&Tools")
};
/** \brief Interface for all plugins which provide entries to the main menubar /** \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 * 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 the menubar. You can connect the * your own QMenu or QAction and emit addMenubarAction to add it to one of the menubar toplevel menus.
* signals and slots for your menu or action inside the plugin.\n * You can also get a pointer to one existing toplevel menus or create a new one with the getMenubarMenu
* The placement of your menu in the global menubar is controlled by the MenuActionType. See MenuActionType for details. * function. You can connect the signals and slots for your menu or action inside the plugin.
*/ */
class MenuInterface { class MenuInterface {
...@@ -78,9 +76,20 @@ public : ...@@ -78,9 +76,20 @@ public :
virtual ~MenuInterface() {}; virtual ~MenuInterface() {};
signals: 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 /** \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 * \n
* Example : \n * Example : \n
* QMenu *colorMenu = new QMenu(tr("&Colors")); \n * QMenu *colorMenu = new QMenu(tr("&Colors")); \n
...@@ -90,10 +99,9 @@ signals: ...@@ -90,10 +99,9 @@ signals:
* to connect the required signals and slots to your plugin. * to connect the required signals and slots to your plugin.
* *
* @param _action Pointer to the new action * @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") Q_DECLARE_INTERFACE(MenuInterface,"OpenFlipper.MenuInterface/1.0")
......
...@@ -553,9 +553,12 @@ void Core::loadPlugin(QString filename, bool silent){ ...@@ -553,9 +553,12 @@ void Core::loadPlugin(QString filename, bool silent){
if ( menubarPlugin && OpenFlipper::Options::gui() ) { if ( menubarPlugin && OpenFlipper::Options::gui() ) {
supported = supported + "Menubar "; supported = supported + "Menubar ";
if ( checkSignal(plugin,"addMenubarAction(QAction*,MenuActionType)") ) if ( checkSignal(plugin,"addMenubarAction(QAction*,QString)") )
connect(plugin , SIGNAL(addMenubarAction(QAction*,MenuActionType)), connect(plugin , SIGNAL(addMenubarAction(QAction*,QString)),
coreWidget_ , SLOT(slotAddMenubarAction(QAction*,MenuActionType)),Qt::DirectConnection); 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 //Check if the plugin supports ContextMenuInterface
......
...@@ -483,7 +483,8 @@ public: ...@@ -483,7 +483,8 @@ public:
//=========================================================================== //===========================================================================
private slots : private slots :
void slotAddMenubarAction( QAction* _action , MenuActionType _type ); void slotAddMenubarAction( QAction* _action , QString _name );
void slotGetMenubarMenu (QString _name, QMenu *& _menu, bool _create);
private: private:
...@@ -499,6 +500,9 @@ public: ...@@ -499,6 +500,9 @@ public:
/// First entry after all relevant parts of the File Menu /// First entry after all relevant parts of the File Menu
QAction* fileMenuEnd_; QAction* fileMenuEnd_;
/// All available menus
QMap<QString, QMenu *> menus_;
/** @} */ /** @} */
//=========================================================================== //===========================================================================
......
...@@ -50,24 +50,33 @@ ...@@ -50,24 +50,33 @@
void CoreWidget::slotAddMenubarAction( QAction* _action , MenuActionType _type ) { void CoreWidget::slotAddMenubarAction( QAction* _action , QString _name ) {
switch (_type) { if (!menus_.contains (_name))
case TOPLEVELMENU : return;
// Add it to the menubar as a top level Menu
menuBar()->insertAction(helpMenu_->menuAction() ,_action); if (_name == FILEMENU)
break; {
case FILEMENU : fileMenu_->insertSeparator(fileMenuEnd_);
fileMenu_->insertSeparator(fileMenuEnd_); fileMenu_->insertAction( fileMenuEnd_ , _action );
fileMenu_->insertAction( fileMenuEnd_ , _action );
break;
case VIEWMENU :
viewMenu_->addAction( _action );
break;
case TOOLSMENU:
toolsMenu_->addAction( _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() ...@@ -103,6 +112,7 @@ void CoreWidget::setupMenuBar()
// ====================================================================== // ======================================================================
fileMenu_ = new QMenu(tr("&File")); fileMenu_ = new QMenu(tr("&File"));
menuBar()->addMenu(fileMenu_ ); menuBar()->addMenu(fileMenu_ );
menus_[tr("&File")] = fileMenu_;
//Clear all //Clear all
QAction* AC_clear_all = new QAction(tr("&Clear All"), this);; QAction* AC_clear_all = new QAction(tr("&Clear All"), this);;
...@@ -206,6 +216,7 @@ void CoreWidget::setupMenuBar() ...@@ -206,6 +216,7 @@ void CoreWidget::setupMenuBar()
// ====================================================================== // ======================================================================
viewMenu_ = new QMenu(tr("&View")); viewMenu_ = new QMenu(tr("&View"));
menuBar()->addMenu(viewMenu_ ); menuBar()->addMenu(viewMenu_ );
menus_[tr("&View")] = viewMenu_;
slotUpdateGlobalDrawMenu(); slotUpdateGlobalDrawMenu();
viewMenu_->addMenu(globalDrawMenu_); viewMenu_->addMenu(globalDrawMenu_);
...@@ -405,6 +416,7 @@ void CoreWidget::setupMenuBar() ...@@ -405,6 +416,7 @@ void CoreWidget::setupMenuBar()
toolsMenu_ = new QMenu(tr("&Tools")); toolsMenu_ = new QMenu(tr("&Tools"));
menuBar()->addMenu(toolsMenu_ ); menuBar()->addMenu(toolsMenu_ );
menus_[tr("&Tools")] = toolsMenu_;
QAction* sceneGraphAction = new QAction( "Show SceneGraph " ,toolsMenu_ ); QAction* sceneGraphAction = new QAction( "Show SceneGraph " ,toolsMenu_ );
sceneGraphAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"scenegraph.png") ); sceneGraphAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"scenegraph.png") );
...@@ -441,6 +453,7 @@ void CoreWidget::setupMenuBar() ...@@ -441,6 +453,7 @@ void CoreWidget::setupMenuBar()
// ====================================================================== // ======================================================================
helpMenu_ = new QMenu(tr("&Help")); helpMenu_ = new QMenu(tr("&Help"));
menuBar()->addMenu(helpMenu_); menuBar()->addMenu(helpMenu_);
menus_[tr("&Help")] = helpMenu_;
//Open Help Browser //Open Help Browser
QAction* AC_HelpBrowser = new QAction(tr("&Help"), this); QAction* AC_HelpBrowser = new QAction(tr("&Help"), this);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment