forked from cyberintruder/DGIPyDrOneQt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqcgaugewidget.h
350 lines (292 loc) · 11.4 KB
/
qcgaugewidget.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/***************************************************************************
** **
** QcGauge, for instrumentation, and real time data measurement **
** visualization widget for Qt. **
** Copyright (C) 2015 Hadj Tahar Berrima **
** **
** This program is free software: you can redistribute it and/or modify **
** it under the terms of the GNU Lesser General Public License as **
** published by the Free Software Foundation, either version 3 of the **
** License, or (at your option) any later version. **
** **
** This program is distributed in the hope that it will be useful, **
** but WITHOUT ANY WARRANTY; without even the implied warranty of **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
** GNU Lesser General Public License for more details. **
** **
** You should have received a copy of the GNU Lesser General Public **
** License along with this program. **
** If not, see http://www.gnu.org/licenses/. **
** **
****************************************************************************
** Author: Hadj Tahar Berrima **
** Website: http://pytricity.com/ **
** Contact: [email protected] **
** Date: 1 dec 2014 **
** Version: 1.0 **
****************************************************************************/
#ifndef QCGAUGEWIDGET_H
#define QCGAUGEWIDGET_H
#include <QWidget>
#include <QPainter>
#include <QObject>
#include <QRectF>
#include <QtMath>
#if defined(QCGAUGE_COMPILE_LIBRARY)
# define QCGAUGE_DECL Q_DECL_EXPORT
#elif defined(QCGAUGE_USE_LIBRARY)
# define QCGAUGE_DECL Q_DECL_IMPORT
#else
# define QCGAUGE_DECL
#endif
class QcGaugeWidget;
class QcItem;
class QcBackgroundItem;
class QcDegreesItem;
class QcValuesItem;
class QcArcItem;
class QcColorBand;
class QcNeedleItem;
class QcLabelItem;
class QcGlassItem;
class QcAttitudeMeter;
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
class QCGAUGE_DECL QcGaugeWidget : public QWidget
{
Q_OBJECT
public:
explicit QcGaugeWidget(QWidget *parent = 0);
QcBackgroundItem* addBackground(float position);
QcDegreesItem* addDegrees(float position);
QcValuesItem* addValues(float position);
QcArcItem* addArc(float position);
QcColorBand* addColorBand(float position);
QcNeedleItem* addNeedle(float position);
QcLabelItem* addLabel(float position);
QcGlassItem* addGlass(float position);
QcAttitudeMeter* addAttitudeMeter(float position);
void addItem(QcItem* item, float position);
int removeItem(QcItem* item);
QList <QcItem*> items();
QList <QcItem*> mItems;
signals:
public slots:
private:
void paintEvent(QPaintEvent *);
};
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
class QCGAUGE_DECL QcItem : public QObject
{
Q_OBJECT
public:
explicit QcItem(QObject *parent = 0);
virtual void draw(QPainter *) = 0;
virtual int type();
void setPosition(float percentage);
float position();
QRectF rect();
enum Error{InvalidValueRange,InvalidDegreeRange,InvalidStep};
protected:
QRectF adjustRect(float percentage);
float getRadius(const QRectF &);
float getAngle(const QPointF&, const QRectF &tmpRect);
QPointF getPoint(float deg, const QRectF &tmpRect);
QRectF resetRect();
void update();
private:
QRectF mRect;
QWidget *parentWidget;
float mPosition;
};
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
class QCGAUGE_DECL QcScaleItem : public QcItem
{
Q_OBJECT
public:
explicit QcScaleItem(QObject *parent = 0);
void setValueRange(float minValue,float maxValue);
void setDgereeRange(float minDegree,float maxDegree);
void setMinValue(float minValue);
void setMaxValue(float maxValue);
void setMinDegree(float minDegree);
void setMaxDegree(float maxDegree);
signals:
public slots:
protected:
float getDegFromValue(float);
float mMinValue;
float mMaxValue;
float mMinDegree;
float mMaxDegree;
};
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
class QCGAUGE_DECL QcBackgroundItem : public QcItem
{
Q_OBJECT
public:
explicit QcBackgroundItem(QObject *parent = 0);
void draw(QPainter*);
void addColor(float position, const QColor& color);
void clearrColors();
private:
QPen mPen;
QList<QPair<float,QColor> > mColors;
QLinearGradient mLinearGrad;
};
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
class QcGlassItem : public QcItem
{
Q_OBJECT
public:
explicit QcGlassItem(QObject *parent = 0);
void draw(QPainter*);
};
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
class QCGAUGE_DECL QcLabelItem : public QcItem
{
Q_OBJECT
public:
explicit QcLabelItem(QObject *parent = 0);
virtual void draw(QPainter *);
void setAngle(float);
float angle();
void setText(const QString &text, bool repaint = true);
QString text();
void setColor(const QColor& color);
QColor color();
private:
float mAngle;
QString mText;
QColor mColor;
};
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
class QCGAUGE_DECL QcArcItem : public QcScaleItem
{
Q_OBJECT
public:
explicit QcArcItem(QObject *parent = 0);
void draw(QPainter*);
void setColor(const QColor& color);
private:
QColor mColor;
signals:
public slots:
};
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
class QCGAUGE_DECL QcColorBand : public QcScaleItem
{
Q_OBJECT
public:
explicit QcColorBand(QObject *parent = 0);
void draw(QPainter*);
void setColors(const QList<QPair<QColor,float> >& colors);
private:
QPainterPath createSubBand(float from,float sweep);
QList<QPair<QColor,float> > mBandColors;
float mBandStartValue;
};
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
class QCGAUGE_DECL QcDegreesItem : public QcScaleItem
{
Q_OBJECT
public:
explicit QcDegreesItem(QObject *parent = 0);
void draw(QPainter *painter);
void setStep(float step);
void setColor(const QColor& color);
void setSubDegree(bool );
private:
float mStep;
QColor mColor;
bool mSubDegree;
};
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
class QCGAUGE_DECL QcNeedleItem : public QcScaleItem
{
Q_OBJECT
public:
explicit QcNeedleItem(QObject *parent = 0);
void draw(QPainter*);
void setCurrentValue(float value);
float currentValue();
void setColor(const QColor & color);
QColor color();
void setLabel(QcLabelItem*);
QcLabelItem * label();
enum NeedleType{DiamonNeedle,TriangleNeedle,FeatherNeedle,AttitudeMeterNeedle,CompassNeedle};//#
void setNeedle(QcNeedleItem::NeedleType needleType);
private:
QPolygonF mNeedlePoly;
float mCurrentValue;
QColor mColor;
void createDiamonNeedle(float r);
void createTriangleNeedle(float r);
void createFeatherNeedle(float r);
void createAttitudeNeedle(float r);
void createCompassNeedle(float r);
NeedleType mNeedleType;
QcLabelItem *mLabel;
};
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
class QCGAUGE_DECL QcValuesItem : public QcScaleItem
{
Q_OBJECT
public:
explicit QcValuesItem(QObject *parent = 0);
void draw(QPainter*);
void setStep(float step);
void setColor(const QColor& color);
private:
float mStep;
QColor mColor;
};
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
class QCGAUGE_DECL QcAttitudeMeter : public QcItem
{
Q_OBJECT
public:
explicit QcAttitudeMeter(QObject *parent = 0);
void draw(QPainter *);
void setCurrentPitch(float pitch);
void setCurrentRoll(float roll);
private:
float mRoll;
float mPitch;
float mPitchOffset;
QPolygonF mHandlePoly;
QPainterPath mStepsPath;
QPointF getIntersection(float r,const QPointF& pitchPoint,const QPointF& pt);
float getStartAngle(const QRectF& tmpRect);
void drawDegrees(QPainter *);
void drawDegree(QPainter * painter, const QRectF& tmpRect,float deg);
void drawUpperEllipse(QPainter *,const QRectF&);
void drawLowerEllipse(QPainter *,const QRectF&);
void drawPitchSteps(QPainter *,const QRectF&);
void drawHandle(QPainter *);
void drawSteps(QPainter *,float);
};
#endif // QCGAUGEWIDGET_H