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 bool handleQuitEvent() override;
74
75 static bool autoSipEnabled;
76 static QString desktopStyleKey();
77
78 void createEventDispatcher() override;
79 static void dispatchEnterLeave(QWidget *enter, QWidget *leave, const QPointF &globalPosF);
80 static QWidget *desktop();
81 void notifyWindowIconChanged() override;
82 bool compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents) final;
83
84#if QT_CONFIG(action)
85 QActionPrivate *createActionPrivate() const override;
86#endif
87#ifndef QT_NO_SHORTCUT
88 QShortcutPrivate *createShortcutPrivate() const override;
89#endif
90
91 //modality
92 Qt::WindowModality defaultModality() const override;
93 bool windowNeverBlocked(QWindow *window) const override;
94 static bool isBlockedByModal(QWidget *widget);
95 static bool modalState();
96 static bool tryModalHelper(QWidget *widget, QWidget **rettop = nullptr);
97
98 bool notify_helper(QObject *receiver, QEvent * e);
99
100 void init();
101 void initialize();
102 void process_cmdline();
103
104 static void setActiveWindow(QWidget* act);
105
106 static bool inPopupMode();
107 void closePopup(QWidget *popup);
108 void openPopup(QWidget *popup);
109 static bool replayMousePress;
110
111 static void setFocusWidget(QWidget *focus, Qt::FocusReason reason);
112 static QWidget *focusNextPrevChild_helper(QWidget *toplevel, bool next,
113 bool *wrappingOccurred = nullptr);
114
115#if QT_CONFIG(graphicsview)
116 // Maintain a list of all scenes to ensure font and palette propagation to
117 // all scenes.
118 QList<QGraphicsScene *> scene_list;
119#endif
120
121 QBasicTimer toolTipWakeUp, toolTipFallAsleep;
122 QPoint toolTipPos, toolTipGlobalPos;
123 QPointer<QWidget> toolTipWidget;
124
125 static QSize app_strut;
126 static QWidgetList *popupWidgets;
127 static QStyle *app_style;
128
129protected:
130 void handleThemeChanged() override;
131
132 QPalette basePalette() const override;
133 void handlePaletteChanged(const char *className = nullptr) override;
134
135#if QT_CONFIG(draganddrop)
136 void notifyDragStarted(const QDrag *) override;
137#endif // QT_CONFIG(draganddrop)
138
139public:
140 static QFont *sys_font;
141 static QFont *set_font;
142 static QWidget *main_widget;
143 static QWidget *focus_widget;
144 static QWidget *hidden_focus_widget;
145#if QT_CONFIG(wheelevent)
146 static QPointer<QWidget> wheel_widget;
147#endif
148
149 static int enabledAnimations; // Combination of QPlatformTheme::UiEffect
150 static bool widgetCount; // Coupled with -widgetcount switch
151
152 static void initializeWidgetPalettesFromTheme();
153 static void initializeWidgetFontHash();
154 static void setSystemFont(const QFont &font);
155
156 using PaletteHash = QHash<QByteArray, QPalette>;
157 static PaletteHash widgetPalettes;
158
159 static QApplicationPrivate *instance() { return self; }
160
161#ifndef QT_NO_STYLE_STYLESHEET
162 static QString styleSheet;
163#endif
164 static QPointer<QWidget> leaveAfterRelease;
165 static QWidget *pickMouseReceiver(QWidget *candidate, const QPointF &windowPos, QPointF *pos,
166 QEvent::Type type, Qt::MouseButtons buttons,
167 QWidget *buttonDown, QWidget *alienWidget);
168 static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget,
169 QWidget *native, QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver,
170 bool spontaneous = true, bool onlyDispatchEnterLeave = false);
171 void sendSyntheticEnterLeave(QWidget *widget);
172
173 static QWindow *windowForWidget(const QWidget *widget)
174 {
175 if (QWindow *window = widget->windowHandle())
176 return window;
177 if (const QWidget *nativeParent = widget->nativeParentWidget())
178 return nativeParent->windowHandle();
179 return nullptr;
180 }
181
182#ifdef Q_OS_WIN
183 static HWND getHWNDForWidget(const QWidget *widget)
184 {
185 if (QWindow *window = windowForWidget(widget))
186 if (auto *windowInterface = window->nativeInterface<QNativeInterface::Private::QWindowsWindow>())
187 return windowInterface->handle();
188 return 0;
189 }
190#endif
191
192#ifndef QT_NO_GESTURES
193 QGestureManager *gestureManager;
194 QWidget *gestureWidget;
195#endif
196
197 static bool updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent);
198 void initializeMultitouch();
199 void initializeMultitouch_sys();
200 void cleanupMultitouch();
201 void cleanupMultitouch_sys();
202 QWidget *findClosestTouchPointTarget(const QPointingDevice *device, const QEventPoint &touchPoint);
203 void appendTouchPoint(const QEventPoint &touchPoint);
204 void removeTouchPoint(int touchPointId);
205 enum ImplicitTouchGrabMode { GrabAcceptedPoints, GrabAllPoints };
206 void activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchBeginEvent,
207 ImplicitTouchGrabMode grabMode = GrabAcceptedPoints);
208 static bool translateRawTouchEvent(QWidget *widget, const QTouchEvent *touchEvent);
209 static void translateTouchCancel(const QPointingDevice *device, ulong timestamp);
210
211 QPixmap applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const override;
212
213private:
214 static QApplicationPrivate *self;
215 static bool tryCloseAllWidgetWindows(QWindowList *processedWindows);
216
217 static void giveFocusAccordingToFocusPolicy(QWidget *w, QEvent *event, QPoint localPos);
218 static bool shouldSetFocus(QWidget *w, Qt::FocusPolicy policy);
219
220 static QWidget *active_window;
221
222 static bool isAlien(QWidget *);
223};
224
225extern void qt_qpa_set_cursor(QWidget * w, bool force);
226
227QT_END_NAMESPACE
228
229#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)
QPointer< QWidget > qt_last_mouse_receiver
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:919