source: trunk/src/gui/painting/qprinter.cpp@ 782

Last change on this file since 782 was 782, checked in by Dmitry A. Kuminov, 15 years ago

gui: Send PDF data to a CUPS printer on OS/2 by default if CUPS is version 1.4.4 or above (where printing PDF data was fixed).

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