configuration_shared.h 3.0 KB

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