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