QtBase  v6.3.1
qpaintengine_preview.cpp
Go to the documentation of this file.
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 <private/qpaintengine_preview_p.h>
41 #include <private/qpainter_p.h>
42 #include <private/qpaintengine_p.h>
43 #include <private/qpicture_p.h>
44 
45 #include <QtPrintSupport/qprintengine.h>
46 #include <QtGui/qpainter.h>
47 #include <QtGui/qpicture.h>
48 
50 
52 {
53  Q_DECLARE_PUBLIC(QPreviewPaintEngine)
54 public:
57 
62 
65 };
66 
67 
69  : QPaintEngine(*(new QPreviewPaintEnginePrivate), PaintEngineFeatures(AllFeatures & ~ObjectBoundingModeGradients))
70 {
72  d->proxy_print_engine = nullptr;
73  d->proxy_paint_engine = nullptr;
74 }
75 
77 {
79 
80  qDeleteAll(d->pages);
81 }
82 
84 {
86 
87  qDeleteAll(d->pages);
88  d->pages.clear();
89 
90  QPicture *page = new QPicture;
91  page->d_func()->in_memory_only = true;
92  d->painter = new QPainter(page);
93  d->engine = d->painter->paintEngine();
94  *d->painter->d_func()->state = *painter()->d_func()->state;
95  d->pages.append(page);
96  d->state = QPrinter::Active;
97  return true;
98 }
99 
101 {
102  Q_D(QPreviewPaintEngine);
103 
104  delete d->painter;
105  d->painter = nullptr;
106  d->engine = nullptr;
107  d->state = QPrinter::Idle;
108  return true;
109 }
110 
112 {
113  Q_D(QPreviewPaintEngine);
114  d->engine->updateState(state);
115 }
116 
118 {
119  Q_D(QPreviewPaintEngine);
120  d->engine->drawPath(path);
121 }
122 
124 {
125  Q_D(QPreviewPaintEngine);
126  d->engine->drawPolygon(points, pointCount, mode);
127 }
128 
130 {
131  Q_D(QPreviewPaintEngine);
132  d->engine->drawTextItem(p, textItem);
133 }
134 
135 void QPreviewPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
136 {
137  Q_D(QPreviewPaintEngine);
138  d->engine->drawPixmap(r, pm, sr);
139 }
140 
142 {
143  Q_D(QPreviewPaintEngine);
144  d->engine->drawTiledPixmap(r, pm, p);
145 }
146 
148 {
149  Q_D(QPreviewPaintEngine);
150 
151  QPicture *page = new QPicture;
152  page->d_func()->in_memory_only = true;
153  QPainter *tmp_painter = new QPainter(page);
154  QPaintEngine *tmp_engine = tmp_painter->paintEngine();
155 
156  // copy the painter state from the original painter
157  Q_ASSERT(painter()->d_func()->state && tmp_painter->d_func()->state);
158  *tmp_painter->d_func()->state = *painter()->d_func()->state;
159 
160  // composition modes aren't supported on a QPrinter and yields a
161  // warning, so ignore it for now
162  tmp_engine->setDirty(DirtyFlags(AllDirty & ~DirtyCompositionMode));
163  tmp_engine->syncState();
164 
165  delete d->painter;
166  d->painter = tmp_painter;
167  d->pages.append(page);
168  d->engine = tmp_engine;
169  return true;
170 }
171 
173 {
174  Q_D(QPreviewPaintEngine);
175  end();
176  qDeleteAll(d->pages);
177  d->state = QPrinter::Aborted;
178 
179  return true;
180 }
181 
183 {
184  Q_D(QPreviewPaintEngine);
185  return d->pages;
186 }
187 
189 {
190  Q_D(QPreviewPaintEngine);
191  d->proxy_print_engine = printEngine;
192  d->proxy_paint_engine = paintEngine;
193 }
194 
196 {
197  Q_D(QPreviewPaintEngine);
198  d->proxy_print_engine->setProperty(key, value);
199 }
200 
202 {
203  Q_D(const QPreviewPaintEngine);
204  return d->proxy_print_engine->property(key);
205 }
206 
208 {
209  Q_D(const QPreviewPaintEngine);
210  return d->proxy_print_engine->metric(id);
211 }
212 
214 {
215  Q_D(const QPreviewPaintEngine);
216  return d->state;
217 }
218 
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:87
friend class QPainter
Definition: qpaintengine.h:255
QPainter * painter() const
void setDirty(DirtyFlags df)
Definition: qpaintengine.h:326
QPaintEngineState * state
Definition: qpaintengine.h:234
The QPaintEngineState class provides information about the active paint engine's current state....
Definition: qpaintengine.h:268
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:82
QPaintEngine * paintEngine() const
Definition: qpainter.cpp:1929
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:65
The QPicture class is a paint device that records and replays QPainter commands.
Definition: qpicture.h:55
The QPixmap class is an off-screen image representation that can be used as a paint device.
Definition: qpixmap.h:63
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
void drawPath(const QPainterPath &path) override
void setProxyEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine)
bool begin(QPaintDevice *dev) override
QList< const QPicture * > pages()
void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) override
void drawTextItem(const QPointF &p, const QTextItem &textItem) override
QVariant property(PrintEnginePropertyKey key) const override
void updateState(const QPaintEngineState &state) override
QPrinter::PrinterState printerState() const override
int metric(QPaintDevice::PaintDeviceMetric) const override
void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) override
void drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &p) override
void setProperty(PrintEnginePropertyKey key, const QVariant &value) override
QList< const QPicture * > pages
QPrinter::PrinterState state
The QPrintEngine class defines an interface for how QPrinter interacts with a given printing subsyste...
Definition: qprintengine.h:55
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:64
PrinterState
Definition: qprinter.h:100
@ Active
Definition: qprinter.h:101
@ Aborted
Definition: qprinter.h:102
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
The QTextItem class provides all the information required to draw text in a custom paint engine.
Definition: qpaintengine.h:64
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
qDeleteAll(list.begin(), list.end())
else opt state
[0]
@ Idle
Definition: qprint_p.h:91
EGLOutputLayerEXT EGLint EGLAttrib value
GLenum mode
GLuint64 key
GLboolean r
[2]
GLfixed GLfixed GLint GLint GLfixed points
Definition: qopenglext.h:5206
GLsizei const GLchar *const * path
Definition: qopenglext.h:4283
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
#define Q_ASSERT(cond)
Definition: qrandom.cpp:84
QByteArray page
[45]