Skip to content
qwt_wheel.cpp 29.4 KiB
Newer Older
Bryant's avatar
Bryant committed
    {
        d_data->stepAlignment = on;
pixhawk's avatar
pixhawk committed
    }
}

Bryant's avatar
Bryant committed
/*!
  \return True, when the step alignment is enabled
  \sa setStepAlignment(), singleStep()
 */
bool QwtWheel::stepAlignment() const
pixhawk's avatar
pixhawk committed
{
Bryant's avatar
Bryant committed
    return d_data->stepAlignment;
pixhawk's avatar
pixhawk committed
}

Bryant's avatar
Bryant committed
/*!
  \brief Set the page step count  
    
  pageStepCount is a multiplicator for the single step size
  that typically corresponds to the user pressing PageUp or PageDown.
    
  A value of 0 disables page stepping. 

  The default value is 1.

  \param count Multiplicator for the single step size
  \sa pageStepCount(), setSingleStep()
 */
void QwtWheel::setPageStepCount( int count )
pixhawk's avatar
pixhawk committed
{
Bryant's avatar
Bryant committed
    d_data->pageStepCount = qMax( 0, count );
}
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
/*! 
  \return Page step count
  \sa setPageStepCount(), singleStep()
 */
int QwtWheel::pageStepCount() const
{
    return d_data->pageStepCount;
}
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
/*!
  \brief Set the minimum and maximum values

  The maximum is adjusted if necessary to ensure that the range remains valid.
  The value might be modified to be inside of the range.

  \param min Minimum value
  \param max Maximum value

  \sa minimum(), maximum()
 */
void QwtWheel::setRange( double min, double max )
{
    max = qMax( min, max );

    if ( d_data->minimum == min && d_data->maximum == max )
        return;

    d_data->minimum = min;
    d_data->maximum = max;

    if ( d_data->value < min || d_data->value > max )
    {
        d_data->value = qBound( min, d_data->value, max );

        update();
        Q_EMIT valueChanged( d_data->value );
    }
pixhawk's avatar
pixhawk committed
}
Bryant's avatar
Bryant committed
/*!
  Set the minimum value of the range
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
  \param value Minimum value
  \sa setRange(), setMaximum(), minimum()

  \note The maximum is adjusted if necessary to ensure that the range remains valid.
*/
void QwtWheel::setMinimum( double value )
pixhawk's avatar
pixhawk committed
{
Bryant's avatar
Bryant committed
    setRange( value, maximum() );
pixhawk's avatar
pixhawk committed
}

Bryant's avatar
Bryant committed
/*!
  \return The minimum of the range
  \sa setRange(), setMinimum(), maximum()
*/
double QwtWheel::minimum() const
{
    return d_data->minimum;
}
pixhawk's avatar
pixhawk committed

/*!
Bryant's avatar
Bryant committed
  Set the maximum value of the range

  \param value Maximum value
  \sa setRange(), setMinimum(), maximum()
pixhawk's avatar
pixhawk committed
*/
Bryant's avatar
Bryant committed
void QwtWheel::setMaximum( double value )
pixhawk's avatar
pixhawk committed
{
Bryant's avatar
Bryant committed
    setRange( minimum(), value );
}
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
/*!
  \return The maximum of the range
  \sa setRange(), setMaximum(), minimum()
*/
double QwtWheel::maximum() const
{
    return d_data->maximum;
pixhawk's avatar
pixhawk committed
}

/*!
Bryant's avatar
Bryant committed
  \brief Set a new value without adjusting to the step raster

  \param value New value
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
  \sa value(), valueChanged()
  \warning The value is clipped when it lies outside the range.
pixhawk's avatar
pixhawk committed
*/
Bryant's avatar
Bryant committed
void QwtWheel::setValue( double value )
pixhawk's avatar
pixhawk committed
{
Bryant's avatar
Bryant committed
    stopFlying();
    d_data->isScrolling = false;

    value = qBound( d_data->minimum, value, d_data->maximum );

    if ( d_data->value != value )
    {
        d_data->value = value;

        update();
        Q_EMIT valueChanged( d_data->value );
    }
pixhawk's avatar
pixhawk committed
}

/*!
Bryant's avatar
Bryant committed
  \return Current value of the wheel
  \sa setValue(), valueChanged()
 */
double QwtWheel::value() const
{
    return d_data->value;
}
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
/*!
  \brief En/Disable inverted appearance

  An inverted wheel increases its values in the opposite direction.
  The direction of an inverted horizontal wheel will be from right to left
  an inverted vertical wheel will increase from bottom to top.
  
  \param on En/Disable inverted appearance
  \sa isInverted()
 
 */
void QwtWheel::setInverted( bool on )
pixhawk's avatar
pixhawk committed
{
Bryant's avatar
Bryant committed
    if ( d_data->inverted != on )
    {
        d_data->inverted = on;
        update();
    }
pixhawk's avatar
pixhawk committed
}

/*!
Bryant's avatar
Bryant committed
  \return True, when the wheel is inverted
  \sa setInverted()
 */
bool QwtWheel::isInverted() const
pixhawk's avatar
pixhawk committed
{
Bryant's avatar
Bryant committed
    return d_data->inverted;
pixhawk's avatar
pixhawk committed
}

/*!
Bryant's avatar
Bryant committed
  \brief En/Disable wrapping

  If wrapping is true stepping up from maximum() value will take 
  you to the minimum() value and vice versa. 

  \param on En/Disable wrapping
  \sa wrapping()
 */
void QwtWheel::setWrapping( bool on )
{
    d_data->wrapping = on;
}

/*!
  \return True, when wrapping is set
  \sa setWrapping()
 */
bool QwtWheel::wrapping() const
{
    return d_data->wrapping;
}

/*!
  \brief Set the slider's mass for flywheel effect.

  If the slider's mass is greater then 0, it will continue
  to move after the mouse button has been released. Its speed
  decreases with time at a rate depending on the slider's mass.
  A large mass means that it will continue to move for a
  long time.

  Derived widgets may overload this function to make it public.

  \param mass New mass in kg

  \bug If the mass is smaller than 1g, it is set to zero.
       The maximal mass is limited to 100kg.
  \sa mass()
pixhawk's avatar
pixhawk committed
*/
Bryant's avatar
Bryant committed
void QwtWheel::setMass( double mass )
pixhawk's avatar
pixhawk committed
{
Bryant's avatar
Bryant committed
    if ( mass < 0.001 )
    {
        d_data->mass = 0.0;
    }
    else
    {
        d_data->mass = qMin( 100.0, mass );
    }

    if ( d_data->mass <= 0.0 )
        stopFlying();
pixhawk's avatar
pixhawk committed
}

/*!
Bryant's avatar
Bryant committed
  \return mass
  \sa setMass()
pixhawk's avatar
pixhawk committed
*/
Bryant's avatar
Bryant committed
double QwtWheel::mass() const
pixhawk's avatar
pixhawk committed
{
Bryant's avatar
Bryant committed
    return d_data->mass;
}

//!  Stop the flying movement of the wheel
void QwtWheel::stopFlying()
{
    if ( d_data->timerId != 0 )
    {
        killTimer( d_data->timerId );
        d_data->timerId = 0;
        d_data->speed = 0.0;
    }
}

double QwtWheel::boundedValue( double value ) const
{
    const double range = d_data->maximum - d_data->minimum;
    
    if ( d_data->wrapping && range >= 0.0 )
    {
        if ( value < d_data->minimum )
        {
            value += ::ceil( ( d_data->minimum - value ) / range ) * range;
        }       
        else if ( value > d_data->maximum )
        {
            value -= ::ceil( ( value - d_data->maximum ) / range ) * range;
        }
    }
    else
    {
        value = qBound( d_data->minimum, value, d_data->maximum );
    }

    return value;
}

double QwtWheel::alignedValue( double value ) const
{
    const double stepSize = d_data->singleStep;

    if ( stepSize > 0.0 )
    {
        value = d_data->minimum +
            qRound( ( value - d_data->minimum ) / stepSize ) * stepSize;

        if ( stepSize > 1e-12 )
        {
            if ( qFuzzyCompare( value + 1.0, 1.0 ) )
            {
                // correct rounding error if value = 0
                value = 0.0;
            }
            else if ( qFuzzyCompare( value, d_data->maximum ) )
            {
                // correct rounding error at the border
                value = d_data->maximum;
            }
        }
    }       

    return value;
pixhawk's avatar
pixhawk committed
}