Salome HOME
Issues #2173, #2169: processing focus in widget by SHAPER loop (instead of Qt loop...
[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 public slots:
118   /// \brief Update all widgets in property panel with values from the given feature
119   /// \param theFeature a Feature to update values in widgets
120   void updateContentWidget(FeaturePtr theFeature);
121
122   /// \brief If the XML definition of the feature contains information about specific
123   /// content of the property panel, it creates the panel and allow filling it by the given feature
124   /// \param theFeature a Feature to fill property panel
125   void createContentPanel(FeaturePtr theFeature);
126
127   /**
128   * Makes the given widget active, highlights it and removes
129   * highlighting from the previous active widget
130   * emits widgetActivated(theWidget) signal
131   * \param theWidget which has to be activated
132   * \param theEmitSignal a flag to prohibit signal emit
133   */
134   virtual void activateWidget(ModuleBase_ModelWidget* theWidget, const bool theEmitSignal = true);
135
136    /// Activates the parameter widget if it can accept focus
137    /// \param theWidget a widget where focus in event happened
138   void onFocusInWidget(ModuleBase_ModelWidget* theWidget);
139
140
141   /// Activate next widget
142   /// \param theWidget the current widget
143   void onActivateNextWidget(ModuleBase_ModelWidget* theWidget);
144
145 signals:
146   /// The signal is emitted if the enter is clicked in the control of the widget
147   /// \param theObject a sender of the event
148   void enterClicked(QObject* theObject);
149
150 protected:
151   /// Makes the widget active, deactivate the previous, activate and hightlight the given one
152   /// \param theWidget a widget
153   bool setActiveWidget(ModuleBase_ModelWidget* theWidget);
154 public:
155   /// The parent method that processes the "Tab"/"SHIF + Tab" keyboard events
156   /// Emits a signal about focus change
157   /// If theIsNext is true, this function searches forward, if next is false, it searches backward.
158   virtual bool focusNextPrevChild_(bool theIsNext);
159 protected:
160   virtual bool focusNextPrevChild(bool theIsNext) { return true; }
161   /// Activate the next widget in the property panel
162   /// \param theWidget a widget. The next widget should be activated
163   /// \param isCheckVisibility flag whether the next widget visibility is checked
164   void activateNextWidget(ModuleBase_ModelWidget* theWidget,
165                           const bool isCheckVisibility);
166
167  protected:
168    /// A method called on the property panel closed
169    /// \param theEvent a close event
170    void closeEvent(QCloseEvent* theEvent);
171
172 private:
173   QWidget* myHeaderWidget;  ///< A header widget
174
175   ModuleBase_PageWidget* myPanelPage;
176   QList<ModuleBase_ModelWidget*> myWidgets;
177
178   /// Currently active widget
179   ModuleBase_ModelWidget* myActiveWidget;
180   /// Currently widget processed by preselection
181   ModuleBase_ModelWidget* myPreselectionWidget;
182
183   XGUI_OperationMgr* myOperationMgr;
184 };
185
186 #endif /* XGUI_PROPERTYPANEL_H_ */