diff options
author | Gunnar Sletta <gunnar.sletta@nokia.com> | 2011-08-10 15:36:51 +0200 |
---|---|---|
committer | Jørgen Lind <jorgen.lind@nokia.com> | 2011-08-11 08:20:55 +0200 |
commit | 46c9f4c212e374f957942f1d16d66f20b0a2949a (patch) | |
tree | bb031dc899ed5ae6d19ddccbcae22d31798e7581 /src/gui/kernel/qwindow.cpp | |
parent | 73769d85ec13ed6b57f1eccd3618616fd03d7cb7 (diff) |
Implement "quit on last window closed" logic for QWindow
Change-Id: Ide33578ad60796f3e267b09be76cda87eaf873d0
Reviewed-on: http://codereview.qt.nokia.com/2827
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
Diffstat (limited to 'src/gui/kernel/qwindow.cpp')
-rw-r--r-- | src/gui/kernel/qwindow.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 9eb011abb1..be96bebd0f 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -440,6 +440,7 @@ void QWindow::setWindowIcon(const QImage &icon) const void QWindow::destroy() { Q_D(QWindow); + setVisible(false); delete d->platformWindow; d->platformWindow = 0; } @@ -569,9 +570,13 @@ bool QWindow::event(QEvent *event) break; #endif - case QEvent::Close: + case QEvent::Close: { + Q_D(QWindow); + bool wasVisible = visible(); destroy(); - break; + if (wasVisible); + d->maybeQuitOnLastWindowClosed(); + break; } case QEvent::Expose: exposeEvent(static_cast<QExposeEvent *>(event)); @@ -630,4 +635,27 @@ Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window) return window->d_func(); } +void QWindowPrivate::maybeQuitOnLastWindowClosed() +{ + 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(); + + if (quitOnClose) { + QWindowList list = QGuiApplication::topLevelWindows(); + bool lastWindowClosed = true; + for (int i = 0; i < list.size(); ++i) { + QWindow *w = list.at(i); + if (!w->visible() || w->parent()) + continue; + lastWindowClosed = false; + break; + } + if (lastWindowClosed) + QGuiApplicationPrivate::emitLastWindowClosed(); + } + +} + QT_END_NAMESPACE |