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