Salome HOME
updated copyright message
[modules/shaper.git] / src / ModuleBase / ModuleBase_ChoiceCtrl.h
1 // Copyright (C) 2014-2023  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_ChoiceCtrl_H
21 #define ModuleBase_ChoiceCtrl_H
22
23 #include "ModuleBase.h"
24
25 #include <QWidget>
26 #include <QStringList>
27 #include <QList>
28
29 class QLabel;
30 class QComboBox;
31 class QGroupBox;
32 class QButtonGroup;
33
34 /**
35 * \ingroup GUI
36 * A Choice control. It provides a choice in several strings.
37 * It can be represented by several radiobuttons or by combo box.
38 * Radio buttons can be represented as by radiou buttons with text
39 * or by icons in toggle buttons.
40 */
41 class MODULEBASE_EXPORT ModuleBase_ChoiceCtrl: public QWidget
42 {
43 Q_OBJECT
44 public:
45   enum ControlType {
46     RadioButtons,
47     ComboBox
48   };
49
50   /**
51   * Constructor
52   * \param theParent a parent widget
53   * \param theChoiceList a list of choice strings
54   * \param theIconsList a list of icon names for radiou buttons
55   * \param theType a type of choice representation
56   * \param theButtonsDir direction of radio buttons placement
57   */
58   ModuleBase_ChoiceCtrl(QWidget* theParent,
59                         const QStringList& theChoiceList,
60                         const QStringList& theIconsList,
61                         ControlType theType = RadioButtons,
62                         Qt::Orientation theButtonsDir = Qt::Horizontal);
63
64   /// Set label for the controls.
65   /// It is a label for combo box and title for group of radio buttons.
66   /// \param theText a text of the label
67   void setLabel(const QString& theText);
68
69   /// Set Icon for the label. Used only for combo box.
70   /// \param theIcon a name of icon
71   void setLabelIcon(const QString& theIcon);
72
73   /// Set value: Id of button or item of combo box.
74   /// \param theVal a value (from 0 to number of items)
75   void setValue(int theVal);
76
77   /// Set value: text of button or item of combo box.
78   /// \param theVal a value (one of text items)
79   void setValue(const QString& theVal);
80
81   /// Set tool tip for label. Used only for combo box.
82   void setTooltip(QString theTip);
83
84   /// Returns currently selected value
85   int value() const;
86
87   /// Returns text of currently selected value
88   QString textValue() const;
89
90   /// Transfer focus on itself
91   bool focusTo();
92
93   /// Returns controls for activation
94   QList<QWidget*> getControls() const;
95
96   /// Set list of choice
97   /// \param theChoiceList a string list of items
98   void setChoiceList(const QStringList& theChoiceList);
99
100 signals:
101   /// A signal raised on change of current value
102   void valueChanged(int theVal);
103
104 private:
105   /// Control type
106   ControlType myType;
107
108   /// A label for cmbo box
109   QLabel* myLabel;
110
111   /// A combo box represerntation of control
112   QComboBox* myCombo;
113
114   /// A group box for radio buttons
115   QGroupBox* myGroupBox;
116
117   /// A group of buttons
118   QButtonGroup* myButtons;
119 };
120
121 #endif