feat: Update water process speed.

This commit is contained in:
sunwen
2025-04-24 17:03:29 +08:00
parent 014fb8383b
commit 27fff41eb3
3 changed files with 11 additions and 17 deletions

View File

@@ -4,6 +4,12 @@
#include <QTimer>
#include <qmath.h>
namespace
{
const double UP_WAVE_SPEED = 0.03125;
const double DOWN_WAVE_SPEED = 0.03571;
}
WaveWidget::WaveWidget(QWidget* parent)
: QWidget(parent)
, mTimer(new QTimer(this))
@@ -38,7 +44,6 @@ void WaveWidget::paintEvent(QPaintEvent* aEvent)
mScale = (qreal)(qAbs(mValue - mMinValue)) / (qAbs(mMaxValue - mMinValue));
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing,true);
//p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
painter.translate(width() / 2, height() / 4);
drawBackground(&painter);
drawWater(&painter);
@@ -54,8 +59,6 @@ void WaveWidget::drawBackground(QPainter* painter)
pen.setColor(Qt::gray);
pen.setStyle(Qt::SolidLine);
painter->setPen(pen);
//painter->setPen(Qt::NoPen);
//painter->setBrush(QColor(40, 40, 40));
painter->drawPie(mRect, 180*16, 180 * 16);
painter->restore();
}
@@ -66,16 +69,8 @@ void WaveWidget::drawText(QPainter* aPainter)
{
aPainter->save();
mText = QString("%1%").arg(mScale * 100,2,'f', 1);
//设置字体大小
//QFont font = painter->font();
//font.setPixelSize(30);
//painter->setFont(font);
//设置画笔
aPainter->setPen(QPen(Qt::white, 4));
//绘制文本
// QRect r(-d->minRadius, -d->minRadius, d->minRadius * 2, d->minRadius * 2);
aPainter->drawText(mRect, Qt::AlignCenter, mText);
aPainter->restore();
}
}
@@ -89,13 +84,11 @@ void WaveWidget::drawWater(QPainter* aPainter)
else if (mValue >= 50)
{
aPainter->save();
//painter->setPen(Qt::NoPen);
QLinearGradient lineGrad(QPointF(0, 0), QPointF(0, mMinRadius * 2));
lineGrad.setColorAt(0,QColor(0,170,255,255));
lineGrad.setColorAt(1,QColor(0,0,0,255));
lineGrad.setSpread(QGradient::PadSpread);
aPainter->setBrush(lineGrad);
//painter->setBrush(QBrush(QColor(0,170,255, 230)));
aPainter->drawPie(mRect , 180*16, 180 * 16);
aPainter->restore();
}
@@ -212,6 +205,7 @@ void WaveWidget::startCharge(int aValue, WaveDirection aDirection)
{
mValue = aValue;
mWaveDirection = aDirection;
mSpeed = mWaveDirection == UpWaveDirection ? UP_WAVE_SPEED : DOWN_WAVE_SPEED;
connect(mTimer, &QTimer::timeout, this, &WaveWidget::updaterWater);
mTimer->start(30);
show();
@@ -226,7 +220,7 @@ void WaveWidget::stopCharge()
void WaveWidget::updaterWater()
{
mYOffset += 0.3;//波浪偏移
mYOffset += 0.3;
if(mWaveDirection == UpWaveDirection && mValue >48)
{
update();
@@ -237,7 +231,6 @@ void WaveWidget::updaterWater()
update();
return;
}
mValue += mWaveDirection * 0.05;
mValue += mWaveDirection * mSpeed;
update();
}

View File

@@ -58,6 +58,7 @@ private:
QString mText;
bool mTextVisible;
QRect mRect;
double mSpeed;
};
#endif // WAVEWIDGET_H

View File

@@ -159,7 +159,7 @@ void DeviceManager::initDevice()
{
this->processWaterCleanResult("{\"code\":-1}");
});
mWaterProcessExitAction = new DmsAsyncAction(USRV_CONTROL, ACT_CTL_WEXIT, this, "responseWaterProcessExit", this);
mWaterProcessExitAction = new DmsAsyncAction(USRV_CONTROL, ACT_CTL_WEXIT, this, "responseWaterProcessExit(const QString&)", this);
mWaterProcessExitAction->setTimeoutInterval(WATERPROCESS_TIMEOUT);
connect(mWaterProcessExitAction, &DmsAsyncAction::timeout, [this]()
{