-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathcircularprogress.hpp
More file actions
104 lines (80 loc) · 3.44 KB
/
circularprogress.hpp
File metadata and controls
104 lines (80 loc) · 3.44 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
#pragma once
#include <QWidget>
class CircularProgress : 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(bool showPercent READ showPercent WRITE setShowPercent)
Q_PROPERTY(QString title READ title WRITE setTitle)
Q_PROPERTY(QColor arcColor READ arcColor WRITE setArcColor)
Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor)
Q_PROPERTY(QColor baseColor READ baseColor WRITE setBaseColor)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
Q_PROPERTY(int animationDuration READ animationDuration WRITE setAnimationDuration)
public:
explicit CircularProgress(const QString &title = "Progress", QWidget *parent = nullptr);
~CircularProgress() 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 setShowPercent(bool percent);
[[nodiscard]] auto showPercent() const -> bool;
void setTitle(const QString &title);
[[nodiscard]] auto title() const -> QString;
// 颜色设置
void setArcColor(const QColor &color);
[[nodiscard]] auto arcColor() const -> QColor;
void setTextColor(const QColor &color);
[[nodiscard]] auto textColor() const -> QColor;
void setTitleColor(const QColor &color);
[[nodiscard]] auto titleColor() const -> QColor;
void setBaseColor(const QColor &color);
[[nodiscard]] auto baseColor() const -> QColor;
void setBackgroundColor(const QColor &color);
[[nodiscard]] auto backgroundColor() 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 getValueRect(double minSize) const;
QRectF getTitleRect(double minSize) const;
void drawArc(QPainter *painter, double minSize);
void drawText(QPainter *painter, double minSize);
void startAnimation(double targetValue);
class CircularProgressPrivate;
QScopedPointer<CircularProgressPrivate> d_ptr;
};