更新代码
This commit is contained in:
@@ -57,8 +57,8 @@ void Battery::drawBorder(QPainter *painter)
|
|||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
double headWidth = width() / 10;
|
qreal headWidth = width() / 10;
|
||||||
double batteryWidth = width() - headWidth;
|
qreal batteryWidth = width() - headWidth;
|
||||||
|
|
||||||
//绘制电池边框
|
//绘制电池边框
|
||||||
QPointF topLeft(5, 5);
|
QPointF topLeft(5, 5);
|
||||||
@@ -86,8 +86,8 @@ void Battery::drawBg(QPainter *painter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int margin = qMin(width(), height()) / 20;
|
int margin = qMin(width(), height()) / 20;
|
||||||
double unit = (batteryRect.width() - (margin * 2)) / 100;
|
qreal unit = (batteryRect.width() - (margin * 2)) / 100;
|
||||||
double width = currentValue * unit;
|
qreal width = currentValue * unit;
|
||||||
QPointF topLeft(batteryRect.topLeft().x() + margin, batteryRect.topLeft().y() + margin);
|
QPointF topLeft(batteryRect.topLeft().x() + margin, batteryRect.topLeft().y() + margin);
|
||||||
QPointF bottomRight(width + margin + 5, batteryRect.bottomRight().y() - margin);
|
QPointF bottomRight(width + margin + 5, batteryRect.bottomRight().y() - margin);
|
||||||
QRectF rect(topLeft, bottomRight);
|
QRectF rect(topLeft, bottomRight);
|
||||||
@@ -137,27 +137,27 @@ void Battery::updateValue()
|
|||||||
this->update();
|
this->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
double Battery::getMinValue() const
|
qreal Battery::getMinValue() const
|
||||||
{
|
{
|
||||||
return this->minValue;
|
return this->minValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Battery::getMaxValue() const
|
qreal Battery::getMaxValue() const
|
||||||
{
|
{
|
||||||
return this->maxValue;
|
return this->maxValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Battery::getValue() const
|
qreal Battery::getValue() const
|
||||||
{
|
{
|
||||||
return this->value;
|
return this->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Battery::getAlarmValue() const
|
qreal Battery::getAlarmValue() const
|
||||||
{
|
{
|
||||||
return this->alarmValue;
|
return this->alarmValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Battery::getStep() const
|
qreal Battery::getStep() const
|
||||||
{
|
{
|
||||||
return this->step;
|
return this->step;
|
||||||
}
|
}
|
||||||
@@ -217,7 +217,7 @@ QSize Battery::minimumSizeHint() const
|
|||||||
return QSize(30, 10);
|
return QSize(30, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Battery::setRange(double minValue, double maxValue)
|
void Battery::setRange(qreal minValue, qreal maxValue)
|
||||||
{
|
{
|
||||||
//如果最小值大于或者等于最大值则不设置
|
//如果最小值大于或者等于最大值则不设置
|
||||||
if (minValue >= maxValue) {
|
if (minValue >= maxValue) {
|
||||||
@@ -240,20 +240,20 @@ void Battery::setRange(double minValue, double maxValue)
|
|||||||
|
|
||||||
void Battery::setRange(int minValue, int 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);
|
setRange(minValue, maxValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Battery::setMaxValue(double maxValue)
|
void Battery::setMaxValue(qreal maxValue)
|
||||||
{
|
{
|
||||||
setRange(minValue, maxValue);
|
setRange(minValue, maxValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Battery::setValue(double value)
|
void Battery::setValue(qreal value)
|
||||||
{
|
{
|
||||||
//值和当前值一致则无需处理
|
//值和当前值一致则无需处理
|
||||||
if (value == this->value) {
|
if (value == this->value) {
|
||||||
@@ -283,10 +283,10 @@ void Battery::setValue(double value)
|
|||||||
|
|
||||||
void Battery::setValue(int 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) {
|
if (this->alarmValue != alarmValue) {
|
||||||
this->alarmValue = alarmValue;
|
this->alarmValue = alarmValue;
|
||||||
@@ -296,10 +296,10 @@ void Battery::setAlarmValue(double alarmValue)
|
|||||||
|
|
||||||
void Battery::setAlarmValue(int 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) {
|
if (this->step != step) {
|
||||||
this->step = step;
|
this->step = step;
|
||||||
@@ -309,7 +309,7 @@ void Battery::setStep(double step)
|
|||||||
|
|
||||||
void Battery::setStep(int step)
|
void Battery::setStep(int step)
|
||||||
{
|
{
|
||||||
setStep((double)step);
|
setStep((qreal)step);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Battery::setBorderRadius(int borderRadius)
|
void Battery::setBorderRadius(int borderRadius)
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 电池电量控件 作者:feiyangqingyun(QQ:517216493) 2016-10-23
|
* 电池电量控件 作者:feiyangqingyun(QQ:517216493) 2016-10-23
|
||||||
* 1:可设置电池电量,动态切换电池电量变化
|
* 1. 可设置电池电量,动态切换电池电量变化
|
||||||
* 2:可设置电池电量警戒值
|
* 2. 可设置电池电量警戒值
|
||||||
* 3:可设置电池电量正常颜色和报警颜色
|
* 3. 可设置电池电量正常颜色和报警颜色
|
||||||
* 4:可设置边框渐变颜色
|
* 4. 可设置边框渐变颜色
|
||||||
* 5:可设置电量变化时每次移动的步长
|
* 5. 可设置电量变化时每次移动的步长
|
||||||
* 6:可设置边框圆角角度/背景进度圆角角度/头部圆角角度
|
* 6. 可设置边框圆角角度/背景进度圆角角度/头部圆角角度
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
@@ -27,12 +27,12 @@ class Battery : public QWidget
|
|||||||
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(double minValue READ getMinValue WRITE setMinValue)
|
Q_PROPERTY(qreal minValue READ getMinValue WRITE setMinValue)
|
||||||
Q_PROPERTY(double maxValue READ getMaxValue WRITE setMaxValue)
|
Q_PROPERTY(qreal maxValue READ getMaxValue WRITE setMaxValue)
|
||||||
Q_PROPERTY(double value READ getValue WRITE setValue)
|
Q_PROPERTY(qreal value READ getValue WRITE setValue)
|
||||||
Q_PROPERTY(double alarmValue READ getAlarmValue WRITE setAlarmValue)
|
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 borderRadius READ getBorderRadius WRITE setBorderRadius)
|
||||||
Q_PROPERTY(int bgRadius READ getBgRadius WRITE setBgRadius)
|
Q_PROPERTY(int bgRadius READ getBgRadius WRITE setBgRadius)
|
||||||
Q_PROPERTY(int headRadius READ getHeadRadius WRITE setHeadRadius)
|
Q_PROPERTY(int headRadius READ getHeadRadius WRITE setHeadRadius)
|
||||||
@@ -60,12 +60,12 @@ private slots:
|
|||||||
void updateValue();
|
void updateValue();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double minValue; //最小值
|
qreal minValue; //最小值
|
||||||
double maxValue; //最大值
|
qreal maxValue; //最大值
|
||||||
double value; //目标电量
|
qreal value; //目标电量
|
||||||
double alarmValue; //电池电量警戒值
|
qreal alarmValue; //电池电量警戒值
|
||||||
|
|
||||||
double step; //每次移动的步长
|
qreal step; //每次移动的步长
|
||||||
int borderRadius; //边框圆角角度
|
int borderRadius; //边框圆角角度
|
||||||
int bgRadius; //背景进度圆角角度
|
int bgRadius; //背景进度圆角角度
|
||||||
int headRadius; //头部圆角角度
|
int headRadius; //头部圆角角度
|
||||||
@@ -80,28 +80,28 @@ private:
|
|||||||
QColor normalColorEnd; //电池正常电量时的渐变结束颜色
|
QColor normalColorEnd; //电池正常电量时的渐变结束颜色
|
||||||
|
|
||||||
bool isForward; //是否往前移
|
bool isForward; //是否往前移
|
||||||
double currentValue; //当前电量
|
qreal currentValue; //当前电量
|
||||||
QRectF batteryRect; //电池主体区域
|
QRectF batteryRect; //电池主体区域
|
||||||
QTimer *timer; //绘制定时器
|
QTimer *timer; //绘制定时器
|
||||||
|
|
||||||
public:
|
public:
|
||||||
double getMinValue() const;
|
qreal getMinValue() const;
|
||||||
double getMaxValue() const;
|
qreal getMaxValue() const;
|
||||||
double getValue() const;
|
qreal getValue() const;
|
||||||
double getAlarmValue() const;
|
qreal getAlarmValue() const;
|
||||||
|
|
||||||
double getStep() const;
|
qreal getStep() const;
|
||||||
int getBorderRadius() const;
|
int getBorderRadius() const;
|
||||||
int getBgRadius() const;
|
int getBgRadius() const;
|
||||||
int getHeadRadius() const;
|
int getHeadRadius() const;
|
||||||
|
|
||||||
QColor getBorderColorStart() const;
|
QColor getBorderColorStart()const;
|
||||||
QColor getBorderColorEnd() const;
|
QColor getBorderColorEnd() const;
|
||||||
|
|
||||||
QColor getAlarmColorStart() const;
|
QColor getAlarmColorStart() const;
|
||||||
QColor getAlarmColorEnd() const;
|
QColor getAlarmColorEnd() const;
|
||||||
|
|
||||||
QColor getNormalColorStart() const;
|
QColor getNormalColorStart()const;
|
||||||
QColor getNormalColorEnd() const;
|
QColor getNormalColorEnd() const;
|
||||||
|
|
||||||
QSize sizeHint() const;
|
QSize sizeHint() const;
|
||||||
@@ -109,23 +109,23 @@ public:
|
|||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
//设置范围值
|
//设置范围值
|
||||||
void setRange(double minValue, double maxValue);
|
void setRange(qreal minValue, qreal maxValue);
|
||||||
void setRange(int minValue, int maxValue);
|
void setRange(int minValue, int maxValue);
|
||||||
|
|
||||||
//设置最大最小值
|
//设置最大最小值
|
||||||
void setMinValue(double minValue);
|
void setMinValue(qreal minValue);
|
||||||
void setMaxValue(double maxValue);
|
void setMaxValue(qreal maxValue);
|
||||||
|
|
||||||
//设置电池电量值
|
//设置电池电量值
|
||||||
void setValue(double value);
|
void setValue(qreal value);
|
||||||
void setValue(int value);
|
void setValue(int value);
|
||||||
|
|
||||||
//设置电池电量警戒值
|
//设置电池电量警戒值
|
||||||
void setAlarmValue(double alarmValue);
|
void setAlarmValue(qreal alarmValue);
|
||||||
void setAlarmValue(int alarmValue);
|
void setAlarmValue(int alarmValue);
|
||||||
|
|
||||||
//设置步长
|
//设置步长
|
||||||
void setStep(double step);
|
void setStep(qreal step);
|
||||||
void setStep(int step);
|
void setStep(int step);
|
||||||
|
|
||||||
//设置边框圆角角度
|
//设置边框圆角角度
|
||||||
@@ -148,7 +148,7 @@ public Q_SLOTS:
|
|||||||
void setNormalColorEnd(const QColor &normalColorEnd);
|
void setNormalColorEnd(const QColor &normalColorEnd);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void valueChanged(double value);
|
void valueChanged(qreal value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BATTERY_H
|
#endif // BATTERY_H
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ frmDbPage::frmDbPage(QWidget *parent) : QWidget(parent), ui(new Ui::frmDbPage)
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->initForm();
|
this->initForm();
|
||||||
|
on_btnSelect_clicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
frmDbPage::~frmDbPage()
|
frmDbPage::~frmDbPage()
|
||||||
|
|||||||
Reference in New Issue
Block a user