Salome HOME
Disabling all input fields of geometry creation panels
[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   /// Change enable/disable internal state to emit key press event
55   /// \param theEnable if true, the signal is emitted
56   /// \return the previous value
57   bool enableKeyPressEvent(const bool& theEnable);
58
59   /// Imitation of disable control value. If theEnable is false, the control becomes
60   /// read only and base color is disabled. 
61   void setValueEnabled(const bool& theEnable);
62
63 signals:
64   /// The signal about key release on the control, that corresponds to the attribute
65   void enterReleased();
66
67  protected slots:
68    /// Called on text changed
69   virtual void onTextChanged(const QString&);
70
71  protected:
72    /// Removes extra trailing zero symbols
73   QString removeTrailingZeroes(const QString&) const;
74   /// Called on key press event
75   virtual void keyReleaseEvent(QKeyEvent* theEvent);
76
77   /// Called on key press event
78   virtual void keyPressEvent(QKeyEvent* theEvent);
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