all repos — mgba @ 1d00ccf6ddb760313c8f4fd0e8bd2e21ae64eca6

mGBA Game Boy Advance Emulator

Show savestate manager over game when in fullscreen
Jeffrey Pfau jeffrey@endrift.com
Thu, 16 Oct 2014 01:52:45 -0700
commit

1d00ccf6ddb760313c8f4fd0e8bd2e21ae64eca6

parent

73d28a1ae423017e3f16266dce1d019b8da292b4

M src/platform/qt/LoadSaveState.cppsrc/platform/qt/LoadSaveState.cpp

@@ -133,3 +133,8 @@ void LoadSaveState::closeEvent(QCloseEvent* event) {

emit closed(); QWidget::closeEvent(event); } + +void LoadSaveState::showEvent(QShowEvent* event) { + m_slots[m_currentFocus]->setFocus(); + QWidget::showEvent(event); +}
M src/platform/qt/LoadSaveState.hsrc/platform/qt/LoadSaveState.h

@@ -31,6 +31,7 @@

protected: virtual bool eventFilter(QObject*, QEvent*) override; virtual void closeEvent(QCloseEvent*) override; + virtual void showEvent(QShowEvent*) override; private: void loadState(int slot);
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -4,6 +4,7 @@ #include <QFileDialog>

#include <QKeyEvent> #include <QKeySequence> #include <QMenuBar> +#include <QStackedLayout> #include "GameController.h" #include "GDBWindow.h"

@@ -17,6 +18,7 @@ Window::Window(QWidget* parent)

: QMainWindow(parent) , m_logView(new LogView()) , m_stateWindow(nullptr) + , m_screenWidget(new QWidget()) #ifdef USE_GDB_STUB , m_gdbController(nullptr) #endif

@@ -25,8 +27,11 @@ m_controller = new GameController(this);

QGLFormat format(QGLFormat(QGL::Rgba | QGL::DoubleBuffer)); format.setSwapInterval(1); + m_screenWidget->setLayout(new QStackedLayout()); + m_screenWidget->layout()->setContentsMargins(0, 0, 0, 0); + setCentralWidget(m_screenWidget); m_display = new Display(format); - setCentralWidget(m_display); + attachWidget(m_display); connect(m_controller, SIGNAL(gameStarted(GBAThread*)), this, SLOT(gameStarted(GBAThread*))); connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_display, SLOT(stopDrawing())); connect(m_controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(gameStopped()));

@@ -133,6 +138,16 @@ emit shutdown();

QMainWindow::closeEvent(event); } +void Window::toggleFullScreen() { + if (isFullScreen()) { + showNormal(); + setCursor(Qt::ArrowCursor); + } else { + showFullScreen(); + setCursor(Qt::BlankCursor); + } +} + void Window::gameStarted(GBAThread* context) { emit startDrawing(m_controller->drawContext(), context); foreach (QAction* action, m_gameActions) {

@@ -153,14 +168,22 @@ }

bool wasPaused = m_controller->isPaused(); m_stateWindow = new LoadSaveState(m_controller); connect(this, SIGNAL(shutdown()), m_stateWindow, SLOT(hide())); - connect(m_stateWindow, &LoadSaveState::closed, [this]() { m_stateWindow = nullptr; }); + connect(m_stateWindow, &LoadSaveState::closed, [this]() { + m_screenWidget->layout()->removeWidget(m_stateWindow); + m_stateWindow = nullptr; + setFocus(); + }); if (!wasPaused) { m_controller->setPaused(true); connect(m_stateWindow, &LoadSaveState::closed, [this]() { m_controller->setPaused(false); }); } m_stateWindow->setAttribute(Qt::WA_DeleteOnClose); m_stateWindow->setMode(ls); - m_stateWindow->show(); + if (isFullScreen()) { + attachWidget(m_stateWindow); + } else { + m_stateWindow->show(); + } } void Window::setupMenu(QMenuBar* menubar) {

@@ -277,7 +300,7 @@ showNormal();

resize(VIDEO_HORIZONTAL_PIXELS * 4, VIDEO_VERTICAL_PIXELS * 4); }); frameMenu->addAction(setSize); - frameMenu->addAction(tr("Fullscreen"), this, SLOT(showFullScreen()), QKeySequence("Ctrl+F")); + frameMenu->addAction(tr("Fullscreen"), this, SLOT(toggleFullScreen()), QKeySequence("Ctrl+F")); QMenu* soundMenu = menubar->addMenu(tr("&Sound")); QMenu* buffersMenu = soundMenu->addMenu(tr("Buffer &size"));

@@ -305,3 +328,8 @@ foreach (QAction* action, m_gameActions) {

action->setDisabled(true); } } + +void Window::attachWidget(QWidget* widget) { + m_screenWidget->layout()->addWidget(widget); + static_cast<QStackedLayout*>(m_screenWidget->layout())->setCurrentWidget(widget); +}
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -46,6 +46,9 @@ signals:

void audioBufferSamplesChanged(int samples); void fpsTargetChanged(float target); +public slots: + void toggleFullScreen(); + private slots: void gameStarted(GBAThread*); void gameStopped();

@@ -54,11 +57,14 @@ private:

void setupMenu(QMenuBar*); void openStateWindow(LoadSave); + void attachWidget(QWidget* widget); + GameController* m_controller; Display* m_display; QList<QAction*> m_gameActions; LogView* m_logView; LoadSaveState* m_stateWindow; + QWidget* m_screenWidget; #ifdef USE_GDB_STUB GDBController* m_gdbController;