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