From a2d855b102d0efba927519f607fb5bf6ad8a821d Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 27 Nov 2020 14:47:31 +1100 Subject: [PATCH] improve UI feedback when cancelling a task --- app/dialog/progress/progress.cpp | 31 ++++++++++++++++++-- app/dialog/progress/progress.h | 7 +++++ app/widget/taskview/elapsedcounterwidget.cpp | 5 ++++ app/widget/taskview/elapsedcounterwidget.h | 3 ++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/dialog/progress/progress.cpp b/app/dialog/progress/progress.cpp index 3024dffca..3b46c8926 100644 --- a/app/dialog/progress/progress.cpp +++ b/app/dialog/progress/progress.cpp @@ -30,7 +30,8 @@ namespace olive { ProgressDialog::ProgressDialog(const QString& message, const QString& title, QWidget *parent) : - QDialog(parent) + QDialog(parent), + show_progress_(true) { if (!title.isEmpty()) { setWindowTitle(title); @@ -56,7 +57,19 @@ ProgressDialog::ProgressDialog(const QString& message, const QString& title, QWi cancel_layout->addStretch(); QPushButton* cancel_btn = new QPushButton(tr("Cancel")); - connect(cancel_btn, &QPushButton::clicked, this, &ProgressDialog::Cancelled); + + // Signal that derivatives can connect to + connect(cancel_btn, &QPushButton::clicked, this, &ProgressDialog::Cancelled, Qt::DirectConnection); + + // Stop updating the elapsed/remaining timers + connect(cancel_btn, &QPushButton::clicked, elapsed_timer_lbl_, &ElapsedCounterWidget::Stop); + + // Disable the button so that users know they don't need to keep clicking it + connect(cancel_btn, &QPushButton::clicked, this, &ProgressDialog::DisableSenderWidget); + + // Prevent the progress bar from continuing to move + connect(cancel_btn, &QPushButton::clicked, this, &ProgressDialog::DisableProgressWidgets); + cancel_layout->addWidget(cancel_btn); cancel_layout->addStretch(); @@ -80,6 +93,10 @@ void ProgressDialog::closeEvent(QCloseEvent *e) void ProgressDialog::SetProgress(double value) { + if (!show_progress_) { + return; + } + int percent = qRound(100.0 * value); bar_->setValue(percent); @@ -101,4 +118,14 @@ void ProgressDialog::ShowErrorMessage(const QString &title, const QString &messa b.exec(); } +void ProgressDialog::DisableSenderWidget() +{ + static_cast(sender())->setEnabled(false); +} + +void ProgressDialog::DisableProgressWidgets() +{ + show_progress_ = false; +} + } diff --git a/app/dialog/progress/progress.h b/app/dialog/progress/progress.h index 75103a900..38e2854b1 100644 --- a/app/dialog/progress/progress.h +++ b/app/dialog/progress/progress.h @@ -54,6 +54,13 @@ private: ElapsedCounterWidget* elapsed_timer_lbl_; + bool show_progress_; + +private slots: + void DisableSenderWidget(); + + void DisableProgressWidgets(); + }; } diff --git a/app/widget/taskview/elapsedcounterwidget.cpp b/app/widget/taskview/elapsedcounterwidget.cpp index d8cc976d0..e38c5e4b8 100644 --- a/app/widget/taskview/elapsedcounterwidget.cpp +++ b/app/widget/taskview/elapsedcounterwidget.cpp @@ -65,6 +65,11 @@ void ElapsedCounterWidget::Start(qint64 start_time) UpdateTimers(); } +void ElapsedCounterWidget::Stop() +{ + elapsed_timer_.stop(); +} + void ElapsedCounterWidget::UpdateTimers() { int64_t elapsed_ms, remaining_ms; diff --git a/app/widget/taskview/elapsedcounterwidget.h b/app/widget/taskview/elapsedcounterwidget.h index 902b11fd4..d85d7ba70 100644 --- a/app/widget/taskview/elapsedcounterwidget.h +++ b/app/widget/taskview/elapsedcounterwidget.h @@ -40,6 +40,9 @@ public: void Start(); void Start(qint64 start_time); +public slots: + void Stop(); + private: QLabel* elapsed_lbl_;