configuration_shared.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "common/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. const CheckState& tracker) {
  14. if (Settings::IsConfiguringGlobal() && setting->UsingGlobal()) {
  15. setting->SetValue(checkbox->checkState());
  16. } else if (!Settings::IsConfiguringGlobal()) {
  17. if (tracker == CheckState::Global) {
  18. setting->SetGlobal(true);
  19. } else {
  20. setting->SetGlobal(false);
  21. setting->SetValue(checkbox->checkState());
  22. }
  23. }
  24. }
  25. void ConfigurationShared::SetPerGameSetting(QCheckBox* checkbox,
  26. const Settings::Setting<bool>* setting) {
  27. if (setting->UsingGlobal()) {
  28. checkbox->setCheckState(Qt::PartiallyChecked);
  29. } else {
  30. checkbox->setCheckState(setting->GetValue() ? Qt::Checked : Qt::Unchecked);
  31. }
  32. }
  33. void ConfigurationShared::SetHighlight(QWidget* widget, bool highlighted) {
  34. if (highlighted) {
  35. widget->setStyleSheet(QStringLiteral("QWidget#%1 { background-color:rgba(0,203,255,0.5) }")
  36. .arg(widget->objectName()));
  37. } else {
  38. widget->setStyleSheet(QStringLiteral("QWidget#%1 { background-color:rgba(0,0,0,0) }")
  39. .arg(widget->objectName()));
  40. }
  41. widget->show();
  42. }
  43. void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox,
  44. const Settings::Setting<bool>& setting,
  45. CheckState& tracker) {
  46. if (setting.UsingGlobal()) {
  47. tracker = CheckState::Global;
  48. } else {
  49. tracker = (setting.GetValue() == setting.GetValue(true)) ? CheckState::On : CheckState::Off;
  50. }
  51. SetHighlight(checkbox, tracker != CheckState::Global);
  52. QObject::connect(checkbox, &QCheckBox::clicked, checkbox, [checkbox, setting, &tracker] {
  53. tracker = static_cast<CheckState>((static_cast<int>(tracker) + 1) %
  54. static_cast<int>(CheckState::Count));
  55. if (tracker == CheckState::Global) {
  56. checkbox->setChecked(setting.GetValue(true));
  57. }
  58. SetHighlight(checkbox, tracker != CheckState::Global);
  59. });
  60. }
  61. void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox, bool global, bool state,
  62. bool global_state, CheckState& tracker) {
  63. if (global) {
  64. tracker = CheckState::Global;
  65. } else {
  66. tracker = (state == global_state) ? CheckState::On : CheckState::Off;
  67. }
  68. SetHighlight(checkbox, tracker != CheckState::Global);
  69. QObject::connect(checkbox, &QCheckBox::clicked, checkbox, [checkbox, global_state, &tracker] {
  70. tracker = static_cast<CheckState>((static_cast<int>(tracker) + 1) %
  71. static_cast<int>(CheckState::Count));
  72. if (tracker == CheckState::Global) {
  73. checkbox->setChecked(global_state);
  74. }
  75. SetHighlight(checkbox, tracker != CheckState::Global);
  76. });
  77. }
  78. void ConfigurationShared::SetColoredComboBox(QComboBox* combobox, QWidget* target, int global) {
  79. InsertGlobalItem(combobox, global);
  80. QObject::connect(combobox, qOverload<int>(&QComboBox::activated), target,
  81. [target](int index) { SetHighlight(target, index != 0); });
  82. }
  83. void ConfigurationShared::InsertGlobalItem(QComboBox* combobox, int global_index) {
  84. const QString use_global_text =
  85. ConfigurePerGame::tr("Use global configuration (%1)").arg(combobox->itemText(global_index));
  86. combobox->insertItem(ConfigurationShared::USE_GLOBAL_INDEX, use_global_text);
  87. combobox->insertSeparator(ConfigurationShared::USE_GLOBAL_SEPARATOR_INDEX);
  88. }