10#include "qwt_abstract_slider.h" 
   11#include "qwt_scale_map.h" 
   12#include "qwt_scale_div.h" 
   17static double qwtAlignToScaleDiv(
 
   22    const int tValue = slider->
transform( value );
 
   33        for ( 
int j = 0; j < ticks.size(); j++ )
 
   35            if ( slider->
transform( ticks[ j ] ) == tValue )
 
   43class QwtAbstractSlider::PrivateData
 
   47        : isScrolling( false )
 
   49        , pendingValueChanged( false )
 
   54        , stepAlignment( true )
 
   58        , invertedControls( false )
 
   64    bool pendingValueChanged;
 
   77    bool invertedControls;
 
   94    m_data = 
new QwtAbstractSlider::PrivateData;
 
   97    setFocusPolicy( Qt::StrongFocus );
 
 
  115    if ( on != m_data->isValid )
 
  117        m_data->isValid = on;
 
 
  127    return m_data->isValid;
 
 
  143    if ( m_data->readOnly != on )
 
  145        m_data->readOnly = on;
 
  146        setFocusPolicy( on ? Qt::StrongFocus : Qt::NoFocus );
 
 
  161    return m_data->readOnly;
 
 
  179    m_data->isTracking = on;
 
 
  188    return m_data->isTracking;
 
 
  208    if ( m_data->isScrolling )
 
  210        m_data->pendingValueChanged = 
false;
 
 
  228    if ( m_data->isValid && m_data->isScrolling )
 
  231        if ( 
value != m_data->value )
 
  235            if ( m_data->stepAlignment )
 
  244            if ( 
value != m_data->value )
 
  246                m_data->value = 
value;
 
  252                if ( m_data->isTracking )
 
  255                    m_data->pendingValueChanged = 
true;
 
 
  273    if ( m_data->isScrolling && m_data->isValid )
 
  275        m_data->isScrolling = 
false;
 
  277        if ( m_data->pendingValueChanged )
 
 
  304    if ( !m_data->isValid || m_data->isScrolling )
 
  307#if QT_VERSION < 0x050000 
  308    const int wheelDelta = 
event->delta();
 
  310    const QPoint delta = 
event->angleDelta();
 
  311    const int wheelDelta = ( qAbs( delta.x() ) > qAbs( delta.y() ) )
 
  312        ? delta.x() : delta.y();
 
  317    if ( ( event->modifiers() & Qt::ControlModifier ) ||
 
  318        ( 
event->modifiers() & Qt::ShiftModifier ) )
 
  321        numSteps = m_data->pageSteps;
 
  322        if ( wheelDelta < 0 )
 
  323            numSteps = -numSteps;
 
  327        const int numTurns = ( wheelDelta / 120 );
 
  328        numSteps = numTurns * m_data->singleSteps;
 
  331    if ( m_data->invertedControls )
 
  332        numSteps = -numSteps;
 
  335    if ( 
value != m_data->value )
 
  337        m_data->value = 
value;
 
 
  378    if ( !m_data->isValid || m_data->isScrolling )
 
  382    double value = m_data->value;
 
  384    switch ( event->key() )
 
  388            numSteps = -
static_cast< int >( m_data->singleSteps );
 
  390                numSteps = -numSteps;
 
  396            numSteps = m_data->singleSteps;
 
  398                numSteps = -numSteps;
 
  404            numSteps = -
static_cast< int >( m_data->singleSteps );
 
  405            if ( m_data->invertedControls )
 
  406                numSteps = -numSteps;
 
  411            numSteps = m_data->singleSteps;
 
  412            if ( m_data->invertedControls )
 
  413                numSteps = -numSteps;
 
  419            numSteps = m_data->pageSteps;
 
  420            if ( m_data->invertedControls )
 
  421                numSteps = -numSteps;
 
  424        case Qt::Key_PageDown:
 
  426            numSteps = -
static_cast< int >( m_data->pageSteps );
 
  427            if ( m_data->invertedControls )
 
  428                numSteps = -numSteps;
 
  452    if ( 
value != m_data->value )
 
  454        m_data->value = 
value;
 
 
  476    m_data->totalSteps = stepCount;
 
 
  485    return m_data->totalSteps;
 
 
  501    m_data->singleSteps = stepCount;
 
 
  510    return m_data->singleSteps;
 
 
  526    m_data->pageSteps = stepCount;
 
 
  535    return m_data->pageSteps;
 
 
  549    if ( on != m_data->stepAlignment )
 
  551        m_data->stepAlignment = on;
 
 
  561    return m_data->stepAlignment;
 
 
  574    const bool changed = ( m_data->value != 
value ) || !m_data->isValid;
 
  576    m_data->value = 
value;
 
  577    m_data->isValid = 
true;
 
 
  589    return m_data->value;
 
 
  601    m_data->wrapping = on;
 
 
  610    return m_data->wrapping;
 
 
  630    m_data->invertedControls = on;
 
 
  639    return m_data->invertedControls;
 
 
  653        m_data->value, stepCount );
 
  655    if ( 
value != m_data->value )
 
  657        m_data->value = 
value;
 
 
  671    double value, 
int stepCount )
 const 
  673    if ( m_data->totalSteps == 0 )
 
  679    if ( transformation == NULL )
 
  682        value += stepCount * range / m_data->totalSteps;
 
  694        const double stepSize = range / m_data->totalSteps;
 
  698        v = qRound( v / stepSize ) * stepSize;
 
  699        v += stepCount * range / m_data->totalSteps;
 
  706    if ( m_data->stepAlignment )
 
 
  712double QwtAbstractSlider::boundedValue( 
double value )
 const 
  717    if ( m_data->wrapping && vmin != vmax )
 
  719        if ( qFuzzyCompare( 
scaleMap().pDist(), 360.0 ) )
 
  723            if ( qFuzzyCompare( 
value, vmax ) )
 
  729                const double range = vmax - vmin;
 
  733                    value += std::ceil( ( vmin - 
value ) / range ) * range;
 
  735                else if ( 
value > vmax )
 
  737                    value -= std::ceil( ( 
value - vmax ) / range ) * range;
 
  745            else if ( 
value > vmax )
 
  757double QwtAbstractSlider::alignedValue( 
double value )
 const 
  759    if ( m_data->totalSteps == 0 )
 
  764    if ( 
scaleMap().transformation() == NULL )
 
  767        if ( stepSize > 0.0 )
 
  777        if ( stepSize > 0.0 )
 
  782                qRound( ( v - 
scaleMap().p1() ) / stepSize ) * stepSize;
 
  788    if ( qAbs( stepSize ) > 1e-12 )
 
  790        if ( qFuzzyCompare( 
value + 1.0, 1.0 ) )
 
  815    const bool changed = ( 
value != m_data->value );
 
  818        m_data->value = 
value;
 
  821    if ( m_data->isValid || changed )
 
 
  834#include "moc_qwt_abstract_slider.cpp" 
An abstract base class for widgets having a scale.
const QwtScaleMap & scaleMap() const
double lowerBound() const
const QwtScaleDiv & scaleDiv() const
int transform(double) const
double upperBound() const
void setScale(double lowerBound, double upperBound)
Specify a scale.
An abstract base class for slider widgets with a scale.
bool invertedControls() const
virtual void scaleChange() override
virtual void mouseReleaseEvent(QMouseEvent *) override
virtual ~QwtAbstractSlider()
Destructor.
virtual void sliderChange()
Calling update()
virtual void keyPressEvent(QKeyEvent *) override
void setTracking(bool)
Enables or disables tracking.
virtual void mousePressEvent(QMouseEvent *) override
void setTotalSteps(uint)
Set the number of steps.
void valueChanged(double value)
Notify a change of value.
void setValue(double value)
double incrementedValue(double value, int stepCount) const
void setStepAlignment(bool)
Enable step alignment.
void setInvertedControls(bool)
void incrementValue(int stepCount)
bool stepAlignment() const
virtual void mouseMoveEvent(QMouseEvent *) override
virtual void wheelEvent(QWheelEvent *) override
void setSingleSteps(uint)
Set the number of steps for a single increment.
double value() const
Returns the current value.
void setPageSteps(uint)
Set the number of steps for a page increment.
void sliderMoved(double value)
virtual bool isScrollPosition(const QPoint &pos) const =0
Determine what to do when the user presses a mouse button.
virtual double scrolledTo(const QPoint &pos) const =0
Determine the value for a new position of the movable part of the slider.
QwtAbstractSlider(QWidget *parent=NULL)
Constructor.
A class representing a scale division.
double lowerBound() const
double upperBound() const
QList< double > ticks(int tickType) const
@ NTickTypes
Number of valid tick types.
double transform(double s) const
const QwtTransform * transformation() const
Get the transformation.
void setPaintInterval(double p1, double p2)
Specify the borders of the paint device interval.
double invTransform(double p) const