rusificationwidget.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. RusificationTreeItem* findItemByName(RusificationTreeItem* item, QString name) {
  12. if (item->name == name)
  13. return item;
  14. for (int i = 0; i < item->childCount(); i++) {
  15. RusificationTreeItem* found_item = findItemByName((RusificationTreeItem*)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. RusificationTreeItem *root_item = new RusificationTreeItem("rusification");
  45. root_item->title = "Русификация";
  46. root_item->setText(0, "Русификация");
  47. root_item->description = "Русификация (описание)";
  48. root_item->setFlags(Qt::ItemIsAutoTristate | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
  49. ui->treeWidget_title->invisibleRootItem()->addChild(root_item);
  50. foreach (const QString &group, patch_list.childGroups()) {
  51. qDebug() << "Processing " << group << " patch item";
  52. RusificationTreeItem *item = new RusificationTreeItem(group);
  53. item->parseSettingsItem(patch_list);
  54. RusificationTreeItem *parent_item = findItemByName(root_item, item->parent_name);
  55. parent_item->addChild(item);
  56. }
  57. ui->treeWidget_title->expandAll();
  58. doStuffWithEveryItemInMyTree(ui->treeWidget_title->invisibleRootItem());
  59. }
  60. void RusificationWidget::hideAllImportWidgets()
  61. {
  62. ui->database_import_widget->hide();
  63. ui->file_import_widget->hide();
  64. ui->textfragment_import_widget->hide();
  65. }
  66. void RusificationWidget::onHoveredTreeItemChanged(QTreeWidgetItem *item, int column)
  67. {
  68. RusificationTreeItem *tree_item = (RusificationTreeItem*)(item);
  69. ui->patch_hint->setText("Патч: " + tree_item->title + "\nОписание: " + tree_item->description);
  70. }
  71. void RusificationWidget::on_database_import_radiobutton_common_clicked()
  72. {
  73. hideAllImportWidgets();
  74. ui->database_import_widget->show();
  75. }
  76. void RusificationWidget::on_file_import_radiobutton_common_clicked()
  77. {
  78. hideAllImportWidgets();
  79. ui->file_import_widget->show();
  80. }
  81. void RusificationWidget::on_textfragment_import_radiobutton_common_clicked()
  82. {
  83. hideAllImportWidgets();
  84. ui->textfragment_import_widget->show();
  85. }
  86. void RusificationWidget::updateUI()
  87. {
  88. if (app->properties.value("settings/expert_mode", 0).toBool()) {
  89. ui->tabWidget_common->tabBar()->show();
  90. } else {
  91. if (ui->tabWidget_common->currentIndex() != 0)
  92. ui->tabWidget_common->setCurrentIndex(0);
  93. ui->tabWidget_common->tabBar()->hide();
  94. }
  95. //======= MANAGEMENT SECTION =======//
  96. auto res = app->client_local_dat.GetIO().GetFilename();
  97. if (res.result == LOTRO_DAT::SUCCESS)
  98. ui->datfile_name_common->setText(QString::fromStdString(res.value));
  99. else
  100. ui->datfile_name_common->setText("(файл не инициализирован)");
  101. }