pineapple/src/yuzu/configuration/configuration_shared.h

73 lines
3 KiB
C
Raw Normal View History

2022-07-27 20:06:50 +02:00
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2020-12-28 16:15:37 +01:00
#pragma once
#include <QCheckBox>
#include <QComboBox>
2021-04-15 04:05:28 +02:00
#include "common/settings.h"
2020-12-28 16:15:37 +01:00
namespace ConfigurationShared {
constexpr int USE_GLOBAL_INDEX = 0;
constexpr int USE_GLOBAL_SEPARATOR_INDEX = 1;
constexpr int USE_GLOBAL_OFFSET = 2;
2021-05-17 02:21:13 +02:00
// CheckBoxes require a tracker for their state since we emulate a tristate CheckBox
2020-12-28 16:15:37 +01:00
enum class CheckState {
2021-05-17 02:21:13 +02:00
Off, // Checkbox overrides to off/false
On, // Checkbox overrides to on/true
Global, // Checkbox defers to the global state
Count, // Simply the number of states, not a valid checkbox state
2020-12-28 16:15:37 +01:00
};
// Global-aware apply and set functions
2021-05-17 02:21:13 +02:00
// ApplyPerGameSetting, given a Settings::Setting and a Qt UI element, properly applies a Setting
2022-07-05 04:21:48 +02:00
void ApplyPerGameSetting(Settings::SwitchableSetting<bool>* setting, const QCheckBox* checkbox,
2020-12-28 16:15:37 +01:00
const CheckState& tracker);
2022-07-17 09:10:25 +02:00
template <typename Type, bool ranged>
void ApplyPerGameSetting(Settings::SwitchableSetting<Type, ranged>* setting,
const QComboBox* combobox) {
2021-07-28 21:57:36 +02:00
if (Settings::IsConfiguringGlobal() && setting->UsingGlobal()) {
setting->SetValue(static_cast<Type>(combobox->currentIndex()));
} else if (!Settings::IsConfiguringGlobal()) {
if (combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
setting->SetGlobal(true);
} else {
setting->SetGlobal(false);
setting->SetValue(static_cast<Type>(combobox->currentIndex() -
ConfigurationShared::USE_GLOBAL_OFFSET));
}
}
}
2020-12-28 16:15:37 +01:00
2021-05-17 02:21:13 +02:00
// Sets a Qt UI element given a Settings::Setting
2022-07-05 04:21:48 +02:00
void SetPerGameSetting(QCheckBox* checkbox, const Settings::SwitchableSetting<bool>* setting);
2021-05-20 01:36:46 +02:00
2022-07-17 09:10:25 +02:00
template <typename Type, bool ranged>
void SetPerGameSetting(QComboBox* combobox,
const Settings::SwitchableSetting<Type, ranged>* setting) {
2021-05-20 01:36:46 +02:00
combobox->setCurrentIndex(setting->UsingGlobal() ? ConfigurationShared::USE_GLOBAL_INDEX
: static_cast<int>(setting->GetValue()) +
ConfigurationShared::USE_GLOBAL_OFFSET);
}
2020-12-28 16:15:37 +01:00
2021-05-17 02:21:13 +02:00
// (Un)highlights a Qt UI element
2020-12-28 16:15:37 +01:00
void SetHighlight(QWidget* widget, bool highlighted);
2021-05-17 02:21:13 +02:00
// Sets up a QCheckBox like a tristate one, given a Setting
2022-07-05 04:21:48 +02:00
void SetColoredTristate(QCheckBox* checkbox, const Settings::SwitchableSetting<bool>& setting,
2020-12-28 16:15:37 +01:00
CheckState& tracker);
void SetColoredTristate(QCheckBox* checkbox, bool global, bool state, bool global_state,
CheckState& tracker);
2021-05-17 02:21:13 +02:00
// Sets up coloring of a QWidget `target` based on the state of a QComboBox, and calls
// InsertGlobalItem
2020-12-28 16:15:37 +01:00
void SetColoredComboBox(QComboBox* combobox, QWidget* target, int global);
2021-05-17 02:21:13 +02:00
// Adds the "Use Global Configuration" selection and separator to the beginning of a QComboBox
2020-12-28 16:15:37 +01:00
void InsertGlobalItem(QComboBox* combobox, int global_index);
} // namespace ConfigurationShared