123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- #include "ui_statuswidget.h"
- #include "statuswidget.h"
- #include "models/patchlist.h"
- #include "widgets/mainwindow.h"
- #include "constants.h"
- #include <QDesktopServices>
- #include <QUrl>
- #include <QDebug>
- #include <QMessageBox>
- #include <QRandomGenerator>
- StatusWidget::StatusWidget(PatchList *legacy_patches, QWidget *parent)
- : QWidget(parent)
- , ui(new Ui::StatusWidget)
- , legacy_patches_(legacy_patches)
- {
- ui->setupUi(this);
- last_statusbar_update_time_.start();
- ui->galadriel_tooltip_example->hide();
- connect(ui->weekly_code_widget, &WeeklyCodeWidget::showCompletedTooltip, this, [this](){setToolTipMessage("ЕЖЕНЕДЕЛЬНЫЙ КОД СКОПИРОВАН В БУФЕР ОБМЕНА", E_INFO);});
- connect(ui->weekly_code_widget, &WeeklyCodeWidget::showHelpTooltip, this, [this](){setToolTipMessage("КЛИКНИТЕ ПО ЕЖЕНЕДЕЛЬНОМУ КОДУ, ЧТОБЫ СКОПИРОВАТЬ ЕГО", E_INFO);});
- connect(ui->weekly_code_widget, &WeeklyCodeWidget::showNoTooltip, this, [this](){unsetToolTipMessage(E_INFO);});
- connect(ui->news_list, &NewsListWidget::showHelpToolTip, this, [this](){setToolTipMessage("НАЖМИТЕ НА ЗАГОЛОВОК НОВОСТИ, ЧТОБЫ ОТКРЫТЬ ЕЕ В БРАУЗЕРЕ", E_INFO);});
- connect(ui->news_list, &NewsListWidget::showNoToolTip, this, [this](){unsetToolTipMessage(E_INFO);});
- connect(ui->server_status_widget, &ServerStatusWidget::showServersTooltip, this, [this](QString message){setToolTipMessage(message, E_INFO);});
- connect(ui->server_status_widget, &ServerStatusWidget::showNoTooltip, this, [this](){unsetToolTipMessage(E_INFO);});
- connect(legacy_patches_, &PatchList::patchOperationsStarted, this, &StatusWidget::onPatchTotalOperationsStarted);
- connect(legacy_patches_, &PatchList::patchOperationsFinished, this, &StatusWidget::onPatchTotalOperationsFinished);
- connect(legacy_patches_, &PatchList::progressChanged, this, &StatusWidget::onPatchTotalProgressChanged);
- foreach (Patch* patch, legacy_patches_->getPatchList()) {
- connect(patch, &Patch::progressChanged, this, &StatusWidget::onPatchProgressChanged);
- connect(patch, &Patch::operationStarted, this, &StatusWidget::onPatchOperationStarted);
- connect(patch, &Patch::operationFinished, this, &StatusWidget::onPatchOperationFinished);
- }
- generateRandomTooltipMessage();
- random_tooltip_generator_timer_.setInterval(5 * 1000);
- connect(&random_tooltip_generator_timer_, &QTimer::timeout, this, &StatusWidget::generateRandomTooltipMessage);
- random_tooltip_generator_timer_.start();
- }
- StatusWidget::~StatusWidget()
- {
- delete ui;
- }
- void StatusWidget::updateFontsSizes()
- {
- ui->game_button->setFont(trajan_11pt);
- ui->news_label->setFont(trajan_10pt);
- }
- void StatusWidget::setToolTipMessage(QString message, StatusWidget::ToolTipState state)
- {
- tooltip_messages_[state] = message;
- tooltip_state_ = ToolTipState(int(tooltip_state_) | int(state));
- qDebug() << "New tooltip state: " << int(tooltip_state_);
- if (tooltip_state_ < state * 2) {
- qDebug() << "Fading between tooltips";
- fadeBetweenToolTips(message);
- }
- }
- void StatusWidget::unsetToolTipMessage(StatusWidget::ToolTipState state)
- {
- tooltip_state_ = ToolTipState(int(tooltip_state_) & (~int(state)));
- qDebug() << "New tooltip state: " << int(tooltip_state_);
- if (tooltip_state_ & E_INFO) {
- fadeBetweenToolTips(tooltip_messages_[E_INFO]);
- } else if (tooltip_state_ & E_ERROR) {
- fadeBetweenToolTips(tooltip_messages_[E_ERROR]);
- } else if (tooltip_state_ & E_PROCESS) {
- fadeBetweenToolTips(tooltip_messages_[E_PROCESS]);
- } else {
- fadeBetweenToolTips(tooltip_messages_[E_RANDOM]);
- }
- }
- void StatusWidget::resizeEvent(QResizeEvent *)
- {
- double coefficient = window_width / default_window_width;
- // ui->game_button->move(QPoint(820, 460) * coefficient);
- // ui->game_button->resize(QSize(150, 60) * coefficient);
- // ui->progressBar->move(QPoint(320, 480) * coefficient);
- // ui->progressBar->resize(QSize(470, 40) * coefficient);
- // ui->progress_label->move(QPoint(330, 390) * coefficient);
- // ui->progress_label->resize(QSize(380, 90) * coefficient);
- // ui->news_label->move(QPoint(45, 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(240, 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->galadriel_widget->move(QPoint(320, 20) * coefficient);
- // ui->galadriel_widget->resize(QSize(531, 461) * coefficient);
- // ui->news_tooltip->move(QPoint(38, 13) * coefficient);
- // ui->news_tooltip->resize(QSize(365, 114) * coefficient);
- // ui->weekly_code_tooltip_1->move(QPoint(38, 13) * coefficient);
- // ui->weekly_code_tooltip_1->resize(QSize(365, 114) * coefficient);
- // ui->weekly_code_tooltip_2->move(QPoint(38, 13) * coefficient);
- // ui->weekly_code_tooltip_2->resize(QSize(365, 114) * coefficient);
- // ui->server_status_tooltip->move(QPoint(38, 13) * coefficient);
- // ui->server_status_tooltip->resize(QSize(365, 114) * coefficient);
- // ui->patches_status->move(QPoint(38, 13) * coefficient);
- // ui->patches_status->resize(QSize(385, 114) * coefficient);
- updateFontsSizes();
- }
- void StatusWidget::generateRandomTooltipMessage()
- {
- quint32 number = QRandomGenerator::system()->generate();
- setToolTipMessage("СЛУЧАЙНОЕ СООБЩЕНИЕ №" + QString::number(number), E_RANDOM);
- }
- void StatusWidget::fadeBetweenToolTips(QString next_tooltip_message)
- {
- if (next_tooltip_message == current_tooltip_message_) {
- return;
- }
- if (!tooltip_widgets_.contains(next_tooltip_message)) {
- createTooltipMessageWidget(next_tooltip_message);
- }
- QPropertyAnimation* showing_anim = tooltip_animations_[next_tooltip_message];
- showing_anim->setDirection(QAbstractAnimation::Forward);
- if (showing_anim->state() == QAbstractAnimation::Stopped)
- showing_anim->start();
- if (tooltip_widgets_.contains(current_tooltip_message_)) {
- QString msg = current_tooltip_message_;
- connect(tooltip_animations_[current_tooltip_message_], &QPropertyAnimation::finished, this, [&, msg](){
- if (tooltip_effects_.contains(msg) && tooltip_effects_[msg]->opacity() == 0) {
- qDebug() << "Deleting " << msg;
- tooltip_widgets_.take(msg)->deleteLater();
- tooltip_effects_.take(msg)->deleteLater();
- tooltip_animations_.take(msg)->deleteLater();
- }
- });
- QPropertyAnimation* hiding_anim = tooltip_animations_[current_tooltip_message_];
- hiding_anim->setDirection(QAbstractAnimation::Backward);
- if (hiding_anim->state() == QAbstractAnimation::Stopped)
- hiding_anim->start();
- }
- current_tooltip_message_ = next_tooltip_message;
- }
- void StatusWidget::onPatchTotalOperationsStarted()
- {
- all_patch_operations_finished_ = false;
- ui->game_button->setEnabled(false);
- ui->check_for_updates_button->setEnabled(false);
- }
- void StatusWidget::onPatchTotalOperationsFinished()
- {
- all_patch_operations_finished_ = true;
- ui->game_button->setEnabled(true);
- ui->check_for_updates_button->setEnabled(true);
- // for (Patch* patch : legacy_patches_->getPatchList()) {
- // QString label_name = patch->getPatchName().toLower() + "_status";
- // QLabel *label = findChild<QLabel*>(label_name);
- // if (!label) {
- // return;
- // }
- // QString install_date;
- // if (!(install_date = Settings::getValue("UpdateDates/" + patch->getPatchName()).toString()).isEmpty()) {
- // label->setText("Патч версии от " + install_date);
- // } else {
- // label->setText("Все операции с патчем завершены.");
- // }
- // }
- // ui->progress_label->setText("");
- }
- void StatusWidget::onPatchOperationStarted(Patch::Operation operation, Patch *patch)
- {
- // QString label_name = patch->getPatchName().toLower() + "_status";
- // QLabel *label = findChild<QLabel*>(label_name);
- // patch_operations[patch] = operation;
- // if (!label) {
- // return;
- // }
- // switch (operation) {
- // case Patch::E_CHECKFORUPDATES:
- // label->setText("Проверка наличия обновлений...");
- // break;
- // case Patch::E_DOWNLOAD:
- // label->setText("Подготовка к загрузке данных...");
- // break;
- // case Patch::E_INSTALL:
- // label->setText("Ожидание начала установки...");
- // break;
- // case Patch::E_ACTIVATE:
- // label->setText("Ожидание начала активации...");
- // default:
- // break;
- // }
- }
- void StatusWidget::onPatchOperationFinished(Patch::Operation operation, Patch *patch)
- {
- // if (all_patch_operations_finished_) {
- // return;
- // }
- // QString label_name = patch->getPatchName().toLower() + "_status";
- // QLabel *label = findChild<QLabel*>(label_name);
- // if (!label) {
- // return;
- // }
- // switch (operation) {
- // case Patch::E_CHECKFORUPDATES:
- // label->setText("Проверка обновлений завершена");
- // break;
- // case Patch::E_DOWNLOAD:
- // label->setText("Загрузка данных завершена");
- // break;
- // case Patch::E_INSTALL:
- // label->setText("Установка патча завершена");
- // break;
- // case Patch::E_ACTIVATE:
- // label->setText("Активация патча завершена");
- // default:
- // break;
- // }
- }
- void StatusWidget::onPatchTotalProgressChanged(Patch::OperationProgress operation_progress)
- {
- // updateStatusBar(operation_progress);
- }
- void StatusWidget::on_game_button_clicked()
- {
- MainWindow* window = qobject_cast<MainWindow*>(parentWidget()->parentWidget()->parentWidget());
- window->showChooseVersionDialog();
- }
- void StatusWidget::onPatchProgressChanged(Patch::OperationProgress progress, Patch *patch)
- {
- // QString label_name = patch->getPatchName().toLower() + "_status";
- // QLabel *label = findChild<QLabel*>(label_name);
- // if (!label) {
- // return;
- // }
- // switch (patch_operations[patch]) {
- // case Patch::E_CHECKFORUPDATES:
- // label->setText("Проверка наличия обновлений...");
- // break;
- // case Patch::E_DOWNLOAD:
- // label->setText("Загрузка... " + QString::number(progress.getDownloadPercent(), 'f', 1)
- // + "% (" + Downloader::getSizeFormatted(progress.download_finished_bytes)
- // + "/" + Downloader::getSizeFormatted(progress.download_total_bytes) + ")");
- // break;
- // case Patch::E_INSTALL:
- // label->setText("Установка... " + QString::number(progress.getInstallPercent(), 'f', 2)
- // + "% (" + QString::number(progress.install_finished_parts) + "/" + QString::number(progress.install_total_parts) + ")");
- // break;
- // case Patch::E_ACTIVATE:
- // label->setText("Активация... " + QString::number(progress.getInstallPercent(), 'f', 2)
- // + "% (" + QString::number(progress.install_finished_parts) + "/" + QString::number(progress.install_total_parts) + ")");
- // default:
- // break;
- // }
- }
- void StatusWidget::updateStatusBar(Patch::OperationProgress progress)
- {
- // if (last_statusbar_update_time_.elapsed() > 500) {
- // QString text = "Выполнение операций...";
- // if (progress.download_total_bytes != 0) {
- // text += "\nЗагрузка данных: " + QString::number(progress.getDownloadPercent(), 'f', 1) + "% ("
- // + Downloader::getSizeFormatted(progress.download_finished_bytes) + "/"
- // + Downloader::getSizeFormatted(progress.download_total_bytes) + ", "
- // + Downloader::getSpeedFormatted(progress.download_speed) + ")\n"
- // + "До конца загрузки: " + Downloader::getElapsedTimeFormatted(progress.download_elapsed_time);
- // }
- // if (progress.install_total_parts != 0) {
- // text += "\nПрименение патчей: " + QString::number(progress.getInstallPercent()) + "% "
- // + "(часть " + QString::number(progress.install_finished_parts + 1) + " из " + QString::number(progress.install_total_parts);
- // }
- // ui->progress_label->setText(text);
- // last_statusbar_update_time_.restart();
- // }
- }
- void StatusWidget::createTooltipMessageWidget(QString tooltip_message)
- {
- qDebug() << "Creating:" << tooltip_message;
- tooltip_widgets_[tooltip_message] = new QLabel(ui->galadriel_widget);
- tooltip_widgets_[tooltip_message]->setText(tooltip_message);
- tooltip_widgets_[tooltip_message]->setGeometry(ui->galadriel_tooltip_example->geometry());
- tooltip_widgets_[tooltip_message]->setStyleSheet(ui->galadriel_tooltip_example->styleSheet());
- tooltip_widgets_[tooltip_message]->setFont(ui->galadriel_tooltip_example->font());
- tooltip_widgets_[tooltip_message]->setWordWrap(true);
- tooltip_widgets_[tooltip_message]->setAlignment(Qt::AlignCenter);
- tooltip_widgets_[tooltip_message]->show();
- tooltip_effects_[tooltip_message] = new QGraphicsOpacityEffect(tooltip_widgets_[tooltip_message]);
- tooltip_effects_[tooltip_message]->setOpacity(0);
- tooltip_animations_[tooltip_message] = new QPropertyAnimation(tooltip_effects_[tooltip_message], "opacity");
- tooltip_animations_[tooltip_message]->setDuration(350);
- tooltip_animations_[tooltip_message]->setStartValue(0);
- tooltip_animations_[tooltip_message]->setEndValue(1);
- tooltip_animations_[tooltip_message]->setDirection(QAbstractAnimation::Forward);
- tooltip_widgets_[tooltip_message]->setGraphicsEffect(tooltip_effects_[tooltip_message]);
- }
- void StatusWidget::on_check_for_updates_button_clicked()
- {
- QMetaObject::invokeMethod(legacy_patches_, &PatchList::update, Qt::QueuedConnection);
- }
|