configuration_shared.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 <QString>
  8. #include "core/settings.h"
  9. #include "yuzu/configuration/configuration_shared.h"
  10. #include "yuzu/configuration/configure_per_game.h"
  11. void ConfigurationShared::ApplyPerGameSetting(Settings::Setting<bool>* setting,
  12. const QCheckBox* checkbox) {
  13. if (checkbox->checkState() == Qt::PartiallyChecked) {
  14. setting->SetGlobal(true);
  15. } else {
  16. setting->SetGlobal(false);
  17. setting->SetValue(checkbox->checkState() == Qt::Checked);
  18. }
  19. }
  20. void ConfigurationShared::ApplyPerGameSetting(Settings::Setting<bool>* setting,
  21. const QCheckBox* checkbox,
  22. const CheckState& tracker) {
  23. if (tracker == CheckState::Global) {
  24. setting->SetGlobal(true);
  25. } else {
  26. setting->SetGlobal(false);
  27. setting->SetValue(checkbox->checkState());
  28. }
  29. }
  30. void ConfigurationShared::ApplyPerGameSetting(Settings::Setting<int>* setting,
  31. const QComboBox* combobox) {
  32. if (combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  33. setting->SetGlobal(true);
  34. } else {
  35. setting->SetGlobal(false);
  36. setting->SetValue(combobox->currentIndex() - ConfigurationShared::USE_GLOBAL_OFFSET);
  37. }
  38. }
  39. void ConfigurationShared::ApplyPerGameSetting(Settings::Setting<Settings::RendererBackend>* setting,
  40. const QComboBox* combobox) {
  41. if (combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  42. setting->SetGlobal(true);
  43. } else {
  44. setting->SetGlobal(false);
  45. setting->SetValue(static_cast<Settings::RendererBackend>(
  46. combobox->currentIndex() - ConfigurationShared::USE_GLOBAL_OFFSET));
  47. }
  48. }
  49. void ConfigurationShared::SetPerGameSetting(QCheckBox* checkbox,
  50. const Settings::Setting<bool>* setting) {
  51. if (setting->UsingGlobal()) {
  52. checkbox->setCheckState(Qt::PartiallyChecked);
  53. } else {
  54. checkbox->setCheckState(setting->GetValue() ? Qt::Checked : Qt::Unchecked);
  55. }
  56. }
  57. void ConfigurationShared::SetPerGameSetting(QComboBox* combobox,
  58. const Settings::Setting<int>* setting) {
  59. combobox->setCurrentIndex(setting->UsingGlobal()
  60. ? ConfigurationShared::USE_GLOBAL_INDEX
  61. : setting->GetValue() + ConfigurationShared::USE_GLOBAL_OFFSET);
  62. }
  63. void ConfigurationShared::SetPerGameSetting(
  64. QComboBox* combobox, const Settings::Setting<Settings::RendererBackend>* setting) {
  65. combobox->setCurrentIndex(setting->UsingGlobal() ? ConfigurationShared::USE_GLOBAL_INDEX
  66. : static_cast<int>(setting->GetValue()) +
  67. ConfigurationShared::USE_GLOBAL_OFFSET);
  68. }
  69. void ConfigurationShared::SetPerGameSetting(
  70. QComboBox* combobox, const Settings::Setting<Settings::GPUAccuracy>* setting) {
  71. combobox->setCurrentIndex(setting->UsingGlobal() ? ConfigurationShared::USE_GLOBAL_INDEX
  72. : static_cast<int>(setting->GetValue()) +
  73. ConfigurationShared::USE_GLOBAL_OFFSET);
  74. }
  75. void ConfigurationShared::SetHighlight(QWidget* widget, const std::string& name, bool highlighted) {
  76. if (highlighted) {
  77. widget->setStyleSheet(QStringLiteral("QWidget#%1 { background-color:rgba(0,203,255,0.5) }")
  78. .arg(QString::fromStdString(name)));
  79. } else {
  80. widget->setStyleSheet(QStringLiteral("QWidget#%1 { background-color:rgba(0,0,0,0) }")
  81. .arg(QString::fromStdString(name)));
  82. }
  83. widget->show();
  84. }
  85. void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox, const std::string& name,
  86. const Settings::Setting<bool>& setting,
  87. CheckState& tracker) {
  88. if (setting.UsingGlobal()) {
  89. tracker = CheckState::Global;
  90. } else {
  91. tracker = (setting.GetValue() == setting.GetValue(true)) ? CheckState::On : CheckState::Off;
  92. }
  93. SetHighlight(checkbox, name, tracker != CheckState::Global);
  94. QObject::connect(checkbox, &QCheckBox::clicked, checkbox,
  95. [checkbox, name, setting, &tracker]() {
  96. tracker = static_cast<CheckState>((static_cast<int>(tracker) + 1) %
  97. static_cast<int>(CheckState::Count));
  98. if (tracker == CheckState::Global) {
  99. checkbox->setChecked(setting.GetValue(true));
  100. }
  101. SetHighlight(checkbox, name, tracker != CheckState::Global);
  102. });
  103. }
  104. void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox, const std::string& name,
  105. bool global, bool state, bool global_state,
  106. CheckState& tracker) {
  107. if (global) {
  108. tracker = CheckState::Global;
  109. } else {
  110. tracker = (state == global_state) ? CheckState::On : CheckState::Off;
  111. }
  112. SetHighlight(checkbox, name, tracker != CheckState::Global);
  113. QObject::connect(checkbox, &QCheckBox::clicked, checkbox,
  114. [checkbox, name, global_state, &tracker]() {
  115. tracker = static_cast<CheckState>((static_cast<int>(tracker) + 1) %
  116. static_cast<int>(CheckState::Count));
  117. if (tracker == CheckState::Global) {
  118. checkbox->setChecked(global_state);
  119. }
  120. SetHighlight(checkbox, name, tracker != CheckState::Global);
  121. });
  122. }
  123. void ConfigurationShared::SetColoredComboBox(QComboBox* combobox, QWidget* target,
  124. const std::string& target_name, int global) {
  125. InsertGlobalItem(combobox, global);
  126. QObject::connect(combobox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), target,
  127. [target, target_name](int index) {
  128. ConfigurationShared::SetHighlight(target, target_name, index != 0);
  129. });
  130. }
  131. void ConfigurationShared::InsertGlobalItem(QComboBox* combobox) {
  132. const QString use_global_text = ConfigurePerGame::tr("Use global configuration");
  133. combobox->insertItem(ConfigurationShared::USE_GLOBAL_INDEX, use_global_text);
  134. combobox->insertSeparator(ConfigurationShared::USE_GLOBAL_SEPARATOR_INDEX);
  135. }
  136. void ConfigurationShared::InsertGlobalItem(QComboBox* combobox, int global_index) {
  137. const QString use_global_text =
  138. ConfigurePerGame::tr("Use global configuration (%1)").arg(combobox->itemText(global_index));
  139. combobox->insertItem(ConfigurationShared::USE_GLOBAL_INDEX, use_global_text);
  140. combobox->insertSeparator(ConfigurationShared::USE_GLOBAL_SEPARATOR_INDEX);
  141. }