From: stv Date: Thu, 23 Jun 2005 06:12:00 +0000 (+0000) Subject: Some minor improovements for spin boxes (update values before getting) X-Git-Tag: T3_0_0_a4~48 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b2b6a64de3a553d1847e53f305dd4e6bca7e8067;p=modules%2Fgui.git Some minor improovements for spin boxes (update values before getting) --- diff --git a/src/Qtx/QtxDblSpinBox.cxx b/src/Qtx/QtxDblSpinBox.cxx index 1a4405026..5c40e9d13 100755 --- a/src/Qtx/QtxDblSpinBox.cxx +++ b/src/Qtx/QtxDblSpinBox.cxx @@ -83,7 +83,7 @@ myPrecision( 0 ) rangeChange(); updateDisplay(); - //connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); + connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); } QtxDblSpinBox::QtxDblSpinBox( double min, double max, double step, QWidget* parent, const char* name ) @@ -100,7 +100,7 @@ myPrecision( 0 ) rangeChange(); updateDisplay(); - //connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); + connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); } QtxDblSpinBox::~QtxDblSpinBox() @@ -177,8 +177,8 @@ void QtxDblSpinBox::setLineStep( double step ) double QtxDblSpinBox::value() const { - QtxDblSpinBox* _this = ( QtxDblSpinBox* )this; - _this->clearFocus(); + QSpinBox::value(); + return myValue; } @@ -273,7 +273,10 @@ void QtxDblSpinBox::updateDisplay() { if ( myBlocked ) return; - + + bool upd = editor()->isUpdatesEnabled(); + editor()->setUpdatesEnabled( false ); + bool isBlock = myBlocked; myBlocked = true; @@ -285,11 +288,20 @@ void QtxDblSpinBox::updateDisplay() QSpinBox::setValue( QSpinBox::minValue() ); else QSpinBox::setValue( ( QSpinBox::minValue() + QSpinBox::maxValue() ) / 2 ); - + QSpinBox::updateDisplay(); - + + editor()->setUpdatesEnabled( upd ); + editor()->setText( myCleared ? QString::null : txt ); - + if ( !myCleared ) + { + if ( editor()->text() == specialValueText() ) + editor()->selectAll(); + else + editor()->setSelection( prefix().length(), editor()->text().length() - prefix().length() - suffix().length() ); + } + myBlocked = isBlock; } @@ -320,7 +332,7 @@ void QtxDblSpinBox::interpretText() void QtxDblSpinBox::valueChange() { updateDisplay(); - emit valueChanged( value() ); + emit valueChanged( myValue ); emit valueChanged( currentValueText() ); } @@ -409,8 +421,6 @@ void QtxDblSpinBox::wheelEvent( QWheelEvent* e ) void QtxDblSpinBox::onTextChanged( const QString& str ) { - bool isBlock = myBlocked; - myBlocked = true; - interpretText(); - myBlocked = isBlock; + if ( !myBlocked ) + myCleared = false; } diff --git a/src/Qtx/QtxDblSpinBox.h b/src/Qtx/QtxDblSpinBox.h index c905bcddc..eea959f7a 100755 --- a/src/Qtx/QtxDblSpinBox.h +++ b/src/Qtx/QtxDblSpinBox.h @@ -29,25 +29,25 @@ public: void setMinValue( double ); void setMaxValue( double ); void setRange( int, int ); - void setRange( double, double ); + virtual void setRange( double, double ); double lineStep() const; void setLineStep( int ); - void setLineStep( double ); + virtual void setLineStep( double ); double value() const; int precision() const; - void setPrecision( const int ); + virtual void setPrecision( const int ); bool isCleared() const; - void setCleared( const bool ); + virtual void setCleared( const bool ); virtual bool eventFilter( QObject*, QEvent* ); signals: void valueChanged( double ); - void valueChanged( const QString& ); + void valueChanged( const QString& ); public slots: virtual void stepUp(); diff --git a/src/Qtx/QtxIntSpinBox.cxx b/src/Qtx/QtxIntSpinBox.cxx index f94c951aa..261266746 100755 --- a/src/Qtx/QtxIntSpinBox.cxx +++ b/src/Qtx/QtxIntSpinBox.cxx @@ -8,14 +8,18 @@ QtxIntSpinBox::QtxIntSpinBox( QWidget* parent, const char* name ) : QSpinBox( parent, name ), -myCleared( false ) +myCleared( false ), +myBlocked( false ) { + connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); } QtxIntSpinBox::QtxIntSpinBox( int min, int max, int step, QWidget* parent, const char* name ) : QSpinBox( min, max, step, parent, name ), -myCleared( false ) +myCleared( false ), +myBlocked( false ) { + connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); } QtxIntSpinBox::~QtxIntSpinBox() @@ -24,66 +28,90 @@ QtxIntSpinBox::~QtxIntSpinBox() bool QtxIntSpinBox::isCleared() const { - return myCleared; + return myCleared; } void QtxIntSpinBox::setCleared( const bool on ) { - if ( myCleared == on ) - return; + if ( myCleared == on ) + return; - myCleared = on; - updateDisplay(); + myCleared = on; + updateDisplay(); } void QtxIntSpinBox::setValue( int value ) { - myCleared = false; - QSpinBox::setValue( value ); + myCleared = false; + + QSpinBox::setValue( value ); } bool QtxIntSpinBox::eventFilter( QObject* o, QEvent* e ) { - if ( !myCleared || o != editor() || !editor()->text().stripWhiteSpace().isEmpty() ) - return QSpinBox::eventFilter( o, e ); + if ( !myCleared || o != editor() || !editor()->text().stripWhiteSpace().isEmpty() ) + return QSpinBox::eventFilter( o, e ); - if ( e->type() == QEvent::FocusOut || e->type() == QEvent::Leave || e->type() == QEvent::Hide ) - return false; + if ( e->type() == QEvent::FocusOut || e->type() == QEvent::Leave || e->type() == QEvent::Hide ) + return false; - if ( e->type() == QEvent::KeyPress && + if ( e->type() == QEvent::KeyPress && ( ((QKeyEvent*)e)->key() == Key_Tab || ((QKeyEvent*)e)->key() == Key_BackTab ) ) - { - QApplication::sendEvent( this, e ); - return true; - } + { + QApplication::sendEvent( this, e ); + return true; + } - return QSpinBox::eventFilter( o, e ); + return QSpinBox::eventFilter( o, e ); } void QtxIntSpinBox::interpretText() { - myCleared = false; - QSpinBox::interpretText(); + myCleared = false; + + QSpinBox::interpretText(); } void QtxIntSpinBox::updateDisplay() { - QSpinBox::updateDisplay(); - if ( myCleared ) - editor()->clear(); + if ( myBlocked ) + return; + + bool block = myBlocked; + myBlocked = true; + + QSpinBox::updateDisplay(); + + if ( myCleared ) + editor()->clear(); + else + { + if ( editor()->text() == specialValueText() ) + editor()->selectAll(); + else + editor()->setSelection( prefix().length(), editor()->text().length() - prefix().length() - suffix().length() ); + } + + myBlocked = block; } void QtxIntSpinBox::leaveEvent( QEvent* e ) { - if ( !myCleared ) - QSpinBox::leaveEvent( e ); + if ( !myCleared ) + QSpinBox::leaveEvent( e ); } void QtxIntSpinBox::wheelEvent( QWheelEvent* e ) { - if ( !isEnabled() ) - return; + if ( !isEnabled() ) + return; - QSpinBox::wheelEvent( e ); - updateDisplay(); + QSpinBox::wheelEvent( e ); + updateDisplay(); +} + +void QtxIntSpinBox::onTextChanged( const QString& ) +{ + if ( !myBlocked ) + myCleared = false; } diff --git a/src/Qtx/QtxIntSpinBox.h b/src/Qtx/QtxIntSpinBox.h index 60fb0e695..a8227b04b 100755 --- a/src/Qtx/QtxIntSpinBox.h +++ b/src/Qtx/QtxIntSpinBox.h @@ -13,26 +13,30 @@ class QTX_EXPORT QtxIntSpinBox : public QSpinBox Q_OBJECT public: - QtxIntSpinBox( QWidget* = 0, const char* = 0 ); - QtxIntSpinBox( int, int, int = 1, QWidget* = 0, const char* = 0 ); - virtual ~QtxIntSpinBox(); + QtxIntSpinBox( QWidget* = 0, const char* = 0 ); + QtxIntSpinBox( int, int, int = 1, QWidget* = 0, const char* = 0 ); + virtual ~QtxIntSpinBox(); - bool isCleared() const; - void setCleared( const bool ); + bool isCleared() const; + virtual void setCleared( const bool ); - virtual bool eventFilter( QObject*, QEvent* ); + virtual bool eventFilter( QObject*, QEvent* ); public slots: - virtual void setValue( int ); - + virtual void setValue( int ); + +protected slots: + virtual void onTextChanged( const QString& ); + protected: - virtual void interpretText(); - virtual void updateDisplay(); - virtual void leaveEvent( QEvent* ); - virtual void wheelEvent( QWheelEvent* ); + virtual void interpretText(); + virtual void updateDisplay(); + virtual void leaveEvent( QEvent* ); + virtual void wheelEvent( QWheelEvent* ); private: - bool myCleared; + bool myCleared; + bool myBlocked; }; #endif