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
qrasterwindow.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
5
6#include <QtGui/private/qpaintdevicewindow_p.h>
7
8#include <QtGui/QBackingStore>
9#include <QtGui/QPainter>
10
12
13/*!
14 \class QRasterWindow
15 \inmodule QtGui
16 \since 5.4
17 \brief QRasterWindow is a convenience class for using QPainter on a QWindow.
18
19 QRasterWindow is a QWindow with a raster-based, non-OpenGL surface. On top of
20 the functionality offered by QWindow, QRasterWindow adds a virtual
21 paintEvent() function and the possibility to open a QPainter on itself. The
22 underlying paint engine will be the raster one, meaning that all drawing will
23 happen on the CPU. For performing accelerated, OpenGL-based drawing, use
24 QOpenGLWindow instead.
25
26 Internally the class is thin wrapper for QWindow and QBackingStore
27 and is very similar to the \l{Raster Window Example}{Raster Window
28 Example} that uses these classes directly.
29
30 \sa QPaintDeviceWindow::paintEvent(), QPaintDeviceWindow::update()
31*/
32
34{
35 Q_DECLARE_PUBLIC(QRasterWindow)
36public:
38 {
40 if (backingstore->size() != q->size())
42 }
43
45 {
47 const QSize size = q->size();
48 if (backingstore->size() != size)
50
52 }
53
55 {
57 }
58
60 {
63 }
64
66};
67
68/*!
69 Constructs a new QRasterWindow with \a parent.
70*/
71QRasterWindow::QRasterWindow(QWindow *parent)
72 : QPaintDeviceWindow(*(new QRasterWindowPrivate), parent)
73{
74 setSurfaceType(QSurface::RasterSurface);
75 d_func()->backingstore.reset(new QBackingStore(this));
76}
77
78QRasterWindow::~QRasterWindow()
79{
80 Q_D(QRasterWindow);
81 // Delete backingstore while window is still alive, as it
82 // might need to reference the window in the process
83 d->backingstore.reset(nullptr);
84}
85
86/*!
87 \internal
88*/
89int QRasterWindow::metric(PaintDeviceMetric metric) const
90{
91 Q_D(const QRasterWindow);
92
93 switch (metric) {
94 case PdmDepth:
95 return d->backingstore->paintDevice()->depth();
96 default:
97 break;
98 }
99 return QPaintDeviceWindow::metric(metric);
100}
101
102/*!
103 \internal
104*/
105QPaintDevice *QRasterWindow::redirected(QPoint *) const
106{
107 Q_D(const QRasterWindow);
108 return d->backingstore->paintDevice();
109}
110
111void QRasterWindow::resizeEvent(QResizeEvent *)
112{
113}
114
115QT_END_NAMESPACE
116
117#include "moc_qrasterwindow.cpp"