Ignore:
Timestamp:
Dec 4, 2010, 11:33:47 PM (14 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

Refactoring of Menu structure for Qt and Text UI done.

  • Menu is now the initialising class for the menu structure.
  • MenuInterface contains virtual declarations of all functions that Menu needs to call.
  • TextMenu and QtMenu are templated classes which contain both Menu and MenuInterface and implement the virtual functions.
  • class TxMenu and its ...MenuItems contain most of the old Menu code for the text-based system. Most of the stuff, such as triggers, are now hidden internally.
  • in ..MainWindow() we basically just construct the desired Menu and call init at the correct time.
Location:
src/UIElements/Menu/Qt4
Files:
2 added
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Menu/Qt4/QtMenu.hpp

    r5813ac rb59da6  
    22 * QtMenu.hpp
    33 *
    4  *  Created on: Jan 15, 2010
    5  *      Author: crueger
     4 *  Created on: Nov 5, 2010
     5 *      Author: heber
    66 */
    77
    8 #ifndef QTMENU_HPP_
    9 #define QTMENU_HPP_
     8#ifndef MENUINTERFACEQT_HPP_
     9#define MENUINTERFACEQT_HPP_
    1010
     11#include <Qt/qaction.h>
     12
     13#include <iostream>
    1114#include <list>
    12 
    13 #include <QtGui/QMenu>
    14 #include <QtCore/QObject>
     15#include <map>
     16#include <string>
    1517
    1618#include "Menu/Menu.hpp"
     19#include "Menu/MenuInterface.hpp"
     20#include "Menu/Qt4/QtMenuPipe.hpp"
    1721
    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 */
     26template <class T>
     27class QtMenu : virtual public MenuInterface, public Menu
     28{
     29public:
     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  {}
    1936
    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  {}
    2343
    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);
    2748
    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
     58protected:
     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
    3190private:
    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
    33117};
    34118
    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_ */
Note: See TracChangeset for help on using the changeset viewer.