summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorrlnilsen <47765059+rlnilsen@users.noreply.github.com>2019-10-30 02:05:42 +0100
committerrlnilsen <47765059+rlnilsen@users.noreply.github.com>2019-11-03 11:55:52 +0100
commitd67a2304b0f542e21f680265da80efef3e0a83d9 (patch)
treea97c8321b7400495bef8c0911d9a3a6b8b939dae /Source/Core
parent49d9c63908e772670d05b9913a0f06209696b443 (diff)
Input: Add optional "enable" setting to the ControlGroup class.
The setting is exposed as a check box in the QGroupBox instance that visualises the ControlGroup instance. The setting is saved under "[control group name]/Enabled", but only when it is "false". The default value is "true".
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/DolphinQt/Config/Mapping/MappingWidget.cpp24
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp18
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h14
3 files changed, 50 insertions, 6 deletions
diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingWidget.cpp b/Source/Core/DolphinQt/Config/Mapping/MappingWidget.cpp
index b9149027ea..0268fe908e 100644
--- a/Source/Core/DolphinQt/Config/Mapping/MappingWidget.cpp
+++ b/Source/Core/DolphinQt/Config/Mapping/MappingWidget.cpp
@@ -4,8 +4,10 @@
#include "DolphinQt/Config/Mapping/MappingWidget.h"
+#include <QCheckBox>
#include <QFormLayout>
#include <QGroupBox>
+#include <QLabel>
#include <QPushButton>
#include <QTimer>
@@ -138,6 +140,28 @@ QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::Con
form_layout->addRow(tr(setting->GetUIName()), setting_widget);
}
+ if (group->can_be_disabled)
+ {
+ QLabel* group_enable_label = new QLabel(tr("Enable"));
+ QCheckBox* group_enable_checkbox = new QCheckBox();
+ group_enable_checkbox->setChecked(group->enabled);
+ form_layout->insertRow(0, group_enable_label, group_enable_checkbox);
+ auto enable_group_by_checkbox = [group, form_layout, group_enable_label,
+ group_enable_checkbox] {
+ group->enabled = group_enable_checkbox->isChecked();
+ for (int i = 0; i < form_layout->count(); ++i)
+ {
+ QWidget* widget = form_layout->itemAt(i)->widget();
+ if (widget != nullptr && widget != group_enable_label && widget != group_enable_checkbox)
+ widget->setEnabled(group->enabled);
+ }
+ };
+ enable_group_by_checkbox();
+ connect(group_enable_checkbox, &QCheckBox::toggled, this, enable_group_by_checkbox);
+ connect(this, &MappingWidget::ConfigChanged, this,
+ [group_enable_checkbox, group] { group_enable_checkbox->setChecked(group->enabled); });
+ }
+
return group_box;
}
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp
index 09370a1f0b..40ccae24f7 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp
@@ -15,13 +15,16 @@
namespace ControllerEmu
{
-ControlGroup::ControlGroup(std::string name_, const GroupType type_)
- : name(name_), ui_name(std::move(name_)), type(type_)
+ControlGroup::ControlGroup(std::string name_, const GroupType type_, CanBeDisabled can_be_disabled_)
+ : name(name_), ui_name(std::move(name_)), type(type_),
+ can_be_disabled(can_be_disabled_ == CanBeDisabled::Yes)
{
}
-ControlGroup::ControlGroup(std::string name_, std::string ui_name_, const GroupType type_)
- : name(std::move(name_)), ui_name(std::move(ui_name_)), type(type_)
+ControlGroup::ControlGroup(std::string name_, std::string ui_name_, const GroupType type_,
+ CanBeDisabled can_be_disabled_)
+ : name(std::move(name_)), ui_name(std::move(ui_name_)), type(type_),
+ can_be_disabled(can_be_disabled_ == CanBeDisabled::Yes)
{
}
@@ -43,6 +46,10 @@ void ControlGroup::LoadConfig(IniFile::Section* sec, const std::string& defdev,
{
const std::string group(base + name + "/");
+ // enabled
+ if (can_be_disabled)
+ sec->Get(group + "Enabled", &enabled, true);
+
for (auto& setting : numeric_settings)
setting->LoadFromIni(*sec, group);
@@ -88,6 +95,9 @@ void ControlGroup::SaveConfig(IniFile::Section* sec, const std::string& defdev,
{
const std::string group(base + name + "/");
+ // enabled
+ sec->Set(group + "Enabled", enabled, true);
+
for (auto& setting : numeric_settings)
setting->SaveToIni(*sec, group);
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h
index 310df90e30..26b3ce5ad6 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h
@@ -48,8 +48,16 @@ enum class GroupType
class ControlGroup
{
public:
- explicit ControlGroup(std::string name, GroupType type = GroupType::Other);
- ControlGroup(std::string name, std::string ui_name, GroupType type = GroupType::Other);
+ enum class CanBeDisabled
+ {
+ No,
+ Yes,
+ };
+
+ explicit ControlGroup(std::string name, GroupType type = GroupType::Other,
+ CanBeDisabled can_be_disabled = CanBeDisabled::No);
+ ControlGroup(std::string name, std::string ui_name, GroupType type = GroupType::Other,
+ CanBeDisabled can_be_disabled = CanBeDisabled::No);
virtual ~ControlGroup();
virtual void LoadConfig(IniFile::Section* sec, const std::string& defdev = "",
@@ -79,7 +87,9 @@ public:
const std::string name;
const std::string ui_name;
const GroupType type;
+ const bool can_be_disabled;
+ bool enabled = true;
std::vector<std::unique_ptr<Control>> controls;
std::vector<std::unique_ptr<NumericSettingBase>> numeric_settings;
};