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
qplatformintegration.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
4#ifndef QPLATFORMINTEGRATION_H
5#define QPLATFORMINTEGRATION_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is part of the QPA API and is not meant to be used
12// in applications. Usage of this API may make your code
13// source and binary incompatible with future versions of Qt.
14//
15
16#include <QtGui/qtguiglobal.h>
17#include <QtGui/qwindowdefs.h>
18#include <qpa/qplatformscreen.h>
19#include <QtGui/qsurfaceformat.h>
20#include <QtGui/qopenglcontext.h>
21
23
24
25class QPlatformWindow;
26class QWindow;
27class QPlatformBackingStore;
28class QPlatformFontDatabase;
29class QPlatformClipboard;
30class QPlatformNativeInterface;
31class QPlatformDrag;
32class QPlatformOpenGLContext;
33class QGuiGLFormat;
34class QAbstractEventDispatcher;
35class QPlatformInputContext;
36class QPlatformKeyMapper;
37class QPlatformAccessibility;
38class QPlatformTheme;
39class QPlatformDialogHelper;
40class QPlatformSharedGraphicsCache;
41class QPlatformServices;
42class QPlatformSessionManager;
43class QKeyEvent;
44class QPlatformOffscreenSurface;
45class QOffscreenSurface;
46class QPlatformVulkanInstance;
47class QVulkanInstance;
48
49namespace QNativeInterface::Private {
50
51template <typename R, typename I, auto func, typename... Args>
53{
54 template <typename T>
55 static R apply(T *obj, Args... args)
56 {
57 if (auto *iface = dynamic_cast<I*>(obj))
58 return (iface->*func)(args...);
59 else
60 return R();
61 }
62};
63
64template <auto func>
66template <typename R, typename I, typename... Args, R(I::*func)(Args...)>
67struct QInterfaceProxy<func> : public QInterfaceProxyImp<R, I, func, Args...> {};
68template <typename R, typename I, typename... Args, R(I::*func)(Args...) const>
69struct QInterfaceProxy<func> : public QInterfaceProxyImp<R, I, func, Args...> {};
70
71} // QNativeInterface::Private
72
73class Q_GUI_EXPORT QPlatformIntegration
74{
75public:
76 Q_DISABLE_COPY_MOVE(QPlatformIntegration)
77
78 enum Capability {
79 ThreadedPixmaps = 1,
80 OpenGL,
81 ThreadedOpenGL,
82 SharedGraphicsCache,
83 BufferQueueingOpenGL,
84 WindowMasks,
85 MultipleWindows,
86 ApplicationState,
87 ForeignWindows,
88 NonFullScreenWindows,
89 NativeWidgets,
90 WindowManagement,
91 WindowActivation, // whether requestActivate is supported
92 SyncState,
93#if QT_REMOVAL_QT7_DEPRECATED_SINCE(6, 11)
94 RasterGLSurface Q_DECL_ENUMERATOR_DEPRECATED_X("This capability is no longer used"),
95#endif
96 AllGLFunctionsQueryable,
97 ApplicationIcon,
98 SwitchableWidgetComposition,
99 TopStackedNativeChildWindows,
100 OpenGLOnRasterSurface,
101 MaximizeUsingFullscreenGeometry,
102 PaintEvents,
103 RhiBasedRendering,
104 ScreenWindowGrabbing, // whether QScreen::grabWindow() is supported
105 BackingStoreStaticContents
106 };
107
108 virtual ~QPlatformIntegration() { }
109
110 virtual bool hasCapability(Capability cap) const;
111
112 virtual QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const;
113 virtual QPlatformWindow *createPlatformWindow(QWindow *window) const = 0;
114 virtual QPlatformWindow *createForeignWindow(QWindow *, WId) const { return nullptr; }
115 virtual QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const = 0;
116#ifndef QT_NO_OPENGL
117 virtual QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const;
118#endif
119 virtual QPlatformSharedGraphicsCache *createPlatformSharedGraphicsCache(const char *cacheId) const;
120 virtual QPaintEngine *createImagePaintEngine(QPaintDevice *paintDevice) const;
121
122// Event dispatcher:
123 virtual QAbstractEventDispatcher *createEventDispatcher() const = 0;
124 virtual void initialize();
125 virtual void destroy();
126
127//Deeper window system integrations
128 virtual QPlatformFontDatabase *fontDatabase() const;
129#ifndef QT_NO_CLIPBOARD
130 virtual QPlatformClipboard *clipboard() const;
131#endif
132#if QT_CONFIG(draganddrop)
133 virtual QPlatformDrag *drag() const;
134#endif
135 virtual QPlatformInputContext *inputContext() const;
136#if QT_CONFIG(accessibility)
137 virtual QPlatformAccessibility *accessibility() const;
138#endif
139
140 // Access native handles. The window handle is already available from Wid;
141 virtual QPlatformNativeInterface *nativeInterface() const;
142
143 virtual QPlatformServices *services() const;
144
145 enum StyleHint {
146 CursorFlashTime,
147 KeyboardInputInterval,
148 MouseDoubleClickInterval,
149 StartDragDistance,
150 StartDragTime,
151 KeyboardAutoRepeatRate,
152 ShowIsFullScreen,
153 PasswordMaskDelay,
154 FontSmoothingGamma,
155 StartDragVelocity,
156 UseRtlExtensions,
157 PasswordMaskCharacter,
158 SetFocusOnTouchRelease,
159 ShowIsMaximized,
160 MousePressAndHoldInterval,
161 TabFocusBehavior,
162 ReplayMousePressOutsidePopup,
163 ItemViewActivateItemOnSingleClick,
164 UiEffects,
165 WheelScrollLines,
166 ShowShortcutsInContextMenus,
167 MouseQuickSelectionThreshold,
168 MouseDoubleClickDistance,
169 FlickStartDistance,
170 FlickMaximumVelocity,
171 FlickDeceleration,
172 UnderlineShortcut,
173 };
174
175 virtual QVariant styleHint(StyleHint hint) const;
176 virtual Qt::WindowState defaultWindowState(Qt::WindowFlags) const;
177
178protected:
179 virtual Qt::KeyboardModifiers queryKeyboardModifiers() const;
180 virtual QList<int> possibleKeys(const QKeyEvent *) const;
181 friend class QPlatformKeyMapper;
182public:
183 virtual QPlatformKeyMapper *keyMapper() const;
184
185 virtual QStringList themeNames() const;
186 virtual QPlatformTheme *createPlatformTheme(const QString &name) const;
187
188 virtual QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const;
189
190#ifndef QT_NO_SESSIONMANAGER
191 virtual QPlatformSessionManager *createPlatformSessionManager(const QString &id, const QString &key) const;
192#endif
193
194 virtual void sync();
195
196#ifndef QT_NO_OPENGL
197 virtual QOpenGLContext::OpenGLModuleType openGLModuleType();
198#endif
199 virtual void setApplicationIcon(const QIcon &icon) const;
200 virtual void setApplicationBadge(qint64 number);
201
202 virtual void beep() const;
203 virtual void quit() const;
204
205#if QT_CONFIG(vulkan) || defined(Q_QDOC)
206 virtual QPlatformVulkanInstance *createPlatformVulkanInstance(QVulkanInstance *instance) const;
207#endif
208
209 template <auto func, typename... Args>
210 auto call(Args... args)
211 {
212 using namespace QNativeInterface::Private;
213 return QInterfaceProxy<func>::apply(this, args...);
214 }
215
216protected:
217 QPlatformIntegration() = default;
218};
219
220QT_END_NAMESPACE
221
222#endif // QPLATFORMINTEGRATION_H
Collection of utility functions for UI scaling.
The QPlatformIntegration class is the entry for WindowSystem specific functionality.
T toNativePixels(const T &value, const C *context)
QHighDpiScaling::Point position(T, QHighDpiScaling::Point::Kind)
QList< T > scale(const QList< T > &list, qreal scaleFactor, QPoint origin=QPoint(0, 0))
T toNativeLocalPosition(const T &value, const C *context)
QSize scale(const QSize &value, qreal scaleFactor, QPointF=QPointF(0, 0))
T toNativeGlobalPosition(const T &value, const C *context)
T fromNativeLocalPosition(const T &value, const C *context)
T fromNativeGlobalPosition(const T &value, const C *context)
T toNative(const T &value, qreal scaleFactor, QPoint origin=QPoint(0, 0))
QRect fromNativeScreenGeometry(const QRect &nativeScreenGeometry, const QScreen *screen)
QRect fromNative(const QRect &rect, const QScreen *screen, const QPoint &screenOrigin)
QRegion fromNativeLocalExposedRegion(const QRegion &pixelRegion, const QWindow *window)
QRegion fromNativeLocalRegion(const QRegion &pixelRegion, const QWindow *window)
qreal scale(qreal value, qreal scaleFactor, QPointF=QPointF(0, 0))
T fromNativePixels(const T &value, const C *context)
QHighDpiScaling::Point position(QPoint point, QHighDpiScaling::Point::Kind kind)
QRegion toNativeLocalRegion(const QRegion &pointRegion, const QWindow *window)
T fromNative(const T &value, qreal scaleFactor, QPoint origin=QPoint(0, 0))
T toNativeWindowGeometry(const T &value, const C *context)
T fromNativeWindowGeometry(const T &value, const C *context)
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcEventDispatcher)
static const char screenFactorsEnvVar[]
static const char dpiAdjustmentPolicyEnvVar[]
static const ScaleFactorRoundingPolicyLookup scaleFactorRoundingPolicyLookup[]
static bool operator==(const EnumLookup< EnumType > &e1, const EnumLookup< EnumType > &e2)
static const char scaleFactorRoundingPolicyEnvVar[]
static std::optional< qreal > qEnvironmentVariableOptionalReal(const char *name)
static Qt::HighDpiScaleFactorRoundingPolicy lookupScaleFactorRoundingPolicy(const QByteArray &v)
static const char enableHighDpiScalingEnvVar[]
static const DpiAdjustmentPolicyLookup dpiAdjustmentPolicyLookup[]
static const char usePhysicalDpiEnvVar[]
static std::optional< QString > qEnvironmentVariableOptionalString(const char *name)
static std::optional< QByteArray > qEnvironmentVariableOptionalByteArray(const char *name)
static QByteArray joinEnumValues(const EnumLookup< EnumType > *i1, const EnumLookup< EnumType > *i2)
static const char scaleFactorEnvVar[]
static const char scaleFactorProperty[]
static QHighDpiScaling::DpiAdjustmentPolicy lookupDpiAdjustmentPolicy(const QByteArray &v)
std::pair< qreal, qreal > QDpi
const char * name