pineapple-src/src/yuzu/configuration/configuration_shared.h

60 lines
2.4 KiB
C
Raw Normal View History

2020-12-28 16:15:37 +01:00
// Copyright 2016 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <QCheckBox>
#include <QComboBox>
#include <QString>
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
2020-12-28 16:15:37 +01:00
void ApplyPerGameSetting(Settings::Setting<bool>* setting, const QCheckBox* checkbox,
const CheckState& tracker);
void ApplyPerGameSetting(Settings::Setting<int>* setting, const QComboBox* combobox);
2021-05-17 02:21:13 +02:00
// Sets a Qt UI element given a Settings::Setting
2020-12-28 16:15:37 +01:00
void SetPerGameSetting(QCheckBox* checkbox, const Settings::Setting<bool>* setting);
2021-05-20 01:36:46 +02:00
template <typename Type>
void SetPerGameSetting(QComboBox* combobox, const Settings::Setting<Type>* setting) {
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
2020-12-28 16:15:37 +01:00
void SetColoredTristate(QCheckBox* checkbox, const Settings::Setting<bool>& setting,
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