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