Salome HOME
Provide connection of new features in SALOME module
[modules/shaper.git] / src / XGUI / XGUI_ContextMenuMgr.h
1
2 #ifndef XGUI_ContextMenuMgr_H
3 #define XGUI_ContextMenuMgr_H
4
5 #include "XGUI.h"
6
7 #include <QObject>
8 #include <QMap>
9
10 class XGUI_Workshop;
11 class QAction;
12 class QContextMenuEvent;
13 class QMenu;
14
15 /**
16 * A claas wihich provides manement of context menu
17 */
18 class XGUI_EXPORT XGUI_ContextMenuMgr: public QObject
19 {
20 Q_OBJECT
21 public:
22   XGUI_ContextMenuMgr(XGUI_Workshop* theParent);
23   virtual ~XGUI_ContextMenuMgr();
24
25   /// Create all actions for context menus. It is called on creation of application
26   void createActions();
27
28   /// Returns action according to the given ID
29   QAction* action(const QString& theId) const;
30
31   /// Returns list of registered actions Ids
32   QStringList actionIds() const;
33
34   /// update state of internal commands
35   void updateCommandsStatus();
36
37   /// Connect to object browser from workshop. Has to called at creation of viewer.
38   void connectObjectBrowser() const;
39
40   /// Connect to viewer from workshop. Has to called at creation of viewer.
41   void connectViewer() const;
42
43   /// Add menu atems for viewer into the given menu (used in SALOME mode)
44   void addViewerItems(QMenu* theMenu) const;
45
46 signals:
47   void actionTriggered(const QString& theId, bool isChecked);
48
49 private slots:
50   void onAction(bool isChecked);
51
52   void onContextMenuRequest(QContextMenuEvent* theEvent);
53
54 private:
55   /** 
56   * Add action
57   * \param theId - string ID of the item
58   * \param theAction - action to add
59   */
60   void addAction(const QString& theId, QAction* theAction);
61
62
63   QMenu* objectBrowserMenu() const;
64   QMenu* viewerMenu() const;
65
66   QMap<QString, QAction*> myActions;
67
68   XGUI_Workshop* myWorkshop;
69 };
70
71 #endif