Salome HOME
Issues #2173, #2169: processing focus in widget by SHAPER loop (instead of Qt loop...
[modules/shaper.git] / src / ModuleBase / ModuleBase_DoubleSpinBox.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:      ModuleBase_DoubleSpinBox.h
4 // Author:    Sergey BELASH
5 //
6 #ifndef MODULEBASE_DOUBLESPINBOX_H_
7 #define MODULEBASE_DOUBLESPINBOX_H_
8
9 #include "ModuleBase.h"
10
11 #include <QDoubleSpinBox>
12 #include <QValidator>
13
14 #include <QColor>
15
16 class QKeyEvent;
17
18 /**
19 * \ingroup GUI
20 * An extension and customization of QDoubleSpinBox class
21 */
22 class MODULEBASE_EXPORT ModuleBase_DoubleSpinBox : public QDoubleSpinBox
23 {
24 Q_OBJECT
25
26  public:
27   explicit ModuleBase_DoubleSpinBox( QWidget* theParent = 0, int thePrecision = -12 );
28   virtual ~ModuleBase_DoubleSpinBox();
29
30   /// Returns true if the control is clear
31   bool isCleared() const;
32
33   /// Set control clear
34   virtual void setCleared(const bool);
35
36   /// Returns current precision
37   int getPrecision() const;
38
39   /// Set precision
40   void setPrecision(const int);
41
42   /// Set step
43   virtual void stepBy(int);
44
45   /// Converts value from string to double
46   virtual double valueFromText(const QString&) const;
47
48   /// Convert value from double to string
49   virtual QString textFromValue(double) const;
50
51   /// Validate current value
52   virtual QValidator::State validate(QString&, int&) const;
53
54   /// Imitation of disable control value. If theEnable is false, the control becomes
55   /// read only and base color is disabled.
56   void setValueEnabled(const bool& theEnable);
57
58  protected slots:
59    /// Called on text changed
60   virtual void onTextChanged(const QString&);
61
62  protected:
63    /// Removes extra trailing zero symbols
64   QString removeTrailingZeroes(const QString&) const;
65
66  private:
67   // boolen flag whether the key event is emitted. The default value is false
68   bool myIsEmitKeyPressEvent;
69
70    /// Is clear flag
71   bool myCleared;
72
73   /// Precision value
74   int myPrecision;
75
76   /// Cashed color of active base palette
77   QColor myEnabledBaseColor;
78 };
79
80 #endif