feat: Update water process speed.
This commit is contained in:
@@ -4,6 +4,12 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const double UP_WAVE_SPEED = 0.03125;
|
||||||
|
const double DOWN_WAVE_SPEED = 0.03571;
|
||||||
|
}
|
||||||
|
|
||||||
WaveWidget::WaveWidget(QWidget* parent)
|
WaveWidget::WaveWidget(QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, mTimer(new QTimer(this))
|
, mTimer(new QTimer(this))
|
||||||
@@ -38,7 +44,6 @@ void WaveWidget::paintEvent(QPaintEvent* aEvent)
|
|||||||
mScale = (qreal)(qAbs(mValue - mMinValue)) / (qAbs(mMaxValue - mMinValue));
|
mScale = (qreal)(qAbs(mValue - mMinValue)) / (qAbs(mMaxValue - mMinValue));
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHint(QPainter::Antialiasing,true);
|
painter.setRenderHint(QPainter::Antialiasing,true);
|
||||||
//p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
|
|
||||||
painter.translate(width() / 2, height() / 4);
|
painter.translate(width() / 2, height() / 4);
|
||||||
drawBackground(&painter);
|
drawBackground(&painter);
|
||||||
drawWater(&painter);
|
drawWater(&painter);
|
||||||
@@ -54,8 +59,6 @@ void WaveWidget::drawBackground(QPainter* painter)
|
|||||||
pen.setColor(Qt::gray);
|
pen.setColor(Qt::gray);
|
||||||
pen.setStyle(Qt::SolidLine);
|
pen.setStyle(Qt::SolidLine);
|
||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
//painter->setPen(Qt::NoPen);
|
|
||||||
//painter->setBrush(QColor(40, 40, 40));
|
|
||||||
painter->drawPie(mRect, 180*16, 180 * 16);
|
painter->drawPie(mRect, 180*16, 180 * 16);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
@@ -66,16 +69,8 @@ void WaveWidget::drawText(QPainter* aPainter)
|
|||||||
{
|
{
|
||||||
aPainter->save();
|
aPainter->save();
|
||||||
mText = QString("%1%").arg(mScale * 100,2,'f', 1);
|
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));
|
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->drawText(mRect, Qt::AlignCenter, mText);
|
||||||
|
|
||||||
aPainter->restore();
|
aPainter->restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,13 +84,11 @@ void WaveWidget::drawWater(QPainter* aPainter)
|
|||||||
else if (mValue >= 50)
|
else if (mValue >= 50)
|
||||||
{
|
{
|
||||||
aPainter->save();
|
aPainter->save();
|
||||||
//painter->setPen(Qt::NoPen);
|
|
||||||
QLinearGradient lineGrad(QPointF(0, 0), QPointF(0, mMinRadius * 2));
|
QLinearGradient lineGrad(QPointF(0, 0), QPointF(0, mMinRadius * 2));
|
||||||
lineGrad.setColorAt(0,QColor(0,170,255,255));
|
lineGrad.setColorAt(0,QColor(0,170,255,255));
|
||||||
lineGrad.setColorAt(1,QColor(0,0,0,255));
|
lineGrad.setColorAt(1,QColor(0,0,0,255));
|
||||||
lineGrad.setSpread(QGradient::PadSpread);
|
lineGrad.setSpread(QGradient::PadSpread);
|
||||||
aPainter->setBrush(lineGrad);
|
aPainter->setBrush(lineGrad);
|
||||||
//painter->setBrush(QBrush(QColor(0,170,255, 230)));
|
|
||||||
aPainter->drawPie(mRect , 180*16, 180 * 16);
|
aPainter->drawPie(mRect , 180*16, 180 * 16);
|
||||||
aPainter->restore();
|
aPainter->restore();
|
||||||
}
|
}
|
||||||
@@ -212,6 +205,7 @@ void WaveWidget::startCharge(int aValue, WaveDirection aDirection)
|
|||||||
{
|
{
|
||||||
mValue = aValue;
|
mValue = aValue;
|
||||||
mWaveDirection = aDirection;
|
mWaveDirection = aDirection;
|
||||||
|
mSpeed = mWaveDirection == UpWaveDirection ? UP_WAVE_SPEED : DOWN_WAVE_SPEED;
|
||||||
connect(mTimer, &QTimer::timeout, this, &WaveWidget::updaterWater);
|
connect(mTimer, &QTimer::timeout, this, &WaveWidget::updaterWater);
|
||||||
mTimer->start(30);
|
mTimer->start(30);
|
||||||
show();
|
show();
|
||||||
@@ -226,7 +220,7 @@ void WaveWidget::stopCharge()
|
|||||||
|
|
||||||
void WaveWidget::updaterWater()
|
void WaveWidget::updaterWater()
|
||||||
{
|
{
|
||||||
mYOffset += 0.3;//波浪偏移
|
mYOffset += 0.3;
|
||||||
if(mWaveDirection == UpWaveDirection && mValue >48)
|
if(mWaveDirection == UpWaveDirection && mValue >48)
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
@@ -237,7 +231,6 @@ void WaveWidget::updaterWater()
|
|||||||
update();
|
update();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
mValue += mWaveDirection * mSpeed;
|
||||||
mValue += mWaveDirection * 0.05;
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ private:
|
|||||||
QString mText;
|
QString mText;
|
||||||
bool mTextVisible;
|
bool mTextVisible;
|
||||||
QRect mRect;
|
QRect mRect;
|
||||||
|
double mSpeed;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WAVEWIDGET_H
|
#endif // WAVEWIDGET_H
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ void DeviceManager::initDevice()
|
|||||||
{
|
{
|
||||||
this->processWaterCleanResult("{\"code\":-1}");
|
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);
|
mWaterProcessExitAction->setTimeoutInterval(WATERPROCESS_TIMEOUT);
|
||||||
connect(mWaterProcessExitAction, &DmsAsyncAction::timeout, [this]()
|
connect(mWaterProcessExitAction, &DmsAsyncAction::timeout, [this]()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user