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