2015-12-04 04:41:17 +00:00
|
|
|
// Copyright 2015 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2017-09-14 17:34:14 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-02-25 19:59:49 +00:00
|
|
|
#include <QAction>
|
2015-12-04 04:41:17 +00:00
|
|
|
#include <QIcon>
|
|
|
|
|
2017-09-04 18:12:13 +00:00
|
|
|
#include "Core/Core.h"
|
2018-11-23 10:02:00 +00:00
|
|
|
#include "Core/NetPlayProto.h"
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Host.h"
|
|
|
|
#include "DolphinQt/Resources.h"
|
|
|
|
#include "DolphinQt/Settings.h"
|
|
|
|
#include "DolphinQt/ToolBar.h"
|
2015-12-04 04:41:17 +00:00
|
|
|
|
2016-01-25 11:36:39 +00:00
|
|
|
static QSize ICON_SIZE(32, 32);
|
2015-12-04 04:41:17 +00:00
|
|
|
|
|
|
|
ToolBar::ToolBar(QWidget* parent) : QToolBar(parent)
|
|
|
|
{
|
|
|
|
setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
2018-04-19 09:32:00 +00:00
|
|
|
setMovable(!Settings::Instance().AreWidgetsLocked());
|
2015-12-04 04:41:17 +00:00
|
|
|
setFloatable(false);
|
|
|
|
setIconSize(ICON_SIZE);
|
2018-04-28 19:27:29 +00:00
|
|
|
setVisible(Settings::Instance().IsToolBarVisible());
|
2015-12-04 04:41:17 +00:00
|
|
|
|
2018-04-19 09:32:00 +00:00
|
|
|
setWindowTitle(tr("Toolbar"));
|
|
|
|
setObjectName(QStringLiteral("toolbar"));
|
|
|
|
|
2015-12-04 04:41:17 +00:00
|
|
|
MakeActions();
|
2017-05-31 23:49:47 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::ThemeChanged, this, &ToolBar::UpdateIcons);
|
2015-12-04 04:41:17 +00:00
|
|
|
UpdateIcons();
|
2016-02-15 01:56:40 +00:00
|
|
|
|
2020-09-12 22:53:17 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
|
2017-09-04 18:12:13 +00:00
|
|
|
[this](Core::State state) { OnEmulationStateChanged(state); });
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2020-09-12 22:53:17 +00:00
|
|
|
connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this,
|
2018-05-05 22:17:06 +00:00
|
|
|
[this] { OnEmulationStateChanged(Core::GetState()); });
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::DebugModeToggled, this, &ToolBar::OnDebugModeToggled);
|
|
|
|
|
2018-04-19 09:32:00 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::ToolBarVisibilityChanged, this, &ToolBar::setVisible);
|
2018-05-19 13:50:21 +00:00
|
|
|
connect(this, &ToolBar::visibilityChanged, &Settings::Instance(), &Settings::SetToolBarVisible);
|
2018-04-19 09:32:00 +00:00
|
|
|
|
2020-09-12 22:53:17 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::WidgetLockChanged, this,
|
2018-04-19 09:32:00 +00:00
|
|
|
[this](bool locked) { setMovable(!locked); });
|
|
|
|
|
2020-09-12 22:53:17 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::GameListRefreshCompleted, this,
|
2019-10-09 21:51:49 +00:00
|
|
|
[this] { m_refresh_action->setEnabled(true); });
|
|
|
|
|
2017-09-04 18:12:13 +00:00
|
|
|
OnEmulationStateChanged(Core::GetState());
|
2018-02-14 22:25:01 +00:00
|
|
|
OnDebugModeToggled(Settings::Instance().IsDebugModeEnabled());
|
2015-12-04 04:41:17 +00:00
|
|
|
}
|
|
|
|
|
2017-09-04 18:12:13 +00:00
|
|
|
void ToolBar::OnEmulationStateChanged(Core::State state)
|
2015-12-04 04:41:17 +00:00
|
|
|
{
|
2017-09-04 18:12:13 +00:00
|
|
|
bool running = state != Core::State::Uninitialized;
|
|
|
|
m_stop_action->setEnabled(running);
|
|
|
|
m_fullscreen_action->setEnabled(running);
|
|
|
|
m_screenshot_action->setEnabled(running);
|
2018-11-23 10:02:00 +00:00
|
|
|
m_controllers_action->setEnabled(NetPlay::IsNetPlayRunning() ? !running : true);
|
2017-09-04 18:12:13 +00:00
|
|
|
|
|
|
|
bool playing = running && state != Core::State::Paused;
|
2018-05-14 20:05:23 +00:00
|
|
|
UpdatePausePlayButtonState(playing);
|
2018-05-05 22:17:06 +00:00
|
|
|
|
|
|
|
bool paused = Core::GetState() == Core::State::Paused;
|
|
|
|
m_step_action->setEnabled(paused);
|
|
|
|
m_step_over_action->setEnabled(paused);
|
|
|
|
m_step_out_action->setEnabled(paused);
|
|
|
|
m_skip_action->setEnabled(paused);
|
|
|
|
m_set_pc_action->setEnabled(paused);
|
2015-12-04 04:41:17 +00:00
|
|
|
}
|
|
|
|
|
2018-04-19 09:32:00 +00:00
|
|
|
void ToolBar::closeEvent(QCloseEvent*)
|
|
|
|
{
|
|
|
|
Settings::Instance().SetToolBarVisible(false);
|
|
|
|
}
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
void ToolBar::OnDebugModeToggled(bool enabled)
|
|
|
|
{
|
|
|
|
m_step_action->setVisible(enabled);
|
|
|
|
m_step_over_action->setVisible(enabled);
|
|
|
|
m_step_out_action->setVisible(enabled);
|
|
|
|
m_skip_action->setVisible(enabled);
|
|
|
|
m_show_pc_action->setVisible(enabled);
|
|
|
|
m_set_pc_action->setVisible(enabled);
|
2018-05-05 22:17:06 +00:00
|
|
|
|
|
|
|
bool paused = Core::GetState() == Core::State::Paused;
|
|
|
|
m_step_action->setEnabled(paused);
|
|
|
|
m_step_over_action->setEnabled(paused);
|
|
|
|
m_step_out_action->setEnabled(paused);
|
|
|
|
m_skip_action->setEnabled(paused);
|
|
|
|
m_set_pc_action->setEnabled(paused);
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
2015-12-04 04:41:17 +00:00
|
|
|
void ToolBar::MakeActions()
|
|
|
|
{
|
2018-09-08 13:58:15 +00:00
|
|
|
// i18n: Here, "Step" is a verb. This feature is used for
|
|
|
|
// going through code step by step.
|
2018-07-09 08:02:10 +00:00
|
|
|
m_step_action = addAction(tr("Step"), this, &ToolBar::StepPressed);
|
2018-09-08 13:58:15 +00:00
|
|
|
// i18n: Here, "Step" is a verb. This feature is used for
|
|
|
|
// going through code step by step.
|
2018-07-09 08:02:10 +00:00
|
|
|
m_step_over_action = addAction(tr("Step Over"), this, &ToolBar::StepOverPressed);
|
2018-09-08 13:58:15 +00:00
|
|
|
// i18n: Here, "Step" is a verb. This feature is used for
|
|
|
|
// going through code step by step.
|
2018-07-09 08:02:10 +00:00
|
|
|
m_step_out_action = addAction(tr("Step Out"), this, &ToolBar::StepOutPressed);
|
|
|
|
m_skip_action = addAction(tr("Skip"), this, &ToolBar::SkipPressed);
|
2018-09-08 13:58:15 +00:00
|
|
|
// i18n: Here, PC is an acronym for program counter, not personal computer.
|
2018-07-09 08:02:10 +00:00
|
|
|
m_show_pc_action = addAction(tr("Show PC"), this, &ToolBar::ShowPCPressed);
|
2018-09-08 13:58:15 +00:00
|
|
|
// i18n: Here, PC is an acronym for program counter, not personal computer.
|
2018-07-09 08:02:10 +00:00
|
|
|
m_set_pc_action = addAction(tr("Set PC"), this, &ToolBar::SetPCPressed);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2018-07-09 08:02:10 +00:00
|
|
|
m_open_action = addAction(tr("Open"), this, &ToolBar::OpenPressed);
|
2019-10-09 21:51:49 +00:00
|
|
|
m_refresh_action = addAction(tr("Refresh"), [this] {
|
|
|
|
m_refresh_action->setEnabled(false);
|
|
|
|
emit RefreshPressed();
|
|
|
|
});
|
2018-06-04 19:44:46 +00:00
|
|
|
|
|
|
|
addSeparator();
|
|
|
|
|
2018-07-09 08:02:10 +00:00
|
|
|
m_pause_play_action = addAction(tr("Play"), this, &ToolBar::PlayPressed);
|
2018-05-14 20:05:23 +00:00
|
|
|
|
2018-07-09 08:02:10 +00:00
|
|
|
m_stop_action = addAction(tr("Stop"), this, &ToolBar::StopPressed);
|
|
|
|
m_fullscreen_action = addAction(tr("FullScr"), this, &ToolBar::FullScreenPressed);
|
|
|
|
m_screenshot_action = addAction(tr("ScrShot"), this, &ToolBar::ScreenShotPressed);
|
2015-12-04 04:41:17 +00:00
|
|
|
|
|
|
|
addSeparator();
|
|
|
|
|
2018-07-09 08:02:10 +00:00
|
|
|
m_config_action = addAction(tr("Config"), this, &ToolBar::SettingsPressed);
|
|
|
|
m_graphics_action = addAction(tr("Graphics"), this, &ToolBar::GraphicsPressed);
|
|
|
|
m_controllers_action = addAction(tr("Controllers"), this, &ToolBar::ControllersPressed);
|
2017-05-09 16:49:10 +00:00
|
|
|
m_controllers_action->setEnabled(true);
|
2017-09-14 17:34:14 +00:00
|
|
|
|
2017-09-26 15:42:51 +00:00
|
|
|
// Ensure every button has about the same width
|
2017-09-14 17:34:14 +00:00
|
|
|
std::vector<QWidget*> items;
|
2018-02-14 22:25:01 +00:00
|
|
|
for (const auto& action :
|
2018-05-14 20:05:23 +00:00
|
|
|
{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})
|
2017-09-14 17:34:14 +00:00
|
|
|
{
|
|
|
|
items.emplace_back(widgetForAction(action));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<int> widths;
|
|
|
|
std::transform(items.begin(), items.end(), std::back_inserter(widths),
|
|
|
|
[](QWidget* item) { return item->sizeHint().width(); });
|
|
|
|
|
2017-09-19 20:26:03 +00:00
|
|
|
const int min_width = *std::max_element(widths.begin(), widths.end()) * 0.85;
|
2017-09-14 17:34:14 +00:00
|
|
|
for (QWidget* widget : items)
|
|
|
|
widget->setMinimumWidth(min_width);
|
2015-12-04 04:41:17 +00:00
|
|
|
}
|
|
|
|
|
2018-05-14 20:05:23 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-04 04:41:17 +00:00
|
|
|
void ToolBar::UpdateIcons()
|
|
|
|
{
|
2018-04-11 21:43:47 +00:00
|
|
|
m_step_action->setIcon(Resources::GetScaledThemeIcon("debugger_step_in"));
|
|
|
|
m_step_over_action->setIcon(Resources::GetScaledThemeIcon("debugger_step_over"));
|
|
|
|
m_step_out_action->setIcon(Resources::GetScaledThemeIcon("debugger_step_out"));
|
|
|
|
m_skip_action->setIcon(Resources::GetScaledThemeIcon("debugger_skip"));
|
2018-10-09 01:09:13 +00:00
|
|
|
m_show_pc_action->setIcon(Resources::GetScaledThemeIcon("debugger_show_pc"));
|
|
|
|
m_set_pc_action->setIcon(Resources::GetScaledThemeIcon("debugger_set_pc"));
|
2018-04-11 21:43:47 +00:00
|
|
|
|
2017-05-30 20:42:21 +00:00
|
|
|
m_open_action->setIcon(Resources::GetScaledThemeIcon("open"));
|
2018-06-04 19:44:46 +00:00
|
|
|
m_refresh_action->setIcon(Resources::GetScaledThemeIcon("refresh"));
|
2018-05-14 20:05:23 +00:00
|
|
|
|
|
|
|
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"));
|
|
|
|
|
2017-05-30 20:42:21 +00:00
|
|
|
m_stop_action->setIcon(Resources::GetScaledThemeIcon("stop"));
|
|
|
|
m_fullscreen_action->setIcon(Resources::GetScaledThemeIcon("fullscreen"));
|
|
|
|
m_screenshot_action->setIcon(Resources::GetScaledThemeIcon("screenshot"));
|
|
|
|
m_config_action->setIcon(Resources::GetScaledThemeIcon("config"));
|
|
|
|
m_controllers_action->setIcon(Resources::GetScaledThemeIcon("classic"));
|
2017-06-15 23:39:59 +00:00
|
|
|
m_graphics_action->setIcon(Resources::GetScaledThemeIcon("graphics"));
|
2015-12-04 04:41:17 +00:00
|
|
|
}
|