-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgaugeitem.h
128 lines (124 loc) · 4.91 KB
/
gaugeitem.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
/**************************************************************************
* Copyright (C) 2010 by Michael Carpenter (malcom2073) *
* *
* This file is a part of OBDToolbox *
* *
* OBDToolbox is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* OBDToolbox 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with OBDToolbox. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef GAUGEITEM_H
#define GAUGEITEM_H
#include <QPen>
#include <QDeclarativeItem>
//#include <QPaintEvent>
#include <QPainter>
//#include <QImage>
#include <QTimer>
class GaugeItem : public QDeclarativeItem
{
Q_OBJECT
public:
Q_PROPERTY(double m_value READ getValue WRITE setRaw)
Q_PROPERTY(double startAngle READ getStartAngle WRITE setStartAngle)
Q_PROPERTY(double endAngle READ getEndAngle WRITE setEndAngle)
Q_PROPERTY(double minimum READ getMinimum WRITE setMinimum)
Q_PROPERTY(double maximum READ getMaximum WRITE setMaximum)
Q_PROPERTY(double numLabels READ getNumLabels WRITE setNumLabels)
Q_PROPERTY(int m_style READ getStyle WRITE setStyle)
Q_PROPERTY(QString text READ getText WRITE setText)
GaugeItem();
double getValue() { return m_value; }
void setValue(double value);
void setRaw(double value);
void passEvent(QStringList evt);
void setMinimum(double min) { _minValue = min; }
double getMinimum() { return _minValue;}
double getMaximum() { return _maxValue;}
double getStartAngle() { return _scaleStartAngle;}
double getEndAngle() { return _scaleEndAngle;}
double smoothing() { return _smoothValue;}
double getNumLabels() { return _numLabels;}
int getStyle() { return m_style; }
void setStyle(int style) { m_style = style; m_redrawBackground = true; }
int fade() { return fadeAmount;}
void setFadingOn(bool fade);
void setMaximum(double max) { _maxValue = max; }
void setStartAngle(double ang) { _scaleStartAngle = ang; m_redrawBackground = true;}
void setEndAngle(double ang) { _scaleEndAngle = ang; m_redrawBackground = true; }
void setSmoothing(double smooth) { _smoothValue = smooth; }
void setNumLabels(int num) { _numLabels = num; m_redrawBackground = true;}
void setColor(QColor outlinecolor, QColor centercolor, QColor topreflectioncolor, QColor bottomreflectioncolor);
void setColor1(QColor needlecolor, QColor needleoutlinecolor, QColor normaltickcolor, QColor bigtickcolor, QColor warningtickcolor, QColor dangertickcolor);
void setColor2(QColor fontcolor, QColor warningfontcolor, QColor dangerfontcolor,QFont font);
void startDemo(int max);
void setFade(int fade);
void show();
//void setFake(bool fake) { m_fake = fake;repaint(); }
void setGaugeStyle(int style);
QString getText() { return m_text; }
void setText(QString text) { m_text = text; update(); }
private:
QString m_text;
bool m_redrawBackground;
double m_value;
void geometryChanged (const QRectF &newgeometry,const QRectF &oldgeometry);
int m_style;
bool m_fake;
bool m_fadeEnabled;
int demoMax;
int fadeAmount;
//void paintEvent(QPaintEvent *evt);
//void resizeEvent (QResizeEvent *evt);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *style , QWidget * w);
bool resizeDraw;
void drawBackground(QPainter *tmpPainter);
QImage *_bgImage;
QImage *_fadedBgImage;
QTimer *demoTimer;
QTimer *gaugeTimer;
QTimer *fadeTimer;
double _scaleEndAngle;
double _scaleStartAngle;
double _maxValue;
double _minValue;
double _value;
double _targetValue;
double _danger;
double _warning;
double _smoothValue;
bool _reverseOrder;
int _numLabels;
QPen outlinePen;
QPen needleCenterPen;
QPen needleCenterOutlinePen;
QPen needlePen;
QPen needleOutlinePen;
QPen normalTickPen;
QPen normalBigTickPen;
QPen normalFontPen;
QPen dangerFontPen;
QPen warningFontPen;
QPen dangerTickPen;
QPen dangerBigTickPen;
QPen warningTickPen;
QPen warningBigTickPen;
QFont labelFont;
QFont labelSmallFont;
int fadeCount;
private slots:
void timerTick();
void gaugeTimerTick();
void fadeTimerTick();
};
#endif //GAUGEITEM_H