Salome HOME
#1042 Sometimes when setting distance constraints, the input field is not displayed...
[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 class QKeyEvent;
15
16 /**
17 * \ingroup GUI
18 * An extension and customization of QDoubleSpinBox class
19 */
20 class MODULEBASE_EXPORT ModuleBase_DoubleSpinBox : public QDoubleSpinBox
21 {
22 Q_OBJECT
23
24  public:
25   explicit ModuleBase_DoubleSpinBox( QWidget* theParent = 0, int thePrecision = -12 );
26   virtual ~ModuleBase_DoubleSpinBox();
27
28   /// Returns true if the control is clear
29   bool isCleared() const;
30
31   /// Set control clear
32   virtual void setCleared(const bool);
33
34   /// Returns current precision
35   int getPrecision() const;
36
37   /// Set precision
38   void setPrecision(const int);
39
40   /// Set step
41   virtual void stepBy(int);
42
43   /// Converts value from string to double
44   virtual double valueFromText(const QString&) const;
45
46   /// Convert value from double to string
47   virtual QString textFromValue(double) const;
48
49   /// Validate current value
50   virtual QValidator::State validate(QString&, int&) const;
51
52   /// Returns true if the current value is modified by has not been applyed yet
53   //virtual bool isModified() const;
54
55   /// Clears modified state
56   //void clearModified();
57
58   /// Change enable/disable internal state to emit key press event
59   /// \param theEnable if true, the signal is emitted
60   /// \return the previous value
61   bool enableKeyPressEvent(const bool& theEnable);
62
63 signals:
64   /// The signal about key release on the control, that corresponds to the attribute
65   /// \param theEvent key release event
66   void enterPressed();
67   void enterReleased();
68
69  protected slots:
70    /// Called on text changed
71   virtual void onTextChanged(const QString&);
72   /// Called on value changed
73   //void onValueChanged(const QString& theValue);
74
75  protected:
76    /// Removes extra trailing zero symbols
77   QString removeTrailingZeroes(const QString&) const;
78   /// Called on key press event
79   virtual void keyReleaseEvent(QKeyEvent* theEvent);
80
81   /// Called on key press event
82   virtual void keyPressEvent(QKeyEvent* theEvent);
83
84  private:
85   // boolen flag whether the key event is emitted. The default value is false
86   bool myIsEmitKeyPressEvent;
87
88    /// Is clear flag
89   bool myCleared;
90
91   /// Precision value
92   int myPrecision;
93   /// Boolean value whether the spin box content is modified
94   //bool myIsModified;
95 };
96
97 #endif