Merge pull request #6862 from aldelaro5/qt-unify-pause-play

Qt: make the pause play button only one button
This commit is contained in:
Léo Lam 2018-05-16 14:07:35 +02:00 committed by GitHub
commit 9335400f65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 14 deletions

View File

@ -56,10 +56,7 @@ void ToolBar::OnEmulationStateChanged(Core::State state)
m_screenshot_action->setEnabled(running);
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);
UpdatePausePlayButtonState(playing);
bool paused = Core::GetState() == Core::State::Paused;
m_step_action->setEnabled(paused);
@ -101,8 +98,8 @@ void ToolBar::MakeActions()
m_set_pc_action = AddAction(this, tr("Set PC"), this, &ToolBar::SetPCPressed);
m_open_action = AddAction(this, tr("Open"), this, &ToolBar::OpenPressed);
m_play_action = AddAction(this, tr("Play"), this, &ToolBar::PlayPressed);
m_pause_action = AddAction(this, tr("Pause"), this, &ToolBar::PausePressed);
m_pause_play_action = AddAction(this, tr("Play"), this, &ToolBar::PlayPressed);
m_stop_action = AddAction(this, tr("Stop"), this, &ToolBar::StopPressed);
m_fullscreen_action = AddAction(this, tr("FullScr"), this, &ToolBar::FullScreenPressed);
m_screenshot_action = AddAction(this, tr("ScrShot"), this, &ToolBar::ScreenShotPressed);
@ -117,10 +114,10 @@ void ToolBar::MakeActions()
// Ensure every button has about the same width
std::vector<QWidget*> items;
for (const auto& action :
{m_open_action, m_play_action, m_pause_action, m_stop_action, m_stop_action,
m_fullscreen_action, m_screenshot_action, m_config_action, m_graphics_action,
m_controllers_action, m_step_action, m_step_over_action, m_step_out_action, m_skip_action,
m_show_pc_action, m_set_pc_action})
{m_open_action, m_pause_play_action, m_stop_action, m_stop_action, m_fullscreen_action,
m_screenshot_action, m_config_action, m_graphics_action, m_controllers_action,
m_step_action, m_step_over_action, m_step_out_action, m_skip_action, m_show_pc_action,
m_set_pc_action})
{
items.emplace_back(widgetForAction(action));
}
@ -134,6 +131,24 @@ void ToolBar::MakeActions()
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()
{
m_step_action->setIcon(Resources::GetScaledThemeIcon("debugger_step_in"));
@ -144,8 +159,14 @@ void ToolBar::UpdateIcons()
m_set_pc_action->setIcon(Resources::GetScaledThemeIcon("debugger_show_pc"));
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_fullscreen_action->setIcon(Resources::GetScaledThemeIcon("fullscreen"));
m_screenshot_action->setIcon(Resources::GetScaledThemeIcon("screenshot"));

View File

@ -46,10 +46,10 @@ private:
void MakeActions();
void UpdateIcons();
void UpdatePausePlayButtonState(bool playing_state);
QAction* m_open_action;
QAction* m_play_action;
QAction* m_pause_action;
QAction* m_pause_play_action;
QAction* m_stop_action;
QAction* m_fullscreen_action;
QAction* m_screenshot_action;