1// Copyright (C) 2020 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 "qpagedpaintdevice_p.h"
5#include <qpagedpaintdevice.h>
6
7QT_BEGIN_NAMESPACE
8
9
10QPagedPaintDevicePrivate::~QPagedPaintDevicePrivate() = default;
11
12/*!
13 \class QPagedPaintDevice
14 \inmodule QtGui
15
16 \brief The QPagedPaintDevice class represents a paint device that supports
17 multiple pages.
18
19 \ingroup painting
20
21 Paged paint devices are used to generate output for printing or for formats like PDF.
22 QPdfWriter and QPrinter inherit from it.
23 */
24
25
26/*!
27 \internal
28 Constructs a new paged paint device with the derived private class.
29*/
30QPagedPaintDevice::QPagedPaintDevice(QPagedPaintDevicePrivate *dd)
31 : d(dd)
32{
33}
34
35/*!
36 Destroys the object.
37 */
38QPagedPaintDevice::~QPagedPaintDevice()
39{
40 delete d;
41}
42
43/*!
44 \internal
45 Returns the QPagedPaintDevicePrivate.
46*/
47QPagedPaintDevicePrivate *QPagedPaintDevice::dd()
48{
49 return d;
50}
51
52/*!
53 \fn bool QPagedPaintDevice::newPage()
54
55 Starts a new page. Returns \c true on success.
56*/
57
58/*!
59 \enum QPagedPaintDevice::PdfVersion
60
61 The PdfVersion enum describes the version of the PDF file that
62 is produced by QPrinter or QPdfWriter.
63
64 \value PdfVersion_1_4 A PDF 1.4 compatible document is produced.
65
66 \value PdfVersion_A1b A PDF/A-1b compatible document is produced.
67
68 \value PdfVersion_1_6 A PDF 1.6 compatible document is produced.
69 This value was added in Qt 5.12.
70*/
71
72/*!
73 \since 5.3
74
75 Sets the page layout to \a newPageLayout.
76
77 You should call this before calling QPainter::begin(), or immediately
78 before calling newPage() to apply the new page layout to a new page.
79 You should not call any painting methods between a call to setPageLayout()
80 and newPage() as the wrong paint metrics may be used.
81
82 Returns true if the page layout was successfully set to \a newPageLayout.
83
84 \sa pageLayout()
85*/
86
87bool QPagedPaintDevice::setPageLayout(const QPageLayout &newPageLayout)
88{
89 return d->setPageLayout(newPageLayout);
90}
91
92/*!
93 \since 5.3
94
95 Sets the page size to \a pageSize.
96
97 To get the current QPageSize use pageLayout().pageSize().
98
99 You should call this before calling QPainter::begin(), or immediately
100 before calling newPage() to apply the new page size to a new page.
101 You should not call any painting methods between a call to setPageSize()
102 and newPage() as the wrong paint metrics may be used.
103
104 Returns true if the page size was successfully set to \a pageSize.
105
106 \sa pageLayout()
107*/
108
109bool QPagedPaintDevice::setPageSize(const QPageSize &pageSize)
110{
111 return d->setPageSize(pageSize);
112}
113
114/*!
115 \since 5.3
116
117 Sets the page \a orientation.
118
119 The page orientation is used to define the orientation of the
120 page size when obtaining the page rect.
121
122 You should call this before calling QPainter::begin(), or immediately
123 before calling newPage() to apply the new orientation to a new page.
124 You should not call any painting methods between a call to setPageOrientation()
125 and newPage() as the wrong paint metrics may be used.
126
127 To get the current QPageLayout::Orientation use pageLayout().orientation().
128
129 Returns true if the page orientation was successfully set to \a orientation.
130
131 \sa pageLayout()
132*/
133
134bool QPagedPaintDevice::setPageOrientation(QPageLayout::Orientation orientation)
135{
136 return d->setPageOrientation(orientation);
137}
138
139/*!
140 \since 5.3
141
142 Set the page \a margins defined in the given \a units.
143
144 You should call this before calling QPainter::begin(), or immediately
145 before calling newPage() to apply the new margins to a new page.
146 You should not call any painting methods between a call to setPageMargins()
147 and newPage() as the wrong paint metrics may be used.
148
149 To get the current page margins use pageLayout().margins().
150
151 Returns true if the page margins were successfully set to \a margins.
152
153 \sa pageLayout()
154*/
155
156bool QPagedPaintDevice::setPageMargins(const QMarginsF &margins, QPageLayout::Unit units)
157{
158 return d->setPageMargins(margins, units);
159}
160
161/*!
162 \since 5.3
163
164 Returns the current page layout. Use this method to access the current
165 QPageSize, QPageLayout::Orientation, QMarginsF, fullRect() and paintRect().
166
167 Note that you cannot use the setters on the returned object, you must either
168 call the individual QPagedPaintDevice setters or use setPageLayout().
169
170 \sa setPageLayout(), setPageSize(), setPageOrientation(), setPageMargins()
171*/
172
173QPageLayout QPagedPaintDevice::pageLayout() const
174{
175 return d->pageLayout();
176}
177
178/*!
179 \since 6.0
180
181 Returns the page ranges associated with this device.
182
183 \sa QPageRanges, QPrinter::fromPage(), QPrinter::toPage()
184*/
185QPageRanges QPagedPaintDevice::pageRanges() const
186{
187 return d->pageRanges;
188}
189
190/*!
191 \since 6.0
192
193 Sets the page ranges for this device to \a ranges.
194*/
195void QPagedPaintDevice::setPageRanges(const QPageRanges &ranges)
196{
197 d->pageRanges = ranges;
198}
199
200QT_END_NAMESPACE
201

source code of qtbase/src/gui/painting/qpagedpaintdevice.cpp