1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef XGUI_ContextMenuMgr_H
21 #define XGUI_ContextMenuMgr_H
30 class QContextMenuEvent;
36 * A class wihich provides managent of context menu
38 class XGUI_EXPORT XGUI_ContextMenuMgr : public QObject
43 /// \param theParent a parent object
44 XGUI_ContextMenuMgr(XGUI_Workshop* theParent);
45 virtual ~XGUI_ContextMenuMgr();
47 /// Create all actions for context menus. It is called on creation of application
50 /// Returns action according to the given ID
51 /// \param theId an id of an action
52 QAction* action(const QString& theId) const;
54 /// Returns action object by its Id (name)
55 /// \param theName is an Id of the action
56 QAction* actionByName(const QString& theName) const;
58 /// Returns list of registered actions Ids
59 QStringList actionIds() const;
61 /// update state of internal commands
62 void updateCommandsStatus();
64 /// Connect to object browser from workshop. Has to called at creation of viewer.
65 void connectObjectBrowser();
67 /// Connect to viewer from workshop. Has to called at creation of viewer.
70 /// Add menu items for Object browser pop-up
71 void addObjBrowserMenu(QMenu*) const;
73 /// Add menu items for Viewer pop-up
74 void addViewerMenu(QMenu*) const;
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);
81 /// Updates menu for object browser
82 void updateObjectBrowserMenu();
84 /// Updates menu for viewer
85 void updateViewerMenu();
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);
93 /// A signal which is sent before context menu show
94 void beforeContextMenu();
96 /// A signal which is sent after context menu show
97 void afterContextMenu();
100 /// Process action event
101 /// \param isChecked a checked action flag
102 void onAction(bool isChecked);
104 /// Process context menu event
105 /// \param theEvent a context menu event
106 void onContextMenuRequest(QContextMenuEvent* theEvent);
110 /// Slot called on Result selection menu press
111 void onResultSelection(bool theChecked);
113 /// Slot called on any shape selection menu press
114 void onShapeSelection(bool theChecked);
119 * \param theId - string ID of the item
120 * \param theAction - action to add
122 void addAction(const QString& theId, QAction* theAction);
124 void addFeatures(QMenu* theMenu) const;
126 /// Creates menu for object browser
127 void buildObjBrowserMenu();
129 /// Creates menu for viewer
130 void buildViewerMenu();
132 /// Map of created actions [id : Action]
133 QMap<QString, QAction*> myActions;
135 /// Reference to workshop
136 XGUI_Workshop* myWorkshop;
138 typedef QList<QAction*> QActionsList;
139 QMap<std::string, QActionsList> myObjBrowserMenus;
140 QMap<std::string, QActionsList> myViewerMenu;
142 //QActionGroup* mySelectActions;
144 QAction* mySeparator1;
145 QAction* mySeparator2;
146 QAction* mySeparator3;