-
Notifications
You must be signed in to change notification settings - Fork 2
/
Battery.h
78 lines (62 loc) · 2.77 KB
/
Battery.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
//
// Created by TURIING on 2023/6/18.
//
#ifndef QTDEMO_BATTERY_H
#define QTDEMO_BATTERY_H
#include <QWidget>
#include <QtGlobal>
#include <QTimer>
#include <QPainter>
#include <QLinearGradient>
class Battery: public QWidget {
Q_OBJECT
public:
explicit Battery(QWidget *_parent = nullptr);
/* getter */
qreal getMinValue() const;
qreal getMaxValue() const;
qreal getTargetValue() const;
qreal getAlarmValue() const;
bool isEnableAnimation() const;
qreal getAnimationStep() const;
void setMinValue(qreal _minValue);
void setMaxValue(qreal _maxValue);
void setAlarmValue(qreal _alarmValue);
void enableAnimation(bool _animation);
void setAnimationStep(qreal _step);
void setRange(qreal _minValue, qreal _maxValue);
protected:
void paintEvent(QPaintEvent *event) override;
private:
void m_drawBorder(QPainter &_painter);
void m_drawBody(QPainter &_painter);
void m_drawHead(QPainter &_painter);
private:
qreal m_minValue; // 电量最小值
qreal m_maxValue; // 最大值
qreal m_targetValue; // 目标电量
qreal m_currentValue; // 当前电量
qreal m_alarmValue; // 电量警戒值
bool m_isEnableAnimation; // 是否启用动画效果
qreal m_animationStep; // 动画显示的步长
uint m_borderWidth; // 边框宽度
uint m_borderRadius; // 边框圆角角度
uint m_bodyRadius; // 电量进度条圆角角度
uint m_headRadius; // 头部的圆角角度
QColor m_borderColorStart; // 边框渐变开始时的颜色
QColor m_borderColorEnd; // 边框渐变结束时的颜色
QColor m_alarmColorStart; // 低电量时渐变开始的颜色
QColor m_alarmColorEnd; // 低电量时渐变结束的颜色
QColor m_normalColorStart; // 电量正常时渐变开始的颜色
QColor m_normalColorEnd; // 电量正常时渐变结束的颜色
bool m_isForward; // 是否往前移动
QRectF m_batteryArea; // 电池主体区域
QTimer *m_timer;
public slots:
void setTargetValue(qreal _targetValue);
private slots:
void m_updateValue();
public: signals:
void valueChanged(qreal _value);
};
#endif //QTDEMO_BATTERY_H