2024-05-24 13:49:54 +08:00
|
|
|
#include "CoordinateXYWidget.h"
|
|
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QRect>
|
|
|
|
|
|
|
|
|
|
#include "utilities/ScanProcessSequence.h"
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
const int BLINK_FREQUENCY = 18;
|
2024-06-18 10:19:32 +08:00
|
|
|
const int XYWIDGET_WIDTH = 655;
|
|
|
|
|
const int XYWIDGET_HEIGHT = 655;
|
2024-05-24 13:49:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CoordinateXYWidget::CoordinateXYWidget(QWidget* aParent)
|
|
|
|
|
: QWidget (aParent)
|
|
|
|
|
, mAngle(0)
|
|
|
|
|
, mTimer(new QTimer(this))
|
|
|
|
|
, mBlinking(false)
|
|
|
|
|
, mBlinkFrequency(0)
|
|
|
|
|
, mBlinkPoint(QPointF())
|
2024-06-18 10:19:32 +08:00
|
|
|
, mBuffer()
|
2024-05-24 13:49:54 +08:00
|
|
|
, mStopGradientEnd(0.05)
|
|
|
|
|
{
|
2024-06-18 10:19:32 +08:00
|
|
|
setFixedSize(XYWIDGET_WIDTH, XYWIDGET_HEIGHT);
|
2024-05-24 13:49:54 +08:00
|
|
|
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);
|
2024-06-18 10:19:32 +08:00
|
|
|
initBuffer();
|
2024-05-24 13:49:54 +08:00
|
|
|
hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CoordinateXYWidget::~CoordinateXYWidget()
|
|
|
|
|
{
|
|
|
|
|
mTimer->stop();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-18 10:19:32 +08:00
|
|
|
void CoordinateXYWidget::initBuffer()
|
|
|
|
|
{
|
|
|
|
|
QPen pen;
|
|
|
|
|
pen.setWidth(2);
|
|
|
|
|
pen.setColor(Qt::gray);
|
|
|
|
|
pen.setStyle(Qt::SolidLine);
|
|
|
|
|
for(int angle=5; angle<=365; angle+=5)
|
|
|
|
|
{
|
|
|
|
|
mBuffer[angle] = QPixmap(XYWIDGET_WIDTH, XYWIDGET_HEIGHT);
|
|
|
|
|
mBuffer[angle].fill(Qt::transparent);
|
|
|
|
|
QPainter bufferPainter(&mBuffer[angle]);
|
|
|
|
|
bufferPainter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
bufferPainter.setPen(pen);
|
|
|
|
|
|
|
|
|
|
int w = XYWIDGET_WIDTH - 5;
|
|
|
|
|
int h = XYWIDGET_HEIGHT - 5;
|
|
|
|
|
QConicalGradient coniGrad(w/2,h/2,360-angle);
|
|
|
|
|
coniGrad.setColorAt(0,QColor(0,0,0,255));
|
|
|
|
|
coniGrad.setColorAt(0.05,QColor(0,170,255,255));
|
|
|
|
|
coniGrad.setColorAt(1,QColor(0,0,0,255));
|
|
|
|
|
coniGrad.setSpread(QGradient::ReflectSpread);
|
|
|
|
|
bufferPainter.setBrush(coniGrad);
|
|
|
|
|
bufferPainter.drawEllipse(this->rect().center(),w/2,h/2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-24 13:49:54 +08:00
|
|
|
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);
|
|
|
|
|
QPen pen;
|
|
|
|
|
pen.setWidth(2);
|
|
|
|
|
pen.setColor(Qt::gray);
|
|
|
|
|
pen.setStyle(Qt::SolidLine);
|
|
|
|
|
p.setPen(pen);
|
|
|
|
|
|
2024-06-18 10:19:32 +08:00
|
|
|
if(mStopGradientEnd < 1)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
p.drawEllipse(center,w/2,h/2);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
p.drawPixmap(0,0, mBuffer[mAngle]);
|
|
|
|
|
}
|
|
|
|
|
p.setBrush(Qt::NoBrush);
|
2024-05-24 13:49:54 +08:00
|
|
|
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();
|
2024-09-23 10:08:53 +08:00
|
|
|
// connect(mTimer,&QTimer::timeout,this, &CoordinateXYWidget::updateFlash);
|
|
|
|
|
// mStopGradientEnd = 1;
|
|
|
|
|
// mTimer->start(20);
|
2024-05-24 13:49:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2024-06-18 11:21:57 +08:00
|
|
|
disconnect(mTimer,&QTimer::timeout,this, &CoordinateXYWidget::updateStopFlash);
|
2024-05-24 13:49:54 +08:00
|
|
|
mTimer->stop();
|
|
|
|
|
hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|