qwt_dial.h 4.85 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* -*- 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_DIAL_H
#define QWT_DIAL_H 1

#include "qwt_global.h"
#include "qwt_abstract_slider.h"
Bryant's avatar
Bryant committed
15 16 17
#include "qwt_abstract_scale_draw.h"
#include <qframe.h>
#include <qpalette.h>
pixhawk's avatar
pixhawk committed
18 19

class QwtDialNeedle;
Bryant's avatar
Bryant committed
20
class QwtRoundScaleDraw;
pixhawk's avatar
pixhawk committed
21 22

/*!
23
  \brief QwtDial class provides a rounded range control.
pixhawk's avatar
pixhawk committed
24 25

  QwtDial is intended as base class for dial widgets like
26
  speedometers, compass widgets, clocks ...
pixhawk's avatar
pixhawk committed
27 28 29 30

  \image html dials2.png

  A dial contains a scale and a needle indicating the current value
31
  of the dial. Depending on Mode one of them is fixed and the
pixhawk's avatar
pixhawk committed
32
  other is rotating. If not isReadOnly() the
33
  dial can be rotated by dragging the mouse or using keyboard inputs
Bryant's avatar
Bryant committed
34
  (see QwtAbstractSlider::keyPressEvent()). A dial might be wrapping, what means
pixhawk's avatar
pixhawk committed
35 36 37
  a rotation below/above one limit continues on the other limit (f.e compass).
  The scale might cover any arc of the dial, its values are related to
  the origin() of the dial.
38

Bryant's avatar
Bryant committed
39 40 41 42
  Often dials have to be updated very often according to values from external
  devices. For these high refresh rates QwtDial caches as much as possible.
  For derived classes it might be necessary to clear these caches manually
  according to attribute changes using invalidateCache().
43

pixhawk's avatar
pixhawk committed
44
  \sa QwtCompass, QwtAnalogClock, QwtDialNeedle
Bryant's avatar
Bryant committed
45 46
  \note The controls and dials examples shows different types of dials.
  \note QDial is more similar to QwtKnob than to QwtDial
pixhawk's avatar
pixhawk committed
47 48 49 50 51 52
*/

class QWT_EXPORT QwtDial: public QwtAbstractSlider
{
    Q_OBJECT

Bryant's avatar
Bryant committed
53
    Q_ENUMS( Shadow Mode Direction )
pixhawk's avatar
pixhawk committed
54

Bryant's avatar
Bryant committed
55 56 57 58 59 60
    Q_PROPERTY( int lineWidth READ lineWidth WRITE setLineWidth )
    Q_PROPERTY( Shadow frameShadow READ frameShadow WRITE setFrameShadow )
    Q_PROPERTY( Mode mode READ mode WRITE setMode )
    Q_PROPERTY( double origin READ origin WRITE setOrigin )
    Q_PROPERTY( double minScaleArc READ minScaleArc WRITE setMinScaleArc )
    Q_PROPERTY( double maxScaleArc READ maxScaleArc WRITE setMaxScaleArc )
pixhawk's avatar
pixhawk committed
61 62 63 64 65 66 67 68 69 70 71

public:

    /*!
        \brief Frame shadow

         Unfortunately it is not possible to use QFrame::Shadow
         as a property of a widget that is not derived from QFrame.
         The following enum is made for the designer only. It is safe
         to use QFrame::Shadow instead.
     */
Bryant's avatar
Bryant committed
72 73 74
    enum Shadow
    {
        //! QFrame::Plain
pixhawk's avatar
pixhawk committed
75
        Plain = QFrame::Plain,
Bryant's avatar
Bryant committed
76 77

        //! QFrame::Raised
pixhawk's avatar
pixhawk committed
78 79
        Raised = QFrame::Raised,

Bryant's avatar
Bryant committed
80 81
        //! QFrame::Sunken
        Sunken = QFrame::Sunken
pixhawk's avatar
pixhawk committed
82 83
    };

Bryant's avatar
Bryant committed
84 85 86 87
    //! Mode controlling whether the needle or the scale is rotating
    enum Mode
    {
        //! The needle is rotating
pixhawk's avatar
pixhawk committed
88
        RotateNeedle,
Bryant's avatar
Bryant committed
89 90

        //! The needle is fixed, the scales are rotating
pixhawk's avatar
pixhawk committed
91 92 93
        RotateScale
    };

Bryant's avatar
Bryant committed
94
    explicit QwtDial( QWidget *parent = NULL );
pixhawk's avatar
pixhawk committed
95 96
    virtual ~QwtDial();

Bryant's avatar
Bryant committed
97
    void setFrameShadow( Shadow );
pixhawk's avatar
pixhawk committed
98 99
    Shadow frameShadow() const;

Bryant's avatar
Bryant committed
100
    void setLineWidth( int );
pixhawk's avatar
pixhawk committed
101 102
    int lineWidth() const;

Bryant's avatar
Bryant committed
103
    void setMode( Mode );
pixhawk's avatar
pixhawk committed
104 105
    Mode mode() const;

Bryant's avatar
Bryant committed
106
    void setScaleArc( double min, double max );
pixhawk's avatar
pixhawk committed
107

Bryant's avatar
Bryant committed
108
    void setMinScaleArc( double min );
pixhawk's avatar
pixhawk committed
109
    double minScaleArc() const;
Bryant's avatar
Bryant committed
110 111

    void setMaxScaleArc( double min );
pixhawk's avatar
pixhawk committed
112 113
    double maxScaleArc() const;

Bryant's avatar
Bryant committed
114
    virtual void setOrigin( double );
pixhawk's avatar
pixhawk committed
115 116
    double origin() const;

Bryant's avatar
Bryant committed
117
    void setNeedle( QwtDialNeedle * );
pixhawk's avatar
pixhawk committed
118 119 120 121
    const QwtDialNeedle *needle() const;
    QwtDialNeedle *needle();

    QRect boundingRect() const;
Bryant's avatar
Bryant committed
122 123 124
    QRect innerRect() const;

    virtual QRect scaleInnerRect() const;
pixhawk's avatar
pixhawk committed
125 126 127 128

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

Bryant's avatar
Bryant committed
129
    void setScaleDraw( QwtRoundScaleDraw * );
pixhawk's avatar
pixhawk committed
130

Bryant's avatar
Bryant committed
131 132
    QwtRoundScaleDraw *scaleDraw();
    const QwtRoundScaleDraw *scaleDraw() const;
pixhawk's avatar
pixhawk committed
133 134

protected:
Bryant's avatar
Bryant committed
135 136 137
    virtual void wheelEvent( QWheelEvent * );
    virtual void paintEvent( QPaintEvent * );
    virtual void changeEvent( QEvent * );
pixhawk's avatar
pixhawk committed
138

Bryant's avatar
Bryant committed
139 140 141
    virtual void drawFrame( QPainter *p );
    virtual void drawContents( QPainter * ) const;
    virtual void drawFocusIndicator( QPainter * ) const;
pixhawk's avatar
pixhawk committed
142

Bryant's avatar
Bryant committed
143
    void invalidateCache();
pixhawk's avatar
pixhawk committed
144

Bryant's avatar
Bryant committed
145 146
    virtual void drawScale( QPainter *, 
        const QPointF &center, double radius ) const;
pixhawk's avatar
pixhawk committed
147

Bryant's avatar
Bryant committed
148 149
    virtual void drawScaleContents( QPainter *painter, 
        const QPointF &center, double radius ) const;
pixhawk's avatar
pixhawk committed
150

Bryant's avatar
Bryant committed
151 152
    virtual void drawNeedle( QPainter *, const QPointF &,
        double radius, double direction, QPalette::ColorGroup ) const;
pixhawk's avatar
pixhawk committed
153

Bryant's avatar
Bryant committed
154 155
    virtual double scrolledTo( const QPoint & ) const;
    virtual bool isScrollPosition( const QPoint & ) const;
pixhawk's avatar
pixhawk committed
156

Bryant's avatar
Bryant committed
157 158
    virtual void sliderChange();
    virtual void scaleChange();
pixhawk's avatar
pixhawk committed
159 160

private:
Bryant's avatar
Bryant committed
161 162
    void setAngleRange( double angle, double span );
    void drawNeedle( QPainter * ) const;
pixhawk's avatar
pixhawk committed
163 164 165 166 167 168

    class PrivateData;
    PrivateData *d_data;
};

#endif