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

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

trunk: Merged in qt 4.6.2 sources.

File size: 66.5 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 // Note: On OS/2, sending PDF data doesn't yet work with the current eCUPS
669 // (which is version 1.3.11 of CUPS), so don't force the PDF format there
670#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) && !defined(Q_WS_PM)
671 if (QCUPSSupport::cupsVersion() >= 10200 && QCUPSSupport().currentPPD()) {
672 setOutputFormat(QPrinter::PdfFormat);
673 d->outputFormat = QPrinter::NativeFormat;
674 }
675#endif
676}
677
678/*!
679 This function is used by subclasses of QPrinter to specify custom
680 print and paint engines (\a printEngine and \a paintEngine,
681 respectively).
682
683 QPrinter does not take ownership of the engines, so you need to
684 manage these engine instances yourself.
685
686 Note that changing the engines will reset the printer state and
687 all its properties.
688
689 \sa printEngine() paintEngine() setOutputFormat()
690
691 \since 4.1
692*/
693void QPrinter::setEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine)
694{
695 Q_D(QPrinter);
696
697 if (d->use_default_engine)
698 delete d->printEngine;
699
700 d->printEngine = printEngine;
701 d->paintEngine = paintEngine;
702 d->use_default_engine = false;
703}
704
705/*!
706 Destroys the printer object and frees any allocated resources. If
707 the printer is destroyed while a print job is in progress this may
708 or may not affect the print job.
709*/
710QPrinter::~QPrinter()
711{
712 Q_D(QPrinter);
713 if (d->use_default_engine)
714 delete d->printEngine;
715#ifndef QT_NO_PRINTPREVIEWWIDGET
716 delete d->previewEngine;
717#endif
718}
719
720/*!
721 \enum QPrinter::OutputFormat
722
723 The OutputFormat enum is used to describe the format QPrinter should
724 use for printing.
725
726 \value NativeFormat QPrinter will print output using a method defined
727 by the platform it is running on. This mode is the default when printing
728 directly to a printer.
729
730 \value PdfFormat QPrinter will generate its output as a searchable PDF file.
731 This mode is the default when printing to a file.
732
733 \value PostScriptFormat QPrinter will generate its output as in the PostScript format.
734 (This feature was introduced in Qt 4.2.)
735
736 \sa outputFormat(), setOutputFormat(), setOutputFileName()
737*/
738
739/*!
740 \since 4.1
741
742 Sets the output format for this printer to \a format.
743*/
744void QPrinter::setOutputFormat(OutputFormat format)
745{
746
747#ifndef QT_NO_PDF
748 Q_D(QPrinter);
749 if (d->validPrinter && d->outputFormat == format)
750 return;
751 d->outputFormat = format;
752
753 QPrintEngine *oldPrintEngine = d->printEngine;
754 QPaintEngine *oldPaintEngine = d->paintEngine; // same as the above - shouldn't be deleted
755 const bool def_engine = d->use_default_engine;
756 d->printEngine = 0;
757
758 d->createDefaultEngines();
759
760 if (oldPrintEngine) {
761 for (int i = 0; i < d->manualSetList.size(); ++i) {
762 QPrintEngine::PrintEnginePropertyKey key = d->manualSetList[i];
763 QVariant prop;
764 // PPK_NumberOfCopies need special treatmeant since it in most cases
765 // will return 1, disregarding the actual value that was set
766 if (key == QPrintEngine::PPK_NumberOfCopies)
767 prop = QVariant(qt_printerRealNumCopies(oldPaintEngine));
768 else
769 prop = oldPrintEngine->property(key);
770 if (prop.isValid())
771 d->printEngine->setProperty(key, prop);
772 }
773 }
774
775 if (def_engine)
776 delete oldPrintEngine;
777
778 if (d->outputFormat == QPrinter::PdfFormat || d->outputFormat == QPrinter::PostScriptFormat)
779 d->validPrinter = true;
780#else
781 Q_UNUSED(format);
782#endif
783}
784
785/*!
786 \since 4.1
787
788 Returns the output format for this printer.
789*/
790QPrinter::OutputFormat QPrinter::outputFormat() const
791{
792 Q_D(const QPrinter);
793 return d->outputFormat;
794}
795
796
797
798/*! \internal
799*/
800int QPrinter::devType() const
801{
802 return QInternal::Printer;
803}
804
805/*!
806 Returns the printer name. This value is initially set to the name
807 of the default printer.
808
809 \sa setPrinterName()
810*/
811QString QPrinter::printerName() const
812{
813 Q_D(const QPrinter);
814 return d->printEngine->property(QPrintEngine::PPK_PrinterName).toString();
815}
816
817/*!
818 Sets the printer name to \a name.
819
820 \sa printerName(), isValid()
821*/
822void QPrinter::setPrinterName(const QString &name)
823{
824 Q_D(QPrinter);
825 ABORT_IF_ACTIVE("QPrinter::setPrinterName");
826
827#if defined(Q_OS_UNIX) && !defined(QT_NO_CUPS)
828 if(d->use_default_engine
829 && d->outputFormat == QPrinter::NativeFormat) {
830 // Note: On OS/2, sending PDF data doesn't yet work with the current eCUPS
831 // (which is version 1.3.11 of CUPS), so don't force the PDF format there
832#ifndef Q_WS_PM
833 if (QCUPSSupport::cupsVersion() >= 10200
834 && QCUPSSupport::printerHasPPD(name.toLocal8Bit().constData()))
835 setOutputFormat(QPrinter::PdfFormat);
836 else
837#endif
838 setOutputFormat(QPrinter::PostScriptFormat);
839 d->outputFormat = QPrinter::NativeFormat;
840 }
841#endif
842
843 QList<QPrinterInfo> prnList = QPrinterInfo::availablePrinters();
844 if (name.isEmpty()) {
845 d->validPrinter = d->outputFormat == QPrinter::PdfFormat || d->outputFormat == QPrinter::PostScriptFormat;
846 } else {
847 d->validPrinter = false;
848 for (int i = 0; i < prnList.size(); ++i) {
849 if (prnList[i].printerName() == name) {
850 d->validPrinter = true;
851 break;
852 }
853 }
854 }
855
856 d->printEngine->setProperty(QPrintEngine::PPK_PrinterName, name);
857 d->addToManualSetList(QPrintEngine::PPK_PrinterName);
858}
859
860
861/*!
862 \since 4.4
863
864 Returns true if the printer currently selected is a valid printer
865 in the system, or a pure PDF/PostScript printer; otherwise returns false.
866
867 To detect other failures check the output of QPainter::begin() or QPrinter::newPage().
868
869 \snippet doc/src/snippets/printing-qprinter/errors.cpp 0
870
871 \sa setPrinterName()
872*/
873bool QPrinter::isValid() const
874{
875 Q_D(const QPrinter);
876#if defined(Q_WS_X11)
877 if (!qApp || !X11) {
878 return false;
879 }
880#endif
881 return d->validPrinter;
882}
883
884
885/*!
886 \fn bool QPrinter::outputToFile() const
887
888 Returns true if the output should be written to a file, or false
889 if the output should be sent directly to the printer. The default
890 setting is false.
891
892 \sa setOutputToFile(), setOutputFileName()
893*/
894
895
896/*!
897 \fn void QPrinter::setOutputToFile(bool enable)
898
899 Specifies whether the output should be written to a file or sent
900 directly to the printer.
901
902 Will output to a file if \a enable is true, or will output
903 directly to the printer if \a enable is false.
904
905 \sa outputToFile(), setOutputFileName()
906*/
907
908
909/*!
910 \fn QString QPrinter::outputFileName() const
911
912 Returns the name of the output file. By default, this is an empty string
913 (indicating that the printer shouldn't print to file).
914
915 \sa QPrintEngine::PrintEnginePropertyKey
916
917*/
918
919QString QPrinter::outputFileName() const
920{
921 Q_D(const QPrinter);
922 return d->printEngine->property(QPrintEngine::PPK_OutputFileName).toString();
923}
924
925/*!
926 Sets the name of the output file to \a fileName.
927
928 Setting a null or empty name (0 or "") disables printing to a file.
929 Setting a non-empty name enables printing to a file.
930
931 This can change the value of outputFormat(). If the file name has the
932 suffix ".ps" then PostScript is automatically selected as output format.
933 If the file name has the ".pdf" suffix PDF is generated. If the file name
934 has a suffix other than ".ps" and ".pdf", the output format used is the
935 one set with setOutputFormat().
936
937 QPrinter uses Qt's cross-platform PostScript or PDF print engines
938 respectively. If you can produce this format natively, for example
939 Mac OS X can generate PDF's from its print engine, set the output format
940 back to NativeFormat.
941
942 \sa outputFileName() setOutputToFile() setOutputFormat()
943*/
944
945void QPrinter::setOutputFileName(const QString &fileName)
946{
947 Q_D(QPrinter);
948 ABORT_IF_ACTIVE("QPrinter::setOutputFileName");
949
950 QFileInfo fi(fileName);
951 if (!fi.suffix().compare(QLatin1String("ps"), Qt::CaseInsensitive))
952 setOutputFormat(QPrinter::PostScriptFormat);
953 else if (!fi.suffix().compare(QLatin1String("pdf"), Qt::CaseInsensitive))
954 setOutputFormat(QPrinter::PdfFormat);
955 else if (fileName.isEmpty())
956 setOutputFormat(QPrinter::NativeFormat);
957
958 d->printEngine->setProperty(QPrintEngine::PPK_OutputFileName, fileName);
959 d->addToManualSetList(QPrintEngine::PPK_OutputFileName);
960}
961
962
963/*!
964 Returns the name of the program that sends the print output to the
965 printer.
966
967 The default is to return an empty string; meaning that QPrinter will try to
968 be smart in a system-dependent way. On X11 only, you can set it to something
969 different to use a specific print program. On the other platforms, this
970 returns an empty string.
971
972 \sa setPrintProgram(), setPrinterSelectionOption()
973*/
974QString QPrinter::printProgram() const
975{
976 Q_D(const QPrinter);
977 return d->printEngine->property(QPrintEngine::PPK_PrinterProgram).toString();
978}
979
980
981/*!
982 Sets the name of the program that should do the print job to \a
983 printProg.
984
985 On X11, this function sets the program to call with the PostScript
986 output. On other platforms, it has no effect.
987
988 \sa printProgram()
989*/
990void QPrinter::setPrintProgram(const QString &printProg)
991{
992 Q_D(QPrinter);
993 ABORT_IF_ACTIVE("QPrinter::setPrintProgram");
994 d->printEngine->setProperty(QPrintEngine::PPK_PrinterProgram, printProg);
995 d->addToManualSetList(QPrintEngine::PPK_PrinterProgram);
996}
997
998
999/*!
1000 Returns the document name.
1001
1002 \sa setDocName(), QPrintEngine::PrintEnginePropertyKey
1003*/
1004QString QPrinter::docName() const
1005{
1006 Q_D(const QPrinter);
1007 return d->printEngine->property(QPrintEngine::PPK_DocumentName).toString();
1008}
1009
1010
1011/*!
1012 Sets the document name to \a name.
1013
1014 On X11, the document name is for example used as the default
1015 output filename in QPrintDialog. Note that the document name does
1016 not affect the file name if the printer is printing to a file.
1017 Use the setOutputFile() function for this.
1018
1019 \sa docName(), QPrintEngine::PrintEnginePropertyKey
1020*/
1021void QPrinter::setDocName(const QString &name)
1022{
1023 Q_D(QPrinter);
1024 ABORT_IF_ACTIVE("QPrinter::setDocName");
1025 d->printEngine->setProperty(QPrintEngine::PPK_DocumentName, name);
1026 d->addToManualSetList(QPrintEngine::PPK_DocumentName);
1027}
1028
1029
1030/*!
1031 Returns the name of the application that created the document.
1032
1033 \sa setCreator()
1034*/
1035QString QPrinter::creator() const
1036{
1037 Q_D(const QPrinter);
1038 return d->printEngine->property(QPrintEngine::PPK_Creator).toString();
1039}
1040
1041
1042/*!
1043 Sets the name of the application that created the document to \a
1044 creator.
1045
1046 This function is only applicable to the X11 version of Qt. If no
1047 creator name is specified, the creator will be set to "Qt"
1048 followed by some version number.
1049
1050 \sa creator()
1051*/
1052void QPrinter::setCreator(const QString &creator)
1053{
1054 Q_D(QPrinter);
1055 ABORT_IF_ACTIVE("QPrinter::setCreator");
1056 d->printEngine->setProperty(QPrintEngine::PPK_Creator, creator);
1057 d->addToManualSetList(QPrintEngine::PPK_Creator);
1058}
1059
1060
1061/*!
1062 Returns the orientation setting. This is driver-dependent, but is usually
1063 QPrinter::Portrait.
1064
1065 \sa setOrientation()
1066*/
1067QPrinter::Orientation QPrinter::orientation() const
1068{
1069 Q_D(const QPrinter);
1070 return QPrinter::Orientation(d->printEngine->property(QPrintEngine::PPK_Orientation).toInt());
1071}
1072
1073
1074/*!
1075 Sets the print orientation to \a orientation.
1076
1077 The orientation can be either QPrinter::Portrait or
1078 QPrinter::Landscape.
1079
1080 The printer driver reads this setting and prints using the
1081 specified orientation.
1082
1083 On Windows, this option can be changed while printing and will
1084 take effect from the next call to newPage().
1085
1086 On Mac OS X, changing the orientation during a print job has no effect.
1087
1088 \sa orientation()
1089*/
1090
1091void QPrinter::setOrientation(Orientation orientation)
1092{
1093 Q_D(QPrinter);
1094 d->printEngine->setProperty(QPrintEngine::PPK_Orientation, orientation);
1095 d->addToManualSetList(QPrintEngine::PPK_Orientation);
1096}
1097
1098
1099/*!
1100 \since 4.4
1101 Returns the printer paper size. The default value is driver-dependent.
1102
1103 \sa setPaperSize() pageRect() paperRect()
1104*/
1105
1106QPrinter::PaperSize QPrinter::paperSize() const
1107{
1108 Q_D(const QPrinter);
1109 return QPrinter::PaperSize(d->printEngine->property(QPrintEngine::PPK_PaperSize).toInt());
1110}
1111
1112/*!
1113 \since 4.4
1114
1115 Sets the printer paper size to \a newPaperSize if that size is
1116 supported. The result is undefined if \a newPaperSize is not
1117 supported.
1118
1119 The default paper size is driver-dependent.
1120
1121 This function is useful mostly for setting a default value that
1122 the user can override in the print dialog.
1123
1124 \sa paperSize() PaperSize setFullPage() setResolution() pageRect() paperRect()
1125*/
1126void QPrinter::setPaperSize(PaperSize newPaperSize)
1127{
1128 Q_D(QPrinter);
1129 if (d->paintEngine->type() != QPaintEngine::Pdf)
1130 ABORT_IF_ACTIVE("QPrinter::setPaperSize");
1131 if (newPaperSize < 0 || newPaperSize >= NPaperSize) {
1132 qWarning("QPrinter::setPaperSize: Illegal paper size %d", newPaperSize);
1133 return;
1134 }
1135 d->printEngine->setProperty(QPrintEngine::PPK_PaperSize, newPaperSize);
1136 d->addToManualSetList(QPrintEngine::PPK_PaperSize);
1137 d->hasUserSetPageSize = true;
1138}
1139
1140/*!
1141 \obsolete
1142
1143 Returns the printer page size. The default value is driver-dependent.
1144
1145 Use paperSize() instead.
1146*/
1147QPrinter::PageSize QPrinter::pageSize() const
1148{
1149 return paperSize();
1150}
1151
1152
1153/*!
1154 \obsolete
1155
1156 Sets the printer page size based on \a newPageSize.
1157
1158 Use setPaperSize() instead.
1159*/
1160
1161void QPrinter::setPageSize(PageSize newPageSize)
1162{
1163 setPaperSize(newPageSize);
1164}
1165
1166/*!
1167 \since 4.4
1168
1169 Sets the paper size based on \a paperSize in \a unit.
1170
1171 \sa paperSize()
1172*/
1173
1174void QPrinter::setPaperSize(const QSizeF &paperSize, QPrinter::Unit unit)
1175{
1176 Q_D(QPrinter);
1177 if (d->paintEngine->type() != QPaintEngine::Pdf)
1178 ABORT_IF_ACTIVE("QPrinter::setPaperSize");
1179 const qreal multiplier = qt_multiplierForUnit(unit, resolution());
1180 QSizeF size(paperSize.width() * multiplier, paperSize.height() * multiplier);
1181 d->printEngine->setProperty(QPrintEngine::PPK_CustomPaperSize, size);
1182 d->addToManualSetList(QPrintEngine::PPK_CustomPaperSize);
1183 d->hasUserSetPageSize = true;
1184}
1185
1186/*!
1187 \since 4.4
1188
1189 Returns the paper size in \a unit.
1190
1191 \sa setPaperSize()
1192*/
1193
1194QSizeF QPrinter::paperSize(Unit unit) const
1195{
1196 Q_D(const QPrinter);
1197 int res = resolution();
1198 const qreal multiplier = qt_multiplierForUnit(unit, res);
1199 PaperSize paperType = paperSize();
1200 if (paperType == Custom) {
1201 QSizeF size = d->printEngine->property(QPrintEngine::PPK_CustomPaperSize).toSizeF();
1202 return QSizeF(size.width() / multiplier, size.height() / multiplier);
1203 }
1204 else {
1205 return qt_printerPaperSize(orientation(), paperType, unit, res);
1206 }
1207}
1208
1209/*!
1210 Sets the page order to \a pageOrder.
1211
1212 The page order can be QPrinter::FirstPageFirst or
1213 QPrinter::LastPageFirst. The application is responsible for
1214 reading the page order and printing accordingly.
1215
1216 This function is mostly useful for setting a default value that
1217 the user can override in the print dialog.
1218
1219 This function is only supported under X11.
1220*/
1221
1222void QPrinter::setPageOrder(PageOrder pageOrder)
1223{
1224 Q_D(QPrinter);
1225 ABORT_IF_ACTIVE("QPrinter::setPageOrder");
1226 d->printEngine->setProperty(QPrintEngine::PPK_PageOrder, pageOrder);
1227 d->addToManualSetList(QPrintEngine::PPK_PageOrder);
1228}
1229
1230
1231/*!
1232 Returns the current page order.
1233
1234 The default page order is \c FirstPageFirst.
1235*/
1236
1237QPrinter::PageOrder QPrinter::pageOrder() const
1238{
1239 Q_D(const QPrinter);
1240 return QPrinter::PageOrder(d->printEngine->property(QPrintEngine::PPK_PageOrder).toInt());
1241}
1242
1243
1244/*!
1245 Sets the printer's color mode to \a newColorMode, which can be
1246 either \c Color or \c GrayScale.
1247
1248 \sa colorMode()
1249*/
1250
1251void QPrinter::setColorMode(ColorMode newColorMode)
1252{
1253 Q_D(QPrinter);
1254 ABORT_IF_ACTIVE("QPrinter::setColorMode");
1255 d->printEngine->setProperty(QPrintEngine::PPK_ColorMode, newColorMode);
1256 d->addToManualSetList(QPrintEngine::PPK_ColorMode);
1257}
1258
1259
1260/*!
1261 Returns the current color mode.
1262
1263 \sa setColorMode()
1264*/
1265QPrinter::ColorMode QPrinter::colorMode() const
1266{
1267 Q_D(const QPrinter);
1268 return QPrinter::ColorMode(d->printEngine->property(QPrintEngine::PPK_ColorMode).toInt());
1269}
1270
1271
1272/*!
1273 Returns the number of copies to be printed. The default value is 1.
1274
1275 On Windows, Mac OS X and X11 systems that support CUPS, this will always
1276 return 1 as these operating systems can internally handle the number
1277 of copies.
1278
1279 On X11, this value will return the number of times the application is
1280 required to print in order to match the number specified in the printer setup
1281 dialog. This has been done since some printer drivers are not capable of
1282 buffering up the copies and in those cases the application must make an
1283 explicit call to the print code for each copy.
1284
1285 \sa setNumCopies(), actualNumCopies()
1286*/
1287
1288int QPrinter::numCopies() const
1289{
1290 Q_D(const QPrinter);
1291 return d->printEngine->property(QPrintEngine::PPK_NumberOfCopies).toInt();
1292}
1293
1294
1295/*!
1296 \since 4.6
1297
1298 Returns the number of copies that will be printed. The default
1299 value is 1.
1300
1301 This function always returns the actual value specified in the print
1302 dialog or using setNumCopies().
1303
1304 \sa setNumCopies(), numCopies()
1305*/
1306int QPrinter::actualNumCopies() const
1307{
1308 Q_D(const QPrinter);
1309 return qt_printerRealNumCopies(d->paintEngine);
1310}
1311
1312
1313
1314/*!
1315 Sets the number of copies to be printed to \a numCopies.
1316
1317 The printer driver reads this setting and prints the specified
1318 number of copies.
1319
1320 \sa numCopies()
1321*/
1322
1323void QPrinter::setNumCopies(int numCopies)
1324{
1325 Q_D(QPrinter);
1326 ABORT_IF_ACTIVE("QPrinter::setNumCopies");
1327 d->printEngine->setProperty(QPrintEngine::PPK_NumberOfCopies, numCopies);
1328 d->addToManualSetList(QPrintEngine::PPK_NumberOfCopies);
1329}
1330
1331
1332/*!
1333 \since 4.1
1334
1335 Returns true if collation is turned on when multiple copies is selected.
1336 Returns false if it is turned off when multiple copies is selected.
1337 When collating is turned off the printing of each individual page will be repeated
1338 the numCopies() amount before the next page is started. With collating turned on
1339 all pages are printed before the next copy of those pages is started.
1340
1341 \sa setCollateCopies()
1342*/
1343bool QPrinter::collateCopies() const
1344{
1345 Q_D(const QPrinter);
1346 return d->printEngine->property(QPrintEngine::PPK_CollateCopies).toBool();
1347}
1348
1349
1350/*!
1351 \since 4.1
1352
1353 Sets the default value for collation checkbox when the print
1354 dialog appears. If \a collate is true, it will enable
1355 setCollateCopiesEnabled(). The default value is false. This value
1356 will be changed by what the user presses in the print dialog.
1357
1358 \sa collateCopies()
1359*/
1360void QPrinter::setCollateCopies(bool collate)
1361{
1362 Q_D(QPrinter);
1363 ABORT_IF_ACTIVE("QPrinter::setCollateCopies");
1364 d->printEngine->setProperty(QPrintEngine::PPK_CollateCopies, collate);
1365 d->addToManualSetList(QPrintEngine::PPK_CollateCopies);
1366}
1367
1368
1369
1370/*!
1371 If \a fp is true, enables support for painting over the entire page;
1372 otherwise restricts painting to the printable area reported by the
1373 device.
1374
1375 By default, full page printing is disabled. In this case, the origin
1376 of the QPrinter's coordinate system coincides with the top-left
1377 corner of the printable area.
1378
1379 If full page printing is enabled, the origin of the QPrinter's
1380 coordinate system coincides with the top-left corner of the paper
1381 itself. In this case, the
1382 \l{QPaintDevice::PaintDeviceMetric}{device metrics} will report
1383 the exact same dimensions as indicated by \l{PaperSize}. It may not
1384 be possible to print on the entire physical page because of the
1385 printer's margins, so the application must account for the margins
1386 itself.
1387
1388 \sa fullPage(), setPaperSize(), width(), height(), {Printing with Qt}
1389*/
1390
1391void QPrinter::setFullPage(bool fp)
1392{
1393 Q_D(QPrinter);
1394 d->printEngine->setProperty(QPrintEngine::PPK_FullPage, fp);
1395 d->addToManualSetList(QPrintEngine::PPK_FullPage);
1396}
1397
1398
1399/*!
1400 Returns true if the origin of the printer's coordinate system is
1401 at the corner of the page and false if it is at the edge of the
1402 printable area.
1403
1404 See setFullPage() for details and caveats.
1405
1406 \sa setFullPage() PaperSize
1407*/
1408
1409bool QPrinter::fullPage() const
1410{
1411 Q_D(const QPrinter);
1412 return d->printEngine->property(QPrintEngine::PPK_FullPage).toBool();
1413}
1414
1415
1416/*!
1417 Requests that the printer prints at \a dpi or as near to \a dpi as
1418 possible.
1419
1420 This setting affects the coordinate system as returned by, for
1421 example QPainter::viewport().
1422
1423 This function must be called before QPainter::begin() to have an effect on
1424 all platforms.
1425
1426 \sa resolution() setPaperSize()
1427*/
1428
1429void QPrinter::setResolution(int dpi)
1430{
1431 Q_D(QPrinter);
1432 ABORT_IF_ACTIVE("QPrinter::setResolution");
1433 d->printEngine->setProperty(QPrintEngine::PPK_Resolution, dpi);
1434 d->addToManualSetList(QPrintEngine::PPK_Resolution);
1435}
1436
1437
1438/*!
1439 Returns the current assumed resolution of the printer, as set by
1440 setResolution() or by the printer driver.
1441
1442 \sa setResolution()
1443*/
1444
1445int QPrinter::resolution() const
1446{
1447 Q_D(const QPrinter);
1448 return d->printEngine->property(QPrintEngine::PPK_Resolution).toInt();
1449}
1450
1451/*!
1452 Sets the paper source setting to \a source.
1453
1454 Windows only: This option can be changed while printing and will
1455 take effect from the next call to newPage()
1456
1457 \sa paperSource()
1458*/
1459
1460void QPrinter::setPaperSource(PaperSource source)
1461{
1462 Q_D(QPrinter);
1463 d->printEngine->setProperty(QPrintEngine::PPK_PaperSource, source);
1464 d->addToManualSetList(QPrintEngine::PPK_PaperSource);
1465}
1466
1467/*!
1468 Returns the printer's paper source. This is \c Manual or a printer
1469 tray or paper cassette.
1470*/
1471QPrinter::PaperSource QPrinter::paperSource() const
1472{
1473 Q_D(const QPrinter);
1474 return QPrinter::PaperSource(d->printEngine->property(QPrintEngine::PPK_PaperSource).toInt());
1475}
1476
1477
1478/*!
1479 \since 4.1
1480
1481 Enabled or disables font embedding depending on \a enable.
1482
1483 Currently this option is only supported on X11.
1484
1485 \sa fontEmbeddingEnabled()
1486*/
1487void QPrinter::setFontEmbeddingEnabled(bool enable)
1488{
1489 Q_D(QPrinter);
1490 d->printEngine->setProperty(QPrintEngine::PPK_FontEmbedding, enable);
1491 d->addToManualSetList(QPrintEngine::PPK_FontEmbedding);
1492}
1493
1494/*!
1495 \since 4.1
1496
1497 Returns true if font embedding is enabled.
1498
1499 Currently this option is only supported on X11.
1500
1501 \sa setFontEmbeddingEnabled()
1502*/
1503bool QPrinter::fontEmbeddingEnabled() const
1504{
1505 Q_D(const QPrinter);
1506 return d->printEngine->property(QPrintEngine::PPK_FontEmbedding).toBool();
1507}
1508
1509/*!
1510 \enum QPrinter::DuplexMode
1511 \since 4.4
1512
1513 This enum is used to indicate whether printing will occur on one or both sides
1514 of each sheet of paper (simplex or duplex printing).
1515
1516 \value DuplexNone Single sided (simplex) printing only.
1517 \value DuplexAuto The printer's default setting is used to determine whether
1518 duplex printing is used.
1519 \value DuplexLongSide Both sides of each sheet of paper are used for printing.
1520 The paper is turned over its longest edge before the second
1521 side is printed
1522 \value DuplexShortSide Both sides of each sheet of paper are used for printing.
1523 The paper is turned over its shortest edge before the second
1524 side is printed
1525*/
1526
1527/*!
1528 \since 4.2
1529
1530 Enables double sided printing if \a doubleSided is true; otherwise disables it.
1531
1532 Currently this option is only supported on X11.
1533*/
1534void QPrinter::setDoubleSidedPrinting(bool doubleSided)
1535{
1536 setDuplex(doubleSided ? DuplexAuto : DuplexNone);
1537}
1538
1539
1540/*!
1541 \since 4.2
1542
1543 Returns true if double side printing is enabled.
1544
1545 Currently this option is only supported on X11.
1546*/
1547bool QPrinter::doubleSidedPrinting() const
1548{
1549 return duplex() != DuplexNone;
1550}
1551
1552/*!
1553 \since 4.4
1554
1555 Enables double sided printing based on the \a duplex mode.
1556
1557 Currently this option is only supported on X11.
1558*/
1559void QPrinter::setDuplex(DuplexMode duplex)
1560{
1561 Q_D(QPrinter);
1562 d->printEngine->setProperty(QPrintEngine::PPK_Duplex, duplex);
1563 d->addToManualSetList(QPrintEngine::PPK_Duplex);
1564}
1565
1566/*!
1567 \since 4.4
1568
1569 Returns the current duplex mode.
1570
1571 Currently this option is only supported on X11.
1572*/
1573QPrinter::DuplexMode QPrinter::duplex() const
1574{
1575 Q_D(const QPrinter);
1576 return static_cast <DuplexMode> (d->printEngine->property(QPrintEngine::PPK_Duplex).toInt());
1577}
1578
1579/*!
1580 \since 4.4
1581
1582 Returns the page's rectangle in \a unit; this is usually smaller
1583 than the paperRect() since the page normally has margins between
1584 its borders and the paper.
1585
1586 \sa paperSize()
1587*/
1588QRectF QPrinter::pageRect(Unit unit) const
1589{
1590 Q_D(const QPrinter);
1591 int res = resolution();
1592 const qreal multiplier = qt_multiplierForUnit(unit, res);
1593 // the page rect is in device pixels
1594 QRect devRect(d->printEngine->property(QPrintEngine::PPK_PageRect).toRect());
1595 if (unit == DevicePixel)
1596 return devRect;
1597 QRectF diRect(devRect.x()*72.0/res,
1598 devRect.y()*72.0/res,
1599 devRect.width()*72.0/res,
1600 devRect.height()*72.0/res);
1601 return QRectF(diRect.x()/multiplier, diRect.y()/multiplier,
1602 diRect.width()/multiplier, diRect.height()/multiplier);
1603}
1604
1605
1606/*!
1607 \since 4.4
1608
1609 Returns the paper's rectangle in \a unit; this is usually larger
1610 than the pageRect().
1611
1612 \sa pageRect()
1613*/
1614QRectF QPrinter::paperRect(Unit unit) const
1615{
1616 Q_D(const QPrinter);
1617 int res = resolution();
1618 const qreal multiplier = qt_multiplierForUnit(unit, resolution());
1619 // the page rect is in device pixels
1620 QRect devRect(d->printEngine->property(QPrintEngine::PPK_PaperRect).toRect());
1621 if (unit == DevicePixel)
1622 return devRect;
1623 QRectF diRect(devRect.x()*72.0/res,
1624 devRect.y()*72.0/res,
1625 devRect.width()*72.0/res,
1626 devRect.height()*72.0/res);
1627 return QRectF(diRect.x()/multiplier, diRect.y()/multiplier,
1628 diRect.width()/multiplier, diRect.height()/multiplier);
1629}
1630
1631/*!
1632 Returns the page's rectangle; this is usually smaller than the
1633 paperRect() since the page normally has margins between its
1634 borders and the paper.
1635
1636 The unit of the returned rectangle is DevicePixel.
1637
1638 \sa paperSize()
1639*/
1640QRect QPrinter::pageRect() const
1641{
1642 Q_D(const QPrinter);
1643 return d->printEngine->property(QPrintEngine::PPK_PageRect).toRect();
1644}
1645
1646/*!
1647 Returns the paper's rectangle; this is usually larger than the
1648 pageRect().
1649
1650 The unit of the returned rectangle is DevicePixel.
1651
1652 \sa pageRect()
1653*/
1654QRect QPrinter::paperRect() const
1655{
1656 Q_D(const QPrinter);
1657 return d->printEngine->property(QPrintEngine::PPK_PaperRect).toRect();
1658}
1659
1660
1661/*!
1662 \since 4.4
1663
1664 This function sets the \a left, \a top, \a right and \a bottom
1665 page margins for this printer. The unit of the margins are
1666 specified with the \a unit parameter.
1667*/
1668void QPrinter::setPageMargins(qreal left, qreal top, qreal right, qreal bottom, QPrinter::Unit unit)
1669{
1670 Q_D(QPrinter);
1671 const qreal multiplier = qt_multiplierForUnit(unit, resolution());
1672 QList<QVariant> margins;
1673 margins << (left * multiplier) << (top * multiplier)
1674 << (right * multiplier) << (bottom * multiplier);
1675 d->printEngine->setProperty(QPrintEngine::PPK_PageMargins, margins);
1676 d->addToManualSetList(QPrintEngine::PPK_PageMargins);
1677 d->hasCustomPageMargins = true;
1678}
1679
1680/*!
1681 \since 4.4
1682
1683 Returns the page margins for this printer in \a left, \a top, \a
1684 right, \a bottom. The unit of the returned margins are specified
1685 with the \a unit parameter.
1686*/
1687void QPrinter::getPageMargins(qreal *left, qreal *top, qreal *right, qreal *bottom, QPrinter::Unit unit) const
1688{
1689 Q_D(const QPrinter);
1690 Q_ASSERT(left && top && right && bottom);
1691 const qreal multiplier = qt_multiplierForUnit(unit, resolution());
1692 QList<QVariant> margins(d->printEngine->property(QPrintEngine::PPK_PageMargins).toList());
1693 *left = margins.at(0).toReal() / multiplier;
1694 *top = margins.at(1).toReal() / multiplier;
1695 *right = margins.at(2).toReal() / multiplier;
1696 *bottom = margins.at(3).toReal() / multiplier;
1697}
1698
1699/*!
1700 \internal
1701
1702 Returns the metric for the given \a id.
1703*/
1704int QPrinter::metric(PaintDeviceMetric id) const
1705{
1706 Q_D(const QPrinter);
1707 return d->printEngine->metric(id);
1708}
1709
1710/*!
1711 Returns the paint engine used by the printer.
1712*/
1713QPaintEngine *QPrinter::paintEngine() const
1714{
1715 Q_D(const QPrinter);
1716 return d->paintEngine;
1717}
1718
1719/*!
1720 \since 4.1
1721
1722 Returns the print engine used by the printer.
1723*/
1724QPrintEngine *QPrinter::printEngine() const
1725{
1726 Q_D(const QPrinter);
1727 return d->printEngine;
1728}
1729
1730#if defined (Q_WS_WIN)
1731/*!
1732 Sets the page size to be used by the printer under Windows to \a
1733 pageSize.
1734
1735 \warning This function is not portable so you may prefer to use
1736 setPaperSize() instead.
1737
1738 \sa winPageSize()
1739*/
1740void QPrinter::setWinPageSize(int pageSize)
1741{
1742 Q_D(QPrinter);
1743 ABORT_IF_ACTIVE("QPrinter::setWinPageSize");
1744 d->printEngine->setProperty(QPrintEngine::PPK_WindowsPageSize, pageSize);
1745 d->addToManualSetList(QPrintEngine::PPK_WindowsPageSize);
1746}
1747
1748/*!
1749 Returns the page size used by the printer under Windows.
1750
1751 \warning This function is not portable so you may prefer to use
1752 paperSize() instead.
1753
1754 \sa setWinPageSize()
1755*/
1756int QPrinter::winPageSize() const
1757{
1758 Q_D(const QPrinter);
1759 return d->printEngine->property(QPrintEngine::PPK_WindowsPageSize).toInt();
1760}
1761#endif // Q_WS_WIN
1762
1763/*!
1764 Returns a list of the resolutions (a list of dots-per-inch
1765 integers) that the printer says it supports.
1766
1767 For X11 where all printing is directly to postscript, this
1768 function will always return a one item list containing only the
1769 postscript resolution, i.e., 72 (72 dpi -- but see PrinterMode).
1770*/
1771QList<int> QPrinter::supportedResolutions() const
1772{
1773 Q_D(const QPrinter);
1774 QList<QVariant> varlist
1775 = d->printEngine->property(QPrintEngine::PPK_SupportedResolutions).toList();
1776 QList<int> intlist;
1777 for (int i=0; i<varlist.size(); ++i)
1778 intlist << varlist.at(i).toInt();
1779 return intlist;
1780}
1781
1782/*!
1783 Tells the printer to eject the current page and to continue
1784 printing on a new page. Returns true if this was successful;
1785 otherwise returns false.
1786
1787 Calling newPage() on an inactive QPrinter object will always
1788 fail.
1789*/
1790bool QPrinter::newPage()
1791{
1792 Q_D(QPrinter);
1793 if (d->printEngine->printerState() != QPrinter::Active)
1794 return false;
1795 return d->printEngine->newPage();
1796}
1797
1798/*!
1799 Aborts the current print run. Returns true if the print run was
1800 successfully aborted and printerState() will return QPrinter::Aborted; otherwise
1801 returns false.
1802
1803 It is not always possible to abort a print job. For example,
1804 all the data has gone to the printer but the printer cannot or
1805 will not cancel the job when asked to.
1806*/
1807bool QPrinter::abort()
1808{
1809 Q_D(QPrinter);
1810 return d->printEngine->abort();
1811}
1812
1813/*!
1814 Returns the current state of the printer. This may not always be
1815 accurate (for example if the printer doesn't have the capability
1816 of reporting its state to the operating system).
1817*/
1818QPrinter::PrinterState QPrinter::printerState() const
1819{
1820 Q_D(const QPrinter);
1821 return d->printEngine->printerState();
1822}
1823
1824
1825/*! \fn void QPrinter::margins(uint *top, uint *left, uint *bottom, uint *right) const
1826
1827 Sets *\a top, *\a left, *\a bottom, *\a right to be the top,
1828 left, bottom, and right margins.
1829
1830 This function has been superseded by paperRect() and pageRect().
1831 Use paperRect().top() - pageRect().top() for the top margin,
1832 paperRect().left() - pageRect().left() for the left margin,
1833 paperRect().bottom() - pageRect().bottom() for the bottom margin,
1834 and papaerRect().right() - pageRect().right() for the right
1835 margin.
1836
1837 \oldcode
1838 uint rightMargin;
1839 uint bottomMargin;
1840 printer->margins(0, 0, &bottomMargin, &rightMargin);
1841 \newcode
1842 int rightMargin = printer->paperRect().right() - printer->pageRect().right();
1843 int bottomMargin = printer->paperRect().bottom() - printer->pageRect().bottom();
1844 \endcode
1845*/
1846
1847/*! \fn QSize QPrinter::margins() const
1848
1849 \overload
1850
1851 Returns a QSize containing the left margin and the top margin.
1852
1853 This function has been superseded by paperRect() and pageRect().
1854 Use paperRect().left() - pageRect().left() for the left margin,
1855 and paperRect().top() - pageRect().top() for the top margin.
1856
1857 \oldcode
1858 QSize margins = printer->margins();
1859 int leftMargin = margins.width();
1860 int topMargin = margins.height();
1861 \newcode
1862 int leftMargin = printer->paperRect().left() - printer->pageRect().left();
1863 int topMargin = printer->paperRect().top() - printer->pageRect().top();
1864 \endcode
1865*/
1866
1867/*! \fn bool QPrinter::aborted()
1868
1869 Use printerState() == QPrinter::Aborted instead.
1870*/
1871
1872#ifdef Q_WS_WIN
1873/*!
1874 \internal
1875*/
1876HDC QPrinter::getDC() const
1877{
1878 Q_D(const QPrinter);
1879 return d->printEngine->getPrinterDC();
1880}
1881
1882/*!
1883 \internal
1884*/
1885void QPrinter::releaseDC(HDC hdc) const
1886{
1887 Q_D(const QPrinter);
1888 d->printEngine->releasePrinterDC(hdc);
1889}
1890
1891/*!
1892 Returns the supported paper sizes for this printer.
1893
1894 The values will be either a value that matches an entry in the
1895 QPrinter::PaperSource enum or a driver spesific value. The driver
1896 spesific values are greater than the constant DMBIN_USER declared
1897 in wingdi.h.
1898
1899 \warning This function is only available in windows.
1900*/
1901
1902QList<QPrinter::PaperSource> QPrinter::supportedPaperSources() const
1903{
1904 Q_D(const QPrinter);
1905 QVariant v = d->printEngine->property(QPrintEngine::PPK_PaperSources);
1906
1907 QList<QVariant> variant_list = v.toList();
1908 QList<QPrinter::PaperSource> int_list;
1909 for (int i=0; i<variant_list.size(); ++i)
1910 int_list << (QPrinter::PaperSource) variant_list.at(i).toInt();
1911
1912 return int_list;
1913}
1914
1915#endif
1916
1917/*!
1918 \fn QString QPrinter::printerSelectionOption() const
1919
1920 Returns the printer options selection string. This is useful only
1921 if the print command has been explicitly set.
1922
1923 The default value (an empty string) implies that the printer should
1924 be selected in a system-dependent manner.
1925
1926 Any other value implies that the given value should be used.
1927
1928 \warning This function is not available on Windows.
1929
1930 \sa setPrinterSelectionOption()
1931*/
1932
1933/*!
1934 \fn void QPrinter::setPrinterSelectionOption(const QString &option)
1935
1936 Sets the printer to use \a option to select the printer. \a option
1937 is null by default (which implies that Qt should be smart enough
1938 to guess correctly), but it can be set to other values to use a
1939 specific printer selection option.
1940
1941 If the printer selection option is changed while the printer is
1942 active, the current print job may or may not be affected.
1943
1944 \warning This function is not available on Windows.
1945
1946 \sa printerSelectionOption()
1947*/
1948
1949#ifndef Q_WS_WIN
1950QString QPrinter::printerSelectionOption() const
1951{
1952 Q_D(const QPrinter);
1953 return d->printEngine->property(QPrintEngine::PPK_SelectionOption).toString();
1954}
1955
1956void QPrinter::setPrinterSelectionOption(const QString &option)
1957{
1958 Q_D(QPrinter);
1959 d->printEngine->setProperty(QPrintEngine::PPK_SelectionOption, option);
1960 d->addToManualSetList(QPrintEngine::PPK_SelectionOption);
1961}
1962#endif
1963
1964/*!
1965 \since 4.1
1966 \fn int QPrinter::fromPage() const
1967
1968 Returns the number of the first page in a range of pages to be printed
1969 (the "from page" setting). Pages in a document are numbered according to
1970 the convention that the first page is page 1.
1971
1972 By default, this function returns a special value of 0, meaning that
1973 the "from page" setting is unset.
1974
1975 \note If fromPage() and toPage() both return 0, this indicates that
1976 \e{the whole document will be printed}.
1977
1978 \sa setFromTo(), toPage()
1979*/
1980
1981int QPrinter::fromPage() const
1982{
1983 Q_D(const QPrinter);
1984 return d->fromPage;
1985}
1986
1987/*!
1988 \since 4.1
1989
1990 Returns the number of the last page in a range of pages to be printed
1991 (the "to page" setting). Pages in a document are numbered according to
1992 the convention that the first page is page 1.
1993
1994 By default, this function returns a special value of 0, meaning that
1995 the "to page" setting is unset.
1996
1997 \note If fromPage() and toPage() both return 0, this indicates that
1998 \e{the whole document will be printed}.
1999
2000 The programmer is responsible for reading this setting and
2001 printing accordingly.
2002
2003 \sa setFromTo(), fromPage()
2004*/
2005
2006int QPrinter::toPage() const
2007{
2008 Q_D(const QPrinter);
2009 return d->toPage;
2010}
2011
2012/*!
2013 \since 4.1
2014
2015 Sets the range of pages to be printed to cover the pages with numbers
2016 specified by \a from and \a to, where \a from corresponds to the first
2017 page in the range and \a to corresponds to the last.
2018
2019 \note Pages in a document are numbered according to the convention that
2020 the first page is page 1. However, if \a from and \a to are both set to 0,
2021 the \e{whole document will be printed}.
2022
2023 This function is mostly used to set a default value that the user can
2024 override in the print dialog when you call setup().
2025
2026 \sa fromPage(), toPage()
2027*/
2028
2029void QPrinter::setFromTo(int from, int to)
2030{
2031 Q_D(QPrinter);
2032 if (from > to) {
2033 qWarning() << "QPrinter::setFromTo: 'from' must be less than or equal to 'to'";
2034 from = to;
2035 }
2036 d->fromPage = from;
2037 d->toPage = to;
2038
2039 if (d->minPage == 0 && d->maxPage == 0) {
2040 d->minPage = 1;
2041 d->maxPage = to;
2042 d->options |= QAbstractPrintDialog::PrintPageRange;
2043 }
2044}
2045
2046/*!
2047 \since 4.1
2048
2049 Sets the print range option in to be \a range.
2050*/
2051void QPrinter::setPrintRange( PrintRange range )
2052{
2053 Q_D(QPrinter);
2054 d->printRange = QAbstractPrintDialog::PrintRange(range);
2055}
2056
2057/*!
2058 \since 4.1
2059
2060 Returns the page range of the QPrinter. After the print setup
2061 dialog has been opened, this function returns the value selected
2062 by the user.
2063
2064 \sa setPrintRange()
2065*/
2066QPrinter::PrintRange QPrinter::printRange() const
2067{
2068 Q_D(const QPrinter);
2069 return PrintRange(d->printRange);
2070}
2071
2072#if defined(QT3_SUPPORT)
2073
2074void QPrinter::setOutputToFile(bool f)
2075{
2076 if (f) {
2077 if (outputFileName().isEmpty())
2078 setOutputFileName(QLatin1String("untitled_printer_document"));
2079 } else {
2080 setOutputFileName(QString());
2081 }
2082}
2083
2084bool qt_compat_QPrinter_printSetup(QPrinter *printer, QPrinterPrivate *pd, QWidget *parent)
2085{
2086 Q_UNUSED(pd);
2087 QPrintDialog dlg(printer, parent);
2088 return dlg.exec() != 0;
2089}
2090
2091
2092#ifdef Q_WS_MAC
2093bool qt_compat_QPrinter_pageSetup(QPrinter *p, QWidget *parent)
2094{
2095 QPageSetupDialog psd(p, parent);
2096 return psd.exec() != 0;
2097}
2098
2099/*!
2100 Executes a page setup dialog so that the user can configure the type of
2101 page used for printing. Returns true if the contents of the dialog are
2102 accepted; returns false if the dialog is canceled.
2103*/
2104bool QPrinter::pageSetup(QWidget *parent)
2105{
2106 return qt_compat_QPrinter_pageSetup(this, parent);
2107}
2108
2109/*!
2110 Executes a print setup dialog so that the user can configure the printing
2111 process. Returns true if the contents of the dialog are accepted; returns
2112 false if the dialog is canceled.
2113*/
2114bool QPrinter::printSetup(QWidget *parent)
2115{
2116 Q_D(QPrinter);
2117 return qt_compat_QPrinter_printSetup(this, d, parent);
2118}
2119#endif // Q_WS_MAC
2120
2121/*!
2122 Use QPrintDialog instead.
2123
2124 \oldcode
2125 if (printer->setup(parent))
2126 ...
2127 \newcode
2128 QPrintDialog dialog(printer, parent);
2129 if (dialog.exec())
2130 ...
2131 \endcode
2132*/
2133bool QPrinter::setup(QWidget *parent)
2134{
2135 Q_D(QPrinter);
2136 return qt_compat_QPrinter_printSetup(this, d, parent)
2137#ifdef Q_WS_MAC
2138 && qt_compat_QPrinter_pageSetup(this, parent);
2139#endif
2140 ;
2141}
2142
2143/*!
2144 Use QPrintDialog::minPage() instead.
2145*/
2146int QPrinter::minPage() const
2147{
2148 Q_D(const QPrinter);
2149 return d->minPage;
2150}
2151
2152/*!
2153 Use QPrintDialog::maxPage() instead.
2154*/
2155int QPrinter::maxPage() const
2156{
2157 Q_D(const QPrinter);
2158 return d->maxPage;
2159}
2160
2161/*!
2162 Use QPrintDialog::setMinMax() instead.
2163*/
2164void QPrinter::setMinMax( int minPage, int maxPage )
2165{
2166 Q_D(QPrinter);
2167 Q_ASSERT_X(minPage <= maxPage, "QPrinter::setMinMax",
2168 "'min' must be less than or equal to 'max'");
2169 d->minPage = minPage;
2170 d->maxPage = maxPage;
2171 d->options |= QPrintDialog::PrintPageRange;
2172}
2173
2174/*!
2175 Returns true if the printer is set up to collate copies of printed documents;
2176 otherwise returns false.
2177
2178 Use QPrintDialog::isOptionEnabled(QPrintDialog::PrintCollateCopies)
2179 instead.
2180
2181 \sa collateCopies()
2182*/
2183bool QPrinter::collateCopiesEnabled() const
2184{
2185 Q_D(const QPrinter);
2186 return (d->options & QPrintDialog::PrintCollateCopies);
2187}
2188
2189/*!
2190 Use QPrintDialog::setOption(QPrintDialog::PrintCollateCopies)
2191 or QPrintDialog::setOptions(QPrintDialog::options()
2192 & ~QPrintDialog::PrintCollateCopies) instead, depending on \a
2193 enable.
2194*/
2195void QPrinter::setCollateCopiesEnabled(bool enable)
2196{
2197 Q_D(QPrinter);
2198
2199 if (enable)
2200 d->options |= QPrintDialog::PrintCollateCopies;
2201 else
2202 d->options &= ~QPrintDialog::PrintCollateCopies;
2203}
2204
2205/*!
2206 Use QPrintDialog instead.
2207*/
2208void QPrinter::setOptionEnabled( PrinterOption option, bool enable )
2209{
2210 Q_D(QPrinter);
2211 if (enable)
2212 d->options |= QPrintDialog::PrintDialogOption(1 << option);
2213 else
2214 d->options &= ~QPrintDialog::PrintDialogOption(1 << option);
2215}
2216
2217/*!
2218 Use QPrintDialog instead.
2219*/
2220bool QPrinter::isOptionEnabled( PrinterOption option ) const
2221{
2222 Q_D(const QPrinter);
2223 return (d->options & QPrintDialog::PrintDialogOption(option));
2224}
2225
2226#endif // QT3_SUPPORT
2227
2228/*!
2229 \class QPrintEngine
2230 \reentrant
2231
2232 \ingroup printing
2233
2234 \brief The QPrintEngine class defines an interface for how QPrinter
2235 interacts with a given printing subsystem.
2236
2237 The common case when creating your own print engine is to derive from both
2238 QPaintEngine and QPrintEngine. Various properties of a print engine are
2239 given with property() and set with setProperty().
2240
2241 \sa QPaintEngine
2242*/
2243
2244/*!
2245 \enum QPrintEngine::PrintEnginePropertyKey
2246
2247 This enum is used to communicate properties between the print
2248 engine and QPrinter. A property may or may not be supported by a
2249 given print engine.
2250
2251 \value PPK_CollateCopies A boolean value indicating whether the
2252 printout should be collated or not.
2253
2254 \value PPK_ColorMode Refers to QPrinter::ColorMode, either color or
2255 monochrome.
2256
2257 \value PPK_Creator A string describing the document's creator.
2258
2259 \value PPK_Duplex A boolean value indicating whether both sides of
2260 the printer paper should be used for the printout.
2261
2262 \value PPK_DocumentName A string describing the document name in
2263 the spooler.
2264
2265 \value PPK_FontEmbedding A boolean value indicating whether data for
2266 the document's fonts should be embedded in the data sent to the
2267 printer.
2268
2269 \value PPK_FullPage A boolean describing if the printer should be
2270 full page or not.
2271
2272 \value PPK_NumberOfCopies An integer specifying the number of
2273 copies
2274
2275 \value PPK_Orientation Specifies a QPrinter::Orientation value.
2276
2277 \value PPK_OutputFileName The output file name as a string. An
2278 empty file name indicates that the printer should not print to a file.
2279
2280 \value PPK_PageOrder Specifies a QPrinter::PageOrder value.
2281
2282 \value PPK_PageRect A QRect specifying the page rectangle
2283
2284 \value PPK_PageSize Obsolete. Use PPK_PaperSize instead.
2285
2286 \value PPK_PaperRect A QRect specifying the paper rectangle.
2287
2288 \value PPK_PaperSource Specifies a QPrinter::PaperSource value.
2289
2290 \value PPK_PaperSources Specifies more than one QPrinter::PaperSource value.
2291
2292 \value PPK_PaperSize Specifies a QPrinter::PaperSize value.
2293
2294 \value PPK_PrinterName A string specifying the name of the printer.
2295
2296 \value PPK_PrinterProgram A string specifying the name of the
2297 printer program used for printing,
2298
2299 \value PPK_Resolution An integer describing the dots per inch for
2300 this printer.
2301
2302 \value PPK_SelectionOption
2303
2304 \value PPK_SupportedResolutions A list of integer QVariants
2305 describing the set of supported resolutions that the printer has.
2306
2307 \value PPK_SuppressSystemPrintStatus Suppress the built-in dialog for showing
2308 printing progress. As of 4.1 this only has effect on Mac OS X where, by default,
2309 a status dialog is shown.
2310
2311 \value PPK_WindowsPageSize An integer specifying a DM_PAPER entry
2312 on Windows.
2313
2314 \value PPK_CustomPaperSize A QSizeF specifying a custom paper size
2315 in the QPrinter::Point unit.
2316
2317 \value PPK_PageMargins A QList<QVariant> containing the left, top,
2318 right and bottom margin values.
2319
2320 \value PPK_CustomBase Basis for extension.
2321*/
2322
2323/*!
2324 \fn QPrintEngine::~QPrintEngine()
2325
2326 Destroys the print engine.
2327*/
2328
2329/*!
2330 \fn void QPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value)
2331
2332 Sets the print engine's property specified by \a key to the given \a value.
2333
2334 \sa property()
2335*/
2336
2337/*!
2338 \fn void QPrintEngine::property(PrintEnginePropertyKey key) const
2339
2340 Returns the print engine's property specified by \a key.
2341
2342 \sa setProperty()
2343*/
2344
2345/*!
2346 \fn bool QPrintEngine::newPage()
2347
2348 Instructs the print engine to start a new page. Returns true if
2349 the printer was able to create the new page; otherwise returns false.
2350*/
2351
2352/*!
2353 \fn bool QPrintEngine::abort()
2354
2355 Instructs the print engine to abort the printing process. Returns
2356 true if successful; otherwise returns false.
2357*/
2358
2359/*!
2360 \fn int QPrintEngine::metric(QPaintDevice::PaintDeviceMetric id) const
2361
2362 Returns the metric for the given \a id.
2363*/
2364
2365/*!
2366 \fn QPrinter::PrinterState QPrintEngine::printerState() const
2367
2368 Returns the current state of the printer being used by the print engine.
2369*/
2370
2371/*!
2372 \fn HDC QPrintEngine::getPrinterDC() const
2373 \internal
2374*/
2375
2376/*!
2377 \fn void QPrintEngine::releasePrinterDC(HDC) const
2378 \internal
2379*/
2380
2381/*
2382 Returns the dimensions for the given paper size, \a size, in millimeters.
2383*/
2384QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size)
2385{
2386 if (size == QPrinter::Custom) return QSizeF(0, 0);
2387 return QSizeF(qt_paperSizes[size][0], qt_paperSizes[size][1]);
2388}
2389
2390/*
2391 Returns the PaperSize type that matches \a size, where \a size
2392 is in millimeters.
2393
2394 Because dimensions may not always be completely accurate (for
2395 example when converting between units), a particular PaperSize
2396 will be returned if it matches within -1/+1 millimeters.
2397*/
2398QPrinter::PaperSize qSizeFTopaperSize(const QSizeF& size)
2399{
2400 for (int i = 0; i < static_cast<int>(QPrinter::NPaperSize); ++i) {
2401 if (qt_paperSizes[i][0] >= size.width() - 1 &&
2402 qt_paperSizes[i][0] <= size.width() + 1 &&
2403 qt_paperSizes[i][1] >= size.height() - 1 &&
2404 qt_paperSizes[i][1] <= size.height() + 1) {
2405 return QPrinter::PaperSize(i);
2406 }
2407 }
2408
2409 return QPrinter::Custom;
2410}
2411
2412QT_END_NAMESPACE
2413
2414#endif // QT_NO_PRINTER
Note: See TracBrowser for help on using the repository browser.