feat: added QT pause button

This commit is contained in:
Djairo Hougee 2024-05-28 19:36:09 +02:00
parent 7b06a54542
commit 489727663c
4 changed files with 14 additions and 4 deletions

View File

@ -84,7 +84,6 @@ void MainWindow::setupTechniques() {
this->timer->SetClientData(program);
this->timer->setDt(DT);
intr->AddObserver(vtkCommand::TimerEvent, this->timer);
intr->AddObserver(vtkCommand::KeyPressEvent, this->timer);
intr->CreateRepeatingTimer(17); // 60 fps == 1000 / 60 == 16.7 ms per frame
}
@ -236,3 +235,6 @@ void MainWindow::on_IregularlySubsampledButton_clicked(bool checked) {
}
void MainWindow::on_pauseButton_clicked(bool checked) {
this->timer->togglePaused();
}

View File

@ -32,6 +32,7 @@ private slots:
void on_FullySampledButton_clicked(bool checked);
void on_RegularlySubsampledButton_clicked(bool checked);
void on_IregularlySubsampledButton_clicked(bool checked);
void on_pauseButton_clicked(bool checked);
private:
Ui::MainWindow* ui;

View File

@ -18,6 +18,7 @@
#include <QtWidgets/QRadioButton>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
#include <QPushButton>
QT_BEGIN_NAMESPACE
@ -54,6 +55,7 @@ public:
QRadioButton *RegularlySubsampledButton;
QRadioButton *IregularlySubsampledButton;
Program *program;
QPushButton *pauseButton;
void setupUi(QMainWindow *MainWindow)
{
@ -234,6 +236,12 @@ public:
horizontalLayout->addWidget(program);
pauseButton = new QPushButton("pause", settingsBox);
pauseButton->setGeometry(QRect(QPoint(100, 100), QSize(200, 50)));
pauseButton->setObjectName(QString::fromUtf8("pauseButton"));
verticalLayout_3->addWidget(pauseButton);
MainWindow->setCentralWidget(centralWidget);
retranslateUi(MainWindow);
@ -265,6 +273,7 @@ public:
FullySampledButton->setText(QCoreApplication::translate("MainWindow", "Fully sampled", nullptr));
RegularlySubsampledButton->setText(QCoreApplication::translate("MainWindow", "Regularly subsampled", nullptr));
IregularlySubsampledButton->setText(QCoreApplication::translate("MainWindow", "Irregularly subsampled", nullptr));
pauseButton->setText(QCoreApplication::translate("MainWindow", "Pause Simulation", nullptr));
} // retranslateUi
};

View File

@ -15,9 +15,7 @@ TimerCallbackCommand* TimerCallbackCommand::New(Program *program) {
void TimerCallbackCommand::Execute(vtkObject* caller, unsigned long eventId, void* vtkNotUsed(callData)) {
auto intr = reinterpret_cast<vtkRenderWindowInteractor *>(caller);
if (eventId == vtkCommand::KeyPressEvent and not strcmp("space", intr->GetKeySym())) {
this->paused = ! this->paused;
} else if (eventId == vtkCommand::TimerEvent and not this->paused) {
if (eventId == vtkCommand::TimerEvent and not this->paused) {
this->time += this->dt;
if (this->time >= this->maxTime) {