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 )
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 QtxDblSpinBox::value() const
{
- QtxDblSpinBox* _this = ( QtxDblSpinBox* )this;
- _this->clearFocus();
+ QSpinBox::value();
+
return myValue;
}
{
if ( myBlocked )
return;
-
+
+ bool upd = editor()->isUpdatesEnabled();
+ editor()->setUpdatesEnabled( false );
+
bool isBlock = myBlocked;
myBlocked = true;
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;
}
void QtxDblSpinBox::valueChange()
{
updateDisplay();
- emit valueChanged( value() );
+ emit valueChanged( myValue );
emit valueChanged( currentValueText() );
}
void QtxDblSpinBox::onTextChanged( const QString& str )
{
- bool isBlock = myBlocked;
- myBlocked = true;
- interpretText();
- myBlocked = isBlock;
+ if ( !myBlocked )
+ myCleared = false;
}
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();
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()
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;
}
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