Salome HOME
Update documentation
[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() const;
48
49   /// Connect to viewer from workshop. Has to called at creation of viewer.
50   void connectViewer() const;
51
52   /// Add menu atems for viewer into the given menu (used in SALOME mode)
53   /// \param theMenu a popup menu to be shown in the viewer
54   void addViewerItems(QMenu* theMenu) const;
55
56 signals:
57   /// Signal aabout triggered action
58   /// \param theId an id of triggered action
59   /// \param isChecked is checked flag
60   void actionTriggered(const QString& theId, bool isChecked);
61
62   /// A signal which is sent before context menu show
63   void beforeContextMenu();
64
65   /// A signal which is sent after context menu show
66   void afterContextMenu();
67
68  private slots:
69    /// Process action event
70    /// \param isChecked a checked action flag
71   void onAction(bool isChecked);
72
73   /// Process context menu event
74   /// \param theEvent a context menu event
75   void onContextMenuRequest(QContextMenuEvent* theEvent);
76
77  private:
78   /** 
79    * Add action
80    * \param theId - string ID of the item
81    * \param theAction - action to add
82    */
83   void addAction(const QString& theId, QAction* theAction);
84
85   /// Creates menu for object browser
86   QMenu* objectBrowserMenu() const;
87
88   /// Creates menu for viewer
89   QMenu* viewerMenu() const;
90
91   /// Map of created actions [id : Action]
92   QMap<QString, QAction*> myActions;
93
94   /// Reference to workshop
95   XGUI_Workshop* myWorkshop;
96 };
97
98 #endif