#include "statuswidget.h" #include "ui_statuswidget.h" #include "widgets/mainwindow.h" #include "models/patchdownloader.h" #include "models/lotrodatmanager.h" #include "constants.h" #include #include #include #include StatusWidget::StatusWidget(QSettings* settings, PatchDownloader* patch_downloader, LotroDatManager* lotro_dat_manager, QWidget *parent) : QWidget(parent), patch_updater(patch_downloader), lotro_manager(lotro_dat_manager), app_settings(settings), ui(new Ui::StatusWidget) { ui->setupUi(this); connect(patch_updater, &PatchDownloader::downloadStarted, this, &StatusWidget::onPatchDownloaderStarted, Qt::QueuedConnection); connect(patch_updater, &PatchDownloader::progressChanged, this, &StatusWidget::onPatchDownloaderProgressChanged, Qt::QueuedConnection); connect(patch_updater, &PatchDownloader::downloadCompleted, this, &StatusWidget::onPatchDownloaderFinished, Qt::QueuedConnection); connect(ui->weekly_code_widget, &WeeklyCodeWidget::showCompletedTooltip, this, &StatusWidget::setToolTipToWeeklyCodeComplete); connect(ui->weekly_code_widget, &WeeklyCodeWidget::showHelpTooltip, this, &StatusWidget::setToolTipToWeeklyCodeHelp); connect(ui->weekly_code_widget, &WeeklyCodeWidget::showNoTooltip, this, &StatusWidget::resetToolTip); connect(ui->news_list, &NewsListWidget::showHelpToolTip, this, &StatusWidget::setToolTipToNewsHelp); connect(ui->news_list, &NewsListWidget::showNoToolTip, this, &StatusWidget::resetToolTip); resetToolTip(); } StatusWidget::~StatusWidget() { delete ui; } void StatusWidget::updateFontsSizes() { QFont pt10_font = QFont(ui->news_label->font()); pt10_font.setPixelSize(pixels_in_10_pt); QFont pt9_font = QFont(ui->progress_label->font()); pt9_font.setPixelSize(pixels_in_9_pt); QFont pt11_font = QFont(ui->game_button->font()); pt11_font.setPixelSize(pixels_in_11_pt); QFont pt8_font = QFont(ui->images_label->font()); pt8_font.setPixelSize(pixels_in_8_pt); ui->progress_label->setFont(pt8_font); ui->game_button->setFont(pt11_font); ui->news_label->setFont(pt10_font); ui->news_tooltip->setFont(pt9_font); ui->images_label->setFont(pt8_font); ui->images_status->setFont(pt8_font); ui->sounds_label->setFont(pt8_font); ui->sounds_status->setFont(pt8_font); ui->texts_label->setFont(pt8_font); ui->texts_status->setFont(pt8_font); ui->videos_label->setFont(pt8_font); ui->videos_status->setFont(pt8_font); ui->weekly_code_tooltip_1->setFont(pt9_font); ui->weekly_code_tooltip_2->setFont(pt9_font); } void StatusWidget::resizeEvent(QResizeEvent *event) { double coefficient = window_width / default_window_width; ui->game_button->move(QPoint(840, 460) * coefficient); ui->game_button->resize(QSize(150, 60) * coefficient); ui->progressBar->move(QPoint(330, 480) * coefficient); ui->progressBar->resize(QSize(501, 40) * coefficient); ui->progress_label->move(QPoint(330, 450) * coefficient); ui->progress_label->resize(QSize(501, 31) * coefficient); ui->news_label->move(QPoint(57, 33)* coefficient); ui->news_label->resize(QSize(180, 21) * coefficient); ui->news_scroll_area->move(QPoint(40, 75) * coefficient); ui->news_scroll_area->resize(QSize(250, 440) * coefficient); ui->server_status_widget->move(QPoint(820, 90) * coefficient); ui->server_status_widget->resize(QSize(155, 320) * coefficient); ui->weekly_code_widget->move(QPoint(810, 13) * coefficient); ui->weekly_code_widget->resize(QSize(173, 57) * coefficient); ui->witch_king_widget->move(QPoint(315, 20) * coefficient); ui->witch_king_widget->resize(QSize(511, 421) * coefficient); ui->witch_king_text_content->move(QPoint(50, 30) * coefficient); ui->witch_king_text_content->resize(QSize(331, 101) * coefficient); updateFontsSizes(); } void StatusWidget::onPatchDownloaderStarted() { qDebug() << "Status widget received DownloadStarted signal!"; ui->progress_label->setText("Загрузка обновлений патчей..."); ui->progressBar->setValue(0); } void StatusWidget::onPatchDownloaderFinished() { ui->progress_label->setText("Загрузка обновлений патчей завершена!"); ui->progressBar->setValue(100); } void StatusWidget::onPatchDownloaderProgressChanged(quint64 bytesDownloaded, quint64 bytesTotal, QString download_speed_formatted, QString elapsed_time_formatted) { ui->progress_label->setText("Загрузка " + download_speed_formatted + ". Загружено " + Downloader::getSizeFormatted(bytesDownloaded) + " из " + Downloader::getSizeFormatted(bytesTotal) + " (" + QString::number(bytesDownloaded * 100 / bytesTotal) + "%) "); //+ "\nОставшееся время: " + elapsed_time_formatted); ui->progressBar->setValue(bytesDownloaded * 100 / bytesTotal + 5); } void StatusWidget::on_game_button_clicked() { MainWindow* window = qobject_cast(parentWidget()->parentWidget()->parentWidget()); window->showChooseVersionDialog(); } void StatusWidget::setToolTipToWeeklyCodeHelp() { ui->patches_status->hide(); ui->weekly_code_tooltip_2->hide(); ui->news_tooltip->hide(); ui->weekly_code_tooltip_1->show(); } void StatusWidget::setToolTipToWeeklyCodeComplete() { ui->patches_status->hide(); ui->weekly_code_tooltip_1->hide(); ui->news_tooltip->hide(); ui->weekly_code_tooltip_2->show(); } void StatusWidget::setToolTipToNewsHelp() { ui->patches_status->hide(); ui->weekly_code_tooltip_1->hide(); ui->weekly_code_tooltip_2->hide(); ui->news_tooltip->show(); } void StatusWidget::resetToolTip() { ui->weekly_code_tooltip_1->hide(); ui->weekly_code_tooltip_2->hide(); ui->news_tooltip->hide(); ui->patches_status->show(); }