settingswidget.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "widgets/settingswidget.h"
  2. #include "ui_settingswidget.h"
  3. #include "models/filesystem.h"
  4. #include "models/lotrodatmanager.h"
  5. #include "widgets/mainwindow.h"
  6. #include <QDebug>
  7. #include <QFileDialog>
  8. #include <QMessageBox>
  9. SettingsWidget::SettingsWidget(QSettings* settings, PatchDownloader* patch_downloader, LotroDatManager* lotro_dat_manager, QWidget *parent) :
  10. QWidget(parent), app_settings(settings), lotro_manager(lotro_dat_manager),
  11. ui(new Ui::SettingsWidget)
  12. {
  13. ui->setupUi(this);
  14. ui->folder_value_common->setText(app_settings->value("General/game_folder_path", "Не выбрана").toString());
  15. }
  16. SettingsWidget::~SettingsWidget()
  17. {
  18. delete ui;
  19. }
  20. void SettingsWidget::on_interface_scale_combobox_common_currentIndexChanged(const QString &arg1)
  21. {
  22. MainWindow* window = qobject_cast<MainWindow*>(qApp->activeWindow());
  23. if (!window) {
  24. ui->interface_scale_combobox_common->setCurrentText(app_settings->value("general/ui_scale", 100).toString() + "%");
  25. qDebug() << "CANNOT FIND MAIN WINDOW!!!";
  26. return;
  27. }
  28. int value = arg1.left(arg1.length() - 1).toInt();
  29. window->resize(1000 * value / 100, 648 * value / 100);
  30. app_settings->setValue("general/ui_scale", value);
  31. }
  32. void SettingsWidget::on_change_folder_button_clicked() {
  33. QStringList known_paths = FileSystem::recognizeRegistryLotroPath();
  34. QString template_path = known_paths.empty() ? "" : known_paths[0];
  35. QString str = QFileDialog::getOpenFileName(0, "Расположение игры", template_path, "LotroLauncher.exe");
  36. QString game_folder= str.replace("/LotroLauncher.exe", "").replace("\\", "/").replace("//", "/");
  37. if (app_settings->value("General/game_folder_path", "").toString() == game_folder)
  38. return;
  39. app_settings->setValue("General/game_folder_path", game_folder);
  40. ui->folder_value_common->setText(game_folder);
  41. QMetaObject::invokeMethod(lotro_manager, "InitialiseManager", Qt::QueuedConnection);
  42. }
  43. void SettingsWidget::on_lotro_patch_language_combobox_common_activated(int index)
  44. {
  45. QString value = "";
  46. if (index == 0)
  47. value = "English";
  48. if (index == 1)
  49. value = "DE";
  50. if (index == 2)
  51. value = "FR";
  52. if (app_settings->value("General/original_locale", "").toString() == value)
  53. return;
  54. app_settings->setValue("General/original_locale", value);
  55. QMetaObject::invokeMethod(lotro_manager, "InitialiseManager", Qt::QueuedConnection);
  56. }
  57. void SettingsWidget::on_patch_all_button_common_clicked()
  58. {
  59. QMetaObject::invokeMethod(lotro_manager, "InstallActivePatches", Qt::QueuedConnection);
  60. }
  61. void SettingsWidget::on_remove_backup_common_clicked()
  62. {
  63. QMetaObject::invokeMethod(lotro_manager, "RemoveBackup", Qt::QueuedConnection);
  64. }
  65. void SettingsWidget::on_create_backup_common_clicked()
  66. {
  67. QMetaObject::invokeMethod(lotro_manager, "CreateBackup", Qt::QueuedConnection);
  68. }
  69. void SettingsWidget::on_restore_backup_common_clicked()
  70. {
  71. QMetaObject::invokeMethod(lotro_manager, "RestoreBackup", Qt::QueuedConnection);
  72. }