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