- Timestamp:
- Dec 4, 2010, 11:33:47 PM (14 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 0af7ef
- Parents:
- 5813ac
- git-author:
- Frederik Heber <heber@…> (11/08/10 09:36:45)
- git-committer:
- Frederik Heber <heber@…> (12/04/10 23:33:47)
- Location:
- src
- Files:
-
- 6 added
- 2 deleted
- 17 edited
- 11 moved
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/ActionRegistry.cpp
r5813ac rb59da6 52 52 } 53 53 54 /** Returns the last present action position in the requested menu. 55 * \param &token token of the menu 56 * \return last used position 57 */ 58 int ActionRegistry::getLastPosition(const std::string &token) const 59 { 60 int position = 0; 61 for (const_iterator iter = getBeginIter(); 62 iter != getEndIter(); 63 ++iter) { 64 const std::string &MenuName = (iter->second)->Traits.getMenuName(); 65 const int &MenuPosition = (iter->second)->Traits.getMenuPosition(); 66 if ((MenuName == token) && (position < MenuPosition)) 67 position = MenuPosition; 68 } 69 return position; 70 } 71 72 54 73 CONSTRUCT_SINGLETON(ActionRegistry) 55 74 CONSTRUCT_REGISTRY(Action) -
src/Actions/ActionRegistry.hpp
r5813ac rb59da6 31 31 Action* getActionByName(const std::string name); 32 32 bool isActionPresentByName(const std::string name) const; 33 int getLastPosition(const std::string &MenuName) const; 33 34 34 35 private: -
src/Actions/ActionTraits.cpp
r5813ac rb59da6 46 46 _Traits.hasDefaultValue() ? _Traits.getDefaultValue() : "", 47 47 _Traits.hasShortForm() ? _Traits.getShortForm() : "" 48 ) 48 ), 49 MenuTitle(_Traits.MenuTitle), 50 MenuPosition(_Traits.MenuPosition) 49 51 { 50 MenuTitle = _Traits.MenuTitle;51 MenuPosition = _Traits.MenuPosition;52 52 for (options_const_iterator iter = _Traits.Options.begin(); iter != _Traits.Options.end(); ++iter) { 53 53 Options.insert( … … 65 65 * \param &_Traits source OptionTrait class to copy 66 66 */ 67 ActionTraits::ActionTraits(const OptionTrait &_Traits) : 68 OptionTrait(_Traits) 67 ActionTraits::ActionTraits(const OptionTrait &_Traits, const std::string _MenuTitle, const int _MenuPosition) : 68 OptionTrait(_Traits), 69 MenuTitle(_MenuTitle), 70 MenuPosition(_MenuPosition) 69 71 { 70 72 //std::cout << "ActionTraits::ActionTraits(OptionTrait &) with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl; … … 94 96 * \return ActionTraits::MenuPosition as std::string 95 97 */ 96 constint ActionTraits::getMenuPosition() const98 int ActionTraits::getMenuPosition() const 97 99 { 98 100 return MenuPosition; -
src/Actions/ActionTraits.hpp
r5813ac rb59da6 31 31 public: 32 32 ActionTraits(const ActionTraits &_Traits); 33 ActionTraits(const OptionTrait &_Traits );33 ActionTraits(const OptionTrait &_Traits, const std::string _MenuTitle = "", const int _MenuPosition = 0); 34 34 explicit ActionTraits(const std::string &_token); 35 35 virtual ~ActionTraits(); … … 40 40 41 41 const std::string& getMenuName() const; 42 constint getMenuPosition() const;42 int getMenuPosition() const; 43 43 44 44 // getter for its options -
src/Makefile.am
r5813ac rb59da6 128 128 UIElements/Qt4/QtMainWindow.hpp \ 129 129 UIElements/Menu/Qt4/QtMenu.hpp \ 130 UIElements/Menu/Qt4/QtMenuPipe.hpp \ 130 131 UIElements/Views/Qt4/QtWorldView.hpp \ 131 132 UIElements/Views/Qt4/GLMoleculeView.hpp \ … … 170 171 UIElements/Qt4/QtDialog.cpp \ 171 172 UIElements/Qt4/QtUIFactory.cpp \ 172 UIElements/Menu/Qt4/QtMenu .cpp \173 UIElements/Menu/Qt4/QtMenuPipe.cpp \ 173 174 UIElements/Views/Qt4/QtWorldView.cpp \ 174 175 UIElements/Views/Qt4/GLMoleculeView.cpp \ -
src/Patterns/Registry_impl.hpp
r5813ac rb59da6 35 35 typename std::map<const std::string,T*>::const_iterator iter; 36 36 iter = InstanceMap.find(name); 37 ASSERT(iter!=InstanceMap.end(),"Query for an instance not stored in registry");37 ASSERT(iter!=InstanceMap.end(),"Query for an instance "+name+" not stored in registry"); 38 38 return iter->second; 39 39 } … … 58 58 //std::cout << "Trying to register instance of type " << typeid(T).name() << " with name " << instance->getName() << "." << std::endl; 59 59 ret = InstanceMap.insert(typename std::pair<const std::string,T*>(instance->getName(),instance)); 60 ASSERT(ret.second,"Two instances with the same name added to registry");60 ASSERT(ret.second,"Two instances with the same name "+instance->getName()+" added to registry"); 61 61 } 62 62 -
src/UIElements/Makefile.am
r5813ac rb59da6 20 20 Menu/Menu.cpp \ 21 21 Menu/MenuDescription.cpp \ 22 Menu/TextMenu.cpp \ 23 Menu/MenuItem.cpp \ 24 Menu/SubMenuItem.cpp \ 25 Menu/ActionMenuItem.cpp \ 26 Menu/SeperatorItem.cpp \ 27 Menu/DisplayMenuItem.cpp 28 22 Menu/MenuInterface.cpp 23 29 24 MENUHEADER = \ 30 25 Menu/Menu.hpp \ 31 26 Menu/MenuDescription.hpp \ 32 Menu/TextMenu.hpp \ 33 Menu/MenuItem.hpp \ 34 Menu/SubMenuItem.hpp \ 35 Menu/ActionMenuItem.hpp \ 36 Menu/SeperatorItem.hpp \ 37 Menu/DisplayMenuItem.hpp 27 Menu/MenuInterface.hpp 28 29 TEXTMENUSOURCE = \ 30 Menu/TextMenu/TxMenu.cpp \ 31 Menu/TextMenu/MenuItem.cpp \ 32 Menu/TextMenu/SubMenuItem.cpp \ 33 Menu/TextMenu/ActionMenuItem.cpp \ 34 Menu/TextMenu/SeperatorItem.cpp \ 35 Menu/TextMenu/DisplayMenuItem.cpp 36 37 TEXTMENUHEADER = \ 38 Menu/TextMenu/TextMenu.hpp \ 39 Menu/TextMenu/TxMenu.hpp \ 40 Menu/TextMenu/MenuItem.hpp \ 41 Menu/TextMenu/SubMenuItem.hpp \ 42 Menu/TextMenu/ActionMenuItem.hpp \ 43 Menu/TextMenu/SeperatorItem.hpp \ 44 Menu/TextMenu/DisplayMenuItem.hpp 38 45 39 46 UISOURCE = \ … … 41 48 ${COMMANDLINEUISOURCE} \ 42 49 ${MENUSOURCE} \ 50 ${TEXTMENUSOURCE} \ 43 51 ${TEXTUISOURCE} \ 44 52 ${VIEWSOURCE} \ … … 69 77 ${COMMANDLINEUIHEADER} \ 70 78 ${MENUHEADER} \ 79 ${TEXTMENUHEADER} \ 71 80 ${TEXTUIHEADER} \ 72 81 ${VIEWHEADER} \ -
src/UIElements/Menu/Menu.cpp
r5813ac rb59da6 20 20 #include "Helpers/MemDebug.hpp" 21 21 22 #include "Menu.hpp"22 #include <iostream> 23 23 24 Menu::Menu() 24 #include "Actions/ActionRegistry.hpp" 25 #include "Actions/Action.hpp" 26 #include "Actions/ActionTraits.hpp" 27 #include "Menu/Menu.hpp" 28 29 /** Constructor of class Menu. 30 * \param &_name name of menu 31 */ 32 Menu::Menu(const std::string &_name) : 33 MenuInterface(_name), 34 name(_name), 35 TopPosition(0), 36 LastItem(NoItem) 37 {} 38 39 /** Destructor of class Menu. 40 * 41 */ 42 Menu::~Menu() 43 {} 44 45 /** Initialiser for class Menu. 46 * Fills menus with items. 47 */ 48 void Menu::init() 25 49 { 26 // TODO Auto-generated constructor stub27 50 populate(); 51 populateActions(); 28 52 } 29 53 30 Menu::~Menu() 54 /** Initializing function. 55 * Inserts Menus and Actions obtained from MenuDescription and 56 * ActionRegistry. 57 */ 58 void Menu::populate() 31 59 { 32 // TODO Auto-generated destructor stub 60 // go through all menus and create them 61 62 bool CompleteFlag = false; // indicates whether all menus have been added 63 bool PossibleMissingFlag = false; // indicates whether a separator is missing 64 while (!CompleteFlag) { 65 CompleteFlag = true; 66 PossibleMissingFlag = false; 67 for(MenuDescription::const_iterator iter = menudescriptions.getBeginIter(); 68 iter != menudescriptions.getEndIter(); 69 ++iter) { 70 // skip when already present 71 if (!isPresent(iter->first)) { 72 // have some short refs to infos 73 const std::string &MenuName = iter->first; 74 const std::string &TopName = iter->second.first; 75 const int &MenuPosition = iter->second.second; 76 std::cout << "MenuName is " << MenuName 77 << ", TopName is " << TopName 78 << " and Position is " << MenuPosition 79 << std::endl; 80 81 // does it belong to us? 82 if (TopName == name) { 83 if (MenuPosition-1 == TopPosition) { 84 Menu::addSubmenu(MenuName, MenuPosition); 85 CompleteFlag = false; 86 } 87 // is there a menuposition specified that we have not reached yet? 88 if (MenuPosition-1 > TopPosition) 89 PossibleMissingFlag = true; 90 } 91 } 92 } 93 if (PossibleMissingFlag && (CompleteFlag)) { 94 Menu::addSeparator(); 95 CompleteFlag = false; // pass once more as there should be a menu to come 96 } 97 } 33 98 } 99 100 /** Fills this menu with all Actions that belong to it. 101 */ 102 void Menu::populateActions() 103 { 104 // go through all actions and add those beloning to this menu 105 ActionRegistry &AR = ActionRegistry::getInstance(); 106 for (ActionRegistry::const_iterator iter = AR.getBeginIter(); 107 iter != AR.getEndIter(); 108 ++iter) { 109 const std::string &MenuName = iter->second->Traits.getMenuName(); 110 if (MenuName == name) { 111 const std::string &ActionName = iter->first; 112 Menu::addAction(ActionName); 113 } 114 } 115 } 116 117 void Menu::addAction(const std::string &ActionName) 118 { 119 LastItem = ActionItem; 120 addActionItem(ActionName, ActionName); 121 } 122 123 void Menu::addSeparator() 124 { 125 std::cout << "Creating separator at position " << TopPosition << std::endl; 126 ASSERT( LastItem != SeparatorItem, 127 "Menu::populate() - adding another separator after a separator!"); 128 LastItem = SeparatorItem; 129 addSeparatorItem(); 130 TopPosition++; 131 } 132 133 void Menu::addSubmenu(const std::string &MenuName, const int MenuPosition) 134 { 135 std::cout << "Creating top-level menu " << MenuName 136 << " at position " << TopPosition << std::endl; 137 ASSERT (!isPresent(MenuName), 138 "Menu::addSubmenu() - trying to add menu "+MenuName+" with already present token!"); 139 addSubmenuItem(MenuName, menudescriptions.getDescription(MenuName)); 140 DuplicatesList.insert(MenuName); 141 LastItem = MenuItem; 142 TopPosition = MenuPosition; 143 } 144 145 bool Menu::isPresent(const std::string &token) 146 { 147 return (DuplicatesList.find(token) != DuplicatesList.end()); 148 } -
src/UIElements/Menu/Menu.hpp
r5813ac rb59da6 9 9 #define MENU_MENU_H_ 10 10 11 using namespace std; 11 #include <set> 12 #include <string> 12 13 13 class MenuItem; 14 #include "Menu/MenuInterface.hpp" 15 #include "Menu/MenuDescription.hpp" 14 16 15 /** 16 * Base class for all Types of menus17 * contains basic abstract functionality to add Items, remove Items and display the menu17 /** Base class for all Types of menus. 18 * Here, we simply initialize the menus. Via the MenuInterface wrapper we may 19 * access the adding of items for each specific menu in a uniform manner. 18 20 * 19 * TODO: Make sure all items are only added once. 21 * Note that this Class is never to be used directly but only via derived 22 * specializations. 20 23 */ 21 class Menu 24 class Menu : virtual public MenuInterface 22 25 { 23 26 public: 24 Menu();27 explicit Menu(const std::string &name); 25 28 virtual ~Menu(); 26 29 30 void init(); 27 31 28 /** 29 * Adding and removing should be handled by the items. 30 */ 31 virtual void addItem(MenuItem*)=0; 32 /** 33 * Adding and removing should be handled by the items. 34 */ 35 virtual void removeItem(MenuItem*)=0; 36 virtual void display()=0; 32 protected: 33 // Unique name of the menu for identification. 34 const std::string name; 35 36 // populater function that adds all menu items 37 void populate(); 38 void populateActions(); 37 39 38 40 private: 41 void addAction(const std::string &ActionName); 42 void addSeparator(); 43 void addSubmenu(const std::string &MenuName, const int MenuPosition); 44 bool isPresent(const std::string &token); 45 46 enum ItemType {ActionItem, MenuItem, SeparatorItem, NoItem}; 47 48 int TopPosition; // current position to add 49 MenuDescription menudescriptions; // contains the menu tree and description to each item 50 enum ItemType LastItem; // check whether separator followed separator 51 std::set <std::string> DuplicatesList; // is used to check for duplicates 39 52 }; 40 53 -
src/UIElements/Menu/MenuDescription.cpp
r5813ac rb59da6 75 75 * \return description string of the menu or empty 76 76 */ 77 const std::string MenuDescription::getDescription( std::stringtoken) const77 const std::string MenuDescription::getDescription(const std::string &token) const 78 78 { 79 79 if (MenuDescriptionsMap.find(token) != MenuDescriptionsMap.end()) … … 87 87 * \return description string of the menu or empty 88 88 */ 89 const std::string MenuDescription::getName( std::stringtoken) const89 const std::string MenuDescription::getName(const std::string &token) const 90 90 { 91 91 if (MenuNameMap.find(token) != MenuNameMap.end()) -
src/UIElements/Menu/MenuDescription.hpp
r5813ac rb59da6 32 32 33 33 // getter for description 34 const std::string getDescription( std::stringtoken) const;35 const std::string getName( std::stringtoken) const;34 const std::string getDescription(const std::string &token) const; 35 const std::string getName(const std::string &token) const; 36 36 37 37 std::multimap <std::string, std::string> getMenuItemsMap() const; -
src/UIElements/Menu/Qt4/QtMenu.hpp
r5813ac rb59da6 2 2 * QtMenu.hpp 3 3 * 4 * Created on: Jan 15, 20105 * Author: crueger4 * Created on: Nov 5, 2010 5 * Author: heber 6 6 */ 7 7 8 #ifndef QTMENU_HPP_9 #define QTMENU_HPP_8 #ifndef MENUINTERFACEQT_HPP_ 9 #define MENUINTERFACEQT_HPP_ 10 10 11 #include <Qt/qaction.h> 12 13 #include <iostream> 11 14 #include <list> 12 13 #include <QtGui/QMenu> 14 #include <QtCore/QObject> 15 #include <map> 16 #include <string> 15 17 16 18 #include "Menu/Menu.hpp" 19 #include "Menu/MenuInterface.hpp" 20 #include "Menu/Qt4/QtMenuPipe.hpp" 17 21 18 class QtMenuPipe; 22 /** QtMenu is a specialization of MenuInterface to Qt-like menus. 23 * I.e. with this interface we can access QMenu and QMenuBar. 24 * (The latter is the reason why we have to add this additional wrapping layer). 25 */ 26 template <class T> 27 class QtMenu : virtual public MenuInterface, public Menu 28 { 29 public: 30 explicit QtMenu(const std::string &_token) : 31 MenuInterface(_token), 32 Menu(_token), 33 MenuInstance(new T(QString(getNameWithAccelerator(_token).c_str()))), 34 deleteMenu(true) 35 {} 19 36 20 class QtMenu : public QMenu, public Menu 21 { 22 Q_OBJECT 37 QtMenu(T *_Menu, const std::string &_token) : 38 MenuInterface(_token), 39 Menu(_token), 40 MenuInstance(_Menu), 41 deleteMenu(false) 42 {} 23 43 24 public: 25 QtMenu(const char *); 26 virtual ~QtMenu(); 44 virtual ~QtMenu() 45 { 46 for(std::list<QtMenuPipe*>::iterator it=plumbing.begin(); it != plumbing.end(); it++) 47 delete (*it); 27 48 28 virtual void addItem(MenuItem*); 29 virtual void removeItem(MenuItem*); 30 virtual void display(); 49 if (deleteMenu) 50 delete MenuInstance; 51 } 52 53 T * const getMenuInstance() 54 { 55 return MenuInstance; 56 } 57 58 protected: 59 // We need to have a reference of the Menu, as Qt returns reference to added menu as well 60 T *MenuInstance; 61 62 /** Puts Qt's token, the ampersand, in front of the accelerator char in the menu name. 63 * \param ActionName Action of menu 64 * \return name with ampersand added at the right place 65 */ 66 std::string getNameWithAccelerator(const std::string &ActionName) 67 { 68 std::string newname; 69 bool Inserted = false; 70 std::pair < MenuShortcutMap::iterator, bool > Inserter; 71 for (std::string::const_iterator CharRunner = ActionName.begin(); 72 CharRunner != ActionName.end(); 73 ++CharRunner) { 74 std::cout << "Current char is " << *CharRunner << std::endl; 75 if (!Inserted) { 76 Inserter = ShortcutMap.insert( 77 std::pair<char, std::string > (*CharRunner, ActionName) 78 ); 79 if (Inserter.second) { 80 std::cout << "Accelerator is " << *CharRunner << std::endl; 81 newname += '&'; 82 Inserted = true; 83 } 84 } 85 newname += *CharRunner; 86 } 87 return newname; 88 } 89 31 90 private: 32 list<QtMenuPipe*> plumbing; 91 bool deleteMenu; 92 std::list<QtMenuPipe*> plumbing; 93 94 typedef std::map <char, std::string> MenuShortcutMap; 95 MenuShortcutMap ShortcutMap; 96 97 virtual void addActionItem(const std::string &token, const std::string &description) 98 { 99 QAction *action = MenuInstance->addAction(QString(getNameWithAccelerator(description).c_str())); 100 QtMenuPipe *pipe = new QtMenuPipe(token,action); 101 QObject::connect(action, SIGNAL(triggered()),pipe,SLOT(called())); 102 plumbing.push_back(pipe); 103 } 104 105 virtual void addSeparatorItem() 106 { 107 MenuInstance->addSeparator(); 108 } 109 110 virtual void addSubmenuItem(const std::string &token, const std::string &description) 111 { 112 QMenu *Menu = MenuInstance->addMenu(QString(token.c_str())); 113 QtMenu<QMenu> *NewMenu = new QtMenu<QMenu>(Menu, token); 114 NewMenu->init(); 115 } 116 33 117 }; 34 118 35 // This handles the plumbing from QT to internal Items 36 // Slots from QT are redirected to internal methods. 37 // This way methods can be used where no QT is available 38 class QtMenuPipe : public QObject { 39 Q_OBJECT 40 public: 41 QtMenuPipe(MenuItem*,QAction*); 42 virtual ~QtMenuPipe(); 43 public slots: 44 void called(); 45 private: 46 MenuItem *theItem; 47 QAction *theAction; 48 }; 49 50 #endif /* QTMENU_HPP_ */ 119 #endif /* MENUINTERFACEQT_HPP_ */ -
src/UIElements/Menu/TextMenu/ActionMenuItem.cpp
r5813ac rb59da6 22 22 #include <iostream> 23 23 24 #include "Menu/ActionMenuItem.hpp" 25 #include "Actions/MethodAction.hpp" 24 #include "Menu/TextMenu/ActionMenuItem.hpp" 25 #include "Actions/Action.hpp" 26 #include "Actions/ActionRegistry.hpp" 26 27 27 28 using namespace std; 28 29 29 ActionMenuItem::ActionMenuItem(char _trigger, const char* _description,Menu* _menu,Action* _action)30 ActionMenuItem::ActionMenuItem(char _trigger, const std::string &_description,TxMenu* const _menu,const std::string &_ActionName) 30 31 : MenuItem(_trigger,_description,_menu), 31 action(_action)32 ActionName(_ActionName) 32 33 { 33 34 } … … 37 38 38 39 void ActionMenuItem::doTrigger() { 40 Action* action = ActionRegistry::getInstance().getActionByName(ActionName); 39 41 action->call(); 40 42 } 41 43 42 44 bool ActionMenuItem::isActive() { 45 Action* action = ActionRegistry::getInstance().getActionByName(ActionName); 43 46 return action->isActive(); 44 47 } -
src/UIElements/Menu/TextMenu/ActionMenuItem.hpp
r5813ac rb59da6 11 11 #include <string> 12 12 13 #include "Menu/ MenuItem.hpp"13 #include "Menu/TextMenu/MenuItem.hpp" 14 14 15 15 class Action; 16 class TxMenu; 16 17 17 18 /** … … 21 22 { 22 23 public: 23 ActionMenuItem(char,const char*,Menu*,Action*);24 ActionMenuItem(char,const std::string &,TxMenu* const,const std::string &); 24 25 virtual ~ActionMenuItem(); 25 26 … … 29 30 30 31 private: 31 Action* action; //!< this action will be called when the trigger matches32 const std::string ActionName; //!< this action will be called when the trigger matches 32 33 }; 33 34 -
src/UIElements/Menu/TextMenu/DisplayMenuItem.cpp
r5813ac rb59da6 23 23 #include <cmath> 24 24 25 #include "Menu/ DisplayMenuItem.hpp"25 #include "Menu/TextMenu/DisplayMenuItem.hpp" 26 26 #include "Views/StringView.hpp" 27 27 28 28 29 DisplayMenuItem::DisplayMenuItem( Menu*_menu, StringView *_view):29 DisplayMenuItem::DisplayMenuItem(TxMenu* const _menu, StringView *_view): 30 30 MenuItem('\0',"",_menu), 31 31 view(_view), … … 34 34 } 35 35 36 DisplayMenuItem::DisplayMenuItem( Menu* _menu, StringView *_view, string_title, char _spacer, int _length ):36 DisplayMenuItem::DisplayMenuItem(TxMenu* const _menu, StringView *_view, const std::string &_title, char _spacer, int _length ): 37 37 MenuItem('\0',"",_menu), 38 38 view(_view), … … 52 52 } 53 53 54 const st ring DisplayMenuItem::formatEntry(){55 st ringstream s;54 const std::string DisplayMenuItem::formatEntry(){ 55 std::stringstream s; 56 56 if(title.length()>0) { 57 57 int pre = floor((length-title.length())/2.0); … … 69 69 70 70 71 const st ring DisplayMenuItem::getDescription(){72 return st ring("");71 const std::string DisplayMenuItem::getDescription(){ 72 return std::string(""); 73 73 } -
src/UIElements/Menu/TextMenu/DisplayMenuItem.hpp
r5813ac rb59da6 9 9 #define DISPLAYMENUITEM_HPP_ 10 10 11 #include "Menu/MenuItem.hpp" 11 #include <string> 12 13 #include "Menu/TextMenu/MenuItem.hpp" 12 14 #include "defs.hpp" 13 15 14 16 class StringView; 17 class TxMenu; 15 18 16 19 /** … … 22 25 { 23 26 public: 24 DisplayMenuItem( Menu*_menu, StringView *_view);25 DisplayMenuItem( Menu* _menu, StringView *_view, string_title,27 DisplayMenuItem(TxMenu* const _menu, StringView *_view); 28 DisplayMenuItem(TxMenu* const _menu, StringView *_view, const std::string &_title, 26 29 char _spacer=STD_MENU_TITLE_SPACER, int _length=STD_MENU_LENGTH); 27 30 virtual ~DisplayMenuItem(); … … 30 33 virtual bool checkTrigger(char); 31 34 32 virtual const st ring formatEntry();35 virtual const std::string formatEntry(); 33 36 34 virtual const st ring getDescription();37 virtual const std::string getDescription(); 35 38 36 39 private: 37 40 StringView *view; 38 st ring title;41 std::string title; 39 42 int length; 40 43 char spacer; -
src/UIElements/Menu/TextMenu/MenuItem.cpp
r5813ac rb59da6 20 20 #include "Helpers/MemDebug.hpp" 21 21 22 #include "Menu/MenuItem.hpp" 22 #include "Menu/TextMenu/MenuItem.hpp" 23 #include "Menu/TextMenu/TxMenu.hpp" 23 24 #include "Menu/Menu.hpp" 24 25 #include <sstream> 25 #include <iostream>26 26 27 27 /** … … 29 29 * The MenuItem is then added to the menu passed to it. 30 30 */ 31 MenuItem::MenuItem(char _trigger, const char* _description,Menu*menu) :31 MenuItem::MenuItem(char _trigger, const std::string &_description,TxMenu* const menu) : 32 32 trigger(_trigger), 33 description(_description), 33 34 added(false) 34 35 { 35 description = new string(_description);36 36 add_to_menu(menu); 37 37 } 38 38 39 39 MenuItem::~MenuItem() 40 { 41 delete description; 42 } 40 {} 43 41 44 42 /** … … 59 57 } 60 58 61 const st ring MenuItem::getDescription() {62 return *description;59 const std::string MenuItem::getDescription() { 60 return description; 63 61 } 64 62 … … 67 65 * Normal format is: "<trigger> - <description>" 68 66 */ 69 const st ring MenuItem::formatEntry(){70 st ringstream s;67 const std::string MenuItem::formatEntry(){ 68 std::stringstream s; 71 69 s << getTrigger() << " - " << getDescription(); 72 70 … … 80 78 * TODO: include funtionality to move Items from one menu to another 81 79 */ 82 void MenuItem::add_to_menu( Menu*menu) {80 void MenuItem::add_to_menu(TxMenu* const menu) { 83 81 if(!wasAdded()) { 84 82 menu->addItem(this); -
src/UIElements/Menu/TextMenu/MenuItem.hpp
r5813ac rb59da6 11 11 #include <string> 12 12 13 using namespace std; 14 15 class Menu; 13 class TxMenu; 16 14 17 15 /** … … 22 20 class MenuItem { 23 21 public: 24 MenuItem(char,const char*,Menu*);22 MenuItem(char,const std::string &,TxMenu* const); 25 23 virtual ~MenuItem(); 26 24 … … 28 26 virtual bool checkTrigger(char); 29 27 30 virtual const st ring formatEntry();28 virtual const std::string formatEntry(); 31 29 32 virtual const st ring getDescription();30 virtual const std::string getDescription(); 33 31 char getTrigger(); 34 32 35 void add_to_menu( Menu*);33 void add_to_menu(TxMenu* const); 36 34 bool wasAdded(); 37 35 38 36 virtual bool isActive(); 39 37 40 protected:41 void setDescription(string);42 43 38 private: 44 39 char trigger; 45 string *description;40 const std::string description; 46 41 bool added; 47 42 }; -
src/UIElements/Menu/TextMenu/SeperatorItem.cpp
r5813ac rb59da6 23 23 #include <sstream> 24 24 25 #include "Menu/SeperatorItem.hpp" 26 #include "Menu/Menu.hpp" 25 #include "Menu/TextMenu/SeperatorItem.hpp" 27 26 #include "defs.hpp" 28 27 29 28 30 SeperatorItem::SeperatorItem( Menu*menu):29 SeperatorItem::SeperatorItem(TxMenu* const menu): 31 30 MenuItem('\0',"",menu), 32 31 spacer(STD_SEPERATOR_SPACER), … … 37 36 } 38 37 39 SeperatorItem::SeperatorItem( Menu*menu,char _spacer, int _length):38 SeperatorItem::SeperatorItem(TxMenu* const menu,char _spacer, int _length): 40 39 MenuItem('\0',"",menu), 41 40 spacer(_spacer), … … 57 56 } 58 57 59 const st ring SeperatorItem::getDescription() {60 return st ring("");58 const std::string SeperatorItem::getDescription() { 59 return std::string(""); 61 60 } 62 61 63 const st ring SeperatorItem::formatEntry(){64 st ringstream s;62 const std::string SeperatorItem::formatEntry(){ 63 std::stringstream s; 65 64 for(int i=0; i<length;i++) 66 65 s << spacer; -
src/UIElements/Menu/TextMenu/SeperatorItem.hpp
r5813ac rb59da6 9 9 #define SEPERATORITEM_H_ 10 10 11 #include "Menu/MenuItem.hpp" 11 #include <string> 12 13 #include "Menu/TextMenu/MenuItem.hpp" 14 15 class TxMenu; 12 16 13 17 /** … … 19 23 { 20 24 public: 21 SeperatorItem( Menu*);22 SeperatorItem( Menu*,char,int);25 SeperatorItem(TxMenu* const ); 26 SeperatorItem(TxMenu* const ,char,int); 23 27 virtual ~SeperatorItem(); 24 28 … … 26 30 virtual bool checkTrigger(char); 27 31 28 virtual const st ring getDescription();32 virtual const std::string getDescription(); 29 33 30 virtual const st ring formatEntry();34 virtual const std::string formatEntry(); 31 35 private: 32 36 char spacer; -
src/UIElements/Menu/TextMenu/SubMenuItem.cpp
r5813ac rb59da6 20 20 #include "Helpers/MemDebug.hpp" 21 21 22 #include "SubMenuItem.hpp"22 #include <iostream> 23 23 24 SubMenuItem::SubMenuItem(char _trigger,const char* _description,Menu* _parent, Menu* _theMenu) : 24 #include "Menu/TextMenu/SubMenuItem.hpp" 25 #include "Menu/TextMenu/TxMenu.hpp" 26 27 SubMenuItem::SubMenuItem(char _trigger,const std::string &_description,TxMenu* const _parent, TxMenu* const _instance) : 25 28 MenuItem(_trigger,_description,_parent), 26 theMenu(_theMenu) 27 { 28 } 29 theMenu(_instance) 30 {} 29 31 30 32 SubMenuItem::~SubMenuItem() 31 { 32 delete theMenu; 33 } 33 {} 34 34 35 35 void SubMenuItem::doTrigger() { -
src/UIElements/Menu/TextMenu/TxMenu.cpp
r5813ac rb59da6 7 7 8 8 /* 9 * T extMenu.cpp9 * TxMenu.cpp 10 10 * 11 11 * Created on: Dec 10, 2009 … … 21 21 22 22 #include <boost/bind.hpp> 23 #include <algorithm> 23 24 #include <iostream> 24 25 #include <cmath> 25 #include "Menu/TextMenu.hpp" 26 #include "Menu/MenuItem.hpp" 26 #include "Actions/Action.hpp" 27 #include "Actions/ActionTraits.hpp" 28 #include "Menu/TextMenu/TxMenu.hpp" 29 #include "Menu/TextMenu/MenuItem.hpp" 27 30 #include "Helpers/Assert.hpp" 28 31 … … 32 35 * The text will later be displayed using the stream passed to the constructor. 33 36 */ 34 T extMenu::TextMenu(ostream& _outputter, conststring _title, char _spacer,int _length) :37 TxMenu::TxMenu(std::ostream& _outputter, const std::string _title, char _spacer,int _length) : 35 38 defaultItem(0), 36 39 outputter(_outputter), … … 42 45 } 43 46 44 T extMenu::~TextMenu()47 TxMenu::~TxMenu() 45 48 { 46 for( list<MenuItem*>::iterator it=items.begin(); it != items.end(); it++)49 for(std::list<MenuItem*>::iterator it=items.begin(); it != items.end(); it++) 47 50 delete (*it); 48 51 } 49 52 50 51 void TextMenu::addItem(MenuItem* item) { 53 void TxMenu::addItem(MenuItem* item) { 52 54 items.push_back(item); 53 55 } 54 56 55 void T extMenu::removeItem(MenuItem* item) {57 void TxMenu::removeItem(MenuItem* item) { 56 58 items.remove(item); 57 59 } 58 60 59 void T extMenu::doQuit(){61 void TxMenu::doQuit(){ 60 62 quit = true; 61 63 } 62 64 63 bool T extMenu::hasQuit(){65 bool TxMenu::hasQuit(){ 64 66 return quit; 65 67 } 66 68 67 void T extMenu::showEntry(MenuItem* entry){69 void TxMenu::showEntry(MenuItem* entry){ 68 70 if(entry->isActive()==false){ 69 71 outputter << "("; … … 76 78 } 77 79 78 void T extMenu::display() {80 void TxMenu::display() { 79 81 char choice; 80 82 bool somethingChosen = false; … … 89 91 outputter << spacer; 90 92 outputter << '\n'; 91 for_each(items.begin(), items.end(), boost::bind(&T extMenu::showEntry,this,_1));93 for_each(items.begin(), items.end(), boost::bind(&TxMenu::showEntry,this,_1)); 92 94 outputter.flush(); 93 95 94 cin >> choice;96 std::cin >> choice; 95 97 96 list<MenuItem*>::iterator iter;98 std::list<MenuItem*>::iterator iter; 97 99 for(iter = items.begin(); iter!=items.end();iter++){ 98 100 if((*iter)->isActive()){ … … 106 108 } 107 109 else{ 108 outputter << "Invalid Choice!" << endl;110 outputter << "Invalid Choice!" << std::endl; 109 111 } 110 112 } … … 112 114 } 113 115 114 st ring TextMenu::getTitle(){116 std::string TxMenu::getTitle(){ 115 117 return title; 116 118 } 117 119 118 void TextMenu::addDefault(MenuItem* _defaultItem) { 120 std::ostream& TxMenu::getOutputter() 121 { 122 return outputter; 123 } 124 125 126 void TxMenu::addDefault(MenuItem* _defaultItem) { 119 127 defaultItem = _defaultItem; 120 128 } … … 122 130 /****************************** Contained Actions ****************/ 123 131 124 T extMenu::LeaveAction::LeaveAction(TextMenu*_menu, const ActionTraits & LeaveActionTrait) :125 Action(LeaveActionTrait, false),132 TxMenu::LeaveAction::LeaveAction(TxMenu* const _menu, const ActionTraits & LeaveActionTrait) : 133 Action(LeaveActionTrait, true), 126 134 menu(_menu) 127 135 {} 128 136 129 T extMenu::LeaveAction::~LeaveAction(){}137 TxMenu::LeaveAction::~LeaveAction(){} 130 138 131 bool T extMenu::LeaveAction::canUndo(){139 bool TxMenu::LeaveAction::canUndo(){ 132 140 return false; 133 141 } 134 142 135 bool T extMenu::LeaveAction::shouldUndo(){143 bool TxMenu::LeaveAction::shouldUndo(){ 136 144 return false; 137 145 } 138 146 139 void T extMenu::LeaveAction::getParametersfromValueStorage()147 void TxMenu::LeaveAction::getParametersfromValueStorage() 140 148 {} 141 149 142 Dialog* T extMenu::LeaveAction::fillDialog(Dialog *dialog){150 Dialog* TxMenu::LeaveAction::fillDialog(Dialog *dialog){ 143 151 ASSERT(dialog,"No Dialog given when filling action dialog"); 144 152 return dialog; … … 146 154 147 155 148 Action::state_ptr T extMenu::LeaveAction::performCall(){156 Action::state_ptr TxMenu::LeaveAction::performCall(){ 149 157 menu->doQuit(); 150 158 return Action::success; … … 152 160 153 161 154 Action::state_ptr T extMenu::LeaveAction::performUndo(Action::state_ptr){162 Action::state_ptr TxMenu::LeaveAction::performUndo(Action::state_ptr){ 155 163 ASSERT(0,"Cannot undo leaving a menu"); 156 164 return Action::success; 157 165 } 158 166 159 Action::state_ptr T extMenu::LeaveAction::performRedo(Action::state_ptr){167 Action::state_ptr TxMenu::LeaveAction::performRedo(Action::state_ptr){ 160 168 ASSERT(0,"Cannot redo leaving a menu"); 161 169 return Action::success; -
src/UIElements/Menu/TextMenu/TxMenu.hpp
r5813ac rb59da6 1 1 /* 2 * T extMenu.h2 * TxMenu.h 3 3 * 4 4 * Created on: Dec 10, 2009 … … 6 6 */ 7 7 8 #ifndef T EXTMENU_H_9 #define T EXTMENU_H_8 #ifndef TXMENU_H_ 9 #define TXMENU_H_ 10 10 11 11 #include <list> … … 25 25 * All Items are displayed and user is prompted for a key. The item corresponding to that key is then activated. 26 26 */ 27 class T extMenu : publicMenu27 class TxMenu 28 28 { 29 29 public: 30 30 class LeaveAction : public Action { 31 31 public: 32 LeaveAction(T extMenu*, const ActionTraits &_trait);32 LeaveAction(TxMenu* const, const ActionTraits &_trait); 33 33 virtual ~LeaveAction(); 34 34 … … 44 44 virtual Action::state_ptr performRedo(Action::state_ptr); 45 45 46 ActionTraits *LeaveActionTrait; 47 TextMenu* menu; 46 TxMenu* const menu; 48 47 }; 49 48 50 T extMenu(ostream& _outputter, conststring _title, char _spacer=STD_MENU_TITLE_SPACER,int _length=STD_MENU_LENGTH);51 virtual ~T extMenu();49 TxMenu(std::ostream& _outputter, const std::string _title, char _spacer=STD_MENU_TITLE_SPACER,int _length=STD_MENU_LENGTH); 50 virtual ~TxMenu(); 52 51 53 virtual void addItem(MenuItem*); 54 virtual void removeItem(MenuItem*); 55 virtual void display(); 56 virtual string getTitle(); 52 void addItem(MenuItem*); 53 void removeItem(MenuItem*); 54 void display(); 55 std::string getTitle(); 56 std::ostream& getOutputter(); 57 char getSuitableShortForm(std::set <char> &ShortcutList, const std::string name) const; 57 58 58 59 /** 59 60 * Call doQuit if you want to return from this menu. 60 61 */ 61 v irtual void doQuit();62 void doQuit(); 62 63 /** 63 64 * Check whether someone has chosen to quit 64 65 */ 65 virtualbool hasQuit();66 bool hasQuit(); 66 67 67 v irtual void addDefault(MenuItem*);68 void addDefault(MenuItem*); 68 69 69 70 protected: 70 v irtual void showEntry(MenuItem*);71 void showEntry(MenuItem*); 71 72 72 73 private: 73 list<MenuItem*> items;74 std::list<MenuItem*> items; 74 75 75 76 MenuItem* defaultItem; 76 77 77 ostream& outputter;78 st ring title;78 std::ostream& outputter; 79 std::string title; 79 80 char spacer; 80 81 int length; … … 83 84 }; 84 85 85 #endif /* T EXTMENU_H_ */86 #endif /* TXMENU_H_ */ -
src/UIElements/Qt4/QtMainWindow.cpp
r5813ac rb59da6 39 39 #include "Actions/ActionRegistry.hpp" 40 40 #include "Actions/ValueStorage.hpp" 41 #include "Menu/MenuDescription.hpp"42 #include "Menu/Menu.hpp"43 41 #include "Menu/Qt4/QtMenu.hpp" 44 #include "Menu/ActionMenuItem.hpp"45 #include "Menu/SubMenuItem.hpp"46 42 #include "Views/Qt4/QtWorldView.hpp" 47 43 #include "Views/Qt4/GLMoleculeView.hpp" … … 60 56 molecule3dDisplay = new GLMoleculeView(); 61 57 62 MenuBar = menuBar(); 63 64 // populate menus and add actions 65 { 66 QtMenuReferenceMap NametoTextMenuMap; // contains token to menu reference map 67 MenuShortcutMap ShortcutMap; 68 populateMenu(NametoTextMenuMap, ShortcutMap); 69 populateMenuWithActions(NametoTextMenuMap, ShortcutMap); 70 } 58 MainMenu = new QtMenu<QMenuBar>(menuBar(), ""); 59 MainMenu->init(); 71 60 72 61 setCentralWidget(splitter1); … … 93 82 } 94 83 95 /** Puts Qt's token, the ampersand, in front of the accelerator char in the menu name.96 * \param ShortcutMap map to all already present accelerator keys97 * \param MenuName Action of menu98 * \param ActionName Action of menu99 * \return name with ampersand added at the right place100 */101 std::string QtMainWindow::getNameWithAccelerator(MenuShortcutMap &ShortcutMap, const std::string &MenuName, const std::string &ActionName) const102 {103 std::string newname;104 bool Inserted = false;105 std::pair < MenuShortcutMap::iterator, bool > Inserter;106 for (std::string::const_iterator CharRunner = ActionName.begin(); CharRunner != ActionName.end(); ++CharRunner) {107 if (!Inserted) {108 Inserter = ShortcutMap.insert( std::pair<std::string, char> (MenuName, *CharRunner) );109 if (Inserter.second) {110 newname += '&';111 Inserted = true;112 }113 }114 newname += *CharRunner;115 }116 return newname;117 }118 119 /** Instantiate all menus.120 * \param NametoTextMenuMap lookup for token to menu reference121 */122 void QtMainWindow::populateMenu(QtMenuReferenceMap &NametoTextMenuMap, MenuShortcutMap &ShortcutMap)123 {124 // go through all menus and create them125 std::map <std::string, int> TopPositions;126 TopPositions.insert( std::pair<std::string, int> ("", 0) ); // contains which position was added last127 QtMenu *Menu = NULL;128 MenuDescription menudescriptions;129 std::set <char> ShortcutList;130 bool CompleteFlag = false;131 while (!CompleteFlag) {132 CompleteFlag = true;133 for(MenuDescription::const_iterator iter = menudescriptions.getBeginIter(); iter != menudescriptions.getEndIter(); ++iter) {134 // skip when already present135 if (NametoTextMenuMap.find(iter->first) == NametoTextMenuMap.end()) {136 // have some short refs to infos137 const std::string &MenuName = iter->first;138 const std::string &TopName = iter->second.first;139 const int &MenuPosition = iter->second.second;140 std::cout << "MenuName is " << MenuName << ", TopName is " << TopName << " and Position is " << MenuPosition << std::endl;141 142 // is it top level?143 if (TopName == "") {144 ASSERT(TopPositions.find(TopName) != TopPositions.end(),145 "QtMainWindow::QtMainWindow() - "+TopName+" not present in TopPositions.");146 if (MenuPosition-1 == TopPositions[TopName]) {147 std::cout << "Creating top-level menu " << MenuName << " at position " << MenuPosition << std::endl;148 Menu = new QtMenu(getNameWithAccelerator(ShortcutMap, TopName, MenuName).c_str());149 MenuBar->addMenu(Menu);150 NametoTextMenuMap.insert( pair <std::string, QtMenu *> (MenuName, Menu) );151 CompleteFlag = false;152 TopPositions[TopName] = MenuPosition;153 TopPositions[MenuName] = 0;154 }155 }156 // is it a submenu and the top-level menu is present?157 else if (NametoTextMenuMap.find(TopName) != NametoTextMenuMap.end()) {158 ASSERT(TopPositions.find(TopName) != TopPositions.end(),159 "QtMainWindow::QtMainWindow() - "+TopName+" not present in TopPositions.");160 if (MenuPosition-1 == TopPositions[TopName]) {161 QtMenu *& TopMenu = NametoTextMenuMap[TopName];162 std::cout << "Creating submenu " << MenuName << " to menu " << TopName << " at position " << MenuPosition << std::endl;163 Menu = new QtMenu(getNameWithAccelerator(ShortcutMap, TopName, MenuName).c_str());164 TopMenu->addMenu(Menu);165 NametoTextMenuMap.insert( pair <std::string, QtMenu *> (MenuName, Menu) );166 CompleteFlag = false;167 TopPositions[TopName] = MenuPosition;168 }169 }170 }171 }172 }173 }174 175 /** Instantiate all actions within the menus.176 * \param NametoTextMenuMap lookup for token to menu reference177 * \param ShortcutMap map for all shortcuts within one menu178 */179 void QtMainWindow::populateMenuWithActions(QtMenuReferenceMap &NametoTextMenuMap, MenuShortcutMap &ShortcutMap)180 {181 typedef std::multimap <std::string, std::string> MenuMap;182 183 // go through all menus184 MenuDescription md;185 MenuMap MenuItems = md.getMenuItemsMap();186 QtMenu *Menu = NULL;187 Action *ActionItem = NULL;188 std::string OldMenuName;189 for (MenuMap::const_iterator MenuRunner = MenuItems.begin(); MenuRunner != MenuItems.end(); ++MenuRunner) {190 const std::string &ActionName = MenuRunner->second;191 const std::string &MenuName = MenuRunner->first;192 // add the actions to this menu193 std::cout << " Adding " << ActionName << " to submenu " << MenuName << std::endl;194 ActionItem = ActionRegistry::getInstance().getActionByName(ActionName);195 ASSERT(NametoTextMenuMap.find(MenuName) != NametoTextMenuMap.end(),196 "QtMainWindow::populateMenu() - cannot find reference for menu "+MenuName+" in NametoTextMenuMap.");197 Menu = NametoTextMenuMap[MenuName];198 //ASSERT(ShortcutMap.find(MenuName) != ShortcutMap.end(),199 // "QtMainWindow::populateMenuWithActions() - missing "+MenuName+" in ShortcutMap.");200 new ActionMenuItem(201 'a',202 ActionItem->Traits.getDescription().c_str(),203 Menu,204 ActionItem);205 }206 } -
src/UIElements/Qt4/QtMainWindow.hpp
r5813ac rb59da6 15 15 #include <set> 16 16 17 #include "Menu/Qt4/QtMenu.hpp" 18 17 19 class QtWorldView; 18 20 class StringView; 19 class QtMenu;20 21 class GLMoleculeView; 21 22 class QtMoleculeView; … … 34 35 35 36 private: 36 typedef std::map <std::string, QtMenu *> QtMenuReferenceMap;37 typedef std::map <std::string, char> MenuShortcutMap;38 39 void populateMenu(QtMenuReferenceMap &NametoTextMenuMap, MenuShortcutMap &ShortcutMap);40 void populateMenuWithActions(QtMenuReferenceMap &NametoTextMenuMap, MenuShortcutMap &ShortcutMap);41 std::string getNameWithAccelerator(MenuShortcutMap &ShortcutMap, const std::string &MenuName, const std::string &ActionName) const;42 43 37 // All kinds of QTStuff used in this window 44 38 QApplication *theApp; … … 47 41 QtMoleculeView *moleculeDisplay; 48 42 QtStatusBar *statusBar; 49 Q MenuBar *MenuBar;43 QtMenu<QMenuBar> *MainMenu; 50 44 51 45 }; -
src/UIElements/TextUI/TextWindow.cpp
r5813ac rb59da6 23 23 #include <boost/shared_ptr.hpp> 24 24 25 #include "Menu/Menu.hpp" 26 #include "Menu/MenuDescription.hpp" 27 #include "Menu/TextMenu.hpp" 28 #include "Menu/ActionMenuItem.hpp" 29 #include "Menu/SeperatorItem.hpp" 30 #include "Menu/DisplayMenuItem.hpp" 31 #include "Menu/SubMenuItem.hpp" 25 #include "Menu/TextMenu/TextMenu.hpp" 26 #include "Menu/TextMenu/TxMenu.hpp" 27 #include "Menu/TextMenu/ActionMenuItem.hpp" 28 #include "Menu/TextMenu/SeperatorItem.hpp" 29 #include "Menu/TextMenu/DisplayMenuItem.hpp" 30 #include "Menu/TextMenu/SubMenuItem.hpp" 32 31 #include "TextUI/TextStatusIndicator.hpp" 33 32 #include "TextUI/TextWindow.hpp" … … 57 56 TextWindow::TextWindow() 58 57 { 59 map <std::string, TextMenu *> NametoTextMenuMap;60 std::set <char> ShortcutList;58 // build the main menu 59 main_menu = new TextMenu<TxMenu>(std::cout, ""); 61 60 // reserve s for save and q for quite 62 ShortcutList.insert('s'); 63 ShortcutList.insert('q'); 64 65 // build the main menu 66 main_menu = new TextMenu(Log() << Verbose(0), "Main Menu"); 61 main_menu->reserveShortcut('s', "output"); 62 main_menu->reserveShortcut('q', "quit"); 67 63 68 64 moleculeView = new StreamStringView(boost::bind(&MoleculeListClass::Enumerate,World::getInstance().getMolecules(),_1)); 69 new DisplayMenuItem(main_menu ,moleculeView,"Molecule List");65 new DisplayMenuItem(main_menu->getMenuInstance(),moleculeView,"Molecule List"); 70 66 71 new SeperatorItem(main_menu );67 new SeperatorItem(main_menu->getMenuInstance()); 72 68 73 Action* undoAction = ActionRegistry::getInstance().getActionByName("undo"); 74 new ActionMenuItem(getSuitableShortForm(ShortcutList,"Undo last operation"),"Undo last operation",main_menu,undoAction); 69 main_menu->init(); 75 70 76 Action* redoAction = ActionRegistry::getInstance().getActionByName("redo"); 77 new ActionMenuItem(getSuitableShortForm(ShortcutList,"Redo last operation"),"Redo last operation",main_menu,redoAction); 78 79 new SeperatorItem(main_menu); 80 81 MenuDescription menudescriptions; 82 for(MenuDescription::const_iterator iter = menudescriptions.getBeginIter(); iter != menudescriptions.getEndIter(); ++iter) { 83 const std::string &MenuName = iter->first; 84 TextMenu *Menu = new TextMenu((ostream &)std::cout, menudescriptions.getDescription(MenuName)); 85 NametoTextMenuMap.insert( pair <std::string, TextMenu *> (MenuName, Menu) ); 86 new SubMenuItem(getSuitableShortForm(ShortcutList,MenuName),menudescriptions.getDescription(MenuName).c_str(),main_menu,Menu); 87 } 88 89 new SeperatorItem(main_menu); 71 new SeperatorItem(main_menu->getMenuInstance()); 90 72 91 73 // save has reserved key 's' 92 Action *saveConfigAction = ActionRegistry::getInstance().getActionByName("output");93 new ActionMenuItem('s',"save current setup to config files",main_menu ,saveConfigAction);74 // Action *saveConfigAction = ActionRegistry::getInstance().getActionByName("output"); 75 new ActionMenuItem('s',"save current setup to config files",main_menu->getMenuInstance(),"output"); 94 76 95 ActionTraits quitTrait(OptionTrait("quitAction", &typeid(void), "quits the program")); 96 quitAction = new MethodAction(quitTrait,boost::bind(&TextMenu::doQuit,main_menu),false); 97 new ActionMenuItem('q',"quit",main_menu,quitAction); 98 99 // quit has reserved key 'q' 100 // go through all menus and create them 101 for (map <std::string, TextMenu *>::iterator MenuRunner = NametoTextMenuMap.begin(); MenuRunner != NametoTextMenuMap.end(); ++MenuRunner) 102 populateMenu(MenuRunner->second, MenuRunner->first); 77 // create a specific quit action for this UI and store in registry 78 ActionTraits quitTrait(OptionTrait("quit", &typeid(void), "quits the program")); 79 quitAction = new MethodAction(quitTrait,boost::bind(&TxMenu::doQuit,main_menu->getMenuInstance()),true); 80 new ActionMenuItem('q',"quit",main_menu->getMenuInstance(),"quit"); 103 81 104 82 // Add status indicators etc... 105 106 83 statusIndicator = new TextStatusIndicator(); 107 84 } … … 122 99 } 123 100 124 char TextWindow::getSuitableShortForm(std::set <char> &ShortcutList, const std::string name) const125 {126 for (std::string::const_iterator CharRunner = name.begin(); CharRunner != name.end(); ++CharRunner) {127 if (ShortcutList.find(*CharRunner) == ShortcutList.end()) {128 ShortcutList.insert(*CharRunner);129 return *CharRunner;130 }131 }132 // if no letter matches, take digits133 int i=0;134 for (;i<10;++i) {135 if (ShortcutList.find((char)i + '0') == ShortcutList.end())136 break;137 }138 if (i != 10) {139 ShortcutList.insert((char)i + '0');140 return ((char)i + '0');141 } else {142 DoeLog(1) && (eLog() << Verbose(1) << "Could not find a suitable shortform for " << name << "." << endl);143 return '#';144 }145 }146 147 void TextWindow::populateMenu(TextMenu* Menu, const std::string &MenuName)148 {149 Action *ActionItem = NULL;150 set <char> ShortcutList;151 // reserve 'q' for quit152 ShortcutList.insert('q');153 // through all actions for this menu154 MenuDescription md;155 std::multimap <std::string, std::string> MenuItems = md.getMenuItemsMap();156 std::pair < std::multimap <std::string, std::string>::iterator, std::multimap <std::string, std::string>::iterator > MenuActions = MenuItems.equal_range(MenuName);157 for (std::multimap <std::string, std::string>::const_iterator MenuRunner = MenuActions.first; MenuRunner != MenuActions.second; ++MenuRunner) {158 ActionItem = ActionRegistry::getInstance().getActionByName(MenuRunner->second);159 new ActionMenuItem(getSuitableShortForm(ShortcutList, MenuRunner->second),ActionItem->Traits.getDescription().c_str(),Menu,ActionItem);160 }161 // finally add default quit item162 ActionTraits LeaveActionTraits("Leave menu: "+Menu->getTitle());163 Action *returnFromAction = new TextMenu::LeaveAction(Menu, LeaveActionTraits);164 //returnFromActions.push_back(returnFromAction);165 MenuItem *returnFromItem = new ActionMenuItem('q',"return to Main menu",Menu,returnFromAction);166 Menu->addDefault(returnFromItem);167 } -
src/UIElements/TextUI/TextWindow.hpp
r5813ac rb59da6 14 14 #include <set> 15 15 16 class TextMenu; 16 #include "Menu/TextMenu/TextMenu.hpp" 17 17 18 class Action; 18 19 class StringView; 19 20 class TextStatusIndicator; 21 class TxMenu; 20 22 21 23 … … 29 31 30 32 private: 31 // populaters 32 char getSuitableShortForm(std::set <char> &ShortcutList, const std::string name) const; 33 void populateMenu(TextMenu* Menu, const std::string &name); 34 35 TextMenu *main_menu; 33 TextMenu<TxMenu> *main_menu; 36 34 37 35 // some actions only needed in textMenus -
src/builder.cpp
r5813ac rb59da6 90 90 #include "UIElements/MainWindow.hpp" 91 91 #include "UIElements/Dialog.hpp" 92 #include "Menu/ActionMenuItem.hpp"92 //#include "Menu/ActionMenuItem.hpp" 93 93 #include "Helpers/Verbose.hpp" 94 94 #include "World.hpp"
Note:
See TracChangeset
for help on using the changeset viewer.