Qt: use Settings::EmulationStateChanged

This commit is contained in:
Michael M 2017-09-04 11:12:13 -07:00
parent 8e805dcbf4
commit 3e1072b24d
22 changed files with 97 additions and 160 deletions

View File

@ -21,6 +21,7 @@
#include <map>
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/HW/SI/SI.h"
#include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"
@ -238,6 +239,9 @@ void ControllersWindow::CreateMainLayout()
void ControllersWindow::ConnectWidgets()
{
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
[=](Core::State state) { OnEmulationStateChanged(state != Core::State::Uninitialized); });
connect(m_wiimote_passthrough, &QRadioButton::toggled, this,
&ControllersWindow::OnWiimoteModeChanged);

View File

@ -25,9 +25,9 @@ class ControllersWindow final : public QDialog
Q_OBJECT
public:
explicit ControllersWindow(QWidget* parent);
void OnEmulationStateChanged(bool running);
private:
void OnEmulationStateChanged(bool running);
void OnWiimoteModeChanged(bool passthrough);
void OnWiimoteTypeChanged(int state);
void OnGCTypeChanged(int state);

View File

@ -11,9 +11,11 @@
#include "Core/Config/GraphicsSettings.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "DolphinQt2/Config/Graphics/GraphicsBool.h"
#include "DolphinQt2/Config/Graphics/GraphicsChoice.h"
#include "DolphinQt2/Config/Graphics/GraphicsWindow.h"
#include "DolphinQt2/Settings.h"
#include "VideoCommon/VideoConfig.h"
AdvancedWidget::AdvancedWidget(GraphicsWindow* parent) : GraphicsWidget(parent)
@ -24,8 +26,8 @@ AdvancedWidget::AdvancedWidget(GraphicsWindow* parent) : GraphicsWidget(parent)
AddDescriptions();
connect(parent, &GraphicsWindow::BackendChanged, this, &AdvancedWidget::OnBackendChanged);
connect(parent, &GraphicsWindow::EmulationStarted, [this] { OnEmulationStateChanged(true); });
connect(parent, &GraphicsWindow::EmulationStopped, [this] { OnEmulationStateChanged(false); });
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
[=](Core::State state) { OnEmulationStateChanged(state != Core::State::Uninitialized); });
OnBackendChanged();
}

View File

@ -15,9 +15,11 @@
#include "Core/Config/GraphicsSettings.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "DolphinQt2/Config/Graphics/GraphicsBool.h"
#include "DolphinQt2/Config/Graphics/GraphicsChoice.h"
#include "DolphinQt2/Config/Graphics/GraphicsWindow.h"
#include "DolphinQt2/Settings.h"
#include "UICommon/VideoUtils.h"
#include "VideoCommon/VideoBackendBase.h"
#include "VideoCommon/VideoConfig.h"
@ -32,8 +34,8 @@ GeneralWidget::GeneralWidget(X11Utils::XRRConfiguration* xrr_config, GraphicsWin
emit BackendChanged(QString::fromStdString(SConfig::GetInstance().m_strVideoBackend));
connect(parent, &GraphicsWindow::BackendChanged, this, &GeneralWidget::OnBackendChanged);
connect(parent, &GraphicsWindow::EmulationStarted, [this] { OnEmulationStateChanged(true); });
connect(parent, &GraphicsWindow::EmulationStopped, [this] { OnEmulationStateChanged(false); });
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
[=](Core::State state) { OnEmulationStateChanged(state != Core::State::Uninitialized); });
}
void GeneralWidget::CreateWidgets()

View File

@ -29,9 +29,6 @@ GraphicsWindow::GraphicsWindow(X11Utils::XRRConfiguration* xrr_config, MainWindo
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
OnBackendChanged(QString::fromStdString(SConfig::GetInstance().m_strVideoBackend));
connect(parent, &MainWindow::EmulationStarted, this, &GraphicsWindow::EmulationStarted);
connect(parent, &MainWindow::EmulationStopped, this, &GraphicsWindow::EmulationStopped);
}
void GraphicsWindow::CreateMainLayout()

View File

@ -33,8 +33,6 @@ public:
bool eventFilter(QObject* object, QEvent* event) override;
signals:
void BackendChanged(const QString& backend);
void EmulationStarted();
void EmulationStopped();
private:
void CreateMainLayout();

View File

@ -40,15 +40,9 @@ SettingsWindow::SettingsWindow(QWidget* parent) : QDialog(parent)
AddTab(m_tabs, tr("General"), new GeneralPane(), "config");
AddTab(m_tabs, tr("Interface"), new InterfacePane(), "browse");
auto* audio_pane = new AudioPane;
m_audio_pane_index = AddTab(m_tabs, tr("Audio"), audio_pane, "play");
m_audio_pane_index = AddTab(m_tabs, tr("Audio"), new AudioPane(), "play");
AddTab(m_tabs, tr("Paths"), new PathPane(), "browse");
connect(this, &SettingsWindow::EmulationStarted,
[audio_pane] { audio_pane->OnEmulationStateChanged(true); });
connect(this, &SettingsWindow::EmulationStopped,
[audio_pane] { audio_pane->OnEmulationStateChanged(false); });
// Dialog box buttons
QDialogButtonBox* ok_box = new QDialogButtonBox(QDialogButtonBox::Ok);
connect(ok_box, &QDialogButtonBox::accepted, this, &SettingsWindow::accept);

View File

@ -15,10 +15,6 @@ public:
explicit SettingsWindow(QWidget* parent = nullptr);
void SelectAudioPane();
signals:
void EmulationStarted();
void EmulationStopped();
private:
ListTabWidget* m_tabs;
int m_audio_pane_index = -1;

View File

@ -174,11 +174,8 @@ void GameList::ShowContextMenu(const QPoint&)
QAction* change_disc = AddAction(menu, tr("Change &Disc"), this, &GameList::ChangeDisc);
connect(this, &GameList::EmulationStarted, change_disc,
[change_disc] { change_disc->setEnabled(true); });
connect(this, &GameList::EmulationStopped, change_disc,
[change_disc] { change_disc->setEnabled(false); });
connect(&Settings::Instance(), &Settings::EmulationStateChanged, change_disc,
[change_disc] { change_disc->setEnabled(Core::IsRunning()); });
change_disc->setEnabled(Core::IsRunning());
menu->addSeparator();
@ -202,15 +199,13 @@ void GameList::ShowContextMenu(const QPoint&)
for (QAction* a : {wad_install_action, wad_uninstall_action})
{
connect(this, &GameList::EmulationStarted, a, [a] { a->setEnabled(false); });
a->setEnabled(!Core::IsRunning());
menu->addAction(a);
}
connect(this, &GameList::EmulationStopped, wad_install_action,
[wad_install_action] { wad_install_action->setEnabled(true); });
connect(this, &GameList::EmulationStopped, wad_uninstall_action, [wad_uninstall_action, game] {
wad_uninstall_action->setEnabled(game->IsInstalled());
connect(&Settings::Instance(), &Settings::EmulationStateChanged, menu, [=](Core::State state) {
wad_install_action->setEnabled(state == Core::State::Uninitialized);
wad_uninstall_action->setEnabled(state == Core::State::Uninitialized && game->IsInstalled());
});
menu->addSeparator();
@ -231,10 +226,9 @@ void GameList::ShowContextMenu(const QPoint&)
connect(netplay_host, &QAction::triggered,
[this, game] { emit NetPlayHost(game->GetUniqueID()); });
connect(this, &GameList::EmulationStarted, netplay_host,
[netplay_host] { netplay_host->setEnabled(false); });
connect(this, &GameList::EmulationStopped, netplay_host,
[netplay_host] { netplay_host->setEnabled(true); });
connect(&Settings::Instance(), &Settings::EmulationStateChanged, menu, [=](Core::State state) {
netplay_host->setEnabled(state == Core::State::Uninitialized);
});
netplay_host->setEnabled(!Core::IsRunning());
menu->addAction(netplay_host);

View File

@ -29,8 +29,6 @@ public:
signals:
void GameSelected();
void EmulationStarted();
void EmulationStopped();
void NetPlayHost(const QString& game_id);
void SelectionChanged(QSharedPointer<GameFile> game_file);

View File

@ -121,9 +121,9 @@ void MainWindow::ShutdownControllers()
void MainWindow::InitCoreCallbacks()
{
Core::SetOnStateChangedCallback([=](Core::State state) {
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [=](Core::State state) {
if (state == Core::State::Uninitialized)
emit EmulationStopped();
OnStopComplete();
});
installEventFilter(this);
m_render_widget->installEventFilter(this);
@ -152,11 +152,6 @@ void MainWindow::CreateComponents()
m_hotkey_window = new MappingWindow(this, 0);
m_logger_widget = new LoggerWidget(this);
connect(this, &MainWindow::EmulationStarted, m_settings_window,
&SettingsWindow::EmulationStarted);
connect(this, &MainWindow::EmulationStopped, m_settings_window,
&SettingsWindow::EmulationStopped);
#if defined(HAVE_XRANDR) && HAVE_XRANDR
m_graphics_window = new GraphicsWindow(
new X11Utils::XRRConfiguration(
@ -233,17 +228,9 @@ void MainWindow::ConnectMenuBar()
connect(m_menu_bar, &MenuBar::ShowAboutDialog, this, &MainWindow::ShowAboutDialog);
connect(this, &MainWindow::EmulationStarted, m_menu_bar, &MenuBar::EmulationStarted);
connect(this, &MainWindow::EmulationPaused, m_menu_bar, &MenuBar::EmulationPaused);
connect(this, &MainWindow::EmulationStopped, m_menu_bar, &MenuBar::EmulationStopped);
connect(m_game_list, &GameList::SelectionChanged, m_menu_bar, &MenuBar::SelectionChanged);
connect(this, &MainWindow::ReadOnlyModeChanged, m_menu_bar, &MenuBar::ReadOnlyModeChanged);
connect(this, &MainWindow::RecordingStatusChanged, m_menu_bar, &MenuBar::RecordingStatusChanged);
connect(this, &MainWindow::EmulationStarted, this,
[=]() { m_controllers_window->OnEmulationStateChanged(true); });
connect(this, &MainWindow::EmulationStopped, this,
[=]() { m_controllers_window->OnEmulationStateChanged(false); });
}
void MainWindow::ConnectHotkeys()
@ -284,20 +271,12 @@ void MainWindow::ConnectToolBar()
connect(m_tool_bar, &ToolBar::SettingsPressed, this, &MainWindow::ShowSettingsWindow);
connect(m_tool_bar, &ToolBar::ControllersPressed, this, &MainWindow::ShowControllersWindow);
connect(m_tool_bar, &ToolBar::GraphicsPressed, this, &MainWindow::ShowGraphicsWindow);
connect(this, &MainWindow::EmulationStarted, m_tool_bar, &ToolBar::EmulationStarted);
connect(this, &MainWindow::EmulationPaused, m_tool_bar, &ToolBar::EmulationPaused);
connect(this, &MainWindow::EmulationStopped, m_tool_bar, &ToolBar::EmulationStopped);
connect(this, &MainWindow::EmulationStopped, this, &MainWindow::OnStopComplete);
}
void MainWindow::ConnectGameList()
{
connect(m_game_list, &GameList::GameSelected, this, &MainWindow::Play);
connect(m_game_list, &GameList::NetPlayHost, this, &MainWindow::NetPlayHost);
connect(this, &MainWindow::EmulationStarted, m_game_list, &GameList::EmulationStarted);
connect(this, &MainWindow::EmulationStopped, m_game_list, &GameList::EmulationStopped);
}
void MainWindow::ConnectRenderWidget()
@ -336,7 +315,6 @@ void MainWindow::Play()
if (Core::GetState() == Core::State::Paused)
{
Core::SetState(Core::State::Running);
emit EmulationStarted();
}
else
{
@ -363,7 +341,6 @@ void MainWindow::Play()
void MainWindow::Pause()
{
Core::SetState(Core::State::Paused);
emit EmulationPaused();
}
void MainWindow::OnStopComplete()
@ -454,7 +431,6 @@ void MainWindow::Reset()
void MainWindow::FrameAdvance()
{
Core::DoFrameStep();
EmulationPaused();
}
void MainWindow::FullScreen()
@ -499,7 +475,6 @@ void MainWindow::StartGame(std::unique_ptr<BootParameters>&& parameters)
return;
}
ShowRenderWidget();
emit EmulationStarted();
#ifdef Q_OS_WIN
// Prevents Windows from sleeping, turning off the display, or idling
@ -676,7 +651,6 @@ void MainWindow::NetPlayInit()
static_cast<void (MainWindow::*)(const QString&)>(&MainWindow::StartGame));
connect(m_netplay_dialog, &NetPlayDialog::Stop, this, &MainWindow::RequestStop);
connect(m_netplay_dialog, &NetPlayDialog::rejected, this, &MainWindow::NetPlayQuit);
connect(this, &MainWindow::EmulationStopped, m_netplay_dialog, &NetPlayDialog::EmulationStopped);
connect(m_netplay_setup_dialog, &NetPlaySetupDialog::Join, this, &MainWindow::NetPlayJoin);
connect(m_netplay_setup_dialog, &NetPlaySetupDialog::Host, this, &MainWindow::NetPlayHost);
}

View File

@ -40,9 +40,6 @@ public:
bool eventFilter(QObject* object, QEvent* event) override;
signals:
void EmulationStarted();
void EmulationPaused();
void EmulationStopped();
void ReadOnlyModeChanged(bool read_only);
void RecordingStatusChanged(bool recording);

View File

@ -38,64 +38,42 @@ MenuBar::MenuBar(QWidget* parent) : QMenuBar(parent)
AddViewMenu();
AddHelpMenu();
EmulationStopped();
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
[=](Core::State state) { OnEmulationStateChanged(state); });
OnEmulationStateChanged(Core::GetState());
connect(this, &MenuBar::SelectionChanged, this, &MenuBar::OnSelectionChanged);
connect(this, &MenuBar::RecordingStatusChanged, this, &MenuBar::OnRecordingStatusChanged);
connect(this, &MenuBar::ReadOnlyModeChanged, this, &MenuBar::OnReadOnlyModeChanged);
}
void MenuBar::EmulationStarted()
void MenuBar::OnEmulationStateChanged(Core::State state)
{
bool running = state != Core::State::Uninitialized;
bool playing = running && state != Core::State::Paused;
// Emulation
m_play_action->setEnabled(false);
m_play_action->setVisible(false);
m_pause_action->setEnabled(true);
m_pause_action->setVisible(true);
m_stop_action->setEnabled(true);
m_reset_action->setEnabled(true);
m_fullscreen_action->setEnabled(true);
m_frame_advance_action->setEnabled(true);
m_screenshot_action->setEnabled(true);
m_state_load_menu->setEnabled(true);
m_state_save_menu->setEnabled(true);
m_play_action->setEnabled(!playing);
m_play_action->setVisible(!playing);
m_pause_action->setEnabled(playing);
m_pause_action->setVisible(playing);
m_stop_action->setEnabled(running);
m_stop_action->setVisible(running);
m_reset_action->setEnabled(running);
m_fullscreen_action->setEnabled(running);
m_frame_advance_action->setEnabled(running);
m_screenshot_action->setEnabled(running);
m_state_load_menu->setEnabled(running);
m_state_save_menu->setEnabled(running);
// Movie
m_recording_read_only->setEnabled(true);
m_recording_play->setEnabled(false);
m_recording_read_only->setEnabled(running);
if (!running)
m_recording_stop->setEnabled(false);
m_recording_play->setEnabled(!running);
UpdateStateSlotMenu();
UpdateToolsMenu(true);
}
void MenuBar::EmulationPaused()
{
m_play_action->setEnabled(true);
m_play_action->setVisible(true);
m_pause_action->setEnabled(false);
m_pause_action->setVisible(false);
}
void MenuBar::EmulationStopped()
{
// Emulation
m_play_action->setEnabled(true);
m_play_action->setVisible(true);
m_pause_action->setEnabled(false);
m_pause_action->setVisible(false);
m_stop_action->setEnabled(false);
m_reset_action->setEnabled(false);
m_fullscreen_action->setEnabled(false);
m_frame_advance_action->setEnabled(false);
m_screenshot_action->setEnabled(false);
m_state_load_menu->setEnabled(false);
m_state_save_menu->setEnabled(false);
// Movie
m_recording_read_only->setEnabled(false);
m_recording_stop->setEnabled(false);
m_recording_play->setEnabled(false);
UpdateStateSlotMenu();
UpdateToolsMenu(false);
UpdateToolsMenu(running);
}
void MenuBar::AddFileMenu()

View File

@ -9,13 +9,18 @@
#include <QMenu>
#include <QMenuBar>
#include "DolphinQt2/GameList/GameFile.h"
namespace Core
{
enum class State;
}
namespace DiscIO
{
enum class Region;
};
#include "DolphinQt2/GameList/GameFile.h"
class MenuBar final : public QMenuBar
{
Q_OBJECT
@ -23,9 +28,6 @@ class MenuBar final : public QMenuBar
public:
explicit MenuBar(QWidget* parent = nullptr);
void EmulationStarted();
void EmulationPaused();
void EmulationStopped();
void UpdateStateSlotMenu();
void UpdateToolsMenu(bool emulation_started);
@ -88,6 +90,8 @@ signals:
void ReadOnlyModeChanged(bool read_only);
private:
void OnEmulationStateChanged(Core::State state);
void AddFileMenu();
void AddEmulationMenu();

View File

@ -188,8 +188,8 @@ void NetPlayDialog::ConnectWidgets()
}
});
connect(this, &NetPlayDialog::EmulationStopped, this, [this] {
if (isVisible())
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [=](Core::State state) {
if (state == Core::State::Uninitialized && isVisible())
GameStatusChanged(false);
});
}

View File

@ -54,7 +54,6 @@ public:
void SetMD5Result(int pid, const std::string& result) override;
void AbortMD5() override;
signals:
void EmulationStopped();
void Boot(const QString& filename);
void Stop();

View File

@ -11,11 +11,16 @@
#include "Common/FileUtil.h"
#include "Common/StringUtil.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "DolphinQt2/GameList/GameListModel.h"
#include "DolphinQt2/Settings.h"
#include "InputCommon/InputConfig.h"
Settings::Settings() = default;
Settings::Settings()
{
Core::SetOnStateChangedCallback(
[this](Core::State new_state) { emit EmulationStateChanged(new_state); });
}
Settings& Settings::Instance()
{

View File

@ -12,6 +12,11 @@
#include "Core/NetPlayClient.h"
#include "Core/NetPlayServer.h"
namespace Core
{
enum class State;
}
namespace DiscIO
{
enum class Language;
@ -76,6 +81,7 @@ public:
GameListModel* GetGameListModel() const;
signals:
void EmulationStateChanged(Core::State new_state);
void ThemeChanged();
void PathAdded(const QString&);
void PathRemoved(const QString&);

View File

@ -18,6 +18,7 @@
#include "AudioCommon/AudioCommon.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "DolphinQt2/Config/SettingsWindow.h"
#include "DolphinQt2/Settings.h"
@ -28,6 +29,8 @@ AudioPane::AudioPane()
ConnectWidgets();
connect(&Settings::Instance(), &Settings::VolumeChanged, this, &AudioPane::OnVolumeChanged);
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
[=](Core::State state) { OnEmulationStateChanged(state != Core::State::Uninitialized); });
}
void AudioPane::CreateWidgets()

View File

@ -21,8 +21,6 @@ class AudioPane final : public QWidget
public:
explicit AudioPane();
void OnEmulationStateChanged(bool running);
private:
void CreateWidgets();
void ConnectWidgets();
@ -30,6 +28,7 @@ private:
void LoadSettings();
void SaveSettings();
void OnEmulationStateChanged(bool running);
void OnBackendChanged();
void OnVolumeChanged(int volume);

View File

@ -4,6 +4,7 @@
#include <QIcon>
#include "Core/Core.h"
#include "DolphinQt2/QtUtils/ActionHelper.h"
#include "DolphinQt2/Resources.h"
#include "DolphinQt2/Settings.h"
@ -22,40 +23,24 @@ ToolBar::ToolBar(QWidget* parent) : QToolBar(parent)
connect(&Settings::Instance(), &Settings::ThemeChanged, this, &ToolBar::UpdateIcons);
UpdateIcons();
EmulationStopped();
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
[this](Core::State state) { OnEmulationStateChanged(state); });
OnEmulationStateChanged(Core::GetState());
}
void ToolBar::EmulationStarted()
void ToolBar::OnEmulationStateChanged(Core::State state)
{
m_play_action->setEnabled(false);
m_play_action->setVisible(false);
m_pause_action->setEnabled(true);
m_pause_action->setVisible(true);
m_stop_action->setEnabled(true);
m_stop_action->setVisible(true);
m_fullscreen_action->setEnabled(true);
m_screenshot_action->setEnabled(true);
}
bool running = state != Core::State::Uninitialized;
m_stop_action->setEnabled(running);
m_stop_action->setVisible(running);
m_fullscreen_action->setEnabled(running);
m_screenshot_action->setEnabled(running);
void ToolBar::EmulationPaused()
{
m_play_action->setEnabled(true);
m_play_action->setVisible(true);
m_pause_action->setEnabled(false);
m_pause_action->setVisible(false);
m_stop_action->setEnabled(true);
m_stop_action->setVisible(true);
}
void ToolBar::EmulationStopped()
{
m_play_action->setEnabled(true);
m_play_action->setVisible(true);
m_pause_action->setEnabled(false);
m_pause_action->setVisible(false);
m_stop_action->setEnabled(false);
m_fullscreen_action->setEnabled(false);
m_screenshot_action->setEnabled(false);
bool playing = running && state != Core::State::Paused;
m_play_action->setEnabled(!playing);
m_play_action->setVisible(!playing);
m_pause_action->setEnabled(playing);
m_pause_action->setVisible(playing);
}
void ToolBar::MakeActions()

View File

@ -8,6 +8,11 @@
#include <QLineEdit>
#include <QToolBar>
namespace Core
{
enum class State;
}
class ToolBar final : public QToolBar
{
Q_OBJECT
@ -15,11 +20,6 @@ class ToolBar final : public QToolBar
public:
explicit ToolBar(QWidget* parent = nullptr);
public slots:
void EmulationStarted();
void EmulationPaused();
void EmulationStopped();
signals:
void OpenPressed();
void PlayPressed();
@ -33,6 +33,8 @@ signals:
void GraphicsPressed();
private:
void OnEmulationStateChanged(Core::State state);
void MakeActions();
void UpdateIcons();