configuration_shared.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 <QString>
  8. #include "common/settings.h"
  9. namespace ConfigurationShared {
  10. constexpr int USE_GLOBAL_INDEX = 0;
  11. constexpr int USE_GLOBAL_SEPARATOR_INDEX = 1;
  12. constexpr int USE_GLOBAL_OFFSET = 2;
  13. // CheckBoxes require a tracker for their state since we emulate a tristate CheckBox
  14. enum class CheckState {
  15. Off, // Checkbox overrides to off/false
  16. On, // Checkbox overrides to on/true
  17. Global, // Checkbox defers to the global state
  18. Count, // Simply the number of states, not a valid checkbox state
  19. };
  20. // Global-aware apply and set functions
  21. // ApplyPerGameSetting, given a Settings::Setting and a Qt UI element, properly applies a Setting
  22. void ApplyPerGameSetting(Settings::Setting<bool>* setting, const QCheckBox* checkbox,
  23. const CheckState& tracker);
  24. template <typename Type>
  25. void ApplyPerGameSetting(Settings::Setting<Type>* setting, 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::Setting<bool>* setting);
  40. template <typename Type>
  41. void SetPerGameSetting(QComboBox* combobox, const Settings::Setting<Type>* 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::Setting<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. } // namespace ConfigurationShared