Salome HOME
External object manager to be used in the multi selector widget
[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 list of registered actions Ids
37   QStringList actionIds() const;
38
39   /// update state of internal commands
40   void updateCommandsStatus();
41
42   /// Connect to object browser from workshop. Has to called at creation of viewer.
43   void connectObjectBrowser() const;
44
45   /// Connect to viewer from workshop. Has to called at creation of viewer.
46   void connectViewer() const;
47
48   /// Add menu atems for viewer into the given menu (used in SALOME mode)
49   /// \param theMenu a popup menu to be shown in the viewer
50   void addViewerItems(QMenu* theMenu) const;
51
52 signals:
53   /// Signal aabout triggered action
54   /// \param theId an id of triggered action
55   /// \param isChecked is checked flag
56   void actionTriggered(const QString& theId, bool isChecked);
57
58   void beforeContextMenu();
59   void afterContextMenu();
60
61  private slots:
62    /// Process action event
63    /// \param isChecked a checked action flag
64   void onAction(bool isChecked);
65
66   /// Process context menu event
67   /// \param theEvent a context menu event
68   void onContextMenuRequest(QContextMenuEvent* theEvent);
69
70  private:
71   /** 
72    * Add action
73    * \param theId - string ID of the item
74    * \param theAction - action to add
75    */
76   void addAction(const QString& theId, QAction* theAction);
77
78   /// Creates menu for object browser
79   QMenu* objectBrowserMenu() const;
80
81   /// Creates menu for viewer
82   QMenu* viewerMenu() const;
83
84   /// Map of created actions [id : Action]
85   QMap<QString, QAction*> myActions;
86
87   /// Reference to workshop
88   XGUI_Workshop* myWorkshop;
89 };
90
91 #endif