configure_gamelist.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Copyright 2016 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <array>
  5. #include <utility>
  6. #include "common/common_types.h"
  7. #include "core/settings.h"
  8. #include "ui_configure_gamelist.h"
  9. #include "yuzu/configuration/configure_gamelist.h"
  10. #include "yuzu/ui_settings.h"
  11. namespace {
  12. constexpr std::array default_icon_sizes{
  13. std::make_pair(0, QT_TR_NOOP("None")),
  14. std::make_pair(32, QT_TR_NOOP("Small (32x32)")),
  15. std::make_pair(64, QT_TR_NOOP("Standard (64x64)")),
  16. std::make_pair(128, QT_TR_NOOP("Large (128x128)")),
  17. std::make_pair(256, QT_TR_NOOP("Full Size (256x256)")),
  18. };
  19. constexpr std::array row_text_names{
  20. QT_TR_NOOP("Filename"),
  21. QT_TR_NOOP("Filetype"),
  22. QT_TR_NOOP("Title ID"),
  23. QT_TR_NOOP("Title Name"),
  24. };
  25. } // Anonymous namespace
  26. ConfigureGameList::ConfigureGameList(QWidget* parent)
  27. : QWidget(parent), ui(new Ui::ConfigureGameList) {
  28. ui->setupUi(this);
  29. InitializeIconSizeComboBox();
  30. InitializeRowComboBoxes();
  31. SetConfiguration();
  32. // Force game list reload if any of the relevant settings are changed.
  33. connect(ui->show_unknown, &QCheckBox::stateChanged, this,
  34. &ConfigureGameList::RequestGameListUpdate);
  35. connect(ui->icon_size_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
  36. &ConfigureGameList::RequestGameListUpdate);
  37. connect(ui->row_1_text_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
  38. &ConfigureGameList::RequestGameListUpdate);
  39. connect(ui->row_2_text_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
  40. &ConfigureGameList::RequestGameListUpdate);
  41. }
  42. ConfigureGameList::~ConfigureGameList() = default;
  43. void ConfigureGameList::ApplyConfiguration() {
  44. UISettings::values.show_unknown = ui->show_unknown->isChecked();
  45. UISettings::values.show_add_ons = ui->show_add_ons->isChecked();
  46. UISettings::values.icon_size = ui->icon_size_combobox->currentData().toUInt();
  47. UISettings::values.row_1_text_id = ui->row_1_text_combobox->currentData().toUInt();
  48. UISettings::values.row_2_text_id = ui->row_2_text_combobox->currentData().toUInt();
  49. Settings::Apply();
  50. }
  51. void ConfigureGameList::RequestGameListUpdate() {
  52. UISettings::values.is_game_list_reload_pending.exchange(true);
  53. }
  54. void ConfigureGameList::SetConfiguration() {
  55. ui->show_unknown->setChecked(UISettings::values.show_unknown);
  56. ui->show_add_ons->setChecked(UISettings::values.show_add_ons);
  57. ui->icon_size_combobox->setCurrentIndex(
  58. ui->icon_size_combobox->findData(UISettings::values.icon_size));
  59. ui->row_1_text_combobox->setCurrentIndex(
  60. ui->row_1_text_combobox->findData(UISettings::values.row_1_text_id));
  61. ui->row_2_text_combobox->setCurrentIndex(
  62. ui->row_2_text_combobox->findData(UISettings::values.row_2_text_id));
  63. }
  64. void ConfigureGameList::changeEvent(QEvent* event) {
  65. if (event->type() == QEvent::LanguageChange) {
  66. RetranslateUI();
  67. }
  68. QWidget::changeEvent(event);
  69. }
  70. void ConfigureGameList::RetranslateUI() {
  71. ui->retranslateUi(this);
  72. for (int i = 0; i < ui->icon_size_combobox->count(); i++) {
  73. ui->icon_size_combobox->setItemText(i, tr(default_icon_sizes[i].second));
  74. }
  75. for (int i = 0; i < ui->row_1_text_combobox->count(); i++) {
  76. const QString name = tr(row_text_names[i]);
  77. ui->row_1_text_combobox->setItemText(i, name);
  78. ui->row_2_text_combobox->setItemText(i, name);
  79. }
  80. }
  81. void ConfigureGameList::InitializeIconSizeComboBox() {
  82. for (const auto& size : default_icon_sizes) {
  83. ui->icon_size_combobox->addItem(QString::fromUtf8(size.second), size.first);
  84. }
  85. }
  86. void ConfigureGameList::InitializeRowComboBoxes() {
  87. for (std::size_t i = 0; i < row_text_names.size(); ++i) {
  88. const QString row_text_name = QString::fromUtf8(row_text_names[i]);
  89. ui->row_1_text_combobox->addItem(row_text_name, QVariant::fromValue(i));
  90. ui->row_2_text_combobox->addItem(row_text_name, QVariant::fromValue(i));
  91. }
  92. }