Salome HOME
db0e71e8541c533142b3a9c49c337b4d66d95e64
[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
16 /**
17  * \ingroup GUI
18  * A claas wihich provides manement of context menu
19  */
20 class XGUI_EXPORT XGUI_ContextMenuMgr : public QObject
21 {
22 Q_OBJECT
23  public:
24    /// Constructor
25    /// \param theParent a parent object
26   XGUI_ContextMenuMgr(XGUI_Workshop* theParent);
27   virtual ~XGUI_ContextMenuMgr();
28
29   /// Create all actions for context menus. It is called on creation of application
30   void createActions();
31
32   /// Returns action according to the given ID
33   /// \param theId an id of an action
34   QAction* action(const QString& theId) const;
35
36   /// Returns action object by its Id (name)
37   /// \param theName is an Id of the action
38   QAction* actionByName(const QString& theName) const;
39
40   /// Returns list of registered actions Ids
41   QStringList actionIds() const;
42
43   /// update state of internal commands
44   void updateCommandsStatus();
45
46   /// Connect to object browser from workshop. Has to called at creation of viewer.
47   void connectObjectBrowser();
48
49   /// Connect to viewer from workshop. Has to called at creation of viewer.
50   void connectViewer();
51
52   void addObjBrowserMenu(QMenu*) const;
53   void addViewerMenu(QMenu*) const;
54
55   /// Returns a list of object group names of the action
56   /// \param theName a name of the action
57   /// \return a list of group names
58   QStringList actionObjectGroups(const QString& theName);
59
60   /// Updates menu for viewer
61   void updateViewerMenu();
62
63 signals:
64   /// Signal aabout triggered action
65   /// \param theId an id of triggered action
66   /// \param isChecked is checked flag
67   void actionTriggered(const QString& theId, bool isChecked);
68
69   /// A signal which is sent before context menu show
70   void beforeContextMenu();
71
72   /// A signal which is sent after context menu show
73   void afterContextMenu();
74
75  private slots:
76    /// Process action event
77    /// \param isChecked a checked action flag
78   void onAction(bool isChecked);
79
80   /// Process context menu event
81   /// \param theEvent a context menu event
82   void onContextMenuRequest(QContextMenuEvent* theEvent);
83
84   void onRename();
85
86  private:
87   /** 
88    * Add action
89    * \param theId - string ID of the item
90    * \param theAction - action to add
91    */
92   void addAction(const QString& theId, QAction* theAction);
93
94   /// Updates menu for object browser
95   void updateObjectBrowserMenu();
96
97   /// Creates menu for object browser
98   void buildObjBrowserMenu();
99
100   /// Creates menu for viewer
101   void buildViewerMenu();
102
103   /// Map of created actions [id : Action]
104   QMap<QString, QAction*> myActions;
105
106   /// Reference to workshop
107   XGUI_Workshop* myWorkshop;
108
109   typedef QList<QAction*> QActionsList;
110   QMap<std::string, QActionsList> myObjBrowserMenus;
111   QMap<std::string, QActionsList> myViewerMenu;
112
113    QAction* mySeparator;
114 };
115
116 #endif