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