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