Salome HOME
ca33862e28afd46e10d007bbc12cefbea3e9b9ff
[modules/shaper.git] / src / XGUI / XGUI_ContextMenuMgr.h
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef XGUI_ContextMenuMgr_H
21 #define XGUI_ContextMenuMgr_H
22
23 #include "XGUI.h"
24
25 #include <QObject>
26 #include <QMap>
27
28 class XGUI_Workshop;
29 class QAction;
30 class QContextMenuEvent;
31 class QMenu;
32 class QActionGroup;
33
34 /**
35  * \ingroup GUI
36  * A class wihich provides managent of context menu
37  */
38 class XGUI_EXPORT XGUI_ContextMenuMgr : public QObject
39 {
40 Q_OBJECT
41  public:
42    /// Constructor
43    /// \param theParent a parent object
44   XGUI_ContextMenuMgr(XGUI_Workshop* theParent);
45   virtual ~XGUI_ContextMenuMgr();
46
47   /// Create all actions for context menus. It is called on creation of application
48   void createActions();
49
50   /// Returns action according to the given ID
51   /// \param theId an id of an action
52   QAction* action(const QString& theId) const;
53
54   /// Returns action object by its Id (name)
55   /// \param theName is an Id of the action
56   QAction* actionByName(const QString& theName) const;
57
58   /// Returns list of registered actions Ids
59   QStringList actionIds() const;
60
61   /// update state of internal commands
62   void updateCommandsStatus();
63
64   /// Connect to object browser from workshop. Has to called at creation of viewer.
65   void connectObjectBrowser();
66
67   /// Connect to viewer from workshop. Has to called at creation of viewer.
68   void connectViewer();
69
70   /// Add menu items for Object browser pop-up
71   void addObjBrowserMenu(QMenu*) const;
72
73   /// Add menu items for Viewer pop-up
74   void addViewerMenu(QMenu*) const;
75
76   /// Returns a list of object group names of the action
77   /// \param theName a name of the action
78   /// \return a list of group names
79   QStringList actionObjectGroups(const QString& theName);
80
81   /// Updates menu for object browser
82   void updateObjectBrowserMenu();
83
84   /// Updates menu for viewer
85   void updateViewerMenu();
86
87 signals:
88   /// Signal aabout triggered action
89   /// \param theId an id of triggered action
90   /// \param isChecked is checked flag
91   void actionTriggered(const QString& theId, bool isChecked);
92
93   /// A signal which is sent before context menu show
94   void beforeContextMenu();
95
96   /// A signal which is sent after context menu show
97   void afterContextMenu();
98
99  private slots:
100    /// Process action event
101    /// \param isChecked a checked action flag
102   void onAction(bool isChecked);
103
104   /// Process context menu event
105   /// \param theEvent a context menu event
106   void onContextMenuRequest(QContextMenuEvent* theEvent);
107
108   void onRename();
109
110   /// Slot called on Result selection menu press
111   void onResultSelection(bool theChecked);
112
113   /// Slot called on any shape selection menu press
114   void onShapeSelection(bool theChecked);
115
116  private:
117   /** 
118    * Add action
119    * \param theId - string ID of the item
120    * \param theAction - action to add
121    */
122   void addAction(const QString& theId, QAction* theAction);
123
124   void addFeatures(QMenu* theMenu) const;
125
126   /// Creates menu for object browser
127   void buildObjBrowserMenu();
128
129   /// Creates menu for viewer
130   void buildViewerMenu();
131
132   /// Map of created actions [id : Action]
133   QMap<QString, QAction*> myActions;
134
135   /// Reference to workshop
136   XGUI_Workshop* myWorkshop;
137
138   typedef QList<QAction*> QActionsList;
139   QMap<std::string, QActionsList> myObjBrowserMenus;
140   QMap<std::string, QActionsList> myViewerMenu;
141
142   //QActionGroup* mySelectActions;
143
144   QAction* mySeparator1;
145   QAction* mySeparator2;
146   QAction* mySeparator3;
147   QAction* mySeparator4;
148 };
149
150 #endif