From 2f9bdeba17ac1e980c0b9702c4f346c242da6ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 17 Jan 2018 14:49:55 +0100 Subject: Add QPlatformWindow::close() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Platforms can reimplement this function to control how non-spontaneous window close is handled. Make QWindow::close() call this function. Change-Id: I3da13e6c8519de2af7e54334d8a1e833ce98cba1 Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qplatformwindow.cpp | 14 ++++++++++++++ src/gui/kernel/qplatformwindow.h | 1 + src/gui/kernel/qwindow.cpp | 5 +---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index a66420c364..a3046a9b44 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -339,6 +339,20 @@ void QPlatformWindow::setWindowFilePath(const QString &filePath) { Q_UNUSED(file */ void QPlatformWindow::setWindowIcon(const QIcon &icon) { Q_UNUSED(icon); } +/*! + Reimplement to let the platform handle non-spontaneous window close. + + When reimplementing make sure to call the base class implementation + or QWindowSystemInterface::handleCloseEvent(), which will prompt the + user to accept the window close (if needed) and then close the QWindow. +*/ +bool QPlatformWindow::close() +{ + bool accepted = false; + QWindowSystemInterface::handleCloseEvent(window(), &accepted); + return accepted; +} + /*! Reimplement to be able to let Qt raise windows to the top of the desktop */ diff --git a/src/gui/kernel/qplatformwindow.h b/src/gui/kernel/qplatformwindow.h index 84dff681d5..bba6390694 100644 --- a/src/gui/kernel/qplatformwindow.h +++ b/src/gui/kernel/qplatformwindow.h @@ -100,6 +100,7 @@ public: virtual void setWindowTitle(const QString &title); virtual void setWindowFilePath(const QString &title); virtual void setWindowIcon(const QIcon &icon); + virtual bool close(); virtual void raise(); virtual void lower(); diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 2c7e061bcf..5db740acb9 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -2144,10 +2144,7 @@ bool QWindow::close() if (!d->platformWindow) return true; - bool accepted = false; - QWindowSystemInterface::handleCloseEvent(this, &accepted); - QWindowSystemInterface::flushWindowSystemEvents(); - return accepted; + return d->platformWindow->close(); } /*! -- cgit v1.2.3