qwt_dial_needle.h 5.38 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 14 15 16 17 18 19 20 21
 * 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 <qpalette.h>
#include "qwt_global.h"

class QPainter;
class QPoint;

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

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

  Qwt is missing a set of good looking needles.
pixhawk's avatar
pixhawk committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
  Contributions are very welcome.

  \sa QwtDial, QwtCompass
*/

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

    /*!
        Draw the needle

        \param painter Painter
        \param center Center of the dial, start position for the needle
        \param length Length of the needle
        \param direction Direction of the needle, in degrees counter clockwise
        \param cg Color group, used for painting
    */
46 47 48
    virtual void draw(QPainter *painter, const QPoint &center,
                      int length, double direction,
                      QPalette::ColorGroup cg = QPalette::Active) const = 0;
pixhawk's avatar
pixhawk committed
49 50

    virtual void setPalette(const QPalette &);
51
    const QPalette &palette() const;
pixhawk's avatar
pixhawk committed
52 53

protected:
54 55
    static void drawKnob(QPainter *, const QPoint &pos,
                         int width, const QBrush &, bool sunken);
pixhawk's avatar
pixhawk committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

private:
    QPalette d_palette;
};

/*!
  \brief A needle for dial widgets

  The following colors are used:
  - QColorGroup::Mid\n
    Pointer
  - QColorGroup::base\n
    Knob

  \sa QwtDial, QwtCompass
*/

class QWT_EXPORT QwtDialSimpleNeedle: public QwtDialNeedle
{
public:
    //! Style of the needle
77
    enum Style {
pixhawk's avatar
pixhawk committed
78 79 80 81
        Arrow,
        Ray
    };

82 83
    QwtDialSimpleNeedle(Style, bool hasKnob = true,
                        const QColor &mid = Qt::gray, const QColor &base = Qt::darkGray);
pixhawk's avatar
pixhawk committed
84

85 86
    virtual void draw(QPainter *, const QPoint &, int length,
                      double direction, QPalette::ColorGroup = QPalette::Active) const;
pixhawk's avatar
pixhawk committed
87

88 89 90 91
    static void drawArrowNeedle(QPainter *,
                                const QPalette&, QPalette::ColorGroup,
                                const QPoint &, int length, int width, double direction,
                                bool hasKnob);
pixhawk's avatar
pixhawk committed
92

93 94 95 96
    static void drawRayNeedle(QPainter *,
                              const QPalette&, QPalette::ColorGroup,
                              const QPoint &, int length, int width, double direction,
                              bool hasKnob);
pixhawk's avatar
pixhawk committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

    void setWidth(int width);
    int width() const;

private:
    Style d_style;
    bool d_hasKnob;
    int d_width;
};

/*!
  \brief A magnet needle for compass widgets

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

  The following colors are used:
  - QColorGroup::Light\n
    Used for pointing south
  - QColorGroup::Dark\n
    Used for pointing north
  - QColorGroup::Base\n
    Knob (ThinStyle only)

  \sa QwtDial, QwtCompass
*/

class QWT_EXPORT QwtCompassMagnetNeedle: public QwtDialNeedle
{
public:
    //! Style of the needle
128
    enum Style {
pixhawk's avatar
pixhawk committed
129 130 131 132
        TriangleStyle,
        ThinStyle
    };
    QwtCompassMagnetNeedle(Style = TriangleStyle,
133
                           const QColor &light = Qt::white, const QColor &dark = Qt::red);
pixhawk's avatar
pixhawk committed
134

135 136
    virtual void draw(QPainter *, const QPoint &, int length,
                      double direction, QPalette::ColorGroup = QPalette::Active) const;
pixhawk's avatar
pixhawk committed
137

138 139 140
    static void drawTriangleNeedle(QPainter *,
                                   const QPalette &, QPalette::ColorGroup,
                                   const QPoint &, int length, double direction);
pixhawk's avatar
pixhawk committed
141 142

    static void drawThinNeedle(QPainter *,
143 144
                               const QPalette &, QPalette::ColorGroup,
                               const QPoint &, int length, double direction);
pixhawk's avatar
pixhawk committed
145 146 147

protected:
    static void drawPointer(QPainter *painter, const QBrush &brush,
148 149
                            int colorOffset, const QPoint &center,
                            int length, int width, double direction);
pixhawk's avatar
pixhawk committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171

private:
    Style d_style;
};

/*!
  \brief An indicator for the wind direction

  QwtCompassWindArrow shows the direction where the wind comes from.

  - QColorGroup::Light\n
    Used for Style1, or the light half of Style2
  - QColorGroup::Dark\n
    Used for the dark half of Style2

  \sa QwtDial, QwtCompass
*/

class QWT_EXPORT QwtCompassWindArrow: public QwtDialNeedle
{
public:
    //! Style of the arrow
172
    enum Style {
pixhawk's avatar
pixhawk committed
173 174 175 176 177
        Style1,
        Style2
    };

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

    virtual void draw(QPainter *, const QPoint &, int length,
181
                      double direction, QPalette::ColorGroup = QPalette::Active) const;
pixhawk's avatar
pixhawk committed
182

183 184 185
    static void drawStyle1Needle(QPainter *,
                                 const QPalette &, QPalette::ColorGroup,
                                 const QPoint &, int length, double direction);
pixhawk's avatar
pixhawk committed
186

187 188 189
    static void drawStyle2Needle(QPainter *,
                                 const QPalette &, QPalette::ColorGroup,
                                 const QPoint &, int length, double direction);
pixhawk's avatar
pixhawk committed
190 191 192 193 194 195

private:
    Style d_style;
};

#endif // QWT_DIAL_NEEDLE_H