improve UI feedback when cancelling a task

This commit is contained in:
itsmattkc
2020-11-27 14:47:31 +11:00
parent 0fa05e1bc9
commit a2d855b102
4 changed files with 44 additions and 2 deletions
+29 -2
View File
@@ -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<QWidget*>(sender())->setEnabled(false);
}
void ProgressDialog::DisableProgressWidgets()
{
show_progress_ = false;
}
}
+7
View File
@@ -54,6 +54,13 @@ private:
ElapsedCounterWidget* elapsed_timer_lbl_;
bool show_progress_;
private slots:
void DisableSenderWidget();
void DisableProgressWidgets();
};
}
@@ -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;
@@ -40,6 +40,9 @@ public:
void Start();
void Start(qint64 start_time);
public slots:
void Stop();
private:
QLabel* elapsed_lbl_;