configuration_shared.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright 2016 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <QCheckBox>
  5. #include <QComboBox>
  6. #include <QObject>
  7. #include "core/settings.h"
  8. #include "yuzu/configuration/configuration_shared.h"
  9. #include "yuzu/configuration/configure_per_game.h"
  10. namespace ConfigurationShared {
  11. Trackers trackers = {};
  12. }
  13. void ConfigurationShared::ApplyPerGameSetting(Settings::Setting<bool>* setting,
  14. const QCheckBox* checkbox) {
  15. if (checkbox->checkState() == Qt::PartiallyChecked) {
  16. setting->SetGlobal(true);
  17. } else {
  18. setting->SetGlobal(false);
  19. setting->SetValue(checkbox->checkState() == Qt::Checked);
  20. }
  21. }
  22. void ConfigurationShared::ApplyPerGameSetting(Settings::Setting<bool>* setting,
  23. const QCheckBox* checkbox,
  24. const CheckState& tracker) {
  25. if (tracker == CheckState::Global) {
  26. setting->SetGlobal(true);
  27. } else {
  28. setting->SetGlobal(false);
  29. setting->SetValue(checkbox->checkState());
  30. }
  31. }
  32. void ConfigurationShared::ApplyPerGameSetting(Settings::Setting<int>* setting,
  33. const QComboBox* combobox) {
  34. if (combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  35. setting->SetGlobal(true);
  36. } else {
  37. setting->SetGlobal(false);
  38. setting->SetValue(combobox->currentIndex() - ConfigurationShared::USE_GLOBAL_OFFSET);
  39. }
  40. }
  41. void ConfigurationShared::ApplyPerGameSetting(Settings::Setting<Settings::RendererBackend>* setting,
  42. const QComboBox* combobox) {
  43. if (combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  44. setting->SetGlobal(true);
  45. } else {
  46. setting->SetGlobal(false);
  47. setting->SetValue(static_cast<Settings::RendererBackend>(
  48. combobox->currentIndex() - ConfigurationShared::USE_GLOBAL_OFFSET));
  49. }
  50. }
  51. void ConfigurationShared::SetPerGameSetting(QCheckBox* checkbox,
  52. const Settings::Setting<bool>* setting) {
  53. if (setting->UsingGlobal()) {
  54. checkbox->setCheckState(Qt::PartiallyChecked);
  55. } else {
  56. checkbox->setCheckState(setting->GetValue() ? Qt::Checked : Qt::Unchecked);
  57. }
  58. }
  59. void ConfigurationShared::SetPerGameSetting(QComboBox* combobox,
  60. const Settings::Setting<int>* setting) {
  61. combobox->setCurrentIndex(setting->UsingGlobal()
  62. ? ConfigurationShared::USE_GLOBAL_INDEX
  63. : setting->GetValue() + ConfigurationShared::USE_GLOBAL_OFFSET);
  64. }
  65. void ConfigurationShared::SetPerGameSetting(
  66. QComboBox* combobox, const Settings::Setting<Settings::RendererBackend>* setting) {
  67. combobox->setCurrentIndex(setting->UsingGlobal() ? ConfigurationShared::USE_GLOBAL_INDEX
  68. : static_cast<int>(setting->GetValue()) +
  69. ConfigurationShared::USE_GLOBAL_OFFSET);
  70. }
  71. void ConfigurationShared::SetPerGameSetting(
  72. QComboBox* combobox, const Settings::Setting<Settings::GPUAccuracy>* setting) {
  73. combobox->setCurrentIndex(setting->UsingGlobal() ? ConfigurationShared::USE_GLOBAL_INDEX
  74. : static_cast<int>(setting->GetValue()) +
  75. ConfigurationShared::USE_GLOBAL_OFFSET);
  76. }
  77. void ConfigurationShared::SetBGColor(QWidget* widget, bool highlighted) {
  78. if (highlighted) {
  79. widget->setStyleSheet(QStringLiteral("background-color:rgba(0,203,255,0.5);"));
  80. } else {
  81. widget->setStyleSheet(QStringLiteral("background-color:rgba(0,0,0,0);"));
  82. }
  83. widget->show();
  84. }
  85. void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox, Settings::Setting<bool>& setting,
  86. ConfigurationShared::CheckState& tracker) {
  87. if (setting.UsingGlobal()) {
  88. tracker = CheckState::Global;
  89. } else {
  90. tracker = (setting.GetValue() == setting.GetValue(true)) ? CheckState::On : CheckState::Off;
  91. }
  92. SetBGColor(checkbox, tracker != CheckState::Global);
  93. QObject::connect(checkbox, &QCheckBox::clicked, checkbox, [checkbox, setting, &tracker]() {
  94. tracker = static_cast<ConfigurationShared::CheckState>((tracker + 1) % CheckState::Count);
  95. if (tracker == CheckState::Global) {
  96. checkbox->setChecked(setting.GetValue(true));
  97. }
  98. SetBGColor(checkbox, tracker != CheckState::Global);
  99. });
  100. }
  101. void ConfigurationShared::InsertGlobalItem(QComboBox* combobox) {
  102. const QString use_global_text = ConfigurePerGame::tr("Use global configuration");
  103. combobox->insertItem(ConfigurationShared::USE_GLOBAL_INDEX, use_global_text);
  104. combobox->insertSeparator(ConfigurationShared::USE_GLOBAL_SEPARATOR_INDEX);
  105. }