#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPainter>
#include <QTimer>
#include <qmath.h>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private:
Ui::Widget *ui;
void paintEvent(QPaintEvent *event);
QTimer* mytimer;
QPoint create_p(int);
QList<QPoint> pl;
int fl_start;
bool fl_stop;
public slots:
void press_pbtn_01();
void press_pbtn_02();
void event_mytimer();
};
#endif // WIDGET_H
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
mytimer = new QTimer();
fl_start = false;
fl_stop = false;
QObject::connect(ui->pbtn_01, SIGNAL(clicked()), this, SLOT(press_pbtn_01()));
QObject::connect(ui->pbtn_02, SIGNAL(clicked()), this, SLOT(press_pbtn_02()));
QObject::connect(mytimer, SIGNAL(timeout()), this, SLOT(event_mytimer()));
}
Widget::~Widget()
{
delete ui;
}
void Widget::press_pbtn_01()
{
QPoint p;
p.setX(width()/2);
p.setY(height()/2+20);
for(int i = 0; i < 10; i++) pl << p;
fl_start = 1;
fl_stop = false;
mytimer->start(20);
}
void Widget::press_pbtn_02()
{
fl_stop = true;
}
QPoint Widget::create_p(int i)
{
QPoint p;
float a1 = width()/2;
float b1 = height()/2+20;
float rad = i * 3.14159/180;
p.setX(a1 + 165*cos(rad));
p.setY(b1 + 165*sin(rad));
return p;
}
void Widget::event_mytimer()
{
static int i = 270;
for(int j = 0; j < fl_start; j++)
{
pl[j] = create_p(i+9-j);
}
if(fl_stop)
{
pl.removeLast();
if(pl.size() == 1)
mytimer->stop();
}
i++;
if(i > 359) i == 0;
if(fl_start < 9) fl_start++;
this->repaint();
}
void Widget::paintEvent(QPaintEvent *event)
{
QPainter Pn(this);
QPoint p1, p2;
Pn.setRenderHint(QPainter::Antialiasing);
QPen penG(Qt::gray);
penG.setWidth(2);
Pn.setPen(penG);
p1.setX(30);
p1.setY(height()/2+20);
p2.setX(width()-30);
p2.setY(height()/2+20);
Pn.drawLine(p1, p2);
p1.setX(width()/2);
p1.setY(47);
p2.setX(width()/2);
p2.setY(height()-10);
Pn.drawLine(p1,p2);
p1.setX(width()/2);
p1.setY(height()/2+20);
Pn.drawEllipse(p1, width()/8, width()/8);
Pn.drawEllipse(p1, width()/4, width()/3.8);
Pn.drawEllipse(p1, width()/2.6, width()/2.6);
QColor clr;
QPen penGr(clr);
penGr.setWidth(2);
for(int i = 0; i < pl.size(); i++)
{
clr.setRgb(0, 255, 255, 150-i*15);
penGr.setColor(clr);
Pn.setPen(penGr);
Pn.drawLine(p1, pl.at(i));
}
}