int QGuiApplicationPrivate::mousePressY = 0;
int QGuiApplicationPrivate::mouse_double_click_distance = 5;
+bool QGuiApplicationPrivate::quitOnLastWindowClosed = true;
+
static Qt::LayoutDirection layout_direction = Qt::LeftToRight;
static bool force_reverse = false;
{
}
+
+/*!
+ \property QGuiApplication::quitOnLastWindowClosed
+
+ \brief whether the application implicitly quits when the last window is
+ closed.
+
+ The default is true.
+
+ If this property is true, the applications quits when the last visible
+ primary window (i.e. window with no parent) is closed.
+
+ \sa quit(), QWindow::close()
+ */
+
+void QGuiApplication::setQuitOnLastWindowClosed(bool quit)
+{
+ QGuiApplicationPrivate::quitOnLastWindowClosed = quit;
+}
+
+
+
+bool QGuiApplication::quitOnLastWindowClosed()
+{
+ return QGuiApplicationPrivate::quitOnLastWindowClosed;
+}
+
+
+
+void QGuiApplicationPrivate::emitLastWindowClosed()
+{
+ if (qGuiApp && qGuiApp->d_func()->in_exec) {
+ if (QGuiApplicationPrivate::quitOnLastWindowClosed) {
+ // get ready to quit, this event might be removed if the
+ // event loop is re-entered, however
+ QGuiApplication::postEvent(qApp, new QEvent(QEvent::Quit));
+ }
+ emit qGuiApp->lastWindowClosed();
+ }
+}
+
+
/*!
\property QGuiApplication::layoutDirection
\brief the default layout direction for this application
Q_PROPERTY(int doubleClickInterval READ doubleClickInterval WRITE setDoubleClickInterval)
Q_PROPERTY(int keyboardInputInterval READ keyboardInputInterval WRITE setKeyboardInputInterval)
+ Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed)
+
public:
QGuiApplication(int &argc, char **argv, int = ApplicationFlags);
virtual ~QGuiApplication();
static QPlatformNativeInterface *platformNativeInterface();
+ static void setQuitOnLastWindowClosed(bool quit);
+ static bool quitOnLastWindowClosed();
+
static int exec();
bool notify(QObject *, QEvent *);
Q_SIGNALS:
void fontDatabaseChanged();
void screenAdded(QScreen *screen);
+ void lastWindowClosed();
protected:
bool event(QEvent *);
return alignment;
}
+ static void emitLastWindowClosed();
+
QPixmap getPixmapCursor(Qt::CursorShape cshape);
static QGuiApplicationPrivate *instance() { return self; }
static QList<QScreen *> screen_list;
static QFont *app_font;
+
+ static bool quitOnLastWindowClosed;
private:
void init();
void QWindow::destroy()
{
Q_D(QWindow);
+ setVisible(false);
delete d->platformWindow;
d->platformWindow = 0;
}
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));
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
class Q_GUI_EXPORT QWindowPrivate : public QObjectPrivate
{
+ Q_DECLARE_PUBLIC(QWindow)
+
public:
QWindowPrivate()
: QObjectPrivate()
{
}
+ void maybeQuitOnLastWindowClosed();
+
QWindow::SurfaceType surfaceType;
Qt::WindowFlags windowFlags;
QWindow *parentWindow;