rusificationwidget.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include "gui\rusificationwidget.h"
  2. #include "ui_rusificationwidget.h"
  3. #include "legacyapp.h"
  4. #include "rusificationtreeitem.h"
  5. void doStuffWithEveryItemInMyTree( QTreeWidgetItem *item )
  6. {
  7. item->setCheckState(0, Qt::Checked);
  8. for( int i = 0; i < item->childCount(); ++i )
  9. doStuffWithEveryItemInMyTree( item->child(i) );
  10. }
  11. QTreeWidgetItem* findItemByName(QTreeWidgetItem* item, QString name) {
  12. for (int i = 0; i < item->childCount(); i++) {
  13. if (((RusificationTreeItem*)item->child(i))->name == name)
  14. return item->child(i);
  15. QTreeWidgetItem* found_item = findItemByName(item->child(i), name);
  16. if (found_item)
  17. return found_item;
  18. }
  19. return nullptr;
  20. }
  21. RusificationWidget::RusificationWidget(LegacyApp *_app, QWidget *parent) :
  22. QWidget(parent),
  23. ui(new Ui::RusificationWidget),
  24. app(_app)
  25. {
  26. ui->setupUi(this);
  27. setupTreeWidget();
  28. hideAllImportWidgets();
  29. ui->database_import_widget->show();
  30. ui_update_timer.setInterval(500);
  31. connect(&ui_update_timer, &QTimer::timeout, this, &RusificationWidget::updateUI);
  32. ui_update_timer.start();
  33. }
  34. RusificationWidget::~RusificationWidget()
  35. {
  36. delete ui;
  37. }
  38. void RusificationWidget::setupTreeWidget()
  39. {
  40. connect(ui->treeWidget_title, &QTreeWidget::itemEntered, this, &RusificationWidget::onHoveredTreeItemChanged);
  41. QSettings patch_list(qApp->applicationDirPath() + "/legacy_patches.ini", QSettings::IniFormat);
  42. patch_list.setIniCodec("UTF-8");
  43. ui->treeWidget_title->setMouseTracking(true);
  44. foreach (const QString &group, patch_list.childGroups()) {
  45. qDebug() << "Processing " << group << " patch item";
  46. RusificationTreeItem* item = new RusificationTreeItem(group);
  47. item->parseSettingsItem(patch_list);
  48. QTreeWidgetItem* parent_item = findItemByName(ui->treeWidget_title->invisibleRootItem(), item->parent_name);
  49. if (!parent_item)
  50. parent_item = ui->treeWidget_title->invisibleRootItem();
  51. parent_item->addChild(item);
  52. }
  53. ui->treeWidget_title->expandAll();
  54. doStuffWithEveryItemInMyTree(ui->treeWidget_title->invisibleRootItem());
  55. }
  56. void RusificationWidget::hideAllImportWidgets()
  57. {
  58. ui->database_import_widget->hide();
  59. ui->file_import_widget->hide();
  60. ui->textfragment_import_widget->hide();
  61. }
  62. void RusificationWidget::onHoveredTreeItemChanged(QTreeWidgetItem *item, int column)
  63. {
  64. RusificationTreeItem *tree_item = (RusificationTreeItem*)(item);
  65. ui->patch_hint->setText("Патч: " + tree_item->title + "\nОписание: " + tree_item->description);
  66. }
  67. void RusificationWidget::on_database_import_radiobutton_common_clicked()
  68. {
  69. hideAllImportWidgets();
  70. ui->database_import_widget->show();
  71. }
  72. void RusificationWidget::on_file_import_radiobutton_common_clicked()
  73. {
  74. hideAllImportWidgets();
  75. ui->file_import_widget->show();
  76. }
  77. void RusificationWidget::on_textfragment_import_radiobutton_common_clicked()
  78. {
  79. hideAllImportWidgets();
  80. ui->textfragment_import_widget->show();
  81. }
  82. void RusificationWidget::updateUI()
  83. {
  84. if (app->properties.value("settings/expert_mode", 0).toBool()) {
  85. ui->tabWidget_common->tabBar()->show();
  86. } else {
  87. if (ui->tabWidget_common->currentIndex() != 0)
  88. ui->tabWidget_common->setCurrentIndex(0);
  89. ui->tabWidget_common->tabBar()->hide();
  90. }
  91. //======= MANAGEMENT SECTION =======//
  92. auto res = app->client_local_dat.GetIO().GetFilename();
  93. if (res.result == LOTRO_DAT::SUCCESS)
  94. ui->datfile_name_common->setText(QString::fromStdString(res.value));
  95. else
  96. ui->datfile_name_common->setText("(файл не инициализирован)");
  97. }