feat: pause/resume button
This commit is contained in:
parent
5ee493dc97
commit
70f914bba0
2 changed files with 33 additions and 1 deletions
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
SelectedTool selectedTool;
|
SelectedTool selectedTool;
|
||||||
|
|
||||||
|
bool simulationPlaying = false;
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
|
@ -46,6 +48,19 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
connect(ui->actionToolScale, &QAction::triggered, this, [&](bool state) { selectedTool = state ? SelectedTool::SCALE : SelectedTool::SELECT; updateSelectedTool(); });
|
connect(ui->actionToolScale, &QAction::triggered, this, [&](bool state) { selectedTool = state ? SelectedTool::SCALE : SelectedTool::SELECT; updateSelectedTool(); });
|
||||||
connect(ui->actionToolRotate, &QAction::triggered, this, [&](bool state) { selectedTool = state ? SelectedTool::ROTATE : SelectedTool::SELECT; updateSelectedTool(); });
|
connect(ui->actionToolRotate, &QAction::triggered, this, [&](bool state) { selectedTool = state ? SelectedTool::ROTATE : SelectedTool::SELECT; updateSelectedTool(); });
|
||||||
ui->actionToolSelect->setChecked(true);
|
ui->actionToolSelect->setChecked(true);
|
||||||
|
|
||||||
|
connect(ui->actionToggleSimulation, &QAction::triggered, this, [&]() {
|
||||||
|
simulationPlaying = !simulationPlaying;
|
||||||
|
if (simulationPlaying) {
|
||||||
|
ui->actionToggleSimulation->setText("Pause simulation");
|
||||||
|
ui->actionToggleSimulation->setToolTip("Pause the simulation");
|
||||||
|
ui->actionToggleSimulation->setIcon(QIcon::fromTheme("media-playback-pause"));
|
||||||
|
} else {
|
||||||
|
ui->actionToggleSimulation->setText("Resume simulation");
|
||||||
|
ui->actionToggleSimulation->setToolTip("Resume the simulation");
|
||||||
|
ui->actionToggleSimulation->setIcon(QIcon::fromTheme("media-playback-start"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// ui->explorerView->Init(ui);
|
// ui->explorerView->Init(ui);
|
||||||
|
|
||||||
|
@ -89,7 +104,8 @@ void MainWindow::timerEvent(QTimerEvent* evt) {
|
||||||
float deltaTime = std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - lastTime).count();
|
float deltaTime = std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - lastTime).count();
|
||||||
lastTime = std::chrono::steady_clock::now();
|
lastTime = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
physicsStep(deltaTime);
|
if (simulationPlaying)
|
||||||
|
physicsStep(deltaTime);
|
||||||
ui->mainWidget->update();
|
ui->mainWidget->update();
|
||||||
ui->mainWidget->updateCycle();
|
ui->mainWidget->updateCycle();
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,8 @@
|
||||||
<addaction name="actionToolMove"/>
|
<addaction name="actionToolMove"/>
|
||||||
<addaction name="actionToolScale"/>
|
<addaction name="actionToolScale"/>
|
||||||
<addaction name="actionToolRotate"/>
|
<addaction name="actionToolRotate"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionToggleSimulation"/>
|
||||||
</widget>
|
</widget>
|
||||||
<action name="actionAddPart">
|
<action name="actionAddPart">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
|
@ -241,6 +243,20 @@
|
||||||
<string>4</string>
|
<string>4</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionToggleSimulation">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="media-playback-start"/>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Start Simulation</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Start the simulation</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>F5</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
|
Loading…
Add table
Reference in a new issue