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