Developer Documentation

Menu Interface

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()
{
// Create a submenu called printing
QMenu *printMenu = new QMenu(tr("&Printing"));
// Set an icon for this submenu
printMenu->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"document-print.png"));
// Add the new submenu to OpenFlippers file menu
emit addMenubarAction(printMenu->menuAction(), FILEMENU );
// Create an action to be added to the submenu
QAction* AC_Print = new QAction(tr("&Print"), this);
// Set status tip for this entry
AC_Print->setStatusTip(tr("Print the current view"));
// Set icon for the entry
AC_Print->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"document-print.png"));
// connect the actions triggered slot to a local slot in this plugin.
connect(AC_Print, SIGNAL(triggered()), this, SLOT(printView()));
// add the new action to the print submenu
printMenu->addAction(AC_Print);
}

If you want to create a toplevel menu you can use the following code snippet:

//Pointer to the new menu
QMenu *topLevelMenu;
// This function checks if a menu called "Toplevel" exists and returns it in the pointer.
// If it does not exist, it is automatically created.
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.