Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qapplication_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QAPPLICATION_P_H
6#define QAPPLICATION_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp
14// and many other. This header file may change from version to version
15// without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <QtWidgets/private/qtwidgetsglobal_p.h>
21#include "QtWidgets/qapplication.h"
22#include "QtGui/qevent.h"
23#include "QtGui/qfont.h"
24#include "QtGui/qcursor.h"
25#include "QtGui/qregion.h"
26#include "QtGui/qwindow.h"
27#include "qwidget.h"
28#include <qpa/qplatformnativeinterface.h>
29#include "QtCore/qmutex.h"
30#include "QtCore/qtranslator.h"
31#include "QtCore/qbasictimer.h"
32#include "QtCore/qhash.h"
33#include "QtCore/qpointer.h"
34#include "private/qcoreapplication_p.h"
35#include "QtCore/qpoint.h"
36#include <QTime>
37#include <qpa/qwindowsysteminterface.h>
38#include <qpa/qwindowsysteminterface_p.h>
39#include <qpa/qplatformintegration.h>
40#include "private/qguiapplication_p.h"
41
42QT_BEGIN_NAMESPACE
43
44class QClipboard;
45class QGraphicsScene;
46class QObject;
47class QWidget;
48class QSocketNotifier;
49class QPointingDevice;
50#ifndef QT_NO_GESTURES
51class QGestureManager;
52#endif
53
54extern Q_GUI_EXPORT bool qt_is_tty_app;
55#ifndef QT_NO_CLIPBOARD
56extern QClipboard *qt_clipboard;
57#endif
58
60Q_WIDGETS_EXPORT FontHash *qt_app_fonts_hash();
61
62class Q_WIDGETS_EXPORT QApplicationPrivate : public QGuiApplicationPrivate
63{
64 Q_DECLARE_PUBLIC(QApplication)
65public:
66 QApplicationPrivate(int &argc, char **argv);
67 ~QApplicationPrivate();
68
69 virtual void notifyLayoutDirectionChange() override;
70 virtual void notifyActiveWindowChange(QWindow *) override;
71
72 static bool autoSipEnabled;
73 static QString desktopStyleKey();
74
75 void createEventDispatcher() override;
76 static void dispatchEnterLeave(QWidget *enter, QWidget *leave, const QPointF &globalPosF);
77 static QWidget *desktop();
78 void notifyWindowIconChanged() override;
79 bool compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents) final;
80
81#ifndef QT_NO_ACTION
82 QActionPrivate *createActionPrivate() const override;
83#endif
84#ifndef QT_NO_SHORTCUT
85 QShortcutPrivate *createShortcutPrivate() const override;
86#endif
87
88 //modality
89 Qt::WindowModality defaultModality() const override;
90 bool windowNeverBlocked(QWindow *window) const override;
91 static bool isBlockedByModal(QWidget *widget);
92 static bool modalState();
93 static bool tryModalHelper(QWidget *widget, QWidget **rettop = nullptr);
94
95#ifdef QT_KEYPAD_NAVIGATION
96 static bool keypadNavigationEnabled()
97 {
98 return navigationMode == Qt::NavigationModeKeypadTabOrder ||
99 navigationMode == Qt::NavigationModeKeypadDirectional;
100 }
101#endif
102
103 bool notify_helper(QObject *receiver, QEvent * e);
104
105 void init();
106 void initialize();
107 void process_cmdline();
108
109 static void setActiveWindow(QWidget* act);
110
111 static bool inPopupMode();
112 void closePopup(QWidget *popup);
113 void openPopup(QWidget *popup);
114 static bool replayMousePress;
115
116 static void setFocusWidget(QWidget *focus, Qt::FocusReason reason);
117 static QWidget *focusNextPrevChild_helper(QWidget *toplevel, bool next,
118 bool *wrappingOccurred = nullptr);
119
120#if QT_CONFIG(graphicsview)
121 // Maintain a list of all scenes to ensure font and palette propagation to
122 // all scenes.
123 QList<QGraphicsScene *> scene_list;
124#endif
125
126 QBasicTimer toolTipWakeUp, toolTipFallAsleep;
127 QPoint toolTipPos, toolTipGlobalPos;
128 QPointer<QWidget> toolTipWidget;
129
130 static QSize app_strut;
131 static QWidgetList *popupWidgets;
132 static QStyle *app_style;
133
134protected:
135 void handleThemeChanged() override;
136
137 QPalette basePalette() const override;
138 void handlePaletteChanged(const char *className = nullptr) override;
139
140#if QT_CONFIG(draganddrop)
141 void notifyDragStarted(const QDrag *) override;
142#endif // QT_CONFIG(draganddrop)
143
144public:
145 static QFont *sys_font;
146 static QFont *set_font;
147 static QWidget *main_widget;
148 static QWidget *focus_widget;
149 static QWidget *hidden_focus_widget;
150#if QT_CONFIG(wheelevent)
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 QPointF &windowPos, QPointF *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 static QWidget *active_window;
232
233 static bool isAlien(QWidget *);
234};
235
236extern void qt_qpa_set_cursor(QWidget * w, bool force);
237
238QT_END_NAMESPACE
239
240#endif // QAPPLICATION_P_H
friend class QWidget
Definition qpainter.h:431
The QStyleFactory class creates QStyle objects.
void setNativeWindowVisibility(bool visible)
QObject * focusObject() const override
Returns the QObject that will be the final receiver of events tied focus, such as key events.
void handleMoveEvent(QMoveEvent *)
void handleMouseEvent(QMouseEvent *)
void handleFocusInEvent(QFocusEvent *)
void handleResizeEvent(QResizeEvent *)
void handleEnterLeaveEvent(QEvent *)
void handleTouchEvent(QTouchEvent *)
static void focusNextPrevChild(QWidget *widget, bool next)
void handleKeyEvent(QKeyEvent *)
void handleContextMenuEvent(QContextMenuEvent *)
bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override
Override this to handle platform dependent events.
bool event(QEvent *) override
Override this to handle any event (ev) sent to the window.
void handleExposeEvent(QExposeEvent *)
void closeEvent(QCloseEvent *) override
Override this to handle close events (ev).
void handleNonClientAreaMouseEvent(QMouseEvent *)
void handleGestureEvent(QNativeGestureEvent *)
void handleWindowStateChangedEvent(QWindowStateChangeEvent *event)
QWidget * widget() const
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
Q_GLOBAL_STATIC(DefaultRoleNames, qDefaultRoleNames, { { Qt::DisplayRole, "display" }, { Qt::DecorationRole, "decoration" }, { Qt::EditRole, "edit" }, { Qt::ToolTipRole, "toolTip" }, { Qt::StatusTipRole, "statusTip" }, { Qt::WhatsThisRole, "whatsThis" }, }) const QHash< int
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")
static int uiEffectToFlag(Qt::UIEffect effect)
static void initResources()
void qt_init_tooltip_palette()
static void ungrabMouseForPopup(QWidget *popup)
static void ungrabKeyboardForPopup(QWidget *popup)
Q_TRACE_POINT(qtwidgets, QApplication_notify_entry, QObject *receiver, QEvent *event, QEvent::Type type)
Q_WIDGETS_EXPORT bool qt_tryModalHelper(QWidget *widget, QWidget **rettop)
int qt_antialiasing_threshold
bool qt_in_tab_key_event
static bool popupGrabOk
void qRegisterWidgetsVariant()
static void grabForPopup(QWidget *popup)
QWidget * qt_tlw_for_window(QWindow *wnd)
Q_GUI_EXPORT bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
bool qt_try_modal(QWidget *widget, QEvent::Type type)
void qt_qpa_set_cursor(QWidget *w, bool force)
Definition qwidget.cpp:5073
QHash< QByteArray, QFont > FontHash
QClipboard * qt_clipboard
Q_TRACE_POINT(qtcore, QCoreApplication_notify_exit, bool consumed, bool filtered)
Q_TRACE_METADATA(qtcore, "ENUM { AUTO, RANGE User ... MaxUser } QEvent::Type;")
Q_TRACE_PREFIX(qtcore, "#include <qcoreevent.h>")
#define qApp
Q_CORE_EXPORT void qt_call_post_routines()
Q_CONSTINIT Q_GUI_EXPORT bool qt_is_tty_app
#define CHECK_QAPP_INSTANCE(...)
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
#define QWIDGETSIZE_MAX
Definition qwidget.h:922
QPointer< QWindow > qt_last_mouse_receiver