Salome HOME
Parameters manager implementation
[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 viewer
65   void updateViewerMenu();
66
67 signals:
68   /// Signal aabout triggered action
69   /// \param theId an id of triggered action
70   /// \param isChecked is checked flag
71   void actionTriggered(const QString& theId, bool isChecked);
72
73   /// A signal which is sent before context menu show
74   void beforeContextMenu();
75
76   /// A signal which is sent after context menu show
77   void afterContextMenu();
78
79  private slots:
80    /// Process action event
81    /// \param isChecked a checked action flag
82   void onAction(bool isChecked);
83
84   /// Process context menu event
85   /// \param theEvent a context menu event
86   void onContextMenuRequest(QContextMenuEvent* theEvent);
87
88   void onRename();
89
90  private:
91   /** 
92    * Add action
93    * \param theId - string ID of the item
94    * \param theAction - action to add
95    */
96   void addAction(const QString& theId, QAction* theAction);
97
98   void addFeatures(QMenu* theMenu) const;
99
100   /// Updates menu for object browser
101   void updateObjectBrowserMenu();
102
103   /// Creates menu for object browser
104   void buildObjBrowserMenu();
105
106   /// Creates menu for viewer
107   void buildViewerMenu();
108
109   /// Map of created actions [id : Action]
110   QMap<QString, QAction*> myActions;
111
112   /// Reference to workshop
113   XGUI_Workshop* myWorkshop;
114
115   typedef QList<QAction*> QActionsList;
116   QMap<std::string, QActionsList> myObjBrowserMenus;
117   QMap<std::string, QActionsList> myViewerMenu;
118
119   QActionGroup* mySelectActions;
120
121   QAction* mySeparator;
122 };
123
124 #endif