Salome HOME
Merge branch 'Dev_GroupsRevision'
[modules/shaper.git] / src / XGUI / XGUI_ContextMenuMgr.h
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef XGUI_ContextMenuMgr_H
22 #define XGUI_ContextMenuMgr_H
23
24 #include "XGUI.h"
25
26 #include <QObject>
27 #include <QMap>
28
29 class XGUI_Workshop;
30 class QAction;
31 class QContextMenuEvent;
32 class QMenu;
33 class QActionGroup;
34
35 /**
36  * \ingroup GUI
37  * A class wihich provides managent of context menu
38  */
39 class XGUI_EXPORT XGUI_ContextMenuMgr : public QObject
40 {
41 Q_OBJECT
42  public:
43    /// Constructor
44    /// \param theParent a parent object
45   XGUI_ContextMenuMgr(XGUI_Workshop* theParent);
46   virtual ~XGUI_ContextMenuMgr();
47
48   /// Create all actions for context menus. It is called on creation of application
49   void createActions();
50
51   /// Returns action according to the given ID
52   /// \param theId an id of an action
53   QAction* action(const QString& theId) const;
54
55   /// Returns action object by its Id (name)
56   /// \param theName is an Id of the action
57   QAction* actionByName(const QString& theName) const;
58
59   /// Returns list of registered actions Ids
60   QStringList actionIds() const;
61
62   /// update state of internal commands
63   void updateCommandsStatus();
64
65   /// Connect to object browser from workshop. Has to called at creation of viewer.
66   void connectObjectBrowser();
67
68   /// Connect to viewer from workshop. Has to called at creation of viewer.
69   void connectViewer();
70
71   /// Add menu items for Object browser pop-up
72   void addObjBrowserMenu(QMenu*) const;
73
74   /// Add menu items for Viewer pop-up
75   void addViewerMenu(QMenu*) const;
76
77   /// Returns a list of object group names of the action
78   /// \param theName a name of the action
79   /// \return a list of group names
80   QStringList actionObjectGroups(const QString& theName);
81
82   /// Updates menu for object browser
83   void updateObjectBrowserMenu();
84
85   /// Updates menu for viewer
86   void updateViewerMenu();
87
88 signals:
89   /// Signal aabout triggered action
90   /// \param theId an id of triggered action
91   /// \param isChecked is checked flag
92   void actionTriggered(const QString& theId, bool isChecked);
93
94   /// A signal which is sent before context menu show
95   void beforeContextMenu();
96
97   /// A signal which is sent after context menu show
98   void afterContextMenu();
99
100  private slots:
101    /// Process action event
102    /// \param isChecked a checked action flag
103   void onAction(bool isChecked);
104
105   /// Process context menu event
106   /// \param theEvent a context menu event
107   void onContextMenuRequest(QContextMenuEvent* theEvent);
108
109   void onRename();
110
111   /// Slot called on Result selection menu press
112   void onResultSelection(bool theChecked);
113
114   /// Slot called on any shape selection menu press
115   void onShapeSelection(bool theChecked);
116
117  private:
118   /** 
119    * Add action
120    * \param theId - string ID of the item
121    * \param theAction - action to add
122    */
123   void addAction(const QString& theId, QAction* theAction);
124
125   void addFeatures(QMenu* theMenu) const;
126
127   /// Creates menu for object browser
128   void buildObjBrowserMenu();
129
130   /// Creates menu for viewer
131   void buildViewerMenu();
132
133   /// Map of created actions [id : Action]
134   QMap<QString, QAction*> myActions;
135
136   /// Reference to workshop
137   XGUI_Workshop* myWorkshop;
138
139   typedef QList<QAction*> QActionsList;
140   QMap<std::string, QActionsList> myObjBrowserMenus;
141   QMap<std::string, QActionsList> myViewerMenu;
142
143   //QActionGroup* mySelectActions;
144
145   QAction* mySeparator1;
146   QAction* mySeparator2;
147   QAction* mySeparator3;
148 };
149
150 #endif