Salome HOME
updated copyright message
[modules/shaper.git] / src / XGUI / XGUI_PropertyPanel.h
1 // Copyright (C) 2014-2023  CEA, EDF
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_PROPERTYPANEL_H_
21 #define XGUI_PROPERTYPANEL_H_
22
23 #include "XGUI.h"
24
25 #include <ModuleBase_ModelWidget.h>
26 #include <ModuleBase_IPropertyPanel.h>
27
28 #include <QList>
29
30 class XGUI_ActionsMgr;
31 class QKeyEvent;
32 class QGridLayout;
33 class QToolButton;
34 class ModuleBase_PageBase;
35 class ModuleBase_PageWidget;
36 class XGUI_OperationMgr;
37
38 /// Internal name of property panel widget
39 MAYBE_UNUSED const static char* PROP_PANEL = "property_panel_dock";
40
41 /// Internal name of Ok button
42 MAYBE_UNUSED const static char* PROP_PANEL_OK = "property_panel_ok";
43
44 /// Internal name of Ok button
45 MAYBE_UNUSED const static char* PROP_PANEL_OK_PLUS = "property_panel_ok_plus";
46
47 /// Internal name of Cancel button
48 MAYBE_UNUSED const static char* PROP_PANEL_CANCEL = "property_panel_cancel";
49
50 /// Internal name of Help button
51 MAYBE_UNUSED const static char* PROP_PANEL_HELP = "property_panel_help";
52
53 /// Internal name of Preview button
54 MAYBE_UNUSED const static char* PROP_PANEL_PREVIEW = "property_panel_preview";
55
56 /**
57 * \ingroup GUI
58 * Realization of Property panel object.
59 */
60 class XGUI_EXPORT XGUI_PropertyPanel : public ModuleBase_IPropertyPanel
61 {
62 Q_OBJECT
63  public:
64
65   /// Constructor
66   /// \param theParent is a parent of the property panel
67   /// \param theMgr operation manager
68   XGUI_PropertyPanel(QWidget* theParent, XGUI_OperationMgr* theMgr);
69
70   virtual ~XGUI_PropertyPanel();
71
72   /// Returns header widget
73   virtual QWidget* headerWidget() const { return myHeaderWidget; }
74
75   /// Returns main widget of the property panel, which children will be created
76   /// by WidgetFactory using the XML definition
77   ModuleBase_PageBase* contentWidget();
78
79   /// Brings back all widget created by widget factory for signal/slot
80   /// connections and further processing
81   void setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets);
82
83   /// Returns all property panel's widget created by WidgetFactory
84   virtual const QList<ModuleBase_ModelWidget*>& modelWidgets() const;
85
86   /// Removes all widgets in the widget area of the property panel
87   virtual void cleanContent();
88
89   /// Returns currently active widget. This is a widget from internal container of widgets
90   /// (myWidgets) activated/deactivated by focus in property panel. If parameter is true,
91   /// the method finds firstly the custom widget, after the direct active widget.
92   /// \param isUseCustomWidget boolean state if the custom widget might be a result
93   virtual ModuleBase_ModelWidget* activeWidget(const bool isUseCustomWidget = false) const;
94
95   /// Activate the next widget in the property panel
96   /// \param theWidget a widget. The next widget should be activated
97   virtual void activateNextWidget(ModuleBase_ModelWidget* theWidget);
98
99   /// Activate the next from current widget in the property panel
100   virtual void activateNextWidget();
101
102   /// Set focus on the Ok button
103   virtual void setFocusOnOkButton();
104
105   /// Set Enable/Disable state of Cancel button
106   /// \param theEnabled Enable/Disable state of Cancel button
107   virtual void setCancelEnabled(bool theEnabled);
108
109   /// \return Enable/Disable state of Cancel button
110   virtual bool isCancelEnabled() const;
111
112   /// Editing mode depends on mode of current operation. This value is defined by it.
113   /// \param isEditing state of editing mode flag
114   virtual void setEditingMode(bool isEditing);
115
116   //! Allows to set predefined actions for the property panel fetched from the ActionsMgr
117   void setupActions(XGUI_ActionsMgr* theMgr);
118
119   /// Returns widget processed by preselection
120   virtual ModuleBase_ModelWidget* preselectionWidget() const;
121
122   /// Sets widget processed by preselection
123   virtual void setPreselectionWidget(ModuleBase_ModelWidget* theWidget);
124
125   /// Returns operation manager
126   XGUI_OperationMgr* operationMgr() const { return myOperationMgr; }
127
128   /// Find under the panel a child button with the parameter name
129   /// \param theInternalName a button object name
130   /// \return button instance or NULL
131   QToolButton* findButton(const char* theInternalName) const;
132
133   /// Possibility to process focus by method, for example when Tab or SHIF+Tab is pressed
134   /// but property panel is not active widget
135   /// \param theIsNext true, if Tab(to the next widget) or false(moving to the previous)
136   bool setFocusNextPrevChild(bool theIsNext);
137
138   /// The method is called on accepting of operation
139   virtual void onAcceptData();
140
141   /// Set internal active widget, that can be returned as active widget and participate in active
142   /// selection filters/modes in application. It emits signal about property panel activation or
143   /// deactivation and updates selection filters/modes accordingly.
144   /// \param theWidget a widget control to store as internal active widget
145   void setInternalActiveWidget(ModuleBase_ModelWidget* theWidget);
146
147   void updateApplyPlusButton(FeaturePtr theFeature);
148
149 public slots:
150   /// \brief Update all widgets in property panel with values from the given feature
151   /// \param theFeature a Feature to update values in widgets
152   void updateContentWidget(FeaturePtr theFeature);
153
154   /// \brief If the XML definition of the feature contains information about specific
155   /// content of the property panel, it creates the panel and allow filling it by the given feature
156   /// \param theFeature a Feature to fill property panel
157   void createContentPanel(FeaturePtr theFeature);
158
159   /**
160   * Makes the given widget active, highlights it and removes
161   * highlighting from the previous active widget
162   * \param theWidget which has to be activated
163   * \param theEmitSignal a flag to prohibit signal emit
164   */
165   virtual void activateWidget(ModuleBase_ModelWidget* theWidget, const bool theEmitSignal = true);
166
167    /// Activates the parameter widget if it can accept focus
168    /// \param theWidget a widget where focus in event happened
169   void onFocusInWidget(ModuleBase_ModelWidget* theWidget);
170
171
172   /// Activate next widget
173   /// \param theWidget the current widget
174   void onActivateNextWidget(ModuleBase_ModelWidget* theWidget);
175
176 signals:
177   /// The signal is emitted if the enter is clicked in the control of the widget
178   /// \param theObject a sender of the event
179   void enterClicked(QObject* theObject);
180
181   /// Emits on deactivating property panel (e.g. by clearContent)
182   void propertyPanelDeactivated();
183   /// Emits on widget activating
184   void propertyPanelActivated();
185
186 protected:
187   /// Makes the widget active, deactivate the previous, activate and hightlight the given one
188   /// \param theWidget a widget
189   /// \param isEmitSignal flag whether panel signals should be emitted
190   bool setActiveWidget(ModuleBase_ModelWidget* theWidget, const bool isEmitSignal);
191   /// The parent method that processes the "Tab"/"SHIF + Tab" keyboard events
192   /// Emits a signal about focus change
193   /// If theIsNext is true, this function searches forward, if next is false, it searches backward.
194   virtual bool focusNextPrevChild(bool theIsNext);
195   /// Activate the next widget in the property panel
196   /// \param theWidget a widget. The next widget should be activated
197   /// \param isCheckVisibility flag whether the next widget visibility is checked
198   void activateNextWidget(ModuleBase_ModelWidget* theWidget,
199                           const bool isCheckVisibility);
200
201  protected:
202    /// A method called on the property panel closed
203    /// \param theEvent a close event
204    void closeEvent(QCloseEvent* theEvent);
205
206 private:
207   QWidget* myHeaderWidget;  ///< A header widget
208
209   ModuleBase_PageWidget* myPanelPage;
210   QList<ModuleBase_ModelWidget*> myWidgets;
211
212   /// Currently active widget
213   ModuleBase_ModelWidget* myActiveWidget;
214   /// Currently widget processed by preselection
215   ModuleBase_ModelWidget* myPreselectionWidget;
216   /// Some custom widget set from outside
217   ModuleBase_ModelWidget* myInternalActiveWidget;
218
219   XGUI_OperationMgr* myOperationMgr;
220 };
221
222 #endif /* XGUI_PROPERTYPANEL_H_ */