Qt: Add a context menu to the toolbar's Settings button when the game is running

A new small context menu that allows to select between global settings
and game settings.
This commit is contained in:
Silent 2023-02-28 19:29:41 +01:00 committed by refractionpcsx2
parent 97d3baba35
commit c33fb2adbd
3 changed files with 35 additions and 3 deletions

View File

@ -254,6 +254,10 @@ void MainWindow::setupAdditionalUi()
m_status_vps_widget->setFixedSize(125, 16);
m_status_vps_widget->hide();
m_settings_toolbar_menu = new QMenu(m_ui.toolBar);
m_settings_toolbar_menu->addAction(m_ui.actionSettings);
m_settings_toolbar_menu->addAction(m_ui.actionViewGameProperties);
for (u32 scale = 0; scale <= 10; scale++)
{
QAction* action = m_ui.menuWindowSize->addAction((scale == 0) ? tr("Internal Resolution") : tr("%1x Scale").arg(scale));
@ -316,6 +320,7 @@ void MainWindow::connectSignals()
connect(m_ui.menuLoadState, &QMenu::aboutToShow, this, &MainWindow::onLoadStateMenuAboutToShow);
connect(m_ui.menuSaveState, &QMenu::aboutToShow, this, &MainWindow::onSaveStateMenuAboutToShow);
connect(m_ui.actionSettings, &QAction::triggered, [this]() { doSettings(); });
connect(m_ui.actionSettings2, &QAction::triggered, this, &MainWindow::onSettingsTriggeredFromToolbar);
connect(m_ui.actionInterfaceSettings, &QAction::triggered, [this]() { doSettings("Interface"); });
connect(m_ui.actionGameListSettings, &QAction::triggered, [this]() { doSettings("Game List"); });
connect(m_ui.actionEmulationSettings, &QAction::triggered, [this]() { doSettings("Emulation"); });
@ -1013,6 +1018,18 @@ void MainWindow::onToolsVideoCaptureToggled(bool checked)
g_emu_thread->beginCapture(path);
}
void MainWindow::onSettingsTriggeredFromToolbar()
{
if (s_vm_valid)
{
m_settings_toolbar_menu->exec(QCursor::pos());
}
else
{
doSettings();
}
}
void MainWindow::saveStateToConfig()
{
if (!isVisible())

View File

@ -19,6 +19,7 @@
#include <QtWidgets/QLabel>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenu>
#include <functional>
#include <optional>
@ -170,6 +171,7 @@ private Q_SLOTS:
void onBlockDumpActionToggled(bool checked);
void onShowAdvancedSettingsToggled(bool checked);
void onToolsVideoCaptureToggled(bool checked);
void onSettingsTriggeredFromToolbar();
// Input Recording
void onInputRecNewActionTriggered();
@ -283,6 +285,8 @@ private:
QLabel* m_status_vps_widget = nullptr;
QLabel* m_status_resolution_widget = nullptr;
QMenu* m_settings_toolbar_menu = nullptr;
QString m_current_disc_path;
QString m_current_elf_override;
QString m_current_game_serial;

View File

@ -79,7 +79,6 @@
<addaction name="menuLoadState"/>
<addaction name="menuSaveState"/>
<addaction name="separator"/>
<addaction name="actionSettings"/>
<addaction name="actionExit"/>
</widget>
<widget class="QMenu" name="menuSettings">
@ -246,7 +245,7 @@
<addaction name="separator"/>
<addaction name="actionFullscreen"/>
<addaction name="separator"/>
<addaction name="actionSettings"/>
<addaction name="actionSettings2"/>
<addaction name="actionControllerSettings"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
@ -523,7 +522,19 @@
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Settings...</string>
<string>&amp;Settings</string>
</property>
<property name="menuRole">
<enum>QAction::PreferencesRole</enum>
</property>
</action>
<action name="actionSettings2">
<property name="icon">
<iconset theme="settings-3-line">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Settings</string>
</property>
<property name="menuRole">
<enum>QAction::PreferencesRole</enum>