Menu and Toolbar management. More...
#include <menu.h>
Public Member Functions | |
| Menu (QMainWindow *_main) | |
| ~Menu () | |
| QString | getAction (int index) |
| QMenuBar * | loadMenu (QWidget *parent) throw (InvalidMenuException) |
| ToolBarList | loadToolBars () throw (InvalidMenuException) |
| ToolBar * | getToolbar (const QString &name) |
| QStringList | getToolbarList () |
| void | saveToolbars () |
| void | restoreToolbars () |
| const QPixmap * | getIcon (const QString &name) |
| const QIconSet * | getIconSet (const QString &name) |
| void | loadItem (const QString &name, QMenuData *parent=NULL, QStringList prev=QStringList()) throw (InvalidMenuException) |
| void | enableByName (const QString &name, bool enable) |
| void | checkByName (const QString &name, bool check) |
| void | showByName (const QString &name, bool show) |
| void | createItem (const QString &parentName, const QString &name, const QString &caption, const QString &action, const QString &accel=QString::null, const QString &icon=QString::null, const QStringList &classes=QStringList()) throw (InvalidMenuException) |
| void | setTextByName (const QString &name, const QString &newText) |
| QString | getTextByName (const QString &name) |
Static Public Member Functions | |
| static QString | pop (QStringList::ConstIterator &it, const QStringList::ConstIterator &end) |
| static char | getAccel (const QString &name) |
| static QString | readItem (const QString &name) throw (InvalidMenuException) |
| static bool | isList (const QString &line) |
| static QString | parseName (QString &line, const QString &name=QString::null) throw (InvalidMenuException) |
| static bool | chopCommand (QString &line, const QString &command) |
| static void | invalidItem (const QString &type, const QString &name, const QString &line, const QString &expected=QString::null) throw (InvalidMenuException) |
Private Member Functions | |
| QString | menuItemText (const QString &caption, const QString &name) |
| QString | toolTipText (const QString &text, const QString &name, QString accel=QString::null) |
| ToolButton * | createToolBarItem (ToolBar *tb, const QString &name, const QString &text, const QString &action, const QString &accel, const QString &icon, const QStringList &classes=QStringList()) |
| void | addToMap (const QString &name, QWidget *item) |
| void | addToMap (const QString &name, QMenuData *parent, int itemId) |
| void | addItem (QString line, QMenuData *parent, const QString &name=QString::null) throw (InvalidMenuException) |
| int | addItem (QMenuData *parent, const QString &name, const QString &caption, const QString &action, const QString &accel=QString::null, const QString &icon=QString::null, const QStringList &classes=QStringList()) throw (InvalidMenuException) |
| bool | reserveAccel (const QString &accelDef, const QString &action) |
| int | addAction (const QString &action) |
| void | loadItemsDef (QString line, QMenuData *menu, QStringList prev=QStringList()) throw (InvalidMenuException) |
| void | loadItems (const QString &name, QMenuData *menu, QStringList prev=QStringList()) throw (InvalidMenuException) |
| void | loadToolBarItem (ToolBar *tb, const QString &item) throw (InvalidMenuException) |
| ToolBar * | loadToolbar (const QString &name, bool visible=true) throw (InvalidMenuException) |
| void | optimizeItems (QMenuData *menu) |
Private Attributes | |
| ActionMap | action_map |
| ActionMapInverse | action_map_i |
| int | action_index |
| QStringList | toolbarNames |
| ToolBarList | toolbarList |
| AccelList | accels |
| QMap< QString, QString > | itemText |
| QMap< QString, QString > | accelText |
| MenuCache | mCache |
| MenuNames | mCacheName |
| MenuAccels | mAccel |
| IconCache * | cache |
| QMainWindow * | main |
| MenuItems | mapMenu |
| ToolbarItems | mapTool |
| int | seqId |
| QMenuBar * | menubar |
Menu and Toolbar management.
This class manages Menu, Toolbars and Shortcuts.
Menus, menu items, toolbars and toolbar items share the same namespace and often menu and toolbar items are interchangable (only difference is that toolbar item must have icon, while menu item can be without an icon)
For more information about menus and toolbars, check doc/design/gui/menu.xml
| gui::Menu::Menu | ( | QMainWindow * | _main | ) |
Contructor of menu system for one specific window
| _main | Main application window |
| gui::Menu::~Menu | ( | ) |
Destructor
| int gui::Menu::addAction | ( | const QString & | action | ) | [private] |
Adds action to menu, returning newly allocated menu Id or existing menu id if action is already present
| action | Name of action |
| int gui::Menu::addItem | ( | QMenuData * | parent, | |
| const QString & | name, | |||
| const QString & | caption, | |||
| const QString & | action, | |||
| const QString & | accel = QString::null, |
|||
| const QString & | icon = QString::null, |
|||
| const QStringList & | classes = QStringList() | |||
| ) | throw (InvalidMenuException) [private] |
Add menu item specified by given data to parent
| parent | parent menu in which this item will be appended | |
| name | Name of the item. Key in settings, or specified from script. Have to be unique | |
| caption | Caption of item (untranslated) | |
| action | Script to execute when the item is selected | |
| accel | Keyboard Accelerator | |
| icon | Name of icon | |
| classes | Item classes |
| void gui::Menu::addItem | ( | QString | line, | |
| QMenuData * | parent, | |||
| const QString & | name = QString::null | |||
| ) | throw (InvalidMenuException) [private] |
Add menu item specified by given data to parent
| line | Line containing menu item specification | |
| parent | parent menu in which this item will be appended | |
| name | Name of this item (key in settings). |
| void gui::Menu::addToMap | ( | const QString & | name, | |
| QMenuData * | parent, | |||
| int | itemId | |||
| ) | [private] |
Add specified menu item to "all items" map
| name | Name of item | |
| parent | Parent menu | |
| itemId | Id of item in parent menu |
| void gui::Menu::addToMap | ( | const QString & | name, | |
| QWidget * | item | |||
| ) | [private] |
Add specified toolbar item to "all items" map
| name | Name of item | |
| item | The toolbutton or widget |
Referenced by getIcon().
| void gui::Menu::checkByName | ( | const QString & | name, | |
| bool | check | |||
| ) |
Check or uncheck item in toolbar and/or menu, given its name
Note: Toolbuttons will automatically convert to Togglable toolbuttons this way and will start togling itself automatically on each succesive click
| name | Name of item | |
| check | True to check, false to uncheck |
| bool gui::Menu::chopCommand | ( | QString & | line, | |
| const QString & | command | |||
| ) | [static] |
Try to remove command string from line. Return true, if command was found and removed from line, false if command was not found (and line is unchanged)
| line | input line | |
| command | Command to look for |
| void gui::Menu::createItem | ( | const QString & | parentName, | |
| const QString & | name, | |||
| const QString & | caption, | |||
| const QString & | action, | |||
| const QString & | accel = QString::null, |
|||
| const QString & | icon = QString::null, |
|||
| const QStringList & | classes = QStringList() | |||
| ) | throw (InvalidMenuException) |
Load one menu or toolbar item and insert it into parent menu or toolbar. If inserting into toolbar and name refers to special toobar item, that item is inserted and rest of parameters are ignored
| parentName | Name of parent menu/toolbar. If NULL/empty, main menubar is the parent | |
| name | Name of the item. Have to be unique. ("" or "-" will insert separator and ignore rest of parameters) | |
| caption | Caption of item | |
| action | Script to execute when the item is selected | |
| accel | Keyboard Accelerator | |
| icon | Name of icon | |
| classes | Item classes |
| ToolButton * gui::Menu::createToolBarItem | ( | ToolBar * | tb, | |
| const QString & | name, | |||
| const QString & | text, | |||
| const QString & | action, | |||
| const QString & | accel, | |||
| const QString & | icon, | |||
| const QStringList & | classes = QStringList() | |||
| ) | [private] |
Create single toolbar button and add it to toolbar
| tb | Toolbar for addition of item | |
| name | Name of the item. Key in settings, or specified from script. Have to be unique | |
| text | Tooltip of item (untranslated) | |
| action | Script to execute when the item is selected | |
| accel | Keyboard Accelerator | |
| icon | Name of icon | |
| classes | Item classes |
| void gui::Menu::enableByName | ( | const QString & | name, | |
| bool | enable | |||
| ) |
Enable or disable item in toolbar and/or menu, given its name
| name | Name of item | |
| enable | True to enable, false to disable |
| char gui::Menu::getAccel | ( | const QString & | name | ) | [static] |
Get accelerator for given description
| name | Name of menu item |
| QString gui::Menu::getAction | ( | int | index | ) |
Return action string from given menu ID
| index | Menu ID of action |
Referenced by gui::QSMenu::getAction().
| const QPixmap * gui::Menu::getIcon | ( | const QString & | name | ) |
Returns icon with given name from cache (loading if necessary)
| name | Name of icon to get |
References addToMap().
| const QIconSet * gui::Menu::getIconSet | ( | const QString & | name | ) |
Returns icon set with given name from cache (creating if necessary)
| name | Name of icon set to get |
Referenced by gui::QSMenu::addItemDef().
| QString gui::Menu::getTextByName | ( | const QString & | name | ) |
Given name of toolbar or menu item, return its text This will return original (untranslated) text (in english) Setting it back with setTextByName will translate it according to the translation file
| name | Name of the item |
| ToolBar * gui::Menu::getToolbar | ( | const QString & | name | ) |
Return toolbar with given name.
| name | Name of toolbar |
References toolbarNames.
| QStringList gui::Menu::getToolbarList | ( | ) |
Return list of toolbar names
| void gui::Menu::invalidItem | ( | const QString & | type, | |
| const QString & | name, | |||
| const QString & | line, | |||
| const QString & | expected = QString::null | |||
| ) | throw (InvalidMenuException) [static] |
Exit with error message after encountering invalid menu/toolbar item
| type | Type of offending item | |
| name | Name of offending item | |
| line | Line with offending item | |
| expected | Optional "Expected" field hinting what is expected to make data valid |
| bool gui::Menu::isList | ( | const QString & | line | ) | [static] |
Check if menu item with given definition is a list
| line | Definition of the item to check |
Referenced by gui::QSMenu::addItem(), and gui::QSMenu::QSMenu().
| void gui::Menu::loadItem | ( | const QString & | name, | |
| QMenuData * | parent = NULL, |
|||
| QStringList | prev = QStringList() | |||
| ) | throw (InvalidMenuException) |
Load one menu item and insert it into parent menu. Recursively load subitems if item is a submenu.
| name | name of item to be loaded from config file | |
| parent | parent menu item. If NULL and the item is list, the item is loaded in cache, but not added anywhere | |
| prev | String list containing names of all parents of this menu item (used for loop detection) |
Referenced by gui::QSMenu::addItem().
| void gui::Menu::loadItems | ( | const QString & | name, | |
| QMenuData * | menu, | |||
| QStringList | prev = QStringList() | |||
| ) | throw (InvalidMenuException) [private] |
Load all needed items into existing menu list
| name | name of item to be loaded from config file | |
| menu | menu in which to load items (menu bar or popup menu) | |
| prev | String list containing names of all parents of this menu item (used for loop detection) |
| void gui::Menu::loadItemsDef | ( | QString | line, | |
| QMenuData * | menu, | |||
| QStringList | prev = QStringList() | |||
| ) | throw (InvalidMenuException) [private] |
Load all needed items into existing menu list
| line | comma separated list of childs | |
| menu | menu in which to load items (menu bar or popup menu) | |
| prev | String list containing names of all parents of this menu item (used for loop detection) |
| QMenuBar * gui::Menu::loadMenu | ( | QWidget * | parent | ) | throw (InvalidMenuException) |
Loads menubar from configuration bar, and return it
If menubar can't be loaded, InvalidMenuException will be thrown Missing menu icons are allowed (if it can't be loaded, there will be no pixmap), missing items in configuration are not.
| parent | QWidget that will contain the menubar |
| ToolBar * gui::Menu::loadToolbar | ( | const QString & | name, | |
| bool | visible = true | |||
| ) | throw (InvalidMenuException) [private] |
Load single toolbar from configuration file
| name | Toolbar name in configuration file | |
| visible | Will be toolbar initially visible? |
| void gui::Menu::loadToolBarItem | ( | ToolBar * | tb, | |
| const QString & | item | |||
| ) | throw (InvalidMenuException) [private] |
Load single toolbar item and add it to toolbar
| tb | Toolbar for addition of item | |
| item | Item name in configuration file |
| ToolBarList gui::Menu::loadToolBars | ( | ) | throw (InvalidMenuException) |
Load all toolbars from configuration files and add them to parent window If toolbar can't be loaded, InvalidMenuException will be thrown
| QString gui::Menu::menuItemText | ( | const QString & | caption, | |
| const QString & | name | |||
| ) | [private] |
Return item text for given menu item Will translate the text
| caption | Caption of the menu item | |
| name | Name if the menu item |
| void gui::Menu::optimizeItems | ( | QMenuData * | menu | ) | [private] |
Add accelerator to items that do not have one
| menu | Menu to process |
References util::explode(), and gui::MENULIST_SEPARATOR.
| QString gui::Menu::parseName | ( | QString & | line, | |
| const QString & | name = QString::null | |||
| ) | throw (InvalidMenuException) [static] |
Parse name of list or item from line. List is then modified to contain only list of its items, or in case if item the rest of parameters
| line | Line with menu list definition | |
| name | Name (key) of this menu item (for locatization) |
Referenced by gui::QSMenu::addItemDef(), and gui::QSMenu::QSMenu().
| QString gui::Menu::pop | ( | QStringList::ConstIterator & | it, | |
| const QStringList::ConstIterator & | end | |||
| ) | [static] |
Get first string from QStringList iterator and advance iterator one item further. Return QString::null if at ending position "end"
| it | iterator | |
| end | iterator marking ending position |
| QString gui::Menu::readItem | ( | const QString & | name | ) | throw (InvalidMenuException) [static] |
Load one GUI item from config file, exiting application with fatal error if item not found
| name | Name of the item to read |
Referenced by gui::QSMenu::addItem(), and gui::QSMenu::QSMenu().
| bool gui::Menu::reserveAccel | ( | const QString & | accelDef, | |
| const QString & | action | |||
| ) | [private] |
Add accelerator to list of used accelerators and return true, if the accelerator was not taken before. Ensure only one item uses the accelerator at time
| accelDef | Accelerator in string form | |
| action | Action to reserve for this accelerator |
| void gui::Menu::restoreToolbars | ( | ) |
Restore toolbar state of QMainWindow from configuration
| void gui::Menu::saveToolbars | ( | ) |
Save toolbar state of QMainWindow to configuration
References toolbarList.
| void gui::Menu::setTextByName | ( | const QString & | name, | |
| const QString & | newText | |||
| ) |
Set text on toolbar or menu item with given name. If both text and menu item exist with same name, both are updated. Note: the text wilol be translated according to the translation file, so english text should be used and any translation should be put into the translation file
| name | Name of the item | |
| newText | text on the item |
| void gui::Menu::showByName | ( | const QString & | name, | |
| bool | show | |||
| ) |
Show or hide item in toolbar, given its name.
Items in menu can't be show or hidden this way
| name | Name of item | |
| show | True to show, false to hide |
| QString gui::Menu::toolTipText | ( | const QString & | text, | |
| const QString & | name, | |||
| QString | accel = QString::null | |||
| ) | [private] |
Return tooltip text for given text Will translate the tooltip, remove any & characters that have meaning in menus and add accelerator if specified
| text | Tooltip text | |
| name | Name of the toolbar item for which the text is. Used for correctly determining possible translation | |
| accel | Accelerator specified for the item (or QString::null if none defined or unknown) |
AccelList gui::Menu::accels [private] |
List of installed accelerators
QMap<QString, QString> gui::Menu::accelText [private] |
Accelerator for item by its name
int gui::Menu::action_index [private] |
Incrementing action index for menu items
ActionMap gui::Menu::action_map [private] |
Mapping between menu IDs and actions
ActionMapInverse gui::Menu::action_map_i [private] |
Inverse mapping between menu IDs and actions
IconCache* gui::Menu::cache [private] |
Cache for icons
QMap<QString, QString> gui::Menu::itemText [private] |
Text for item by its name
MenuAccels gui::Menu::mAccel [private] |
List of used menu accels
QMainWindow* gui::Menu::main [private] |
Main application window
MenuItems gui::Menu::mapMenu [private] |
Pointer to of all items by item or "item class" name - menu items
ToolbarItems gui::Menu::mapTool [private] |
Pointer to of all items by item or "item class" name - toolbar items
MenuCache gui::Menu::mCache [private] |
Cache for menu items
MenuNames gui::Menu::mCacheName [private] |
Cache for menu items - names
QMenuBar* gui::Menu::menubar [private] |
The main menu bar
int gui::Menu::seqId [private] |
Sequenc id for map key
ToolBarList gui::Menu::toolbarList [private] |
List of loaded toolbars
Referenced by saveToolbars().
QStringList gui::Menu::toolbarNames [private] |
List of loaded toolbars names
Referenced by getToolbar().