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 QAPPLICATION_P_H
5#define QAPPLICATION_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp
13// and many other. This header file may change from version to version
14// without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtWidgets/private/qtwidgetsglobal_p.h>
20#include "QtWidgets/qapplication.h"
21#include "QtGui/qevent.h"
22#include "QtGui/qfont.h"
23#include "QtGui/qcursor.h"
24#include "QtGui/qregion.h"
25#include "QtGui/qwindow.h"
26#include "qwidget.h"
27#include <qpa/qplatformnativeinterface.h>
28#include "QtCore/qmutex.h"
29#include "QtCore/qtranslator.h"
30#include "QtCore/qbasictimer.h"
31#include "QtCore/qhash.h"
32#include "QtCore/qpointer.h"
33#include "private/qcoreapplication_p.h"
34#include "QtCore/qpoint.h"
35#include <QTime>
36#include <qpa/qwindowsysteminterface.h>
37#include <qpa/qwindowsysteminterface_p.h>
38#include <qpa/qplatformintegration.h>
39#include "private/qguiapplication_p.h"
40
41QT_BEGIN_NAMESPACE
42
43class QClipboard;
44class QGraphicsScene;
45class QObject;
46class QWidget;
47class QSocketNotifier;
48class QPointingDevice;
49#ifndef QT_NO_GESTURES
50class QGestureManager;
51#endif
52
53extern Q_GUI_EXPORT bool qt_is_tty_app;
54#ifndef QT_NO_CLIPBOARD
55extern QClipboard *qt_clipboard;
56#endif
57
58typedef QHash<QByteArray, QFont> FontHash;
59Q_WIDGETS_EXPORT FontHash *qt_app_fonts_hash();
60
61class Q_WIDGETS_EXPORT QApplicationPrivate : public QGuiApplicationPrivate
62{
63 Q_DECLARE_PUBLIC(QApplication)
64public:
65 QApplicationPrivate(int &argc, char **argv);
66 ~QApplicationPrivate();
67
68 virtual void notifyLayoutDirectionChange() override;
69 virtual void notifyActiveWindowChange(QWindow *) override;
70
71 static bool autoSipEnabled;
72 static QString desktopStyleKey();
73
74 void createEventDispatcher() override;
75 static void dispatchEnterLeave(QWidget *enter, QWidget *leave, const QPointF &globalPosF);
76 static QWidget *desktop();
77 void notifyWindowIconChanged() override;
78
79#ifndef QT_NO_ACTION
80 QActionPrivate *createActionPrivate() const override;
81#endif
82#ifndef QT_NO_SHORTCUT
83 QShortcutPrivate *createShortcutPrivate() const override;
84#endif
85
86 //modality
87 Qt::WindowModality defaultModality() const override;
88 bool windowNeverBlocked(QWindow *window) const override;
89 static bool isBlockedByModal(QWidget *widget);
90 static bool modalState();
91 static bool tryModalHelper(QWidget *widget, QWidget **rettop = nullptr);
92
93#ifdef QT_KEYPAD_NAVIGATION
94 static bool keypadNavigationEnabled()
95 {
96 return navigationMode == Qt::NavigationModeKeypadTabOrder ||
97 navigationMode == Qt::NavigationModeKeypadDirectional;
98 }
99#endif
100
101 bool notify_helper(QObject *receiver, QEvent * e);
102
103 void init();
104 void initialize();
105 void process_cmdline();
106
107 static void setActiveWindow(QWidget* act);
108
109 static bool inPopupMode();
110 bool popupActive() override { return inPopupMode(); }
111 bool closeAllPopups() override;
112 void closePopup(QWidget *popup);
113 void openPopup(QWidget *popup);
114 static void setFocusWidget(QWidget *focus, Qt::FocusReason reason);
115 static QWidget *focusNextPrevChild_helper(QWidget *toplevel, bool next,
116 bool *wrappingOccurred = nullptr);
117
118#if QT_CONFIG(graphicsview)
119 // Maintain a list of all scenes to ensure font and palette propagation to
120 // all scenes.
121 QList<QGraphicsScene *> scene_list;
122#endif
123
124 QBasicTimer toolTipWakeUp, toolTipFallAsleep;
125 QPoint toolTipPos, toolTipGlobalPos, hoverGlobalPos;
126 QPointer<QWidget> toolTipWidget;
127
128 static QSize app_strut;
129 static QWidgetList *popupWidgets;
130 static QStyle *app_style;
131
132protected:
133 void handleThemeChanged() override;
134
135 QPalette basePalette() const override;
136 void handlePaletteChanged(const char *className = nullptr) override;
137
138#if QT_CONFIG(draganddrop)
139 void notifyDragStarted(const QDrag *) override;
140#endif // QT_CONFIG(draganddrop)
141
142public:
143 static QFont *sys_font;
144 static QFont *set_font;
145 static QWidget *main_widget;
146 static QWidget *focus_widget;
147 static QWidget *hidden_focus_widget;
148 static QWidget *active_window;
149#if QT_CONFIG(wheelevent)
150 static int wheel_scroll_lines;
151 static QPointer<QWidget> wheel_widget;
152#endif
153
154 static int enabledAnimations; // Combination of QPlatformTheme::UiEffect
155 static bool widgetCount; // Coupled with -widgetcount switch
156
157 static void initializeWidgetPalettesFromTheme();
158 static void initializeWidgetFontHash();
159 static void setSystemFont(const QFont &font);
160
161 using PaletteHash = QHash<QByteArray, QPalette>;
162 static PaletteHash widgetPalettes;
163
164 static QApplicationPrivate *instance() { return self; }
165
166#ifdef QT_KEYPAD_NAVIGATION
167 static QWidget *oldEditFocus;
168 static Qt::NavigationMode navigationMode;
169#endif
170
171#ifndef QT_NO_STYLE_STYLESHEET
172 static QString styleSheet;
173#endif
174 static QPointer<QWidget> leaveAfterRelease;
175 static QWidget *pickMouseReceiver(QWidget *candidate, const QPoint &windowPos, QPoint *pos,
176 QEvent::Type type, Qt::MouseButtons buttons,
177 QWidget *buttonDown, QWidget *alienWidget);
178 static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget,
179 QWidget *native, QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver,
180 bool spontaneous = true, bool onlyDispatchEnterLeave = false);
181 void sendSyntheticEnterLeave(QWidget *widget);
182
183 static QWindow *windowForWidget(const QWidget *widget)
184 {
185 if (QWindow *window = widget->windowHandle())
186 return window;
187 if (const QWidget *nativeParent = widget->nativeParentWidget())
188 return nativeParent->windowHandle();
189 return nullptr;
190 }
191
192#ifdef Q_OS_WIN
193 static HWND getHWNDForWidget(const QWidget *widget)
194 {
195 if (QWindow *window = windowForWidget(widget))
196 if (window->handle() && QGuiApplication::platformNativeInterface())
197 return static_cast<HWND> (QGuiApplication::platformNativeInterface()->
198 nativeResourceForWindow(QByteArrayLiteral("handle"), window));
199 return 0;
200 }
201#endif
202
203#ifndef QT_NO_GESTURES
204 QGestureManager *gestureManager;
205 QWidget *gestureWidget;
206#endif
207
208 static bool updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent);
209 void initializeMultitouch();
210 void initializeMultitouch_sys();
211 void cleanupMultitouch();
212 void cleanupMultitouch_sys();
213 QWidget *findClosestTouchPointTarget(const QPointingDevice *device, const QEventPoint &touchPoint);
214 void appendTouchPoint(const QEventPoint &touchPoint);
215 void removeTouchPoint(int touchPointId);
216 enum ImplicitTouchGrabMode { GrabAcceptedPoints, GrabAllPoints };
217 void activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchBeginEvent,
218 ImplicitTouchGrabMode grabMode = GrabAcceptedPoints);
219 static bool translateRawTouchEvent(QWidget *widget, const QTouchEvent *touchEvent);
220 static void translateTouchCancel(const QPointingDevice *device, ulong timestamp);
221
222 QPixmap applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const override;
223
224private:
225 static QApplicationPrivate *self;
226 static bool tryCloseAllWidgetWindows(QWindowList *processedWindows);
227
228 static void giveFocusAccordingToFocusPolicy(QWidget *w, QEvent *event, QPoint localPos);
229 static bool shouldSetFocus(QWidget *w, Qt::FocusPolicy policy);
230
231
232 static bool isAlien(QWidget *);
233};
234
235extern void qt_qpa_set_cursor(QWidget * w, bool force);
236
237QT_END_NAMESPACE
238
239#endif // QAPPLICATION_P_H
240

source code of qtbase/src/widgets/kernel/qapplication_p.h