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

#include "qwt_global.h"
#include "qwt_abstract_slider.h"

class QwtScaleDraw;

/*!
  \brief The Slider Widget

  QwtSlider is a slider widget which operates on an interval
Bryant's avatar
Bryant committed
22
23
  of type double. Its position is related to a scale showing
  the current value.
pixhawk's avatar
pixhawk committed
24

Bryant's avatar
Bryant committed
25
  The slider can be customized by having a through, a groove - or both.
pixhawk's avatar
pixhawk committed
26

Bryant's avatar
Bryant committed
27
  \image html sliders.png
pixhawk's avatar
pixhawk committed
28
29
*/

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

    Q_ENUMS( ScalePosition BackgroundStyle )

    Q_PROPERTY( Qt::Orientation orientation
                READ orientation WRITE setOrientation )
    Q_PROPERTY( ScalePosition scalePosition READ scalePosition
        WRITE setScalePosition )

    Q_PROPERTY( bool trough READ hasTrough WRITE setTrough )
    Q_PROPERTY( bool groove READ hasGroove WRITE setGroove )

    Q_PROPERTY( QSize handleSize READ handleSize WRITE setHandleSize )
pixhawk's avatar
pixhawk committed
45
    Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth )
Bryant's avatar
Bryant committed
46
    Q_PROPERTY( int spacing READ spacing WRITE setSpacing )
47

pixhawk's avatar
pixhawk committed
48
49
public:

50
    /*!
Bryant's avatar
Bryant committed
51
52
      Position of the scale
      \sa QwtSlider(), setScalePosition(), setOrientation()
pixhawk's avatar
pixhawk committed
53
     */
Bryant's avatar
Bryant committed
54
55
56
    enum ScalePosition
    {
        //! The slider has no scale
57
58
        NoScale,

Bryant's avatar
Bryant committed
59
60
        //! The scale is right of a vertical or below a horizontal slider
        LeadingScale,
pixhawk's avatar
pixhawk committed
61

Bryant's avatar
Bryant committed
62
63
        //! The scale is left of a vertical or above a horizontal slider
        TrailingScale
pixhawk's avatar
pixhawk committed
64
65
    };

Bryant's avatar
Bryant committed
66
67
    explicit QwtSlider( QWidget *parent = NULL );
    explicit QwtSlider( Qt::Orientation, QWidget *parent = NULL );
68

pixhawk's avatar
pixhawk committed
69
70
    virtual ~QwtSlider();

Bryant's avatar
Bryant committed
71
72
73
74
75
    void setOrientation( Qt::Orientation );
    Qt::Orientation orientation() const;

    void setScalePosition( ScalePosition );
    ScalePosition scalePosition() const;
pixhawk's avatar
pixhawk committed
76

Bryant's avatar
Bryant committed
77
78
    void setTrough( bool );
    bool hasTrough() const;
79

Bryant's avatar
Bryant committed
80
81
    void setGroove( bool );
    bool hasGroove() const;
pixhawk's avatar
pixhawk committed
82

Bryant's avatar
Bryant committed
83
84
85
86
    void setHandleSize( const QSize & );
    QSize handleSize() const;

    void setBorderWidth( int bw );
pixhawk's avatar
pixhawk committed
87
88
    int borderWidth() const;

Bryant's avatar
Bryant committed
89
90
    void setSpacing( int );
    int spacing() const;
pixhawk's avatar
pixhawk committed
91
92
93

    virtual QSize sizeHint() const;
    virtual QSize minimumSizeHint() const;
94

Bryant's avatar
Bryant committed
95
    void setScaleDraw( QwtScaleDraw * );
pixhawk's avatar
pixhawk committed
96
97
    const QwtScaleDraw *scaleDraw() const;

Bryant's avatar
Bryant committed
98
99
100
    void setUpdateInterval( int );
    int updateInterval() const;

pixhawk's avatar
pixhawk committed
101
protected:
Bryant's avatar
Bryant committed
102
103
    virtual double scrolledTo( const QPoint & ) const;
    virtual bool isScrollPosition( const QPoint & ) const;
pixhawk's avatar
pixhawk committed
104

Bryant's avatar
Bryant committed
105
106
    virtual void drawSlider ( QPainter *, const QRect & ) const;
    virtual void drawHandle( QPainter *, const QRect &, int pos ) const;
pixhawk's avatar
pixhawk committed
107

Bryant's avatar
Bryant committed
108
109
110
111
112
113
    virtual void mousePressEvent( QMouseEvent * );
    virtual void mouseReleaseEvent( QMouseEvent * );
    virtual void resizeEvent( QResizeEvent * );
    virtual void paintEvent ( QPaintEvent * );
    virtual void changeEvent( QEvent * );
    virtual void timerEvent( QTimerEvent * );
pixhawk's avatar
pixhawk committed
114
115
116

    virtual void scaleChange();

Bryant's avatar
Bryant committed
117
118
    QRect sliderRect() const;
    QRect handleRect() const;
pixhawk's avatar
pixhawk committed
119

Bryant's avatar
Bryant committed
120
private:
pixhawk's avatar
pixhawk committed
121
122
    QwtScaleDraw *scaleDraw();

Bryant's avatar
Bryant committed
123
124
    void layoutSlider( bool );
    void initSlider( Qt::Orientation );
pixhawk's avatar
pixhawk committed
125
126
127
128
129
130

    class PrivateData;
    PrivateData *d_data;
};

#endif