summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/configuration/configuration_shared.cpp75
-rw-r--r--src/yuzu/configuration/configuration_shared.h69
2 files changed, 0 insertions, 144 deletions
diff --git a/src/yuzu/configuration/configuration_shared.cpp b/src/yuzu/configuration/configuration_shared.cpp
index dff70f04b..624d9ba1b 100644
--- a/src/yuzu/configuration/configuration_shared.cpp
+++ b/src/yuzu/configuration/configuration_shared.cpp
@@ -38,78 +38,3 @@ Tab::Tab(std::shared_ptr<std::forward_list<Tab*>> group_, QWidget* parent)
38Tab::~Tab() = default; 38Tab::~Tab() = default;
39 39
40} // namespace ConfigurationShared 40} // namespace ConfigurationShared
41
42void ConfigurationShared::ApplyPerGameSetting(Settings::SwitchableSetting<bool>* setting,
43 const QCheckBox* checkbox,
44 const CheckState& tracker) {
45 if (Settings::IsConfiguringGlobal() && setting->UsingGlobal()) {
46 setting->SetValue(checkbox->checkState());
47 } else if (!Settings::IsConfiguringGlobal()) {
48 if (tracker == CheckState::Global) {
49 setting->SetGlobal(true);
50 } else {
51 setting->SetGlobal(false);
52 setting->SetValue(checkbox->checkState());
53 }
54 }
55}
56
57void ConfigurationShared::SetPerGameSetting(QCheckBox* checkbox,
58 const Settings::SwitchableSetting<bool>* setting) {
59 if (setting->UsingGlobal()) {
60 checkbox->setCheckState(Qt::PartiallyChecked);
61 } else {
62 checkbox->setCheckState(setting->GetValue() ? Qt::Checked : Qt::Unchecked);
63 }
64}
65
66void ConfigurationShared::SetHighlight(QWidget* widget, bool highlighted) {
67 if (highlighted) {
68 widget->setStyleSheet(QStringLiteral("QWidget#%1 { background-color:rgba(0,203,255,0.5) }")
69 .arg(widget->objectName()));
70 } else {
71 widget->setStyleSheet(QStringLiteral(""));
72 }
73 widget->show();
74}
75
76void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox, bool global, bool state,
77 bool global_state, CheckState& tracker) {
78 if (global) {
79 tracker = CheckState::Global;
80 } else {
81 tracker = (state == global_state) ? CheckState::On : CheckState::Off;
82 }
83 SetHighlight(checkbox, tracker != CheckState::Global);
84 QObject::connect(checkbox, &QCheckBox::clicked, checkbox, [checkbox, global_state, &tracker] {
85 tracker = static_cast<CheckState>((static_cast<int>(tracker) + 1) %
86 static_cast<int>(CheckState::Count));
87 if (tracker == CheckState::Global) {
88 checkbox->setChecked(global_state);
89 }
90 SetHighlight(checkbox, tracker != CheckState::Global);
91 });
92}
93
94void ConfigurationShared::SetColoredComboBox(QComboBox* combobox, QWidget* target, int global) {
95 InsertGlobalItem(combobox, global);
96 QObject::connect(combobox, qOverload<int>(&QComboBox::activated), target,
97 [target](int index) { SetHighlight(target, index != 0); });
98}
99
100void ConfigurationShared::InsertGlobalItem(QComboBox* combobox, int global_index) {
101 const QString use_global_text =
102 ConfigurePerGame::tr("Use global configuration (%1)").arg(combobox->itemText(global_index));
103 combobox->insertItem(ConfigurationShared::USE_GLOBAL_INDEX, use_global_text);
104 combobox->insertSeparator(ConfigurationShared::USE_GLOBAL_SEPARATOR_INDEX);
105}
106
107int ConfigurationShared::GetComboboxIndex(int global_setting_index, const QComboBox* combobox) {
108 if (Settings::IsConfiguringGlobal()) {
109 return combobox->currentIndex();
110 }
111 if (combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
112 return global_setting_index;
113 }
114 return combobox->currentIndex() - ConfigurationShared::USE_GLOBAL_OFFSET;
115}
diff --git a/src/yuzu/configuration/configuration_shared.h b/src/yuzu/configuration/configuration_shared.h
index 83a0dd574..046d78e2b 100644
--- a/src/yuzu/configuration/configuration_shared.h
+++ b/src/yuzu/configuration/configuration_shared.h
@@ -41,73 +41,4 @@ enum class CheckState {
41 Count, // Simply the number of states, not a valid checkbox state 41 Count, // Simply the number of states, not a valid checkbox state
42}; 42};
43 43
44// Global-aware apply and set functions
45
46// ApplyPerGameSetting, given a Settings::Setting and a Qt UI element, properly applies a Setting
47void ApplyPerGameSetting(Settings::SwitchableSetting<bool>* setting, const QCheckBox* checkbox,
48 const CheckState& tracker);
49template <typename Type, bool ranged>
50void ApplyPerGameSetting(Settings::SwitchableSetting<Type, ranged>* setting,
51 const QComboBox* combobox) {
52 if (Settings::IsConfiguringGlobal() && setting->UsingGlobal()) {
53 setting->SetValue(static_cast<Type>(combobox->currentIndex()));
54 } else if (!Settings::IsConfiguringGlobal()) {
55 if (combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
56 setting->SetGlobal(true);
57 } else {
58 setting->SetGlobal(false);
59 setting->SetValue(static_cast<Type>(combobox->currentIndex() -
60 ConfigurationShared::USE_GLOBAL_OFFSET));
61 }
62 }
63}
64
65// Sets a Qt UI element given a Settings::Setting
66void SetPerGameSetting(QCheckBox* checkbox, const Settings::SwitchableSetting<bool>* setting);
67
68template <typename Type, bool ranged>
69void SetPerGameSetting(QComboBox* combobox,
70 const Settings::SwitchableSetting<Type, ranged>* setting) {
71 combobox->setCurrentIndex(setting->UsingGlobal() ? ConfigurationShared::USE_GLOBAL_INDEX
72 : static_cast<int>(setting->GetValue()) +
73 ConfigurationShared::USE_GLOBAL_OFFSET);
74}
75
76// (Un)highlights a Qt UI element
77void SetHighlight(QWidget* widget, bool highlighted);
78
79// Sets up a QCheckBox like a tristate one, given a Setting
80template <bool ranged>
81void SetColoredTristate(QCheckBox* checkbox,
82 const Settings::SwitchableSetting<bool, ranged>& setting,
83 CheckState& tracker) {
84 if (setting.UsingGlobal()) {
85 tracker = CheckState::Global;
86 } else {
87 tracker = (setting.GetValue() == setting.GetValue(true)) ? CheckState::On : CheckState::Off;
88 }
89 SetHighlight(checkbox, tracker != CheckState::Global);
90 QObject::connect(checkbox, &QCheckBox::clicked, checkbox, [checkbox, setting, &tracker] {
91 tracker = static_cast<CheckState>((static_cast<int>(tracker) + 1) %
92 static_cast<int>(CheckState::Count));
93 if (tracker == CheckState::Global) {
94 checkbox->setChecked(setting.GetValue(true));
95 }
96 SetHighlight(checkbox, tracker != CheckState::Global);
97 });
98}
99
100void SetColoredTristate(QCheckBox* checkbox, bool global, bool state, bool global_state,
101 CheckState& tracker);
102
103// Sets up coloring of a QWidget `target` based on the state of a QComboBox, and calls
104// InsertGlobalItem
105void SetColoredComboBox(QComboBox* combobox, QWidget* target, int global);
106
107// Adds the "Use Global Configuration" selection and separator to the beginning of a QComboBox
108void InsertGlobalItem(QComboBox* combobox, int global_index);
109
110// Returns the correct index of a QComboBox taking into account global configuration
111int GetComboboxIndex(int global_setting_index, const QComboBox* combobox);
112
113} // namespace ConfigurationShared 44} // namespace ConfigurationShared