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