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 "qpagedpaintdevice_p.h"
41#include <qpagedpaintdevice.h>
42
43QT_BEGIN_NAMESPACE
44
45// ### Qt 6: remove when the deprecated constructor is removed
46class QDummyPagedPaintDevicePrivate : public QPagedPaintDevicePrivate
47{
48 bool setPageLayout(const QPageLayout &newPageLayout) override
49 {
50 m_pageLayout = newPageLayout;
51 return m_pageLayout.isEquivalentTo(newPageLayout);
52 }
53
54 bool setPageSize(const QPageSize &pageSize) override
55 {
56 m_pageLayout.setPageSize(pageSize);
57 return m_pageLayout.pageSize().isEquivalentTo(pageSize);
58 }
59
60 bool setPageOrientation(QPageLayout::Orientation orientation) override
61 {
62 m_pageLayout.setOrientation(orientation);
63 return m_pageLayout.orientation() == orientation;
64 }
65
66 bool setPageMargins(const QMarginsF &margins, QPageLayout::Unit units) override
67 {
68 m_pageLayout.setUnits(units);
69 m_pageLayout.setMargins(margins);
70 return m_pageLayout.margins() == margins && m_pageLayout.units() == units;
71 }
72
73 QPageLayout pageLayout() const override
74 {
75 return m_pageLayout;
76 }
77
78 QPageLayout m_pageLayout;
79};
80
81QPagedPaintDevicePrivate::~QPagedPaintDevicePrivate()
82{
83}
84
85/*!
86 \class QPagedPaintDevice
87 \inmodule QtGui
88
89 \brief The QPagedPaintDevice class represents a paint device that supports
90 multiple pages.
91
92 \ingroup painting
93
94 Paged paint devices are used to generate output for printing or for formats like PDF.
95 QPdfWriter and QPrinter inherit from it.
96 */
97
98/*!
99 Constructs a new paged paint device.
100
101 \deprecated
102 */
103QPagedPaintDevice::QPagedPaintDevice()
104 : d(new QDummyPagedPaintDevicePrivate)
105{
106}
107
108/*!
109 \internal
110 Constructs a new paged paint device with the derived private class.
111*/
112QPagedPaintDevice::QPagedPaintDevice(QPagedPaintDevicePrivate *dd)
113 : d(dd)
114{
115}
116
117/*!
118 Destroys the object.
119 */
120QPagedPaintDevice::~QPagedPaintDevice()
121{
122 delete d;
123}
124
125/*!
126 \internal
127 Returns the QPagedPaintDevicePrivate.
128*/
129QPagedPaintDevicePrivate *QPagedPaintDevice::dd()
130{
131 return d;
132}
133
134/*!
135 \enum QPagedPaintDevice::PageSize
136
137 This enum type lists the available page sizes as defined in the Postscript
138 PPD standard. These values are duplicated in QPageSize and QPrinter.
139
140 The defined sizes are:
141
142 \value A0 841 x 1189 mm
143 \value A1 594 x 841 mm
144 \value A2 420 x 594 mm
145 \value A3 297 x 420 mm
146 \value A4 210 x 297 mm, 8.26 x 11.69 inches
147 \value A5 148 x 210 mm
148 \value A6 105 x 148 mm
149 \value A7 74 x 105 mm
150 \value A8 52 x 74 mm
151 \value A9 37 x 52 mm
152 \value B0 1000 x 1414 mm
153 \value B1 707 x 1000 mm
154 \value B2 500 x 707 mm
155 \value B3 353 x 500 mm
156 \value B4 250 x 353 mm
157 \value B5 176 x 250 mm, 6.93 x 9.84 inches
158 \value B6 125 x 176 mm
159 \value B7 88 x 125 mm
160 \value B8 62 x 88 mm
161 \value B9 33 x 62 mm
162 \value B10 31 x 44 mm
163 \value C5E 163 x 229 mm
164 \value Comm10E 105 x 241 mm, U.S. Common 10 Envelope
165 \value DLE 110 x 220 mm
166 \value Executive 7.5 x 10 inches, 190.5 x 254 mm
167 \value Folio 210 x 330 mm
168 \value Ledger 431.8 x 279.4 mm
169 \value Legal 8.5 x 14 inches, 215.9 x 355.6 mm
170 \value Letter 8.5 x 11 inches, 215.9 x 279.4 mm
171 \value Tabloid 279.4 x 431.8 mm
172 \value Custom Unknown, or a user defined size.
173 \value A10
174 \value A3Extra
175 \value A4Extra
176 \value A4Plus
177 \value A4Small
178 \value A5Extra
179 \value B5Extra
180 \value JisB0
181 \value JisB1
182 \value JisB2
183 \value JisB3
184 \value JisB4
185 \value JisB5
186 \value JisB6,
187 \value JisB7
188 \value JisB8
189 \value JisB9
190 \value JisB10
191 \value AnsiA = Letter
192 \value AnsiB = Ledger
193 \value AnsiC
194 \value AnsiD
195 \value AnsiE
196 \value LegalExtra
197 \value LetterExtra
198 \value LetterPlus
199 \value LetterSmall
200 \value TabloidExtra
201 \value ArchA
202 \value ArchB
203 \value ArchC
204 \value ArchD
205 \value ArchE
206 \value Imperial7x9
207 \value Imperial8x10
208 \value Imperial9x11
209 \value Imperial9x12
210 \value Imperial10x11
211 \value Imperial10x13
212 \value Imperial10x14
213 \value Imperial12x11
214 \value Imperial15x11
215 \value ExecutiveStandard
216 \value Note
217 \value Quarto
218 \value Statement
219 \value SuperA
220 \value SuperB
221 \value Postcard
222 \value DoublePostcard
223 \value Prc16K
224 \value Prc32K
225 \value Prc32KBig
226 \value FanFoldUS
227 \value FanFoldGerman
228 \value FanFoldGermanLegal
229 \value EnvelopeB4
230 \value EnvelopeB5
231 \value EnvelopeB6
232 \value EnvelopeC0
233 \value EnvelopeC1
234 \value EnvelopeC2
235 \value EnvelopeC3
236 \value EnvelopeC4
237 \value EnvelopeC5 = C5E
238 \value EnvelopeC6
239 \value EnvelopeC65
240 \value EnvelopeC7
241 \value EnvelopeDL = DLE
242 \value Envelope9
243 \value Envelope10 = Comm10E
244 \value Envelope11
245 \value Envelope12
246 \value Envelope14
247 \value EnvelopeMonarch
248 \value EnvelopePersonal
249 \value EnvelopeChou3
250 \value EnvelopeChou4
251 \value EnvelopeInvite
252 \value EnvelopeItalian
253 \value EnvelopeKaku2
254 \value EnvelopeKaku3
255 \value EnvelopePrc1
256 \value EnvelopePrc2
257 \value EnvelopePrc3
258 \value EnvelopePrc4
259 \value EnvelopePrc5
260 \value EnvelopePrc6
261 \value EnvelopePrc7
262 \value EnvelopePrc8
263 \value EnvelopePrc9
264 \value EnvelopePrc10
265 \value EnvelopeYou4
266 \value LastPageSize = EnvelopeYou4
267 \omitvalue NPageSize
268 \omitvalue NPaperSize
269
270 Due to historic reasons QPageSize::Executive is not the same as the standard
271 Postscript and Windows Executive size, use QPageSize::ExecutiveStandard instead.
272
273 The Postscript standard size QPageSize::Folio is different to the Windows
274 DMPAPER_FOLIO size, use the Postscript standard size QPageSize::FanFoldGermanLegal
275 if needed.
276*/
277
278/*!
279 \fn bool QPagedPaintDevice::newPage()
280
281 Starts a new page. Returns \c true on success.
282*/
283
284/*!
285 \enum QPagedPaintDevice::PdfVersion
286
287 The PdfVersion enum describes the version of the PDF file that
288 is produced by QPrinter or QPdfWriter.
289
290 \value PdfVersion_1_4 A PDF 1.4 compatible document is produced.
291
292 \value PdfVersion_A1b A PDF/A-1b compatible document is produced.
293
294 \value PdfVersion_1_6 A PDF 1.6 compatible document is produced.
295 This value was added in Qt 5.12.
296*/
297
298/*!
299 Sets the size of the a page to \a size.
300
301 \sa setPageSizeMM()
302 */
303void QPagedPaintDevice::setPageSize(PageSize size)
304{
305 d->setPageSize(QPageSize(QPageSize::PageSizeId(size)));
306}
307
308/*!
309 Returns the currently used page size.
310 */
311QPagedPaintDevice::PageSize QPagedPaintDevice::pageSize() const
312{
313 return PageSize(d->pageLayout().pageSize().id());
314}
315
316/*!
317 Sets the page size to \a size. \a size is specified in millimeters.
318
319 If the size matches a standard QPagedPaintDevice::PageSize then that page
320 size will be used, otherwise QPagedPaintDevice::Custom will be set.
321*/
322void QPagedPaintDevice::setPageSizeMM(const QSizeF &size)
323{
324 d->setPageSize(QPageSize(size, QPageSize::Millimeter));
325}
326
327/*!
328 Returns the page size in millimeters.
329 */
330QSizeF QPagedPaintDevice::pageSizeMM() const
331{
332 return d->pageLayout().pageSize().size(QPageSize::Millimeter);
333}
334
335/*!
336 Sets the margins to be used to \a margins.
337
338 Margins are specified in millimeters.
339
340 The margins are purely a hint to the drawing method. They don't affect the
341 coordinate system or clipping.
342
343 \sa margins()
344 */
345void QPagedPaintDevice::setMargins(const Margins &margins)
346{
347 d->setPageMargins(QMarginsF(margins.left, margins.top, margins.right, margins.bottom), QPageLayout::Millimeter);
348}
349
350/*!
351 Returns the current margins of the paint device. The default is 0.
352
353 Margins are specified in millimeters.
354
355 \sa setMargins()
356 */
357QPagedPaintDevice::Margins QPagedPaintDevice::margins() const
358{
359 QMarginsF margins = d->pageLayout().margins(QPageLayout::Millimeter);
360 Margins result;
361 result.left = margins.left();
362 result.top = margins.top();
363 result.right = margins.right();
364 result.bottom = margins.bottom();
365 return result;
366}
367
368/*!
369 \since 5.3
370
371 Sets the page layout to \a newPageLayout.
372
373 You should call this before calling QPainter::begin(), or immediately
374 before calling newPage() to apply the new page layout to a new page.
375 You should not call any painting methods between a call to setPageLayout()
376 and newPage() as the wrong paint metrics may be used.
377
378 Returns true if the page layout was successfully set to \a newPageLayout.
379
380 \sa pageLayout()
381*/
382
383bool QPagedPaintDevice::setPageLayout(const QPageLayout &newPageLayout)
384{
385 return d->setPageLayout(newPageLayout);
386}
387
388/*!
389 \since 5.3
390
391 Sets the page size to \a pageSize.
392
393 To get the current QPageSize use pageLayout().pageSize().
394
395 You should call this before calling QPainter::begin(), or immediately
396 before calling newPage() to apply the new page size to a new page.
397 You should not call any painting methods between a call to setPageSize()
398 and newPage() as the wrong paint metrics may be used.
399
400 Returns true if the page size was successfully set to \a pageSize.
401
402 \sa pageLayout()
403*/
404
405bool QPagedPaintDevice::setPageSize(const QPageSize &pageSize)
406{
407 return d->setPageSize(pageSize);
408}
409
410/*!
411 \since 5.3
412
413 Sets the page \a orientation.
414
415 The page orientation is used to define the orientation of the
416 page size when obtaining the page rect.
417
418 You should call this before calling QPainter::begin(), or immediately
419 before calling newPage() to apply the new orientation to a new page.
420 You should not call any painting methods between a call to setPageOrientation()
421 and newPage() as the wrong paint metrics may be used.
422
423 To get the current QPageLayout::Orientation use pageLayout().pageOrientation().
424
425 Returns true if the page orientation was successfully set to \a orientation.
426
427 \sa pageLayout()
428*/
429
430bool QPagedPaintDevice::setPageOrientation(QPageLayout::Orientation orientation)
431{
432 return d->setPageOrientation(orientation);
433}
434
435/*!
436 \since 5.3
437
438 Set the page \a margins in the current page layout units.
439
440 You should call this before calling QPainter::begin(), or immediately
441 before calling newPage() to apply the new margins to a new page.
442 You should not call any painting methods between a call to setPageMargins()
443 and newPage() as the wrong paint metrics may be used.
444
445 To get the current page margins use pageLayout().pageMargins().
446
447 Returns true if the page margins were successfully set to \a margins.
448
449 \sa pageLayout()
450*/
451
452bool QPagedPaintDevice::setPageMargins(const QMarginsF &margins)
453{
454 return setPageMargins(margins, pageLayout().units());
455}
456
457/*!
458 \since 5.3
459
460 Set the page \a margins defined in the given \a units.
461
462 You should call this before calling QPainter::begin(), or immediately
463 before calling newPage() to apply the new margins to a new page.
464 You should not call any painting methods between a call to setPageMargins()
465 and newPage() as the wrong paint metrics may be used.
466
467 To get the current page margins use pageLayout().pageMargins().
468
469 Returns true if the page margins were successfully set to \a margins.
470
471 \sa pageLayout()
472*/
473
474bool QPagedPaintDevice::setPageMargins(const QMarginsF &margins, QPageLayout::Unit units)
475{
476 return d->setPageMargins(margins, units);
477}
478
479/*!
480 \since 5.3
481
482 Returns the current page layout. Use this method to access the current
483 QPageSize, QPageLayout::Orientation, QMarginsF, fullRect() and paintRect().
484
485 Note that you cannot use the setters on the returned object, you must either
486 call the individual QPagedPaintDevice setters or use setPageLayout().
487
488 \sa setPageLayout(), setPageSize(), setPageOrientation(), setPageMargins()
489*/
490
491QPageLayout QPagedPaintDevice::pageLayout() const
492{
493 return d->pageLayout();
494}
495
496/*!
497 \internal
498
499 \deprecated
500
501 Returns the internal device page layout.
502*/
503
504QPageLayout QPagedPaintDevice::devicePageLayout() const
505{
506 qWarning("QPagedPaintDevice::devicePageLayout() is deprecated, just use QPagedPaintDevice::pageLayout()");
507 return d->pageLayout();
508}
509
510/*!
511 \internal
512
513 \deprecated
514
515 Returns the internal device page layout.
516*/
517
518QPageLayout &QPagedPaintDevice::devicePageLayout()
519{
520 qWarning("QPagedPaintDevice::devicePageLayout() is deprecated, you shouldn't be using this at all.");
521 static QPageLayout dummy;
522 return dummy;
523}
524
525QT_END_NAMESPACE
526