diff --git a/app/dialog/progress/progress.cpp b/app/dialog/progress/progress.cpp index 421404793..32f47e6e5 100644 --- a/app/dialog/progress/progress.cpp +++ b/app/dialog/progress/progress.cpp @@ -29,9 +29,12 @@ namespace olive { +#define super QDialog + ProgressDialog::ProgressDialog(const QString& message, const QString& title, QWidget *parent) : - QDialog(parent), - show_progress_(true) + super(parent), + show_progress_(true), + first_show_(true) { if (!title.isEmpty()) { setWindowTitle(title); @@ -77,18 +80,26 @@ ProgressDialog::ProgressDialog(const QString& message, const QString& title, QWi void ProgressDialog::showEvent(QShowEvent *e) { - QDialog::showEvent(e); + super::showEvent(e); - elapsed_timer_lbl_->Start(); + if (first_show_) { + elapsed_timer_lbl_->Start(); - Core::instance()->main_window()->SetApplicationProgressStatus(MainWindow::kProgressShow); + Core::instance()->main_window()->SetApplicationProgressStatus(MainWindow::kProgressShow); + + first_show_ = false; + } } void ProgressDialog::closeEvent(QCloseEvent *e) { - QDialog::closeEvent(e); + super::closeEvent(e); Core::instance()->main_window()->SetApplicationProgressStatus(MainWindow::kProgressNone); + + elapsed_timer_lbl_->Stop(); + + first_show_ = true; } void ProgressDialog::SetProgress(double value) diff --git a/app/dialog/progress/progress.h b/app/dialog/progress/progress.h index cbe450b69..123417762 100644 --- a/app/dialog/progress/progress.h +++ b/app/dialog/progress/progress.h @@ -56,6 +56,8 @@ private: bool show_progress_; + bool first_show_; + private slots: void DisableSenderWidget(); diff --git a/app/dialog/task/task.cpp b/app/dialog/task/task.cpp index 504411e97..8b16bd944 100644 --- a/app/dialog/task/task.cpp +++ b/app/dialog/task/task.cpp @@ -24,10 +24,13 @@ namespace olive { +#define super ProgressDialog + TaskDialog::TaskDialog(Task* task, const QString& title, QWidget *parent) : - ProgressDialog(task->GetTitle(), title, parent), + super(task->GetTitle(), title, parent), task_(task), - destroy_on_close_(true) + destroy_on_close_(true), + already_shown_(false) { // Clear task when this dialog is destroyed task_->setParent(this); @@ -42,17 +45,21 @@ TaskDialog::TaskDialog(Task* task, const QString& title, QWidget *parent) : void TaskDialog::showEvent(QShowEvent *e) { - ProgressDialog::showEvent(e); + super::showEvent(e); - // Create watcher for when the task finishes - QFutureWatcher* task_watcher = new QFutureWatcher(); + if (!already_shown_) { + // Create watcher for when the task finishes + QFutureWatcher* task_watcher = new QFutureWatcher(); - // Listen for when the task finishes - connect(task_watcher, &QFutureWatcher::finished, - this, &TaskDialog::TaskFinished, Qt::QueuedConnection); + // Listen for when the task finishes + connect(task_watcher, &QFutureWatcher::finished, + this, &TaskDialog::TaskFinished, Qt::QueuedConnection); - // Run task in another thread with QtConcurrent - task_watcher->setFuture(QtConcurrent::run(task_, &Task::Start)); + // Run task in another thread with QtConcurrent + task_watcher->setFuture(QtConcurrent::run(task_, &Task::Start)); + + already_shown_ = true; + } } void TaskDialog::closeEvent(QCloseEvent *e) @@ -61,7 +68,10 @@ void TaskDialog::closeEvent(QCloseEvent *e) task_->Cancel(); // Standard close function - ProgressDialog::closeEvent(e); + super::closeEvent(e); + + // Reset shown + already_shown_ = false; // Clean up this task and dialog if (destroy_on_close_) { diff --git a/app/dialog/task/task.h b/app/dialog/task/task.h index 7143d4b31..8abb4a060 100644 --- a/app/dialog/task/task.h +++ b/app/dialog/task/task.h @@ -72,6 +72,8 @@ private: bool destroy_on_close_; + bool already_shown_; + private slots: void TaskFinished();