更新代码

This commit is contained in:
feiyangqingyun
2020-08-02 15:20:06 +08:00
parent 185e3e5f2c
commit eb46edf769
3 changed files with 72 additions and 71 deletions

View File

@@ -57,8 +57,8 @@ void Battery::drawBorder(QPainter *painter)
{
painter->save();
double headWidth = width() / 10;
double batteryWidth = width() - headWidth;
qreal headWidth = width() / 10;
qreal batteryWidth = width() - headWidth;
//绘制电池边框
QPointF topLeft(5, 5);
@@ -86,8 +86,8 @@ void Battery::drawBg(QPainter *painter)
}
int margin = qMin(width(), height()) / 20;
double unit = (batteryRect.width() - (margin * 2)) / 100;
double width = currentValue * unit;
qreal unit = (batteryRect.width() - (margin * 2)) / 100;
qreal width = currentValue * unit;
QPointF topLeft(batteryRect.topLeft().x() + margin, batteryRect.topLeft().y() + margin);
QPointF bottomRight(width + margin + 5, batteryRect.bottomRight().y() - margin);
QRectF rect(topLeft, bottomRight);
@@ -137,27 +137,27 @@ void Battery::updateValue()
this->update();
}
double Battery::getMinValue() const
qreal Battery::getMinValue() const
{
return this->minValue;
}
double Battery::getMaxValue() const
qreal Battery::getMaxValue() const
{
return this->maxValue;
}
double Battery::getValue() const
qreal Battery::getValue() const
{
return this->value;
}
double Battery::getAlarmValue() const
qreal Battery::getAlarmValue() const
{
return this->alarmValue;
}
double Battery::getStep() const
qreal Battery::getStep() const
{
return this->step;
}
@@ -217,7 +217,7 @@ QSize Battery::minimumSizeHint() const
return QSize(30, 10);
}
void Battery::setRange(double minValue, double maxValue)
void Battery::setRange(qreal minValue, qreal maxValue)
{
//如果最小值大于或者等于最大值则不设置
if (minValue >= maxValue) {
@@ -240,20 +240,20 @@ void Battery::setRange(double minValue, double maxValue)
void Battery::setRange(int minValue, int maxValue)
{
setRange((double)minValue, (double)maxValue);
setRange((qreal)minValue, (qreal)maxValue);
}
void Battery::setMinValue(double minValue)
void Battery::setMinValue(qreal minValue)
{
setRange(minValue, maxValue);
}
void Battery::setMaxValue(double maxValue)
void Battery::setMaxValue(qreal maxValue)
{
setRange(minValue, maxValue);
}
void Battery::setValue(double value)
void Battery::setValue(qreal value)
{
//值和当前值一致则无需处理
if (value == this->value) {
@@ -283,10 +283,10 @@ void Battery::setValue(double value)
void Battery::setValue(int value)
{
setValue((double)value);
setValue((qreal)value);
}
void Battery::setAlarmValue(double alarmValue)
void Battery::setAlarmValue(qreal alarmValue)
{
if (this->alarmValue != alarmValue) {
this->alarmValue = alarmValue;
@@ -296,10 +296,10 @@ void Battery::setAlarmValue(double alarmValue)
void Battery::setAlarmValue(int alarmValue)
{
setAlarmValue((double)alarmValue);
setAlarmValue((qreal)alarmValue);
}
void Battery::setStep(double step)
void Battery::setStep(qreal step)
{
if (this->step != step) {
this->step = step;
@@ -309,7 +309,7 @@ void Battery::setStep(double step)
void Battery::setStep(int step)
{
setStep((double)step);
setStep((qreal)step);
}
void Battery::setBorderRadius(int borderRadius)

View File

@@ -3,12 +3,12 @@
/**
* 电池电量控件 作者:feiyangqingyun(QQ:517216493) 2016-10-23
* 1:可设置电池电量,动态切换电池电量变化
* 2:可设置电池电量警戒值
* 3:可设置电池电量正常颜色和报警颜色
* 4:可设置边框渐变颜色
* 5:可设置电量变化时每次移动的步长
* 6:可设置边框圆角角度/背景进度圆角角度/头部圆角角度
* 1. 可设置电池电量,动态切换电池电量变化
* 2. 可设置电池电量警戒值
* 3. 可设置电池电量正常颜色和报警颜色
* 4. 可设置边框渐变颜色
* 5. 可设置电量变化时每次移动的步长
* 6. 可设置边框圆角角度/背景进度圆角角度/头部圆角角度
*/
#include <QWidget>
@@ -27,12 +27,12 @@ class Battery : public QWidget
{
Q_OBJECT
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)
Q_PROPERTY(qreal minValue READ getMinValue WRITE setMinValue)
Q_PROPERTY(qreal maxValue READ getMaxValue WRITE setMaxValue)
Q_PROPERTY(qreal value READ getValue WRITE setValue)
Q_PROPERTY(qreal alarmValue READ getAlarmValue WRITE setAlarmValue)
Q_PROPERTY(double step READ getStep WRITE setStep)
Q_PROPERTY(qreal step READ getStep WRITE setStep)
Q_PROPERTY(int borderRadius READ getBorderRadius WRITE setBorderRadius)
Q_PROPERTY(int bgRadius READ getBgRadius WRITE setBgRadius)
Q_PROPERTY(int headRadius READ getHeadRadius WRITE setHeadRadius)
@@ -60,72 +60,72 @@ private slots:
void updateValue();
private:
double minValue; //最小值
double maxValue; //最大值
double value; //目标电量
double alarmValue; //电池电量警戒值
qreal minValue; //最小值
qreal maxValue; //最大值
qreal value; //目标电量
qreal alarmValue; //电池电量警戒值
double step; //每次移动的步长
int borderRadius; //边框圆角角度
int bgRadius; //背景进度圆角角度
int headRadius; //头部圆角角度
qreal step; //每次移动的步长
int borderRadius; //边框圆角角度
int bgRadius; //背景进度圆角角度
int headRadius; //头部圆角角度
QColor borderColorStart; //边框渐变开始颜色
QColor borderColorEnd; //边框渐变结束颜色
QColor borderColorStart; //边框渐变开始颜色
QColor borderColorEnd; //边框渐变结束颜色
QColor alarmColorStart; //电池低电量时的渐变开始颜色
QColor alarmColorEnd; //电池低电量时的渐变结束颜色
QColor alarmColorStart; //电池低电量时的渐变开始颜色
QColor alarmColorEnd; //电池低电量时的渐变结束颜色
QColor normalColorStart; //电池正常电量时的渐变开始颜色
QColor normalColorEnd; //电池正常电量时的渐变结束颜色
QColor normalColorStart; //电池正常电量时的渐变开始颜色
QColor normalColorEnd; //电池正常电量时的渐变结束颜色
bool isForward; //是否往前移
double currentValue; //当前电量
QRectF batteryRect; //电池主体区域
QTimer *timer; //绘制定时器
bool isForward; //是否往前移
qreal currentValue; //当前电量
QRectF batteryRect; //电池主体区域
QTimer *timer; //绘制定时器
public:
double getMinValue() const;
double getMaxValue() const;
double getValue() const;
double getAlarmValue() const;
qreal getMinValue() const;
qreal getMaxValue() const;
qreal getValue() const;
qreal getAlarmValue() const;
double getStep() const;
int getBorderRadius() const;
int getBgRadius() const;
int getHeadRadius() const;
qreal getStep() const;
int getBorderRadius() const;
int getBgRadius() const;
int getHeadRadius() const;
QColor getBorderColorStart() const;
QColor getBorderColorEnd() const;
QColor getBorderColorStart()const;
QColor getBorderColorEnd() const;
QColor getAlarmColorStart() const;
QColor getAlarmColorEnd() const;
QColor getAlarmColorStart() const;
QColor getAlarmColorEnd() const;
QColor getNormalColorStart() const;
QColor getNormalColorEnd() const;
QColor getNormalColorStart()const;
QColor getNormalColorEnd() const;
QSize sizeHint() const;
QSize minimumSizeHint() const;
QSize sizeHint() const;
QSize minimumSizeHint() const;
public Q_SLOTS:
//设置范围值
void setRange(double minValue, double maxValue);
void setRange(qreal minValue, qreal maxValue);
void setRange(int minValue, int maxValue);
//设置最大最小值
void setMinValue(double minValue);
void setMaxValue(double maxValue);
void setMinValue(qreal minValue);
void setMaxValue(qreal maxValue);
//设置电池电量值
void setValue(double value);
void setValue(qreal value);
void setValue(int value);
//设置电池电量警戒值
void setAlarmValue(double alarmValue);
void setAlarmValue(qreal alarmValue);
void setAlarmValue(int alarmValue);
//设置步长
void setStep(double step);
void setStep(qreal step);
void setStep(int step);
//设置边框圆角角度
@@ -148,7 +148,7 @@ public Q_SLOTS:
void setNormalColorEnd(const QColor &normalColorEnd);
Q_SIGNALS:
void valueChanged(double value);
void valueChanged(qreal value);
};
#endif // BATTERY_H

View File

@@ -6,6 +6,7 @@ frmDbPage::frmDbPage(QWidget *parent) : QWidget(parent), ui(new Ui::frmDbPage)
{
ui->setupUi(this);
this->initForm();
on_btnSelect_clicked();
}
frmDbPage::~frmDbPage()