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