| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QGUIAPPLICATION_H |
| 5 | #define QGUIAPPLICATION_H |
| 6 | |
| 7 | #include <QtGui/qtguiglobal.h> |
| 8 | #include <QtCore/qcoreapplication.h> |
| 9 | #include <QtGui/qwindowdefs.h> |
| 10 | #include <QtGui/qinputmethod.h> |
| 11 | #include <QtCore/qlocale.h> |
| 12 | #include <QtCore/qpoint.h> |
| 13 | #include <QtCore/qsize.h> |
| 14 | |
| 15 | QT_BEGIN_NAMESPACE |
| 16 | |
| 17 | |
| 18 | class QSessionManager; |
| 19 | class QGuiApplicationPrivate; |
| 20 | class QPlatformNativeInterface; |
| 21 | class QPlatformIntegration; |
| 22 | class QPalette; |
| 23 | class QScreen; |
| 24 | class QStyleHints; |
| 25 | |
| 26 | #if defined(qApp) |
| 27 | #undef qApp |
| 28 | #endif |
| 29 | #define qApp (static_cast<QGuiApplication *>(QCoreApplication::instance())) |
| 30 | |
| 31 | #if defined(qGuiApp) |
| 32 | #undef qGuiApp |
| 33 | #endif |
| 34 | #define qGuiApp (static_cast<QGuiApplication *>(QCoreApplication::instance())) |
| 35 | |
| 36 | class Q_GUI_EXPORT QGuiApplication : public QCoreApplication |
| 37 | { |
| 38 | Q_OBJECT |
| 39 | Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon) |
| 40 | Q_PROPERTY(QString applicationDisplayName READ applicationDisplayName |
| 41 | WRITE setApplicationDisplayName NOTIFY applicationDisplayNameChanged) |
| 42 | Q_PROPERTY(QString desktopFileName READ desktopFileName WRITE setDesktopFileName) |
| 43 | Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection |
| 44 | NOTIFY layoutDirectionChanged) |
| 45 | Q_PROPERTY(QString platformName READ platformName STORED false CONSTANT) |
| 46 | Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed |
| 47 | WRITE setQuitOnLastWindowClosed) |
| 48 | Q_PROPERTY(QScreen *primaryScreen READ primaryScreen NOTIFY primaryScreenChanged STORED false) |
| 49 | |
| 50 | public: |
| 51 | #ifdef Q_QDOC |
| 52 | QGuiApplication(int &argc, char **argv); |
| 53 | #else |
| 54 | QGuiApplication(int &argc, char **argv, int = ApplicationFlags); |
| 55 | #endif |
| 56 | ~QGuiApplication(); |
| 57 | |
| 58 | static void setApplicationDisplayName(const QString &name); |
| 59 | static QString applicationDisplayName(); |
| 60 | |
| 61 | Q_SLOT void setBadgeNumber(qint64 number); |
| 62 | |
| 63 | static void setDesktopFileName(const QString &name); |
| 64 | static QString desktopFileName(); |
| 65 | |
| 66 | static QWindowList allWindows(); |
| 67 | static QWindowList topLevelWindows(); |
| 68 | static QWindow *topLevelAt(const QPoint &pos); |
| 69 | |
| 70 | static void setWindowIcon(const QIcon &icon); |
| 71 | static QIcon windowIcon(); |
| 72 | |
| 73 | static QString platformName(); |
| 74 | |
| 75 | static QWindow *modalWindow(); |
| 76 | |
| 77 | static QWindow *focusWindow(); |
| 78 | static QObject *focusObject(); |
| 79 | |
| 80 | static QScreen *primaryScreen(); |
| 81 | static QList<QScreen *> screens(); |
| 82 | static QScreen *screenAt(const QPoint &point); |
| 83 | |
| 84 | qreal devicePixelRatio() const; |
| 85 | |
| 86 | #ifndef QT_NO_CURSOR |
| 87 | static QCursor *overrideCursor(); |
| 88 | static void setOverrideCursor(const QCursor &); |
| 89 | static void changeOverrideCursor(const QCursor &); |
| 90 | static void restoreOverrideCursor(); |
| 91 | #endif |
| 92 | |
| 93 | static QFont font(); |
| 94 | static void setFont(const QFont &); |
| 95 | |
| 96 | #ifndef QT_NO_CLIPBOARD |
| 97 | static QClipboard *clipboard(); |
| 98 | #endif |
| 99 | |
| 100 | static QPalette palette(); |
| 101 | static void setPalette(const QPalette &pal); |
| 102 | |
| 103 | static Qt::KeyboardModifiers keyboardModifiers(); |
| 104 | static Qt::KeyboardModifiers queryKeyboardModifiers(); |
| 105 | static Qt::MouseButtons mouseButtons(); |
| 106 | |
| 107 | static void setLayoutDirection(Qt::LayoutDirection direction); |
| 108 | static Qt::LayoutDirection layoutDirection(); |
| 109 | |
| 110 | static inline bool isRightToLeft() { return layoutDirection() == Qt::RightToLeft; } |
| 111 | static inline bool isLeftToRight() { return layoutDirection() == Qt::LeftToRight; } |
| 112 | |
| 113 | static QStyleHints *styleHints(); |
| 114 | static void setDesktopSettingsAware(bool on); |
| 115 | static bool desktopSettingsAware(); |
| 116 | |
| 117 | static QInputMethod *inputMethod(); |
| 118 | |
| 119 | static QPlatformNativeInterface *platformNativeInterface(); |
| 120 | |
| 121 | static QFunctionPointer platformFunction(const QByteArray &function); |
| 122 | |
| 123 | static void setQuitOnLastWindowClosed(bool quit); |
| 124 | static bool quitOnLastWindowClosed(); |
| 125 | |
| 126 | static Qt::ApplicationState applicationState(); |
| 127 | |
| 128 | static void setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy policy); |
| 129 | static Qt::HighDpiScaleFactorRoundingPolicy highDpiScaleFactorRoundingPolicy(); |
| 130 | |
| 131 | static int exec(); |
| 132 | bool notify(QObject *, QEvent *) override; |
| 133 | |
| 134 | #ifndef QT_NO_SESSIONMANAGER |
| 135 | // session management |
| 136 | bool isSessionRestored() const; |
| 137 | QString sessionId() const; |
| 138 | QString sessionKey() const; |
| 139 | bool isSavingSession() const; |
| 140 | #endif |
| 141 | |
| 142 | QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QGuiApplication) |
| 143 | |
| 144 | static void sync(); |
| 145 | Q_SIGNALS: |
| 146 | void fontDatabaseChanged(); |
| 147 | void screenAdded(QScreen *screen); |
| 148 | void screenRemoved(QScreen *screen); |
| 149 | void primaryScreenChanged(QScreen *screen); |
| 150 | void lastWindowClosed(); |
| 151 | void focusObjectChanged(QObject *focusObject); |
| 152 | void focusWindowChanged(QWindow *focusWindow); |
| 153 | void applicationStateChanged(Qt::ApplicationState state); |
| 154 | void layoutDirectionChanged(Qt::LayoutDirection direction); |
| 155 | #ifndef QT_NO_SESSIONMANAGER |
| 156 | void commitDataRequest(QSessionManager &sessionManager); |
| 157 | void saveStateRequest(QSessionManager &sessionManager); |
| 158 | #endif |
| 159 | void applicationDisplayNameChanged(); |
| 160 | #if QT_DEPRECATED_SINCE(6, 0) |
| 161 | QT_DEPRECATED_VERSION_X_6_0("Handle QEvent::ApplicationPaletteChange instead" ) void paletteChanged(const QPalette &pal); |
| 162 | QT_DEPRECATED_VERSION_X_6_0("Handle QEvent::ApplicationFontChange instead" ) void fontChanged(const QFont &font); |
| 163 | #endif |
| 164 | protected: |
| 165 | bool event(QEvent *) override; |
| 166 | bool compressEvent(QEvent *, QObject *receiver, QPostEventList *) override; |
| 167 | |
| 168 | QGuiApplication(QGuiApplicationPrivate &p); |
| 169 | |
| 170 | private: |
| 171 | Q_DISABLE_COPY(QGuiApplication) |
| 172 | Q_DECLARE_PRIVATE(QGuiApplication) |
| 173 | |
| 174 | Q_PRIVATE_SLOT(d_func(), void _q_updateFocusObject(QObject *object)) |
| 175 | |
| 176 | #ifndef QT_NO_GESTURES |
| 177 | friend class QGestureManager; |
| 178 | #endif |
| 179 | friend class QFontDatabasePrivate; |
| 180 | friend class QPlatformIntegration; |
| 181 | #ifndef QT_NO_SESSIONMANAGER |
| 182 | friend class QPlatformSessionManager; |
| 183 | #endif |
| 184 | }; |
| 185 | |
| 186 | QT_END_NAMESPACE |
| 187 | |
| 188 | #include <QtGui/qguiapplication_platform.h> |
| 189 | |
| 190 | #endif // QGUIAPPLICATION_H |
| 191 | |