From 5745862fa8c768db16b8251a419b60446acc7c2b Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sat, 4 May 2024 23:09:02 +0200 Subject: [PATCH] Qt: properly hide and show progress indicator This was previously always shown, since we never really re-used the progress dialogs. --- rpcs3/rpcs3qt/progress_dialog.cpp | 41 +++++++++++++++++++++------- rpcs3/rpcs3qt/progress_dialog.h | 4 +++ rpcs3/rpcs3qt/progress_indicator.cpp | 7 +++++ rpcs3/rpcs3qt/progress_indicator.h | 1 + 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/rpcs3/rpcs3qt/progress_dialog.cpp b/rpcs3/rpcs3qt/progress_dialog.cpp index 98e5febf87..9ad405c71f 100644 --- a/rpcs3/rpcs3qt/progress_dialog.cpp +++ b/rpcs3/rpcs3qt/progress_dialog.cpp @@ -16,17 +16,7 @@ progress_dialog::progress_dialog(const QString& windowTitle, const QString& labe SetDeleteOnClose(); } - // Try to find a window handle first - QWindow* handle = windowHandle(); - - for (QWidget* ancestor = this; !handle && ancestor;) - { - ancestor = static_cast(ancestor->parent()); - if (ancestor) handle = ancestor->windowHandle(); - } - m_progress_indicator = std::make_unique(minimum, maximum); - m_progress_indicator->show(handle); } progress_dialog::~progress_dialog() @@ -61,3 +51,34 @@ void progress_dialog::SignalFailure() const QApplication::beep(); } + +void progress_dialog::show_progress_indicator() +{ + // Try to find a window handle first + QWindow* handle = windowHandle(); + + for (QWidget* ancestor = this; !handle && ancestor;) + { + ancestor = static_cast(ancestor->parent()); + if (ancestor) handle = ancestor->windowHandle(); + } + + m_progress_indicator->show(handle); +} + +void progress_dialog::setVisible(bool visible) +{ + if (visible) + { + if (!isVisible()) + { + show_progress_indicator(); + } + } + else if (isVisible()) + { + m_progress_indicator->hide(); + } + + QProgressDialog::setVisible(visible); +} diff --git a/rpcs3/rpcs3qt/progress_dialog.h b/rpcs3/rpcs3qt/progress_dialog.h index 930ce2cb07..a27c31784e 100644 --- a/rpcs3/rpcs3qt/progress_dialog.h +++ b/rpcs3/rpcs3qt/progress_dialog.h @@ -14,6 +14,10 @@ public: void SetDeleteOnClose(); void SignalFailure() const; + void show_progress_indicator(); + + void setVisible(bool visible) override; + private: std::unique_ptr m_progress_indicator; }; diff --git a/rpcs3/rpcs3qt/progress_indicator.cpp b/rpcs3/rpcs3qt/progress_indicator.cpp index 3130444fbf..0baa65e725 100644 --- a/rpcs3/rpcs3qt/progress_indicator.cpp +++ b/rpcs3/rpcs3qt/progress_indicator.cpp @@ -46,6 +46,13 @@ void progress_indicator::show(QWindow* window) #endif } +void progress_indicator::hide() +{ +#ifdef HAS_QT_WIN_STUFF + m_tb_button->progress()->hide(); +#endif +} + int progress_indicator::value() const { #ifdef HAS_QT_WIN_STUFF diff --git a/rpcs3/rpcs3qt/progress_indicator.h b/rpcs3/rpcs3qt/progress_indicator.h index 9e27f40ab4..eff8dd1a68 100644 --- a/rpcs3/rpcs3qt/progress_indicator.h +++ b/rpcs3/rpcs3qt/progress_indicator.h @@ -13,6 +13,7 @@ public: ~progress_indicator(); void show(QWindow* window); + void hide(); int value() const;