-
Notifications
You must be signed in to change notification settings - Fork 3
/
gauge.h
238 lines (173 loc) · 9.04 KB
/
gauge.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#ifndef GAUGE_H
#define GAUGE_H
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QColor>
#include <QRect>
/*!
* \brief The guage class uses QGraphicsScene to display a gauge.
*
* The gauge has up to three different regions of display, the low, OK, and high
* regions. Each region can be colored to indicate when the value being
* displayed (the reading) is within the region. To use the DialScene, first
* call any set functions as needed to configure the guage. Then call setupView()
* to setup the QGraphicsView that will display this scene. Finally call
* setReading() to change the value being displayed.
*
* Gauge is an abstract class
*/
class Gauge
{
public:
Gauge();
~Gauge();
//! Setup the view to contain our scene
virtual void setupView(QGraphicsView* view);
//! \return the value at the bottom of the gauge scale
double getScaleStart(void) const {return scaleStart;}
//! \return The range of the low range of the scale
double getScaleLowRange(void) const {return scaleLowRange;}
//! \return The range of the mid range of the scale
double getScaleMidRange(void) const {return scaleMidRange;}
//! \return The range of the High range of the scale
double getScaleHighRange(void) const {return scaleHighRange;}
//! \return the reading at the top of the scale
double getTopOfScale(void) const;
//! \return the top of the low range of the scale
double getTopOfLowRange(void) const {return scaleStart+scaleLowRange;}
//! \return the top of the mid range of the scale
double getTopOfMidRange(void) const {return scaleStart+scaleLowRange+scaleMidRange;}
//! \return the total range of the scale
double getTotalRange(void) const;
//! \return Major tick mark spacing (also sets label spacing)
double getMajorSpacing(void) const {return majorSpacing;}
//! \return Minor tick mark spacing
double getMinorSpacing(void) const {return minorSpacing;}
//! \return the label text
QString getLabel(void) const {return label;}
//! \return the enable flag for reading text
bool getTextEnable(void) const {return textEnable;}
//! \return the enable flag for tick mark labels
bool getTickMarkLabelEnable(void) const {return tickMarkLabelEnable;}
//! \return The color when the reading is low
QColor getLowColor(void) const {return lowColor;}
//! \return The color when the reading is mid
QColor getMidColor(void) const {return midColor;}
//! \return The color when the reading is high
QColor getHighColor(void) const {return highColor;}
//! \return The color of the background
QColor getBackgroundColor(void) const {return backgroundColor;}
//! \return The color of the tickmarks and text
QColor getTickMarkColor(void) const {return tickMarkColor;}
//! \return The color of the text that displays the reading
QColor getTextReadingColor(void) const {return textReadingColor;}
//! \return Length of the major tick mark as a fraction of the size
double getMajorTickMarkLength(void) const {return majorTickMarkLength;}
//! \return Length of the minor tick mark as a fraction of the size
double getMinorTickMarkLength(void) const {return minorTickMarkLength;}
//! \return The number of decimal places in the tick mark label
int getTickMarkPrecision(void) const {return tickMarkPrecision;}
//! \return The number of decimal places in the reading text
int getReadingPrecision(void) const {return readingPrecision;}
//! \return The gauge reading used for the pointer
double getGaugeReading(void) const {return gaugeReading;}
//! \return The gauge reading used for the text display
double getTextReading(void) const {return textReading;}
//! \return The color based on a reading
QColor getColorFromReading(double read);
//! Set the value at the bottom of the gauge scale
void setScaleStart(double start);
//! Set The range of the low range of the scale
void setScaleLowRange(double lowRange);
//! Set The range of the mid range of the scale
void setScaleMidRange(double midRange);
//! Set The range of the High range of the scale
void setScaleHighRange(double highRange);
//! Set major tick mark spacing (also sets label spacing)
void setMajorSpacing(double major);
//! Set minor tick mark spacing
void setMinorSpacing(double minor);
//! Set the color when the reading is low
void setLowColor(QColor low);
//! Set the color when the reading is mid
void setMidColor(QColor mid);
//! Set the color when the reading is high
void setHighColor(QColor high);
//! Set the color of the background, use Qt::transparent for no background
void setBackgroundColor(QColor back);
//! Set the color of the tickmarks
void setTickMarkColor(QColor color);
//! Set the color of the text that displays the reading
void setTextReadingColor(QColor color);
//! Set length of the major tick mark as a fraction of the size
void setMajorTickMarkLength(double major);
//! Set length of the minor tick mark as a fraction of the size
void setMinorTickMarkLength(double minor);
//! Set the label text
void setLabel(const QString& text);
//! Set the enable/disable flag for displaying reading text
void setTextEnable(bool enable);
//! Set the enable flag for tick mark labels
void setTickMarkLabelEnable(bool enable);
//! Set the number of decimal places in the tick mark label
void setTickMarkPrecision(int precision);
//! Set the number of decimal places in the reading text
void setReadingPrecision(int precision);
//! Set the gauge reading
virtual void setReading(double value){(void)value;}
//! Set the gauge reading
virtual void setReading(double pointerValue, double textValue){(void)pointerValue; (void)textValue;}
//! Redraw the guage as needed
void redraw(void) {setReading(gaugeReading, textReading);}
protected: // methods
inline double rad2deg(double rad){return rad*180.0/pi;}
inline double deg2rad(double deg){return deg*pi/180.0;}
//! Set the size the scene from the view rect
virtual void setSize(QRect rect) = 0;
//! Create the entire scene
virtual void createScene(QGraphicsScene& scene) = 0;
//! location is with respect to the rect center
QPointF rectOffsetForCenter(const QRectF rect) const;
//! location is with respect to the center of the top side.
QPointF rectOffsetForTopCenter(const QRectF rect) const;
//! location is with respect to the top left corner.
QPointF rectOffsetForTopLeft(void) const;
//! location is with respect to the top right corner.
QPointF rectOffsetForTopRight(const QRectF rect) const;
//! location is with respect to the center of the bottom side.
QPointF rectOffsetForBottomCenter(const QRectF rect) const;
//! location is with respect to the bottom left corner
QPointF rectOffsetForBottomLeft(const QRectF rect) const;
//! location is with respect to the bottom right tcorner.
QPointF rectOffsetForBottomRight(const QRectF rect) const;
//! the location is with respect to the center of the left side
QPointF rectOffsetForLeftCenter(const QRectF rect) const;
//! the location is with respect to the cente of the right side.
QPointF rectOffsetForRightCenter(const QRectF rect) const;
protected: // properties
double scaleStart; //!< The value at the bottom of the gauge scale
double scaleLowRange; //!< The range of the low range of the scale
double scaleMidRange; //!< The range of the Mid range of the scale
double scaleHighRange; //!< The range of the High range of the scale
double majorSpacing; //!< Major tick mark spacing (also sets label spacing)
double minorSpacing; //!< Minor tick mark spacing
QColor lowColor; //!< The color when the reading is low
QColor midColor; //!< The color when the reading is mid
QColor highColor; //!< The color when the reading is high
QColor backgroundColor; //!< The color of the background
QColor tickMarkColor; //!< The color of the tickmarks
QColor textReadingColor; //!< The color of the reading text
double majorTickMarkLength; //!< Length of the major tick mark as a fraction of the size
double minorTickMarkLength; //!< Length of the minor tick mark as a fraction of the size
double textReading; //!< The gauge reading for the text
double gaugeReading; //!< The gauge reading for the graphics
bool dirty; //!< Flap indicating the scene needs to be redrawn
QGraphicsScene myScene; //!< The scene we render into
QString label; //!< The label text
bool textEnable; //!< Flag to enable the reading text
int tickMarkPrecision; //!< Number of decimal places to use on the tick mark labels
int readingPrecision; //!< Number of decimal places to use on the reading display
bool tickMarkLabelEnable; //!< Flag to enable the text mark label
const double pi;
};
#endif // GAUGE_H