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
qpaintengine_preview.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 <private/qpaintengine_preview_p.h>
5#include <private/qpainter_p.h>
6#include <private/qpaintengine_p.h>
7#include <private/qpicture_p.h>
8
9#include <QtPrintSupport/qprintengine.h>
10#include <QtGui/qpainter.h>
11#include <QtGui/qpicture.h>
12
14
30
31
33 : QPaintEngine(*(new QPreviewPaintEnginePrivate), PaintEngineFeatures(AllFeatures & ~ObjectBoundingModeGradients))
34{
36 d->proxy_print_engine = nullptr;
37 d->proxy_paint_engine = nullptr;
38}
39
46
48{
50
51 qDeleteAll(d->pages);
52 d->pages.clear();
53
54 QPicture *page = new QPicture;
55 page->d_func()->in_memory_only = true;
56 d->painter = new QPainter(page);
57 d->engine = d->painter->paintEngine();
58 *d->painter->d_func()->state = *painter()->d_func()->state;
59 d->pages.append(page);
60 d->state = QPrinter::Active;
61 return true;
62}
63
65{
67
68 delete d->painter;
69 d->painter = nullptr;
70 d->engine = nullptr;
71 d->state = QPrinter::Idle;
72 return true;
73}
74
76{
78 d->engine->updateState(state);
79}
80
82{
84 d->engine->drawPath(path);
85}
86
88{
90 d->engine->drawPolygon(points, pointCount, mode);
91}
92
94{
96 d->engine->drawTextItem(p, textItem);
97}
98
99void QPreviewPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
100{
102 d->engine->drawPixmap(r, pm, sr);
103}
104
106{
108 d->engine->drawTiledPixmap(r, pm, p);
109}
110
112{
114
115 QPicture *page = new QPicture;
116 page->d_func()->in_memory_only = true;
117 QPainter *tmp_painter = new QPainter(page);
118 QPaintEngine *tmp_engine = tmp_painter->paintEngine();
119
120 // copy the painter state from the original painter
121 Q_ASSERT(painter()->d_func()->state && tmp_painter->d_func()->state);
122 *tmp_painter->d_func()->state = *painter()->d_func()->state;
123
124 // composition modes aren't supported on a QPrinter and yields a
125 // warning, so ignore it for now
126 tmp_engine->setDirty(DirtyFlags(AllDirty & ~DirtyCompositionMode));
127 tmp_engine->syncState();
128
129 delete d->painter;
130 d->painter = tmp_painter;
131 d->pages.append(page);
132 d->engine = tmp_engine;
133 return true;
134}
135
137{
139 end();
140 qDeleteAll(d->pages);
141 d->state = QPrinter::Aborted;
142
143 return true;
144}
145
146QList<const QPicture *> QPreviewPaintEngine::pages()
147{
149 return d->pages;
150}
151
153{
155 d->proxy_print_engine = printEngine;
156 d->proxy_paint_engine = paintEngine;
157}
158
160{
162 d->proxy_print_engine->setProperty(key, value);
163}
164
166{
167 Q_D(const QPreviewPaintEngine);
168 return d->proxy_print_engine->property(key);
169}
170
172{
173 Q_D(const QPreviewPaintEngine);
174 return d->proxy_print_engine->metric(id);
175}
176
178{
179 Q_D(const QPreviewPaintEngine);
180 return d->state;
181}
182
The QPaintEngineState class provides information about the active paint engine's current state....
QPaintEngine::DirtyFlags state() const
Returns a combination of flags identifying the set of properties that need to be updated when updatin...
\inmodule QtGui
friend class QPainter
PolygonDrawMode
\value OddEvenMode The polygon should be drawn using OddEven fill rule.
QPainter * painter() const
Returns the paint engine's painter.
QPaintEngineState * state
\inmodule QtGui
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
The QPicture class is a paint device that records and replays QPainter commands.
Definition qpicture.h:19
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\inmodule QtCore\reentrant
Definition qpoint.h:217
QList< const QPicture * > pages
void drawPath(const QPainterPath &path) override
The default implementation ignores the path and does nothing.
void setProxyEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine)
bool begin(QPaintDevice *dev) override
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
QList< const QPicture * > pages()
void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) override
Reimplement this virtual function to draw the polygon defined by the pointCount first points in point...
bool abort() override
Instructs the print engine to abort the printing process.
void drawTextItem(const QPointF &p, const QTextItem &textItem) override
This function draws the text item textItem at position p.
bool end() override
Reimplement this function to finish painting on the current paint device.
QVariant property(PrintEnginePropertyKey key) const override
Returns the print engine's property specified by key.
void updateState(const QPaintEngineState &state) override
Reimplement this function to update the state of a paint engine.
QPrinter::PrinterState printerState() const override
Returns the current state of the printer being used by the print engine.
int metric(QPaintDevice::PaintDeviceMetric) const override
Returns the metric for the given id.
bool newPage() override
Instructs the print engine to start a new page.
void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) override
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r.
void drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &p) override
Reimplement this function to draw the pixmap in the given rect, starting at the given p.
void setProperty(PrintEnginePropertyKey key, const QVariant &value) override
Sets the print engine's property specified by key to the given value.
\reentrant
PrintEnginePropertyKey
This enum is used to communicate properties between the print engine and QPrinter.
\reentrant
Definition qprinter.h:28
PrinterState
\value Idle \value Active \value Aborted \value Error
Definition qprinter.h:64
@ Aborted
Definition qprinter.h:66
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtGui
\inmodule QtCore
Definition qvariant.h:65
qDeleteAll(list.begin(), list.end())
else opt state
[0]
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum mode
GLuint64 key
GLboolean r
[2]
GLfixed GLfixed GLint GLint GLfixed points
GLsizei const GLchar *const * path
GLfloat GLfloat p
[1]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QByteArray page
[45]