refactor: Scan process.
This commit is contained in:
182
src/components/CoordinateXYWidget.cpp
Normal file
182
src/components/CoordinateXYWidget.cpp
Normal file
@@ -0,0 +1,182 @@
|
||||
#include "CoordinateXYWidget.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QTimer>
|
||||
#include <QRect>
|
||||
|
||||
#include "utilities/ScanProcessSequence.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
const int BLINK_FREQUENCY = 18;
|
||||
}
|
||||
|
||||
CoordinateXYWidget::CoordinateXYWidget(QWidget* aParent)
|
||||
: QWidget (aParent)
|
||||
, mAngle(0)
|
||||
, mTimer(new QTimer(this))
|
||||
, mBlinking(false)
|
||||
, mBlinkFrequency(0)
|
||||
, mBlinkPoint(QPointF())
|
||||
, mStopGradientEnd(0.05)
|
||||
{
|
||||
setFixedSize(655,655);
|
||||
connect(ScanProcessSequence::getInstance(), &ScanProcessSequence::startAutoLocate, this, &CoordinateXYWidget::startFlash);
|
||||
connect(ScanProcessSequence::getInstance(), &ScanProcessSequence::stopAutoLocate, this, &CoordinateXYWidget::stopFlash);
|
||||
connect(ScanProcessSequence::getInstance(), &ScanProcessSequence::quitAutoLocate, this, &CoordinateXYWidget::quit);
|
||||
connect(ScanProcessSequence::getInstance(), &ScanProcessSequence::autoLocateXYUpdated, this, &CoordinateXYWidget::setBlinkPoint);
|
||||
hide();
|
||||
}
|
||||
|
||||
CoordinateXYWidget::~CoordinateXYWidget()
|
||||
{
|
||||
mTimer->stop();
|
||||
}
|
||||
|
||||
void CoordinateXYWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
QPainter p(this);
|
||||
|
||||
int w = this->width()-5 ;
|
||||
int h = this->height()-5 ;
|
||||
QPoint center = this->rect().center();
|
||||
QRect rect(center,QPoint(w,h));
|
||||
p.setRenderHint(QPainter::Antialiasing,true);
|
||||
|
||||
|
||||
QConicalGradient coniGrad(w/2,h/2,360-mAngle);
|
||||
coniGrad.setColorAt(0,QColor(0,0,0,255));
|
||||
coniGrad.setColorAt(0.05,QColor(0,170,255,255));
|
||||
coniGrad.setColorAt(mStopGradientEnd,QColor(0,0,0,255));
|
||||
coniGrad.setColorAt(1,QColor(0,0,0,255));
|
||||
coniGrad.setSpread(QGradient::ReflectSpread);
|
||||
p.setBrush(coniGrad);
|
||||
|
||||
QPen pen;
|
||||
pen.setWidth(2);
|
||||
pen.setColor(Qt::gray);
|
||||
pen.setStyle(Qt::SolidLine);
|
||||
p.setPen(pen);
|
||||
|
||||
p.drawEllipse(center,w/2,h/2);
|
||||
p.drawEllipse(center,w/2 - 100,h/2 - 100);
|
||||
pen.setColor(QColor(0, 224, 255, 255).lighter());
|
||||
p.setPen(pen);
|
||||
p.drawEllipse(center,w/2 - 200,h/2 - 200);
|
||||
QRect r = this->rect();
|
||||
int raidLength = 7;
|
||||
QPointF coordinate = mBlinkPoint + center;
|
||||
if (mBlinking)
|
||||
{
|
||||
QRadialGradient radialGradient(coordinate,raidLength, coordinate + 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(coordinate,raidLength, coordinate + 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(coordinate, raidLength, raidLength);
|
||||
|
||||
p.translate(r.center());
|
||||
pen.setColor(Qt::gray);
|
||||
p.setPen(pen);
|
||||
for(int i=1;i<=360;i++)
|
||||
{
|
||||
p.rotate(1);
|
||||
p.drawLine(0,w/2,0,w/2 -5);
|
||||
}
|
||||
|
||||
for(int i=1;i<=72;i++)
|
||||
{
|
||||
p.rotate(5);
|
||||
p.drawLine(0,w/2,0,w/2-8);
|
||||
}
|
||||
for(int i=1;i<=36;i++)
|
||||
{
|
||||
p.rotate(10);
|
||||
p.drawLine(0,w/2,0,w/2-12);
|
||||
}
|
||||
for(int i=1;i<=4;i++)
|
||||
{
|
||||
p.rotate(90);
|
||||
p.drawLine(0,w/2,0,w/2-60);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CoordinateXYWidget::setBlinkPoint(int aX, int aY)
|
||||
{
|
||||
mBlinkPoint.setX(aX);
|
||||
mBlinkPoint.setY(aY);
|
||||
}
|
||||
|
||||
void CoordinateXYWidget::updateFlash()
|
||||
{
|
||||
if(mAngle > 360)
|
||||
{
|
||||
mAngle = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
mAngle += 5;
|
||||
}
|
||||
mBlinkFrequency++;
|
||||
if( mBlinkFrequency == BLINK_FREQUENCY)
|
||||
{
|
||||
mBlinking = !mBlinking;
|
||||
mBlinkFrequency = 0;
|
||||
}
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
void CoordinateXYWidget::updateStopFlash()
|
||||
{
|
||||
mBlinking = true;
|
||||
if(mStopGradientEnd <=0.1)
|
||||
{
|
||||
mTimer->stop();
|
||||
disconnect(mTimer,&QTimer::timeout,this, &CoordinateXYWidget::updateStopFlash);
|
||||
mStopGradientEnd = 0.05;
|
||||
this->update();
|
||||
ScanProcessSequence::getInstance()->startFullScan();
|
||||
return;
|
||||
}
|
||||
mStopGradientEnd-=0.02;
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
void CoordinateXYWidget::startFlash()
|
||||
{
|
||||
show();
|
||||
connect(mTimer,&QTimer::timeout,this, &CoordinateXYWidget::updateFlash);
|
||||
mStopGradientEnd = 1;
|
||||
mTimer->start(20);
|
||||
}
|
||||
|
||||
void CoordinateXYWidget::stopFlash()
|
||||
{
|
||||
disconnect(mTimer,&QTimer::timeout,this, &CoordinateXYWidget::updateFlash);
|
||||
connect(mTimer,&QTimer::timeout,this, &CoordinateXYWidget::updateStopFlash);
|
||||
mTimer->stop();
|
||||
mTimer->start(20);
|
||||
}
|
||||
|
||||
void CoordinateXYWidget::quit()
|
||||
{
|
||||
disconnect(mTimer,&QTimer::timeout,this, &CoordinateXYWidget::updateFlash);
|
||||
mTimer->stop();
|
||||
hide();
|
||||
}
|
||||
|
||||
|
||||
37
src/components/CoordinateXYWidget.h
Normal file
37
src/components/CoordinateXYWidget.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef COORDINATEXYWIDGET_H
|
||||
#define COORDINATEXYWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QTimer;
|
||||
|
||||
class CoordinateXYWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CoordinateXYWidget(QWidget* aParent);
|
||||
~CoordinateXYWidget();
|
||||
void setBlinkPoint(int aX, int aY);
|
||||
void stopFlash();
|
||||
void startFlash();
|
||||
void quit();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* aEvent);
|
||||
|
||||
private:
|
||||
void updateFlash();
|
||||
void updateStopFlash();
|
||||
|
||||
private:
|
||||
int mAngle;
|
||||
QTimer* mTimer;
|
||||
bool mBlinking;
|
||||
int mBlinkFrequency;
|
||||
int mBlinkPointX;
|
||||
QPointF mBlinkPoint;
|
||||
|
||||
double mStopGradientEnd;
|
||||
};
|
||||
|
||||
#endif // COORDINATEXYWIDGET_H
|
||||
181
src/components/CoordinateZWidget.cpp
Normal file
181
src/components/CoordinateZWidget.cpp
Normal file
@@ -0,0 +1,181 @@
|
||||
#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);
|
||||
mTimer->stop();
|
||||
hide();
|
||||
}
|
||||
|
||||
39
src/components/CoordinateZWidget.h
Normal file
39
src/components/CoordinateZWidget.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef COORDINATEZWIDGET_H
|
||||
#define COORDINATEZWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QTimer;
|
||||
|
||||
class CoordinateZWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CoordinateZWidget(QWidget* aParent);
|
||||
void setBlinkPoint(int aZ);
|
||||
void stopFlash();
|
||||
void startFlash();
|
||||
|
||||
void quit();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* aEvent);
|
||||
|
||||
private:
|
||||
void updateFlash();
|
||||
void updateStopFlash();
|
||||
|
||||
private:
|
||||
QTimer* mTimer;
|
||||
int mRenderStartPoint;
|
||||
int mRenderEndPoint;
|
||||
bool mRenderDirectionUp;
|
||||
int mRenderDirectionNumber;
|
||||
bool mBlinking;
|
||||
int mBlinkFrequency;
|
||||
QPointF mBlinkPoint;
|
||||
double mStopGradientEnd;
|
||||
|
||||
};
|
||||
|
||||
#endif // COORDINATEZWIDGET_H
|
||||
Reference in New Issue
Block a user