The MenuInterface can be used by plugins to add menu entries to OpenFlippers UI. The entries will be added to OpenFlippers menubar or submenus (See image).
To use the MenuInterface:
-
include MenuInterface.hh in your plugins header file
-
derive your plugin from the class MenuInterface
-
add Q_INTERFACES(MenuInterface) to your plugin class
-
And add the signals or slots you want to use to your plugin class (You don't need to implement all of them)
Usually you should implement the BaseInterface::pluginsInitialized() function from BaseInterface. In this function you can setup your menus.
The following code shows a simple example to create a menu entry in the file menu.
void PrintPlugin::pluginsInitialized()
{
QMenu *printMenu = new QMenu(tr("&Printing"));
printMenu->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"document-print.png"));
emit addMenubarAction(printMenu->menuAction(),
FILEMENU );
QAction* AC_Print = new QAction(tr("&Print"), this);
AC_Print->setStatusTip(tr("Print the current view"));
AC_Print->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"document-print.png"));
connect(AC_Print, SIGNAL(triggered()), this, SLOT(printView()));
printMenu->addAction(AC_Print);
}
If you want to create a toplevel menu you can use the following code snippet:
QMenu *topLevelMenu;
emit getMenubarMenu(tr("Toplevel"), topLevelMenu, true );
Signals and slots of your menus (e.g. from an action inside it) can be directly connected to signals and slots in your plugin. Therefore the embedding of your menus into the OpenFlippers menu list is fully transparent.