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

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

gui: Implemented support for printing through CUPS on OS/2.

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