/src/qtbase/src/gui/kernel/qrasterwindow.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /**************************************************************************** |
2 | | ** |
3 | | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | | ** Contact: https://www.qt.io/licensing/ |
5 | | ** |
6 | | ** This file is part of the QtGui module of the Qt Toolkit. |
7 | | ** |
8 | | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | | ** Commercial License Usage |
10 | | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | | ** accordance with the commercial license agreement provided with the |
12 | | ** Software or, alternatively, in accordance with the terms contained in |
13 | | ** a written agreement between you and The Qt Company. For licensing terms |
14 | | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | | ** information use the contact form at https://www.qt.io/contact-us. |
16 | | ** |
17 | | ** GNU Lesser General Public License Usage |
18 | | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | | ** General Public License version 3 as published by the Free Software |
20 | | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | | ** packaging of this file. Please review the following information to |
22 | | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | | ** |
25 | | ** GNU General Public License Usage |
26 | | ** Alternatively, this file may be used under the terms of the GNU |
27 | | ** General Public License version 2.0 or (at your option) the GNU General |
28 | | ** Public license version 3 or any later version approved by the KDE Free |
29 | | ** Qt Foundation. The licenses are as published by the Free Software |
30 | | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | | ** included in the packaging of this file. Please review the following |
32 | | ** information to ensure the GNU General Public License requirements will |
33 | | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | | ** |
36 | | ** $QT_END_LICENSE$ |
37 | | ** |
38 | | ****************************************************************************/ |
39 | | |
40 | | #include "qrasterwindow.h" |
41 | | |
42 | | #include <QtGui/private/qpaintdevicewindow_p.h> |
43 | | |
44 | | #include <QtGui/QBackingStore> |
45 | | #include <QtGui/QPainter> |
46 | | |
47 | | QT_BEGIN_NAMESPACE |
48 | | |
49 | | /*! |
50 | | \class QRasterWindow |
51 | | \inmodule QtGui |
52 | | \since 5.4 |
53 | | \brief QRasterWindow is a convenience class for using QPainter on a QWindow. |
54 | | |
55 | | QRasterWindow is a QWindow with a raster-based, non-OpenGL surface. On top of |
56 | | the functionality offered by QWindow, QRasterWindow adds a virtual |
57 | | paintEvent() function and the possibility to open a QPainter on itself. The |
58 | | underlying paint engine will be the raster one, meaning that all drawing will |
59 | | happen on the CPU. For performing accelerated, OpenGL-based drawing, use |
60 | | QOpenGLWindow instead. |
61 | | |
62 | | Internally the class is thin wrapper for QWindow and QBackingStore |
63 | | and is very similar to the \l{Raster Window Example}{Raster Window |
64 | | Example} that uses these classes directly. |
65 | | |
66 | | \sa QPaintDeviceWindow::paintEvent(), QPaintDeviceWindow::update() |
67 | | */ |
68 | | |
69 | | class QRasterWindowPrivate : public QPaintDeviceWindowPrivate |
70 | | { |
71 | | Q_DECLARE_PUBLIC(QRasterWindow) |
72 | | public: |
73 | | void beginPaint(const QRegion ®ion) override |
74 | 0 | { |
75 | 0 | Q_Q(QRasterWindow); |
76 | 0 | const QSize size = q->size(); |
77 | 0 | if (backingstore->size() != size) { |
78 | 0 | backingstore->resize(size); |
79 | 0 | markWindowAsDirty(); |
80 | 0 | } |
81 | 0 | backingstore->beginPaint(region); |
82 | 0 | } |
83 | | |
84 | | void endPaint() override |
85 | 0 | { |
86 | 0 | backingstore->endPaint(); |
87 | 0 | } |
88 | | |
89 | | void flush(const QRegion ®ion) override |
90 | 0 | { |
91 | 0 | Q_Q(QRasterWindow); |
92 | 0 | backingstore->flush(region, q); |
93 | 0 | } |
94 | | |
95 | | QScopedPointer<QBackingStore> backingstore; |
96 | | }; |
97 | | |
98 | | /*! |
99 | | Constructs a new QRasterWindow with \a parent. |
100 | | */ |
101 | | QRasterWindow::QRasterWindow(QWindow *parent) |
102 | 0 | : QPaintDeviceWindow(*(new QRasterWindowPrivate), parent) |
103 | 0 | { |
104 | 0 | setSurfaceType(QSurface::RasterSurface); |
105 | 0 | d_func()->backingstore.reset(new QBackingStore(this)); |
106 | 0 | } |
107 | | |
108 | | QRasterWindow::~QRasterWindow() |
109 | 0 | { |
110 | 0 | Q_D(QRasterWindow); |
111 | | // Delete backingstore while window is still alive, as it |
112 | | // might need to reference the window in the process |
113 | 0 | d->backingstore.reset(nullptr); |
114 | 0 | } |
115 | | |
116 | | /*! |
117 | | \internal |
118 | | */ |
119 | | int QRasterWindow::metric(PaintDeviceMetric metric) const |
120 | 0 | { |
121 | 0 | Q_D(const QRasterWindow); |
122 | |
|
123 | 0 | switch (metric) { |
124 | 0 | case PdmDepth: |
125 | 0 | return d->backingstore->paintDevice()->depth(); |
126 | 0 | default: |
127 | 0 | break; |
128 | 0 | } |
129 | 0 | return QPaintDeviceWindow::metric(metric); |
130 | 0 | } |
131 | | |
132 | | /*! |
133 | | \internal |
134 | | */ |
135 | | QPaintDevice *QRasterWindow::redirected(QPoint *) const |
136 | 0 | { |
137 | 0 | Q_D(const QRasterWindow); |
138 | 0 | return d->backingstore->paintDevice(); |
139 | 0 | } |
140 | | |
141 | | QT_END_NAMESPACE |
142 | | |
143 | | #include "moc_qrasterwindow.cpp" |