Salome HOME
Updated copyright comment
[modules/shaper.git] / src / ModuleBase / ModuleBase_DoubleSpinBox.h
1 // Copyright (C) 2014-2024  CEA, EDF
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_DOUBLESPINBOX_H_
21 #define MODULEBASE_DOUBLESPINBOX_H_
22
23 #include "ModuleBase.h"
24
25 #include <QDoubleSpinBox>
26 #include <QValidator>
27
28 #include <QColor>
29
30 class QKeyEvent;
31
32 /**
33 * \ingroup GUI
34 * An extension and customization of QDoubleSpinBox class
35 */
36 class MODULEBASE_EXPORT ModuleBase_DoubleSpinBox : public QDoubleSpinBox
37 {
38 Q_OBJECT
39
40  public:
41   explicit ModuleBase_DoubleSpinBox( QWidget* theParent = 0, int thePrecision = -12 );
42   virtual ~ModuleBase_DoubleSpinBox();
43
44   /// Returns true if the control is clear
45   bool isCleared() const;
46
47   /// Set control clear
48   virtual void setCleared(const bool);
49
50   /// Returns current precision
51   int getPrecision() const;
52
53   /// Set precision
54   void setPrecision(const int);
55
56   /// Set step
57   virtual void stepBy(int);
58
59   /// Converts value from string to double
60   virtual double valueFromText(const QString&) const;
61
62   /// Convert value from double to string
63   virtual QString textFromValue(double) const;
64
65   /// Validate current value
66   virtual QValidator::State validate(QString&, int&) const;
67
68   /// Imitation of disable control value. If theEnable is false, the control becomes
69   /// read only and base color is disabled.
70   void setValueEnabled(const bool& theEnable);
71
72  protected slots:
73    /// Called on text changed
74   virtual void onTextChanged(const QString&);
75
76  protected:
77    /// Removes extra trailing zero symbols
78   QString removeTrailingZeroes(const QString&) const;
79
80  private:
81   // boolen flag whether the key event is emitted. The default value is false
82   bool myIsEmitKeyPressEvent;
83
84    /// Is clear flag
85   bool myCleared;
86
87   /// Precision value
88   int myPrecision;
89
90   /// Cashed color of active base palette
91   QColor myEnabledBaseColor;
92 };
93
94 #endif