From 365e3fb9656ab69a65c5aa469de0e6b4dc8e0c22 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 24 Nov 2023 16:08:28 +1000 Subject: [PATCH] Qt: Fix progress dialog cancelling --- src/duckstation-qt/qtprogresscallback.cpp | 11 ++++++----- src/duckstation-qt/qtprogresscallback.h | 11 ++++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/duckstation-qt/qtprogresscallback.cpp b/src/duckstation-qt/qtprogresscallback.cpp index db6da6750..832e72755 100644 --- a/src/duckstation-qt/qtprogresscallback.cpp +++ b/src/duckstation-qt/qtprogresscallback.cpp @@ -16,16 +16,12 @@ QtModalProgressCallback::QtModalProgressCallback(QWidget* parent_widget, float s m_dialog.setModal(parent_widget != nullptr); m_dialog.setAutoClose(false); m_dialog.setAutoReset(false); + connect(&m_dialog, &QProgressDialog::canceled, this, &QtModalProgressCallback::dialogCancelled); checkForDelayedShow(); } QtModalProgressCallback::~QtModalProgressCallback() = default; -bool QtModalProgressCallback::IsCancelled() const -{ - return m_dialog.wasCanceled(); -} - void QtModalProgressCallback::SetCancellable(bool cancellable) { if (m_cancellable == cancellable) @@ -105,6 +101,11 @@ void QtModalProgressCallback::ModalInformation(const char* message) QMessageBox::information(&m_dialog, tr("Information"), QString::fromUtf8(message)); } +void QtModalProgressCallback::dialogCancelled() +{ + m_cancelled = true; +} + void QtModalProgressCallback::checkForDelayedShow() { if (m_dialog.isVisible()) diff --git a/src/duckstation-qt/qtprogresscallback.h b/src/duckstation-qt/qtprogresscallback.h index e271ed7e9..98ab41e97 100644 --- a/src/duckstation-qt/qtprogresscallback.h +++ b/src/duckstation-qt/qtprogresscallback.h @@ -1,11 +1,13 @@ -// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once + #include "common/progress_callback.h" #include "common/timer.h" -#include + #include +#include #include #include @@ -17,7 +19,7 @@ public: QtModalProgressCallback(QWidget* parent_widget, float show_delay = 0.0f); ~QtModalProgressCallback(); - bool IsCancelled() const override; + QProgressDialog& GetDialog() { return m_dialog; } void SetCancellable(bool cancellable) override; void SetTitle(const char* title) override; @@ -34,6 +36,9 @@ public: bool ModalConfirmation(const char* message) override; void ModalInformation(const char* message) override; +private Q_SLOTS: + void dialogCancelled(); + private: void checkForDelayedShow();