From 5659dde498190265b30bec0587f1d7c5a42b609f Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Tue, 13 Feb 2018 20:02:17 +0000 Subject: [PATCH] Pause the emulator when Disks are swapped. Signed-off-by: Andrea Odetti --- source/frontends/qapple/qapple.cpp | 41 ++++++++++++++++++++---------- source/frontends/qapple/qapple.h | 14 ++++++++++ 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/source/frontends/qapple/qapple.cpp b/source/frontends/qapple/qapple.cpp index 3eaf02bd..b2a98330 100644 --- a/source/frontends/qapple/qapple.cpp +++ b/source/frontends/qapple/qapple.cpp @@ -147,6 +147,24 @@ int MessageBox(HWND, const char * text, const char * caption, UINT type) } } + +QApple::PauseEmulator::PauseEmulator(QApple * qapple) : myQApple(qapple) +{ + myWasRunning = myQApple->actionPause->isEnabled(); + if (myWasRunning) + { + myQApple->actionPause->trigger(); + } +} + +QApple::PauseEmulator::~PauseEmulator() +{ + if (myWasRunning) + { + myQApple->actionStart->trigger(); + } +} + QApple::QApple(QWidget *parent) : QMainWindow(parent), myTimerID(0), myPreferences(this) { @@ -299,15 +317,12 @@ void QApple::on_actionMemory_triggered() void QApple::on_actionOptions_triggered() { - const bool running = actionPause->isEnabled(); - if (running) - { - // this is to overcome an issue in GNOME where the open file dialog gets lost - // if the emulator is running - // at times it can be found in a separate desktop, or it magically reappears - // but often it forces to terminate the emulator - actionPause->trigger(); - } + // this is to overcome an issue in GNOME where the open file dialog gets lost + // if the emulator is running + // at times it can be found in a separate desktop, or it magically reappears + // but often it forces to terminate the emulator + PauseEmulator pause(this); + const Preferences::Data currentOptions = getCurrentOptions(myGamepad); QSettings settings; // the function will "modify" it @@ -319,11 +334,6 @@ void QApple::on_actionOptions_triggered() setNewOptions(currentOptions, newOptions, myGamepad); } - if (running) - { - // otherwise we would slow down later - actionStart->trigger(); - } } void QApple::on_actionSave_state_triggered() @@ -390,5 +400,8 @@ void QApple::on_actionScreenshot_triggered() void QApple::on_actionSwap_disks_triggered() { + PauseEmulator pause(this); + + // this might open a file dialog DiskDriveSwap(); } diff --git a/source/frontends/qapple/qapple.h b/source/frontends/qapple/qapple.h index 643efd4b..9192da43 100644 --- a/source/frontends/qapple/qapple.h +++ b/source/frontends/qapple/qapple.h @@ -25,6 +25,7 @@ protected: virtual void timerEvent(QTimerEvent *event); private slots: + void on_actionStart_triggered(); void on_actionPause_triggered(); @@ -59,6 +60,19 @@ private slots: private: + // helper class to pause the emulator and restart at the end of the block + class PauseEmulator + { + public: + PauseEmulator(QApple * qapple); + + ~PauseEmulator(); + + private: + bool myWasRunning; + QApple * myQApple; + }; + void stopTimer(); void restartTimeCounters();