Salome HOME
NRI : Merge from V1_2.
[modules/kernel.git] / src / SALOMEGUI / QAD_SpinBoxDbl.h
1 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : QAD_SpinBoxDbl.h
8 //  Author : Vadim SANDLER
9 //  Module : SALOME
10 //  $Header$
11
12 #ifndef QAD_SPINBOXDBL_H
13 #define QAD_SPINBOXDBL_H
14
15 #include "QAD.h"
16 #include <qframe.h>
17
18 class QAD_EXPORT QDblRangeControl
19 {
20 public:
21   QDblRangeControl();
22   QDblRangeControl( double minValue, double maxValue,
23                     double lineStep, double pageStep, 
24                     double value,
25                     int    precision = 6, 
26                     double dblPrecision = 1e-6,
27                     char   cFlag = 'g');
28   virtual       ~QDblRangeControl();
29   double        value() const;
30   void          setValue( double );
31   void          addPage();
32   void          subtractPage();
33   void          addLine();
34   void          subtractLine();
35                 
36   double        minValue()  const;
37   double        maxValue()  const;
38   void          setRange( double minValue, double maxValue );
39   void          setMinValue( double minVal );
40   void          setMaxValue( double minVal );
41                 
42   double        lineStep()  const;
43   double        pageStep()  const;
44   void          setSteps( double line, double page );
45                 
46   int           precision() const;
47   void          setPrecision( int precision );
48   double        dblPrecision() const;
49   void          setDblPrecision( double dblPrecision );
50   char          convertFlag() const;
51   void          setConvertFlag( char cFlag );
52
53   double        bound( double ) const;
54   
55 protected:
56   void          directSetValue( double val );
57   double        prevValue()  const;
58   
59   virtual void  valueChange();
60   virtual void  rangeChange();
61   virtual void  stepChange();
62   bool          equal( double first, double second ) const;
63   double        roundPrecision( double value) const;
64   
65 private:
66   double        minVal, maxVal;
67   double        line,   page;
68   double        val,    prevVal;
69   int           prec;
70   double        dblPrec;
71   char          convFlag;
72   
73 private:  // Disabled copy constructor and operator=
74 #if defined(Q_DISABLE_COPY)
75   QDblRangeControl( const QDblRangeControl & );
76   QDblRangeControl &operator=( const QDblRangeControl & );
77 #endif
78 };
79
80 class QPushButton;
81 class QLineEdit;
82 class QValidator;
83
84 class QAD_EXPORT QAD_SpinBoxDbl: public QFrame, public QDblRangeControl
85 {
86   Q_OBJECT
87
88 public:
89   QAD_SpinBoxDbl( QWidget* parent, const char* name = 0 );
90   QAD_SpinBoxDbl( QWidget*    parent, 
91                   double      minValue, 
92                   double      maxValue, 
93                   double      step, 
94                   int         precision = 6, 
95                   double      dblPrecision = 1e-6,
96                   char        cFlag = 'g',
97                   const char* name = 0 );
98   ~QAD_SpinBoxDbl();
99
100   QString           text() const;
101   
102   virtual QString   prefix() const;
103   virtual QString   suffix() const;
104   virtual QString   cleanText() const;
105
106   virtual void      setSpecialValueText( const QString &text );
107   QString           specialValueText() const;
108   
109   virtual void      setWrapping( bool on );
110   bool              wrapping() const;
111   
112   enum ButtonSymbols { UpDownArrows, PlusMinus };
113   void              setButtonSymbols( ButtonSymbols ); 
114   ButtonSymbols     buttonSymbols() const;
115   
116   virtual void      setValidator( const QValidator* v );
117   const QValidator* validator() const;
118   
119   QSize             sizeHint() const;
120   
121   double            minValue();
122   double            maxValue();
123   void              setMinValue( double );
124   void              setMaxValue( double );
125   double            lineStep();
126   void              setLineStep( double );
127   double            value();
128                     
129 public slots:
130   virtual void      setValue( double );
131   virtual void      setPrefix( const QString &text );
132   virtual void      setSuffix( const QString &text );
133   virtual void      stepUp();
134   virtual void      stepDown();
135   virtual void      setEnabled( bool );
136   virtual void      selectAll();
137                     
138 signals:            
139   void              valueChanged( double value );
140   void              valueChanged( const QString &valueText );
141
142 protected:          
143   virtual QString   mapValueToText( double value );
144   virtual double    mapTextToValue( bool* ok );
145   QString           currentValueText();
146   
147   virtual void      updateDisplay();
148   virtual void      interpretText();
149   
150   QPushButton*      upButton() const;
151   QPushButton*      downButton() const;
152   QLineEdit*        editor() const;
153   
154   virtual void      valueChange();
155   virtual void      rangeChange();
156   
157   bool              eventFilter( QObject* obj, QEvent* ev );
158   void              resizeEvent( QResizeEvent* ev );
159   void              wheelEvent( QWheelEvent * );
160   void              leaveEvent( QEvent* );
161   
162   void              styleChange( QStyle& );
163   
164 protected slots:
165   void              textChanged();
166   
167 private:
168   void              initSpinBox();
169
170   ButtonSymbols     butSymbols;
171   QPushButton*      up;
172   QPushButton*      down;
173   QLineEdit*        vi;
174   QValidator*       validate;
175   QString           pfix;
176   QString           sfix;
177   QString           specText;
178   bool              wrap;
179   bool              edited;
180   bool              selreq;
181   
182   void              arrangeWidgets();
183   void              updateButtonSymbols();
184   
185   private:  // Disabled copy constructor and operator=
186 #if defined(Q_DISABLE_COPY)
187     QAD_SpinBoxDbl( const QAD_SpinBoxDbl& );
188     QAD_SpinBoxDbl& operator=( const QAD_SpinBoxDbl& );
189 #endif
190     
191 };                  
192
193 #endif