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

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 @@
#include <QMenuBar>
#include <OpenFlipper/common/Types.hh>
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")
......
......@@ -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
......
......@@ -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<QString, QMenu *> menus_;
/** @} */
//===========================================================================
......
......@@ -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);
......
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