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 };
110
111 virtual ~QPlatformIntegration() { }
112
113 virtual bool hasCapability(Capability cap) const;
114
115 virtual QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const;
116 virtual QPlatformWindow *createPlatformWindow(QWindow *window) const = 0;
117 virtual QPlatformWindow *createForeignWindow(QWindow *, WId) const { return nullptr; }
118 virtual QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const = 0;
119#ifndef QT_NO_OPENGL
120 virtual QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const;
121#endif
122 virtual QPlatformSharedGraphicsCache *createPlatformSharedGraphicsCache(const char *cacheId) const;
123 virtual QPaintEngine *createImagePaintEngine(QPaintDevice *paintDevice) const;
124
125// Event dispatcher:
126 virtual QAbstractEventDispatcher *createEventDispatcher() const = 0;
127 virtual void initialize();
128 virtual void destroy();
129
130//Deeper window system integrations
131 virtual QPlatformFontDatabase *fontDatabase() const;
132#ifndef QT_NO_CLIPBOARD
133 virtual QPlatformClipboard *clipboard() const;
134#endif
135#if QT_CONFIG(draganddrop)
136 virtual QPlatformDrag *drag() const;
137#endif
138 virtual QPlatformInputContext *inputContext() const;
139#if QT_CONFIG(accessibility)
140 virtual QPlatformAccessibility *accessibility() const;
141#endif
142
143 // Access native handles. The window handle is already available from Wid;
144 virtual QPlatformNativeInterface *nativeInterface() const;
145
146 virtual QPlatformServices *services() const;
147
148 enum StyleHint {
149 CursorFlashTime,
150 KeyboardInputInterval,
151 MouseDoubleClickInterval,
152 StartDragDistance,
153 StartDragTime,
154 KeyboardAutoRepeatRate,
155 ShowIsFullScreen,
156 PasswordMaskDelay,
157 FontSmoothingGamma,
158 StartDragVelocity,
159 UseRtlExtensions,
160 PasswordMaskCharacter,
161 SetFocusOnTouchRelease,
162 ShowIsMaximized,
163 MousePressAndHoldInterval,
164 TabFocusBehavior,
165 ReplayMousePressOutsidePopup,
166 ItemViewActivateItemOnSingleClick,
167 UiEffects,
168 WheelScrollLines,
169 ShowShortcutsInContextMenus,
170 MouseQuickSelectionThreshold,
171 MouseDoubleClickDistance,
172 FlickStartDistance,
173 FlickMaximumVelocity,
174 FlickDeceleration,
175 UnderlineShortcut,
176 };
177
178 virtual QVariant styleHint(StyleHint hint) const;
179 virtual Qt::WindowState defaultWindowState(Qt::WindowFlags) const;
180
181protected:
182 virtual Qt::KeyboardModifiers queryKeyboardModifiers() const;
183 virtual QList<int> possibleKeys(const QKeyEvent *) const;
184 friend class QPlatformKeyMapper;
185public:
186 virtual QPlatformKeyMapper *keyMapper() const;
187
188 virtual QStringList themeNames() const;
189 virtual QPlatformTheme *createPlatformTheme(const QString &name) const;
190
191 virtual QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const;
192
193#ifndef QT_NO_SESSIONMANAGER
194 virtual QPlatformSessionManager *createPlatformSessionManager(const QString &id, const QString &key) const;
195#endif
196
197 virtual void sync();
198
199#ifndef QT_NO_OPENGL
200 virtual QOpenGLContext::OpenGLModuleType openGLModuleType();
201#endif
202 virtual void setApplicationIcon(const QIcon &icon) const;
203 virtual void setApplicationBadge(qint64 number);
204
205 virtual void beep() const;
206 virtual void quit() const;
207
208#if QT_CONFIG(vulkan) || defined(Q_QDOC)
209 virtual QPlatformVulkanInstance *createPlatformVulkanInstance(QVulkanInstance *instance) const;
210#endif
211
212 template <auto func, typename... Args>
213 auto call(Args... args)
214 {
215 using namespace QNativeInterface::Private;
216 return QInterfaceProxy<func>::apply(this, args...);
217 }
218
219protected:
220 QPlatformIntegration() = default;
221};
222
223QT_END_NAMESPACE
224
225#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