| 1 | /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
|
|---|
| 2 | * Qwt Widget Library
|
|---|
| 3 | * Copyright (C) 1997 Josef Wilgen
|
|---|
| 4 | * Copyright (C) 2002 Uwe Rathmann
|
|---|
| 5 | *
|
|---|
| 6 | * This library is free software; you can redistribute it and/or
|
|---|
| 7 | * modify it under the terms of the Qwt License, Version 1.0
|
|---|
| 8 | *****************************************************************************/
|
|---|
| 9 |
|
|---|
| 10 | #ifndef QWT_DIAL_NEEDLE_H
|
|---|
| 11 | #define QWT_DIAL_NEEDLE_H 1
|
|---|
| 12 |
|
|---|
| 13 | #include <qpalette.h>
|
|---|
| 14 | #include "qwt_global.h"
|
|---|
| 15 |
|
|---|
| 16 | class QPainter;
|
|---|
| 17 | class QPoint;
|
|---|
| 18 |
|
|---|
| 19 | /*!
|
|---|
| 20 | \brief Base class for needles that can be used in a QwtDial.
|
|---|
| 21 |
|
|---|
| 22 | QwtDialNeedle is a pointer that indicates a value by pointing
|
|---|
| 23 | to a specific direction.
|
|---|
| 24 |
|
|---|
| 25 | Qwt is missing a set of good looking needles.
|
|---|
| 26 | Contributions are very welcome.
|
|---|
| 27 |
|
|---|
| 28 | \sa QwtDial, QwtCompass
|
|---|
| 29 | */
|
|---|
| 30 |
|
|---|
| 31 | class QWT_EXPORT QwtDialNeedle
|
|---|
| 32 | {
|
|---|
| 33 | public:
|
|---|
| 34 | QwtDialNeedle();
|
|---|
| 35 | virtual ~QwtDialNeedle();
|
|---|
| 36 |
|
|---|
| 37 | /*!
|
|---|
| 38 | Draw the needle
|
|---|
| 39 |
|
|---|
| 40 | \param painter Painter
|
|---|
| 41 | \param center Center of the dial, start position for the needle
|
|---|
| 42 | \param length Length of the needle
|
|---|
| 43 | \param direction Direction of the needle, in degrees counter clockwise
|
|---|
| 44 | \param cg Color group, used for painting
|
|---|
| 45 | */
|
|---|
| 46 | virtual void draw(QPainter *painter, const QPoint ¢er,
|
|---|
| 47 | int length, double direction,
|
|---|
| 48 | QPalette::ColorGroup cg = QPalette::Active) const = 0;
|
|---|
| 49 |
|
|---|
| 50 | virtual void setPalette(const QPalette &);
|
|---|
| 51 | const QPalette &palette() const;
|
|---|
| 52 |
|
|---|
| 53 | protected:
|
|---|
| 54 | static void drawKnob(QPainter *, const QPoint &pos,
|
|---|
| 55 | int width, const QBrush &, bool sunken);
|
|---|
| 56 |
|
|---|
| 57 | private:
|
|---|
| 58 | QPalette d_palette;
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | /*!
|
|---|
| 62 | \brief A needle for dial widgets
|
|---|
| 63 |
|
|---|
| 64 | The following colors are used:
|
|---|
| 65 | - QColorGroup::Mid\n
|
|---|
| 66 | Pointer
|
|---|
| 67 | - QColorGroup::base\n
|
|---|
| 68 | Knob
|
|---|
| 69 |
|
|---|
| 70 | \sa QwtDial, QwtCompass
|
|---|
| 71 | */
|
|---|
| 72 |
|
|---|
| 73 | class QWT_EXPORT QwtDialSimpleNeedle: public QwtDialNeedle
|
|---|
| 74 | {
|
|---|
| 75 | public:
|
|---|
| 76 | //! Style of the needle
|
|---|
| 77 | enum Style
|
|---|
| 78 | {
|
|---|
| 79 | Arrow,
|
|---|
| 80 | Ray
|
|---|
| 81 | };
|
|---|
| 82 |
|
|---|
| 83 | QwtDialSimpleNeedle(Style, bool hasKnob = true,
|
|---|
| 84 | const QColor &mid = Qt::gray, const QColor &base = Qt::darkGray);
|
|---|
| 85 |
|
|---|
| 86 | virtual void draw(QPainter *, const QPoint &, int length,
|
|---|
| 87 | double direction, QPalette::ColorGroup = QPalette::Active) const;
|
|---|
| 88 |
|
|---|
| 89 | static void drawArrowNeedle(QPainter *,
|
|---|
| 90 | const QPalette&, QPalette::ColorGroup,
|
|---|
| 91 | const QPoint &, int length, int width, double direction,
|
|---|
| 92 | bool hasKnob);
|
|---|
| 93 |
|
|---|
| 94 | static void drawRayNeedle(QPainter *,
|
|---|
| 95 | const QPalette&, QPalette::ColorGroup,
|
|---|
| 96 | const QPoint &, int length, int width, double direction,
|
|---|
| 97 | bool hasKnob);
|
|---|
| 98 |
|
|---|
| 99 | void setWidth(int width);
|
|---|
| 100 | int width() const;
|
|---|
| 101 |
|
|---|
| 102 | private:
|
|---|
| 103 | Style d_style;
|
|---|
| 104 | bool d_hasKnob;
|
|---|
| 105 | int d_width;
|
|---|
| 106 | };
|
|---|
| 107 |
|
|---|
| 108 | /*!
|
|---|
| 109 | \brief A magnet needle for compass widgets
|
|---|
| 110 |
|
|---|
| 111 | A magnet needle points to two opposite directions indicating
|
|---|
| 112 | north and south.
|
|---|
| 113 |
|
|---|
| 114 | The following colors are used:
|
|---|
| 115 | - QColorGroup::Light\n
|
|---|
| 116 | Used for pointing south
|
|---|
| 117 | - QColorGroup::Dark\n
|
|---|
| 118 | Used for pointing north
|
|---|
| 119 | - QColorGroup::Base\n
|
|---|
| 120 | Knob (ThinStyle only)
|
|---|
| 121 |
|
|---|
| 122 | \sa QwtDial, QwtCompass
|
|---|
| 123 | */
|
|---|
| 124 |
|
|---|
| 125 | class QWT_EXPORT QwtCompassMagnetNeedle: public QwtDialNeedle
|
|---|
| 126 | {
|
|---|
| 127 | public:
|
|---|
| 128 | //! Style of the needle
|
|---|
| 129 | enum Style
|
|---|
| 130 | {
|
|---|
| 131 | TriangleStyle,
|
|---|
| 132 | ThinStyle
|
|---|
| 133 | };
|
|---|
| 134 | QwtCompassMagnetNeedle(Style = TriangleStyle,
|
|---|
| 135 | const QColor &light = Qt::white, const QColor &dark = Qt::red);
|
|---|
| 136 |
|
|---|
| 137 | virtual void draw(QPainter *, const QPoint &, int length,
|
|---|
| 138 | double direction, QPalette::ColorGroup = QPalette::Active) const;
|
|---|
| 139 |
|
|---|
| 140 | static void drawTriangleNeedle(QPainter *,
|
|---|
| 141 | const QPalette &, QPalette::ColorGroup,
|
|---|
| 142 | const QPoint &, int length, double direction);
|
|---|
| 143 |
|
|---|
| 144 | static void drawThinNeedle(QPainter *,
|
|---|
| 145 | const QPalette &, QPalette::ColorGroup,
|
|---|
| 146 | const QPoint &, int length, double direction);
|
|---|
| 147 |
|
|---|
| 148 | protected:
|
|---|
| 149 | static void drawPointer(QPainter *painter, const QBrush &brush,
|
|---|
| 150 | int colorOffset, const QPoint ¢er,
|
|---|
| 151 | int length, int width, double direction);
|
|---|
| 152 |
|
|---|
| 153 | private:
|
|---|
| 154 | Style d_style;
|
|---|
| 155 | };
|
|---|
| 156 |
|
|---|
| 157 | /*!
|
|---|
| 158 | \brief An indicator for the wind direction
|
|---|
| 159 |
|
|---|
| 160 | QwtCompassWindArrow shows the direction where the wind comes from.
|
|---|
| 161 |
|
|---|
| 162 | - QColorGroup::Light\n
|
|---|
| 163 | Used for Style1, or the light half of Style2
|
|---|
| 164 | - QColorGroup::Dark\n
|
|---|
| 165 | Used for the dark half of Style2
|
|---|
| 166 |
|
|---|
| 167 | \sa QwtDial, QwtCompass
|
|---|
| 168 | */
|
|---|
| 169 |
|
|---|
| 170 | class QWT_EXPORT QwtCompassWindArrow: public QwtDialNeedle
|
|---|
| 171 | {
|
|---|
| 172 | public:
|
|---|
| 173 | //! Style of the arrow
|
|---|
| 174 | enum Style
|
|---|
| 175 | {
|
|---|
| 176 | Style1,
|
|---|
| 177 | Style2
|
|---|
| 178 | };
|
|---|
| 179 |
|
|---|
| 180 | QwtCompassWindArrow(Style, const QColor &light = Qt::white,
|
|---|
| 181 | const QColor &dark = Qt::gray);
|
|---|
| 182 |
|
|---|
| 183 | virtual void draw(QPainter *, const QPoint &, int length,
|
|---|
| 184 | double direction, QPalette::ColorGroup = QPalette::Active) const;
|
|---|
| 185 |
|
|---|
| 186 | static void drawStyle1Needle(QPainter *,
|
|---|
| 187 | const QPalette &, QPalette::ColorGroup,
|
|---|
| 188 | const QPoint &, int length, double direction);
|
|---|
| 189 |
|
|---|
| 190 | static void drawStyle2Needle(QPainter *,
|
|---|
| 191 | const QPalette &, QPalette::ColorGroup,
|
|---|
| 192 | const QPoint &, int length, double direction);
|
|---|
| 193 |
|
|---|
| 194 | private:
|
|---|
| 195 | Style d_style;
|
|---|
| 196 | };
|
|---|
| 197 |
|
|---|
| 198 | #endif // QWT_DIAL_NEEDLE_H
|
|---|