Salome HOME
Issue #1860: fix end lines with spaces
[modules/shaper.git] / src / PartSet / PartSet_MenuMgr.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_MenuMgr.h
4 // Created:     03 April 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #ifndef PartSet_MenuMgr_H
8 #define PartSet_MenuMgr_H
9
10 #include <ModelAPI_Feature.h>
11
12 #include <QObject>
13 #include <QMap>
14 #include <QString>
15 #include <QList>
16 #include <QColor>
17
18 class ModuleBase_Operation;
19 class PartSet_Module;
20 class QAction;
21 class QMenu;
22
23 /**
24 * \ingroup Modules
25 * A class for management of module specific menu
26 */
27 class PartSet_MenuMgr: public QObject
28 {
29   Q_OBJECT
30 public:
31   /// Constructor
32   /// \param theModule a parent module
33   PartSet_MenuMgr(PartSet_Module* theModule);
34
35
36   /// Returns action according to the given ID
37   /// \param theId an action identifier, it should be uniqued in the bounds of the module
38   QAction* action(const QString& theId) const;
39
40   /// Add menu items for viewer into the actions map
41   /// \param theStdActions a map of standard actions
42   /// \param theParent a parent widget for the
43   /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
44   /// \return true if items are added and there is no necessity to provide standard menu
45   bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
46                      QWidget* theParent,
47                      QMap<int, QAction*>& theMenuActions) const;
48
49   /// Update state of pop-up menu items in viewer
50   /// \param theStdActions - a map of standard actions
51   void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
52
53   /// Activates a PartSet document
54   void activatePartSet() const;
55
56   /// Returns list of granted operation indices
57   virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
58
59 public slots:
60   /// Processes the context menu action click
61   /// \param isChecked a state of toggle if the action is checkable
62   void onAction(bool isChecked);
63
64 private slots:
65
66   /// A slot which is called on selection of menu item coresponding to line with coincedence
67   /// \param theAction an action of the selected item
68   void onLineHighlighted(QAction* theAction);
69
70   /// A slot which is called on hiding Detach menu
71   void onDetachMenuHide();
72
73   /// A slot which is called on selection an Item in Detach menu
74   /// \param theAction an action of the selected item
75   void onLineDetach(QAction* theAction);
76
77   /// A slot called on Part activation command
78   void onActivatePart(bool);
79
80   /// A slot called on PartSet activation command
81   void onActivatePartSet(bool);
82
83   /// A slot called on edit of feature
84   void onEdit(bool);
85
86 protected:
87   /// Redefinition of virtual method
88   /// \param theObj an object
89   /// \param theEvent an event
90   virtual bool eventFilter(QObject* theObj, QEvent* theEvent);
91
92 private:
93   /// Returns true if the current operation is sketch entity create operation
94   /// \param theValue the current auxiliary value
95   /// \return the boolean result
96   bool canSetAuxiliary(bool& theValue) const;
97
98   /// Changes the sketcher entity construction argument value
99   /// \param isChecked if true, the feature is a construction
100   void setAuxiliary(const bool isChecked);
101
102   /// Create all actions for context menus. It is called on creation of module
103   /// Put the created actions into an internal map
104   void createActions();
105
106   /// Add action to the internal map
107   /// \param theId - string ID of the item
108   /// \param theAction - action to add
109   void addAction(const QString& theId, QAction* theAction);
110
111   /// Set color on presentation of result listed in myCoinsideLines
112   /// \param theId object Id in myCoinsideLines list
113   /// \param theColor a color which has to be set
114   /// \param theUpdate update viewer flag
115   /// \return previously defined color on the object
116   QColor setLineColor(int theId, const QColor theColor, bool theUpdate);
117
118   /// Reference to a parent module
119   PartSet_Module* myModule;
120
121   /// the popup menu actions
122   QMap<QString, QAction*> myActions;
123
124   /// List of lines coincided in a one point
125   mutable QList<FeaturePtr> myCoinsideLines;
126
127   /// A Coincedence feature selected by user for detaching
128   mutable FeaturePtr mySelectedFeature;
129
130   /// Id of menu item in Detach menu previously selected
131   int myPrevId;
132
133   /// Original color of highlighted line
134   QColor myColor;
135 };
136
137 #endif