2015-12-03 21:41:17 -07:00
|
|
|
// Copyright 2015 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2017-09-14 11:34:14 -06:00
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
|
|
|
|
2015-12-03 21:41:17 -07:00
|
|
|
#include <QIcon>
|
|
|
|
|
2017-09-04 12:12:13 -06:00
|
|
|
#include "Core/Core.h"
|
2017-09-02 15:38:02 -06:00
|
|
|
#include "DolphinQt2/QtUtils/ActionHelper.h"
|
2017-05-30 14:42:21 -06:00
|
|
|
#include "DolphinQt2/Resources.h"
|
2015-12-20 16:36:39 -07:00
|
|
|
#include "DolphinQt2/Settings.h"
|
2015-12-03 21:41:17 -07:00
|
|
|
#include "DolphinQt2/ToolBar.h"
|
|
|
|
|
2016-01-25 04:36:39 -07:00
|
|
|
static QSize ICON_SIZE(32, 32);
|
2015-12-03 21:41:17 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
ToolBar::ToolBar(QWidget* parent) : QToolBar(parent)
|
2015-12-03 21:41:17 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
2018-04-19 03:32:00 -06:00
|
|
|
setMovable(!Settings::Instance().AreWidgetsLocked());
|
2016-06-24 02:43:46 -06:00
|
|
|
setFloatable(false);
|
|
|
|
setIconSize(ICON_SIZE);
|
2015-12-03 21:41:17 -07:00
|
|
|
|
2018-04-19 03:32:00 -06:00
|
|
|
setWindowTitle(tr("Toolbar"));
|
|
|
|
setObjectName(QStringLiteral("toolbar"));
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
MakeActions();
|
2017-05-31 17:49:47 -06:00
|
|
|
connect(&Settings::Instance(), &Settings::ThemeChanged, this, &ToolBar::UpdateIcons);
|
2016-06-24 02:43:46 -06:00
|
|
|
UpdateIcons();
|
2016-02-14 18:56:40 -07:00
|
|
|
|
2017-09-04 12:12:13 -06:00
|
|
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
|
|
|
|
[this](Core::State state) { OnEmulationStateChanged(state); });
|
2018-02-14 15:25:01 -07:00
|
|
|
|
|
|
|
connect(&Settings::Instance(), &Settings::DebugModeToggled, this, &ToolBar::OnDebugModeToggled);
|
|
|
|
|
2018-04-19 03:32:00 -06:00
|
|
|
connect(&Settings::Instance(), &Settings::ToolBarVisibilityChanged, this, &ToolBar::setVisible);
|
|
|
|
|
|
|
|
connect(&Settings::Instance(), &Settings::WidgetLockChanged, this,
|
|
|
|
[this](bool locked) { setMovable(!locked); });
|
|
|
|
|
2017-09-04 12:12:13 -06:00
|
|
|
OnEmulationStateChanged(Core::GetState());
|
2018-02-14 15:25:01 -07:00
|
|
|
OnDebugModeToggled(Settings::Instance().IsDebugModeEnabled());
|
2015-12-03 21:41:17 -07:00
|
|
|
}
|
|
|
|
|
2017-09-04 12:12:13 -06:00
|
|
|
void ToolBar::OnEmulationStateChanged(Core::State state)
|
2015-12-03 21:41:17 -07:00
|
|
|
{
|
2017-09-04 12:12:13 -06:00
|
|
|
bool running = state != Core::State::Uninitialized;
|
|
|
|
m_stop_action->setEnabled(running);
|
|
|
|
m_fullscreen_action->setEnabled(running);
|
|
|
|
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);
|
2015-12-03 21:41:17 -07:00
|
|
|
}
|
|
|
|
|
2018-04-19 03:32:00 -06:00
|
|
|
void ToolBar::closeEvent(QCloseEvent*)
|
|
|
|
{
|
|
|
|
Settings::Instance().SetToolBarVisible(false);
|
|
|
|
}
|
|
|
|
|
2018-02-14 15:25:01 -07: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);
|
|
|
|
}
|
|
|
|
|
2015-12-03 21:41:17 -07:00
|
|
|
void ToolBar::MakeActions()
|
|
|
|
{
|
2018-02-14 15:25:01 -07:00
|
|
|
m_step_action = AddAction(this, tr("Step"), this, &ToolBar::StepPressed);
|
|
|
|
m_step_over_action = AddAction(this, tr("Step Over"), this, &ToolBar::StepOverPressed);
|
|
|
|
m_step_out_action = AddAction(this, tr("Step Out"), this, &ToolBar::StepOutPressed);
|
|
|
|
m_skip_action = AddAction(this, tr("Skip"), this, &ToolBar::SkipPressed);
|
|
|
|
m_show_pc_action = AddAction(this, tr("Show PC"), this, &ToolBar::ShowPCPressed);
|
|
|
|
m_set_pc_action = AddAction(this, tr("Set PC"), this, &ToolBar::SetPCPressed);
|
|
|
|
|
2017-09-02 15:38:02 -06:00
|
|
|
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_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);
|
2015-12-03 21:41:17 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
addSeparator();
|
2015-12-03 21:41:17 -07:00
|
|
|
|
2017-09-02 15:38:02 -06:00
|
|
|
m_config_action = AddAction(this, tr("Config"), this, &ToolBar::SettingsPressed);
|
|
|
|
m_graphics_action = AddAction(this, tr("Graphics"), this, &ToolBar::GraphicsPressed);
|
|
|
|
m_controllers_action = AddAction(this, tr("Controllers"), this, &ToolBar::ControllersPressed);
|
2017-05-09 10:49:10 -06:00
|
|
|
m_controllers_action->setEnabled(true);
|
2017-09-14 11:34:14 -06:00
|
|
|
|
2017-09-26 09:42:51 -06:00
|
|
|
// Ensure every button has about the same width
|
2017-09-14 11:34:14 -06:00
|
|
|
std::vector<QWidget*> items;
|
2018-02-14 15:25:01 -07:00
|
|
|
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})
|
2017-09-14 11:34:14 -06: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 14:26:03 -06:00
|
|
|
const int min_width = *std::max_element(widths.begin(), widths.end()) * 0.85;
|
2017-09-14 11:34:14 -06:00
|
|
|
for (QWidget* widget : items)
|
|
|
|
widget->setMinimumWidth(min_width);
|
2015-12-03 21:41:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToolBar::UpdateIcons()
|
|
|
|
{
|
2018-04-11 15:43:47 -06: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"));
|
|
|
|
m_show_pc_action->setIcon(Resources::GetScaledThemeIcon("debugger_set_pc"));
|
|
|
|
m_set_pc_action->setIcon(Resources::GetScaledThemeIcon("debugger_show_pc"));
|
|
|
|
|
2017-05-30 14:42:21 -06:00
|
|
|
m_open_action->setIcon(Resources::GetScaledThemeIcon("open"));
|
|
|
|
m_play_action->setIcon(Resources::GetScaledThemeIcon("play"));
|
|
|
|
m_pause_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"));
|
|
|
|
m_config_action->setIcon(Resources::GetScaledThemeIcon("config"));
|
|
|
|
m_controllers_action->setIcon(Resources::GetScaledThemeIcon("classic"));
|
2017-06-15 17:39:59 -06:00
|
|
|
m_graphics_action->setIcon(Resources::GetScaledThemeIcon("graphics"));
|
2015-12-03 21:41:17 -07:00
|
|
|
}
|