Salome HOME
Copyright update 2022
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetOptionalBox.h
1 // Copyright (C) 2014-2022  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 ModuleBase_WidgetOptionalBox_H_
21 #define ModuleBase_WidgetOptionalBox_H_
22
23 #include <ModuleBase.h>
24 #include <ModuleBase_PageBase.h>
25 #include <ModuleBase_ModelWidget.h>
26
27 class QGroupBox;
28 class QFrame;
29 class QCheckBox;
30 class QVBoxLayout;
31 class QHBoxLayout;
32 class QGridLayout;
33
34 /**
35 * \ingroup GUI
36 * Implements a model widget for switch as a container widget. It can be defined in XML with "toolbox" keyword
37 */
38 class MODULEBASE_EXPORT ModuleBase_WidgetOptionalBox : public ModuleBase_ModelWidget,
39                                                          public ModuleBase_PageBase
40 {
41   Q_OBJECT
42
43   enum OptionType {CheckBox, GroupBox};
44 public:
45   /// Constructor
46   /// \param theParent the parent object
47   /// \param theData the widget configuration. The attribute of the model widget is obtained from
48   ModuleBase_WidgetOptionalBox(QWidget* theParent, const Config_WidgetAPI* theData);
49   virtual ~ModuleBase_WidgetOptionalBox();
50
51   /// Defines if it is supported to set the value in this widget
52   /// \return false because this is an info widget
53   virtual bool canAcceptFocus() const { return false; };
54
55   /// Methods to be redefined from ModuleBase_PageBase: start
56   /// Cast the page to regular QWidget
57   virtual QWidget* pageWidget();
58   /// Methods to be redefined from ModuleBase_PageBase: end
59
60   /// Methods to be redefined from ModuleBase_ModelWidget: start
61   /// Returns list of widget controls
62   /// \return a control list
63   virtual QList<QWidget*> getControls() const;
64   /// Methods to be redefined from ModuleBase_ModelWidget: end
65
66 protected slots:
67   // store value to the model
68   void onPageClicked();
69
70 protected:
71   /// Methods to be redefined from ModuleBase_PageBase: start
72   /// Adds the given widget to page's layout
73   virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
74   /// Adds the given page to page's layout
75   virtual void placeWidget(QWidget* theWidget);
76   /// Returns page's layout (QGridLayout)
77   virtual QLayout* pageLayout();
78   /// Adds a stretch to page's layout
79   virtual void addPageStretch();
80   /// Methods to be redefined from ModuleBase_PageBase: end
81
82
83   /// Methods to be redefined from ModuleBase_ModelWidget: start
84   /// Saves the internal parameters to the given feature
85   /// \return True in success
86   virtual bool storeValueCustom();
87   /// Restore value from attribute data to the widget's control
88   virtual bool restoreValueCustom();
89   /// Methods to be redefined from ModuleBase_ModelWidget: end
90
91 private:
92   /// Sets whether Check box or Group box is used currently
93   /// \param theType a type of the control
94   void setOptionType(const OptionType& theType);
95
96   /// Returns true if the model widget is set into the check box frame
97   /// \return boolean value
98   bool isCheckBoxFilled() const;
99
100   /// Creates controls for the given type if it was not perfomed yet
101   /// \param theType a type to create whether check box or group box controls
102   void createControl(const OptionType& theType);
103
104   /// Returns true if control is checked
105   /// \return boolean value
106   bool getCurrentValue() const;
107
108   /// Returns true if control is checked
109   /// \param theValue a new value to fill the control state
110   void setCurrentValue(const bool& theValue);
111
112   /// Makes model widget controls either disabled(for check box mode) or hidden(for group box mode)
113   void updateControlsVisibility();
114
115   bool toEnableWidgets() const;
116
117 private:
118   std::string myToolTip; ///< tool tip defined in XML
119   std::string myGroupTitle; ///< a title for group box
120
121   OptionType myOptionType; ///< current option state
122   QVBoxLayout* myMainLayout; ///< the main layout
123   // controls to fill check box frame
124   QWidget* myCheckBoxFrame; ///< frame with check box, to be hidden when group box is used
125   QCheckBox* myCheckBox; ///< control used if only one model widget is placed inside
126   QHBoxLayout* myCheckBoxLayout; ///< layout of check box frame
127   ModuleBase_ModelWidget* myCheckBoxWidget; /// model widget, placed in the check box frame
128   // controls to fill group box frame
129   QGroupBox* myGroupBox; ///< control used if more than model widget is placed inside
130   QGridLayout* myGroupBoxLayout; ///< page's layout
131
132   QWidget* myCheckGroup;
133   QCheckBox* myCheckGroupBtn;
134   QWidget* myCheckContent;
135   QVBoxLayout* myCheckGroupLayout;
136
137   bool myHaveFrame;
138   bool myEnableOnCheck;
139   bool myAlwaysShowTitle;
140 };
141
142 #endif /* ModuleBase_WidgetOptionalBox_H_ */