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 "qprinter.h"
5#include "qprinter_p.h"
6
7#ifndef QT_NO_PRINTER
8
9#include <qpa/qplatformprintplugin.h>
10#include <qpa/qplatformprintersupport.h>
11
12#include "qprintengine.h"
13#include "qlist.h"
14#include <qcoreapplication.h>
15#include <qfileinfo.h>
16
17#include <private/qpagedpaintdevice_p.h>
18
19#include "qprintengine_pdf_p.h"
20
21#include <qpicture.h>
22#if QT_CONFIG(printpreviewwidget)
23#include <private/qpaintengine_preview_p.h>
24#endif
25
26QT_BEGIN_NAMESPACE
27
28using namespace Qt::StringLiterals;
29
30#define ABORT_IF_ACTIVE(location) \
31 if (d->printEngine->printerState() == QPrinter::Active) { \
32 qWarning("%s: Cannot be changed while printer is active", location); \
33 return; \
34 }
35
36#define ABORT_IF_ACTIVE_RETURN(location, retValue) \
37 if (d->printEngine->printerState() == QPrinter::Active) { \
38 qWarning("%s: Cannot be changed while printer is active", location); \
39 return retValue; \
40 }
41
42extern qreal qt_pixelMultiplier(int resolution);
43extern QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits);
44
45QPrinterInfo QPrinterPrivate::findValidPrinter(const QPrinterInfo &printer)
46{
47 // Try find a valid printer to use, either the one given, the default or the first available
48 QPrinterInfo printerToUse = printer;
49 if (printerToUse.isNull()) {
50 printerToUse = QPrinterInfo::defaultPrinter();
51 if (printerToUse.isNull()) {
52 QStringList availablePrinterNames = QPrinterInfo::availablePrinterNames();
53 if (!availablePrinterNames.isEmpty())
54 printerToUse = QPrinterInfo::printerInfo(printerName: availablePrinterNames.at(i: 0));
55 }
56 }
57 return printerToUse;
58}
59
60void QPrinterPrivate::initEngines(QPrinter::OutputFormat format, const QPrinterInfo &printer)
61{
62 // Default to PdfFormat
63 outputFormat = QPrinter::PdfFormat;
64 QPlatformPrinterSupport *ps = nullptr;
65 QString printerName;
66
67 // Only set NativeFormat if we have a valid plugin and printer to use
68 if (format == QPrinter::NativeFormat) {
69 ps = QPlatformPrinterSupportPlugin::get();
70 QPrinterInfo printerToUse = findValidPrinter(printer);
71 if (ps && !printerToUse.isNull()) {
72 outputFormat = QPrinter::NativeFormat;
73 printerName = printerToUse.printerName();
74 }
75 }
76
77 if (outputFormat == QPrinter::NativeFormat) {
78 printEngine = ps->createNativePrintEngine(printerMode, deviceId: printerName);
79 paintEngine = ps->createPaintEngine(printEngine, printerMode);
80 } else {
81 static const QHash<QPrinter::PdfVersion, QPdfEngine::PdfVersion> engineMapping {
82 {QPrinter::PdfVersion_1_4, QPdfEngine::Version_1_4},
83 {QPrinter::PdfVersion_A1b, QPdfEngine::Version_A1b},
84 {QPrinter::PdfVersion_1_6, QPdfEngine::Version_1_6}
85 };
86 const auto pdfEngineVersion = engineMapping.value(key: pdfVersion, defaultValue: QPdfEngine::Version_1_4);
87 QPdfPrintEngine *pdfEngine = new QPdfPrintEngine(printerMode, pdfEngineVersion);
88 paintEngine = pdfEngine;
89 printEngine = pdfEngine;
90 }
91
92 use_default_engine = true;
93 had_default_engines = true;
94 validPrinter = true;
95}
96
97void QPrinterPrivate::changeEngines(QPrinter::OutputFormat format, const QPrinterInfo &printer)
98{
99 QPrintEngine *oldPrintEngine = printEngine;
100 const bool def_engine = use_default_engine;
101
102 initEngines(format, printer);
103
104 if (oldPrintEngine) {
105 const auto properties = m_properties; // take a copy: setProperty() below modifies m_properties
106 for (const auto &key : properties) {
107 QVariant prop;
108 // PPK_NumberOfCopies need special treatmeant since it in most cases
109 // will return 1, disregarding the actual value that was set
110 // PPK_PrinterName also needs special treatment as initEngines has set it already
111 if (key == QPrintEngine::PPK_NumberOfCopies)
112 prop = QVariant(q_ptr->copyCount());
113 else if (key != QPrintEngine::PPK_PrinterName)
114 prop = oldPrintEngine->property(key);
115 if (prop.isValid())
116 setProperty(key, value: prop);
117 }
118 }
119
120 if (def_engine)
121 delete oldPrintEngine;
122}
123
124#if QT_CONFIG(printpreviewwidget)
125QList<const QPicture *> QPrinterPrivate::previewPages() const
126{
127 if (previewEngine)
128 return previewEngine->pages();
129 return QList<const QPicture *>();
130}
131
132void QPrinterPrivate::setPreviewMode(bool enable)
133{
134 Q_Q(QPrinter);
135 if (enable) {
136 if (!previewEngine)
137 previewEngine = new QPreviewPaintEngine;
138 had_default_engines = use_default_engine;
139 use_default_engine = false;
140 realPrintEngine = printEngine;
141 realPaintEngine = paintEngine;
142 q->setEngines(printEngine: previewEngine, paintEngine: previewEngine);
143 previewEngine->setProxyEngines(printEngine: realPrintEngine, paintEngine: realPaintEngine);
144 } else {
145 q->setEngines(printEngine: realPrintEngine, paintEngine: realPaintEngine);
146 use_default_engine = had_default_engines;
147 }
148}
149#endif // QT_CONFIG(printpreviewwidget)
150
151void QPrinterPrivate::setProperty(QPrintEngine::PrintEnginePropertyKey key, const QVariant &value)
152{
153 printEngine->setProperty(key, value);
154 m_properties.insert(value: key);
155}
156
157
158class QPrinterPagedPaintDevicePrivate : public QPagedPaintDevicePrivate
159{
160public:
161 QPrinterPagedPaintDevicePrivate(QPrinter *p)
162 : QPagedPaintDevicePrivate(), m_printer(p)
163 {}
164
165 virtual ~QPrinterPagedPaintDevicePrivate()
166 {}
167
168 bool setPageLayout(const QPageLayout &newPageLayout) override
169 {
170 QPrinterPrivate *pd = QPrinterPrivate::get(printer: m_printer);
171
172 if (pd->paintEngine->type() != QPaintEngine::Pdf
173 && pd->printEngine->printerState() == QPrinter::Active) {
174 qWarning(msg: "QPrinter::setPageLayout: Cannot be changed while printer is active");
175 return false;
176 }
177
178 // Try to set the print engine page layout
179 pd->setProperty(key: QPrintEngine::PPK_QPageLayout, value: QVariant::fromValue(value: newPageLayout));
180
181 return pageLayout().isEquivalentTo(other: newPageLayout);
182 }
183
184 bool setPageSize(const QPageSize &pageSize) override
185 {
186 QPrinterPrivate *pd = QPrinterPrivate::get(printer: m_printer);
187
188 if (pd->paintEngine->type() != QPaintEngine::Pdf
189 && pd->printEngine->printerState() == QPrinter::Active) {
190 qWarning(msg: "QPrinter::setPageLayout: Cannot be changed while printer is active");
191 return false;
192 }
193
194
195 // Try to set the print engine page size
196 pd->setProperty(key: QPrintEngine::PPK_QPageSize, value: QVariant::fromValue(value: pageSize));
197
198 return pageLayout().pageSize().isEquivalentTo(other: pageSize);
199 }
200
201 bool setPageOrientation(QPageLayout::Orientation orientation) override
202 {
203 QPrinterPrivate *pd = QPrinterPrivate::get(printer: m_printer);
204
205 // Set the print engine value
206 pd->setProperty(key: QPrintEngine::PPK_Orientation, value: orientation);
207
208 return pageLayout().orientation() == orientation;
209 }
210
211 bool setPageMargins(const QMarginsF &margins, QPageLayout::Unit units) override
212 {
213 QPrinterPrivate *pd = QPrinterPrivate::get(printer: m_printer);
214
215 // Try to set print engine margins
216 QPair<QMarginsF, QPageLayout::Unit> pair = qMakePair(value1: margins, value2&: units);
217 pd->setProperty(key: QPrintEngine::PPK_QPageMargins, value: QVariant::fromValue(value: pair));
218
219 return pageLayout().margins() == margins && pageLayout().units() == units;
220 }
221
222 QPageLayout pageLayout() const override
223 {
224 QPrinterPrivate *pd = QPrinterPrivate::get(printer: m_printer);
225
226 return qvariant_cast<QPageLayout>(v: pd->printEngine->property(key: QPrintEngine::PPK_QPageLayout));
227 }
228
229 QPrinter *m_printer;
230};
231
232
233/*!
234 \class QPrinter
235 \reentrant
236
237 \brief The QPrinter class is a paint device that paints on a printer.
238
239 \ingroup printing
240 \inmodule QtPrintSupport
241
242
243 This device represents a series of pages of printed output, and is
244 used in almost exactly the same way as other paint devices such as
245 QWidget and QPixmap.
246 A set of additional functions are provided to manage device-specific
247 features, such as orientation and resolution, and to step through
248 the pages in a document as it is generated.
249
250 When printing directly to a printer on Windows or \macos, QPrinter uses
251 the built-in printer drivers. On X11, QPrinter uses the
252 \l{Common Unix Printing System (CUPS)}
253 to send PDF output to the printer. As an alternative,
254 the printProgram() function can be used to specify the command or utility
255 to use instead of the system default.
256
257 Note that setting parameters like paper size and resolution on an
258 invalid printer is undefined. You can use QPrinter::isValid() to
259 verify this before changing any parameters.
260
261 QPrinter supports a number of parameters, most of which can be
262 changed by the end user through a \l{QPrintDialog}{print dialog}. In
263 general, QPrinter passes these functions onto the underlying QPrintEngine.
264
265 The most important parameters are:
266 \list
267 \li setPageLayout() tells QPrinter which page orientation to use, and
268 what size to expect from the printer.
269 \li setResolution() tells QPrinter what resolution you wish the
270 printer to provide, in dots per inch (DPI).
271 \li setFullPage() tells QPrinter whether you want to deal with the
272 full page or just with the part the printer can draw on.
273 \li setCopyCount() tells QPrinter how many copies of the document
274 it should print.
275 \endlist
276
277 Many of these functions can only be called before the actual printing
278 begins (i.e., before QPainter::begin() is called). This usually makes
279 sense because, for example, it's not possible to change the number of
280 copies when you are halfway through printing. There are also some
281 settings that the user sets (through the printer dialog) and that
282 applications are expected to obey. See QAbstractPrintDialog's
283 documentation for more details.
284
285 When QPainter::begin() is called, the QPrinter it operates on is prepared for
286 a new page, enabling the QPainter to be used immediately to paint the first
287 page in a document. Once the first page has been painted, newPage() can be
288 called to request a new blank page to paint on, or QPainter::end() can be
289 called to finish printing. The second page and all following pages are
290 prepared using a call to newPage() before they are painted.
291
292 The first page in a document does not need to be preceded by a call to
293 newPage(). You only need to calling newPage() after QPainter::begin() if you
294 need to insert a blank page at the beginning of a printed document.
295 Similarly, calling newPage() after the last page in a document is painted will
296 result in a trailing blank page appended to the end of the printed document.
297
298 If you want to abort the print job, abort() will try its best to
299 stop printing. It may cancel the entire job or just part of it.
300
301 Since QPrinter can print to any QPrintEngine subclass, it is possible to
302 extend printing support to cover new types of printing subsystem by
303 subclassing QPrintEngine and reimplementing its interface.
304
305 \sa QPrintDialog, {Qt Print Support}
306*/
307
308/*!
309 \enum QPrinter::PrinterState
310
311 \value Idle
312 \value Active
313 \value Aborted
314 \value Error
315*/
316
317/*!
318 \enum QPrinter::PrinterMode
319
320 This enum describes the mode the printer should work in. It
321 basically presets a certain resolution and working mode.
322
323 \value ScreenResolution Sets the resolution of the print device to
324 the screen resolution. This has the big advantage that the results
325 obtained when painting on the printer will match more or less
326 exactly the visible output on the screen. It is the easiest to
327 use, as font metrics on the screen and on the printer are the
328 same. This is the default value. ScreenResolution will produce a
329 lower quality output than HighResolution and should only be used
330 for drafts.
331
332 \value PrinterResolution This value is deprecated. It is
333 equivalent to ScreenResolution on Unix and HighResolution on
334 Windows and Mac. Due to the difference between ScreenResolution
335 and HighResolution, use of this value may lead to non-portable
336 printer code.
337
338 \value HighResolution On Windows, sets the printer resolution to that
339 defined for the printer in use. For PDF printing, sets the
340 resolution of the PDF driver to 1200 dpi.
341
342 \note When rendering text on a QPrinter device, it is important
343 to realize that the size of text, when specified in points, is
344 independent of the resolution specified for the device itself.
345 Therefore, it may be useful to specify the font size in pixels
346 when combining text with graphics to ensure that their relative
347 sizes are what you expect.
348*/
349
350/*!
351 \enum QPrinter::PrintRange
352
353 Used to specify the print range selection option.
354
355 \value AllPages All pages should be printed.
356 \value Selection Only the selection should be printed.
357 \value PageRange The specified page range should be printed.
358 \value CurrentPage Only the current page should be printed.
359
360 \sa setPrintRange(), printRange(), QAbstractPrintDialog::PrintRange
361*/
362
363/*!
364 \enum QPrinter::PageOrder
365
366 This enum type is used by QPrinter to tell the application program
367 how to print.
368
369 \value FirstPageFirst the lowest-numbered page should be printed
370 first.
371
372 \value LastPageFirst the highest-numbered page should be printed
373 first.
374*/
375
376/*!
377 \enum QPrinter::ColorMode
378
379 This enum type is used to indicate whether QPrinter should print
380 in color or not.
381
382 \value Color print in color if available, otherwise in grayscale.
383
384 \value GrayScale print in grayscale, even on color printers.
385*/
386
387/*!
388 \enum QPrinter::PaperSource
389
390 This enum type specifies what paper source QPrinter is to use.
391 QPrinter does not check that the paper source is available; it
392 just uses this information to try and set the paper source.
393 Whether it will set the paper source depends on whether the
394 printer has that particular source.
395
396 \warning This is currently only implemented for Windows.
397
398 \value Auto
399 \value Cassette
400 \value Envelope
401 \value EnvelopeManual
402 \value FormSource
403 \value LargeCapacity
404 \value LargeFormat
405 \value Lower
406 \value MaxPageSource Deprecated, use LastPaperSource instead
407 \value Middle
408 \value Manual
409 \value OnlyOne
410 \value Tractor
411 \value SmallFormat
412 \value Upper
413 \value CustomSource A PaperSource defined by the printer that is unknown to Qt
414 \value LastPaperSource The highest valid PaperSource value, currently CustomSource
415*/
416
417/*!
418 \enum QPrinter::Unit
419 \since 4.4
420
421 This enum type is used to specify the measurement unit for page and
422 paper sizes.
423
424 \value Millimeter
425 \value Point
426 \value Inch
427 \value Pica
428 \value Didot
429 \value Cicero
430 \value DevicePixel
431
432 Note the difference between Point and DevicePixel. The Point unit is
433 defined to be 1/72th of an inch, while the DevicePixel unit is
434 resolution dependent and is based on the actual pixels, or dots, on
435 the printer.
436*/
437
438/*!
439 Creates a new printer object with the given \a mode.
440*/
441QPrinter::QPrinter(PrinterMode mode)
442 : QPagedPaintDevice(new QPrinterPagedPaintDevicePrivate(this)),
443 d_ptr(new QPrinterPrivate(this))
444{
445 d_ptr->init(printer: QPrinterInfo(), mode);
446}
447
448/*!
449 \since 4.4
450
451 Creates a new printer object with the given \a printer and \a mode.
452*/
453QPrinter::QPrinter(const QPrinterInfo& printer, PrinterMode mode)
454 : QPagedPaintDevice(new QPrinterPagedPaintDevicePrivate(this)),
455 d_ptr(new QPrinterPrivate(this))
456{
457 d_ptr->init(printer, mode);
458}
459
460void QPrinterPrivate::init(const QPrinterInfo &printer, QPrinter::PrinterMode mode)
461{
462 if (Q_UNLIKELY(!QCoreApplication::instance())) {
463 qFatal(msg: "QPrinter: Must construct a QCoreApplication before a QPrinter");
464 return;
465 }
466
467 printerMode = mode;
468
469 initEngines(format: QPrinter::NativeFormat, printer);
470}
471
472/*!
473 This function is used by subclasses of QPrinter to specify custom
474 print and paint engines (\a printEngine and \a paintEngine,
475 respectively).
476
477 QPrinter does not take ownership of the engines, so you need to
478 manage these engine instances yourself.
479
480 Note that changing the engines will reset the printer state and
481 all its properties.
482
483 \sa printEngine(), paintEngine(), setOutputFormat()
484
485 \since 4.1
486*/
487void QPrinter::setEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine)
488{
489 Q_D(QPrinter);
490
491 if (d->use_default_engine)
492 delete d->printEngine;
493
494 d->printEngine = printEngine;
495 d->paintEngine = paintEngine;
496 d->use_default_engine = false;
497}
498
499/*!
500 Destroys the printer object and frees any allocated resources. If
501 the printer is destroyed while a print job is in progress this may
502 or may not affect the print job.
503*/
504QPrinter::~QPrinter()
505{
506 Q_D(QPrinter);
507 if (d->use_default_engine)
508 delete d->printEngine;
509#if QT_CONFIG(printpreviewwidget)
510 delete d->previewEngine;
511#endif
512}
513
514/*!
515 \enum QPrinter::OutputFormat
516
517 The OutputFormat enum is used to describe the format QPrinter should
518 use for printing.
519
520 \value NativeFormat QPrinter will print output using a method defined
521 by the platform it is running on. This mode is the default when printing
522 directly to a printer.
523
524 \value PdfFormat QPrinter will generate its output as a searchable PDF file.
525 This mode is the default when printing to a file.
526
527 \sa outputFormat(), setOutputFormat(), setOutputFileName()
528*/
529
530/*!
531 \since 4.1
532
533 Sets the output format for this printer to \a format.
534
535 If \a format is the same value as currently set then no change will be made.
536
537 If \a format is NativeFormat then the printerName will be set to the default
538 printer. If there are no valid printers configured then no change will be made.
539 If you want to set NativeFormat with a specific printerName then use
540 setPrinterName().
541
542 \sa setPrinterName()
543*/
544void QPrinter::setOutputFormat(OutputFormat format)
545{
546 Q_D(QPrinter);
547
548 if (d->outputFormat == format)
549 return;
550
551 if (format == QPrinter::NativeFormat) {
552 QPrinterInfo printerToUse = d->findValidPrinter();
553 if (!printerToUse.isNull())
554 d->changeEngines(format, printer: printerToUse);
555 } else {
556 d->changeEngines(format, printer: QPrinterInfo());
557 }
558}
559
560/*!
561 \since 4.1
562
563 Returns the output format for this printer.
564*/
565QPrinter::OutputFormat QPrinter::outputFormat() const
566{
567 Q_D(const QPrinter);
568 return d->outputFormat;
569}
570
571/*!
572 \since 5.10
573
574 Sets the PDF version for this printer to \a version.
575
576 If \a version is the same value as currently set then no change will be made.
577*/
578void QPrinter::setPdfVersion(PdfVersion version)
579{
580 Q_D(QPrinter);
581
582 if (d->pdfVersion == version)
583 return;
584
585 d->pdfVersion = version;
586
587 if (d->outputFormat == QPrinter::PdfFormat) {
588 d->changeEngines(format: d->outputFormat, printer: QPrinterInfo());
589 }
590}
591
592/*!
593 \since 5.10
594
595 Returns the PDF version for this printer. The default is \c PdfVersion_1_4.
596*/
597QPrinter::PdfVersion QPrinter::pdfVersion() const
598{
599 Q_D(const QPrinter);
600 return d->pdfVersion;
601}
602
603/*! \internal
604*/
605int QPrinter::devType() const
606{
607 return QInternal::Printer;
608}
609
610/*!
611 Returns the printer name. This value is initially set to the name
612 of the default printer.
613
614 \sa setPrinterName()
615*/
616QString QPrinter::printerName() const
617{
618 Q_D(const QPrinter);
619 return d->printEngine->property(key: QPrintEngine::PPK_PrinterName).toString();
620}
621
622/*!
623 Sets the printer name to \a name.
624
625 If the \a name is empty then the output format will be set to PdfFormat.
626
627 If the \a name is not a valid printer then no change will be made.
628
629 If the \a name is a valid printer then the output format will be set to NativeFormat.
630
631 \sa printerName(), isValid(), setOutputFormat()
632*/
633void QPrinter::setPrinterName(const QString &name)
634{
635 Q_D(QPrinter);
636 ABORT_IF_ACTIVE("QPrinter::setPrinterName");
637
638 if (printerName() == name)
639 return;
640
641 if (name.isEmpty()) {
642 setOutputFormat(QPrinter::PdfFormat);
643 return;
644 }
645
646 QPrinterInfo printerToUse = QPrinterInfo::printerInfo(printerName: name);
647 if (printerToUse.isNull())
648 return;
649
650 if (outputFormat() == QPrinter::PdfFormat) {
651 d->changeEngines(format: QPrinter::NativeFormat, printer: printerToUse);
652 } else {
653 d->setProperty(key: QPrintEngine::PPK_PrinterName, value: name);
654 }
655}
656
657/*!
658 \since 4.4
659
660 Returns \c true if the printer currently selected is a valid printer
661 in the system, or a pure PDF printer; otherwise returns \c false.
662
663 To detect other failures check the output of QPainter::begin() or QPrinter::newPage().
664
665 \snippet printing-qprinter/errors.cpp 0
666
667 \sa setPrinterName()
668*/
669bool QPrinter::isValid() const
670{
671 Q_D(const QPrinter);
672 if (!qApp)
673 return false;
674 return d->validPrinter;
675}
676
677/*!
678 \fn QString QPrinter::outputFileName() const
679
680 Returns the name of the output file. By default, this is an empty string
681 (indicating that the printer shouldn't print to file).
682
683 \sa QPrintEngine::PrintEnginePropertyKey
684
685*/
686
687QString QPrinter::outputFileName() const
688{
689 Q_D(const QPrinter);
690 return d->printEngine->property(key: QPrintEngine::PPK_OutputFileName).toString();
691}
692
693/*!
694 Sets the name of the output file to \a fileName.
695
696 Setting a null or empty name (0 or "") disables printing to a file.
697 Setting a non-empty name enables printing to a file.
698
699 This can change the value of outputFormat().
700 If the file name has the ".pdf" suffix PDF is generated. If the file name
701 has a suffix other than ".pdf", the output format used is the
702 one set with setOutputFormat().
703
704 QPrinter uses Qt's cross-platform PDF print engines
705 respectively. If you can produce this format natively, for example
706 \macos can generate PDF's from its print engine, set the output format
707 back to NativeFormat.
708
709 \sa outputFileName(), setOutputFormat()
710*/
711
712void QPrinter::setOutputFileName(const QString &fileName)
713{
714 Q_D(QPrinter);
715 ABORT_IF_ACTIVE("QPrinter::setOutputFileName");
716
717 QFileInfo fi(fileName);
718 if (!fi.suffix().compare(other: "pdf"_L1, cs: Qt::CaseInsensitive))
719 setOutputFormat(QPrinter::PdfFormat);
720 else if (fileName.isEmpty())
721 setOutputFormat(QPrinter::NativeFormat);
722
723 d->setProperty(key: QPrintEngine::PPK_OutputFileName, value: fileName);
724}
725
726
727/*!
728 Returns the name of the program that sends the print output to the
729 printer.
730
731 The default is to return an empty string; meaning that QPrinter will try to
732 be smart in a system-dependent way. On X11 only, you can set it to something
733 different to use a specific print program. On the other platforms, this
734 returns an empty string.
735
736 \sa setPrintProgram(), setPrinterSelectionOption()
737*/
738QString QPrinter::printProgram() const
739{
740 Q_D(const QPrinter);
741 return d->printEngine->property(key: QPrintEngine::PPK_PrinterProgram).toString();
742}
743
744
745/*!
746 Sets the name of the program that should do the print job to \a
747 printProg.
748
749 On X11, this function sets the program to call with the PDF
750 output. On other platforms, it has no effect.
751
752 \sa printProgram()
753*/
754void QPrinter::setPrintProgram(const QString &printProg)
755{
756 Q_D(QPrinter);
757 ABORT_IF_ACTIVE("QPrinter::setPrintProgram");
758 d->setProperty(key: QPrintEngine::PPK_PrinterProgram, value: printProg);
759}
760
761
762/*!
763 Returns the document name.
764
765 \sa setDocName(), QPrintEngine::PrintEnginePropertyKey
766*/
767QString QPrinter::docName() const
768{
769 Q_D(const QPrinter);
770 return d->printEngine->property(key: QPrintEngine::PPK_DocumentName).toString();
771}
772
773
774/*!
775 Sets the document name to \a name.
776
777 On X11, the document name is for example used as the default
778 output filename in QPrintDialog. Note that the document name does
779 not affect the file name if the printer is printing to a file.
780 Use the setOutputFile() function for this.
781
782 \sa docName(), QPrintEngine::PrintEnginePropertyKey
783*/
784void QPrinter::setDocName(const QString &name)
785{
786 Q_D(QPrinter);
787 ABORT_IF_ACTIVE("QPrinter::setDocName");
788 d->setProperty(key: QPrintEngine::PPK_DocumentName, value: name);
789}
790
791
792/*!
793 Returns the name of the application that created the document.
794
795 \sa setCreator()
796*/
797QString QPrinter::creator() const
798{
799 Q_D(const QPrinter);
800 return d->printEngine->property(key: QPrintEngine::PPK_Creator).toString();
801}
802
803
804/*!
805 Sets the name of the application that created the document to \a
806 creator.
807
808 This function is only applicable to the X11 version of Qt. If no
809 creator name is specified, the creator will be set to "Qt"
810 followed by some version number.
811
812 \sa creator()
813*/
814void QPrinter::setCreator(const QString &creator)
815{
816 Q_D(QPrinter);
817 ABORT_IF_ACTIVE("QPrinter::setCreator");
818 d->setProperty(key: QPrintEngine::PPK_Creator, value: creator);
819}
820
821/*!
822 Sets the page order to \a pageOrder.
823
824 The page order can be QPrinter::FirstPageFirst or
825 QPrinter::LastPageFirst. The application is responsible for
826 reading the page order and printing accordingly.
827
828 This function is mostly useful for setting a default value that
829 the user can override in the print dialog.
830
831 This function is only supported under X11.
832*/
833
834void QPrinter::setPageOrder(PageOrder pageOrder)
835{
836 d->pageOrderAscending = (pageOrder == FirstPageFirst);
837
838 Q_D(QPrinter);
839 ABORT_IF_ACTIVE("QPrinter::setPageOrder");
840 d->setProperty(key: QPrintEngine::PPK_PageOrder, value: pageOrder);
841}
842
843
844/*!
845 Returns the current page order.
846
847 The default page order is \c FirstPageFirst.
848*/
849
850QPrinter::PageOrder QPrinter::pageOrder() const
851{
852 Q_D(const QPrinter);
853 return QPrinter::PageOrder(d->printEngine->property(key: QPrintEngine::PPK_PageOrder).toInt());
854}
855
856
857/*!
858 Sets the printer's color mode to \a newColorMode, which can be
859 either \c Color or \c GrayScale.
860
861 \sa colorMode()
862*/
863
864void QPrinter::setColorMode(ColorMode newColorMode)
865{
866 Q_D(QPrinter);
867 ABORT_IF_ACTIVE("QPrinter::setColorMode");
868 d->setProperty(key: QPrintEngine::PPK_ColorMode, value: newColorMode);
869}
870
871
872/*!
873 Returns the current color mode.
874
875 \sa setColorMode()
876*/
877QPrinter::ColorMode QPrinter::colorMode() const
878{
879 Q_D(const QPrinter);
880 return QPrinter::ColorMode(d->printEngine->property(key: QPrintEngine::PPK_ColorMode).toInt());
881}
882
883/*!
884 \since 4.7
885
886 Sets the number of copies to be printed to \a count.
887
888 The printer driver reads this setting and prints the specified number of
889 copies.
890
891 \sa copyCount(), supportsMultipleCopies()
892*/
893
894void QPrinter::setCopyCount(int count)
895{
896 Q_D(QPrinter);
897 ABORT_IF_ACTIVE("QPrinter::setCopyCount;");
898 d->setProperty(key: QPrintEngine::PPK_CopyCount, value: count);
899}
900
901/*!
902 \since 4.7
903
904 Returns the number of copies that will be printed. The default value is 1.
905
906 \sa setCopyCount(), supportsMultipleCopies()
907*/
908
909int QPrinter::copyCount() const
910{
911 Q_D(const QPrinter);
912 return d->printEngine->property(key: QPrintEngine::PPK_CopyCount).toInt();
913}
914
915/*!
916 \since 4.7
917
918 Returns \c true if the printer supports printing multiple copies of the same
919 document in one job; otherwise false is returned.
920
921 On most systems this function will return true. However, on X11 systems
922 that do not support CUPS, this function will return false. That means the
923 application has to handle the number of copies by printing the same
924 document the required number of times.
925
926 \sa setCopyCount(), copyCount()
927*/
928
929bool QPrinter::supportsMultipleCopies() const
930{
931 Q_D(const QPrinter);
932 return d->printEngine->property(key: QPrintEngine::PPK_SupportsMultipleCopies).toBool();
933}
934
935/*!
936 \since 4.1
937
938 Returns \c true if collation is turned on when multiple copies is selected.
939 Returns \c false if it is turned off when multiple copies is selected.
940 When collating is turned off the printing of each individual page will be repeated
941 the numCopies() amount before the next page is started. With collating turned on
942 all pages are printed before the next copy of those pages is started.
943
944 \sa setCollateCopies()
945*/
946bool QPrinter::collateCopies() const
947{
948 Q_D(const QPrinter);
949 return d->printEngine->property(key: QPrintEngine::PPK_CollateCopies).toBool();
950}
951
952
953/*!
954 \since 4.1
955
956 Sets the default value for collation checkbox when the print
957 dialog appears. If \a collate is true, it will enable
958 setCollateCopiesEnabled(). The default value is false. This value
959 will be changed by what the user presses in the print dialog.
960
961 \sa collateCopies()
962*/
963void QPrinter::setCollateCopies(bool collate)
964{
965 Q_D(QPrinter);
966 ABORT_IF_ACTIVE("QPrinter::setCollateCopies");
967 d->setProperty(key: QPrintEngine::PPK_CollateCopies, value: collate);
968}
969
970
971
972/*!
973 If \a fp is true, enables support for painting over the entire page;
974 otherwise restricts painting to the printable area reported by the
975 device.
976
977 By default, full page printing is disabled. In this case, the origin
978 of the QPrinter's coordinate system coincides with the top-left
979 corner of the printable area.
980
981 If full page printing is enabled, the origin of the QPrinter's
982 coordinate system coincides with the top-left corner of the paper
983 itself. In this case, the
984 \l{QPaintDevice::PaintDeviceMetric}{device metrics} will report
985 the exact same dimensions as indicated by \{QPageSize}. It may not
986 be possible to print on the entire physical page because of the
987 printer's margins, so the application must account for the margins
988 itself.
989
990 \sa fullPage(), QPagedPaintDevice::pageLayout(), QPagedPaintDevice::setPageSize()
991*/
992
993void QPrinter::setFullPage(bool fp)
994{
995 Q_D(QPrinter);
996 // Set the print engine
997 d->setProperty(key: QPrintEngine::PPK_FullPage, value: fp);
998}
999
1000
1001/*!
1002 Returns \c true if the origin of the printer's coordinate system is
1003 at the corner of the page and false if it is at the edge of the
1004 printable area.
1005
1006 See setFullPage() for details and caveats.
1007
1008 \sa setFullPage(), QPagedPaintDevice::pageLayout()
1009*/
1010
1011bool QPrinter::fullPage() const
1012{
1013 Q_D(const QPrinter);
1014 return d->printEngine->property(key: QPrintEngine::PPK_FullPage).toBool();
1015}
1016
1017
1018/*!
1019 Requests that the printer prints at \a dpi or as near to \a dpi as
1020 possible.
1021
1022 This setting affects the coordinate system as returned by, for
1023 example QPainter::viewport().
1024
1025 This function must be called before QPainter::begin() to have an effect on
1026 all platforms.
1027
1028 \sa resolution(), QPagedPaintDevice::setPageSize()
1029*/
1030
1031void QPrinter::setResolution(int dpi)
1032{
1033 Q_D(QPrinter);
1034 ABORT_IF_ACTIVE("QPrinter::setResolution");
1035 d->setProperty(key: QPrintEngine::PPK_Resolution, value: dpi);
1036}
1037
1038
1039/*!
1040 Returns the current assumed resolution of the printer, as set by
1041 setResolution() or by the printer driver.
1042
1043 \sa setResolution()
1044*/
1045
1046int QPrinter::resolution() const
1047{
1048 Q_D(const QPrinter);
1049 return d->printEngine->property(key: QPrintEngine::PPK_Resolution).toInt();
1050}
1051
1052/*!
1053 Sets the paper source setting to \a source.
1054
1055 Windows only: This option can be changed while printing and will
1056 take effect from the next call to newPage()
1057
1058 \sa paperSource()
1059*/
1060
1061void QPrinter::setPaperSource(PaperSource source)
1062{
1063 Q_D(QPrinter);
1064 d->setProperty(key: QPrintEngine::PPK_PaperSource, value: source);
1065}
1066
1067/*!
1068 Returns the printer's paper source. This is \c Manual or a printer
1069 tray or paper cassette.
1070*/
1071QPrinter::PaperSource QPrinter::paperSource() const
1072{
1073 Q_D(const QPrinter);
1074 return QPrinter::PaperSource(d->printEngine->property(key: QPrintEngine::PPK_PaperSource).toInt());
1075}
1076
1077
1078/*!
1079 \since 4.1
1080
1081 Enabled or disables font embedding depending on \a enable.
1082
1083 \sa fontEmbeddingEnabled()
1084*/
1085void QPrinter::setFontEmbeddingEnabled(bool enable)
1086{
1087 Q_D(QPrinter);
1088 d->setProperty(key: QPrintEngine::PPK_FontEmbedding, value: enable);
1089}
1090
1091/*!
1092 \since 4.1
1093
1094 Returns \c true if font embedding is enabled.
1095
1096 \sa setFontEmbeddingEnabled()
1097*/
1098bool QPrinter::fontEmbeddingEnabled() const
1099{
1100 Q_D(const QPrinter);
1101 return d->printEngine->property(key: QPrintEngine::PPK_FontEmbedding).toBool();
1102}
1103
1104/*!
1105 \enum QPrinter::DuplexMode
1106 \since 4.4
1107
1108 This enum is used to indicate whether printing will occur on one or both sides
1109 of each sheet of paper (simplex or duplex printing).
1110
1111 \value DuplexNone Single sided (simplex) printing only.
1112 \value DuplexAuto The printer's default setting is used to determine whether
1113 duplex printing is used.
1114 \value DuplexLongSide Both sides of each sheet of paper are used for printing.
1115 The paper is turned over its longest edge before the second
1116 side is printed
1117 \value DuplexShortSide Both sides of each sheet of paper are used for printing.
1118 The paper is turned over its shortest edge before the second
1119 side is printed
1120*/
1121
1122/*!
1123 \since 4.4
1124
1125 Enables double sided printing based on the \a duplex mode.
1126
1127 \sa duplex()
1128*/
1129void QPrinter::setDuplex(DuplexMode duplex)
1130{
1131 Q_D(QPrinter);
1132 d->setProperty(key: QPrintEngine::PPK_Duplex, value: duplex);
1133}
1134
1135/*!
1136 \since 4.4
1137
1138 Returns the current duplex mode.
1139
1140 \sa setDuplex()
1141*/
1142QPrinter::DuplexMode QPrinter::duplex() const
1143{
1144 Q_D(const QPrinter);
1145 return static_cast <DuplexMode> (d->printEngine->property(key: QPrintEngine::PPK_Duplex).toInt());
1146}
1147
1148/*!
1149 \since 4.4
1150
1151 Returns the page's rectangle in \a unit; this is usually smaller
1152 than the paperRect() since the page normally has margins between
1153 its borders and the paper.
1154
1155 \sa QPagedPaintDevice::pageLayout()
1156*/
1157QRectF QPrinter::pageRect(Unit unit) const
1158{
1159 if (unit == QPrinter::DevicePixel)
1160 return pageLayout().paintRectPixels(resolution: resolution());
1161 else
1162 return pageLayout().paintRect(units: QPageLayout::Unit(unit));
1163}
1164
1165
1166/*!
1167 \since 4.4
1168
1169 Returns the paper's rectangle in \a unit; this is usually larger
1170 than the pageRect().
1171
1172 \sa pageRect()
1173*/
1174QRectF QPrinter::paperRect(Unit unit) const
1175{
1176 if (unit == QPrinter::DevicePixel)
1177 return pageLayout().fullRectPixels(resolution: resolution());
1178 else
1179 return pageLayout().fullRect(units: QPageLayout::Unit(unit));
1180}
1181
1182/*!
1183 \internal
1184
1185 Returns the metric for the given \a id.
1186*/
1187int QPrinter::metric(PaintDeviceMetric id) const
1188{
1189 Q_D(const QPrinter);
1190 return d->printEngine->metric(id);
1191}
1192
1193/*!
1194 Returns the paint engine used by the printer.
1195*/
1196QPaintEngine *QPrinter::paintEngine() const
1197{
1198 Q_D(const QPrinter);
1199 return d->paintEngine;
1200}
1201
1202/*!
1203 \since 4.1
1204
1205 Returns the print engine used by the printer.
1206*/
1207QPrintEngine *QPrinter::printEngine() const
1208{
1209 Q_D(const QPrinter);
1210 return d->printEngine;
1211}
1212
1213/*!
1214 Returns a list of the resolutions (a list of dots-per-inch
1215 integers) that the printer says it supports.
1216
1217 For X11 where all printing is directly to PDF, this
1218 function will always return a one item list containing only the
1219 PDF resolution, i.e., 72 (72 dpi -- but see PrinterMode).
1220*/
1221QList<int> QPrinter::supportedResolutions() const
1222{
1223 Q_D(const QPrinter);
1224 const QList<QVariant> varlist
1225 = d->printEngine->property(key: QPrintEngine::PPK_SupportedResolutions).toList();
1226 QList<int> intlist;
1227 intlist.reserve(asize: varlist.size());
1228 for (const auto &var : varlist)
1229 intlist << var.toInt();
1230 return intlist;
1231}
1232
1233/*!
1234 Tells the printer to eject the current page and to continue
1235 printing on a new page. Returns \c true if this was successful;
1236 otherwise returns \c false.
1237
1238 Calling newPage() on an inactive QPrinter object will always
1239 fail.
1240*/
1241bool QPrinter::newPage()
1242{
1243 Q_D(QPrinter);
1244 if (d->printEngine->printerState() != QPrinter::Active)
1245 return false;
1246 return d->printEngine->newPage();
1247}
1248
1249/*!
1250 Aborts the current print run. Returns \c true if the print run was
1251 successfully aborted and printerState() will return QPrinter::Aborted; otherwise
1252 returns \c false.
1253
1254 It is not always possible to abort a print job. For example,
1255 all the data has gone to the printer but the printer cannot or
1256 will not cancel the job when asked to.
1257*/
1258bool QPrinter::abort()
1259{
1260 Q_D(QPrinter);
1261 return d->printEngine->abort();
1262}
1263
1264/*!
1265 Returns the current state of the printer. This may not always be
1266 accurate (for example if the printer doesn't have the capability
1267 of reporting its state to the operating system).
1268*/
1269QPrinter::PrinterState QPrinter::printerState() const
1270{
1271 Q_D(const QPrinter);
1272 return d->printEngine->printerState();
1273}
1274
1275#if defined(Q_OS_WIN) || defined(Q_QDOC)
1276/*!
1277 Returns the supported paper sizes for this printer.
1278
1279 The values will be either a value that matches an entry in the
1280 QPrinter::PaperSource enum or a driver spesific value. The driver
1281 spesific values are greater than the constant DMBIN_USER declared
1282 in wingdi.h.
1283
1284 \warning This function is only available in windows.
1285*/
1286
1287QList<QPrinter::PaperSource> QPrinter::supportedPaperSources() const
1288{
1289 Q_D(const QPrinter);
1290 QVariant v = d->printEngine->property(QPrintEngine::PPK_PaperSources);
1291
1292 const QList<QVariant> variant_list = v.toList();
1293 QList<QPrinter::PaperSource> int_list;
1294 int_list.reserve(variant_list.size());
1295 for (const auto &variant : variant_list)
1296 int_list << QPrinter::PaperSource(variant.toInt());
1297
1298 return int_list;
1299}
1300
1301#endif // Q_OS_WIN
1302
1303/*!
1304 \fn QString QPrinter::printerSelectionOption() const
1305
1306 Returns the printer options selection string. This is useful only
1307 if the print command has been explicitly set.
1308
1309 The default value (an empty string) implies that the printer should
1310 be selected in a system-dependent manner.
1311
1312 Any other value implies that the given value should be used.
1313
1314 This function always returns an empty string on Windows and Mac.
1315
1316 \sa setPrinterSelectionOption(), setPrintProgram()
1317*/
1318
1319QString QPrinter::printerSelectionOption() const
1320{
1321 Q_D(const QPrinter);
1322 return d->printEngine->property(key: QPrintEngine::PPK_SelectionOption).toString();
1323}
1324
1325/*!
1326 \fn void QPrinter::setPrinterSelectionOption(const QString &option)
1327
1328 Sets the printer to use \a option to select the printer. \a option
1329 is null by default (which implies that Qt should be smart enough
1330 to guess correctly), but it can be set to other values to use a
1331 specific printer selection option.
1332
1333 If the printer selection option is changed while the printer is
1334 active, the current print job may or may not be affected.
1335
1336 This function has no effect on Windows or Mac.
1337
1338 \sa printerSelectionOption(), setPrintProgram()
1339*/
1340
1341void QPrinter::setPrinterSelectionOption(const QString &option)
1342{
1343 Q_D(QPrinter);
1344 d->setProperty(key: QPrintEngine::PPK_SelectionOption, value: option);
1345}
1346
1347/*!
1348 \since 4.1
1349 \fn int QPrinter::fromPage() const
1350
1351 Returns the number of the first page in a range of pages to be printed
1352 (the "from page" setting). Pages in a document are numbered according to
1353 the convention that the first page is page 1.
1354
1355 By default, this function returns a special value of 0, meaning that
1356 the "from page" setting is unset.
1357
1358 \note If fromPage() and toPage() both return 0, this indicates that
1359 \e{the whole document will be printed}.
1360
1361 \sa setFromTo(), toPage(), pageRanges()
1362*/
1363
1364int QPrinter::fromPage() const
1365{
1366 return d->pageRanges.firstPage();
1367}
1368
1369/*!
1370 \since 4.1
1371
1372 Returns the number of the last page in a range of pages to be printed
1373 (the "to page" setting). Pages in a document are numbered according to
1374 the convention that the first page is page 1.
1375
1376 By default, this function returns a special value of 0, meaning that
1377 the "to page" setting is unset.
1378
1379 \note If fromPage() and toPage() both return 0, this indicates that
1380 \e{the whole document will be printed}.
1381
1382 The programmer is responsible for reading this setting and
1383 printing accordingly.
1384
1385 \sa setFromTo(), fromPage(), pageRanges()
1386*/
1387
1388int QPrinter::toPage() const
1389{
1390 return d->pageRanges.lastPage();
1391}
1392
1393/*!
1394 \since 4.1
1395
1396 Sets the range of pages to be printed to cover the pages with numbers
1397 specified by \a from and \a to, where \a from corresponds to the first
1398 page in the range and \a to corresponds to the last.
1399
1400 \note Pages in a document are numbered according to the convention that
1401 the first page is page 1. However, if \a from and \a to are both set to 0,
1402 the \e{whole document will be printed}.
1403
1404 This function is mostly used to set a default value that the user can
1405 override in the print dialog when you call setup().
1406
1407 \sa fromPage(), toPage(), pageRanges()
1408*/
1409
1410void QPrinter::setFromTo(int from, int to)
1411{
1412 d->pageRanges.clear();
1413 if (from && to)
1414 d->pageRanges.addRange(from, to);
1415}
1416
1417/*!
1418 \since 4.1
1419
1420 Sets the print range option in to be \a range.
1421*/
1422void QPrinter::setPrintRange( PrintRange range )
1423{
1424 d->printSelectionOnly = (range == Selection);
1425
1426 Q_D(QPrinter);
1427 d->printRange = range;
1428}
1429
1430/*!
1431 \since 4.1
1432
1433 Returns the page range of the QPrinter. After the print setup
1434 dialog has been opened, this function returns the value selected
1435 by the user.
1436
1437 \sa setPrintRange()
1438*/
1439QPrinter::PrintRange QPrinter::printRange() const
1440{
1441 Q_D(const QPrinter);
1442 return d->printRange;
1443}
1444
1445
1446/*!
1447 \class QPrintEngine
1448 \reentrant
1449
1450 \ingroup printing
1451 \inmodule QtPrintSupport
1452
1453 \brief The QPrintEngine class defines an interface for how QPrinter
1454 interacts with a given printing subsystem.
1455
1456 The common case when creating your own print engine is to derive from both
1457 QPaintEngine and QPrintEngine. Various properties of a print engine are
1458 given with property() and set with setProperty().
1459
1460 \sa QPaintEngine
1461*/
1462
1463/*!
1464 \enum QPrintEngine::PrintEnginePropertyKey
1465
1466 This enum is used to communicate properties between the print
1467 engine and QPrinter. A property may or may not be supported by a
1468 given print engine.
1469
1470 \value PPK_CollateCopies A boolean value indicating whether the
1471 printout should be collated or not.
1472
1473 \value PPK_ColorMode Refers to QPrinter::ColorMode, either color or
1474 monochrome.
1475
1476 \value PPK_Creator A string describing the document's creator.
1477
1478 \value PPK_Duplex A boolean value indicating whether both sides of
1479 the printer paper should be used for the printout.
1480
1481 \value PPK_DocumentName A string describing the document name in
1482 the spooler.
1483
1484 \value PPK_FontEmbedding A boolean value indicating whether data for
1485 the document's fonts should be embedded in the data sent to the
1486 printer.
1487
1488 \value PPK_FullPage A boolean describing if the printer should be
1489 full page or not.
1490
1491 \value PPK_NumberOfCopies Obsolete. An integer specifying the number of
1492 copies. Use PPK_CopyCount instead.
1493
1494 \value PPK_Orientation Specifies a QPageLayout::Orientation value.
1495
1496 \value PPK_OutputFileName The output file name as a string. An
1497 empty file name indicates that the printer should not print to a file.
1498
1499 \value PPK_PageOrder Specifies a QPrinter::PageOrder value.
1500
1501 \value PPK_PageRect A QRect specifying the page rectangle
1502
1503 \value PPK_PageSize Obsolete. Use PPK_PaperSize instead.
1504
1505 \value PPK_PaperRect A QRect specifying the paper rectangle.
1506
1507 \value PPK_PaperSource Specifies a QPrinter::PaperSource value.
1508
1509 \value PPK_PaperSources Specifies more than one QPrinter::PaperSource value.
1510
1511 \value PPK_PaperName A string specifying the name of the paper.
1512
1513 \value PPK_PaperSize Specifies a QPrinter::PaperSize value.
1514
1515 \value PPK_PrinterName A string specifying the name of the printer.
1516
1517 \value PPK_PrinterProgram A string specifying the name of the
1518 printer program used for printing,
1519
1520 \value PPK_Resolution An integer describing the dots per inch for
1521 this printer.
1522
1523 \value PPK_SelectionOption
1524
1525 \value PPK_SupportedResolutions A list of integer QVariants
1526 describing the set of supported resolutions that the printer has.
1527
1528 \value PPK_WindowsPageSize An integer specifying a DM_PAPER entry
1529 on Windows.
1530
1531 \value PPK_CustomPaperSize A QSizeF specifying a custom paper size
1532 in the QPrinter::Point unit.
1533
1534 \value PPK_PageMargins A QList<QVariant> containing the left, top,
1535 right and bottom margin values in the QPrinter::Point unit.
1536
1537 \value PPK_CopyCount An integer specifying the number of copies to print.
1538
1539 \value PPK_SupportsMultipleCopies A boolean value indicating whether or not
1540 the printer supports printing multiple copies in one job.
1541
1542 \value PPK_QPageSize Set the page size using a QPageSize object.
1543
1544 \value PPK_QPageMargins Set the page margins using a QPair of QMarginsF and QPageLayout::Unit.
1545
1546 \value PPK_QPageLayout Set the page layout using a QPageLayout object.
1547
1548 \value PPK_CustomBase Basis for extension.
1549*/
1550
1551/*!
1552 \fn QPrintEngine::~QPrintEngine()
1553
1554 Destroys the print engine.
1555*/
1556
1557/*!
1558 \fn void QPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value)
1559
1560 Sets the print engine's property specified by \a key to the given \a value.
1561
1562 \sa property()
1563*/
1564
1565/*!
1566 \fn void QPrintEngine::property(PrintEnginePropertyKey key) const
1567
1568 Returns the print engine's property specified by \a key.
1569
1570 \sa setProperty()
1571*/
1572
1573/*!
1574 \fn bool QPrintEngine::newPage()
1575
1576 Instructs the print engine to start a new page. Returns \c true if
1577 the printer was able to create the new page; otherwise returns \c false.
1578*/
1579
1580/*!
1581 \fn bool QPrintEngine::abort()
1582
1583 Instructs the print engine to abort the printing process. Returns
1584 true if successful; otherwise returns \c false.
1585*/
1586
1587/*!
1588 \fn int QPrintEngine::metric(QPaintDevice::PaintDeviceMetric id) const
1589
1590 Returns the metric for the given \a id.
1591*/
1592
1593/*!
1594 \fn QPrinter::PrinterState QPrintEngine::printerState() const
1595
1596 Returns the current state of the printer being used by the print engine.
1597*/
1598
1599QT_END_NAMESPACE
1600
1601#endif // QT_NO_PRINTER
1602

source code of qtbase/src/printsupport/kernel/qprinter.cpp