Salome HOME
Updated translation files
[modules/shaper.git] / src / XGUI / XGUI_ContextMenuMgr.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #ifndef XGUI_ContextMenuMgr_H
4 #define XGUI_ContextMenuMgr_H
5
6 #include "XGUI.h"
7
8 #include <QObject>
9 #include <QMap>
10
11 class XGUI_Workshop;
12 class QAction;
13 class QContextMenuEvent;
14 class QMenu;
15 class QActionGroup;
16
17 /**
18  * \ingroup GUI
19  * A claas wihich provides manement of context menu
20  */
21 class XGUI_EXPORT XGUI_ContextMenuMgr : public QObject
22 {
23 Q_OBJECT
24  public:
25    /// Constructor
26    /// \param theParent a parent object
27   XGUI_ContextMenuMgr(XGUI_Workshop* theParent);
28   virtual ~XGUI_ContextMenuMgr();
29
30   /// Create all actions for context menus. It is called on creation of application
31   void createActions();
32
33   /// Returns action according to the given ID
34   /// \param theId an id of an action
35   QAction* action(const QString& theId) const;
36
37   /// Returns action object by its Id (name)
38   /// \param theName is an Id of the action
39   QAction* actionByName(const QString& theName) const;
40
41   /// Returns list of registered actions Ids
42   QStringList actionIds() const;
43
44   /// update state of internal commands
45   void updateCommandsStatus();
46
47   /// Connect to object browser from workshop. Has to called at creation of viewer.
48   void connectObjectBrowser();
49
50   /// Connect to viewer from workshop. Has to called at creation of viewer.
51   void connectViewer();
52
53   /// Add menu items for Object browser pop-up
54   void addObjBrowserMenu(QMenu*) const;
55
56   /// Add menu items for Viewer pop-up
57   void addViewerMenu(QMenu*) const;
58
59   /// Returns a list of object group names of the action
60   /// \param theName a name of the action
61   /// \return a list of group names
62   QStringList actionObjectGroups(const QString& theName);
63
64   /// Updates menu for object browser
65   void updateObjectBrowserMenu();
66
67   /// Updates menu for viewer
68   void updateViewerMenu();
69
70 signals:
71   /// Signal aabout triggered action
72   /// \param theId an id of triggered action
73   /// \param isChecked is checked flag
74   void actionTriggered(const QString& theId, bool isChecked);
75
76   /// A signal which is sent before context menu show
77   void beforeContextMenu();
78
79   /// A signal which is sent after context menu show
80   void afterContextMenu();
81
82  private slots:
83    /// Process action event
84    /// \param isChecked a checked action flag
85   void onAction(bool isChecked);
86
87   /// Process context menu event
88   /// \param theEvent a context menu event
89   void onContextMenuRequest(QContextMenuEvent* theEvent);
90
91   void onRename();
92
93   /// Slot called on Result selection menu press
94   void onResultSelection(bool theChecked);
95
96   /// Slot called on any shape selection menu press
97   void onShapeSelection(bool theChecked);
98
99  private:
100   /** 
101    * Add action
102    * \param theId - string ID of the item
103    * \param theAction - action to add
104    */
105   void addAction(const QString& theId, QAction* theAction);
106
107   void addFeatures(QMenu* theMenu) const;
108
109   /// Creates menu for object browser
110   void buildObjBrowserMenu();
111
112   /// Creates menu for viewer
113   void buildViewerMenu();
114
115   /// Map of created actions [id : Action]
116   QMap<QString, QAction*> myActions;
117
118   /// Reference to workshop
119   XGUI_Workshop* myWorkshop;
120
121   typedef QList<QAction*> QActionsList;
122   QMap<std::string, QActionsList> myObjBrowserMenus;
123   QMap<std::string, QActionsList> myViewerMenu;
124
125   //QActionGroup* mySelectActions;
126
127   QAction* mySeparator;
128 };
129
130 #endif