104 lines
2.6 KiB
C++
104 lines
2.6 KiB
C++
#include "ZFlashWidget.h"
|
|
|
|
#include <QTimer>
|
|
#include <QPainter>
|
|
|
|
#include "utilities/ScanProcessSequence.h"
|
|
|
|
namespace
|
|
{
|
|
const int ANIME_RECT_HEIGHT = 350;
|
|
const int ANIME_SPEED = 10;
|
|
const int RENFER_START_POINT = 640;
|
|
const int TOP_POINT_Y = 0;
|
|
const int BOTTOM_POINT_Y = 395;
|
|
}
|
|
|
|
ZFlashWidget::ZFlashWidget(QWidget* aParent)
|
|
: QWidget(aParent)
|
|
, mTimer(new QTimer(this))
|
|
, mRenderStartPoint(RENFER_START_POINT)
|
|
, mRenderEndPoint(mRenderStartPoint+ANIME_RECT_HEIGHT)
|
|
, mRenderDirectionUp(true)
|
|
, mRenderDirectionNumber(1)
|
|
, mStopGradientEnd(1)
|
|
, mMinRadius(0)
|
|
{
|
|
//setFixedSize(WIDGET_WIDTH,WIDGET_HEIGHT);
|
|
hide();
|
|
}
|
|
|
|
void ZFlashWidget::resizeEvent(QResizeEvent* aEvent)
|
|
{
|
|
mMinRadius = qMin(width(), height()) / 2;
|
|
QWidget::resizeEvent(aEvent);
|
|
}
|
|
|
|
void ZFlashWidget::paintEvent(QPaintEvent* aEvent)
|
|
{
|
|
Q_UNUSED(aEvent);
|
|
QPainter p(this);
|
|
|
|
p.translate(width() / 2, height() / 4);
|
|
QRect rect(-mMinRadius, -mMinRadius, mMinRadius * 2 - 60, mMinRadius * 2);
|
|
p.setRenderHint(QPainter::Antialiasing,true);
|
|
QLinearGradient lineGrad(QPointF(0, mRenderStartPoint), QPointF(0, mRenderEndPoint));
|
|
lineGrad.setColorAt(0,QColor(0,0,0,255));
|
|
lineGrad.setColorAt(0.1,QColor(0,170,255,255));
|
|
lineGrad.setColorAt(mStopGradientEnd,QColor(0,0,0,255));
|
|
lineGrad.setColorAt(1,QColor(0,0,0,255));
|
|
lineGrad.setSpread(QGradient::PadSpread);
|
|
p.setBrush(lineGrad);
|
|
|
|
QPen pen;
|
|
pen.setWidth(3);
|
|
pen.setColor(Qt::gray);
|
|
pen.setStyle(Qt::SolidLine);
|
|
p.setPen(pen);
|
|
p.drawPie(rect, 180*16, 180*16);
|
|
}
|
|
|
|
void ZFlashWidget::startFlash()
|
|
{
|
|
show();
|
|
connect(mTimer,&QTimer::timeout,this, &ZFlashWidget::updateFlash);
|
|
mTimer->start(20);
|
|
}
|
|
|
|
void ZFlashWidget::stopFlash()
|
|
{
|
|
mTimer->stop();
|
|
disconnect(mTimer,&QTimer::timeout,this, &ZFlashWidget::updateFlash);
|
|
hide();
|
|
}
|
|
|
|
void ZFlashWidget::updateFlash()
|
|
{
|
|
if(mRenderEndPoint <= TOP_POINT_Y && mRenderDirectionUp)
|
|
{
|
|
mRenderDirectionUp = false;
|
|
mRenderDirectionNumber *= -1;
|
|
mRenderStartPoint = mRenderDirectionNumber * ANIME_SPEED + TOP_POINT_Y;
|
|
}
|
|
|
|
if(mRenderEndPoint >= BOTTOM_POINT_Y && !mRenderDirectionUp)
|
|
{
|
|
mRenderDirectionUp = true;
|
|
mRenderDirectionNumber *= -1;
|
|
mRenderStartPoint = BOTTOM_POINT_Y - ANIME_SPEED;
|
|
}
|
|
|
|
mRenderStartPoint -= mRenderDirectionNumber*ANIME_SPEED;
|
|
mRenderEndPoint = mRenderStartPoint + mRenderDirectionNumber*ANIME_RECT_HEIGHT;
|
|
this->update();
|
|
}
|
|
|
|
|
|
void ZFlashWidget::quit()
|
|
{
|
|
disconnect(mTimer,&QTimer::timeout,this, &ZFlashWidget::updateFlash);
|
|
mTimer->stop();
|
|
hide();
|
|
}
|
|
|