#include "QtxIntSpinBox.h"
-#include <qlineedit.h>
-#include <qapplication.h>
+#include <QLineEdit>
+//#include <QApplication>
/*!
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& ) ) );
}
/*!
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 );
}
/*!
*/
void QtxIntSpinBox::onTextChanged( const QString& )
{
- if ( !myBlocked )
- myCleared = false;
+ myCleared = false;
}
#include "Qtx.h"
-#include <qspinbox.h>
+#include <QSpinBox>
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