Salome HOME
*** empty log message ***
[modules/gui.git] / src / Qtx / QtxIntSpinBox.cxx
1 // File:      QtxIntSpinBox.cxx
2 // Author:    Sergey TELKOV
3
4 #include "QtxIntSpinBox.h"
5
6 #include <qlineedit.h>
7 #include <qapplication.h>
8
9 QtxIntSpinBox::QtxIntSpinBox( QWidget* parent, const char* name )
10 : QSpinBox( parent, name ),
11 myCleared( false )
12 {
13 }
14
15 QtxIntSpinBox::QtxIntSpinBox( int min, int max, int step, QWidget* parent, const char* name )
16 : QSpinBox( min, max, step, parent, name ),
17 myCleared( false )
18 {
19 }
20
21 QtxIntSpinBox::~QtxIntSpinBox()
22 {
23 }
24
25 bool QtxIntSpinBox::isCleared() const
26 {
27     return myCleared;
28 }
29
30 void QtxIntSpinBox::setCleared( const bool on )
31 {
32     if ( myCleared == on )
33         return;
34     
35     myCleared = on;
36     updateDisplay();
37 }
38
39 void QtxIntSpinBox::setValue( int value )
40 {
41     myCleared = false;
42     QSpinBox::setValue( value );
43 }
44
45 bool QtxIntSpinBox::eventFilter( QObject* o, QEvent* e )
46 {
47     if ( !myCleared || o != editor() || !editor()->text().stripWhiteSpace().isEmpty() )
48         return QSpinBox::eventFilter( o, e );
49
50     if ( e->type() == QEvent::FocusOut || e->type() == QEvent::Leave || e->type() == QEvent::Hide )
51         return false;
52
53     if ( e->type() == QEvent::KeyPress &&
54              ( ((QKeyEvent*)e)->key() == Key_Tab || ((QKeyEvent*)e)->key() == Key_BackTab ) )
55     {
56         QApplication::sendEvent( this, e );
57         return true;
58     }
59
60     return QSpinBox::eventFilter( o, e );
61 }
62
63 void QtxIntSpinBox::interpretText()
64 {
65     myCleared = false;
66     QSpinBox::interpretText();
67 }
68
69 void QtxIntSpinBox::updateDisplay()
70 {
71     QSpinBox::updateDisplay();
72     if ( myCleared )
73         editor()->clear();
74 }
75
76 void QtxIntSpinBox::leaveEvent( QEvent* e )
77 {
78     if ( !myCleared )
79         QSpinBox::leaveEvent( e );
80 }
81
82 void QtxIntSpinBox::wheelEvent( QWheelEvent* e )
83 {
84     if ( !isEnabled() )
85         return;
86
87     QSpinBox::wheelEvent( e );
88     updateDisplay();
89 }