1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 // File: QtxIntSpinBox.cxx
20 // Author: Sergey TELKOV
22 #include "QtxIntSpinBox.h"
24 #include <qlineedit.h>
25 #include <qapplication.h>
27 QtxIntSpinBox::QtxIntSpinBox( QWidget* parent, const char* name )
28 : QSpinBox( parent, name ),
32 connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) );
35 QtxIntSpinBox::QtxIntSpinBox( int min, int max, int step, QWidget* parent, const char* name )
36 : QSpinBox( min, max, step, parent, name ),
40 connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) );
43 QtxIntSpinBox::~QtxIntSpinBox()
47 bool QtxIntSpinBox::isCleared() const
52 void QtxIntSpinBox::setCleared( const bool on )
54 if ( myCleared == on )
61 void QtxIntSpinBox::setValue( int value )
65 QSpinBox::setValue( value );
68 bool QtxIntSpinBox::eventFilter( QObject* o, QEvent* e )
70 if ( !myCleared || o != editor() || !editor()->text().stripWhiteSpace().isEmpty() )
71 return QSpinBox::eventFilter( o, e );
73 if ( e->type() == QEvent::FocusOut || e->type() == QEvent::Leave || e->type() == QEvent::Hide )
76 if ( e->type() == QEvent::KeyPress &&
77 ( ((QKeyEvent*)e)->key() == Key_Tab || ((QKeyEvent*)e)->key() == Key_BackTab ) )
79 QApplication::sendEvent( this, e );
83 return QSpinBox::eventFilter( o, e );
86 void QtxIntSpinBox::interpretText()
90 QSpinBox::interpretText();
93 void QtxIntSpinBox::updateDisplay()
98 bool block = myBlocked;
101 QSpinBox::updateDisplay();
105 else if ( editor()->hasFocus() )
107 if ( editor()->text() == specialValueText() )
108 editor()->selectAll();
110 editor()->setSelection( prefix().length(), editor()->text().length() - prefix().length() - suffix().length() );
116 void QtxIntSpinBox::leaveEvent( QEvent* e )
119 QSpinBox::leaveEvent( e );
122 void QtxIntSpinBox::wheelEvent( QWheelEvent* e )
127 QSpinBox::wheelEvent( e );
131 void QtxIntSpinBox::onTextChanged( const QString& )