statuswidget.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #include "statuswidget.h"
  2. #include "ui_statuswidget.h"
  3. #include "widgets/mainwindow.h"
  4. #include "models/patchdownloader.h"
  5. #include "models/lotrodatmanager.h"
  6. #include "constants.h"
  7. #include <QDesktopServices>
  8. #include <QUrl>
  9. #include <QDebug>
  10. #include <QMessageBox>
  11. StatusWidget::StatusWidget(QSettings* settings, PatchDownloader* patch_downloader, LotroDatManager* lotro_dat_manager, QWidget *parent) :
  12. QWidget(parent), patch_updater(patch_downloader), lotro_manager(lotro_dat_manager), app_settings(settings),
  13. ui(new Ui::StatusWidget)
  14. {
  15. ui->setupUi(this);
  16. connect(patch_updater, &PatchDownloader::downloadStarted, this, &StatusWidget::onPatchDownloaderStarted, Qt::QueuedConnection);
  17. connect(patch_updater, &PatchDownloader::progressChanged, this, &StatusWidget::onPatchDownloaderProgressChanged, Qt::QueuedConnection);
  18. connect(patch_updater, &PatchDownloader::downloadCompleted, this, &StatusWidget::onPatchDownloaderFinished, Qt::QueuedConnection);
  19. connect(ui->weekly_code_widget, &WeeklyCodeWidget::showCompletedTooltip, this, &StatusWidget::setToolTipToWeeklyCodeComplete);
  20. connect(ui->weekly_code_widget, &WeeklyCodeWidget::showHelpTooltip, this, &StatusWidget::setToolTipToWeeklyCodeHelp);
  21. connect(ui->weekly_code_widget, &WeeklyCodeWidget::showNoTooltip, this, &StatusWidget::resetToolTip);
  22. connect(ui->news_list, &NewsListWidget::showHelpToolTip, this, &StatusWidget::setToolTipToNewsHelp);
  23. connect(ui->news_list, &NewsListWidget::showNoToolTip, this, &StatusWidget::resetToolTip);
  24. resetToolTip();
  25. }
  26. StatusWidget::~StatusWidget()
  27. {
  28. delete ui;
  29. }
  30. void StatusWidget::updateFontsSizes()
  31. {
  32. QFont pt10_font = QFont(ui->news_label->font());
  33. pt10_font.setPixelSize(pixels_in_10_pt);
  34. QFont pt9_font = QFont(ui->progress_label->font());
  35. pt9_font.setPixelSize(pixels_in_9_pt);
  36. QFont pt11_font = QFont(ui->game_button->font());
  37. pt11_font.setPixelSize(pixels_in_11_pt);
  38. QFont pt8_font = QFont(ui->images_label->font());
  39. pt8_font.setPixelSize(pixels_in_8_pt);
  40. ui->progress_label->setFont(pt8_font);
  41. ui->game_button->setFont(pt11_font);
  42. ui->news_label->setFont(pt10_font);
  43. ui->news_tooltip->setFont(pt9_font);
  44. ui->images_label->setFont(pt8_font);
  45. ui->images_status->setFont(pt8_font);
  46. ui->sounds_label->setFont(pt8_font);
  47. ui->sounds_status->setFont(pt8_font);
  48. ui->texts_label->setFont(pt8_font);
  49. ui->texts_status->setFont(pt8_font);
  50. ui->videos_label->setFont(pt8_font);
  51. ui->videos_status->setFont(pt8_font);
  52. ui->weekly_code_tooltip_1->setFont(pt9_font);
  53. ui->weekly_code_tooltip_2->setFont(pt9_font);
  54. }
  55. void StatusWidget::resizeEvent(QResizeEvent *event)
  56. {
  57. double coefficient = window_width / default_window_width;
  58. ui->game_button->move(QPoint(840, 460) * coefficient);
  59. ui->game_button->resize(QSize(150, 60) * coefficient);
  60. ui->progressBar->move(QPoint(330, 480) * coefficient);
  61. ui->progressBar->resize(QSize(501, 40) * coefficient);
  62. ui->progress_label->move(QPoint(330, 450) * coefficient);
  63. ui->progress_label->resize(QSize(501, 31) * coefficient);
  64. ui->news_label->move(QPoint(57, 33)* coefficient);
  65. ui->news_label->resize(QSize(180, 21) * coefficient);
  66. ui->news_scroll_area->move(QPoint(40, 75) * coefficient);
  67. ui->news_scroll_area->resize(QSize(250, 440) * coefficient);
  68. ui->server_status_widget->move(QPoint(820, 90) * coefficient);
  69. ui->server_status_widget->resize(QSize(155, 320) * coefficient);
  70. ui->weekly_code_widget->move(QPoint(810, 13) * coefficient);
  71. ui->weekly_code_widget->resize(QSize(173, 57) * coefficient);
  72. ui->witch_king_widget->move(QPoint(315, 20) * coefficient);
  73. ui->witch_king_widget->resize(QSize(511, 421) * coefficient);
  74. ui->witch_king_text_content->move(QPoint(50, 30) * coefficient);
  75. ui->witch_king_text_content->resize(QSize(331, 101) * coefficient);
  76. updateFontsSizes();
  77. }
  78. void StatusWidget::onPatchDownloaderStarted()
  79. {
  80. qDebug() << "Status widget received DownloadStarted signal!";
  81. ui->progress_label->setText("Загрузка обновлений патчей...");
  82. ui->progressBar->setValue(0);
  83. }
  84. void StatusWidget::onPatchDownloaderFinished()
  85. {
  86. ui->progress_label->setText("Загрузка обновлений патчей завершена!");
  87. ui->progressBar->setValue(100);
  88. }
  89. void StatusWidget::onPatchDownloaderProgressChanged(quint64 bytesDownloaded, quint64 bytesTotal, QString download_speed_formatted, QString elapsed_time_formatted)
  90. {
  91. ui->progress_label->setText("Загрузка " + download_speed_formatted + ". Загружено "
  92. + Downloader::getSizeFormatted(bytesDownloaded) + " из " + Downloader::getSizeFormatted(bytesTotal)
  93. + " (" + QString::number(bytesDownloaded * 100 / bytesTotal) + "%) ");
  94. //+ "\nОставшееся время: " + elapsed_time_formatted);
  95. ui->progressBar->setValue(bytesDownloaded * 100 / bytesTotal + 5);
  96. }
  97. void StatusWidget::on_game_button_clicked()
  98. {
  99. MainWindow* window = qobject_cast<MainWindow*>(parentWidget()->parentWidget()->parentWidget());
  100. window->showChooseVersionDialog();
  101. }
  102. void StatusWidget::setToolTipToWeeklyCodeHelp()
  103. {
  104. ui->patches_status->hide();
  105. ui->weekly_code_tooltip_2->hide();
  106. ui->news_tooltip->hide();
  107. ui->weekly_code_tooltip_1->show();
  108. }
  109. void StatusWidget::setToolTipToWeeklyCodeComplete()
  110. {
  111. ui->patches_status->hide();
  112. ui->weekly_code_tooltip_1->hide();
  113. ui->news_tooltip->hide();
  114. ui->weekly_code_tooltip_2->show();
  115. }
  116. void StatusWidget::setToolTipToNewsHelp()
  117. {
  118. ui->patches_status->hide();
  119. ui->weekly_code_tooltip_1->hide();
  120. ui->weekly_code_tooltip_2->hide();
  121. ui->news_tooltip->show();
  122. }
  123. void StatusWidget::resetToolTip()
  124. {
  125. ui->weekly_code_tooltip_1->hide();
  126. ui->weekly_code_tooltip_2->hide();
  127. ui->news_tooltip->hide();
  128. ui->patches_status->show();
  129. }