qt_demoe/control/battery/battery.h

167 lines
5.3 KiB
C
Raw Normal View History

2019-10-23 06:32:50 +00:00
#ifndef BATTERY_H
#define BATTERY_H
/**
* :feiyangqingyun(QQ:517216493) 2016-10-23
2021-09-13 08:12:35 +00:00
* 1.
* 2.
* 3.
* 4.
* 5.
* 6.
2019-10-23 06:32:50 +00:00
*/
#include <QWidget>
#ifdef quc
2020-12-24 10:00:09 +00:00
class Q_DECL_EXPORT Battery : public QWidget
2019-10-23 06:32:50 +00:00
#else
class Battery : public QWidget
#endif
{
2021-05-30 07:59:42 +00:00
Q_OBJECT
2020-12-24 10:00:09 +00:00
Q_PROPERTY(double minValue READ getMinValue WRITE setMinValue)
Q_PROPERTY(double maxValue READ getMaxValue WRITE setMaxValue)
Q_PROPERTY(double value READ getValue WRITE setValue)
Q_PROPERTY(double alarmValue READ getAlarmValue WRITE setAlarmValue)
2019-10-23 06:32:50 +00:00
2023-03-20 07:04:23 +00:00
Q_PROPERTY(bool animation READ getAnimation WRITE setAnimation)
Q_PROPERTY(double animationStep READ getAnimationStep WRITE setAnimationStep)
2020-12-24 10:00:09 +00:00
Q_PROPERTY(int borderWidth READ getBorderWidth WRITE setBorderWidth)
2019-10-23 06:32:50 +00:00
Q_PROPERTY(int borderRadius READ getBorderRadius WRITE setBorderRadius)
Q_PROPERTY(int bgRadius READ getBgRadius WRITE setBgRadius)
Q_PROPERTY(int headRadius READ getHeadRadius WRITE setHeadRadius)
Q_PROPERTY(QColor borderColorStart READ getBorderColorStart WRITE setBorderColorStart)
Q_PROPERTY(QColor borderColorEnd READ getBorderColorEnd WRITE setBorderColorEnd)
Q_PROPERTY(QColor alarmColorStart READ getAlarmColorStart WRITE setAlarmColorStart)
Q_PROPERTY(QColor alarmColorEnd READ getAlarmColorEnd WRITE setAlarmColorEnd)
Q_PROPERTY(QColor normalColorStart READ getNormalColorStart WRITE setNormalColorStart)
Q_PROPERTY(QColor normalColorEnd READ getNormalColorEnd WRITE setNormalColorEnd)
public:
explicit Battery(QWidget *parent = 0);
~Battery();
protected:
void paintEvent(QPaintEvent *);
void drawBorder(QPainter *painter);
void drawBg(QPainter *painter);
void drawHead(QPainter *painter);
private slots:
void updateValue();
2021-05-30 07:59:42 +00:00
private:
2023-09-08 05:51:39 +00:00
double minValue; //最小值
double maxValue; //最大值
double value; //目标电量
double alarmValue; //电池电量警戒值
2019-10-23 06:32:50 +00:00
2023-09-08 05:51:39 +00:00
bool animation; //是否启用动画显示
double animationStep; //动画显示时步长
2023-03-20 07:04:23 +00:00
2023-09-08 05:51:39 +00:00
int borderWidth; //边框粗细
int borderRadius; //边框圆角角度
int bgRadius; //背景进度圆角角度
int headRadius; //头部圆角角度
2019-10-23 06:32:50 +00:00
2023-09-08 05:51:39 +00:00
QColor borderColorStart;//边框渐变开始颜色
QColor borderColorEnd; //边框渐变结束颜色
2019-10-23 06:32:50 +00:00
2023-09-08 05:51:39 +00:00
QColor alarmColorStart; //电池低电量时的渐变开始颜色
QColor alarmColorEnd; //电池低电量时的渐变结束颜色
2019-10-23 06:32:50 +00:00
2023-09-08 05:51:39 +00:00
QColor normalColorStart;//电池正常电量时的渐变开始颜色
QColor normalColorEnd; //电池正常电量时的渐变结束颜色
2019-10-23 06:32:50 +00:00
2023-09-08 05:51:39 +00:00
bool isForward; //是否往前移
double currentValue; //当前电量
QRectF batteryRect; //电池主体区域
QTimer *timer; //绘制定时器
2019-10-23 06:32:50 +00:00
2021-05-30 07:59:42 +00:00
public:
2023-09-08 05:51:39 +00:00
//默认尺寸和最小尺寸
QSize sizeHint() const;
QSize minimumSizeHint() const;
2019-10-23 06:32:50 +00:00
//设置范围值
2020-12-24 10:00:09 +00:00
void setRange(double minValue, double maxValue);
2019-10-23 06:32:50 +00:00
void setRange(int minValue, int maxValue);
2023-09-08 05:51:39 +00:00
//获取和设置最小值
double getMinValue() const;
2020-12-24 10:00:09 +00:00
void setMinValue(double minValue);
2023-09-08 05:51:39 +00:00
//获取和设置最大值
double getMaxValue() const;
2020-12-24 10:00:09 +00:00
void setMaxValue(double maxValue);
2019-10-23 06:32:50 +00:00
2023-09-08 05:51:39 +00:00
//获取和设置电池电量值
double getValue() const;
2020-12-24 10:00:09 +00:00
void setValue(double value);
2019-10-23 06:32:50 +00:00
2023-09-08 05:51:39 +00:00
//获取和设置电池电量警戒值
double getAlarmValue() const;
2020-12-24 10:00:09 +00:00
void setAlarmValue(double alarmValue);
2019-10-23 06:32:50 +00:00
2023-09-08 05:51:39 +00:00
//获取和设置是否启用动画显示
bool getAnimation() const;
2023-03-20 07:04:23 +00:00
void setAnimation(bool animation);
2023-09-08 05:51:39 +00:00
//获取和设置动画显示的步长
double getAnimationStep() const;
2023-03-20 07:04:23 +00:00
void setAnimationStep(double animationStep);
2019-10-23 06:32:50 +00:00
2023-09-08 05:51:39 +00:00
//获取和设置边框粗细
int getBorderWidth() const;
2020-12-24 10:00:09 +00:00
void setBorderWidth(int borderWidth);
2023-09-08 05:51:39 +00:00
//获取和设置边框圆角角度
int getBorderRadius() const;
2019-10-23 06:32:50 +00:00
void setBorderRadius(int borderRadius);
2023-09-08 05:51:39 +00:00
//获取和设置背景圆角角度
int getBgRadius() const;
2019-10-23 06:32:50 +00:00
void setBgRadius(int bgRadius);
2023-09-08 05:51:39 +00:00
//获取和设置头部圆角角度
int getHeadRadius() const;
2019-10-23 06:32:50 +00:00
void setHeadRadius(int headRadius);
2023-09-08 05:51:39 +00:00
//获取和设置边框渐变颜色
QColor getBorderColorStart() const;
2019-10-23 06:32:50 +00:00
void setBorderColorStart(const QColor &borderColorStart);
2023-09-08 05:51:39 +00:00
QColor getBorderColorEnd() const;
2019-10-23 06:32:50 +00:00
void setBorderColorEnd(const QColor &borderColorEnd);
2023-09-08 05:51:39 +00:00
//获取和设置电池电量报警时的渐变颜色
QColor getAlarmColorStart() const;
2019-10-23 06:32:50 +00:00
void setAlarmColorStart(const QColor &alarmColorStart);
2023-09-08 05:51:39 +00:00
QColor getAlarmColorEnd() const;
2019-10-23 06:32:50 +00:00
void setAlarmColorEnd(const QColor &alarmColorEnd);
2023-09-08 05:51:39 +00:00
//获取和设置电池电量正常时的渐变颜色
QColor getNormalColorStart() const;
2019-10-23 06:32:50 +00:00
void setNormalColorStart(const QColor &normalColorStart);
2023-09-08 05:51:39 +00:00
QColor getNormalColorEnd() const;
2019-10-23 06:32:50 +00:00
void setNormalColorEnd(const QColor &normalColorEnd);
2023-09-08 05:51:39 +00:00
public Q_SLOTS:
void setValue(int value);
void setAlarmValue(int alarmValue);
2019-10-23 06:32:50 +00:00
Q_SIGNALS:
2020-12-24 10:00:09 +00:00
void valueChanged(double value);
2019-10-23 06:32:50 +00:00
};
#endif // BATTERY_H