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#ifndef QPRINTER_H
41#define QPRINTER_H
42
43#include <QtPrintSupport/qtprintsupportglobal.h>
44#include <QtCore/qstring.h>
45#include <QtCore/qscopedpointer.h>
46#include <QtGui/qpagedpaintdevice.h>
47#include <QtGui/qpagelayout.h>
48
49QT_BEGIN_NAMESPACE
50
51
52#ifndef QT_NO_PRINTER
53
54#if defined(B0)
55#undef B0 // Terminal hang-up. We assume that you do not want that.
56#endif
57
58class QPrinterPrivate;
59class QPaintEngine;
60class QPrintEngine;
61class QPrinterInfo;
62class QPageSize;
63class QPageMargins;
64
65class Q_PRINTSUPPORT_EXPORT QPrinter : public QPagedPaintDevice
66{
67 Q_DECLARE_PRIVATE(QPrinter)
68public:
69 enum PrinterMode { ScreenResolution, PrinterResolution, HighResolution };
70
71 explicit QPrinter(PrinterMode mode = ScreenResolution);
72 explicit QPrinter(const QPrinterInfo& printer, PrinterMode mode = ScreenResolution);
73 ~QPrinter();
74
75 int devType() const override;
76
77 enum Orientation { Portrait, Landscape };
78
79 // ### Qt6 Remove in favor of QPage::PageSize
80 typedef PageSize PaperSize;
81
82 enum PageOrder { FirstPageFirst,
83 LastPageFirst };
84
85 enum ColorMode { GrayScale,
86 Color };
87
88 enum PaperSource { OnlyOne,
89 Lower,
90 Middle,
91 Manual,
92 Envelope,
93 EnvelopeManual,
94 Auto,
95 Tractor,
96 SmallFormat,
97 LargeFormat,
98 LargeCapacity,
99 Cassette,
100 FormSource,
101 MaxPageSource, // Deprecated
102 CustomSource,
103 LastPaperSource = CustomSource,
104 Upper = OnlyOne // As defined in Windows
105 };
106
107 enum PrinterState { Idle,
108 Active,
109 Aborted,
110 Error };
111
112 enum OutputFormat { NativeFormat, PdfFormat };
113
114 // Keep in sync with QAbstractPrintDialog::PrintRange
115 enum PrintRange { AllPages, Selection, PageRange, CurrentPage };
116
117 enum Unit {
118 Millimeter,
119 Point,
120 Inch,
121 Pica,
122 Didot,
123 Cicero,
124 DevicePixel
125 };
126
127 enum DuplexMode {
128 DuplexNone = 0,
129 DuplexAuto,
130 DuplexLongSide,
131 DuplexShortSide
132 };
133
134 void setOutputFormat(OutputFormat format);
135 OutputFormat outputFormat() const;
136
137 void setPdfVersion(PdfVersion version);
138 PdfVersion pdfVersion() const;
139
140 void setPrinterName(const QString &);
141 QString printerName() const;
142
143 bool isValid() const;
144
145 void setOutputFileName(const QString &);
146 QString outputFileName()const;
147
148 void setPrintProgram(const QString &);
149 QString printProgram() const;
150
151 void setDocName(const QString &);
152 QString docName() const;
153
154 void setCreator(const QString &);
155 QString creator() const;
156
157#ifdef Q_CLANG_QDOC
158 // ### Qt6 Remove when these are made virtual in QPagedPaintDevice
159 bool setPageLayout(const QPageLayout &pageLayout);
160 bool setPageSize(const QPageSize &pageSize);
161 bool setPageOrientation(QPageLayout::Orientation orientation);
162 bool setPageMargins(const QMarginsF &margins);
163 bool setPageMargins(const QMarginsF &margins, QPageLayout::Unit units);
164 QPageLayout pageLayout() const;
165#else
166 using QPagedPaintDevice::setPageSize;
167 using QPagedPaintDevice::setPageMargins;
168#endif
169
170#if QT_DEPRECATED_SINCE(5,15)
171 QT_DEPRECATED_VERSION_X_5_15("Use setPageOrientation() instead.")
172 void setOrientation(Orientation);
173 QT_DEPRECATED_VERSION_X_5_15("Use pageLayout().orientation() instead.")
174 Orientation orientation() const;
175
176 QT_DEPRECATED_VERSION_X_5_15("Use setPageSize(QPageSize) instead.")
177 void setPageSize(PageSize) override;
178 QT_DEPRECATED_VERSION_X_5_15("Use pageLayout().pageSize().id() instead.")
179 PageSize pageSize() const;
180
181 QT_DEPRECATED_VERSION_X_5_15("Use setPageSize(QPageSize) instead.")
182 void setPageSizeMM(const QSizeF &size) override;
183
184 QT_DEPRECATED_VERSION_X_5_15("Use setPageSize(QPageSize) instead.")
185 void setPaperSize(PaperSize);
186 QT_DEPRECATED_VERSION_X_5_15("pageLayout().pageSize().id()")
187 PaperSize paperSize() const;
188
189 QT_DEPRECATED_VERSION_X_5_15("Use setPageSize(QPageSize) instead.")
190 void setPaperSize(const QSizeF &paperSize, Unit unit);
191 QT_DEPRECATED_VERSION_X_5_15("Use pageLayout().pageSize().size() or pageLayout().fullPageSize() instead.")
192 QSizeF paperSize(Unit unit) const;
193
194 QT_DEPRECATED_VERSION_X_5_15("Use setPageSize(QPageSize) instead.")
195 void setPaperName(const QString &paperName);
196 QT_DEPRECATED_VERSION_X_5_15("Use pageLayout().pageSize().name() instead.")
197 QString paperName() const;
198#endif
199
200 void setPageOrder(PageOrder);
201 PageOrder pageOrder() const;
202
203 void setResolution(int);
204 int resolution() const;
205
206 void setColorMode(ColorMode);
207 ColorMode colorMode() const;
208
209 void setCollateCopies(bool collate);
210 bool collateCopies() const;
211
212 void setFullPage(bool);
213 bool fullPage() const;
214
215#if QT_DEPRECATED_SINCE(5,15)
216 QT_DEPRECATED_VERSION_X_5_15("Use setCopyCount() instead.")
217 void setNumCopies(int);
218 QT_DEPRECATED_VERSION_X_5_15("Use copyCount() instead.")
219 int numCopies() const;
220 QT_DEPRECATED_VERSION_X_5_15("Use copyCount() instead.")
221 int actualNumCopies() const;
222#endif
223
224 void setCopyCount(int);
225 int copyCount() const;
226 bool supportsMultipleCopies() const;
227
228 void setPaperSource(PaperSource);
229 PaperSource paperSource() const;
230
231 void setDuplex(DuplexMode duplex);
232 DuplexMode duplex() const;
233
234 QList<int> supportedResolutions() const;
235
236#if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC)
237 QList<PaperSource> supportedPaperSources() const;
238#endif
239
240 void setFontEmbeddingEnabled(bool enable);
241 bool fontEmbeddingEnabled() const;
242
243#if QT_DEPRECATED_SINCE(5,15)
244 QT_DEPRECATED_VERSION_X_5_15("Use setDuplex() instead.")
245 void setDoubleSidedPrinting(bool enable);
246 QT_DEPRECATED_VERSION_X_5_15("Use duplex() instead.")
247 bool doubleSidedPrinting() const;
248#endif
249
250#if QT_DEPRECATED_SINCE(5,15)
251 QT_DEPRECATED_VERSION_X_5_15("Use QPageSize::id(windowsId) and setPageLayout(QPageSize) instead.")
252 void setWinPageSize(int winPageSize);
253 QT_DEPRECATED_VERSION_X_5_15("Use pageLayout.pageSize().windowsId() instead.")
254 int winPageSize() const;
255
256 QT_DEPRECATED_VERSION_X_5_15("Use pageLayout().fullRectPixels(resolution()) instead.")
257 QRect paperRect() const;
258 QT_DEPRECATED_VERSION_X_5_15("Use pageLayout().paintRectPixels(resolution()) instead.")
259 QRect pageRect() const;
260#endif
261 QRectF paperRect(Unit) const;
262 QRectF pageRect(Unit) const;
263
264 QString printerSelectionOption() const;
265 void setPrinterSelectionOption(const QString &);
266
267 bool newPage() override;
268 bool abort();
269
270 PrinterState printerState() const;
271
272 QPaintEngine *paintEngine() const override;
273 QPrintEngine *printEngine() const;
274
275 void setFromTo(int fromPage, int toPage);
276 int fromPage() const;
277 int toPage() const;
278
279 void setPrintRange(PrintRange range);
280 PrintRange printRange() const;
281
282#if QT_DEPRECATED_SINCE(5,15)
283 QT_DEPRECATED_VERSION_X_5_15("Use setPageMargins(QMarginsF, QPageLayout::Unit) instead.")
284 void setMargins(const Margins &m) override;
285
286 QT_DEPRECATED_VERSION_X_5_15("Use setPageMargins(QMarginsF, QPageLayout::Unit) instead.")
287 void setPageMargins(qreal left, qreal top, qreal right, qreal bottom, Unit unit);
288 QT_DEPRECATED_VERSION_X_5_15("Use pageLayout().margins() instead.")
289 void getPageMargins(qreal *left, qreal *top, qreal *right, qreal *bottom, Unit unit) const;
290#endif
291
292protected:
293 int metric(PaintDeviceMetric) const override;
294 void setEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine);
295
296private:
297 Q_DISABLE_COPY(QPrinter)
298
299 QScopedPointer<QPrinterPrivate> d_ptr;
300
301 friend class QPrintDialogPrivate;
302 friend class QAbstractPrintDialog;
303 friend class QAbstractPrintDialogPrivate;
304 friend class QPrintPreviewWidgetPrivate;
305 friend class QTextDocument;
306 friend class QPageSetupWidget;
307};
308
309#endif // QT_NO_PRINTER
310
311QT_END_NAMESPACE
312
313#endif // QPRINTER_H
314