qwt_dial_needle.h 3.99 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_DIAL_NEEDLE_H
#define QWT_DIAL_NEEDLE_H 1

#include "qwt_global.h"
Bryant's avatar
Bryant committed
14
#include <qpalette.h>
pixhawk's avatar
pixhawk committed
15 16 17 18 19 20 21

class QPainter;
class QPoint;

/*!
  \brief Base class for needles that can be used in a QwtDial.

22 23 24
  QwtDialNeedle is a pointer that indicates a value by pointing
  to a specific direction.

pixhawk's avatar
pixhawk committed
25 26 27 28 29 30 31 32 33
  \sa QwtDial, QwtCompass
*/

class QWT_EXPORT QwtDialNeedle
{
public:
    QwtDialNeedle();
    virtual ~QwtDialNeedle();

Bryant's avatar
Bryant committed
34 35 36 37 38 39 40 41
    virtual void setPalette( const QPalette & );
    const QPalette &palette() const;

    virtual void draw( QPainter *painter, const QPointF &center,
        double length, double direction, 
        QPalette::ColorGroup = QPalette::Active ) const;

protected:
pixhawk's avatar
pixhawk committed
42
    /*!
Bryant's avatar
Bryant committed
43
      \brief Draw the needle
pixhawk's avatar
pixhawk committed
44

Bryant's avatar
Bryant committed
45 46
      The origin of the needle is at position (0.0, 0.0 )
      pointing in direction 0.0 ( = east ). 
pixhawk's avatar
pixhawk committed
47

Bryant's avatar
Bryant committed
48 49
      The painter is already initialized with translation and 
      rotation.
pixhawk's avatar
pixhawk committed
50

Bryant's avatar
Bryant committed
51 52 53 54 55 56 57 58 59 60 61
      \param painter Painter
      \param length Length of the needle
      \param colorGroup Color group, used for painting

      \sa setPalette(), palette()
    */
    virtual void drawNeedle( QPainter *painter, 
        double length, QPalette::ColorGroup colorGroup ) const = 0;

    virtual void drawKnob( QPainter *, double width, 
        const QBrush &, bool sunken ) const;
pixhawk's avatar
pixhawk committed
62 63 64 65 66 67 68 69 70

private:
    QPalette d_palette;
};

/*!
  \brief A needle for dial widgets

  The following colors are used:
Bryant's avatar
Bryant committed
71 72

  - QPalette::Mid\n
pixhawk's avatar
pixhawk committed
73
    Pointer
Bryant's avatar
Bryant committed
74
  - QPalette::Base\n
pixhawk's avatar
pixhawk committed
75 76 77 78 79 80 81 82 83
    Knob

  \sa QwtDial, QwtCompass
*/

class QWT_EXPORT QwtDialSimpleNeedle: public QwtDialNeedle
{
public:
    //! Style of the needle
Bryant's avatar
Bryant committed
84 85 86
    enum Style
    {
        //! Arrow
pixhawk's avatar
pixhawk committed
87
        Arrow,
Bryant's avatar
Bryant committed
88 89

        //! A straight line from the center
pixhawk's avatar
pixhawk committed
90 91 92
        Ray
    };

Bryant's avatar
Bryant committed
93 94
    QwtDialSimpleNeedle( Style, bool hasKnob = true,
        const QColor &mid = Qt::gray, const QColor &base = Qt::darkGray );
pixhawk's avatar
pixhawk committed
95

Bryant's avatar
Bryant committed
96 97
    void setWidth( double width );
    double width() const;
pixhawk's avatar
pixhawk committed
98

Bryant's avatar
Bryant committed
99 100 101
protected:
    virtual void drawNeedle( QPainter *, double length,
        QPalette::ColorGroup ) const;
pixhawk's avatar
pixhawk committed
102 103 104 105

private:
    Style d_style;
    bool d_hasKnob;
Bryant's avatar
Bryant committed
106
    double d_width;
pixhawk's avatar
pixhawk committed
107 108 109 110 111 112 113 114 115
};

/*!
  \brief A magnet needle for compass widgets

  A magnet needle points to two opposite directions indicating
  north and south.

  The following colors are used:
Bryant's avatar
Bryant committed
116
  - QPalette::Light\n
pixhawk's avatar
pixhawk committed
117
    Used for pointing south
Bryant's avatar
Bryant committed
118
  - QPalette::Dark\n
pixhawk's avatar
pixhawk committed
119
    Used for pointing north
Bryant's avatar
Bryant committed
120
  - QPalette::Base\n
pixhawk's avatar
pixhawk committed
121 122 123 124 125 126 127 128 129
    Knob (ThinStyle only)

  \sa QwtDial, QwtCompass
*/

class QWT_EXPORT QwtCompassMagnetNeedle: public QwtDialNeedle
{
public:
    //! Style of the needle
Bryant's avatar
Bryant committed
130 131 132
    enum Style
    {
        //! A needle with a triangular shape
pixhawk's avatar
pixhawk committed
133
        TriangleStyle,
Bryant's avatar
Bryant committed
134 135

        //! A thin needle 
pixhawk's avatar
pixhawk committed
136 137 138
        ThinStyle
    };

Bryant's avatar
Bryant committed
139 140
    QwtCompassMagnetNeedle( Style = TriangleStyle,
        const QColor &light = Qt::white, const QColor &dark = Qt::red );
pixhawk's avatar
pixhawk committed
141 142

protected:
Bryant's avatar
Bryant committed
143 144
    virtual void drawNeedle( QPainter *, 
        double length, QPalette::ColorGroup ) const;
pixhawk's avatar
pixhawk committed
145 146 147 148 149 150 151 152 153 154

private:
    Style d_style;
};

/*!
  \brief An indicator for the wind direction

  QwtCompassWindArrow shows the direction where the wind comes from.

Bryant's avatar
Bryant committed
155
  - QPalette::Light\n
pixhawk's avatar
pixhawk committed
156
    Used for Style1, or the light half of Style2
Bryant's avatar
Bryant committed
157
  - QPalette::Dark\n
pixhawk's avatar
pixhawk committed
158 159 160 161 162 163 164 165 166
    Used for the dark half of Style2

  \sa QwtDial, QwtCompass
*/

class QWT_EXPORT QwtCompassWindArrow: public QwtDialNeedle
{
public:
    //! Style of the arrow
Bryant's avatar
Bryant committed
167 168 169
    enum Style
    {
        //! A needle pointing to the center
pixhawk's avatar
pixhawk committed
170
        Style1,
Bryant's avatar
Bryant committed
171 172

        //! A needle pointing to the center
pixhawk's avatar
pixhawk committed
173 174 175
        Style2
    };

Bryant's avatar
Bryant committed
176 177
    QwtCompassWindArrow( Style, const QColor &light = Qt::white,
        const QColor &dark = Qt::gray );
pixhawk's avatar
pixhawk committed
178

Bryant's avatar
Bryant committed
179 180 181
protected:
    virtual void drawNeedle( QPainter *, 
        double length, QPalette::ColorGroup ) const;
pixhawk's avatar
pixhawk committed
182 183 184 185 186

private:
    Style d_style;
};

Bryant's avatar
Bryant committed
187
#endif