Skip to content

Commit

Permalink
Qt: make the pause play button only one button
Browse files Browse the repository at this point in the history
This is to avoid several issue with using 2 actions and switching between them.  This commit will instead have one action get his property changed on pause and play.
  • Loading branch information
aldelaro5 committed May 16, 2018
1 parent 1fe92b8 commit bc43f45
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
45 changes: 33 additions & 12 deletions Source/Core/DolphinQt2/ToolBar.cpp
Expand Up @@ -56,10 +56,7 @@ void ToolBar::OnEmulationStateChanged(Core::State state)
m_screenshot_action->setEnabled(running); m_screenshot_action->setEnabled(running);


bool playing = running && state != Core::State::Paused; bool playing = running && state != Core::State::Paused;
m_play_action->setEnabled(!playing); UpdatePausePlayButtonState(playing);
m_play_action->setVisible(!playing);
m_pause_action->setEnabled(playing);
m_pause_action->setVisible(playing);


bool paused = Core::GetState() == Core::State::Paused; bool paused = Core::GetState() == Core::State::Paused;
m_step_action->setEnabled(paused); m_step_action->setEnabled(paused);
Expand Down Expand Up @@ -101,8 +98,8 @@ void ToolBar::MakeActions()
m_set_pc_action = AddAction(this, tr("Set PC"), this, &ToolBar::SetPCPressed); m_set_pc_action = AddAction(this, tr("Set PC"), this, &ToolBar::SetPCPressed);


m_open_action = AddAction(this, tr("Open"), this, &ToolBar::OpenPressed); m_open_action = AddAction(this, tr("Open"), this, &ToolBar::OpenPressed);
m_play_action = AddAction(this, tr("Play"), this, &ToolBar::PlayPressed); m_pause_play_action = AddAction(this, tr("Play"), this, &ToolBar::PlayPressed);
m_pause_action = AddAction(this, tr("Pause"), this, &ToolBar::PausePressed);
m_stop_action = AddAction(this, tr("Stop"), this, &ToolBar::StopPressed); m_stop_action = AddAction(this, tr("Stop"), this, &ToolBar::StopPressed);
m_fullscreen_action = AddAction(this, tr("FullScr"), this, &ToolBar::FullScreenPressed); m_fullscreen_action = AddAction(this, tr("FullScr"), this, &ToolBar::FullScreenPressed);
m_screenshot_action = AddAction(this, tr("ScrShot"), this, &ToolBar::ScreenShotPressed); m_screenshot_action = AddAction(this, tr("ScrShot"), this, &ToolBar::ScreenShotPressed);
Expand All @@ -117,10 +114,10 @@ void ToolBar::MakeActions()
// Ensure every button has about the same width // Ensure every button has about the same width
std::vector<QWidget*> items; std::vector<QWidget*> items;
for (const auto& action : for (const auto& action :
{m_open_action, m_play_action, m_pause_action, m_stop_action, m_stop_action, {m_open_action, m_pause_play_action, m_stop_action, m_stop_action, m_fullscreen_action,
m_fullscreen_action, m_screenshot_action, m_config_action, m_graphics_action, m_screenshot_action, m_config_action, m_graphics_action, m_controllers_action,
m_controllers_action, m_step_action, m_step_over_action, m_step_out_action, m_skip_action, m_step_action, m_step_over_action, m_step_out_action, m_skip_action, m_show_pc_action,
m_show_pc_action, m_set_pc_action}) m_set_pc_action})
{ {
items.emplace_back(widgetForAction(action)); items.emplace_back(widgetForAction(action));
} }
Expand All @@ -134,6 +131,24 @@ void ToolBar::MakeActions()
widget->setMinimumWidth(min_width); widget->setMinimumWidth(min_width);
} }


void ToolBar::UpdatePausePlayButtonState(const bool playing_state)
{
if (playing_state)
{
disconnect(m_pause_play_action, 0, 0, 0);
m_pause_play_action->setText(tr("Pause"));
m_pause_play_action->setIcon(Resources::GetScaledThemeIcon("pause"));
connect(m_pause_play_action, &QAction::triggered, this, &ToolBar::PausePressed);
}
else
{
disconnect(m_pause_play_action, 0, 0, 0);
m_pause_play_action->setText(tr("Play"));
m_pause_play_action->setIcon(Resources::GetScaledThemeIcon("play"));
connect(m_pause_play_action, &QAction::triggered, this, &ToolBar::PlayPressed);
}
}

void ToolBar::UpdateIcons() void ToolBar::UpdateIcons()
{ {
m_step_action->setIcon(Resources::GetScaledThemeIcon("debugger_step_in")); m_step_action->setIcon(Resources::GetScaledThemeIcon("debugger_step_in"));
Expand All @@ -144,8 +159,14 @@ void ToolBar::UpdateIcons()
m_set_pc_action->setIcon(Resources::GetScaledThemeIcon("debugger_show_pc")); m_set_pc_action->setIcon(Resources::GetScaledThemeIcon("debugger_show_pc"));


m_open_action->setIcon(Resources::GetScaledThemeIcon("open")); m_open_action->setIcon(Resources::GetScaledThemeIcon("open"));
m_play_action->setIcon(Resources::GetScaledThemeIcon("play"));
m_pause_action->setIcon(Resources::GetScaledThemeIcon("pause")); const Core::State state = Core::GetState();
const bool playing = state != Core::State::Uninitialized && state != Core::State::Paused;
if (!playing)
m_pause_play_action->setIcon(Resources::GetScaledThemeIcon("play"));
else
m_pause_play_action->setIcon(Resources::GetScaledThemeIcon("pause"));

m_stop_action->setIcon(Resources::GetScaledThemeIcon("stop")); m_stop_action->setIcon(Resources::GetScaledThemeIcon("stop"));
m_fullscreen_action->setIcon(Resources::GetScaledThemeIcon("fullscreen")); m_fullscreen_action->setIcon(Resources::GetScaledThemeIcon("fullscreen"));
m_screenshot_action->setIcon(Resources::GetScaledThemeIcon("screenshot")); m_screenshot_action->setIcon(Resources::GetScaledThemeIcon("screenshot"));
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt2/ToolBar.h
Expand Up @@ -46,10 +46,10 @@ class ToolBar final : public QToolBar


void MakeActions(); void MakeActions();
void UpdateIcons(); void UpdateIcons();
void UpdatePausePlayButtonState(bool playing_state);


QAction* m_open_action; QAction* m_open_action;
QAction* m_play_action; QAction* m_pause_play_action;
QAction* m_pause_action;
QAction* m_stop_action; QAction* m_stop_action;
QAction* m_fullscreen_action; QAction* m_fullscreen_action;
QAction* m_screenshot_action; QAction* m_screenshot_action;
Expand Down

0 comments on commit bc43f45

Please sign in to comment.