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