aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/drone_controller.cc25
-rw-r--r--src/drone_controller.hh2
-rw-r--r--src/main_window.cc2
3 files changed, 22 insertions, 7 deletions
diff --git a/src/drone_controller.cc b/src/drone_controller.cc
index 46acc7e..2f1364e 100644
--- a/src/drone_controller.cc
+++ b/src/drone_controller.cc
@@ -62,36 +62,47 @@ int DroneController::getDuration() const {
void DroneController::step() {
- qDebug() << "frame " << frame << "/" << duration
- << " (" << (double) frame / duration * 100 << "%)";
+ qDebug("frame %d (%d%%)", frame, (int) ((double) frame / duration * 100));
emit frameChanged(frame);
- frame++;
+ if (frame == duration) {
+ pause();
+ } else {
+ frame++;
+ }
}
void DroneController::play() {
+ if (!paused) return;
paused = false;
timer.start(1000. / framerate);
qDebug() << "playing";
+ emit playing();
}
void DroneController::pause() {
+ if (paused) return;
paused = true;
timer.stop();
qDebug() << "pausing";
+ emit pausing();
}
void DroneController::suspend() {
- bool old_paused = paused;
- pause();
- paused = old_paused;
+ if (!paused) {
+ pause();
+ paused = false;
+ }
}
void DroneController::resume() {
- if (!paused) play();
+ if (!paused) {
+ paused = true;
+ play();
+ }
}
diff --git a/src/drone_controller.hh b/src/drone_controller.hh
index 484cd57..4afc2b6 100644
--- a/src/drone_controller.hh
+++ b/src/drone_controller.hh
@@ -41,6 +41,8 @@ public:
signals:
void frameChanged(int frame);
+ void playing();
+ void pausing();
private slots:
void step();
diff --git a/src/main_window.cc b/src/main_window.cc
index 5e58660..8acfefb 100644
--- a/src/main_window.cc
+++ b/src/main_window.cc
@@ -55,6 +55,8 @@ void MainWindow::open(const QString &path) {
if (dc) delete dc;
dc = new DroneController(json_doc.object());
playpause_action->setEnabled(true);
+ connect(dc, &DroneController::playing, this, &MainWindow::play);
+ connect(dc, &DroneController::pausing, this, &MainWindow::pause);
slider->setMinimum(0);
slider->setMaximum(dc->getDuration());
connect(slider, &QSlider::sliderPressed, dc, &DroneController::suspend);