configuration_shared.cpp 4.1 KB

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