Przeglądaj źródła

Finished with Galadriel widget interface impl

Ivan Arkhipov 4 lat temu
rodzic
commit
d651758911
2 zmienionych plików z 84 dodań i 177 usunięć
  1. 79 169
      src/Legacy/widgets/statuswidget.cpp
  2. 5 8
      src/Legacy/widgets/statuswidget.h

+ 79 - 169
src/Legacy/widgets/statuswidget.cpp

@@ -34,18 +34,15 @@ StatusWidget::StatusWidget(PatchList *legacy_patches, QWidget *parent)
 
     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);
-    }
+    connect(legacy_patches_, &PatchList::progressChanged, this, &StatusWidget::updatePatchProgressStatus);
 
     generateRandomTooltipMessage();
     random_tooltip_generator_timer_.setInterval(5 * 1000);
     connect(&random_tooltip_generator_timer_, &QTimer::timeout, this, &StatusWidget::generateRandomTooltipMessage);
     random_tooltip_generator_timer_.start();
+
+    process_completed_tooltip_hide_timer_.setInterval(10 * 1000); // 10 seconds message "Installation completed" will be shown
+    connect(&process_completed_tooltip_hide_timer_, &QTimer::timeout, this, [this](){unsetToolTipMessage(E_PROCESS);});
 }
 
 StatusWidget::~StatusWidget()
@@ -65,9 +62,19 @@ void StatusWidget::setToolTipMessage(QString message, StatusWidget::ToolTipState
     tooltip_state_ = ToolTipState(int(tooltip_state_) | int(state));
     qDebug() << "New tooltip state: " << int(tooltip_state_);
 
+    QString message_id = message;
+    if (state == E_PROCESS) {
+        message_id = "E_PROCESS";
+    }
+
+    if (!tooltip_widgets_.contains(message_id)) {
+        createTooltipMessageWidget(message_id);
+    }
+    tooltip_widgets_[message_id]->setText(message);
+
     if (tooltip_state_ < state * 2) {
         qDebug() << "Fading between tooltips";
-        fadeBetweenToolTips(message);
+        fadeBetweenToolTips(message_id);
     }
 }
 
@@ -76,15 +83,26 @@ void StatusWidget::unsetToolTipMessage(StatusWidget::ToolTipState state)
     tooltip_state_ = ToolTipState(int(tooltip_state_) & (~int(state)));
     qDebug() << "New tooltip state: " << int(tooltip_state_);
 
+    ToolTipState showing_state = E_RANDOM;
+
     if (tooltip_state_ & E_INFO) {
-        fadeBetweenToolTips(tooltip_messages_[E_INFO]);
+        showing_state = E_INFO;
     } else if (tooltip_state_ & E_ERROR) {
-        fadeBetweenToolTips(tooltip_messages_[E_ERROR]);
+        showing_state = E_ERROR;
     } else if (tooltip_state_ & E_PROCESS) {
-        fadeBetweenToolTips(tooltip_messages_[E_PROCESS]);
-    } else {
-        fadeBetweenToolTips(tooltip_messages_[E_RANDOM]);
+        showing_state = E_PROCESS;
     }
+
+    QString message_id = tooltip_messages_[showing_state];
+    if (showing_state == E_PROCESS) {
+        message_id = "E_PROCESS";
+    }
+
+    if (!tooltip_widgets_.contains(message_id)) {
+        createTooltipMessageWidget(message_id);
+    }
+    tooltip_widgets_[message_id]->setText(tooltip_messages_[showing_state]);
+    fadeBetweenToolTips(message_id);
 }
 
 void StatusWidget::resizeEvent(QResizeEvent *)
@@ -128,20 +146,17 @@ void StatusWidget::generateRandomTooltipMessage()
     setToolTipMessage("СЛУЧАЙНОЕ СООБЩЕНИЕ №" + QString::number(number), E_RANDOM);
 }
 
-void StatusWidget::fadeBetweenToolTips(QString next_tooltip_message)
+void StatusWidget::fadeBetweenToolTips(QString tooltip_id)
 {
-    if (next_tooltip_message == current_tooltip_message_) {
+    if (tooltip_id == current_tooltip_message_) {
         return;
     }
 
-    if (!tooltip_widgets_.contains(next_tooltip_message)) {
-        createTooltipMessageWidget(next_tooltip_message);
-    }
-
-    QPropertyAnimation* showing_anim = tooltip_animations_[next_tooltip_message];
+    QPropertyAnimation* showing_anim = tooltip_animations_[tooltip_id];
     showing_anim->setDirection(QAbstractAnimation::Forward);
-    if (showing_anim->state() == QAbstractAnimation::Stopped)
+    if (showing_anim->state() == QAbstractAnimation::Stopped) {
         showing_anim->start();
+    }
 
     if (tooltip_widgets_.contains(current_tooltip_message_)) {
         QString msg = current_tooltip_message_;
@@ -156,11 +171,12 @@ void StatusWidget::fadeBetweenToolTips(QString next_tooltip_message)
 
         QPropertyAnimation* hiding_anim = tooltip_animations_[current_tooltip_message_];
         hiding_anim->setDirection(QAbstractAnimation::Backward);
-        if (hiding_anim->state() == QAbstractAnimation::Stopped)
+        if (hiding_anim->state() == QAbstractAnimation::Stopped) {
             hiding_anim->start();
+        }
     }
 
-    current_tooltip_message_ = next_tooltip_message;
+    current_tooltip_message_ = tooltip_id;
 }
 
 void StatusWidget::onPatchTotalOperationsStarted()
@@ -168,6 +184,7 @@ void StatusWidget::onPatchTotalOperationsStarted()
     all_patch_operations_finished_ = false;
     ui->game_button->setEnabled(false);
     ui->check_for_updates_button->setEnabled(false);
+    setToolTipMessage("Запуск процесса проверки и установки русификации...", E_PROCESS);
 }
 
 void StatusWidget::onPatchTotalOperationsFinished()
@@ -175,84 +192,8 @@ 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);
+    setToolTipMessage("Все процессы установки русификации завершены. Можно играть. Mae govannen. Еще какой-то текст...", E_PROCESS);
+    process_completed_tooltip_hide_timer_.start();
 }
 
 void StatusWidget::on_game_button_clicked()
@@ -261,79 +202,48 @@ void StatusWidget::on_game_button_clicked()
     window->showChooseVersionDialog();
 }
 
-void StatusWidget::onPatchProgressChanged(Patch::OperationProgress progress, Patch *patch)
+void StatusWidget::updatePatchProgressStatus(Patch::OperationProgress progress)
 {
-//    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;
-//    }
-}
+    if (last_statusbar_update_time_.elapsed() > 400) {
+        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);
+        }
 
-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();
-    //    }
+        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);
+        }
+
+        setToolTipMessage(text, E_PROCESS);
+        last_statusbar_update_time_.restart();
+    }
 }
 
-void StatusWidget::createTooltipMessageWidget(QString tooltip_message)
+void StatusWidget::createTooltipMessageWidget(QString tooltip_id)
 {
-    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]);
+    tooltip_widgets_[tooltip_id] = new QLabel(ui->galadriel_widget);
+    tooltip_widgets_[tooltip_id]->setGeometry(ui->galadriel_tooltip_example->geometry());
+    tooltip_widgets_[tooltip_id]->setStyleSheet(ui->galadriel_tooltip_example->styleSheet());
+    tooltip_widgets_[tooltip_id]->setFont(ui->galadriel_tooltip_example->font());
+    tooltip_widgets_[tooltip_id]->setWordWrap(true);
+    tooltip_widgets_[tooltip_id]->setAlignment(Qt::AlignCenter);
+    tooltip_widgets_[tooltip_id]->show();
+
+    tooltip_effects_[tooltip_id] = new QGraphicsOpacityEffect(tooltip_widgets_[tooltip_id]);
+    tooltip_effects_[tooltip_id]->setOpacity(0);
+
+    tooltip_animations_[tooltip_id] = new QPropertyAnimation(tooltip_effects_[tooltip_id], "opacity");
+    tooltip_animations_[tooltip_id]->setDuration(300);
+    tooltip_animations_[tooltip_id]->setStartValue(0);
+    tooltip_animations_[tooltip_id]->setEndValue(1);
+    tooltip_animations_[tooltip_id]->setDirection(QAbstractAnimation::Forward);
+
+    tooltip_widgets_[tooltip_id]->setGraphicsEffect(tooltip_effects_[tooltip_id]);
 }
 
 void StatusWidget::on_check_for_updates_button_clicked()

+ 5 - 8
src/Legacy/widgets/statuswidget.h

@@ -44,25 +44,21 @@ protected:
 private slots:
     void generateRandomTooltipMessage();
 
-    void fadeBetweenToolTips(QString tooltip_message);
+    void fadeBetweenToolTips(QString tooltip_id);
 
     void onPatchTotalOperationsStarted();
-    void onPatchTotalOperationsFinished();
 
-    void onPatchOperationStarted(Patch::Operation operation, Patch* patch);
-    void onPatchOperationFinished(Patch::Operation operation, Patch* patch);
+    void onPatchTotalOperationsFinished();
 
-    void onPatchTotalProgressChanged(Patch::OperationProgress operation_progress);
-    void onPatchProgressChanged(Patch::OperationProgress progress, Patch* patch);
+    void updatePatchProgressStatus(Patch::OperationProgress progress);
 
     void on_game_button_clicked();
 
     void on_check_for_updates_button_clicked();
 
 private:
-    void updateStatusBar(Patch::OperationProgress progress);
+    void createTooltipMessageWidget(QString tooltip_id);
 
-    void createTooltipMessageWidget(QString tooltip_message);
 private:
     Ui::StatusWidget *ui;
 
@@ -83,6 +79,7 @@ private:
     QMap<ToolTipState, QString> tooltip_messages_;
 
     QTimer random_tooltip_generator_timer_;
+    QTimer process_completed_tooltip_hide_timer_;
 };
 
 #endif // STATUSWIDGET_H