-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathdashboardwidget.h
More file actions
124 lines (96 loc) · 4.26 KB
/
Copy pathdashboardwidget.h
File metadata and controls
124 lines (96 loc) · 4.26 KB
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
#pragma once
#include <QWidget>
class DashBoardWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged)
Q_PROPERTY(double minValue READ minValue WRITE setMinValue)
Q_PROPERTY(double maxValue READ maxValue WRITE setMaxValue)
Q_PROPERTY(double startAngle READ startAngle WRITE setStartAngle)
Q_PROPERTY(double endAngle READ endAngle WRITE setEndAngle)
Q_PROPERTY(int scaleMajor READ scaleMajor WRITE setScaleMajor)
Q_PROPERTY(int scaleMinor READ scaleMinor WRITE setScaleMinor)
Q_PROPERTY(QString unit READ unit WRITE setUnit)
Q_PROPERTY(QString title READ title WRITE setTitle)
Q_PROPERTY(QColor arcColor READ arcColor WRITE setArcColor)
Q_PROPERTY(QColor scaleColor READ scaleColor WRITE setScaleColor)
Q_PROPERTY(QColor pointerColor READ pointerColor WRITE setPointerColor)
Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
Q_PROPERTY(QColor valueColor READ valueColor WRITE setValueColor)
Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor)
Q_PROPERTY(int animationDuration READ animationDuration WRITE setAnimationDuration)
public:
explicit DashBoardWidget(QWidget *parent = nullptr);
~DashBoardWidget() override;
[[nodiscard]] auto minimumSizeHint() const -> QSize override;
// 数值设置
void setValueAnimated(double value);
void setValue(double value);
[[nodiscard]] auto value() const -> double;
void setMinValue(double min);
[[nodiscard]] auto minValue() const -> double;
void setMaxValue(double max);
[[nodiscard]] auto maxValue() const -> double;
// 角度设置
void setStartAngle(double startAngle);
[[nodiscard]] auto startAngle() const -> double;
void setEndAngle(double endAngle);
[[nodiscard]] auto endAngle() const -> double;
// 刻度设置
void setScaleMajor(int scale);
[[nodiscard]] auto scaleMajor() const -> int;
void setScaleMinor(int scale);
[[nodiscard]] auto scaleMinor() const -> int;
// 文本设置
void setUnit(const QString &unit);
[[nodiscard]] auto unit() const -> QString;
void setTitle(const QString &title);
[[nodiscard]] auto title() const -> QString;
// 颜色设置
void setArcColor(const QColor &color);
[[nodiscard]] auto arcColor() const -> QColor;
void setScaleColor(const QColor &color);
[[nodiscard]] auto scaleColor() const -> QColor;
void setPointerColor(const QColor &color);
[[nodiscard]] auto pointerColor() const -> QColor;
void setTextColor(const QColor &color);
[[nodiscard]] auto textColor() const -> QColor;
void setBackgroundColor(const QColor &color);
[[nodiscard]] auto backgroundColor() const -> QColor;
void setValueColor(const QColor &color);
[[nodiscard]] auto valueColor() const -> QColor;
void setTitleColor(const QColor &color);
[[nodiscard]] auto titleColor() const -> QColor;
// 动画设置
void setAnimationDuration(int duration);
[[nodiscard]] auto animationDuration() const -> int;
[[nodiscard]] bool isAnimating() const;
public slots:
void increaseValue(double increment = 1.0);
void decreaseValue(double decrement = 1.0);
void reset();
signals:
void valueChanged(double value);
void valueIncreased(double newValue);
void valueDecreased(double newValue);
void valueReset();
void animationStarted(double oldValue, double newValue);
void animationFinished(double value);
protected:
void paintEvent(QPaintEvent *event) override;
private slots:
void onAnimationFinished();
private:
void setupFont(QPainter *painter, double minSize, double ratio);
QRectF getTextRect(double minSize, double verticalRatio, double heightRatio) const;
void drawArc(QPainter *painter, double minSize);
void drawScale(QPainter *painter, double minSize);
void drawScaleNumbers(QPainter *painter, double minSize);
void drawPointer(QPainter *painter, double minSize);
void drawValue(QPainter *painter, double minSize);
void drawTitle(QPainter *painter, double minSize);
void startAnimation(double targetValue);
class DashBoardWidgetPrivate;
QScopedPointer<DashBoardWidgetPrivate> d_ptr;
};