183 lines
5.4 KiB
C++
183 lines
5.4 KiB
C++
#include "CoordinateZWidget.h"
|
|
|
|
#include <QTimer>
|
|
#include <QPainter>
|
|
|
|
#include "utilities/ScanProcessSequence.h"
|
|
|
|
namespace
|
|
{
|
|
const int ANIME_RECT_HEIGHT = 350;
|
|
const int ANIME_SPEED = 10;
|
|
const int BLINK_FREQUENCY = 18;
|
|
const int WIDGET_WIDTH = 630;
|
|
const int WIDGET_HEIGHT = 690;
|
|
const int TOP_POINT_Y = 170;
|
|
const int BOTTOM_POINT_Y = 515;
|
|
}
|
|
|
|
CoordinateZWidget::CoordinateZWidget(QWidget* aParent)
|
|
: QWidget(aParent)
|
|
, mTimer(new QTimer(this))
|
|
, mRenderStartPoint(WIDGET_HEIGHT - 50)
|
|
, mRenderEndPoint(mRenderStartPoint+ANIME_RECT_HEIGHT)
|
|
, mRenderDirectionUp(true)
|
|
, mRenderDirectionNumber(1)
|
|
, mBlinking(false)
|
|
, mBlinkFrequency(0)
|
|
, mBlinkPoint(QPointF())
|
|
, mStopGradientEnd(0.1)
|
|
{
|
|
setFixedSize(WIDGET_WIDTH,WIDGET_HEIGHT);
|
|
connect(ScanProcessSequence::getInstance(), &ScanProcessSequence::startAutoLocate, this, &CoordinateZWidget::startFlash);
|
|
connect(ScanProcessSequence::getInstance(), &ScanProcessSequence::stopAutoLocate, this, &CoordinateZWidget::stopFlash);
|
|
connect(ScanProcessSequence::getInstance(), &ScanProcessSequence::quitAutoLocate, this, &CoordinateZWidget::quit);
|
|
connect(ScanProcessSequence::getInstance(), &ScanProcessSequence::autoLocateZUpdated, this, &CoordinateZWidget::setBlinkPoint);
|
|
hide();
|
|
}
|
|
|
|
void CoordinateZWidget::paintEvent(QPaintEvent* aEvent)
|
|
{
|
|
Q_UNUSED(aEvent);
|
|
QPainter p(this);
|
|
int w = this->width() - 10;
|
|
int h = this->height();
|
|
|
|
QRect rect(5,-175,w,h);
|
|
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);
|
|
//p.fillRect(0,0,w,h, lineGrad);
|
|
|
|
QPen pen;
|
|
pen.setWidth(3);
|
|
pen.setColor(Qt::gray);
|
|
pen.setStyle(Qt::SolidLine);
|
|
p.setPen(pen);
|
|
p.drawPie(rect, 180*16, 180 * 16);
|
|
|
|
QPointF coor = QPointF(this->rect().center().x() + 20, TOP_POINT_Y + mBlinkPoint.y());
|
|
int raidLength = 7;
|
|
if (mBlinking)
|
|
{
|
|
QRadialGradient radialGradient(coor,raidLength, coor + QPointF(0,0));
|
|
radialGradient.setColorAt(0, QColor(0, 224, 255, 255));
|
|
radialGradient.setColorAt(0.2, QColor(0, 224, 255, 255));
|
|
radialGradient.setColorAt(1, QColor(0, 224, 255, 0));
|
|
p.setBrush(radialGradient);
|
|
}
|
|
else
|
|
{
|
|
QRadialGradient radialGradient(coor,raidLength, coor + QPointF(0,0));
|
|
radialGradient.setColorAt(0, QColor(0, 224, 255, 100));
|
|
radialGradient.setColorAt(0.3, QColor(0, 224, 255, 100));
|
|
radialGradient.setColorAt(1, QColor(0, 224, 255, 0));
|
|
p.setBrush(radialGradient);
|
|
}
|
|
p.setPen(Qt::NoPen);
|
|
p.drawEllipse(coor, raidLength, raidLength);
|
|
|
|
pen.setWidth(1);
|
|
p.setPen(pen);
|
|
p.drawLine(w/2,TOP_POINT_Y,w/2,BOTTOM_POINT_Y);
|
|
int samllLineWidth = 5;
|
|
for(int i=TOP_POINT_Y; i<BOTTOM_POINT_Y; i+=5)
|
|
{
|
|
if((i-TOP_POINT_Y)%25!=0)
|
|
p.drawLine(w/2,i,w/2+samllLineWidth,i);
|
|
}
|
|
|
|
samllLineWidth = 12;
|
|
for(int i=TOP_POINT_Y; i<BOTTOM_POINT_Y; i+=25)
|
|
{
|
|
p.drawLine(w/2,i,w/2+samllLineWidth,i);
|
|
}
|
|
|
|
pen.setWidth(2);
|
|
pen.setColor(QColor(0, 224, 255, 255).lighter());
|
|
pen.setStyle(Qt::SolidLine);
|
|
p.setPen(pen);
|
|
|
|
samllLineWidth = 25;
|
|
p.drawLine(w/2,TOP_POINT_Y + 25*6,w/2+samllLineWidth,TOP_POINT_Y + 25*6);
|
|
p.drawLine(w/2,TOP_POINT_Y + 25*9,w/2+samllLineWidth,TOP_POINT_Y + 25*9);
|
|
}
|
|
|
|
void CoordinateZWidget::setBlinkPoint(int aZ)
|
|
{
|
|
mBlinkPoint.setY(aZ);
|
|
}
|
|
|
|
void CoordinateZWidget::startFlash()
|
|
{
|
|
// show();
|
|
// connect(mTimer,&QTimer::timeout,this, &CoordinateZWidget::updateFlash);
|
|
// mStopGradientEnd = 1;
|
|
// mTimer->start(20);
|
|
}
|
|
|
|
void CoordinateZWidget::stopFlash()
|
|
{
|
|
// disconnect(mTimer,&QTimer::timeout,this, &CoordinateZWidget::updateFlash);
|
|
// connect(mTimer,&QTimer::timeout,this, &CoordinateZWidget::updateStopFlash);
|
|
// mTimer->stop();
|
|
// mTimer->start(20);
|
|
}
|
|
|
|
void CoordinateZWidget::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;
|
|
mBlinkFrequency++;
|
|
if( mBlinkFrequency == BLINK_FREQUENCY)
|
|
{
|
|
mBlinking = !mBlinking;
|
|
mBlinkFrequency = 0;
|
|
}
|
|
|
|
this->update();
|
|
}
|
|
void CoordinateZWidget::updateStopFlash()
|
|
{
|
|
mBlinking = true;
|
|
if(mStopGradientEnd <=0.2)
|
|
{
|
|
mTimer->stop();
|
|
disconnect(mTimer,&QTimer::timeout,this, &CoordinateZWidget::updateStopFlash);
|
|
mStopGradientEnd = 0.1;
|
|
this->update();
|
|
return;
|
|
}
|
|
mStopGradientEnd-=0.02;
|
|
|
|
this->update();
|
|
}
|
|
|
|
void CoordinateZWidget::quit()
|
|
{
|
|
disconnect(mTimer,&QTimer::timeout,this, &CoordinateZWidget::updateFlash);
|
|
disconnect(mTimer,&QTimer::timeout,this, &CoordinateZWidget::updateStopFlash);
|
|
mTimer->stop();
|
|
hide();
|
|
}
|
|
|