From 1998aa96a40b999e901958750507d062540b82fe Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 24 Jan 2020 14:50:40 +1000 Subject: [PATCH] Qt: Simplify Change Disc menu logic --- src/duckstation-qt/mainwindow.cpp | 35 ++++++++++++++----------------- src/duckstation-qt/mainwindow.h | 2 ++ src/duckstation-qt/mainwindow.ui | 23 +++++++++++++++++++- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index bc014ab15..01e9e7538 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -129,27 +129,20 @@ void MainWindow::onStartDiscActionTriggered() m_host_interface->bootSystem(std::move(filename), QString()); } -void MainWindow::onChangeDiscActionTriggered() +void MainWindow::onChangeDiscFromFileActionTriggered() { - QMenu menu(tr("Change Disc..."), this); - QAction* from_file = menu.addAction(tr("From File...")); - QAction* from_game_list = menu.addAction(tr("From Game List")); + QString filename = + QFileDialog::getOpenFileName(this, tr("Select Disc Image"), QString(), tr(DISC_IMAGE_FILTER), nullptr); + if (filename.isEmpty()) + return; - QAction* selected = menu.exec(QCursor::pos()); - if (selected == from_file) - { - QString filename = - QFileDialog::getOpenFileName(this, tr("Select Disc Image"), QString(), tr(DISC_IMAGE_FILTER), nullptr); - if (filename.isEmpty()) - return; + m_host_interface->changeDisc(filename); +} - m_host_interface->changeDisc(filename); - } - else if (selected == from_game_list) - { - m_host_interface->pauseSystem(true); - switchToGameListView(); - } +void MainWindow::onChangeDiscFromGameListActionTriggered() +{ + m_host_interface->pauseSystem(true); + switchToGameListView(); } void MainWindow::onStartBiosActionTriggered() @@ -217,6 +210,7 @@ void MainWindow::updateEmulationActions(bool starting, bool running) m_ui.actionReset->setDisabled(starting || !running); m_ui.actionPause->setDisabled(starting || !running); m_ui.actionChangeDisc->setDisabled(starting || !running); + m_ui.menuChangeDisc->setDisabled(starting || !running); m_ui.actionLoadState->setDisabled(starting); m_ui.actionSaveState->setDisabled(starting); @@ -263,7 +257,10 @@ void MainWindow::connectSignals() connect(m_ui.actionStartDisc, &QAction::triggered, this, &MainWindow::onStartDiscActionTriggered); connect(m_ui.actionStartBios, &QAction::triggered, this, &MainWindow::onStartBiosActionTriggered); - connect(m_ui.actionChangeDisc, &QAction::triggered, this, &MainWindow::onChangeDiscActionTriggered); + connect(m_ui.actionChangeDisc, &QAction::triggered, [this] { m_ui.menuChangeDisc->exec(QCursor::pos()); }); + connect(m_ui.actionChangeDiscFromFile, &QAction::triggered, this, &MainWindow::onChangeDiscFromFileActionTriggered); + connect(m_ui.actionChangeDiscFromGameList, &QAction::triggered, this, + &MainWindow::onChangeDiscFromGameListActionTriggered); connect(m_ui.actionOpenDirectory, &QAction::triggered, this, &MainWindow::onOpenDirectoryActionTriggered); connect(m_ui.actionPowerOff, &QAction::triggered, m_host_interface, &QtHostInterface::powerOffSystem); connect(m_ui.actionReset, &QAction::triggered, m_host_interface, &QtHostInterface::resetSystem); diff --git a/src/duckstation-qt/mainwindow.h b/src/duckstation-qt/mainwindow.h index 15d2d6070..27e5f4779 100644 --- a/src/duckstation-qt/mainwindow.h +++ b/src/duckstation-qt/mainwindow.h @@ -33,6 +33,8 @@ private Q_SLOTS: void onStartDiscActionTriggered(); void onChangeDiscActionTriggered(); + void onChangeDiscFromFileActionTriggered(); + void onChangeDiscFromGameListActionTriggered(); void onStartBiosActionTriggered(); void onOpenDirectoryActionTriggered(); void onExitActionTriggered(); diff --git a/src/duckstation-qt/mainwindow.ui b/src/duckstation-qt/mainwindow.ui index 397af7d5f..27cc6a8f7 100644 --- a/src/duckstation-qt/mainwindow.ui +++ b/src/duckstation-qt/mainwindow.ui @@ -37,13 +37,24 @@ System + + + Change Disc + + + + :/icons/media-optical.png:/icons/media-optical.png + + + + - + @@ -340,6 +351,16 @@ &Settings... + + + From File... + + + + + From Game List... + +