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 <qpa/qplatformwindow_p.h>
30#include "QtCore/qmutex.h"
31#include "QtCore/qtranslator.h"
32#include "QtCore/qbasictimer.h"
33#include "QtCore/qhash.h"
34#include "QtCore/qpointer.h"
35#include "private/qcoreapplication_p.h"
36#include "QtCore/qpoint.h"
37#include <QTime>
38#include <qpa/qwindowsysteminterface.h>
39#include <qpa/qwindowsysteminterface_p.h>
40#include <qpa/qplatformintegration.h>
41#include "private/qguiapplication_p.h"
42
43QT_BEGIN_NAMESPACE
44
45class QClipboard;
46class QGraphicsScene;
47class QObject;
48class QWidget;
49class QSocketNotifier;
50class QPointingDevice;
51#ifndef QT_NO_GESTURES
52class QGestureManager;
53#endif
54
55extern Q_GUI_EXPORT bool qt_is_tty_app;
56#ifndef QT_NO_CLIPBOARD
57extern QClipboard *qt_clipboard;
58#endif
59
61Q_WIDGETS_EXPORT FontHash *qt_app_fonts_hash();
62
63class Q_WIDGETS_EXPORT QApplicationPrivate : public QGuiApplicationPrivate
64{
65 Q_DECLARE_PUBLIC(QApplication)
66public:
67 QApplicationPrivate(int &argc, char **argv);
68 ~QApplicationPrivate();
69
70 virtual void notifyLayoutDirectionChange() override;
71 virtual void notifyActiveWindowChange(QWindow *) override;
72
73 static bool autoSipEnabled;
74 static QString desktopStyleKey();
75
76 void createEventDispatcher() override;
77 static void dispatchEnterLeave(QWidget *enter, QWidget *leave, const QPointF &globalPosF);
78 static QWidget *desktop();
79 void notifyWindowIconChanged() override;
80 bool compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents) final;
81
82#ifndef QT_NO_ACTION
83 QActionPrivate *createActionPrivate() const override;
84#endif
85#ifndef QT_NO_SHORTCUT
86 QShortcutPrivate *createShortcutPrivate() const override;
87#endif
88
89 //modality
90 Qt::WindowModality defaultModality() const override;
91 bool windowNeverBlocked(QWindow *window) const override;
92 static bool isBlockedByModal(QWidget *widget);
93 static bool modalState();
94 static bool tryModalHelper(QWidget *widget, QWidget **rettop = nullptr);
95
96 bool notify_helper(QObject *receiver, QEvent * e);
97
98 void init();
99 void initialize();
100 void process_cmdline();
101
102 static void setActiveWindow(QWidget* act);
103
104 static bool inPopupMode();
105 void closePopup(QWidget *popup);
106 void openPopup(QWidget *popup);
107 static bool replayMousePress;
108
109 static void setFocusWidget(QWidget *focus, Qt::FocusReason reason);
110 static QWidget *focusNextPrevChild_helper(QWidget *toplevel, bool next,
111 bool *wrappingOccurred = nullptr);
112
113#if QT_CONFIG(graphicsview)
114 // Maintain a list of all scenes to ensure font and palette propagation to
115 // all scenes.
116 QList<QGraphicsScene *> scene_list;
117#endif
118
119 QBasicTimer toolTipWakeUp, toolTipFallAsleep;
120 QPoint toolTipPos, toolTipGlobalPos;
121 QPointer<QWidget> toolTipWidget;
122
123 static QSize app_strut;
124 static QWidgetList *popupWidgets;
125 static QStyle *app_style;
126
127protected:
128 void handleThemeChanged() override;
129
130 QPalette basePalette() const override;
131 void handlePaletteChanged(const char *className = nullptr) override;
132
133#if QT_CONFIG(draganddrop)
134 void notifyDragStarted(const QDrag *) override;
135#endif // QT_CONFIG(draganddrop)
136
137public:
138 static QFont *sys_font;
139 static QFont *set_font;
140 static QWidget *main_widget;
141 static QWidget *focus_widget;
142 static QWidget *hidden_focus_widget;
143#if QT_CONFIG(wheelevent)
144 static QPointer<QWidget> wheel_widget;
145#endif
146
147 static int enabledAnimations; // Combination of QPlatformTheme::UiEffect
148 static bool widgetCount; // Coupled with -widgetcount switch
149
150 static void initializeWidgetPalettesFromTheme();
151 static void initializeWidgetFontHash();
152 static void setSystemFont(const QFont &font);
153
154 using PaletteHash = QHash<QByteArray, QPalette>;
155 static PaletteHash widgetPalettes;
156
157 static QApplicationPrivate *instance() { return self; }
158
159#ifndef QT_NO_STYLE_STYLESHEET
160 static QString styleSheet;
161#endif
162 static QPointer<QWidget> leaveAfterRelease;
163 static QWidget *pickMouseReceiver(QWidget *candidate, const QPointF &windowPos, QPointF *pos,
164 QEvent::Type type, Qt::MouseButtons buttons,
165 QWidget *buttonDown, QWidget *alienWidget);
166 static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget,
167 QWidget *native, QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver,
168 bool spontaneous = true, bool onlyDispatchEnterLeave = false);
169 void sendSyntheticEnterLeave(QWidget *widget);
170
171 static QWindow *windowForWidget(const QWidget *widget)
172 {
173 if (QWindow *window = widget->windowHandle())
174 return window;
175 if (const QWidget *nativeParent = widget->nativeParentWidget())
176 return nativeParent->windowHandle();
177 return nullptr;
178 }
179
180#ifdef Q_OS_WIN
181 static HWND getHWNDForWidget(const QWidget *widget)
182 {
183 if (QWindow *window = windowForWidget(widget))
184 if (auto *windowInterface = window->nativeInterface<QNativeInterface::Private::QWindowsWindow>())
185 return windowInterface->handle();
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:5038
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