dolphin/Source/Core/DolphinQt/Config/CheatWarningWidget.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
2.2 KiB
C++
Raw Normal View History

2017-08-26 12:55:16 -06:00
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
2018-07-06 16:40:15 -06:00
#include "DolphinQt/Config/CheatWarningWidget.h"
2017-08-26 12:55:16 -06:00
#include <QHBoxLayout>
#include <QLabel>
#include <QPixmap>
#include <QPushButton>
#include <QStyle>
#include "Core/ConfigManager.h"
#include "Core/Core.h"
2018-05-27 19:48:04 -06:00
2018-07-06 16:40:15 -06:00
#include "DolphinQt/Settings.h"
2017-08-26 12:55:16 -06:00
CheatWarningWidget::CheatWarningWidget(const std::string& game_id, bool restart_required,
QWidget* parent)
: QWidget(parent), m_game_id(game_id), m_restart_required(restart_required)
2017-08-26 12:55:16 -06:00
{
CreateWidgets();
ConnectWidgets();
2018-03-25 20:17:47 -06:00
connect(&Settings::Instance(), &Settings::EnableCheatsChanged, this,
2017-08-30 13:00:59 -06:00
[this] { Update(Core::IsRunning()); });
2018-03-25 20:17:47 -06:00
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
[this](Core::State state) { Update(state == Core::State::Running); });
2017-08-26 12:55:16 -06:00
2017-08-30 13:00:59 -06:00
Update(Core::IsRunning());
2017-08-26 12:55:16 -06:00
}
void CheatWarningWidget::CreateWidgets()
{
auto* icon = new QLabel;
2017-08-30 13:00:59 -06:00
const auto size = 1.5 * QFontMetrics(font()).height();
QPixmap warning_icon = style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(size, size);
2017-08-26 12:55:16 -06:00
icon->setPixmap(warning_icon);
m_text = new QLabel();
m_config_button = new QPushButton(tr("Configure Dolphin"));
m_config_button->setHidden(true);
auto* layout = new QHBoxLayout;
layout->addWidget(icon);
2017-08-30 13:00:59 -06:00
layout->addWidget(m_text, 1);
2017-08-26 12:55:16 -06:00
layout->addWidget(m_config_button);
2017-08-30 13:00:59 -06:00
layout->setContentsMargins(0, 0, 0, 0);
2017-08-26 12:55:16 -06:00
setLayout(layout);
}
2017-08-30 13:00:59 -06:00
void CheatWarningWidget::Update(bool running)
2017-08-26 12:55:16 -06:00
{
2017-08-30 13:00:59 -06:00
bool hide_widget = true;
bool hide_config_button = true;
2017-08-26 12:55:16 -06:00
2018-03-25 20:17:47 -06:00
if (running && SConfig::GetInstance().GetGameID() == m_game_id && m_restart_required)
2017-08-26 12:55:16 -06:00
{
2017-08-30 13:00:59 -06:00
hide_widget = false;
2017-08-26 12:55:16 -06:00
m_text->setText(tr("Changing cheats will only take effect when the game is restarted."));
}
2017-08-30 13:00:59 -06:00
if (!Settings::Instance().GetCheatsEnabled())
2017-08-26 12:55:16 -06:00
{
2017-08-30 13:00:59 -06:00
hide_widget = false;
hide_config_button = false;
2017-08-26 12:55:16 -06:00
m_text->setText(tr("Dolphin's cheat system is currently disabled."));
}
2017-08-30 13:00:59 -06:00
setHidden(hide_widget);
m_config_button->setHidden(hide_config_button);
2017-08-26 12:55:16 -06:00
}
void CheatWarningWidget::ConnectWidgets()
{
connect(m_config_button, &QPushButton::clicked, this,
2017-08-30 13:00:59 -06:00
&CheatWarningWidget::OpenCheatEnableSettings);
2017-08-26 12:55:16 -06:00
}