From ca7709ff32eb73c38ee389b6b425d3cb04e595e8 Mon Sep 17 00:00:00 2001 From: stv Date: Thu, 31 May 2007 08:10:46 +0000 Subject: [PATCH] no message --- src/Qtx/QtxIntSpinBox.cxx | 115 +++++++------------------------------- src/Qtx/QtxIntSpinBox.h | 29 ++++------ 2 files changed, 30 insertions(+), 114 deletions(-) diff --git a/src/Qtx/QtxIntSpinBox.cxx b/src/Qtx/QtxIntSpinBox.cxx index e002377e6..d8d4e1858 100755 --- a/src/Qtx/QtxIntSpinBox.cxx +++ b/src/Qtx/QtxIntSpinBox.cxx @@ -21,29 +21,30 @@ #include "QtxIntSpinBox.h" -#include -#include +#include +//#include /*! Constructor */ -QtxIntSpinBox::QtxIntSpinBox( QWidget* parent, const char* name ) -: QSpinBox( parent, name ), -myCleared( false ), -myBlocked( false ) +QtxIntSpinBox::QtxIntSpinBox( QWidget* parent ) +: QSpinBox( parent ), +myCleared( false ) { - connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); + connect( lineEdit(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); } /*! Constructor */ -QtxIntSpinBox::QtxIntSpinBox( int min, int max, int step, QWidget* parent, const char* name ) -: QSpinBox( min, max, step, parent, name ), -myCleared( false ), -myBlocked( false ) +QtxIntSpinBox::QtxIntSpinBox( int min, int max, int step, QWidget* parent ) +: QSpinBox( parent ), +myCleared( false ) { - connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); + setMinimum( min ); + setMaximum( max ); + setSingleStep( step ); + connect( lineEdit(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); } /*! @@ -71,96 +72,19 @@ void QtxIntSpinBox::setCleared( const bool on ) return; myCleared = on; - updateDisplay(); + setSpecialValueText( specialValueText() ); } -/*! - Changes value of spin box - \param val - new value of spin box -*/ -void QtxIntSpinBox::setValue( int value ) +QString QtxIntSpinBox::textFromValue( int val ) const { - myCleared = false; - - QSpinBox::setValue( value ); + return myCleared ? QString() : QSpinBox::textFromValue( val ); } -/*! - Custom event filter -*/ -bool QtxIntSpinBox::eventFilter( QObject* o, QEvent* 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::KeyPress && - ( ((QKeyEvent*)e)->key() == Key_Tab || ((QKeyEvent*)e)->key() == Key_BackTab ) ) - { - QApplication::sendEvent( this, e ); - return true; - } - - return QSpinBox::eventFilter( o, e ); -} - -/*! - Sets integer value by text in editor -*/ -void QtxIntSpinBox::interpretText() +void QtxIntSpinBox::stepBy( int steps ) { myCleared = false; - QSpinBox::interpretText(); -} - -/*! - Updates text of editor -*/ -void QtxIntSpinBox::updateDisplay() -{ - if ( myBlocked ) - return; - - bool block = myBlocked; - myBlocked = true; - - QSpinBox::updateDisplay(); - - if ( myCleared ) - editor()->clear(); - else if ( editor()->hasFocus() ) - { - if ( editor()->text() == specialValueText() ) - editor()->selectAll(); - else - editor()->setSelection( prefix().length(), editor()->text().length() - prefix().length() - suffix().length() ); - } - - myBlocked = block; -} - -/*! - Custom handler for leave event -*/ -void QtxIntSpinBox::leaveEvent( QEvent* e ) -{ - if ( !myCleared ) - QSpinBox::leaveEvent( e ); -} - -/*! - Custom handler for wheel event -*/ -void QtxIntSpinBox::wheelEvent( QWheelEvent* e ) -{ - if ( !isEnabled() ) - return; - - QSpinBox::wheelEvent( e ); - updateDisplay(); + QSpinBox::stepBy( steps ); } /*! @@ -168,6 +92,5 @@ void QtxIntSpinBox::wheelEvent( QWheelEvent* e ) */ void QtxIntSpinBox::onTextChanged( const QString& ) { - if ( !myBlocked ) - myCleared = false; + myCleared = false; } diff --git a/src/Qtx/QtxIntSpinBox.h b/src/Qtx/QtxIntSpinBox.h index 7f083d519..31580a1d8 100755 --- a/src/Qtx/QtxIntSpinBox.h +++ b/src/Qtx/QtxIntSpinBox.h @@ -24,37 +24,30 @@ #include "Qtx.h" -#include +#include class QTX_EXPORT QtxIntSpinBox : public QSpinBox { - Q_OBJECT + Q_OBJECT public: - QtxIntSpinBox( QWidget* = 0, const char* = 0 ); - QtxIntSpinBox( int, int, int = 1, QWidget* = 0, const char* = 0 ); + QtxIntSpinBox( QWidget* = 0 ); + QtxIntSpinBox( int, int, int = 1, QWidget* = 0 ); virtual ~QtxIntSpinBox(); - bool isCleared() const; - virtual void setCleared( const bool ); + bool isCleared() const; + virtual void setCleared( const bool ); - virtual bool eventFilter( QObject*, QEvent* ); - -public slots: - virtual void setValue( int ); - + virtual void stepBy( int ); + protected slots: - virtual void onTextChanged( const QString& ); + virtual void onTextChanged( const QString& ); protected: - virtual void interpretText(); - virtual void updateDisplay(); - virtual void leaveEvent( QEvent* ); - virtual void wheelEvent( QWheelEvent* ); + virtual QString textFromValue( int ) const; private: - bool myCleared; - bool myBlocked; + bool myCleared; }; #endif -- 2.39.2