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

Last change on this file since 5 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

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