Skip to content
qwt_abstract_slider.h 4.3 KiB
Newer Older
pixhawk's avatar
pixhawk committed
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
pixhawk's avatar
pixhawk committed
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#ifndef QWT_ABSTRACT_SLIDER_H
#define QWT_ABSTRACT_SLIDER_H

#include "qwt_global.h"
Bryant's avatar
Bryant committed
#include "qwt_abstract_scale.h"
pixhawk's avatar
pixhawk committed

/*!
Bryant's avatar
Bryant committed
  \brief An abstract base class for slider widgets with a scale

  A slider widget displays a value according to a scale.
  The class is designed as a common super class for widgets like 
  QwtKnob, QwtDial and QwtSlider.

  When the slider is nor readOnly() its value can be modified 
  by keyboard, mouse and wheel inputs. 

  The range of the slider is divided into a number of steps from
  which the value increments according to user inputs depend. 
  Only for linear scales the number of steps correspond with
  a fixed step size.
pixhawk's avatar
pixhawk committed
*/

Bryant's avatar
Bryant committed
class QWT_EXPORT QwtAbstractSlider: public QwtAbstractScale
pixhawk's avatar
pixhawk committed
{
Bryant's avatar
Bryant committed

    Q_PROPERTY( double value READ value WRITE setValue )

    Q_PROPERTY( uint totalSteps READ totalSteps WRITE setTotalSteps )
    Q_PROPERTY( uint singleSteps READ singleSteps WRITE setSingleSteps )
    Q_PROPERTY( uint pageSteps READ pageSteps WRITE setPageSteps )
    Q_PROPERTY( bool stepAlignment READ stepAlignment WRITE setStepAlignment )

pixhawk's avatar
pixhawk committed
    Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
Bryant's avatar
Bryant committed
    Q_PROPERTY( bool tracking READ isTracking WRITE setTracking )
    Q_PROPERTY( bool wrapping READ wrapping WRITE setWrapping )

    Q_PROPERTY( bool invertedControls READ invertedControls WRITE setInvertedControls )
pixhawk's avatar
pixhawk committed

public:
Bryant's avatar
Bryant committed
    explicit QwtAbstractSlider( QWidget *parent = NULL );
pixhawk's avatar
pixhawk committed
    virtual ~QwtAbstractSlider();

Bryant's avatar
Bryant committed
    void setValid( bool );
    bool isValid() const;
Bryant's avatar
Bryant committed
    double value() const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void setWrapping( bool );
    bool wrapping() const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void setTotalSteps( uint );
    uint totalSteps() const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void setSingleSteps( uint );
    uint singleSteps() const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void setPageSteps( uint );
    uint pageSteps() const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void setStepAlignment( bool ); 
    bool stepAlignment() const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void setTracking( bool );
    bool isTracking() const;

    void setReadOnly( bool );
    bool isReadOnly() const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void setInvertedControls( bool );
    bool invertedControls() const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
public Q_SLOTS:
    void setValue( double val );

Q_SIGNALS:
pixhawk's avatar
pixhawk committed

    /*!
      \brief Notify a change of value.

Bryant's avatar
Bryant committed
      When tracking is enabled (default setting), 
      this signal will be emitted every time the value changes. 

      \param value New value

      \sa setTracking(), sliderMoved()
pixhawk's avatar
pixhawk committed
    */
Bryant's avatar
Bryant committed
    void valueChanged( double value );
pixhawk's avatar
pixhawk committed

    /*!
      This signal is emitted when the user presses the
Bryant's avatar
Bryant committed
      movable part of the slider.
pixhawk's avatar
pixhawk committed
    */
    void sliderPressed();

    /*!
      This signal is emitted when the user releases the
pixhawk's avatar
pixhawk committed
      movable part of the slider.
    */
    void sliderReleased();
Bryant's avatar
Bryant committed

pixhawk's avatar
pixhawk committed
    /*!
      This signal is emitted when the user moves the
      slider with the mouse.
Bryant's avatar
Bryant committed

      \param value New value

      \sa valueChanged()
pixhawk's avatar
pixhawk committed
    */
Bryant's avatar
Bryant committed
    void sliderMoved( double value );
pixhawk's avatar
pixhawk committed
protected:
Bryant's avatar
Bryant committed
    virtual void mousePressEvent( QMouseEvent * );
    virtual void mouseReleaseEvent( QMouseEvent * );
    virtual void mouseMoveEvent( QMouseEvent * );
    virtual void keyPressEvent( QKeyEvent * );
    virtual void wheelEvent( QWheelEvent * );
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
      \brief Determine what to do when the user presses a mouse button.

      \param pos Mouse position
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
      \retval True, when pos is a valid scroll position
      \sa scrolledTo()
Bryant's avatar
Bryant committed
    virtual bool isScrollPosition( const QPoint &pos ) const = 0;

Bryant's avatar
Bryant committed
      \brief Determine the value for a new position of the
             movable part of the slider
Bryant's avatar
Bryant committed
      \param pos Mouse position

      \return Value for the mouse position
      \sa isScrollPosition()
Bryant's avatar
Bryant committed
    virtual double scrolledTo( const QPoint &pos ) const = 0;

    void incrementValue( int numSteps );
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    virtual void scaleChange();

protected:
    virtual void sliderChange();
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    double incrementedValue( 
        double value, int stepCount ) const;
pixhawk's avatar
pixhawk committed

private:
Bryant's avatar
Bryant committed
    double alignedValue( double ) const;
    double boundedValue( double ) const;
pixhawk's avatar
pixhawk committed

    class PrivateData;
    PrivateData *d_data;
};

#endif