synchronize playing status to play/pause button
This commit is contained in:
parent
7fbe0814d5
commit
e706579675
@ -62,36 +62,47 @@ int DroneController::getDuration() const {
|
|||||||
|
|
||||||
|
|
||||||
void DroneController::step() {
|
void DroneController::step() {
|
||||||
qDebug() << "frame " << frame << "/" << duration
|
qDebug("frame %d (%d%%)", frame, (int) ((double) frame / duration * 100));
|
||||||
<< " (" << (double) frame / duration * 100 << "%)";
|
|
||||||
emit frameChanged(frame);
|
emit frameChanged(frame);
|
||||||
frame++;
|
if (frame == duration) {
|
||||||
|
pause();
|
||||||
|
} else {
|
||||||
|
frame++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DroneController::play() {
|
void DroneController::play() {
|
||||||
|
if (!paused) return;
|
||||||
paused = false;
|
paused = false;
|
||||||
timer.start(1000. / framerate);
|
timer.start(1000. / framerate);
|
||||||
qDebug() << "playing";
|
qDebug() << "playing";
|
||||||
|
emit playing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DroneController::pause() {
|
void DroneController::pause() {
|
||||||
|
if (paused) return;
|
||||||
paused = true;
|
paused = true;
|
||||||
timer.stop();
|
timer.stop();
|
||||||
qDebug() << "pausing";
|
qDebug() << "pausing";
|
||||||
|
emit pausing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DroneController::suspend() {
|
void DroneController::suspend() {
|
||||||
bool old_paused = paused;
|
if (!paused) {
|
||||||
pause();
|
pause();
|
||||||
paused = old_paused;
|
paused = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DroneController::resume() {
|
void DroneController::resume() {
|
||||||
if (!paused) play();
|
if (!paused) {
|
||||||
|
paused = true;
|
||||||
|
play();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,6 +41,8 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void frameChanged(int frame);
|
void frameChanged(int frame);
|
||||||
|
void playing();
|
||||||
|
void pausing();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void step();
|
void step();
|
||||||
|
@ -55,6 +55,8 @@ void MainWindow::open(const QString &path) {
|
|||||||
if (dc) delete dc;
|
if (dc) delete dc;
|
||||||
dc = new DroneController(json_doc.object());
|
dc = new DroneController(json_doc.object());
|
||||||
playpause_action->setEnabled(true);
|
playpause_action->setEnabled(true);
|
||||||
|
connect(dc, &DroneController::playing, this, &MainWindow::play);
|
||||||
|
connect(dc, &DroneController::pausing, this, &MainWindow::pause);
|
||||||
slider->setMinimum(0);
|
slider->setMinimum(0);
|
||||||
slider->setMaximum(dc->getDuration());
|
slider->setMaximum(dc->getDuration());
|
||||||
connect(slider, &QSlider::sliderPressed, dc, &DroneController::suspend);
|
connect(slider, &QSlider::sliderPressed, dc, &DroneController::suspend);
|
||||||
|
Loading…
Reference in New Issue
Block a user