-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
80 lines (65 loc) · 1.72 KB
/
mainwindow.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTimer>
#include <QTime>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTime time = QTime::currentTime();
qsrand((uint)time.msec());
m_renderer = new RenderThread(this);
m_wnd = new RenderArea(m_renderer, this);
setCentralWidget(m_wnd);
on_slider_Speed_valueChanged(ui->slider_Speed->value());
on_slider_Scale_valueChanged(ui->slider_Scale->value());
on_slider_Radius_valueChanged(ui->slider_Radius->value());
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::addObjects(int N)
{
for(int i=0; i<N; i++)
{
QRect rect = centralWidget()->rect();
m_renderer->addObject(new Circle(randInt(20,rect.width()-20),
randInt(20,rect.height()-20),
m_wnd->m_radius));
}
}
int MainWindow::randInt(int low, int high)
{
return qrand() % ((high + 1) - low) + low;
}
void MainWindow::on_actionClear_triggered()
{
m_renderer->removeAllObjects();
}
void MainWindow::on_actionAdd_10_triggered()
{
addObjects(10);
}
void MainWindow::on_actionAdd_100_triggered()
{
addObjects(100);
}
void MainWindow::on_slider_Speed_valueChanged(int value)
{
double v = value;
v /= 1000;
ui->label_speed->setText(QString::number(v, 'f', 3));
m_renderer->setSpeed(v);
}
void MainWindow::on_slider_Scale_valueChanged(int value)
{
ui->label_scale->setText(QString::number(value));
m_renderer->setScale(value);
}
void MainWindow::on_slider_Radius_valueChanged(int value)
{
ui->label_radius->setText(QString::number(value));
m_wnd->m_radius = value;
}