#include "gui\rusificationwidget.h" #include "ui_rusificationwidget.h" #include "legacyapp.h" #include "rusificationtreeitem.h" void doStuffWithEveryItemInMyTree( QTreeWidgetItem *item ) { item->setCheckState(0, Qt::Checked); for( int i = 0; i < item->childCount(); ++i ) doStuffWithEveryItemInMyTree( item->child(i) ); } RusificationTreeItem* findItemByName(RusificationTreeItem* item, QString name) { if (item->name == name) return item; for (int i = 0; i < item->childCount(); i++) { RusificationTreeItem* found_item = findItemByName((RusificationTreeItem*)item->child(i), name); if (found_item) return found_item; } return nullptr; } RusificationWidget::RusificationWidget(LegacyApp *_app, QWidget *parent) : QWidget(parent), ui(new Ui::RusificationWidget), app(_app) { ui->setupUi(this); setupTreeWidget(); hideAllImportWidgets(); ui->database_import_widget->show(); ui_update_timer.setInterval(500); connect(&ui_update_timer, &QTimer::timeout, this, &RusificationWidget::updateUI); ui_update_timer.start(); } RusificationWidget::~RusificationWidget() { delete ui; } void RusificationWidget::setupTreeWidget() { connect(ui->treeWidget_title, &QTreeWidget::itemEntered, this, &RusificationWidget::onHoveredTreeItemChanged); QSettings patch_list(qApp->applicationDirPath() + "/legacy_patches.ini", QSettings::IniFormat); patch_list.setIniCodec("UTF-8"); ui->treeWidget_title->setMouseTracking(true); RusificationTreeItem *root_item = new RusificationTreeItem("rusification"); root_item->title = "Русификация"; root_item->setText(0, "Русификация"); root_item->description = "Русификация (описание)"; root_item->setFlags(Qt::ItemIsAutoTristate | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable); ui->treeWidget_title->invisibleRootItem()->addChild(root_item); foreach (const QString &group, patch_list.childGroups()) { qDebug() << "Processing " << group << " patch item"; RusificationTreeItem *item = new RusificationTreeItem(group); item->parseSettingsItem(patch_list); RusificationTreeItem *parent_item = findItemByName(root_item, item->parent_name); parent_item->addChild(item); } ui->treeWidget_title->expandAll(); doStuffWithEveryItemInMyTree(ui->treeWidget_title->invisibleRootItem()); } void RusificationWidget::hideAllImportWidgets() { ui->database_import_widget->hide(); ui->file_import_widget->hide(); ui->textfragment_import_widget->hide(); } void RusificationWidget::onHoveredTreeItemChanged(QTreeWidgetItem *item, int column) { RusificationTreeItem *tree_item = (RusificationTreeItem*)(item); ui->patch_hint->setText("Патч: " + tree_item->title + "\nОписание: " + tree_item->description); } void RusificationWidget::on_database_import_radiobutton_common_clicked() { hideAllImportWidgets(); ui->database_import_widget->show(); } void RusificationWidget::on_file_import_radiobutton_common_clicked() { hideAllImportWidgets(); ui->file_import_widget->show(); } void RusificationWidget::on_textfragment_import_radiobutton_common_clicked() { hideAllImportWidgets(); ui->textfragment_import_widget->show(); } void RusificationWidget::updateUI() { if (app->properties.value("settings/expert_mode", 0).toBool()) { ui->tabWidget_common->tabBar()->show(); } else { if (ui->tabWidget_common->currentIndex() != 0) ui->tabWidget_common->setCurrentIndex(0); ui->tabWidget_common->tabBar()->hide(); } //======= MANAGEMENT SECTION =======// auto res = app->client_local_dat.GetIO().GetFilename(); if (res.result == LOTRO_DAT::SUCCESS) ui->datfile_name_common->setText(QString::fromStdString(res.value)); else ui->datfile_name_common->setText("(файл не инициализирован)"); }