From 0af228700e85167b9406193a38ea27584c6dc4d7 Mon Sep 17 00:00:00 2001 From: Jorgen Lind Date: Tue, 8 Jul 2014 13:24:24 +0200 Subject: Make QWindow::close go through the QWindowSystemInterface This causes a closeEvent to be sent for all calls to close. As a side effect destroy now handles more of the state in QGuiApplication. [ChangeLog][QtGui][QWindow] QWindow::close() sends a QCloseEvent which must be accepted before destroy() will be called. destroy() is the function to close the window without confirmation. Task-number: QTBUG-40093 Change-Id: I1ce09da4940fc29fae8decf40548a42e3bec6eca Reviewed-by: Shawn Rutledge --- src/gui/kernel/qwindow.cpp | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'src/gui/kernel/qwindow.cpp') diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 5630199da9..327544c59c 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -209,14 +209,8 @@ QWindow::QWindow(QWindowPrivate &dd, QWindow *parent) */ QWindow::~QWindow() { - if (QGuiApplicationPrivate::focus_window == this) - QGuiApplicationPrivate::focus_window = 0; - if (QGuiApplicationPrivate::currentMouseWindow == this) - QGuiApplicationPrivate::currentMouseWindow = 0; - if (QGuiApplicationPrivate::tabletPressTarget == this) - QGuiApplicationPrivate::tabletPressTarget = 0; - QGuiApplicationPrivate::window_list.removeAll(this); destroy(); + QGuiApplicationPrivate::window_list.removeAll(this); } void QWindowPrivate::init() @@ -1569,16 +1563,28 @@ void QWindow::destroy() QObject *object = childrenWindows.at(i); if (object->isWindowType()) { QWindow *w = static_cast(object); - QGuiApplicationPrivate::window_list.removeAll(w); w->destroy(); } } + + if (QGuiApplicationPrivate::focus_window == this) + QGuiApplicationPrivate::focus_window = parent(); + if (QGuiApplicationPrivate::currentMouseWindow == this) + QGuiApplicationPrivate::currentMouseWindow = parent(); + if (QGuiApplicationPrivate::tabletPressTarget == this) + QGuiApplicationPrivate::tabletPressTarget = parent(); + + bool wasVisible = isVisible(); + setVisible(false); delete d->platformWindow; d->resizeEventPending = true; d->receivedExpose = false; d->exposed = false; d->platformWindow = 0; + + if (wasVisible) + d->maybeQuitOnLastWindowClosed(); } /*! @@ -1839,15 +1845,10 @@ bool QWindow::close() if (!d->platformWindow) return true; - if (QGuiApplicationPrivate::focus_window == this) - QGuiApplicationPrivate::focus_window = 0; - if (QGuiApplicationPrivate::currentMouseWindow == this) - QGuiApplicationPrivate::currentMouseWindow = 0; - - QGuiApplicationPrivate::window_list.removeAll(this); - destroy(); - d->maybeQuitOnLastWindowClosed(); - return true; + bool accepted = false; + QWindowSystemInterface::handleCloseEvent(this, &accepted); + QWindowSystemInterface::flushWindowSystemEvents(); + return accepted; } /*! @@ -1995,7 +1996,7 @@ bool QWindow::event(QEvent *ev) case QEvent::Close: if (ev->isAccepted()) - close(); + destroy(); break; case QEvent::Expose: @@ -2208,8 +2209,10 @@ Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window) void QWindowPrivate::maybeQuitOnLastWindowClosed() { - Q_Q(QWindow); + if (!QCoreApplication::instance()) + return; + Q_Q(QWindow); // Attempt to close the application only if this has WA_QuitOnClose set and a non-visible parent bool quitOnClose = QGuiApplication::quitOnLastWindowClosed() && !q->parent(); -- cgit v1.2.3