| [65b6e0] | 1 | /*
 | 
|---|
| [56f73b] | 2 |  * Menu.hpp
 | 
|---|
| [65b6e0] | 3 |  *
 | 
|---|
 | 4 |  *  Created on: Dec 10, 2009
 | 
|---|
 | 5 |  *      Author: crueger
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
| [56f73b] | 8 | #ifndef MENU_MENU_HPP_
 | 
|---|
 | 9 | #define MENU_MENU_HPP_
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | // include config.h
 | 
|---|
 | 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 13 | #include <config.h>
 | 
|---|
 | 14 | #endif
 | 
|---|
| [65b6e0] | 15 | 
 | 
|---|
| [b59da6] | 16 | #include <set>
 | 
|---|
 | 17 | #include <string>
 | 
|---|
| [65b6e0] | 18 | 
 | 
|---|
| [b59da6] | 19 | #include "Menu/MenuInterface.hpp"
 | 
|---|
 | 20 | #include "Menu/MenuDescription.hpp"
 | 
|---|
| [65b6e0] | 21 | 
 | 
|---|
| [b59da6] | 22 | /** Base class for all Types of menus.
 | 
|---|
 | 23 |  * Here, we simply initialize the menus. Via the MenuInterface wrapper we may
 | 
|---|
 | 24 |  * access the adding of items for each specific menu in a uniform manner.
 | 
|---|
| [ef81b0] | 25 |  *
 | 
|---|
| [b59da6] | 26 |  * Note that this Class is never to be used directly but only via derived
 | 
|---|
 | 27 |  * specializations.
 | 
|---|
| [8f3f40] | 28 |  *
 | 
|---|
 | 29 |  * Note that we do not call member function init() directly in the constructor
 | 
|---|
 | 30 |  * to allow for something to be add to the menu beforehand which is necessary
 | 
|---|
 | 31 |  * for the TextMenu for example.
 | 
|---|
 | 32 |  *
 | 
|---|
 | 33 |  * <h1>Howto</h1>
 | 
|---|
 | 34 |  *
 | 
|---|
 | 35 |  * First, derive your own menu class, see QtMenu or TextMenu for example. These
 | 
|---|
 | 36 |  * have been templated because of the two Qt classes QMenu and QMenuBar to be
 | 
|---|
 | 37 |  * addressable in a unified manner. TextMenu does not actually need to be a
 | 
|---|
 | 38 |  * template but it does not hurt either.
 | 
|---|
 | 39 |  *
 | 
|---|
 | 40 |  * Basically, the structure is as follows:
 | 
|---|
 | 41 |  *  -# Menu implements the initialization: it goes through MenuDescription's and
 | 
|---|
 | 42 |  *     ActionRegistry's contents and adds MenuItem's and Action's as requested.
 | 
|---|
 | 43 |  *  -# It does so by calling virtual functions defined in MenuInterface. These
 | 
|---|
 | 44 |  *     allow for adding of specific type of items: separators, Actions, menus
 | 
|---|
 | 45 |  *  -# Your derived Menu implements add these specific adders, basically just as
 | 
|---|
 | 46 |  *     wrappers. If you really have another UI type, implement its Menu
 | 
|---|
 | 47 |  *     functionality separately, such as TxMenu does.
 | 
|---|
 | 48 |  *  -# It also inherits both Menu and virtually MenuInterface such that it
 | 
|---|
 | 49 |  *     contains initializing and adding functionality
 | 
|---|
 | 50 |  *
 | 
|---|
 | 51 |  *  Note that MenuInterface is inherited by both Menu and your class and hence has
 | 
|---|
 | 52 |  *  to be declared as a "virtual" base class for both.
 | 
|---|
| [ef81b0] | 53 |  */
 | 
|---|
| [b59da6] | 54 | class Menu : virtual public MenuInterface
 | 
|---|
| [65b6e0] | 55 | {
 | 
|---|
 | 56 | public:
 | 
|---|
| [b59da6] | 57 |   explicit Menu(const std::string &name);
 | 
|---|
| [65b6e0] | 58 |   virtual ~Menu();
 | 
|---|
 | 59 | 
 | 
|---|
| [b59da6] | 60 |   void init();
 | 
|---|
| [ef81b0] | 61 | 
 | 
|---|
| [b59da6] | 62 | protected:
 | 
|---|
| [163110] | 63 |   //!> Unique name of the menu for identification.
 | 
|---|
| [b59da6] | 64 |   const std::string name;
 | 
|---|
 | 65 | 
 | 
|---|
| [163110] | 66 |   /** populater function that adds all menu items.
 | 
|---|
 | 67 |    *
 | 
|---|
 | 68 |    */
 | 
|---|
| [b59da6] | 69 |   void populate();
 | 
|---|
| [163110] | 70 | 
 | 
|---|
 | 71 |   /** Populater function for all Actions in this menu.
 | 
|---|
 | 72 |    *
 | 
|---|
 | 73 |    */
 | 
|---|
| [b59da6] | 74 |   void populateActions();
 | 
|---|
| [65b6e0] | 75 | 
 | 
|---|
 | 76 | private:
 | 
|---|
| [163110] | 77 |   /** Adds an action to this menu.
 | 
|---|
 | 78 |    *
 | 
|---|
 | 79 |    * @param ActionName name of action
 | 
|---|
 | 80 |    * @param ActionDescription of the action (e.g. for tooltips)
 | 
|---|
 | 81 |    */
 | 
|---|
 | 82 |   void addAction(const std::string &ActionName, const std::string &ActionDescription);
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 |   /** Adds a separator (e.g. horizontal line) to menu.
 | 
|---|
 | 85 |    *
 | 
|---|
 | 86 |    */
 | 
|---|
| [b59da6] | 87 |   void addSeparator();
 | 
|---|
| [163110] | 88 | 
 | 
|---|
 | 89 |   /** Adds a submenu to this menu.
 | 
|---|
 | 90 |    *
 | 
|---|
 | 91 |    * @param MenuName name of submenu
 | 
|---|
 | 92 |    * @param MenuPosition position in sequence of items of submenu
 | 
|---|
 | 93 |    */
 | 
|---|
| [b59da6] | 94 |   void addSubmenu(const std::string &MenuName, const int MenuPosition);
 | 
|---|
| [163110] | 95 | 
 | 
|---|
 | 96 |   /** Checks whether an item named \a token exists in this menu.
 | 
|---|
 | 97 |    *
 | 
|---|
 | 98 |    * @param token name of action of submenu
 | 
|---|
 | 99 |    * @return true - item exists, false - item does not exist in this menu
 | 
|---|
 | 100 |    */
 | 
|---|
| [b59da6] | 101 |   bool isPresent(const std::string &token);
 | 
|---|
 | 102 | 
 | 
|---|
| [163110] | 103 |   //!> enumeration of all valid item types
 | 
|---|
| [b59da6] | 104 |   enum ItemType {ActionItem, MenuItem, SeparatorItem, NoItem};
 | 
|---|
 | 105 | 
 | 
|---|
| [163110] | 106 |   //!> current position to add
 | 
|---|
 | 107 |   int TopPosition;
 | 
|---|
 | 108 |   //!> check whether separator followed separator
 | 
|---|
 | 109 |   enum ItemType LastItem;
 | 
|---|
 | 110 |   //!> is used to check for duplicates
 | 
|---|
 | 111 |   std::set <std::string> DuplicatesList;
 | 
|---|
| [65b6e0] | 112 | };
 | 
|---|
 | 113 | 
 | 
|---|
| [56f73b] | 114 | #endif /* MENU_HPP_ */
 | 
|---|