/
dialog.cpp
65 lines (53 loc) · 1.37 KB
/
dialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog),
m_ball(Ball(Coordinate(250, 250, 500, 500), 20, 0, 10, 10)),
m_counter(0)
{
ui->setupUi(this);
this->resize(500, 500);
this->setStyleSheet("background-color: #82CAFF;");
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(nextFrame()));
timer->start(16);
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::paintEvent(QPaintEvent *event)
{
bool animation = true;
if (animation) {
QPainter painter(this);
m_ball.render(painter, m_counter);
m_counter++;
}
else {
QPainter painter(this);
QPen pen;
pen.setWidth(3);
pen.setColor(Qt::black);
QBrush brush(Qt::yellow);
painter.setPen (pen);
painter.setBrush(brush);
painter.drawEllipse(30, 30, 100, 100);
brush.setColor("#C36241");
painter.setBrush(brush);
pen.setWidth(1);
QPolygon roof;
roof.putPoints(0, 3, 250, 260, 290, 220, 330, 260);
painter.drawPolygon(roof);
brush.setColor("#835C3B");
painter.setBrush(brush);
QPolygon house;
house.putPoints(0, 4, 260, 260, 260, 299, 320, 299, 320, 260);
painter.drawPolygon(house);
}
}
void Dialog::nextFrame()
{
update();
}