1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtGui module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qprinter.h" |
41 | #include "qprinter_p.h" |
42 | |
43 | #ifndef QT_NO_PRINTER |
44 | |
45 | #include <qpa/qplatformprintplugin.h> |
46 | #include <qpa/qplatformprintersupport.h> |
47 | |
48 | #include "qprintengine.h" |
49 | #include "qlist.h" |
50 | #include <qcoreapplication.h> |
51 | #include <qfileinfo.h> |
52 | |
53 | #include <private/qpagedpaintdevice_p.h> |
54 | |
55 | #include "qprintengine_pdf_p.h" |
56 | |
57 | #include <qpicture.h> |
58 | #if QT_CONFIG(printpreviewwidget) |
59 | #include <private/qpaintengine_preview_p.h> |
60 | #endif |
61 | |
62 | QT_BEGIN_NAMESPACE |
63 | |
64 | #define ABORT_IF_ACTIVE(location) \ |
65 | if (d->printEngine->printerState() == QPrinter::Active) { \ |
66 | qWarning("%s: Cannot be changed while printer is active", location); \ |
67 | return; \ |
68 | } |
69 | |
70 | #define ABORT_IF_ACTIVE_RETURN(location, retValue) \ |
71 | if (d->printEngine->printerState() == QPrinter::Active) { \ |
72 | qWarning("%s: Cannot be changed while printer is active", location); \ |
73 | return retValue; \ |
74 | } |
75 | |
76 | extern qreal qt_pixelMultiplier(int resolution); |
77 | extern QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits); |
78 | |
79 | /// return the multiplier of converting from the unit value to postscript-points. |
80 | Q_PRINTSUPPORT_EXPORT double qt_multiplierForUnit(QPrinter::Unit unit, int resolution) |
81 | { |
82 | switch(unit) { |
83 | case QPrinter::Millimeter: |
84 | return 2.83464566929; |
85 | case QPrinter::Point: |
86 | return 1.0; |
87 | case QPrinter::Inch: |
88 | return 72.0; |
89 | case QPrinter::Pica: |
90 | return 12; |
91 | case QPrinter::Didot: |
92 | return 1.065826771; |
93 | case QPrinter::Cicero: |
94 | return 12.789921252; |
95 | case QPrinter::DevicePixel: |
96 | return 72.0/resolution; |
97 | } |
98 | return 1.0; |
99 | } |
100 | |
101 | // not static: it's needed in qpagesetupdialog_unix.cpp |
102 | Q_PRINTSUPPORT_EXPORT QSizeF qt_printerPaperSize(QPrinter::Orientation orientation, |
103 | QPrinter::PaperSize paperSize, |
104 | QPrinter::Unit unit, |
105 | int resolution) |
106 | { |
107 | QPageSize pageSize = QPageSize(QPageSize::PageSizeId(paperSize)); |
108 | QSizeF sizef; |
109 | if (unit == QPrinter::DevicePixel) |
110 | sizef = pageSize.size(units: QPageSize::Point) * qt_multiplierForUnit(unit, resolution); |
111 | else |
112 | sizef = pageSize.size(units: QPageSize::Unit(unit)); |
113 | return orientation == QPrinter::Landscape ? sizef.transposed() : sizef; |
114 | } |
115 | |
116 | QPrinterInfo QPrinterPrivate::findValidPrinter(const QPrinterInfo &printer) |
117 | { |
118 | // Try find a valid printer to use, either the one given, the default or the first available |
119 | QPrinterInfo printerToUse = printer; |
120 | if (printerToUse.isNull()) { |
121 | printerToUse = QPrinterInfo::defaultPrinter(); |
122 | if (printerToUse.isNull()) { |
123 | QStringList availablePrinterNames = QPrinterInfo::availablePrinterNames(); |
124 | if (!availablePrinterNames.isEmpty()) |
125 | printerToUse = QPrinterInfo::printerInfo(printerName: availablePrinterNames.at(i: 0)); |
126 | } |
127 | } |
128 | return printerToUse; |
129 | } |
130 | |
131 | void QPrinterPrivate::initEngines(QPrinter::OutputFormat format, const QPrinterInfo &printer) |
132 | { |
133 | // Default to PdfFormat |
134 | outputFormat = QPrinter::PdfFormat; |
135 | QPlatformPrinterSupport *ps = nullptr; |
136 | QString printerName; |
137 | |
138 | // Only set NativeFormat if we have a valid plugin and printer to use |
139 | if (format == QPrinter::NativeFormat) { |
140 | ps = QPlatformPrinterSupportPlugin::get(); |
141 | QPrinterInfo printerToUse = findValidPrinter(printer); |
142 | if (ps && !printerToUse.isNull()) { |
143 | outputFormat = QPrinter::NativeFormat; |
144 | printerName = printerToUse.printerName(); |
145 | } |
146 | } |
147 | |
148 | if (outputFormat == QPrinter::NativeFormat) { |
149 | printEngine = ps->createNativePrintEngine(printerMode, deviceId: printerName); |
150 | paintEngine = ps->createPaintEngine(printEngine, printerMode); |
151 | } else { |
152 | static const QHash<QPrinter::PdfVersion, QPdfEngine::PdfVersion> engineMapping { |
153 | {QPrinter::PdfVersion_1_4, QPdfEngine::Version_1_4}, |
154 | {QPrinter::PdfVersion_A1b, QPdfEngine::Version_A1b}, |
155 | {QPrinter::PdfVersion_1_6, QPdfEngine::Version_1_6} |
156 | }; |
157 | const auto pdfEngineVersion = engineMapping.value(akey: pdfVersion, adefaultValue: QPdfEngine::Version_1_4); |
158 | QPdfPrintEngine *pdfEngine = new QPdfPrintEngine(printerMode, pdfEngineVersion); |
159 | paintEngine = pdfEngine; |
160 | printEngine = pdfEngine; |
161 | } |
162 | |
163 | use_default_engine = true; |
164 | had_default_engines = true; |
165 | validPrinter = true; |
166 | } |
167 | |
168 | void QPrinterPrivate::changeEngines(QPrinter::OutputFormat format, const QPrinterInfo &printer) |
169 | { |
170 | QPrintEngine *oldPrintEngine = printEngine; |
171 | const bool def_engine = use_default_engine; |
172 | |
173 | initEngines(format, printer); |
174 | |
175 | if (oldPrintEngine) { |
176 | const auto properties = m_properties; // take a copy: setProperty() below modifies m_properties |
177 | for (const auto &key : properties) { |
178 | QVariant prop; |
179 | // PPK_NumberOfCopies need special treatmeant since it in most cases |
180 | // will return 1, disregarding the actual value that was set |
181 | // PPK_PrinterName also needs special treatment as initEngines has set it already |
182 | if (key == QPrintEngine::PPK_NumberOfCopies) |
183 | prop = QVariant(q_ptr->copyCount()); |
184 | else if (key != QPrintEngine::PPK_PrinterName) |
185 | prop = oldPrintEngine->property(key); |
186 | if (prop.isValid()) |
187 | setProperty(key, value: prop); |
188 | } |
189 | } |
190 | |
191 | if (def_engine) |
192 | delete oldPrintEngine; |
193 | } |
194 | |
195 | #if QT_CONFIG(printpreviewwidget) |
196 | QList<const QPicture *> QPrinterPrivate::previewPages() const |
197 | { |
198 | if (previewEngine) |
199 | return previewEngine->pages(); |
200 | return QList<const QPicture *>(); |
201 | } |
202 | |
203 | void QPrinterPrivate::setPreviewMode(bool enable) |
204 | { |
205 | Q_Q(QPrinter); |
206 | if (enable) { |
207 | if (!previewEngine) |
208 | previewEngine = new QPreviewPaintEngine; |
209 | had_default_engines = use_default_engine; |
210 | use_default_engine = false; |
211 | realPrintEngine = printEngine; |
212 | realPaintEngine = paintEngine; |
213 | q->setEngines(printEngine: previewEngine, paintEngine: previewEngine); |
214 | previewEngine->setProxyEngines(printEngine: realPrintEngine, paintEngine: realPaintEngine); |
215 | } else { |
216 | q->setEngines(printEngine: realPrintEngine, paintEngine: realPaintEngine); |
217 | use_default_engine = had_default_engines; |
218 | } |
219 | } |
220 | #endif // QT_CONFIG(printpreviewwidget) |
221 | |
222 | void QPrinterPrivate::setProperty(QPrintEngine::PrintEnginePropertyKey key, const QVariant &value) |
223 | { |
224 | printEngine->setProperty(key, value); |
225 | m_properties.insert(value: key); |
226 | } |
227 | |
228 | |
229 | class QPrinterPagedPaintDevicePrivate : public QPagedPaintDevicePrivate |
230 | { |
231 | public: |
232 | QPrinterPagedPaintDevicePrivate(QPrinter *p) |
233 | : QPagedPaintDevicePrivate(), m_printer(p) |
234 | {} |
235 | |
236 | virtual ~QPrinterPagedPaintDevicePrivate() |
237 | {} |
238 | |
239 | bool setPageLayout(const QPageLayout &newPageLayout) override |
240 | { |
241 | QPrinterPrivate *pd = QPrinterPrivate::get(printer: m_printer); |
242 | |
243 | if (pd->paintEngine->type() != QPaintEngine::Pdf |
244 | && pd->printEngine->printerState() == QPrinter::Active) { |
245 | qWarning(msg: "QPrinter::setPageLayout: Cannot be changed while printer is active" ); |
246 | return false; |
247 | } |
248 | |
249 | // Try to set the print engine page layout |
250 | pd->setProperty(key: QPrintEngine::PPK_QPageLayout, value: QVariant::fromValue(value: newPageLayout)); |
251 | |
252 | return pageLayout().isEquivalentTo(other: newPageLayout); |
253 | } |
254 | |
255 | bool setPageSize(const QPageSize &pageSize) override |
256 | { |
257 | QPrinterPrivate *pd = QPrinterPrivate::get(printer: m_printer); |
258 | |
259 | if (pd->paintEngine->type() != QPaintEngine::Pdf |
260 | && pd->printEngine->printerState() == QPrinter::Active) { |
261 | qWarning(msg: "QPrinter::setPageLayout: Cannot be changed while printer is active" ); |
262 | return false; |
263 | } |
264 | |
265 | |
266 | // Try to set the print engine page size |
267 | pd->setProperty(key: QPrintEngine::PPK_QPageSize, value: QVariant::fromValue(value: pageSize)); |
268 | |
269 | return pageLayout().pageSize().isEquivalentTo(other: pageSize); |
270 | } |
271 | |
272 | bool setPageOrientation(QPageLayout::Orientation orientation) override |
273 | { |
274 | QPrinterPrivate *pd = QPrinterPrivate::get(printer: m_printer); |
275 | |
276 | // Set the print engine value |
277 | pd->setProperty(key: QPrintEngine::PPK_Orientation, value: orientation); |
278 | |
279 | return pageLayout().orientation() == orientation; |
280 | } |
281 | |
282 | bool setPageMargins(const QMarginsF &margins, QPageLayout::Unit units) override |
283 | { |
284 | QPrinterPrivate *pd = QPrinterPrivate::get(printer: m_printer); |
285 | |
286 | // Try to set print engine margins |
287 | QPair<QMarginsF, QPageLayout::Unit> pair = qMakePair(x: margins, y: units); |
288 | pd->setProperty(key: QPrintEngine::PPK_QPageMargins, value: QVariant::fromValue(value: pair)); |
289 | |
290 | return pageLayout().margins() == margins && pageLayout().units() == units; |
291 | } |
292 | |
293 | QPageLayout pageLayout() const override |
294 | { |
295 | QPrinterPrivate *pd = QPrinterPrivate::get(printer: m_printer); |
296 | |
297 | return qvariant_cast<QPageLayout>(v: pd->printEngine->property(key: QPrintEngine::PPK_QPageLayout)); |
298 | } |
299 | |
300 | QPrinter *m_printer; |
301 | }; |
302 | |
303 | |
304 | /*! |
305 | \class QPrinter |
306 | \reentrant |
307 | |
308 | \brief The QPrinter class is a paint device that paints on a printer. |
309 | |
310 | \ingroup printing |
311 | \inmodule QtPrintSupport |
312 | |
313 | |
314 | This device represents a series of pages of printed output, and is |
315 | used in almost exactly the same way as other paint devices such as |
316 | QWidget and QPixmap. |
317 | A set of additional functions are provided to manage device-specific |
318 | features, such as orientation and resolution, and to step through |
319 | the pages in a document as it is generated. |
320 | |
321 | When printing directly to a printer on Windows or \macos, QPrinter uses |
322 | the built-in printer drivers. On X11, QPrinter uses the |
323 | \l{Common Unix Printing System (CUPS)} |
324 | to send PDF output to the printer. As an alternative, |
325 | the printProgram() function can be used to specify the command or utility |
326 | to use instead of the system default. |
327 | |
328 | Note that setting parameters like paper size and resolution on an |
329 | invalid printer is undefined. You can use QPrinter::isValid() to |
330 | verify this before changing any parameters. |
331 | |
332 | QPrinter supports a number of parameters, most of which can be |
333 | changed by the end user through a \l{QPrintDialog}{print dialog}. In |
334 | general, QPrinter passes these functions onto the underlying QPrintEngine. |
335 | |
336 | The most important parameters are: |
337 | \list |
338 | \li setOrientation() tells QPrinter which page orientation to use. |
339 | \li setPaperSize() tells QPrinter what paper size to expect from the |
340 | printer. |
341 | \li setResolution() tells QPrinter what resolution you wish the |
342 | printer to provide, in dots per inch (DPI). |
343 | \li setFullPage() tells QPrinter whether you want to deal with the |
344 | full page or just with the part the printer can draw on. |
345 | \li setCopyCount() tells QPrinter how many copies of the document |
346 | it should print. |
347 | \endlist |
348 | |
349 | Many of these functions can only be called before the actual printing |
350 | begins (i.e., before QPainter::begin() is called). This usually makes |
351 | sense because, for example, it's not possible to change the number of |
352 | copies when you are halfway through printing. There are also some |
353 | settings that the user sets (through the printer dialog) and that |
354 | applications are expected to obey. See QAbstractPrintDialog's |
355 | documentation for more details. |
356 | |
357 | When QPainter::begin() is called, the QPrinter it operates on is prepared for |
358 | a new page, enabling the QPainter to be used immediately to paint the first |
359 | page in a document. Once the first page has been painted, newPage() can be |
360 | called to request a new blank page to paint on, or QPainter::end() can be |
361 | called to finish printing. The second page and all following pages are |
362 | prepared using a call to newPage() before they are painted. |
363 | |
364 | The first page in a document does not need to be preceded by a call to |
365 | newPage(). You only need to calling newPage() after QPainter::begin() if you |
366 | need to insert a blank page at the beginning of a printed document. |
367 | Similarly, calling newPage() after the last page in a document is painted will |
368 | result in a trailing blank page appended to the end of the printed document. |
369 | |
370 | If you want to abort the print job, abort() will try its best to |
371 | stop printing. It may cancel the entire job or just part of it. |
372 | |
373 | Since QPrinter can print to any QPrintEngine subclass, it is possible to |
374 | extend printing support to cover new types of printing subsystem by |
375 | subclassing QPrintEngine and reimplementing its interface. |
376 | |
377 | \sa QPrintDialog, {Qt Print Support} |
378 | */ |
379 | |
380 | /*! |
381 | \enum QPrinter::PrinterState |
382 | |
383 | \value Idle |
384 | \value Active |
385 | \value Aborted |
386 | \value Error |
387 | */ |
388 | |
389 | /*! |
390 | \enum QPrinter::PrinterMode |
391 | |
392 | This enum describes the mode the printer should work in. It |
393 | basically presets a certain resolution and working mode. |
394 | |
395 | \value ScreenResolution Sets the resolution of the print device to |
396 | the screen resolution. This has the big advantage that the results |
397 | obtained when painting on the printer will match more or less |
398 | exactly the visible output on the screen. It is the easiest to |
399 | use, as font metrics on the screen and on the printer are the |
400 | same. This is the default value. ScreenResolution will produce a |
401 | lower quality output than HighResolution and should only be used |
402 | for drafts. |
403 | |
404 | \value PrinterResolution This value is deprecated. It is |
405 | equivalent to ScreenResolution on Unix and HighResolution on |
406 | Windows and Mac. Due to the difference between ScreenResolution |
407 | and HighResolution, use of this value may lead to non-portable |
408 | printer code. |
409 | |
410 | \value HighResolution On Windows, sets the printer resolution to that |
411 | defined for the printer in use. For PDF printing, sets the |
412 | resolution of the PDF driver to 1200 dpi. |
413 | |
414 | \note When rendering text on a QPrinter device, it is important |
415 | to realize that the size of text, when specified in points, is |
416 | independent of the resolution specified for the device itself. |
417 | Therefore, it may be useful to specify the font size in pixels |
418 | when combining text with graphics to ensure that their relative |
419 | sizes are what you expect. |
420 | */ |
421 | |
422 | /*! |
423 | \enum QPrinter::Orientation |
424 | |
425 | This enum type (not to be confused with \c Orientation) is used |
426 | to specify each page's orientation. |
427 | |
428 | \value Portrait the page's height is greater than its width. |
429 | |
430 | \value Landscape the page's width is greater than its height. |
431 | |
432 | This type interacts with \l QPrinter::PaperSize and |
433 | QPrinter::setFullPage() to determine the final size of the page |
434 | available to the application. |
435 | */ |
436 | |
437 | |
438 | /*! |
439 | \enum QPrinter::PrintRange |
440 | |
441 | Used to specify the print range selection option. |
442 | |
443 | \value AllPages All pages should be printed. |
444 | \value Selection Only the selection should be printed. |
445 | \value PageRange The specified page range should be printed. |
446 | \value CurrentPage Only the current page should be printed. |
447 | |
448 | \sa setPrintRange(), printRange(), QAbstractPrintDialog::PrintRange |
449 | */ |
450 | |
451 | /*! |
452 | \typedef QPrinter::PaperSize |
453 | \since 4.4 |
454 | |
455 | typdef for the enum QPagedPaintDevice::PageSize. |
456 | |
457 | This enum type specifies what paper size QPrinter should use. |
458 | QPrinter does not check that the paper size is available; it just |
459 | uses this information, together with QPrinter::Orientation and |
460 | QPrinter::setFullPage(), to determine the printable area. |
461 | |
462 | The defined sizes (with setFullPage(true)) are found in QPagedPaintDevice. |
463 | |
464 | With setFullPage(false) (the default), the metrics will be a bit |
465 | smaller; how much depends on the printer in use. |
466 | |
467 | Due to historic reasons QPageSize::Executive is not the same as the standard |
468 | Postscript and Windows Executive size, use QPageSize::ExecutiveStandard instead. |
469 | |
470 | The Postscript standard size QPageSize::Folio is different to the Windows |
471 | DMPAPER_FOLIO size, use the Postscript standard size QPageSize::FanFoldGermanLegal |
472 | if needed. |
473 | */ |
474 | |
475 | |
476 | /*! |
477 | \enum QPrinter::PageOrder |
478 | |
479 | This enum type is used by QPrinter to tell the application program |
480 | how to print. |
481 | |
482 | \value FirstPageFirst the lowest-numbered page should be printed |
483 | first. |
484 | |
485 | \value LastPageFirst the highest-numbered page should be printed |
486 | first. |
487 | */ |
488 | |
489 | /*! |
490 | \enum QPrinter::ColorMode |
491 | |
492 | This enum type is used to indicate whether QPrinter should print |
493 | in color or not. |
494 | |
495 | \value Color print in color if available, otherwise in grayscale. |
496 | |
497 | \value GrayScale print in grayscale, even on color printers. |
498 | */ |
499 | |
500 | /*! |
501 | \enum QPrinter::PaperSource |
502 | |
503 | This enum type specifies what paper source QPrinter is to use. |
504 | QPrinter does not check that the paper source is available; it |
505 | just uses this information to try and set the paper source. |
506 | Whether it will set the paper source depends on whether the |
507 | printer has that particular source. |
508 | |
509 | \warning This is currently only implemented for Windows. |
510 | |
511 | \value Auto |
512 | \value Cassette |
513 | \value Envelope |
514 | \value EnvelopeManual |
515 | \value FormSource |
516 | \value LargeCapacity |
517 | \value LargeFormat |
518 | \value Lower |
519 | \value MaxPageSource Deprecated, use LastPaperSource instead |
520 | \value Middle |
521 | \value Manual |
522 | \value OnlyOne |
523 | \value Tractor |
524 | \value SmallFormat |
525 | \value Upper |
526 | \value CustomSource A PaperSource defined by the printer that is unknown to Qt |
527 | \value LastPaperSource The highest valid PaperSource value, currently CustomSource |
528 | */ |
529 | |
530 | /*! |
531 | \enum QPrinter::Unit |
532 | \since 4.4 |
533 | |
534 | This enum type is used to specify the measurement unit for page and |
535 | paper sizes. |
536 | |
537 | \value Millimeter |
538 | \value Point |
539 | \value Inch |
540 | \value Pica |
541 | \value Didot |
542 | \value Cicero |
543 | \value DevicePixel |
544 | |
545 | Note the difference between Point and DevicePixel. The Point unit is |
546 | defined to be 1/72th of an inch, while the DevicePixel unit is |
547 | resolution dependant and is based on the actual pixels, or dots, on |
548 | the printer. |
549 | */ |
550 | |
551 | /*! |
552 | Creates a new printer object with the given \a mode. |
553 | */ |
554 | QPrinter::QPrinter(PrinterMode mode) |
555 | : QPagedPaintDevice(new QPrinterPagedPaintDevicePrivate(this)), |
556 | d_ptr(new QPrinterPrivate(this)) |
557 | { |
558 | d_ptr->init(printer: QPrinterInfo(), mode); |
559 | } |
560 | |
561 | /*! |
562 | \since 4.4 |
563 | |
564 | Creates a new printer object with the given \a printer and \a mode. |
565 | */ |
566 | QPrinter::QPrinter(const QPrinterInfo& printer, PrinterMode mode) |
567 | : QPagedPaintDevice(new QPrinterPagedPaintDevicePrivate(this)), |
568 | d_ptr(new QPrinterPrivate(this)) |
569 | { |
570 | d_ptr->init(printer, mode); |
571 | } |
572 | |
573 | void QPrinterPrivate::init(const QPrinterInfo &printer, QPrinter::PrinterMode mode) |
574 | { |
575 | if (Q_UNLIKELY(!QCoreApplication::instance())) { |
576 | qFatal(msg: "QPrinter: Must construct a QCoreApplication before a QPrinter" ); |
577 | return; |
578 | } |
579 | |
580 | printerMode = mode; |
581 | |
582 | initEngines(format: QPrinter::NativeFormat, printer); |
583 | } |
584 | |
585 | /*! |
586 | This function is used by subclasses of QPrinter to specify custom |
587 | print and paint engines (\a printEngine and \a paintEngine, |
588 | respectively). |
589 | |
590 | QPrinter does not take ownership of the engines, so you need to |
591 | manage these engine instances yourself. |
592 | |
593 | Note that changing the engines will reset the printer state and |
594 | all its properties. |
595 | |
596 | \sa printEngine(), paintEngine(), setOutputFormat() |
597 | |
598 | \since 4.1 |
599 | */ |
600 | void QPrinter::setEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine) |
601 | { |
602 | Q_D(QPrinter); |
603 | |
604 | if (d->use_default_engine) |
605 | delete d->printEngine; |
606 | |
607 | d->printEngine = printEngine; |
608 | d->paintEngine = paintEngine; |
609 | d->use_default_engine = false; |
610 | } |
611 | |
612 | /*! |
613 | Destroys the printer object and frees any allocated resources. If |
614 | the printer is destroyed while a print job is in progress this may |
615 | or may not affect the print job. |
616 | */ |
617 | QPrinter::~QPrinter() |
618 | { |
619 | Q_D(QPrinter); |
620 | if (d->use_default_engine) |
621 | delete d->printEngine; |
622 | #if QT_CONFIG(printpreviewwidget) |
623 | delete d->previewEngine; |
624 | #endif |
625 | } |
626 | |
627 | /*! |
628 | \enum QPrinter::OutputFormat |
629 | |
630 | The OutputFormat enum is used to describe the format QPrinter should |
631 | use for printing. |
632 | |
633 | \value NativeFormat QPrinter will print output using a method defined |
634 | by the platform it is running on. This mode is the default when printing |
635 | directly to a printer. |
636 | |
637 | \value PdfFormat QPrinter will generate its output as a searchable PDF file. |
638 | This mode is the default when printing to a file. |
639 | |
640 | \sa outputFormat(), setOutputFormat(), setOutputFileName() |
641 | */ |
642 | |
643 | /*! |
644 | \since 4.1 |
645 | |
646 | Sets the output format for this printer to \a format. |
647 | |
648 | If \a format is the same value as currently set then no change will be made. |
649 | |
650 | If \a format is NativeFormat then the printerName will be set to the default |
651 | printer. If there are no valid printers configured then no change will be made. |
652 | If you want to set NativeFormat with a specific printerName then use |
653 | setPrinterName(). |
654 | |
655 | \sa setPrinterName() |
656 | */ |
657 | void QPrinter::setOutputFormat(OutputFormat format) |
658 | { |
659 | Q_D(QPrinter); |
660 | |
661 | if (d->outputFormat == format) |
662 | return; |
663 | |
664 | if (format == QPrinter::NativeFormat) { |
665 | QPrinterInfo printerToUse = d->findValidPrinter(); |
666 | if (!printerToUse.isNull()) |
667 | d->changeEngines(format, printer: printerToUse); |
668 | } else { |
669 | d->changeEngines(format, printer: QPrinterInfo()); |
670 | } |
671 | } |
672 | |
673 | /*! |
674 | \since 4.1 |
675 | |
676 | Returns the output format for this printer. |
677 | */ |
678 | QPrinter::OutputFormat QPrinter::outputFormat() const |
679 | { |
680 | Q_D(const QPrinter); |
681 | return d->outputFormat; |
682 | } |
683 | |
684 | /*! |
685 | \since 5.10 |
686 | |
687 | Sets the PDF version for this printer to \a version. |
688 | |
689 | If \a version is the same value as currently set then no change will be made. |
690 | */ |
691 | void QPrinter::setPdfVersion(PdfVersion version) |
692 | { |
693 | Q_D(QPrinter); |
694 | |
695 | if (d->pdfVersion == version) |
696 | return; |
697 | |
698 | d->pdfVersion = version; |
699 | |
700 | if (d->outputFormat == QPrinter::PdfFormat) { |
701 | d->changeEngines(format: d->outputFormat, printer: QPrinterInfo()); |
702 | } |
703 | } |
704 | |
705 | /*! |
706 | \since 5.10 |
707 | |
708 | Returns the PDF version for this printer. The default is \c PdfVersion_1_4. |
709 | */ |
710 | QPrinter::PdfVersion QPrinter::pdfVersion() const |
711 | { |
712 | Q_D(const QPrinter); |
713 | return d->pdfVersion; |
714 | } |
715 | |
716 | /*! \internal |
717 | */ |
718 | int QPrinter::devType() const |
719 | { |
720 | return QInternal::Printer; |
721 | } |
722 | |
723 | /*! |
724 | Returns the printer name. This value is initially set to the name |
725 | of the default printer. |
726 | |
727 | \sa setPrinterName() |
728 | */ |
729 | QString QPrinter::printerName() const |
730 | { |
731 | Q_D(const QPrinter); |
732 | return d->printEngine->property(key: QPrintEngine::PPK_PrinterName).toString(); |
733 | } |
734 | |
735 | /*! |
736 | Sets the printer name to \a name. |
737 | |
738 | If the \a name is empty then the output format will be set to PdfFormat. |
739 | |
740 | If the \a name is not a valid printer then no change will be made. |
741 | |
742 | If the \a name is a valid printer then the output format will be set to NativeFormat. |
743 | |
744 | \sa printerName(), isValid(), setOutputFormat() |
745 | */ |
746 | void QPrinter::setPrinterName(const QString &name) |
747 | { |
748 | Q_D(QPrinter); |
749 | ABORT_IF_ACTIVE("QPrinter::setPrinterName" ); |
750 | |
751 | if (printerName() == name) |
752 | return; |
753 | |
754 | if (name.isEmpty()) { |
755 | setOutputFormat(QPrinter::PdfFormat); |
756 | return; |
757 | } |
758 | |
759 | QPrinterInfo printerToUse = QPrinterInfo::printerInfo(printerName: name); |
760 | if (printerToUse.isNull()) |
761 | return; |
762 | |
763 | if (outputFormat() == QPrinter::PdfFormat) { |
764 | d->changeEngines(format: QPrinter::NativeFormat, printer: printerToUse); |
765 | } else { |
766 | d->setProperty(key: QPrintEngine::PPK_PrinterName, value: name); |
767 | } |
768 | } |
769 | |
770 | /*! |
771 | \since 4.4 |
772 | |
773 | Returns \c true if the printer currently selected is a valid printer |
774 | in the system, or a pure PDF printer; otherwise returns \c false. |
775 | |
776 | To detect other failures check the output of QPainter::begin() or QPrinter::newPage(). |
777 | |
778 | \snippet printing-qprinter/errors.cpp 0 |
779 | |
780 | \sa setPrinterName() |
781 | */ |
782 | bool QPrinter::isValid() const |
783 | { |
784 | Q_D(const QPrinter); |
785 | if (!qApp) |
786 | return false; |
787 | return d->validPrinter; |
788 | } |
789 | |
790 | /*! |
791 | \fn QString QPrinter::outputFileName() const |
792 | |
793 | Returns the name of the output file. By default, this is an empty string |
794 | (indicating that the printer shouldn't print to file). |
795 | |
796 | \sa QPrintEngine::PrintEnginePropertyKey |
797 | |
798 | */ |
799 | |
800 | QString QPrinter::outputFileName() const |
801 | { |
802 | Q_D(const QPrinter); |
803 | return d->printEngine->property(key: QPrintEngine::PPK_OutputFileName).toString(); |
804 | } |
805 | |
806 | /*! |
807 | Sets the name of the output file to \a fileName. |
808 | |
809 | Setting a null or empty name (0 or "") disables printing to a file. |
810 | Setting a non-empty name enables printing to a file. |
811 | |
812 | This can change the value of outputFormat(). |
813 | If the file name has the ".pdf" suffix PDF is generated. If the file name |
814 | has a suffix other than ".pdf", the output format used is the |
815 | one set with setOutputFormat(). |
816 | |
817 | QPrinter uses Qt's cross-platform PDF print engines |
818 | respectively. If you can produce this format natively, for example |
819 | \macos can generate PDF's from its print engine, set the output format |
820 | back to NativeFormat. |
821 | |
822 | \sa outputFileName(), setOutputFormat() |
823 | */ |
824 | |
825 | void QPrinter::setOutputFileName(const QString &fileName) |
826 | { |
827 | Q_D(QPrinter); |
828 | ABORT_IF_ACTIVE("QPrinter::setOutputFileName" ); |
829 | |
830 | QFileInfo fi(fileName); |
831 | if (!fi.suffix().compare(other: QLatin1String("pdf" ), cs: Qt::CaseInsensitive)) |
832 | setOutputFormat(QPrinter::PdfFormat); |
833 | else if (fileName.isEmpty()) |
834 | setOutputFormat(QPrinter::NativeFormat); |
835 | |
836 | d->setProperty(key: QPrintEngine::PPK_OutputFileName, value: fileName); |
837 | } |
838 | |
839 | |
840 | /*! |
841 | Returns the name of the program that sends the print output to the |
842 | printer. |
843 | |
844 | The default is to return an empty string; meaning that QPrinter will try to |
845 | be smart in a system-dependent way. On X11 only, you can set it to something |
846 | different to use a specific print program. On the other platforms, this |
847 | returns an empty string. |
848 | |
849 | \sa setPrintProgram(), setPrinterSelectionOption() |
850 | */ |
851 | QString QPrinter::printProgram() const |
852 | { |
853 | Q_D(const QPrinter); |
854 | return d->printEngine->property(key: QPrintEngine::PPK_PrinterProgram).toString(); |
855 | } |
856 | |
857 | |
858 | /*! |
859 | Sets the name of the program that should do the print job to \a |
860 | printProg. |
861 | |
862 | On X11, this function sets the program to call with the PDF |
863 | output. On other platforms, it has no effect. |
864 | |
865 | \sa printProgram() |
866 | */ |
867 | void QPrinter::setPrintProgram(const QString &printProg) |
868 | { |
869 | Q_D(QPrinter); |
870 | ABORT_IF_ACTIVE("QPrinter::setPrintProgram" ); |
871 | d->setProperty(key: QPrintEngine::PPK_PrinterProgram, value: printProg); |
872 | } |
873 | |
874 | |
875 | /*! |
876 | Returns the document name. |
877 | |
878 | \sa setDocName(), QPrintEngine::PrintEnginePropertyKey |
879 | */ |
880 | QString QPrinter::docName() const |
881 | { |
882 | Q_D(const QPrinter); |
883 | return d->printEngine->property(key: QPrintEngine::PPK_DocumentName).toString(); |
884 | } |
885 | |
886 | |
887 | /*! |
888 | Sets the document name to \a name. |
889 | |
890 | On X11, the document name is for example used as the default |
891 | output filename in QPrintDialog. Note that the document name does |
892 | not affect the file name if the printer is printing to a file. |
893 | Use the setOutputFile() function for this. |
894 | |
895 | \sa docName(), QPrintEngine::PrintEnginePropertyKey |
896 | */ |
897 | void QPrinter::setDocName(const QString &name) |
898 | { |
899 | Q_D(QPrinter); |
900 | ABORT_IF_ACTIVE("QPrinter::setDocName" ); |
901 | d->setProperty(key: QPrintEngine::PPK_DocumentName, value: name); |
902 | } |
903 | |
904 | |
905 | /*! |
906 | Returns the name of the application that created the document. |
907 | |
908 | \sa setCreator() |
909 | */ |
910 | QString QPrinter::creator() const |
911 | { |
912 | Q_D(const QPrinter); |
913 | return d->printEngine->property(key: QPrintEngine::PPK_Creator).toString(); |
914 | } |
915 | |
916 | |
917 | /*! |
918 | Sets the name of the application that created the document to \a |
919 | creator. |
920 | |
921 | This function is only applicable to the X11 version of Qt. If no |
922 | creator name is specified, the creator will be set to "Qt" |
923 | followed by some version number. |
924 | |
925 | \sa creator() |
926 | */ |
927 | void QPrinter::setCreator(const QString &creator) |
928 | { |
929 | Q_D(QPrinter); |
930 | ABORT_IF_ACTIVE("QPrinter::setCreator" ); |
931 | d->setProperty(key: QPrintEngine::PPK_Creator, value: creator); |
932 | } |
933 | |
934 | // Defined in QPagedPaintDevice but non-virtual, add QPrinter specific doc here |
935 | #ifdef Q_CLANG_QDOC |
936 | /*! |
937 | \fn bool QPrinter::setPageLayout(const QPageLayout &newLayout) |
938 | \since 5.3 |
939 | |
940 | Sets the page layout to \a newLayout. |
941 | |
942 | If the \a newLayout is not valid for the current printer then the page |
943 | layout will not be changed. For example, if the page size is not supported |
944 | by the printer, or if the margins fall outside the printable area. |
945 | |
946 | Returns true if the page layout was successfully set to \a newLayout. |
947 | |
948 | \sa pageLayout(), setPageSize(), setPageOrientation(), setPageMargins() |
949 | */ |
950 | |
951 | /*! |
952 | \fn bool QPrinter::setPageSize(const QPageSize &pageSize) |
953 | \since 5.3 |
954 | |
955 | Sets the page size to \a pageSize. |
956 | |
957 | If the \a pageSize is not valid for the current printer then the page |
958 | size will not be changed. |
959 | |
960 | Changing the page size may affect the current page margins if they fall |
961 | outside the printable margins for the new page size on the current printer. |
962 | |
963 | To obtain the current QPageSize use pageLayout().pageSize(). |
964 | |
965 | Returns true if the page size was successfully set to \a pageSize. |
966 | |
967 | \sa pageLayout(), setPageLayout() |
968 | */ |
969 | |
970 | /*! |
971 | \fn bool QPrinter::setPageOrientation(QPageLayout::Orientation orientation) |
972 | \since 5.3 |
973 | |
974 | Sets the page \a orientation to QPageLayout::Portrait or QPageLayout::Landscape. |
975 | |
976 | The printer driver reads this setting and prints the page using the |
977 | specified orientation. |
978 | |
979 | On Windows and Mac, this option can be changed while printing and will |
980 | take effect from the next call to newPage(). |
981 | |
982 | To obtain the current QPageLayout::Orientation use pageLayout().orientation(). |
983 | |
984 | Returns true if the page orientation was successfully set to \a orientation. |
985 | |
986 | \sa pageLayout(), setPageLayout() |
987 | */ |
988 | |
989 | /*! |
990 | \fn bool QPrinter::setPageMargins(const QMarginsF &margins, QPageLayout::Unit units) |
991 | \since 5.3 |
992 | |
993 | Set the page margins to \a margins in the given \a units. If \a units are |
994 | not provided then the current units are used. |
995 | |
996 | If in Full Page mode then no check is performed on the \a margins set, |
997 | otherwise the \a margins must fall within the printable area for the page |
998 | size on the current printer. |
999 | |
1000 | To obtain the current page margins use pageLayout().margins(). |
1001 | |
1002 | Returns \c true if the page margins was successfully set to \a margins. |
1003 | |
1004 | \sa pageLayout(), setPageLayout() |
1005 | */ |
1006 | |
1007 | /*! |
1008 | \fn bool QPrinter::setPageMargins(const QMarginsF &margins) |
1009 | |
1010 | Set the page margins to \a margins using the current units. |
1011 | Returns \c true if the page margins were set successfully. |
1012 | |
1013 | \sa pageLayout(), setPageLayout() |
1014 | */ |
1015 | /*! |
1016 | \fn QPageLayout QPrinter::pageLayout() const |
1017 | \since 5.3 |
1018 | |
1019 | Returns the current page layout. Use this method to access the current |
1020 | QPageSize, QPageLayout::Orientation, QMarginsF, fullPageRect() and paintRect(). |
1021 | |
1022 | Note that you cannot use the setters on the returned object, you must either |
1023 | call the QPrinter methods or setPageLayout(). |
1024 | |
1025 | \sa setPageLayout(), setPageSize(), setPageOrientation(), setPageMargins() |
1026 | */ |
1027 | #endif |
1028 | |
1029 | /*! |
1030 | \obsolete Use pageLayout().orientation() instead. |
1031 | |
1032 | Returns the orientation setting. This is driver-dependent, but is usually |
1033 | QPrinter::Portrait. |
1034 | |
1035 | \sa pageLayout() |
1036 | */ |
1037 | QPrinter::Orientation QPrinter::orientation() const |
1038 | { |
1039 | return QPrinter::Orientation(pageLayout().orientation()); |
1040 | } |
1041 | |
1042 | |
1043 | /*! |
1044 | \obsolete Use setPageOrientation() instead. |
1045 | |
1046 | Sets the print orientation to \a orientation. |
1047 | |
1048 | The orientation can be either QPrinter::Portrait or |
1049 | QPrinter::Landscape. |
1050 | |
1051 | The printer driver reads this setting and prints using the |
1052 | specified orientation. |
1053 | |
1054 | On Windows and Mac, this option can be changed while printing and will |
1055 | take effect from the next call to newPage(). |
1056 | |
1057 | \sa setPageOrientation() |
1058 | */ |
1059 | |
1060 | void QPrinter::setOrientation(Orientation orientation) |
1061 | { |
1062 | setPageOrientation(QPageLayout::Orientation(orientation)); |
1063 | } |
1064 | |
1065 | /*! |
1066 | \since 4.4 |
1067 | |
1068 | \obsolete Use pageLayout().pageSize().id() instead. |
1069 | |
1070 | Returns the printer paper size. The default value is driver-dependent. |
1071 | |
1072 | \sa pageLayout() |
1073 | */ |
1074 | |
1075 | QPrinter::PaperSize QPrinter::paperSize() const |
1076 | { |
1077 | return pageSize(); |
1078 | } |
1079 | |
1080 | /*! |
1081 | \since 4.4 |
1082 | |
1083 | \obsolete Use setPageSize(QPageSize) instead. |
1084 | |
1085 | Sets the printer paper size to \a newPaperSize if that size is |
1086 | supported. The result is undefined if \a newPaperSize is not |
1087 | supported. |
1088 | |
1089 | The default paper size is driver-dependent. |
1090 | |
1091 | This function is useful mostly for setting a default value that |
1092 | the user can override in the print dialog. |
1093 | |
1094 | \sa setPageSize() |
1095 | */ |
1096 | void QPrinter::setPaperSize(PaperSize newPaperSize) |
1097 | { |
1098 | setPageSize(QPageSize(QPageSize::PageSizeId(newPaperSize))); |
1099 | } |
1100 | |
1101 | /*! |
1102 | \obsolete Use pageLayout().pageSize().id() instead. |
1103 | |
1104 | Returns the printer page size. The default value is driver-dependent. |
1105 | |
1106 | \sa pageLayout() |
1107 | */ |
1108 | QPrinter::PageSize QPrinter::pageSize() const |
1109 | { |
1110 | return QPrinter::PaperSize(pageLayout().pageSize().id()); |
1111 | } |
1112 | |
1113 | |
1114 | /*! |
1115 | \obsolete Use setPageSize(QPageSize) instead. |
1116 | |
1117 | Sets the printer page size based on \a newPageSize. |
1118 | |
1119 | \sa setPageSize() |
1120 | */ |
1121 | |
1122 | void QPrinter::setPageSize(PageSize newPageSize) |
1123 | { |
1124 | setPageSize(QPageSize(QPageSize::PageSizeId(newPageSize))); |
1125 | } |
1126 | |
1127 | /*! |
1128 | \since 4.4 |
1129 | |
1130 | \obsolete Use setPageSize(QPageSize) instead. |
1131 | |
1132 | Sets the paper size based on \a paperSize in \a unit. |
1133 | |
1134 | Note that the paper size is defined in a portrait layout, regardless of |
1135 | what the current printer orientation is set to. |
1136 | |
1137 | \sa setPageSize() |
1138 | */ |
1139 | |
1140 | void QPrinter::setPaperSize(const QSizeF &paperSize, QPrinter::Unit unit) |
1141 | { |
1142 | if (unit == QPrinter::DevicePixel) |
1143 | setPageSize(QPageSize(paperSize * qt_pixelMultiplier(resolution: resolution()), QPageSize::Point)); |
1144 | else |
1145 | setPageSize(QPageSize(paperSize, QPageSize::Unit(unit))); |
1146 | } |
1147 | |
1148 | /*! |
1149 | \reimp |
1150 | |
1151 | \obsolete Use setPageSize(QPageSize) instead. |
1152 | |
1153 | Use setPageSize(QPageSize) instead. |
1154 | |
1155 | Note that the page size is defined in a portrait layout, regardless of |
1156 | what the current printer orientation is set to. |
1157 | |
1158 | \sa setPageSize() |
1159 | */ |
1160 | void QPrinter::setPageSizeMM(const QSizeF &size) |
1161 | { |
1162 | setPageSize(QPageSize(size, QPageSize::Millimeter)); |
1163 | } |
1164 | |
1165 | /*! |
1166 | \since 4.4 |
1167 | |
1168 | \obsolete Use pageLayout().pageSize().size() or |
1169 | pageLayout().fullPageSize() instead. |
1170 | |
1171 | Returns the paper size in \a unit. |
1172 | |
1173 | Note that the returned size reflects the current paper orientation. |
1174 | |
1175 | \sa pageLayout() |
1176 | */ |
1177 | |
1178 | QSizeF QPrinter::paperSize(Unit unit) const |
1179 | { |
1180 | if (unit == QPrinter::DevicePixel) |
1181 | return pageLayout().fullRectPixels(resolution: resolution()).size(); |
1182 | else |
1183 | return pageLayout().fullRect(units: QPageLayout::Unit(unit)).size(); |
1184 | } |
1185 | |
1186 | /*! |
1187 | \since 5.1 |
1188 | |
1189 | \obsolete Use setPageSize(QPageSize) instead. |
1190 | |
1191 | Sets the paper used by the printer to \a paperName. |
1192 | |
1193 | \sa setPageSize() |
1194 | */ |
1195 | |
1196 | void QPrinter::setPaperName(const QString &paperName) |
1197 | { |
1198 | Q_D(QPrinter); |
1199 | if (d->paintEngine->type() != QPaintEngine::Pdf) |
1200 | ABORT_IF_ACTIVE("QPrinter::setPaperName" ); |
1201 | d->setProperty(key: QPrintEngine::PPK_PaperName, value: paperName); |
1202 | } |
1203 | |
1204 | /*! |
1205 | \since 5.1 |
1206 | |
1207 | \obsolete Use pageLayout().pageSize().name() instead. |
1208 | |
1209 | Returns the paper name of the paper set on the printer. |
1210 | |
1211 | The default value for this is driver-dependent. |
1212 | |
1213 | \sa pageLayout() |
1214 | */ |
1215 | |
1216 | QString QPrinter::paperName() const |
1217 | { |
1218 | Q_D(const QPrinter); |
1219 | return d->printEngine->property(key: QPrintEngine::PPK_PaperName).toString(); |
1220 | } |
1221 | |
1222 | /*! |
1223 | Sets the page order to \a pageOrder. |
1224 | |
1225 | The page order can be QPrinter::FirstPageFirst or |
1226 | QPrinter::LastPageFirst. The application is responsible for |
1227 | reading the page order and printing accordingly. |
1228 | |
1229 | This function is mostly useful for setting a default value that |
1230 | the user can override in the print dialog. |
1231 | |
1232 | This function is only supported under X11. |
1233 | */ |
1234 | |
1235 | void QPrinter::setPageOrder(PageOrder pageOrder) |
1236 | { |
1237 | d->pageOrderAscending = (pageOrder == FirstPageFirst); |
1238 | |
1239 | Q_D(QPrinter); |
1240 | ABORT_IF_ACTIVE("QPrinter::setPageOrder" ); |
1241 | d->setProperty(key: QPrintEngine::PPK_PageOrder, value: pageOrder); |
1242 | } |
1243 | |
1244 | |
1245 | /*! |
1246 | Returns the current page order. |
1247 | |
1248 | The default page order is \c FirstPageFirst. |
1249 | */ |
1250 | |
1251 | QPrinter::PageOrder QPrinter::pageOrder() const |
1252 | { |
1253 | Q_D(const QPrinter); |
1254 | return QPrinter::PageOrder(d->printEngine->property(key: QPrintEngine::PPK_PageOrder).toInt()); |
1255 | } |
1256 | |
1257 | |
1258 | /*! |
1259 | Sets the printer's color mode to \a newColorMode, which can be |
1260 | either \c Color or \c GrayScale. |
1261 | |
1262 | \sa colorMode() |
1263 | */ |
1264 | |
1265 | void QPrinter::setColorMode(ColorMode newColorMode) |
1266 | { |
1267 | Q_D(QPrinter); |
1268 | ABORT_IF_ACTIVE("QPrinter::setColorMode" ); |
1269 | d->setProperty(key: QPrintEngine::PPK_ColorMode, value: newColorMode); |
1270 | } |
1271 | |
1272 | |
1273 | /*! |
1274 | Returns the current color mode. |
1275 | |
1276 | \sa setColorMode() |
1277 | */ |
1278 | QPrinter::ColorMode QPrinter::colorMode() const |
1279 | { |
1280 | Q_D(const QPrinter); |
1281 | return QPrinter::ColorMode(d->printEngine->property(key: QPrintEngine::PPK_ColorMode).toInt()); |
1282 | } |
1283 | |
1284 | |
1285 | /*! |
1286 | \obsolete |
1287 | Returns the number of copies to be printed. The default value is 1. |
1288 | |
1289 | On Windows, \macos and X11 systems that support CUPS, this will always |
1290 | return 1 as these operating systems can internally handle the number |
1291 | of copies. |
1292 | |
1293 | On X11, this value will return the number of times the application is |
1294 | required to print in order to match the number specified in the printer setup |
1295 | dialog. This has been done since some printer drivers are not capable of |
1296 | buffering up the copies and in those cases the application must make an |
1297 | explicit call to the print code for each copy. |
1298 | |
1299 | Use copyCount() in conjunction with supportsMultipleCopies() instead. |
1300 | |
1301 | \sa setNumCopies(), actualNumCopies() |
1302 | */ |
1303 | |
1304 | int QPrinter::numCopies() const |
1305 | { |
1306 | Q_D(const QPrinter); |
1307 | return d->printEngine->property(key: QPrintEngine::PPK_NumberOfCopies).toInt(); |
1308 | } |
1309 | |
1310 | |
1311 | /*! |
1312 | \obsolete |
1313 | \since 4.6 |
1314 | |
1315 | Returns the number of copies that will be printed. The default |
1316 | value is 1. |
1317 | |
1318 | This function always returns the actual value specified in the print |
1319 | dialog or using setNumCopies(). |
1320 | |
1321 | Use copyCount() instead. |
1322 | |
1323 | \sa setNumCopies(), numCopies() |
1324 | */ |
1325 | int QPrinter::actualNumCopies() const |
1326 | { |
1327 | return copyCount(); |
1328 | } |
1329 | |
1330 | |
1331 | |
1332 | /*! |
1333 | \obsolete |
1334 | Sets the number of copies to be printed to \a numCopies. |
1335 | |
1336 | The printer driver reads this setting and prints the specified |
1337 | number of copies. |
1338 | |
1339 | Use setCopyCount() instead. |
1340 | |
1341 | \sa numCopies() |
1342 | */ |
1343 | |
1344 | void QPrinter::setNumCopies(int numCopies) |
1345 | { |
1346 | Q_D(QPrinter); |
1347 | ABORT_IF_ACTIVE("QPrinter::setNumCopies" ); |
1348 | d->setProperty(key: QPrintEngine::PPK_NumberOfCopies, value: numCopies); |
1349 | } |
1350 | |
1351 | /*! |
1352 | \since 4.7 |
1353 | |
1354 | Sets the number of copies to be printed to \a count. |
1355 | |
1356 | The printer driver reads this setting and prints the specified number of |
1357 | copies. |
1358 | |
1359 | \sa copyCount(), supportsMultipleCopies() |
1360 | */ |
1361 | |
1362 | void QPrinter::setCopyCount(int count) |
1363 | { |
1364 | Q_D(QPrinter); |
1365 | ABORT_IF_ACTIVE("QPrinter::setCopyCount;" ); |
1366 | d->setProperty(key: QPrintEngine::PPK_CopyCount, value: count); |
1367 | } |
1368 | |
1369 | /*! |
1370 | \since 4.7 |
1371 | |
1372 | Returns the number of copies that will be printed. The default value is 1. |
1373 | |
1374 | \sa setCopyCount(), supportsMultipleCopies() |
1375 | */ |
1376 | |
1377 | int QPrinter::copyCount() const |
1378 | { |
1379 | Q_D(const QPrinter); |
1380 | return d->printEngine->property(key: QPrintEngine::PPK_CopyCount).toInt(); |
1381 | } |
1382 | |
1383 | /*! |
1384 | \since 4.7 |
1385 | |
1386 | Returns \c true if the printer supports printing multiple copies of the same |
1387 | document in one job; otherwise false is returned. |
1388 | |
1389 | On most systems this function will return true. However, on X11 systems |
1390 | that do not support CUPS, this function will return false. That means the |
1391 | application has to handle the number of copies by printing the same |
1392 | document the required number of times. |
1393 | |
1394 | \sa setCopyCount(), copyCount() |
1395 | */ |
1396 | |
1397 | bool QPrinter::supportsMultipleCopies() const |
1398 | { |
1399 | Q_D(const QPrinter); |
1400 | return d->printEngine->property(key: QPrintEngine::PPK_SupportsMultipleCopies).toBool(); |
1401 | } |
1402 | |
1403 | /*! |
1404 | \since 4.1 |
1405 | |
1406 | Returns \c true if collation is turned on when multiple copies is selected. |
1407 | Returns \c false if it is turned off when multiple copies is selected. |
1408 | When collating is turned off the printing of each individual page will be repeated |
1409 | the numCopies() amount before the next page is started. With collating turned on |
1410 | all pages are printed before the next copy of those pages is started. |
1411 | |
1412 | \sa setCollateCopies() |
1413 | */ |
1414 | bool QPrinter::collateCopies() const |
1415 | { |
1416 | Q_D(const QPrinter); |
1417 | return d->printEngine->property(key: QPrintEngine::PPK_CollateCopies).toBool(); |
1418 | } |
1419 | |
1420 | |
1421 | /*! |
1422 | \since 4.1 |
1423 | |
1424 | Sets the default value for collation checkbox when the print |
1425 | dialog appears. If \a collate is true, it will enable |
1426 | setCollateCopiesEnabled(). The default value is false. This value |
1427 | will be changed by what the user presses in the print dialog. |
1428 | |
1429 | \sa collateCopies() |
1430 | */ |
1431 | void QPrinter::setCollateCopies(bool collate) |
1432 | { |
1433 | Q_D(QPrinter); |
1434 | ABORT_IF_ACTIVE("QPrinter::setCollateCopies" ); |
1435 | d->setProperty(key: QPrintEngine::PPK_CollateCopies, value: collate); |
1436 | } |
1437 | |
1438 | |
1439 | |
1440 | /*! |
1441 | If \a fp is true, enables support for painting over the entire page; |
1442 | otherwise restricts painting to the printable area reported by the |
1443 | device. |
1444 | |
1445 | By default, full page printing is disabled. In this case, the origin |
1446 | of the QPrinter's coordinate system coincides with the top-left |
1447 | corner of the printable area. |
1448 | |
1449 | If full page printing is enabled, the origin of the QPrinter's |
1450 | coordinate system coincides with the top-left corner of the paper |
1451 | itself. In this case, the |
1452 | \l{QPaintDevice::PaintDeviceMetric}{device metrics} will report |
1453 | the exact same dimensions as indicated by \l{PaperSize}. It may not |
1454 | be possible to print on the entire physical page because of the |
1455 | printer's margins, so the application must account for the margins |
1456 | itself. |
1457 | |
1458 | \sa fullPage(), pageLayout(), setPageSize(), width(), height() |
1459 | */ |
1460 | |
1461 | void QPrinter::setFullPage(bool fp) |
1462 | { |
1463 | Q_D(QPrinter); |
1464 | // Set the print engine |
1465 | d->setProperty(key: QPrintEngine::PPK_FullPage, value: fp); |
1466 | } |
1467 | |
1468 | |
1469 | /*! |
1470 | Returns \c true if the origin of the printer's coordinate system is |
1471 | at the corner of the page and false if it is at the edge of the |
1472 | printable area. |
1473 | |
1474 | See setFullPage() for details and caveats. |
1475 | |
1476 | \sa setFullPage(), pageLayout() |
1477 | */ |
1478 | |
1479 | bool QPrinter::fullPage() const |
1480 | { |
1481 | Q_D(const QPrinter); |
1482 | return d->printEngine->property(key: QPrintEngine::PPK_FullPage).toBool(); |
1483 | } |
1484 | |
1485 | |
1486 | /*! |
1487 | Requests that the printer prints at \a dpi or as near to \a dpi as |
1488 | possible. |
1489 | |
1490 | This setting affects the coordinate system as returned by, for |
1491 | example QPainter::viewport(). |
1492 | |
1493 | This function must be called before QPainter::begin() to have an effect on |
1494 | all platforms. |
1495 | |
1496 | \sa resolution(), setPaperSize() |
1497 | */ |
1498 | |
1499 | void QPrinter::setResolution(int dpi) |
1500 | { |
1501 | Q_D(QPrinter); |
1502 | ABORT_IF_ACTIVE("QPrinter::setResolution" ); |
1503 | d->setProperty(key: QPrintEngine::PPK_Resolution, value: dpi); |
1504 | } |
1505 | |
1506 | |
1507 | /*! |
1508 | Returns the current assumed resolution of the printer, as set by |
1509 | setResolution() or by the printer driver. |
1510 | |
1511 | \sa setResolution() |
1512 | */ |
1513 | |
1514 | int QPrinter::resolution() const |
1515 | { |
1516 | Q_D(const QPrinter); |
1517 | return d->printEngine->property(key: QPrintEngine::PPK_Resolution).toInt(); |
1518 | } |
1519 | |
1520 | /*! |
1521 | Sets the paper source setting to \a source. |
1522 | |
1523 | Windows only: This option can be changed while printing and will |
1524 | take effect from the next call to newPage() |
1525 | |
1526 | \sa paperSource() |
1527 | */ |
1528 | |
1529 | void QPrinter::setPaperSource(PaperSource source) |
1530 | { |
1531 | Q_D(QPrinter); |
1532 | d->setProperty(key: QPrintEngine::PPK_PaperSource, value: source); |
1533 | } |
1534 | |
1535 | /*! |
1536 | Returns the printer's paper source. This is \c Manual or a printer |
1537 | tray or paper cassette. |
1538 | */ |
1539 | QPrinter::PaperSource QPrinter::paperSource() const |
1540 | { |
1541 | Q_D(const QPrinter); |
1542 | return QPrinter::PaperSource(d->printEngine->property(key: QPrintEngine::PPK_PaperSource).toInt()); |
1543 | } |
1544 | |
1545 | |
1546 | /*! |
1547 | \since 4.1 |
1548 | |
1549 | Enabled or disables font embedding depending on \a enable. |
1550 | |
1551 | \sa fontEmbeddingEnabled() |
1552 | */ |
1553 | void QPrinter::setFontEmbeddingEnabled(bool enable) |
1554 | { |
1555 | Q_D(QPrinter); |
1556 | d->setProperty(key: QPrintEngine::PPK_FontEmbedding, value: enable); |
1557 | } |
1558 | |
1559 | /*! |
1560 | \since 4.1 |
1561 | |
1562 | Returns \c true if font embedding is enabled. |
1563 | |
1564 | \sa setFontEmbeddingEnabled() |
1565 | */ |
1566 | bool QPrinter::fontEmbeddingEnabled() const |
1567 | { |
1568 | Q_D(const QPrinter); |
1569 | return d->printEngine->property(key: QPrintEngine::PPK_FontEmbedding).toBool(); |
1570 | } |
1571 | |
1572 | /*! |
1573 | \enum QPrinter::DuplexMode |
1574 | \since 4.4 |
1575 | |
1576 | This enum is used to indicate whether printing will occur on one or both sides |
1577 | of each sheet of paper (simplex or duplex printing). |
1578 | |
1579 | \value DuplexNone Single sided (simplex) printing only. |
1580 | \value DuplexAuto The printer's default setting is used to determine whether |
1581 | duplex printing is used. |
1582 | \value DuplexLongSide Both sides of each sheet of paper are used for printing. |
1583 | The paper is turned over its longest edge before the second |
1584 | side is printed |
1585 | \value DuplexShortSide Both sides of each sheet of paper are used for printing. |
1586 | The paper is turned over its shortest edge before the second |
1587 | side is printed |
1588 | */ |
1589 | |
1590 | /*! |
1591 | \since 4.2 |
1592 | |
1593 | \obsolete Use setDuplex() instead. |
1594 | |
1595 | Enables double sided printing if \a doubleSided is true; otherwise disables it. |
1596 | |
1597 | \sa setDuplex() |
1598 | */ |
1599 | void QPrinter::setDoubleSidedPrinting(bool doubleSided) |
1600 | { |
1601 | setDuplex(doubleSided ? DuplexAuto : DuplexNone); |
1602 | } |
1603 | |
1604 | |
1605 | /*! |
1606 | \since 4.2 |
1607 | |
1608 | \obsolete Use duplex() instead. |
1609 | |
1610 | Returns \c true if double side printing is enabled. |
1611 | |
1612 | \sa duplex() |
1613 | */ |
1614 | bool QPrinter::doubleSidedPrinting() const |
1615 | { |
1616 | return duplex() != DuplexNone; |
1617 | } |
1618 | |
1619 | /*! |
1620 | \since 4.4 |
1621 | |
1622 | Enables double sided printing based on the \a duplex mode. |
1623 | |
1624 | \sa duplex() |
1625 | */ |
1626 | void QPrinter::setDuplex(DuplexMode duplex) |
1627 | { |
1628 | Q_D(QPrinter); |
1629 | d->setProperty(key: QPrintEngine::PPK_Duplex, value: duplex); |
1630 | } |
1631 | |
1632 | /*! |
1633 | \since 4.4 |
1634 | |
1635 | Returns the current duplex mode. |
1636 | |
1637 | \sa setDuplex() |
1638 | */ |
1639 | QPrinter::DuplexMode QPrinter::duplex() const |
1640 | { |
1641 | Q_D(const QPrinter); |
1642 | return static_cast <DuplexMode> (d->printEngine->property(key: QPrintEngine::PPK_Duplex).toInt()); |
1643 | } |
1644 | |
1645 | /*! |
1646 | \since 4.4 |
1647 | |
1648 | Returns the page's rectangle in \a unit; this is usually smaller |
1649 | than the paperRect() since the page normally has margins between |
1650 | its borders and the paper. |
1651 | |
1652 | \sa paperSize() |
1653 | */ |
1654 | QRectF QPrinter::(Unit unit) const |
1655 | { |
1656 | if (unit == QPrinter::DevicePixel) |
1657 | return pageLayout().paintRectPixels(resolution: resolution()); |
1658 | else |
1659 | return pageLayout().paintRect(units: QPageLayout::Unit(unit)); |
1660 | } |
1661 | |
1662 | |
1663 | /*! |
1664 | \since 4.4 |
1665 | |
1666 | Returns the paper's rectangle in \a unit; this is usually larger |
1667 | than the pageRect(). |
1668 | |
1669 | \sa pageRect() |
1670 | */ |
1671 | QRectF QPrinter::paperRect(Unit unit) const |
1672 | { |
1673 | if (unit == QPrinter::DevicePixel) |
1674 | return pageLayout().fullRectPixels(resolution: resolution()); |
1675 | else |
1676 | return pageLayout().fullRect(units: QPageLayout::Unit(unit)); |
1677 | } |
1678 | |
1679 | /*! |
1680 | \obsolete Use pageLayout().paintRectPixels(resolution()) instead. |
1681 | |
1682 | Returns the page's rectangle; this is usually smaller than the |
1683 | paperRect() since the page normally has margins between its |
1684 | borders and the paper. |
1685 | |
1686 | The unit of the returned rectangle is DevicePixel. |
1687 | |
1688 | \sa pageLayout() |
1689 | */ |
1690 | QRect QPrinter::() const |
1691 | { |
1692 | Q_D(const QPrinter); |
1693 | return d->printEngine->property(key: QPrintEngine::PPK_PageRect).toRect(); |
1694 | } |
1695 | |
1696 | /*! |
1697 | \obsolete Use pageLayout().fullRectPixels(resolution()) instead. |
1698 | |
1699 | Returns the paper's rectangle; this is usually larger than the |
1700 | pageRect(). |
1701 | |
1702 | The unit of the returned rectangle is DevicePixel. |
1703 | |
1704 | \sa pageLayout() |
1705 | */ |
1706 | QRect QPrinter::paperRect() const |
1707 | { |
1708 | Q_D(const QPrinter); |
1709 | return d->printEngine->property(key: QPrintEngine::PPK_PaperRect).toRect(); |
1710 | } |
1711 | |
1712 | /*! |
1713 | \since 4.4 |
1714 | |
1715 | \obsolete Use setPageMargins(QMarginsF, QPageLayout::Unit) instead. |
1716 | |
1717 | This function sets the \a left, \a top, \a right and \a bottom |
1718 | page margins for this printer. The unit of the margins are |
1719 | specified with the \a unit parameter. |
1720 | |
1721 | \sa setPageMargins() |
1722 | */ |
1723 | void QPrinter::setPageMargins(qreal left, qreal top, qreal right, qreal bottom, QPrinter::Unit unit) |
1724 | { |
1725 | if (unit == QPrinter::DevicePixel) { |
1726 | QMarginsF margins = QMarginsF(left, top, right, bottom); |
1727 | margins *= qt_pixelMultiplier(resolution: resolution()); |
1728 | margins = qt_convertMargins(margins, fromUnits: QPageLayout::Point, toUnits: pageLayout().units()); |
1729 | setPageMargins(margins, units: pageLayout().units()); |
1730 | } else { |
1731 | setPageMargins(margins: QMarginsF(left, top, right, bottom), units: QPageLayout::Unit(unit)); |
1732 | } |
1733 | } |
1734 | |
1735 | /*! |
1736 | \reimp |
1737 | |
1738 | \obsolete Use setPageMargins(QMarginsF, QPageLayout::Unit) instead. |
1739 | |
1740 | \sa setPageMargins() |
1741 | */ |
1742 | void QPrinter::setMargins(const Margins &m) |
1743 | { |
1744 | setPageMargins(margins: QMarginsF(m.left, m.top, m.right, m.bottom), units: QPageLayout::Millimeter); |
1745 | } |
1746 | |
1747 | /*! |
1748 | \since 4.4 |
1749 | |
1750 | \obsolete Use pageLayout().margins() instead. |
1751 | |
1752 | Returns the page margins for this printer in \a left, \a top, \a |
1753 | right, \a bottom. The unit of the returned margins are specified |
1754 | with the \a unit parameter. |
1755 | |
1756 | \sa pageLayout(), setPageMargins() |
1757 | */ |
1758 | void QPrinter::getPageMargins(qreal *left, qreal *top, qreal *right, qreal *bottom, QPrinter::Unit unit) const |
1759 | { |
1760 | QMarginsF margins; |
1761 | if (unit == QPrinter::DevicePixel) { |
1762 | QMargins tmp = pageLayout().marginsPixels(resolution: resolution()); |
1763 | margins = QMarginsF(tmp.left(), tmp.top(), tmp.right(), tmp.bottom()); |
1764 | } else { |
1765 | margins = pageLayout().margins(units: QPageLayout::Unit(unit)); |
1766 | } |
1767 | if (left) |
1768 | *left = margins.left(); |
1769 | if (right) |
1770 | *right = margins.right(); |
1771 | if (top) |
1772 | *top = margins.top(); |
1773 | if (bottom) |
1774 | *bottom = margins.bottom(); |
1775 | } |
1776 | |
1777 | /*! |
1778 | \internal |
1779 | |
1780 | Returns the metric for the given \a id. |
1781 | */ |
1782 | int QPrinter::metric(PaintDeviceMetric id) const |
1783 | { |
1784 | Q_D(const QPrinter); |
1785 | return d->printEngine->metric(id); |
1786 | } |
1787 | |
1788 | /*! |
1789 | Returns the paint engine used by the printer. |
1790 | */ |
1791 | QPaintEngine *QPrinter::paintEngine() const |
1792 | { |
1793 | Q_D(const QPrinter); |
1794 | return d->paintEngine; |
1795 | } |
1796 | |
1797 | /*! |
1798 | \since 4.1 |
1799 | |
1800 | Returns the print engine used by the printer. |
1801 | */ |
1802 | QPrintEngine *QPrinter::printEngine() const |
1803 | { |
1804 | Q_D(const QPrinter); |
1805 | return d->printEngine; |
1806 | } |
1807 | |
1808 | /*! |
1809 | \obsolete Use QPageSize::id(windowsId) and setPageLayout(QPageSize) instead. |
1810 | |
1811 | Sets the page size to be used by the printer under Windows to \a |
1812 | pageSize. |
1813 | |
1814 | \sa pageLayout() |
1815 | */ |
1816 | void QPrinter::setWinPageSize(int pageSize) |
1817 | { |
1818 | Q_D(QPrinter); |
1819 | ABORT_IF_ACTIVE("QPrinter::setWinPageSize" ); |
1820 | d->setProperty(key: QPrintEngine::PPK_WindowsPageSize, value: pageSize); |
1821 | } |
1822 | |
1823 | /*! |
1824 | \obsolete Use pageLayout.pageSize().windowsId() instead. |
1825 | |
1826 | Returns the page size used by the printer under Windows. |
1827 | |
1828 | \sa pageLayout() |
1829 | */ |
1830 | int QPrinter::winPageSize() const |
1831 | { |
1832 | Q_D(const QPrinter); |
1833 | return d->printEngine->property(key: QPrintEngine::PPK_WindowsPageSize).toInt(); |
1834 | } |
1835 | |
1836 | /*! |
1837 | Returns a list of the resolutions (a list of dots-per-inch |
1838 | integers) that the printer says it supports. |
1839 | |
1840 | For X11 where all printing is directly to PDF, this |
1841 | function will always return a one item list containing only the |
1842 | PDF resolution, i.e., 72 (72 dpi -- but see PrinterMode). |
1843 | */ |
1844 | QList<int> QPrinter::supportedResolutions() const |
1845 | { |
1846 | Q_D(const QPrinter); |
1847 | const QList<QVariant> varlist |
1848 | = d->printEngine->property(key: QPrintEngine::PPK_SupportedResolutions).toList(); |
1849 | QList<int> intlist; |
1850 | intlist.reserve(alloc: varlist.size()); |
1851 | for (const auto &var : varlist) |
1852 | intlist << var.toInt(); |
1853 | return intlist; |
1854 | } |
1855 | |
1856 | /*! |
1857 | Tells the printer to eject the current page and to continue |
1858 | printing on a new page. Returns \c true if this was successful; |
1859 | otherwise returns \c false. |
1860 | |
1861 | Calling newPage() on an inactive QPrinter object will always |
1862 | fail. |
1863 | */ |
1864 | bool QPrinter::newPage() |
1865 | { |
1866 | Q_D(QPrinter); |
1867 | if (d->printEngine->printerState() != QPrinter::Active) |
1868 | return false; |
1869 | return d->printEngine->newPage(); |
1870 | } |
1871 | |
1872 | /*! |
1873 | Aborts the current print run. Returns \c true if the print run was |
1874 | successfully aborted and printerState() will return QPrinter::Aborted; otherwise |
1875 | returns \c false. |
1876 | |
1877 | It is not always possible to abort a print job. For example, |
1878 | all the data has gone to the printer but the printer cannot or |
1879 | will not cancel the job when asked to. |
1880 | */ |
1881 | bool QPrinter::abort() |
1882 | { |
1883 | Q_D(QPrinter); |
1884 | return d->printEngine->abort(); |
1885 | } |
1886 | |
1887 | /*! |
1888 | Returns the current state of the printer. This may not always be |
1889 | accurate (for example if the printer doesn't have the capability |
1890 | of reporting its state to the operating system). |
1891 | */ |
1892 | QPrinter::PrinterState QPrinter::printerState() const |
1893 | { |
1894 | Q_D(const QPrinter); |
1895 | return d->printEngine->printerState(); |
1896 | } |
1897 | |
1898 | #if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC) |
1899 | /*! |
1900 | Returns the supported paper sizes for this printer. |
1901 | |
1902 | The values will be either a value that matches an entry in the |
1903 | QPrinter::PaperSource enum or a driver spesific value. The driver |
1904 | spesific values are greater than the constant DMBIN_USER declared |
1905 | in wingdi.h. |
1906 | |
1907 | \warning This function is only available in windows. |
1908 | */ |
1909 | |
1910 | QList<QPrinter::PaperSource> QPrinter::supportedPaperSources() const |
1911 | { |
1912 | Q_D(const QPrinter); |
1913 | QVariant v = d->printEngine->property(QPrintEngine::PPK_PaperSources); |
1914 | |
1915 | const QList<QVariant> variant_list = v.toList(); |
1916 | QList<QPrinter::PaperSource> int_list; |
1917 | int_list.reserve(variant_list.size()); |
1918 | for (const auto &variant : variant_list) |
1919 | int_list << QPrinter::PaperSource(variant.toInt()); |
1920 | |
1921 | return int_list; |
1922 | } |
1923 | |
1924 | #endif // Q_OS_WIN |
1925 | |
1926 | /*! |
1927 | \fn QString QPrinter::printerSelectionOption() const |
1928 | |
1929 | Returns the printer options selection string. This is useful only |
1930 | if the print command has been explicitly set. |
1931 | |
1932 | The default value (an empty string) implies that the printer should |
1933 | be selected in a system-dependent manner. |
1934 | |
1935 | Any other value implies that the given value should be used. |
1936 | |
1937 | This function always returns an empty string on Windows and Mac. |
1938 | |
1939 | \sa setPrinterSelectionOption(), setPrintProgram() |
1940 | */ |
1941 | |
1942 | QString QPrinter::printerSelectionOption() const |
1943 | { |
1944 | Q_D(const QPrinter); |
1945 | return d->printEngine->property(key: QPrintEngine::PPK_SelectionOption).toString(); |
1946 | } |
1947 | |
1948 | /*! |
1949 | \fn void QPrinter::setPrinterSelectionOption(const QString &option) |
1950 | |
1951 | Sets the printer to use \a option to select the printer. \a option |
1952 | is null by default (which implies that Qt should be smart enough |
1953 | to guess correctly), but it can be set to other values to use a |
1954 | specific printer selection option. |
1955 | |
1956 | If the printer selection option is changed while the printer is |
1957 | active, the current print job may or may not be affected. |
1958 | |
1959 | This function has no effect on Windows or Mac. |
1960 | |
1961 | \sa printerSelectionOption(), setPrintProgram() |
1962 | */ |
1963 | |
1964 | void QPrinter::setPrinterSelectionOption(const QString &option) |
1965 | { |
1966 | Q_D(QPrinter); |
1967 | d->setProperty(key: QPrintEngine::PPK_SelectionOption, value: option); |
1968 | } |
1969 | |
1970 | /*! |
1971 | \since 4.1 |
1972 | \fn int QPrinter::fromPage() const |
1973 | |
1974 | Returns the number of the first page in a range of pages to be printed |
1975 | (the "from page" setting). Pages in a document are numbered according to |
1976 | the convention that the first page is page 1. |
1977 | |
1978 | By default, this function returns a special value of 0, meaning that |
1979 | the "from page" setting is unset. |
1980 | |
1981 | \note If fromPage() and toPage() both return 0, this indicates that |
1982 | \e{the whole document will be printed}. |
1983 | |
1984 | \sa setFromTo(), toPage() |
1985 | */ |
1986 | |
1987 | int QPrinter::fromPage() const |
1988 | { |
1989 | return d->fromPage; |
1990 | } |
1991 | |
1992 | /*! |
1993 | \since 4.1 |
1994 | |
1995 | Returns the number of the last page in a range of pages to be printed |
1996 | (the "to page" setting). Pages in a document are numbered according to |
1997 | the convention that the first page is page 1. |
1998 | |
1999 | By default, this function returns a special value of 0, meaning that |
2000 | the "to page" setting is unset. |
2001 | |
2002 | \note If fromPage() and toPage() both return 0, this indicates that |
2003 | \e{the whole document will be printed}. |
2004 | |
2005 | The programmer is responsible for reading this setting and |
2006 | printing accordingly. |
2007 | |
2008 | \sa setFromTo(), fromPage() |
2009 | */ |
2010 | |
2011 | int QPrinter::toPage() const |
2012 | { |
2013 | return d->toPage; |
2014 | } |
2015 | |
2016 | /*! |
2017 | \since 4.1 |
2018 | |
2019 | Sets the range of pages to be printed to cover the pages with numbers |
2020 | specified by \a from and \a to, where \a from corresponds to the first |
2021 | page in the range and \a to corresponds to the last. |
2022 | |
2023 | \note Pages in a document are numbered according to the convention that |
2024 | the first page is page 1. However, if \a from and \a to are both set to 0, |
2025 | the \e{whole document will be printed}. |
2026 | |
2027 | This function is mostly used to set a default value that the user can |
2028 | override in the print dialog when you call setup(). |
2029 | |
2030 | \sa fromPage(), toPage() |
2031 | */ |
2032 | |
2033 | void QPrinter::setFromTo(int from, int to) |
2034 | { |
2035 | if (from > to) { |
2036 | qWarning(msg: "QPrinter::setFromTo: 'from' must be less than or equal to 'to'" ); |
2037 | from = to; |
2038 | } |
2039 | d->fromPage = from; |
2040 | d->toPage = to; |
2041 | } |
2042 | |
2043 | /*! |
2044 | \since 4.1 |
2045 | |
2046 | Sets the print range option in to be \a range. |
2047 | */ |
2048 | void QPrinter::setPrintRange( PrintRange range ) |
2049 | { |
2050 | d->printSelectionOnly = (range == Selection); |
2051 | |
2052 | Q_D(QPrinter); |
2053 | d->printRange = range; |
2054 | } |
2055 | |
2056 | /*! |
2057 | \since 4.1 |
2058 | |
2059 | Returns the page range of the QPrinter. After the print setup |
2060 | dialog has been opened, this function returns the value selected |
2061 | by the user. |
2062 | |
2063 | \sa setPrintRange() |
2064 | */ |
2065 | QPrinter::PrintRange QPrinter::printRange() const |
2066 | { |
2067 | Q_D(const QPrinter); |
2068 | return d->printRange; |
2069 | } |
2070 | |
2071 | |
2072 | /*! |
2073 | \class QPrintEngine |
2074 | \reentrant |
2075 | |
2076 | \ingroup printing |
2077 | \inmodule QtPrintSupport |
2078 | |
2079 | \brief The QPrintEngine class defines an interface for how QPrinter |
2080 | interacts with a given printing subsystem. |
2081 | |
2082 | The common case when creating your own print engine is to derive from both |
2083 | QPaintEngine and QPrintEngine. Various properties of a print engine are |
2084 | given with property() and set with setProperty(). |
2085 | |
2086 | \sa QPaintEngine |
2087 | */ |
2088 | |
2089 | /*! |
2090 | \enum QPrintEngine::PrintEnginePropertyKey |
2091 | |
2092 | This enum is used to communicate properties between the print |
2093 | engine and QPrinter. A property may or may not be supported by a |
2094 | given print engine. |
2095 | |
2096 | \value PPK_CollateCopies A boolean value indicating whether the |
2097 | printout should be collated or not. |
2098 | |
2099 | \value PPK_ColorMode Refers to QPrinter::ColorMode, either color or |
2100 | monochrome. |
2101 | |
2102 | \value PPK_Creator A string describing the document's creator. |
2103 | |
2104 | \value PPK_Duplex A boolean value indicating whether both sides of |
2105 | the printer paper should be used for the printout. |
2106 | |
2107 | \value PPK_DocumentName A string describing the document name in |
2108 | the spooler. |
2109 | |
2110 | \value PPK_FontEmbedding A boolean value indicating whether data for |
2111 | the document's fonts should be embedded in the data sent to the |
2112 | printer. |
2113 | |
2114 | \value PPK_FullPage A boolean describing if the printer should be |
2115 | full page or not. |
2116 | |
2117 | \value PPK_NumberOfCopies Obsolete. An integer specifying the number of |
2118 | copies. Use PPK_CopyCount instead. |
2119 | |
2120 | \value PPK_Orientation Specifies a QPrinter::Orientation value. |
2121 | |
2122 | \value PPK_OutputFileName The output file name as a string. An |
2123 | empty file name indicates that the printer should not print to a file. |
2124 | |
2125 | \value PPK_PageOrder Specifies a QPrinter::PageOrder value. |
2126 | |
2127 | \value PPK_PageRect A QRect specifying the page rectangle |
2128 | |
2129 | \value PPK_PageSize Obsolete. Use PPK_PaperSize instead. |
2130 | |
2131 | \value PPK_PaperRect A QRect specifying the paper rectangle. |
2132 | |
2133 | \value PPK_PaperSource Specifies a QPrinter::PaperSource value. |
2134 | |
2135 | \value PPK_PaperSources Specifies more than one QPrinter::PaperSource value. |
2136 | |
2137 | \value PPK_PaperName A string specifying the name of the paper. |
2138 | |
2139 | \value PPK_PaperSize Specifies a QPrinter::PaperSize value. |
2140 | |
2141 | \value PPK_PrinterName A string specifying the name of the printer. |
2142 | |
2143 | \value PPK_PrinterProgram A string specifying the name of the |
2144 | printer program used for printing, |
2145 | |
2146 | \value PPK_Resolution An integer describing the dots per inch for |
2147 | this printer. |
2148 | |
2149 | \value PPK_SelectionOption |
2150 | |
2151 | \value PPK_SupportedResolutions A list of integer QVariants |
2152 | describing the set of supported resolutions that the printer has. |
2153 | |
2154 | \value PPK_WindowsPageSize An integer specifying a DM_PAPER entry |
2155 | on Windows. |
2156 | |
2157 | \value PPK_CustomPaperSize A QSizeF specifying a custom paper size |
2158 | in the QPrinter::Point unit. |
2159 | |
2160 | \value PPK_PageMargins A QList<QVariant> containing the left, top, |
2161 | right and bottom margin values in the QPrinter::Point unit. |
2162 | |
2163 | \value PPK_CopyCount An integer specifying the number of copies to print. |
2164 | |
2165 | \value PPK_SupportsMultipleCopies A boolean value indicating whether or not |
2166 | the printer supports printing multiple copies in one job. |
2167 | |
2168 | \value PPK_QPageSize Set the page size using a QPageSize object. |
2169 | |
2170 | \value PPK_QPageMargins Set the page margins using a QPair of QMarginsF and QPageLayout::Unit. |
2171 | |
2172 | \value PPK_QPageLayout Set the page layout using a QPageLayout object. |
2173 | |
2174 | \value PPK_CustomBase Basis for extension. |
2175 | */ |
2176 | |
2177 | /*! |
2178 | \fn QPrintEngine::~QPrintEngine() |
2179 | |
2180 | Destroys the print engine. |
2181 | */ |
2182 | |
2183 | /*! |
2184 | \fn void QPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value) |
2185 | |
2186 | Sets the print engine's property specified by \a key to the given \a value. |
2187 | |
2188 | \sa property() |
2189 | */ |
2190 | |
2191 | /*! |
2192 | \fn void QPrintEngine::property(PrintEnginePropertyKey key) const |
2193 | |
2194 | Returns the print engine's property specified by \a key. |
2195 | |
2196 | \sa setProperty() |
2197 | */ |
2198 | |
2199 | /*! |
2200 | \fn bool QPrintEngine::newPage() |
2201 | |
2202 | Instructs the print engine to start a new page. Returns \c true if |
2203 | the printer was able to create the new page; otherwise returns \c false. |
2204 | */ |
2205 | |
2206 | /*! |
2207 | \fn bool QPrintEngine::abort() |
2208 | |
2209 | Instructs the print engine to abort the printing process. Returns |
2210 | true if successful; otherwise returns \c false. |
2211 | */ |
2212 | |
2213 | /*! |
2214 | \fn int QPrintEngine::metric(QPaintDevice::PaintDeviceMetric id) const |
2215 | |
2216 | Returns the metric for the given \a id. |
2217 | */ |
2218 | |
2219 | /*! |
2220 | \fn QPrinter::PrinterState QPrintEngine::printerState() const |
2221 | |
2222 | Returns the current state of the printer being used by the print engine. |
2223 | */ |
2224 | |
2225 | QT_END_NAMESPACE |
2226 | |
2227 | #elif defined(Q_OS_WINRT) |
2228 | QT_BEGIN_NAMESPACE |
2229 | bool Q_PRINTSUPPORT_EXPORT qt_winrt_export_lib_creation_variable; |
2230 | QT_END_NAMESPACE |
2231 | #endif // QT_NO_PRINTER |
2232 | |