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 bool notify_helper(QObject *receiver, QEvent * e);
96
97 void init();
98 void initialize();
99 void process_cmdline();
100
101 static void setActiveWindow(QWidget* act);
102
103 static bool inPopupMode();
104 void closePopup(QWidget *popup);
105 void openPopup(QWidget *popup);
106 static bool replayMousePress;
107
108 static void setFocusWidget(QWidget *focus, Qt::FocusReason reason);
109 static QWidget *focusNextPrevChild_helper(QWidget *toplevel, bool next,
110 bool *wrappingOccurred = nullptr);
111
112#if QT_CONFIG(graphicsview)
113 // Maintain a list of all scenes to ensure font and palette propagation to
114 // all scenes.
115 QList<QGraphicsScene *> scene_list;
116#endif
117
118 QBasicTimer toolTipWakeUp, toolTipFallAsleep;
119 QPoint toolTipPos, toolTipGlobalPos;
120 QPointer<QWidget> toolTipWidget;
121
122 static QSize app_strut;
123 static QWidgetList *popupWidgets;
124 static QStyle *app_style;
125
126protected:
127 void handleThemeChanged() override;
128
129 QPalette basePalette() const override;
130 void handlePaletteChanged(const char *className = nullptr) override;
131
132#if QT_CONFIG(draganddrop)
133 void notifyDragStarted(const QDrag *) override;
134#endif // QT_CONFIG(draganddrop)
135
136public:
137 static QFont *sys_font;
138 static QFont *set_font;
139 static QWidget *main_widget;
140 static QWidget *focus_widget;
141 static QWidget *hidden_focus_widget;
142#if QT_CONFIG(wheelevent)
143 static QPointer<QWidget> wheel_widget;
144#endif
145
146 static int enabledAnimations; // Combination of QPlatformTheme::UiEffect
147 static bool widgetCount; // Coupled with -widgetcount switch
148
149 static void initializeWidgetPalettesFromTheme();
150 static void initializeWidgetFontHash();
151 static void setSystemFont(const QFont &font);
152
153 using PaletteHash = QHash<QByteArray, QPalette>;
154 static PaletteHash widgetPalettes;
155
156 static QApplicationPrivate *instance() { return self; }
157
158#ifndef QT_NO_STYLE_STYLESHEET
159 static QString styleSheet;
160#endif
161 static QPointer<QWidget> leaveAfterRelease;
162 static QWidget *pickMouseReceiver(QWidget *candidate, const QPointF &windowPos, QPointF *pos,
163 QEvent::Type type, Qt::MouseButtons buttons,
164 QWidget *buttonDown, QWidget *alienWidget);
165 static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget,
166 QWidget *native, QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver,
167 bool spontaneous = true, bool onlyDispatchEnterLeave = false);
168 void sendSyntheticEnterLeave(QWidget *widget);
169
170 static QWindow *windowForWidget(const QWidget *widget)
171 {
172 if (QWindow *window = widget->windowHandle())
173 return window;
174 if (const QWidget *nativeParent = widget->nativeParentWidget())
175 return nativeParent->windowHandle();
176 return nullptr;
177 }
178
179#ifdef Q_OS_WIN
180 static HWND getHWNDForWidget(const QWidget *widget)
181 {
182 if (QWindow *window = windowForWidget(widget))
183 if (window->handle() && QGuiApplication::platformNativeInterface())
184 return static_cast<HWND> (QGuiApplication::platformNativeInterface()->
185 nativeResourceForWindow(QByteArrayLiteral("handle"), window));
186 return 0;
187 }
188#endif
189
190#ifndef QT_NO_GESTURES
191 QGestureManager *gestureManager;
192 QWidget *gestureWidget;
193#endif
194
195 static bool updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent);
196 void initializeMultitouch();
197 void initializeMultitouch_sys();
198 void cleanupMultitouch();
199 void cleanupMultitouch_sys();
200 QWidget *findClosestTouchPointTarget(const QPointingDevice *device, const QEventPoint &touchPoint);
201 void appendTouchPoint(const QEventPoint &touchPoint);
202 void removeTouchPoint(int touchPointId);
203 enum ImplicitTouchGrabMode { GrabAcceptedPoints, GrabAllPoints };
204 void activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchBeginEvent,
205 ImplicitTouchGrabMode grabMode = GrabAcceptedPoints);
206 static bool translateRawTouchEvent(QWidget *widget, const QTouchEvent *touchEvent);
207 static void translateTouchCancel(const QPointingDevice *device, ulong timestamp);
208
209 QPixmap applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const override;
210
211private:
212 static QApplicationPrivate *self;
213 static bool tryCloseAllWidgetWindows(QWindowList *processedWindows);
214
215 static void giveFocusAccordingToFocusPolicy(QWidget *w, QEvent *event, QPoint localPos);
216 static bool shouldSetFocus(QWidget *w, Qt::FocusPolicy policy);
217
218 static QWidget *active_window;
219
220 static bool isAlien(QWidget *);
221};
222
223extern void qt_qpa_set_cursor(QWidget * w, bool force);
224
225QT_END_NAMESPACE
226
227#endif // QAPPLICATION_P_H
\inmodule QtWidgets
friend class QWidget
Definition qpainter.h:432
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
Combined button and popup list for selecting options.
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
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:5041
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(...)
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
#define QWIDGETSIZE_MAX
Definition qwidget.h:917
QPointer< QWindow > qt_last_mouse_receiver