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>
30 QtxIntSpinBox::QtxIntSpinBox( QWidget* parent, const char* name )
31 : QSpinBox( parent, name ),
35 connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) );
41 QtxIntSpinBox::QtxIntSpinBox( int min, int max, int step, QWidget* parent, const char* name )
42 : QSpinBox( min, max, step, parent, name ),
46 connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) );
52 QtxIntSpinBox::~QtxIntSpinBox()
57 \return true if spin box is cleared
59 bool QtxIntSpinBox::isCleared() const
65 Changes cleared status of spin box
66 \param on - new status
68 void QtxIntSpinBox::setCleared( const bool on )
70 if ( myCleared == on )
78 Changes value of spin box
79 \param val - new value of spin box
81 void QtxIntSpinBox::setValue( int value )
85 QSpinBox::setValue( value );
91 bool QtxIntSpinBox::eventFilter( QObject* o, QEvent* e )
93 if ( !myCleared || o != editor() || !editor()->text().stripWhiteSpace().isEmpty() )
94 return QSpinBox::eventFilter( o, e );
96 if ( e->type() == QEvent::FocusOut || e->type() == QEvent::Leave || e->type() == QEvent::Hide )
99 if ( e->type() == QEvent::KeyPress &&
100 ( ((QKeyEvent*)e)->key() == Key_Tab || ((QKeyEvent*)e)->key() == Key_BackTab ) )
102 QApplication::sendEvent( this, e );
106 return QSpinBox::eventFilter( o, e );
110 Sets integer value by text in editor
112 void QtxIntSpinBox::interpretText()
116 QSpinBox::interpretText();
120 Updates text of editor
122 void QtxIntSpinBox::updateDisplay()
127 bool block = myBlocked;
130 QSpinBox::updateDisplay();
134 else if ( editor()->hasFocus() )
136 if ( editor()->text() == specialValueText() )
137 editor()->selectAll();
139 editor()->setSelection( prefix().length(), editor()->text().length() - prefix().length() - suffix().length() );
146 Custom handler for leave event
148 void QtxIntSpinBox::leaveEvent( QEvent* e )
151 QSpinBox::leaveEvent( e );
155 Custom handler for wheel event
157 void QtxIntSpinBox::wheelEvent( QWheelEvent* e )
162 QSpinBox::wheelEvent( e );
167 SLOT: called if text is changed
169 void QtxIntSpinBox::onTextChanged( const QString& )