configuration_shared.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. void ApplyPerGameSetting(Settings::Setting<int>* setting, const QComboBox* combobox);
  25. // Sets a Qt UI element given a Settings::Setting
  26. void SetPerGameSetting(QCheckBox* checkbox, const Settings::Setting<bool>* setting);
  27. template <typename Type>
  28. void SetPerGameSetting(QComboBox* combobox, const Settings::Setting<Type>* setting) {
  29. combobox->setCurrentIndex(setting->UsingGlobal() ? ConfigurationShared::USE_GLOBAL_INDEX
  30. : static_cast<int>(setting->GetValue()) +
  31. ConfigurationShared::USE_GLOBAL_OFFSET);
  32. }
  33. // (Un)highlights a Qt UI element
  34. void SetHighlight(QWidget* widget, bool highlighted);
  35. // Sets up a QCheckBox like a tristate one, given a Setting
  36. void SetColoredTristate(QCheckBox* checkbox, const Settings::Setting<bool>& setting,
  37. CheckState& tracker);
  38. void SetColoredTristate(QCheckBox* checkbox, bool global, bool state, bool global_state,
  39. CheckState& tracker);
  40. // Sets up coloring of a QWidget `target` based on the state of a QComboBox, and calls
  41. // InsertGlobalItem
  42. void SetColoredComboBox(QComboBox* combobox, QWidget* target, int global);
  43. // Adds the "Use Global Configuration" selection and separator to the beginning of a QComboBox
  44. void InsertGlobalItem(QComboBox* combobox, int global_index);
  45. } // namespace ConfigurationShared