From 8687f6aae7928d4fc2268c1c0251f051503612af Mon Sep 17 00:00:00 2001
From: spycrab <spycrab@users.noreply.github.com>
Date: Sat, 26 Aug 2017 20:55:16 +0200
Subject: [PATCH] Qt: Implement CheatWarningWidget

---
 .../DolphinQt2/Config/CheatWarningWidget.cpp  | 79 +++++++++++++++++++
 .../DolphinQt2/Config/CheatWarningWidget.h    | 37 +++++++++
 2 files changed, 116 insertions(+)
 create mode 100644 Source/Core/DolphinQt2/Config/CheatWarningWidget.cpp
 create mode 100644 Source/Core/DolphinQt2/Config/CheatWarningWidget.h

diff --git a/Source/Core/DolphinQt2/Config/CheatWarningWidget.cpp b/Source/Core/DolphinQt2/Config/CheatWarningWidget.cpp
new file mode 100644
index 0000000000..c47bb93bd4
--- /dev/null
+++ b/Source/Core/DolphinQt2/Config/CheatWarningWidget.cpp
@@ -0,0 +1,79 @@
+// 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 <QMessageBox>
+#include <QPixmap>
+#include <QPushButton>
+#include <QStyle>
+#include <QTimer>
+
+#include "Core/ConfigManager.h"
+#include "Core/Core.h"
+
+CheatWarningWidget::CheatWarningWidget(const std::string& game_id) : m_game_id(game_id)
+{
+  CreateWidgets();
+  ConnectWidgets();
+
+  setHidden(true);
+
+  connect(this, &CheatWarningWidget::CheatEnableToggled, this,
+          &CheatWarningWidget::CheatEnableToggled);
+  connect(this, &CheatWarningWidget::EmulationStarted, this,
+          &CheatWarningWidget::CheatEnableToggled);
+  connect(this, &CheatWarningWidget::EmulationStopped, this,
+          &CheatWarningWidget::CheatEnableToggled);
+}
+
+void CheatWarningWidget::CreateWidgets()
+{
+  auto* icon = new QLabel;
+
+  QPixmap warning_icon = style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(24, 24);
+
+  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);
+  layout->addWidget(m_text);
+  layout->addWidget(m_config_button);
+
+  setLayout(layout);
+}
+
+void CheatWarningWidget::Update()
+{
+  bool cheats_enabled = SConfig::GetInstance().bEnableCheats;
+
+  bool hide = true;
+
+  if (Core::IsRunning() && SConfig::GetInstance().GetGameID() == m_game_id)
+  {
+    hide = false;
+    m_text->setText(tr("Changing cheats will only take effect when the game is restarted."));
+  }
+
+  if (!cheats_enabled)
+  {
+    hide = false;
+    m_text->setText(tr("Dolphin's cheat system is currently disabled."));
+  }
+
+  m_config_button->setHidden(hide);
+}
+
+void CheatWarningWidget::ConnectWidgets()
+{
+  connect(m_config_button, &QPushButton::pressed, [this] { emit OpenCheatEnableSettings(); });
+}
diff --git a/Source/Core/DolphinQt2/Config/CheatWarningWidget.h b/Source/Core/DolphinQt2/Config/CheatWarningWidget.h
new file mode 100644
index 0000000000..77f8506824
--- /dev/null
+++ b/Source/Core/DolphinQt2/Config/CheatWarningWidget.h
@@ -0,0 +1,37 @@
+// Copyright 2017 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <QWidget>
+
+#include <string>
+
+class QLabel;
+class QPushButton;
+class QTimer;
+
+class CheatWarningWidget : public QWidget
+{
+  Q_OBJECT
+public:
+  explicit CheatWarningWidget(const std::string& game_id);
+
+signals:
+  void OpenCheatEnableSettings();
+  void CheatEnableToggled();
+  void EmulationStarted();
+  void EmulationStopped();
+
+private:
+  const std::string& m_game_id;
+
+  void CreateWidgets();
+  void ConnectWidgets();
+
+  void Update();
+
+  QLabel* m_text;
+  QPushButton* m_config_button;
+};