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 QtWidgets 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 QAPPLICATION_H
41 #define QAPPLICATION_H
42 
43 #include <QtWidgets/qtwidgetsglobal.h>
44 #include <QtCore/qcoreapplication.h>
45 #include <QtGui/qwindowdefs.h>
46 #include <QtCore/qpoint.h>
47 #include <QtCore/qsize.h>
48 #include <QtGui/qcursor.h>
49 #ifdef QT_INCLUDE_COMPAT
50 # include <QtWidgets/qdesktopwidget.h>
51 #endif
52 #include <QtGui/qguiapplication.h>
53 
54 QT_BEGIN_NAMESPACE
55 
56 
57 class QDesktopWidget;
58 class QStyle;
59 class QEventLoop;
60 class QIcon;
61 template <typename T> class QList;
62 class QLocale;
63 class QPlatformNativeInterface;
64 
65 class QApplication;
66 class QApplicationPrivate;
67 #if defined(qApp)
68 #undef qApp
69 #endif
70 #define qApp (static_cast<QApplication *>(QCoreApplication::instance()))
71 
72 class Q_WIDGETS_EXPORT QApplication : public QGuiApplication
73 {
74     Q_OBJECT
75     Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon)
76     Q_PROPERTY(int cursorFlashTime READ cursorFlashTime WRITE setCursorFlashTime)
77     Q_PROPERTY(int doubleClickInterval  READ doubleClickInterval WRITE setDoubleClickInterval)
78     Q_PROPERTY(int keyboardInputInterval READ keyboardInputInterval WRITE setKeyboardInputInterval)
79 #if QT_CONFIG(wheelevent)
80     Q_PROPERTY(int wheelScrollLines  READ wheelScrollLines WRITE setWheelScrollLines)
81 #endif
82 #if QT_DEPRECATED_SINCE(5, 15)
83     Q_PROPERTY(QSize globalStrut READ globalStrut WRITE setGlobalStrut)
84 #endif
85     Q_PROPERTY(int startDragTime  READ startDragTime WRITE setStartDragTime)
86     Q_PROPERTY(int startDragDistance  READ startDragDistance WRITE setStartDragDistance)
87 #ifndef QT_NO_STYLE_STYLESHEET
88     Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
89 #endif
90     Q_PROPERTY(bool autoSipEnabled READ autoSipEnabled WRITE setAutoSipEnabled)
91 
92 public:
93 #ifdef Q_QDOC
94     QApplication(int &argc, char **argv);
95 #else
96     QApplication(int &argc, char **argv, int = ApplicationFlags);
97 #endif
98     virtual ~QApplication();
99 
100     static QStyle *style();
101     static void setStyle(QStyle*);
102     static QStyle *setStyle(const QString&);
103     enum ColorSpec { NormalColor=0, CustomColor=1, ManyColor=2 };
104 #if QT_DEPRECATED_SINCE(5, 8)
105     QT_DEPRECATED static int colorSpec();
106     QT_DEPRECATED static void setColorSpec(int);
107 #endif // QT_DEPRECATED_SINCE(5, 8)
108 #if QT_DEPRECATED_SINCE(5, 0)
setGraphicsSystem(const QString &)109     QT_DEPRECATED static inline void setGraphicsSystem(const QString &) {}
110 #endif
111 
112     using QGuiApplication::palette;
113     static QPalette palette(const QWidget *);
114     static QPalette palette(const char *className);
115     static void setPalette(const QPalette &, const char* className = nullptr);
116     static QFont font();
117     static QFont font(const QWidget*);
118     static QFont font(const char *className);
119     static void setFont(const QFont &, const char* className = nullptr);
120     static QFontMetrics fontMetrics();
121 
122 #if QT_VERSION < 0x060000 // remove these forwarders in Qt 6
123     static void setWindowIcon(const QIcon &icon);
124     static QIcon windowIcon();
125 #endif
126 
127     static QWidgetList allWidgets();
128     static QWidgetList topLevelWidgets();
129 
130     static QDesktopWidget *desktop();
131 
132     static QWidget *activePopupWidget();
133     static QWidget *activeModalWidget();
134     static QWidget *focusWidget();
135 
136     static QWidget *activeWindow();
137     static void setActiveWindow(QWidget* act);
138 
139     static QWidget *widgetAt(const QPoint &p);
widgetAt(int x,int y)140     static inline QWidget *widgetAt(int x, int y) { return widgetAt(QPoint(x, y)); }
141     static QWidget *topLevelAt(const QPoint &p);
topLevelAt(int x,int y)142     static inline QWidget *topLevelAt(int x, int y)  { return topLevelAt(QPoint(x, y)); }
143 
144 #if QT_DEPRECATED_SINCE(5, 0)
syncX()145     QT_DEPRECATED static inline void syncX() {}
146 #endif
147     static void beep();
148     static void alert(QWidget *widget, int duration = 0);
149 
150     static void setCursorFlashTime(int);
151     static int cursorFlashTime();
152 
153     static void setDoubleClickInterval(int);
154     static int doubleClickInterval();
155 
156     static void setKeyboardInputInterval(int);
157     static int keyboardInputInterval();
158 
159 #if QT_CONFIG(wheelevent)
160     static void setWheelScrollLines(int);
161     static int wheelScrollLines();
162 #endif
163 #if QT_DEPRECATED_SINCE(5, 15)
164     static void setGlobalStrut(const QSize &);
165     static QSize globalStrut();
166 #endif
167 
168     static void setStartDragTime(int ms);
169     static int startDragTime();
170     static void setStartDragDistance(int l);
171     static int startDragDistance();
172 
173     static bool isEffectEnabled(Qt::UIEffect);
174     static void setEffectEnabled(Qt::UIEffect, bool enable = true);
175 
176 #if QT_DEPRECATED_SINCE(5, 0)
keyboardInputLocale()177     QT_DEPRECATED static QLocale keyboardInputLocale()
178     { return qApp ? QGuiApplication::inputMethod()->locale() : QLocale::c(); }
keyboardInputDirection()179     QT_DEPRECATED static Qt::LayoutDirection keyboardInputDirection()
180     { return qApp ? QGuiApplication::inputMethod()->inputDirection() : Qt::LeftToRight; }
181 #endif
182 
183     static int exec();
184     bool notify(QObject *, QEvent *) override;
185 
186 #ifdef QT_KEYPAD_NAVIGATION
187 # if QT_DEPRECATED_SINCE(5, 13)
188     static QT_DEPRECATED_X ("Use QApplication::setNavigationMode() instead")
189     void setKeypadNavigationEnabled(bool);
190     static QT_DEPRECATED_X ("Use QApplication::navigationMode() instead")
191     bool keypadNavigationEnabled();
192 # endif
193     static void setNavigationMode(Qt::NavigationMode mode);
194     static Qt::NavigationMode navigationMode();
195 #endif
196 
197 Q_SIGNALS:
198     void focusChanged(QWidget *old, QWidget *now);
199 
200 public:
201     QString styleSheet() const;
202 public Q_SLOTS:
203 #ifndef QT_NO_STYLE_STYLESHEET
204     void setStyleSheet(const QString& sheet);
205 #endif
206     void setAutoSipEnabled(const bool enabled);
207     bool autoSipEnabled() const;
208     static void closeAllWindows();
209     static void aboutQt();
210 
211 protected:
212     bool event(QEvent *) override;
213     bool compressEvent(QEvent *, QObject *receiver, QPostEventList *) override;
214 
215 private:
216     Q_DISABLE_COPY(QApplication)
217     Q_DECLARE_PRIVATE(QApplication)
218 
219     friend class QGraphicsWidget;
220     friend class QGraphicsItem;
221     friend class QGraphicsScene;
222     friend class QGraphicsScenePrivate;
223     friend class QWidget;
224     friend class QWidgetPrivate;
225     friend class QWidgetWindow;
226     friend class QTranslator;
227     friend class QWidgetAnimator;
228 #ifndef QT_NO_SHORTCUT
229     friend class QShortcut;
230     friend class QLineEdit;
231     friend class QWidgetTextControl;
232 #endif
233     friend class QAction;
234 
235 #ifndef QT_NO_GESTURES
236     friend class QGestureManager;
237 #endif
238 };
239 
240 QT_END_NAMESPACE
241 
242 #endif // QAPPLICATION_H
243