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