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

87 lines
2.1 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.
#include "DolphinQt2/Config/CheatWarningWidget.h"
#include <QHBoxLayout>
#include <QLabel>
#include <QPixmap>
#include <QPushButton>
#include <QStyle>
#include <iostream>
2017-08-26 12:55:16 -06:00
#include "Core/ConfigManager.h"
#include "Core/Core.h"
2017-08-30 13:00:59 -06:00
#include "DolphinQt2/Settings.h"
2017-08-26 12:55:16 -06:00
CheatWarningWidget::CheatWarningWidget(const std::string& game_id) : m_game_id(game_id)
{
CreateWidgets();
ConnectWidgets();
2017-08-30 13:00:59 -06:00
connect(&Settings::Instance(), &Settings::EnableCheatsChanged,
[this] { Update(Core::IsRunning()); });
connect(&Settings::Instance(), &Settings::EmulationStateChanged, [this](Core::State state) {
std::cout << (state == Core::State::Running) << std::endl;
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
2017-08-30 13:00:59 -06:00
if (running && SConfig::GetInstance().GetGameID() == m_game_id)
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()
{
2017-08-30 13:00:59 -06:00
connect(m_config_button, &QPushButton::pressed, this,
&CheatWarningWidget::OpenCheatEnableSettings);
2017-08-26 12:55:16 -06:00
}