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