From 27fff41eb3fad927c2d9788a79d1a400a40007f7 Mon Sep 17 00:00:00 2001 From: sunwen Date: Thu, 24 Apr 2025 17:03:29 +0800 Subject: [PATCH] feat: Update water process speed. --- src/components/WaveWidget.cpp | 25 +++++++++---------------- src/components/WaveWidget.h | 1 + src/device/DeviceManager.cpp | 2 +- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/components/WaveWidget.cpp b/src/components/WaveWidget.cpp index 19bfdab..d0b30fa 100644 --- a/src/components/WaveWidget.cpp +++ b/src/components/WaveWidget.cpp @@ -4,6 +4,12 @@ #include #include +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(); } diff --git a/src/components/WaveWidget.h b/src/components/WaveWidget.h index c5b84bd..0646bf8 100644 --- a/src/components/WaveWidget.h +++ b/src/components/WaveWidget.h @@ -58,6 +58,7 @@ private: QString mText; bool mTextVisible; QRect mRect; + double mSpeed; }; #endif // WAVEWIDGET_H diff --git a/src/device/DeviceManager.cpp b/src/device/DeviceManager.cpp index 5f0fbfb..a816ab2 100644 --- a/src/device/DeviceManager.cpp +++ b/src/device/DeviceManager.cpp @@ -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]() {