1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QGUIAPPLICATION_H
41#define QGUIAPPLICATION_H
42
43#include <QtGui/qtguiglobal.h>
44#include <QtCore/qcoreapplication.h>
45#include <QtGui/qwindowdefs.h>
46#include <QtGui/qinputmethod.h>
47#include <QtCore/qlocale.h>
48#include <QtCore/qpoint.h>
49#include <QtCore/qsize.h>
50
51QT_BEGIN_NAMESPACE
52
53
54class QSessionManager;
55class QGuiApplicationPrivate;
56class QPlatformNativeInterface;
57class QPlatformIntegration;
58class QPalette;
59class QScreen;
60class QStyleHints;
61
62#if defined(qApp)
63#undef qApp
64#endif
65#define qApp (static_cast<QGuiApplication *>(QCoreApplication::instance()))
66
67#if defined(qGuiApp)
68#undef qGuiApp
69#endif
70#define qGuiApp (static_cast<QGuiApplication *>(QCoreApplication::instance()))
71
72class Q_GUI_EXPORT QGuiApplication : public QCoreApplication
73{
74 Q_OBJECT
75 Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon)
76 Q_PROPERTY(QString applicationDisplayName READ applicationDisplayName WRITE setApplicationDisplayName NOTIFY applicationDisplayNameChanged)
77 Q_PROPERTY(QString desktopFileName READ desktopFileName WRITE setDesktopFileName)
78 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
79 Q_PROPERTY(QString platformName READ platformName STORED false)
80 Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed)
81 Q_PROPERTY(QScreen *primaryScreen READ primaryScreen NOTIFY primaryScreenChanged STORED false)
82
83public:
84#ifdef Q_QDOC
85 QGuiApplication(int &argc, char **argv);
86#else
87 QGuiApplication(int &argc, char **argv, int = ApplicationFlags);
88#endif
89 ~QGuiApplication();
90
91 static void setApplicationDisplayName(const QString &name);
92 static QString applicationDisplayName();
93
94 static void setDesktopFileName(const QString &name);
95 static QString desktopFileName();
96
97 static QWindowList allWindows();
98 static QWindowList topLevelWindows();
99 static QWindow *topLevelAt(const QPoint &pos);
100
101 static void setWindowIcon(const QIcon &icon);
102 static QIcon windowIcon();
103
104 static QString platformName();
105
106 static QWindow *modalWindow();
107
108 static QWindow *focusWindow();
109 static QObject *focusObject();
110
111 static QScreen *primaryScreen();
112 static QList<QScreen *> screens();
113 static QScreen *screenAt(const QPoint &point);
114
115 qreal devicePixelRatio() const;
116
117#ifndef QT_NO_CURSOR
118 static QCursor *overrideCursor();
119 static void setOverrideCursor(const QCursor &);
120 static void changeOverrideCursor(const QCursor &);
121 static void restoreOverrideCursor();
122#endif
123
124 static QFont font();
125 static void setFont(const QFont &);
126
127#ifndef QT_NO_CLIPBOARD
128 static QClipboard *clipboard();
129#endif
130
131 static QPalette palette();
132 static void setPalette(const QPalette &pal);
133
134 static Qt::KeyboardModifiers keyboardModifiers();
135 static Qt::KeyboardModifiers queryKeyboardModifiers();
136 static Qt::MouseButtons mouseButtons();
137
138 static void setLayoutDirection(Qt::LayoutDirection direction);
139 static Qt::LayoutDirection layoutDirection();
140
141 static inline bool isRightToLeft() { return layoutDirection() == Qt::RightToLeft; }
142 static inline bool isLeftToRight() { return layoutDirection() == Qt::LeftToRight; }
143
144 static QStyleHints *styleHints();
145 static void setDesktopSettingsAware(bool on);
146 static bool desktopSettingsAware();
147
148 static QInputMethod *inputMethod();
149
150 static QPlatformNativeInterface *platformNativeInterface();
151
152 static QFunctionPointer platformFunction(const QByteArray &function);
153
154 static void setQuitOnLastWindowClosed(bool quit);
155 static bool quitOnLastWindowClosed();
156
157 static Qt::ApplicationState applicationState();
158
159 static void setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy policy);
160 static Qt::HighDpiScaleFactorRoundingPolicy highDpiScaleFactorRoundingPolicy();
161
162 static int exec();
163 bool notify(QObject *, QEvent *) override;
164
165#ifndef QT_NO_SESSIONMANAGER
166 // session management
167 bool isSessionRestored() const;
168 QString sessionId() const;
169 QString sessionKey() const;
170 bool isSavingSession() const;
171
172 static bool isFallbackSessionManagementEnabled();
173 static void setFallbackSessionManagementEnabled(bool);
174#endif
175
176 static void sync();
177Q_SIGNALS:
178 void fontDatabaseChanged();
179 void screenAdded(QScreen *screen);
180 void screenRemoved(QScreen *screen);
181 void primaryScreenChanged(QScreen *screen);
182 void lastWindowClosed();
183 void focusObjectChanged(QObject *focusObject);
184 void focusWindowChanged(QWindow *focusWindow);
185 void applicationStateChanged(Qt::ApplicationState state);
186 void layoutDirectionChanged(Qt::LayoutDirection direction);
187#ifndef QT_NO_SESSIONMANAGER
188 void commitDataRequest(QSessionManager &sessionManager);
189 void saveStateRequest(QSessionManager &sessionManager);
190#endif
191 void paletteChanged(const QPalette &pal);
192 void applicationDisplayNameChanged();
193 void fontChanged(const QFont &font);
194
195protected:
196 bool event(QEvent *) override;
197 bool compressEvent(QEvent *, QObject *receiver, QPostEventList *) override;
198
199 QGuiApplication(QGuiApplicationPrivate &p);
200
201private:
202 Q_DISABLE_COPY(QGuiApplication)
203 Q_DECLARE_PRIVATE(QGuiApplication)
204
205 Q_PRIVATE_SLOT(d_func(), void _q_updateFocusObject(QObject *object))
206
207#ifndef QT_NO_GESTURES
208 friend class QGestureManager;
209#endif
210 friend class QFontDatabasePrivate;
211 friend class QPlatformIntegration;
212#ifndef QT_NO_SESSIONMANAGER
213 friend class QPlatformSessionManager;
214#endif
215};
216
217QT_END_NAMESPACE
218
219#endif // QGUIAPPLICATION_H
220

source code of qtbase/src/gui/kernel/qguiapplication.h