From 276943c8b791ba5897dcdb1ecfda780ac33a090b Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 15 Sep 2021 09:58:27 +0200 Subject: [PATCH] Make the closeAllPopup helper virtual in QGuiApplication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QPA plugins might have to close popups for events that are not delivered to QWindow or QWidget instances. For instance, the Cocoa plugin has to explicilty close popups when the user clicks into the window frame. Expose this functionality through a virtual in QGuiApplicationPrivate, and move the QApplication implementation from a static helper into the override. Task-number: QTBUG-96450 Change-Id: I52be5710c8d7515b9ae2e4bbadb069df4b3ed546 Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qguiapplication_p.h | 1 + src/widgets/kernel/qapplication.cpp | 23 ++++++++++++----------- src/widgets/kernel/qapplication_p.h | 1 + 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index b98a1b9ecf..7b28c70993 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -223,6 +223,7 @@ public: static void updateBlockedStatus(QWindow *window); virtual bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = nullptr) const; virtual bool popupActive() { return false; } + virtual bool closeAllPopups() { return false; } static Qt::MouseButton mousePressButton; static QPointF lastCursorPosition; diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index de450923ff..9069b9005d 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -2628,16 +2628,6 @@ bool QApplicationPrivate::shouldQuit() return QGuiApplicationPrivate::shouldQuitInternal(processedWindows); } -static inline void closeAllPopups() -{ - // Close all popups: In case some popup refuses to close, - // we give up after 1024 attempts (to avoid an infinite loop). - int maxiter = 1024; - QWidget *popup; - while ((popup = QApplication::activePopupWidget()) && maxiter--) - popup->close(); -} - /*! \reimp */ bool QApplication::notify(QObject *receiver, QEvent *e) @@ -2711,7 +2701,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) // Close all popups (triggers when switching applications // by pressing ALT-TAB on Windows, which is not receive as key event. // triggers when the screen rotates.) - closeAllPopups(); + d->closeAllPopups(); break; case QEvent::Wheel: // User input and window activation makes tooltips sleep case QEvent::ActivationChange: @@ -3444,6 +3434,17 @@ extern QWidget *qt_popup_down; extern bool qt_replay_popup_mouse_event; extern bool qt_popup_down_closed; +bool QApplicationPrivate::closeAllPopups() +{ + // Close all popups: In case some popup refuses to close, + // we give up after 1024 attempts (to avoid an infinite loop). + int maxiter = 1024; + QWidget *popup; + while ((popup = QApplication::activePopupWidget()) && maxiter--) + popup->close(); // this will call QApplicationPrivate::closePopup + return true; +} + void QApplicationPrivate::closePopup(QWidget *popup) { if (!popupWidgets) diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index ee41f91060..59c13f06af 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -145,6 +145,7 @@ public: static bool inPopupMode(); bool popupActive() override { return inPopupMode(); } + bool closeAllPopups() override; void closePopup(QWidget *popup); void openPopup(QWidget *popup); static void setFocusWidget(QWidget *focus, Qt::FocusReason reason);