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