Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qoffscreencommon.cpp
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#include "qoffscreencommon.h"
6#include "qoffscreenwindow.h"
7
8
9#include <QtGui/QPainter>
10#include <QtGui/private/qpixmap_raster_p.h>
11#include <QtGui/private/qguiapplication_p.h>
12
13#include <qpa/qplatformcursor.h>
14#include <qpa/qplatformwindow.h>
15
17
19
20
21QList<QPlatformScreen *> QOffscreenScreen::virtualSiblings() const
22{
23 QList<QPlatformScreen *> platformScreens;
24 for (auto screen : m_integration->screens()) {
25 platformScreens.append(screen);
26 }
27 return platformScreens;
28}
29
31{
32public:
33 QOffscreenCursor() : m_pos(10, 10) {}
34
35 QPoint pos() const override { return m_pos; }
36 void setPos(const QPoint &pos) override
37 {
38 m_pos = pos;
40 QWindow *containing = nullptr;
41 for (QWindow *w : wl) {
42 if (w->type() != Qt::Desktop && w->isExposed() && w->geometry().contains(pos)) {
43 containing = w;
44 break;
45 }
46 }
47
48 QPoint local = pos;
49 if (containing)
50 local -= containing->position();
51
53
54 if (containing != previous)
55 QWindowSystemInterface::handleEnterLeaveEvent(containing, previous, local, pos);
56
59
60 QOffscreenScreen::windowContainingCursor = containing ? containing->handle() : nullptr;
61 }
62#ifndef QT_NO_CURSOR
63 void changeCursor(QCursor *windowCursor, QWindow *window) override
64 {
65 Q_UNUSED(windowCursor);
67 }
68#endif
69private:
70 QPoint m_pos;
71};
72
74 : m_geometry(0, 0, 800, 600)
75 , m_cursor(new QOffscreenCursor)
76 , m_integration(integration)
77{
78}
79
80QPixmap QOffscreenScreen::grabWindow(WId id, int x, int y, int width, int height) const
81{
83
84 // id == 0 -> grab the screen, so all windows intersecting rect
85 if (!id) {
86 if (width == -1)
87 rect.setWidth(m_geometry.width());
88 if (height == -1)
89 rect.setHeight(m_geometry.height());
90 QPixmap screenImage(rect.size());
91 QPainter painter(&screenImage);
92 painter.translate(-x, -y);
94 for (QWindow *w : wl) {
95 if (w->isExposed() && w->geometry().intersects(rect)) {
97 const QImage windowImage = store ? store->toImage() : QImage();
98 if (!windowImage.isNull())
99 painter.drawImage(w->position(), windowImage);
100 }
101 }
102 return screenImage;
103 }
104
106 if (store)
107 return store->grabWindow(id, rect);
108 return QPixmap();
109}
110
115
120
122{
123 return &m_image;
124}
125
127{
128 Q_UNUSED(region);
129
130 if (m_image.size().isEmpty())
131 return;
132
133 QSize imageSize = m_image.size();
134
135 QRegion clipped = QRect(0, 0, window->width(), window->height());
136 clipped &= QRect(0, 0, imageSize.width(), imageSize.height()).translated(-offset);
137
138 QRect bounds = clipped.boundingRect().translated(offset);
139
140 if (bounds.isNull())
141 return;
142
143 WId id = window->winId();
144
145 m_windowAreaHash[id] = bounds;
146 m_backingStoreForWinIdHash[id] = this;
147}
148
150{
152 if (m_image.size() != size)
153 m_image = QImage(size, format);
154 clearHash();
155}
156
157extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset);
158
159bool QOffscreenBackingStore::scroll(const QRegion &area, int dx, int dy)
160{
161 if (m_image.isNull())
162 return false;
163
164 const QRect rect = area.boundingRect();
165 qt_scrollRectInImage(m_image, rect, QPoint(dx, dy));
166
167 return true;
168}
169
171{
172 QRect area = m_windowAreaHash.value(window, QRect());
173 if (area.isNull())
174 return QPixmap();
175
176 QRect adjusted = rect;
177 if (adjusted.width() <= 0)
178 adjusted.setWidth(area.width());
179 if (adjusted.height() <= 0)
180 adjusted.setHeight(area.height());
181
182 adjusted = adjusted.translated(area.topLeft()) & area;
183
184 if (adjusted.isEmpty())
185 return QPixmap();
186
187 return QPixmap::fromImage(m_image.copy(adjusted));
188}
189
191{
192 return m_backingStoreForWinIdHash.value(id, nullptr);
193}
194
195void QOffscreenBackingStore::clearHash()
196{
197 for (auto it = m_windowAreaHash.cbegin(), end = m_windowAreaHash.cend(); it != end; ++it) {
198 const auto it2 = std::as_const(m_backingStoreForWinIdHash).find(it.key());
199 if (it2.value() == this)
200 m_backingStoreForWinIdHash.erase(it2);
201 }
202 m_windowAreaHash.clear();
203}
204
205QHash<WId, QOffscreenBackingStore *> QOffscreenBackingStore::m_backingStoreForWinIdHash;
206
208 : m_integration(integration)
209{
210
211}
212
214
215/*
216 Set platform configuration, e.g. screen configuration
217*/
219{
220 iface->m_integration->setConfiguration(configuration);
221}
222
223/*
224 Get the current platform configuration
225*/
227{
228 return iface->m_integration->configuration();
229}
230
232{
233 if (resource == "setConfiguration")
234 return reinterpret_cast<void*>(&QOffscreenPlatformNativeInterface::setConfiguration);
235 else if (resource == "configuration")
236 return reinterpret_cast<void*>(&QOffscreenPlatformNativeInterface::configuration);
237 else
238 return nullptr;
239}
240
\inmodule QtCore
Definition qbytearray.h:57
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition qcursor.h:45
@ MouseMove
Definition qcoreevent.h:63
static QWindowList topLevelWindows()
Returns a list of the top-level windows in the application.
QScreen * primaryScreen
the primary (or default) screen of the application.
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
static Qt::MouseButtons mouseButtons()
Returns the current state of the buttons on the mouse.
const_iterator cbegin() const noexcept
Definition qhash.h:1214
T value(const Key &key) const noexcept
Definition qhash.h:1054
const_iterator cend() const noexcept
Definition qhash.h:1218
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
Definition qhash.h:951
\inmodule QtGui
Definition qimage.h:37
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
QSize size() const
Returns the size of the image, i.e.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition qimage.cpp:1222
Format
The following image formats are available in Qt.
Definition qimage.h:41
\inmodule QtCore\reentrant
Definition qjsonobject.h:20
void append(parameter_type t)
Definition qlist.h:458
bool scroll(const QRegion &area, int dx, int dy) override
Scrolls the given area dx pixels to the right and dy downward; both dx and dy may be negative.
QImage toImage() const override
Implemented in subclasses to return the content of the backingstore as a QImage.
static QOffscreenBackingStore * backingStoreForWinId(WId id)
void flush(QWindow *window, const QRegion &region, const QPoint &offset) override
Flushes the given region from the specified window.
void resize(const QSize &size, const QRegion &staticContents) override
QOffscreenBackingStore(QWindow *window)
QPaintDevice * paintDevice() override
Implement this function to return the appropriate paint device.
QPixmap grabWindow(WId window, const QRect &rect) const
void setPos(const QPoint &pos) override
QPoint pos() const override
void changeCursor(QCursor *windowCursor, QWindow *window) override
This method is called by Qt whenever the cursor graphic should be changed.
QList< QOffscreenScreen * > screens() const
void * nativeResourceForIntegration(const QByteArray &resource) override
QOffscreenPlatformNativeInterface(QOffscreenIntegration *integration)
static QJsonObject configuration(QOffscreenPlatformNativeInterface *iface)
static void setConfiguration(const QJsonObject &configuration, QOffscreenPlatformNativeInterface *iface)
static QPlatformWindow * windowContainingCursor
QOffscreenScreen(const QOffscreenIntegration *integration)
QList< QPlatformScreen * > virtualSiblings() const override
Returns a list of all the platform screens that are part of the same virtual desktop.
QPixmap grabWindow(WId window, int x, int y, int width, int height) const override
This function is called when Qt needs to be able to grab the content of a window.
const QOffscreenIntegration * m_integration
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Draws the rectangular portion source of the given image into the target rectangle in the paint device...
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition qpixmap.cpp:1437
The QPlatformBackingStore class provides the drawing area for top-level windows.
QWindow * window() const
Returns a pointer to the top-level window associated with this surface.
The QPlatformCursor class provides information about pointer device events (movement,...
QScreen * screen() const
virtual QImage::Format format() const =0
Reimplement in subclass to return the image format which corresponds to the screen format.
The QPlatformWindow class provides an abstraction for top-level windows.
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr bool isEmpty() const noexcept
Returns true if the rectangle is empty, otherwise returns false.
Definition qrect.h:167
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition qrect.h:164
constexpr void setWidth(int w) noexcept
Sets the width of the rectangle to the given width.
Definition qrect.h:381
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
constexpr QRect translated(int dx, int dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
Definition qrect.h:261
constexpr void setHeight(int h) noexcept
Sets the height of the rectangle to the given height.
Definition qrect.h:384
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
QPlatformScreen * handle() const
Get the platform screen handle.
Definition qscreen.cpp:83
\inmodule QtCore
Definition qsize.h:25
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
Definition qsize.h:124
static bool handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
static void handleEnterLeaveEvent(QWindow *enter, QWindow *leave, const QPointF &local=QPointF(), const QPointF &global=QPointF())
This method can be used to ensure leave and enter events are both in queue when moving from one QWind...
\inmodule QtGui
Definition qwindow.h:63
int width
the width of the window's geometry
Definition qwindow.h:82
int height
the height of the window's geometry
Definition qwindow.h:83
QSet< QString >::iterator it
rect
[4]
Combined button and popup list for selecting options.
@ NoButton
Definition qnamespace.h:57
@ MouseEventSynthesizedByQt
@ Desktop
Definition qnamespace.h:215
static int area(const QSize &s)
Definition qicon.cpp:153
void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset)
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLuint end
GLenum GLuint id
[7]
GLint GLsizei width
GLenum GLuint GLintptr offset
GLint GLsizei GLsizei GLenum format
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei imageSize
GLint y
GLint void * img
Definition qopenglext.h:233
void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset)
#define Q_UNUSED(x)
QPainter painter(this)
[7]
aWidget window() -> setWindowTitle("New Window Title")
[2]