configuration_shared.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-FileCopyrightText: 2016 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <QCheckBox>
  5. #include <QComboBox>
  6. #include "common/settings.h"
  7. namespace ConfigurationShared {
  8. constexpr int USE_GLOBAL_INDEX = 0;
  9. constexpr int USE_GLOBAL_SEPARATOR_INDEX = 1;
  10. constexpr int USE_GLOBAL_OFFSET = 2;
  11. // CheckBoxes require a tracker for their state since we emulate a tristate CheckBox
  12. enum class CheckState {
  13. Off, // Checkbox overrides to off/false
  14. On, // Checkbox overrides to on/true
  15. Global, // Checkbox defers to the global state
  16. Count, // Simply the number of states, not a valid checkbox state
  17. };
  18. // Global-aware apply and set functions
  19. // ApplyPerGameSetting, given a Settings::Setting and a Qt UI element, properly applies a Setting
  20. void ApplyPerGameSetting(Settings::SwitchableSetting<bool>* setting, const QCheckBox* checkbox,
  21. const CheckState& tracker);
  22. template <typename Type, bool ranged>
  23. void ApplyPerGameSetting(Settings::SwitchableSetting<Type, ranged>* setting,
  24. const QComboBox* combobox) {
  25. if (Settings::IsConfiguringGlobal() && setting->UsingGlobal()) {
  26. setting->SetValue(static_cast<Type>(combobox->currentIndex()));
  27. } else if (!Settings::IsConfiguringGlobal()) {
  28. if (combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  29. setting->SetGlobal(true);
  30. } else {
  31. setting->SetGlobal(false);
  32. setting->SetValue(static_cast<Type>(combobox->currentIndex() -
  33. ConfigurationShared::USE_GLOBAL_OFFSET));
  34. }
  35. }
  36. }
  37. // Sets a Qt UI element given a Settings::Setting
  38. void SetPerGameSetting(QCheckBox* checkbox, const Settings::SwitchableSetting<bool>* setting);
  39. template <typename Type, bool ranged>
  40. void SetPerGameSetting(QComboBox* combobox,
  41. const Settings::SwitchableSetting<Type, ranged>* setting) {
  42. combobox->setCurrentIndex(setting->UsingGlobal() ? ConfigurationShared::USE_GLOBAL_INDEX
  43. : static_cast<int>(setting->GetValue()) +
  44. ConfigurationShared::USE_GLOBAL_OFFSET);
  45. }
  46. // (Un)highlights a Qt UI element
  47. void SetHighlight(QWidget* widget, bool highlighted);
  48. // Sets up a QCheckBox like a tristate one, given a Setting
  49. void SetColoredTristate(QCheckBox* checkbox, const Settings::SwitchableSetting<bool>& setting,
  50. CheckState& tracker);
  51. void SetColoredTristate(QCheckBox* checkbox, bool global, bool state, bool global_state,
  52. CheckState& tracker);
  53. // Sets up coloring of a QWidget `target` based on the state of a QComboBox, and calls
  54. // InsertGlobalItem
  55. void SetColoredComboBox(QComboBox* combobox, QWidget* target, int global);
  56. // Adds the "Use Global Configuration" selection and separator to the beginning of a QComboBox
  57. void InsertGlobalItem(QComboBox* combobox, int global_index);
  58. // Returns the correct index of a QComboBox taking into account global configuration
  59. int GetComboboxIndex(int global_setting_index, const QComboBox* combobox);
  60. } // namespace ConfigurationShared