16 #include <qlineedit.h> 17 #include <qvalidator.h> 75 QHBoxLayout *layout =
new QHBoxLayout(
this );
76 layout->setSpacing( 0 );
77 layout->setContentsMargins( QMargins() );
79 for (
int i =
ButtonCnt - 1; i >= 0; i-- )
83 btn->setFocusPolicy( Qt::NoFocus );
84 layout->addWidget( btn );
86 connect( btn, SIGNAL(released()), SLOT(
btnReleased()) );
87 connect( btn, SIGNAL(clicked()), SLOT(
btnClicked()) );
105 btn->setFocusPolicy( Qt::NoFocus );
106 layout->addWidget( btn );
108 connect( btn, SIGNAL(released()), SLOT(
btnReleased()) );
109 connect( btn, SIGNAL(clicked()), SLOT(
btnClicked()) );
120 QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ) );
123 setFocusPolicy( Qt::StrongFocus );
207 value = qBound( vmin, value, vmax );
369 if ( i < numButtons )
473 bool converted =
false;
487 if ( event->type() == QEvent::PolishRequest )
499 return QWidget::event( event );
526 bool accepted =
true;
528 switch ( event->key() )
532 if ( event->modifiers() & Qt::ControlModifier )
540 if ( event->modifiers() & Qt::ControlModifier )
557 case Qt::Key_PageDown:
564 if ( event->modifiers() & Qt::ShiftModifier )
567 if ( event->key() == Qt::Key_PageDown )
568 increment = -increment;
584 QWidget::keyPressEvent ( event );
601 if ( event->modifiers() & Qt::ControlModifier )
606 if ( event->modifiers() & Qt::ShiftModifier )
610 #if QT_VERSION < 0x050e00 611 const QPoint wheelPos =
event->pos();
612 const int wheelDelta =
event->delta();
614 const QPoint wheelPos =
event->position().toPoint();
616 const QPoint delta =
event->angleDelta();
617 const int wheelDelta = ( qAbs( delta.x() ) > qAbs( delta.y() ) )
618 ? delta.x() : delta.y();
644 stepSize =
qwtMaxF( stepSize, 1.0e-10 * ( max - min ) );
651 const double range = max -
min;
655 value += std::ceil( ( min - value ) / range ) * range;
657 else if ( value > max )
659 value -= std::ceil( ( value - max ) / range ) * range;
664 value = qBound( min, value, max );
667 value = min + qRound( ( value - min ) / stepSize ) * stepSize;
669 if ( stepSize > 1e-12 )
671 if ( qFuzzyCompare( value + 1.0, 1.0 ) )
676 else if ( qFuzzyCompare( value, max ) )
732 text.setNum( number );
763 int w = tmp.setNum(
minimum() ).length();
764 int w1 = tmp.setNum(
maximum() ).length();
779 w += 2 * style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
784 w += QWidget::sizeHint().width() -
d_data->
valueEdit->sizeHint().width();
786 const int h = qMin( QWidget::sizeHint().height(),
789 return QSize( w, h );
793 #include "moc_qwt_counter.cpp"
void textChanged()
Set from lineedit.
QwtArrowButton * buttonUp[ButtonCnt]
void valueChanged(double value)
void btnClicked()
Button clicked.
virtual ~QwtCounter()
Destructor.
virtual void keyPressEvent(QKeyEvent *) QWT_OVERRIDE
QwtArrowButton * buttonDown[ButtonCnt]
void buttonReleased(double value)
QWT_CONSTEXPR float qwtMaxF(float a, float b)
void setStepButton1(int nSteps)
void setWrapping(bool)
En/Disable wrapping.
void setStepButton2(int nSteps)
void incrementValue(int numSteps)
Button intended for medium steps.
Button intended for minor steps.
QWT_CONSTEXPR float qwtMinF(float a, float b)
void updateButtons()
Update buttons according to the current value.
virtual QSize sizeHint() const QWT_OVERRIDE
A size hint.
static int horizontalAdvance(const QFontMetrics &, const QString &)
virtual void wheelEvent(QWheelEvent *) QWT_OVERRIDE
void setRange(double min, double max)
Set the minimum and maximum values.
void setIncSteps(QwtCounter::Button, int numSteps)
Button intended for large steps.
virtual bool event(QEvent *) QWT_OVERRIDE
void setValue(double)
Set a new value without adjusting to the step raster.
void setSingleStep(double stepSize)
Set the step size of the counter.
void btnReleased()
Button released.
int incSteps(QwtCounter::Button) const
void setReadOnly(bool)
Allow/disallow the user to manually edit the value.
void setStepButton3(int nSteps)
double singleStep() const
QwtCounter(QWidget *parent=NULL)