Qt 4.8
qprinter.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QPRINTER_H
43 #define QPRINTER_H
44 
45 #include <QtCore/qstring.h>
46 #include <QtCore/qscopedpointer.h>
47 #include <QtGui/qpaintdevice.h>
48 
50 
52 
53 QT_MODULE(Gui)
54 
55 #ifndef QT_NO_PRINTER
56 
57 #if defined(B0)
58 #undef B0 // Terminal hang-up. We assume that you do not want that.
59 #endif
60 
61 class QPrinterPrivate;
62 class QPaintEngine;
63 class QPrintEngine;
64 class QPrinterInfo;
65 
67 {
69 public:
70  enum PrinterMode { ScreenResolution, PrinterResolution, HighResolution };
71 
72  explicit QPrinter(PrinterMode mode = ScreenResolution);
73  explicit QPrinter(const QPrinterInfo& printer, PrinterMode mode = ScreenResolution);
74  ~QPrinter();
75 
76  int devType() const;
77 
78  enum Orientation { Portrait, Landscape };
79 
80 #ifndef Q_QDOC
81  enum PageSize { A4, B5, Letter, Legal, Executive,
82  A0, A1, A2, A3, A5, A6, A7, A8, A9, B0, B1,
83  B10, B2, B3, B4, B6, B7, B8, B9, C5E, Comm10E,
84  DLE, Folio, Ledger, Tabloid, Custom, NPageSize = Custom, NPaperSize = Custom };
85  typedef PageSize PaperSize;
86 #else
87  enum PageSize { A4, B5, Letter, Legal, Executive,
88  A0, A1, A2, A3, A5, A6, A7, A8, A9, B0, B1,
89  B10, B2, B3, B4, B6, B7, B8, B9, C5E, Comm10E,
90  DLE, Folio, Ledger, Tabloid, Custom, NPageSize = Custom };
91  enum PaperSize { A4, B5, Letter, Legal, Executive,
92  A0, A1, A2, A3, A5, A6, A7, A8, A9, B0, B1,
93  B10, B2, B3, B4, B6, B7, B8, B9, C5E, Comm10E,
94  DLE, Folio, Ledger, Tabloid, Custom, NPageSize = Custom, NPaperSize = Custom };
95 #endif
96 
97  enum PageOrder { FirstPageFirst,
98  LastPageFirst };
99 
101  Color };
102 
103  enum PaperSource { OnlyOne,
116  MaxPageSource
117  };
118 
119  enum PrinterState { Idle,
122  Error };
123 
124  enum OutputFormat { NativeFormat, PdfFormat, PostScriptFormat };
125 
126  // ### Qt 5: Merge with QAbstractPrintDialog::PrintRange
127  enum PrintRange { AllPages, Selection, PageRange, CurrentPage };
128 
129  enum Unit {
136  DevicePixel
137  };
138 
139  enum DuplexMode {
140  DuplexNone = 0,
143  DuplexShortSide
144  };
145 
146 #ifdef QT3_SUPPORT
147  enum PrinterOption { PrintToFile, PrintSelection, PrintPageRange };
148 #endif // QT3_SUPPORT
149 
150  void setOutputFormat(OutputFormat format);
151  OutputFormat outputFormat() const;
152 
153  void setPrinterName(const QString &);
154  QString printerName() const;
155 
156  bool isValid() const;
157 
158  void setOutputFileName(const QString &);
159  QString outputFileName()const;
160 
161  void setPrintProgram(const QString &);
162  QString printProgram() const;
163 
164  void setDocName(const QString &);
165  QString docName() const;
166 
167  void setCreator(const QString &);
168  QString creator() const;
169 
170  void setOrientation(Orientation);
171  Orientation orientation() const;
172 
173  void setPageSize(PageSize);
174  PageSize pageSize() const;
175 
176  void setPaperSize(PaperSize);
177  PaperSize paperSize() const;
178 
179  void setPaperSize(const QSizeF &paperSize, Unit unit);
180  QSizeF paperSize(Unit unit) const;
181 
182  void setPageOrder(PageOrder);
183  PageOrder pageOrder() const;
184 
185  void setResolution(int);
186  int resolution() const;
187 
188  void setColorMode(ColorMode);
189  ColorMode colorMode() const;
190 
191  void setCollateCopies(bool collate);
192  bool collateCopies() const;
193 
194  void setFullPage(bool);
195  bool fullPage() const;
196 
197  void setNumCopies(int);
198  int numCopies() const;
199 
200  int actualNumCopies() const;
201 
202  void setCopyCount(int);
203  int copyCount() const;
204  bool supportsMultipleCopies() const;
205 
206  void setPaperSource(PaperSource);
207  PaperSource paperSource() const;
208 
209  void setDuplex(DuplexMode duplex);
210  DuplexMode duplex() const;
211 
212  QList<int> supportedResolutions() const;
213 
214 #ifdef Q_WS_WIN
215  QList<PaperSource> supportedPaperSources() const;
216 #endif
217 
218  void setFontEmbeddingEnabled(bool enable);
219  bool fontEmbeddingEnabled() const;
220 
221  void setDoubleSidedPrinting(bool enable);
222  bool doubleSidedPrinting() const;
223 
224 #ifdef Q_WS_WIN
225  void setWinPageSize(int winPageSize);
226  int winPageSize() const;
227 #endif
228 
229  QRect paperRect() const;
230  QRect pageRect() const;
231  QRectF paperRect(Unit) const;
232  QRectF pageRect(Unit) const;
233 
234 #if !defined(Q_WS_WIN) || defined(qdoc)
235  QString printerSelectionOption() const;
236  void setPrinterSelectionOption(const QString &);
237 #endif
238 
239  bool newPage();
240  bool abort();
241 
242  PrinterState printerState() const;
243 
244  QPaintEngine *paintEngine() const;
245  QPrintEngine *printEngine() const;
246 
247 #ifdef Q_WS_WIN
248  HDC getDC() const;
249  void releaseDC(HDC hdc) const;
250 #endif
251 
252  void setFromTo(int fromPage, int toPage);
253  int fromPage() const;
254  int toPage() const;
255 
256  void setPrintRange(PrintRange range);
257  PrintRange printRange() const;
258 
259  void setPageMargins(qreal left, qreal top, qreal right, qreal bottom, Unit unit);
260  void getPageMargins(qreal *left, qreal *top, qreal *right, qreal *bottom, Unit unit) const;
261 
262 #ifdef QT3_SUPPORT
263 #ifdef Q_WS_MAC
264  QT3_SUPPORT bool pageSetup(QWidget *parent = 0);
265  QT3_SUPPORT bool printSetup(QWidget *parent = 0);
266 #endif
267 
268  QT3_SUPPORT bool setup(QWidget *parent = 0);
269 
270  QT3_SUPPORT void setMinMax(int minPage, int maxPage);
271  QT3_SUPPORT int minPage() const;
272  QT3_SUPPORT int maxPage() const;
273 
274  QT3_SUPPORT void setCollateCopiesEnabled(bool);
275  QT3_SUPPORT bool collateCopiesEnabled() const;
276 
277  QT3_SUPPORT void setOptionEnabled(PrinterOption, bool enable);
278  QT3_SUPPORT bool isOptionEnabled(PrinterOption) const;
279 
280  inline QT3_SUPPORT QSize margins() const;
281  inline QT3_SUPPORT void margins(uint *top, uint *left, uint *bottom, uint *right) const;
282 
283  inline QT3_SUPPORT bool aborted() { return printerState() == Aborted; }
284 
285  QT3_SUPPORT void setOutputToFile(bool);
286  inline QT3_SUPPORT bool outputToFile() const { return !outputFileName().isEmpty(); }
287 #endif
288 
289 protected:
290  int metric(PaintDeviceMetric) const;
291  void setEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine);
292 
293 private:
294  void init(PrinterMode mode);
295 
297 
299 
306 };
307 
308 #ifdef QT3_SUPPORT
309 inline QSize QPrinter::margins() const
310 {
311  QRect page = pageRect();
312  QRect paper = paperRect();
313  return QSize(page.left() - paper.left(), page.top() - paper.top());
314 }
315 
316 inline void QPrinter::margins(uint *top, uint *left, uint *bottom, uint *right) const
317 {
318  QRect page = pageRect();
319  QRect paper = paperRect();
320  if (top)
321  *top = page.top() - paper.top();
322  if (left)
323  *left = page.left() - paper.left();
324  if (bottom)
325  *bottom = paper.bottom() - page.bottom();
326  if (right)
327  *right = paper.right() - page.right();
328 }
329 #endif
330 
331 #endif // QT_NO_PRINTER
332 
334 
336 
337 #endif // QPRINTER_H
Error
Definition: qaudio.h:58
PaperSize paperSize(QPrinter::PaperSize paperSize)
Definition: qpdf.cpp:905
double qreal
Definition: qglobal.h:1193
PrinterState
Definition: qprinter.h:119
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
PrinterMode
This enum describes the mode the printer should work in.
Definition: qprinter.h:70
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
Orientation
This enum type (not to be confused with Orientation) is used to specify each page&#39;s orientation...
Definition: qprinter.h:78
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual int devType() const
Definition: qpaintdevice.h:167
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
virtual void releaseDC(HDC hdc) const
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
Unit
This enum type is used to specify the measurement unit for page and paper sizes.
Definition: qprinter.h:129
DuplexMode
This enum is used to indicate whether printing will occur on one or both sides of each sheet of paper...
Definition: qprinter.h:139
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QPrintEngine class defines an interface for how QPrinter interacts with a given printing subsyste...
Definition: qprintengine.h:56
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static bool init
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
OutputFormat
The OutputFormat enum is used to describe the format QPrinter should use for printing.
Definition: qprinter.h:124
unsigned int uint
Definition: qglobal.h:996
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
The QPrinterInfo class gives access to information about existing printers.
Definition: qprinterinfo.h:58
virtual QPaintEngine * paintEngine() const =0
The QAbstractPrintDialog class provides a base implementation for print dialogs used to configure pri...
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
virtual HDC getDC() const
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
PaperSize
This enum type specifies what paper size QPrinter should use.
Definition: qprinter.h:91
ColorMode
This enum type is used to indicate whether QPrinter should print in color or not. ...
Definition: qprinter.h:100
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
virtual int metric(PaintDeviceMetric metric) const
PageOrder
This enum type is used by QPrinter to tell the application program how to print.
Definition: qprinter.h:97
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
PrintRange
Used to specify the print range selection option.
Definition: qprinter.h:127
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
PageSize
Use QPrinter::PaperSize instead.
Definition: qprinter.h:87
#define class
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
#define QT_END_HEADER
Definition: qglobal.h:137
static void setup()
Definition: qtextcodec.cpp:718
PaperSource
This enum type specifies what paper source QPrinter is to use.
Definition: qprinter.h:103