-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
73 lines (58 loc) · 2.16 KB
/
Copy pathmainwindow.cpp
File metadata and controls
73 lines (58 loc) · 2.16 KB
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
#include "mainwindow.h"
#include "./ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QWidget* simulation = new QWidget();
simulation->setCursor(Qt::CrossCursor);
this->draw_area = new DrawArea(800, 500, simulation);
ui->verticalLayout->addWidget(simulation);
auto timer = new QTimer();
QObject::connect(timer, &QTimer::timeout, draw_area, &DrawArea::animate);
timer->start(1);
QObject::connect(ui->start_button, &QPushButton::clicked, this, &MainWindow::SwitchGravity);
ui->plan_colliders->setCheckable(true);
QObject::connect(ui->plan_colliders, &QPushButton::clicked, this, &MainWindow::AddingPlanColliders);
ui->sphere_colliders->setCheckable(true);
QObject::connect(ui->sphere_colliders, &QPushButton::clicked, this, &MainWindow::AddingSphereColliders);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::SwitchGravity()
{
if (this->draw_area->context.isGravityOn) {
this->draw_area->context.isGravityOn = false;
ui->start_button->setText("Activate Gravity");
} else {
this->draw_area->context.isGravityOn = true;
ui->start_button->setText("Deactivate Gravity");
}
}
void MainWindow::AddingPlanColliders()
{
if (this->draw_area->context.addPlanCollidersOn) {
this->draw_area->context.addPlanCollidersOn = false;
ui->plan_colliders->setChecked(false);
ui->plan_colliders->setText("Add Plan Colliders");
} else {
this->draw_area->context.addPlanCollidersOn = true;
ui->plan_colliders->setChecked(true);
ui->plan_colliders->setText("Stop Adding Plan Colliders");
}
}
void MainWindow::AddingSphereColliders()
{
if (this->draw_area->context.addSphereColliderOn) {
this->draw_area->context.addSphereColliderOn = false;
ui->sphere_colliders->setChecked(false);
ui->sphere_colliders->setText("Add Sphere Colliders");
} else {
this->draw_area->context.addSphereColliderOn = true;
ui->sphere_colliders->setChecked(true);
ui->sphere_colliders->setText("Stop Adding Sphere Colliders");
}
}