configuration_shared.cpp 4.1 KB

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