更新文档

This commit is contained in:
feiyangqingyun
2023-03-20 15:04:50 +08:00
parent de1053676c
commit 016603fbc5
37 changed files with 183 additions and 125 deletions

View File

@@ -11,7 +11,9 @@ Battery::Battery(QWidget *parent) : QWidget(parent)
maxValue = 100;
value = 0;
alarmValue = 30;
step = 0.5;
animation = true;
animationStep = 0.5;
borderWidth = 5;
borderRadius = 8;
@@ -91,7 +93,7 @@ void Battery::drawBg(QPainter *painter)
}
int margin = qMin(width(), height()) / 20;
double unit = (batteryRect.width() - (margin * 2)) / 100;
double unit = (batteryRect.width() - (margin * 2)) / (maxValue - minValue);
double width = currentValue * unit;
QPointF topLeft(batteryRect.topLeft().x() + margin, batteryRect.topLeft().y() + margin);
QPointF bottomRight(width + margin + borderWidth, batteryRect.bottomRight().y() - margin);
@@ -126,13 +128,13 @@ void Battery::drawHead(QPainter *painter)
void Battery::updateValue()
{
if (isForward) {
currentValue -= step;
currentValue -= animationStep;
if (currentValue <= value) {
currentValue = value;
timer->stop();
}
} else {
currentValue += step;
currentValue += animationStep;
if (currentValue >= value) {
currentValue = value;
timer->stop();
@@ -162,9 +164,14 @@ double Battery::getAlarmValue() const
return this->alarmValue;
}
double Battery::getStep() const
bool Battery::getAnimation() const
{
return this->step;
return this->animation;
}
double Battery::getAnimationStep() const
{
return this->animationStep;
}
int Battery::getBorderWidth() const
@@ -288,10 +295,14 @@ void Battery::setValue(double value)
}
this->value = value;
this->update();
emit valueChanged(value);
timer->stop();
timer->start();
if (animation) {
timer->stop();
timer->start();
} else {
this->currentValue = value;
this->update();
}
}
void Battery::setValue(int value)
@@ -312,17 +323,20 @@ void Battery::setAlarmValue(int alarmValue)
setAlarmValue((double)alarmValue);
}
void Battery::setStep(double step)
void Battery::setAnimation(bool animation)
{
if (this->step != step) {
this->step = step;
if (this->animation != animation) {
this->animation = animation;
this->update();
}
}
void Battery::setStep(int step)
void Battery::setAnimationStep(double animationStep)
{
setStep((double)step);
if (this->animationStep != animationStep) {
this->animationStep = animationStep;
this->update();
}
}
void Battery::setBorderWidth(int borderWidth)

View File

@@ -27,7 +27,9 @@ class Battery : public QWidget
Q_PROPERTY(double value READ getValue WRITE setValue)
Q_PROPERTY(double alarmValue READ getAlarmValue WRITE setAlarmValue)
Q_PROPERTY(double step READ getStep WRITE setStep)
Q_PROPERTY(bool animation READ getAnimation WRITE setAnimation)
Q_PROPERTY(double animationStep READ getAnimationStep WRITE setAnimationStep)
Q_PROPERTY(int borderWidth READ getBorderWidth WRITE setBorderWidth)
Q_PROPERTY(int borderRadius READ getBorderRadius WRITE setBorderRadius)
Q_PROPERTY(int bgRadius READ getBgRadius WRITE setBgRadius)
@@ -61,7 +63,9 @@ private:
double value; //目标电量
double alarmValue; //电池电量警戒值
double step; //每次移动的步长
bool animation; //是否启用动画显示
double animationStep; //动画显示时步长
int borderWidth; //边框粗细
int borderRadius; //边框圆角角度
int bgRadius; //背景进度圆角角度
@@ -87,7 +91,9 @@ public:
double getValue() const;
double getAlarmValue() const;
double getStep() const;
bool getAnimation() const;
double getAnimationStep() const;
int getBorderWidth() const;
int getBorderRadius() const;
int getBgRadius() const;
@@ -122,9 +128,10 @@ public Q_SLOTS:
void setAlarmValue(double alarmValue);
void setAlarmValue(int alarmValue);
//设置步长
void setStep(double step);
void setStep(int step);
//设置是否启用动画显示
void setAnimation(bool animation);
//设置动画显示的步长
void setAnimationStep(double animationStep);
//设置边框粗细
void setBorderWidth(int borderWidth);

View File

@@ -218,7 +218,7 @@ void DeviceSizeTable::checkSize(const QString &result, const QString &name)
QStringList list = result.split(" ");
int index = 0;
for (int i = 0; i < list.size(); ++i) {
for (int i = 0; i < list.count(); ++i) {
QString s = list.at(i).trimmed();
if (s.isEmpty()) {
continue;

View File

@@ -136,7 +136,7 @@ IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject
if (!fontDb.families().contains(fontName) && QFile(fontFile).exists()) {
int fontId = fontDb.addApplicationFont(fontFile);
QStringList listName = fontDb.applicationFontFamilies(fontId);
if (listName.size() == 0) {
if (listName.count() == 0) {
qDebug() << QString("load %1 error").arg(fontName);
}
}
@@ -265,8 +265,8 @@ void IconHelper::setStyle1(QWidget *widget, QList<QToolButton *> btns, QList<int
void IconHelper::setStyle1(QWidget *widget, QList<QAbstractButton *> btns, QList<int> icons, const IconHelper::StyleColor &styleColor)
{
int btnCount = btns.size();
int iconCount = icons.size();
int btnCount = btns.count();
int iconCount = icons.count();
if (btnCount <= 0 || iconCount <= 0 || btnCount != iconCount) {
return;
}
@@ -329,7 +329,7 @@ void IconHelper::setStyle1(QWidget *widget, QList<QAbstractButton *> btns, QList
//可能会重复调用设置所以先要移除上一次的
for (int i = 0; i < btnCount; ++i) {
for (int j = 0; j < this->btns.size(); j++) {
for (int j = 0; j < this->btns.count(); j++) {
if (this->btns.at(j) == btns.at(i)) {
disconnect(btns.at(i), SIGNAL(toggled(bool)), this, SLOT(toggled(bool)));
this->btns.at(j)->removeEventFilter(this);

View File

@@ -114,7 +114,7 @@ SaveLog::SaveLog(QObject *parent) : QObject(parent)
//默认取应用程序可执行文件名称
QString str = qApp->applicationFilePath();
QStringList list = str.split("/");
name = list.at(list.size() - 1).split(".").at(0);
name = list.at(list.count() - 1).split(".").at(0);
fileName = "";
//默认所有类型都输出

View File

@@ -28,7 +28,7 @@ SaveRunTime::SaveRunTime(QObject *parent) : QObject(parent)
path = qApp->applicationDirPath();
QString str = qApp->applicationFilePath();
QStringList list = str.split("/");
name = list.at(list.size() - 1).split(".").at(0);
name = list.at(list.count() - 1).split(".").at(0);
saveInterval = 1 * 60 * 1000;
startTime = QDateTime::currentDateTime();
@@ -187,7 +187,7 @@ void SaveRunTime::saveLog()
//重新清空文件
file.resize(0);
//如果行数小于2则返回
if (content.size() < 2) {
if (content.count() < 2) {
file.close();
return;
}
@@ -206,7 +206,7 @@ void SaveRunTime::saveLog()
lastLine = list.join("\t");
//重新替换最后一行并写入新的数据
content[content.size() - 1] = lastLine;
content[content.count() - 1] = lastLine;
QTextStream stream(&file);
stream << content.join("") << "\n";

View File

@@ -4,7 +4,7 @@
QPainterPath SmoothCurve::createSmoothCurve(const QVector<QPointF> &points)
{
QPainterPath path;
int len = points.size();
int len = points.count();
if (len < 2) {
return path;
}
@@ -24,13 +24,13 @@ QPainterPath SmoothCurve::createSmoothCurve(const QVector<QPointF> &points)
QPainterPath SmoothCurve::createSmoothCurve2(const QVector<QPointF> &points)
{
//采用Qt原生方法不做任何处理
int size = points.size();
if (size == 0) {
int count = points.count();
if (count == 0) {
return QPainterPath();
}
QPainterPath path(points.at(0));
for (int i = 0; i < size - 1; ++i) {
for (int i = 0; i < count - 1; ++i) {
//控制点的 x 坐标为 sp 与 ep 的 x 坐标和的一半
//第一个控制点 c1 的 y 坐标为起始点 sp 的 y 坐标
//第二个控制点 c2 的 y 坐标为结束点 ep 的 y 坐标
@@ -68,7 +68,7 @@ void SmoothCurve::calculateControlPoints(const QVector<QPointF> &datas,
QVector<QPointF> *firstControlPoints,
QVector<QPointF> *secondControlPoints)
{
int n = datas.size() - 1;
int n = datas.count() - 1;
for (int i = 0; i < n; ++i) {
firstControlPoints->append(QPointF());
secondControlPoints->append(QPointF());

View File

@@ -250,7 +250,7 @@ void ZhToPY::loadPY(const QString &fileName)
QString ZhToPY::zhToPY(const QString &chinese)
{
if (listPY.size() == 0) {
if (listPY.count() == 0) {
return "";
}