-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.cpp~
77 lines (57 loc) · 1.92 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
#include "MainWindow.h"
#include "NewSimulationDialog.h"
#include <QtCore/QSettings>
using namespace Pirogronian;
using namespace Qt;
MainWindow::MainWindow() {
QSettings conf;
resize(conf.value("MainWindow.size", QSize(300, 200)).toSize());
move(conf.value("MainWindow.pos", QPoint(300, 200)).toPoint());
timer = new QTimer(this);
timer->setInterval(50);
timer->setSingleShot(false);
connect(timer, SIGNAL(timeout()), this, SLOT(stepSimulation()));
createActions();
createMenus();
pres = new Presenter;
setCentralWidget(pres);
}
MainWindow::~MainWindow() {
QSettings conf;
conf.setValue("MainWindow.size", size());
conf.setValue("MainWindow.pos", pos());
}
void MainWindow::createActions() {
newSimulationAction = new QAction(QIcon::fromTheme("New Document"), tr("Nowa symulacja"), this);
connect(newSimulationAction, SIGNAL(triggered()), this, SLOT(newSimulation()));
startSimulationAction = new QAction(tr("Zacznij symulację"), this);
connect(startSimulationAction, SIGNAL(triggered()), this, SLOT(startSimulation()));
stopSimulationAction = new QAction(tr("Zatrzymaj symulację"), this);
connect(stopSimulationAction, SIGNAL(triggered()), this, SLOT(stopSimulation()));
}
void MainWindow::createMenus() {
QMenu *menu = menuBar()->addMenu(tr("Symulacja"));
menu->addAction(newSimulationAction);
menu->addAction(startSimulationAction);
menu->addAction(stopSimulationAction);
}
void MainWindow::newSimulation() {
NewSimulationDialog dial(this);
dial.show();
if (dial.exec() == QDialog::Accepted) {
sim = new ElasticBodySimulator(dial.x(), dial.y(), dial.z(), dial.granMass(), dial.linkMass(), dial.couple(), dial.space(), dial.initspace(), dial.time());
pres->setSimulator(sim);
pres->init();
pres->update();
}
}
void MainWindow::startSimulation() {
timer->start();
}
void MainWindow::stopSimulation() {
timer->stop();
}
void MainWindow::stepSimulation() {
sim->doStep();
pres->update();
}