qwt_abstract_slider.h 4.3 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
5
 *
pixhawk's avatar
pixhawk committed
6 7 8 9 10 11 12 13
 * 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
14
#include "qwt_abstract_scale.h"
pixhawk's avatar
pixhawk committed
15 16

/*!
Bryant's avatar
Bryant committed
17 18 19 20 21 22 23 24 25 26 27 28 29
  \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
30 31
*/

Bryant's avatar
Bryant committed
32
class QWT_EXPORT QwtAbstractSlider: public QwtAbstractScale
pixhawk's avatar
pixhawk committed
33
{
34
    Q_OBJECT
Bryant's avatar
Bryant committed
35 36 37 38 39 40 41 42

    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
43
    Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
Bryant's avatar
Bryant committed
44 45 46 47
    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
48 49

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

Bryant's avatar
Bryant committed
53 54
    void setValid( bool );
    bool isValid() const;
55

Bryant's avatar
Bryant committed
56
    double value() const;
pixhawk's avatar
pixhawk committed
57

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

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

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

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

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

Bryant's avatar
Bryant committed
73 74 75 76 77
    void setTracking( bool );
    bool isTracking() const;

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

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

Bryant's avatar
Bryant committed
82 83 84 85
public Q_SLOTS:
    void setValue( double val );

Q_SIGNALS:
pixhawk's avatar
pixhawk committed
86 87 88 89

    /*!
      \brief Notify a change of value.

Bryant's avatar
Bryant committed
90 91 92 93 94 95
      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
96
    */
Bryant's avatar
Bryant committed
97
    void valueChanged( double value );
pixhawk's avatar
pixhawk committed
98 99

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

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

pixhawk's avatar
pixhawk committed
111 112 113
    /*!
      This signal is emitted when the user moves the
      slider with the mouse.
Bryant's avatar
Bryant committed
114 115 116 117

      \param value New value

      \sa valueChanged()
pixhawk's avatar
pixhawk committed
118
    */
Bryant's avatar
Bryant committed
119
    void sliderMoved( double value );
120

pixhawk's avatar
pixhawk committed
121
protected:
Bryant's avatar
Bryant committed
122 123 124 125 126
    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
127

128
    /*!
Bryant's avatar
Bryant committed
129 130 131
      \brief Determine what to do when the user presses a mouse button.

      \param pos Mouse position
pixhawk's avatar
pixhawk committed
132

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

138
    /*!
Bryant's avatar
Bryant committed
139 140
      \brief Determine the value for a new position of the
             movable part of the slider
141

Bryant's avatar
Bryant committed
142 143 144 145
      \param pos Mouse position

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

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

Bryant's avatar
Bryant committed
151 152 153 154
    virtual void scaleChange();

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

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

private:
Bryant's avatar
Bryant committed
160 161
    double alignedValue( double ) const;
    double boundedValue( double ) const;
pixhawk's avatar
pixhawk committed
162 163 164 165 166 167

    class PrivateData;
    PrivateData *d_data;
};

#endif