Salome HOME
Update copyrights
[modules/shaper.git] / src / XGUI / XGUI_PropertyPanel.h
1 // Copyright (C) 2014-2019  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_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 const static char* PROP_PANEL = "property_panel_dock";
40
41 /// Internal name of Ok button
42 const static char* PROP_PANEL_OK = "property_panel_ok";
43
44 /// Internal name of Ok button
45 const static char* PROP_PANEL_OK_PLUS = "property_panel_ok_plus";
46
47 /// Internal name of Cancel button
48 const static char* PROP_PANEL_CANCEL = "property_panel_cancel";
49
50 /// Internal name of Help button
51 const static char* PROP_PANEL_HELP = "property_panel_help";
52
53 /// Internal name of Preview button
54 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 public slots:
148   /// \brief Update all widgets in property panel with values from the given feature
149   /// \param theFeature a Feature to update values in widgets
150   void updateContentWidget(FeaturePtr theFeature);
151
152   /// \brief If the XML definition of the feature contains information about specific
153   /// content of the property panel, it creates the panel and allow filling it by the given feature
154   /// \param theFeature a Feature to fill property panel
155   void createContentPanel(FeaturePtr theFeature);
156
157   /**
158   * Makes the given widget active, highlights it and removes
159   * highlighting from the previous active widget
160   * \param theWidget which has to be activated
161   * \param theEmitSignal a flag to prohibit signal emit
162   */
163   virtual void activateWidget(ModuleBase_ModelWidget* theWidget, const bool theEmitSignal = true);
164
165    /// Activates the parameter widget if it can accept focus
166    /// \param theWidget a widget where focus in event happened
167   void onFocusInWidget(ModuleBase_ModelWidget* theWidget);
168
169
170   /// Activate next widget
171   /// \param theWidget the current widget
172   void onActivateNextWidget(ModuleBase_ModelWidget* theWidget);
173
174 signals:
175   /// The signal is emitted if the enter is clicked in the control of the widget
176   /// \param theObject a sender of the event
177   void enterClicked(QObject* theObject);
178
179   /// Emits on deactivating property panel (e.g. by clearContent)
180   void propertyPanelDeactivated();
181   /// Emits on widget activating
182   void propertyPanelActivated();
183
184 protected:
185   /// Makes the widget active, deactivate the previous, activate and hightlight the given one
186   /// \param theWidget a widget
187   /// \param isEmitSignal flag whether panel signals should be emitted
188   bool setActiveWidget(ModuleBase_ModelWidget* theWidget, const bool isEmitSignal);
189   /// The parent method that processes the "Tab"/"SHIF + Tab" keyboard events
190   /// Emits a signal about focus change
191   /// If theIsNext is true, this function searches forward, if next is false, it searches backward.
192   virtual bool focusNextPrevChild(bool theIsNext);
193   /// Activate the next widget in the property panel
194   /// \param theWidget a widget. The next widget should be activated
195   /// \param isCheckVisibility flag whether the next widget visibility is checked
196   void activateNextWidget(ModuleBase_ModelWidget* theWidget,
197                           const bool isCheckVisibility);
198
199  protected:
200    /// A method called on the property panel closed
201    /// \param theEvent a close event
202    void closeEvent(QCloseEvent* theEvent);
203
204 private:
205   QWidget* myHeaderWidget;  ///< A header widget
206
207   ModuleBase_PageWidget* myPanelPage;
208   QList<ModuleBase_ModelWidget*> myWidgets;
209
210   /// Currently active widget
211   ModuleBase_ModelWidget* myActiveWidget;
212   /// Currently widget processed by preselection
213   ModuleBase_ModelWidget* myPreselectionWidget;
214   /// Some custom widget set from outside
215   ModuleBase_ModelWidget* myInternalActiveWidget;
216
217   XGUI_OperationMgr* myOperationMgr;
218 };
219
220 #endif /* XGUI_PROPERTYPANEL_H_ */