| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com) | 
|---|
| 5 | ** | 
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | 
|---|
| 7 | ** | 
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 9 | ** Commercial Usage | 
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 13 | ** a written agreement between you and Nokia. | 
|---|
| 14 | ** | 
|---|
| 15 | ** GNU Lesser General Public License Usage | 
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software | 
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
| 19 | ** packaging of this file.  Please review the following information to | 
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
| 22 | ** | 
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain | 
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL | 
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this | 
|---|
| 26 | ** package. | 
|---|
| 27 | ** | 
|---|
| 28 | ** GNU General Public License Usage | 
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 32 | ** packaging of this file.  Please review the following information to | 
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please | 
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #ifndef QPRINTER_H | 
|---|
| 43 | #define QPRINTER_H | 
|---|
| 44 |  | 
|---|
| 45 | #include <QtGui/qpaintdevice.h> | 
|---|
| 46 | #include <QtCore/qstring.h> | 
|---|
| 47 |  | 
|---|
| 48 | QT_BEGIN_HEADER | 
|---|
| 49 |  | 
|---|
| 50 | QT_BEGIN_NAMESPACE | 
|---|
| 51 |  | 
|---|
| 52 | QT_MODULE(Gui) | 
|---|
| 53 |  | 
|---|
| 54 | #ifndef QT_NO_PRINTER | 
|---|
| 55 |  | 
|---|
| 56 | #if defined(B0) | 
|---|
| 57 | #undef B0 // Terminal hang-up.  We assume that you do not want that. | 
|---|
| 58 | #endif | 
|---|
| 59 |  | 
|---|
| 60 | class QPrinterPrivate; | 
|---|
| 61 | class QPaintEngine; | 
|---|
| 62 | class QPrintEngine; | 
|---|
| 63 | class QPrinterInfo; | 
|---|
| 64 |  | 
|---|
| 65 | class Q_GUI_EXPORT QPrinter : public QPaintDevice | 
|---|
| 66 | { | 
|---|
| 67 | Q_DECLARE_PRIVATE(QPrinter) | 
|---|
| 68 | public: | 
|---|
| 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; | 
|---|
| 76 |  | 
|---|
| 77 | enum Orientation { Portrait, Landscape }; | 
|---|
| 78 |  | 
|---|
| 79 | #ifndef Q_QDOC | 
|---|
| 80 | enum PageSize { A4, B5, Letter, Legal, Executive, | 
|---|
| 81 | A0, A1, A2, A3, A5, A6, A7, A8, A9, B0, B1, | 
|---|
| 82 | B10, B2, B3, B4, B6, B7, B8, B9, C5E, Comm10E, | 
|---|
| 83 | DLE, Folio, Ledger, Tabloid, Custom, NPageSize = Custom, NPaperSize = Custom }; | 
|---|
| 84 | typedef PageSize PaperSize; | 
|---|
| 85 | #else | 
|---|
| 86 | enum PageSize { A4, B5, Letter, Legal, Executive, | 
|---|
| 87 | A0, A1, A2, A3, A5, A6, A7, A8, A9, B0, B1, | 
|---|
| 88 | B10, B2, B3, B4, B6, B7, B8, B9, C5E, Comm10E, | 
|---|
| 89 | DLE, Folio, Ledger, Tabloid, Custom, NPageSize = Custom }; | 
|---|
| 90 | enum PaperSize { A4, B5, Letter, Legal, Executive, | 
|---|
| 91 | A0, A1, A2, A3, A5, A6, A7, A8, A9, B0, B1, | 
|---|
| 92 | B10, B2, B3, B4, B6, B7, B8, B9, C5E, Comm10E, | 
|---|
| 93 | DLE, Folio, Ledger, Tabloid, Custom, NPageSize = Custom, NPaperSize = Custom }; | 
|---|
| 94 | #endif | 
|---|
| 95 |  | 
|---|
| 96 | enum PageOrder   { FirstPageFirst, | 
|---|
| 97 | LastPageFirst }; | 
|---|
| 98 |  | 
|---|
| 99 | enum ColorMode   { GrayScale, | 
|---|
| 100 | Color }; | 
|---|
| 101 |  | 
|---|
| 102 | enum PaperSource { OnlyOne, | 
|---|
| 103 | Lower, | 
|---|
| 104 | Middle, | 
|---|
| 105 | Manual, | 
|---|
| 106 | Envelope, | 
|---|
| 107 | EnvelopeManual, | 
|---|
| 108 | Auto, | 
|---|
| 109 | Tractor, | 
|---|
| 110 | SmallFormat, | 
|---|
| 111 | LargeFormat, | 
|---|
| 112 | LargeCapacity, | 
|---|
| 113 | Cassette, | 
|---|
| 114 | FormSource, | 
|---|
| 115 | MaxPageSource | 
|---|
| 116 | }; | 
|---|
| 117 |  | 
|---|
| 118 | enum PrinterState { Idle, | 
|---|
| 119 | Active, | 
|---|
| 120 | Aborted, | 
|---|
| 121 | Error }; | 
|---|
| 122 |  | 
|---|
| 123 | enum OutputFormat { NativeFormat, PdfFormat, PostScriptFormat }; | 
|---|
| 124 |  | 
|---|
| 125 | // ### Qt 5: Merge with QAbstractPrintDialog::PrintRange | 
|---|
| 126 | enum PrintRange { AllPages, Selection, PageRange }; | 
|---|
| 127 |  | 
|---|
| 128 | enum Unit { | 
|---|
| 129 | Millimeter, | 
|---|
| 130 | Point, | 
|---|
| 131 | Inch, | 
|---|
| 132 | Pica, | 
|---|
| 133 | Didot, | 
|---|
| 134 | Cicero, | 
|---|
| 135 | DevicePixel | 
|---|
| 136 | }; | 
|---|
| 137 |  | 
|---|
| 138 | enum DuplexMode { | 
|---|
| 139 | DuplexNone = 0, | 
|---|
| 140 | DuplexAuto, | 
|---|
| 141 | DuplexLongSide, | 
|---|
| 142 | DuplexShortSide | 
|---|
| 143 | }; | 
|---|
| 144 |  | 
|---|
| 145 | #ifdef QT3_SUPPORT | 
|---|
| 146 | enum PrinterOption { PrintToFile, PrintSelection, PrintPageRange }; | 
|---|
| 147 | #endif // QT3_SUPPORT | 
|---|
| 148 |  | 
|---|
| 149 | void setOutputFormat(OutputFormat format); | 
|---|
| 150 | OutputFormat outputFormat() const; | 
|---|
| 151 |  | 
|---|
| 152 | void setPrinterName(const QString &); | 
|---|
| 153 | QString printerName() const; | 
|---|
| 154 |  | 
|---|
| 155 | bool isValid() const; | 
|---|
| 156 |  | 
|---|
| 157 | void setOutputFileName(const QString &); | 
|---|
| 158 | QString outputFileName()const; | 
|---|
| 159 |  | 
|---|
| 160 | void setPrintProgram(const QString &); | 
|---|
| 161 | QString printProgram() const; | 
|---|
| 162 |  | 
|---|
| 163 | void setDocName(const QString &); | 
|---|
| 164 | QString docName() const; | 
|---|
| 165 |  | 
|---|
| 166 | void setCreator(const QString &); | 
|---|
| 167 | QString creator() const; | 
|---|
| 168 |  | 
|---|
| 169 | void setOrientation(Orientation); | 
|---|
| 170 | Orientation orientation() const; | 
|---|
| 171 |  | 
|---|
| 172 | void setPageSize(PageSize); | 
|---|
| 173 | PageSize pageSize() const; | 
|---|
| 174 |  | 
|---|
| 175 | void setPaperSize(PaperSize); | 
|---|
| 176 | PaperSize paperSize() const; | 
|---|
| 177 |  | 
|---|
| 178 | void setPaperSize(const QSizeF &paperSize, Unit unit); | 
|---|
| 179 | QSizeF paperSize(Unit unit) const; | 
|---|
| 180 |  | 
|---|
| 181 | void setPageOrder(PageOrder); | 
|---|
| 182 | PageOrder pageOrder() const; | 
|---|
| 183 |  | 
|---|
| 184 | void setResolution(int); | 
|---|
| 185 | int resolution() const; | 
|---|
| 186 |  | 
|---|
| 187 | void setColorMode(ColorMode); | 
|---|
| 188 | ColorMode colorMode() const; | 
|---|
| 189 |  | 
|---|
| 190 | void setCollateCopies(bool collate); | 
|---|
| 191 | bool collateCopies() const; | 
|---|
| 192 |  | 
|---|
| 193 | void setFullPage(bool); | 
|---|
| 194 | bool fullPage() const; | 
|---|
| 195 |  | 
|---|
| 196 | void setNumCopies(int); | 
|---|
| 197 | int numCopies() const; | 
|---|
| 198 |  | 
|---|
| 199 | void setPaperSource(PaperSource); | 
|---|
| 200 | PaperSource paperSource() const; | 
|---|
| 201 |  | 
|---|
| 202 | void setDuplex(DuplexMode duplex); | 
|---|
| 203 | DuplexMode duplex() const; | 
|---|
| 204 |  | 
|---|
| 205 | QList<int> supportedResolutions() const; | 
|---|
| 206 |  | 
|---|
| 207 | #ifdef Q_WS_WIN | 
|---|
| 208 | QList<PaperSource> supportedPaperSources() const; | 
|---|
| 209 | #endif | 
|---|
| 210 |  | 
|---|
| 211 | void setFontEmbeddingEnabled(bool enable); | 
|---|
| 212 | bool fontEmbeddingEnabled() const; | 
|---|
| 213 |  | 
|---|
| 214 | void setDoubleSidedPrinting(bool enable); | 
|---|
| 215 | bool doubleSidedPrinting() const; | 
|---|
| 216 |  | 
|---|
| 217 | #ifdef Q_WS_WIN | 
|---|
| 218 | void setWinPageSize(int winPageSize); | 
|---|
| 219 | int winPageSize() const; | 
|---|
| 220 | #endif | 
|---|
| 221 |  | 
|---|
| 222 | QRect paperRect() const; | 
|---|
| 223 | QRect pageRect() const; | 
|---|
| 224 | QRectF paperRect(Unit) const; | 
|---|
| 225 | QRectF pageRect(Unit) const; | 
|---|
| 226 |  | 
|---|
| 227 | #if !defined(Q_WS_WIN) || defined(qdoc) | 
|---|
| 228 | QString printerSelectionOption() const; | 
|---|
| 229 | void setPrinterSelectionOption(const QString &); | 
|---|
| 230 | #endif | 
|---|
| 231 |  | 
|---|
| 232 | bool newPage(); | 
|---|
| 233 | bool abort(); | 
|---|
| 234 |  | 
|---|
| 235 | PrinterState printerState() const; | 
|---|
| 236 |  | 
|---|
| 237 | QPaintEngine *paintEngine() const; | 
|---|
| 238 | QPrintEngine *printEngine() const; | 
|---|
| 239 |  | 
|---|
| 240 | #ifdef Q_WS_WIN | 
|---|
| 241 | HDC getDC() const; | 
|---|
| 242 | void releaseDC(HDC hdc) const; | 
|---|
| 243 | #endif | 
|---|
| 244 |  | 
|---|
| 245 | void setFromTo(int fromPage, int toPage); | 
|---|
| 246 | int fromPage() const; | 
|---|
| 247 | int toPage() const; | 
|---|
| 248 |  | 
|---|
| 249 | void setPrintRange(PrintRange range); | 
|---|
| 250 | PrintRange printRange() const; | 
|---|
| 251 |  | 
|---|
| 252 | void setPageMargins(qreal left, qreal top, qreal right, qreal bottom, Unit unit); | 
|---|
| 253 | void getPageMargins(qreal *left, qreal *top, qreal *right, qreal *bottom, Unit unit) const; | 
|---|
| 254 |  | 
|---|
| 255 | #ifdef QT3_SUPPORT | 
|---|
| 256 | #ifdef Q_WS_MAC | 
|---|
| 257 | QT3_SUPPORT bool pageSetup(QWidget *parent = 0); | 
|---|
| 258 | QT3_SUPPORT bool printSetup(QWidget *parent = 0); | 
|---|
| 259 | #endif | 
|---|
| 260 |  | 
|---|
| 261 | QT3_SUPPORT bool setup(QWidget *parent = 0); | 
|---|
| 262 |  | 
|---|
| 263 | QT3_SUPPORT void setMinMax(int minPage, int maxPage); | 
|---|
| 264 | QT3_SUPPORT int minPage() const; | 
|---|
| 265 | QT3_SUPPORT int maxPage() const; | 
|---|
| 266 |  | 
|---|
| 267 | QT3_SUPPORT void setCollateCopiesEnabled(bool); | 
|---|
| 268 | QT3_SUPPORT bool collateCopiesEnabled() const; | 
|---|
| 269 |  | 
|---|
| 270 | QT3_SUPPORT void setOptionEnabled(PrinterOption, bool enable); | 
|---|
| 271 | QT3_SUPPORT bool isOptionEnabled(PrinterOption) const; | 
|---|
| 272 |  | 
|---|
| 273 | inline QT3_SUPPORT QSize margins() const; | 
|---|
| 274 | inline QT3_SUPPORT void margins(uint *top, uint *left, uint *bottom, uint *right) const; | 
|---|
| 275 |  | 
|---|
| 276 | inline QT3_SUPPORT bool aborted() { return printerState() == Aborted; } | 
|---|
| 277 |  | 
|---|
| 278 | QT3_SUPPORT void setOutputToFile(bool); | 
|---|
| 279 | inline QT3_SUPPORT bool outputToFile() const { return !outputFileName().isEmpty(); } | 
|---|
| 280 | #endif | 
|---|
| 281 |  | 
|---|
| 282 | protected: | 
|---|
| 283 | int metric(PaintDeviceMetric) const; | 
|---|
| 284 | void setEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine); | 
|---|
| 285 |  | 
|---|
| 286 | private: | 
|---|
| 287 | void init(PrinterMode mode); | 
|---|
| 288 |  | 
|---|
| 289 | Q_DISABLE_COPY(QPrinter) | 
|---|
| 290 |  | 
|---|
| 291 | QPrinterPrivate *d_ptr; | 
|---|
| 292 |  | 
|---|
| 293 | friend class QPrintDialogPrivate; | 
|---|
| 294 | friend class QAbstractPrintDialog; | 
|---|
| 295 | friend class QAbstractPrintDialogPrivate; | 
|---|
| 296 | friend class QPrintPreviewWidgetPrivate; | 
|---|
| 297 | friend class QTextDocument; | 
|---|
| 298 | friend class QPageSetupWidget; | 
|---|
| 299 | }; | 
|---|
| 300 |  | 
|---|
| 301 | #ifdef QT3_SUPPORT | 
|---|
| 302 | inline QSize QPrinter::margins() const | 
|---|
| 303 | { | 
|---|
| 304 | QRect page = pageRect(); | 
|---|
| 305 | QRect paper = paperRect(); | 
|---|
| 306 | return QSize(page.left() - paper.left(), page.top() - paper.top()); | 
|---|
| 307 | } | 
|---|
| 308 |  | 
|---|
| 309 | inline void QPrinter::margins(uint *top, uint *left, uint *bottom, uint *right) const | 
|---|
| 310 | { | 
|---|
| 311 | QRect page = pageRect(); | 
|---|
| 312 | QRect paper = paperRect(); | 
|---|
| 313 | if (top) | 
|---|
| 314 | *top = page.top() - paper.top(); | 
|---|
| 315 | if (left) | 
|---|
| 316 | *left = page.left() - paper.left(); | 
|---|
| 317 | if (bottom) | 
|---|
| 318 | *bottom = paper.bottom() - page.bottom(); | 
|---|
| 319 | if (right) | 
|---|
| 320 | *right = paper.right() - page.right(); | 
|---|
| 321 | } | 
|---|
| 322 | #endif | 
|---|
| 323 |  | 
|---|
| 324 | #endif // QT_NO_PRINTER | 
|---|
| 325 |  | 
|---|
| 326 | QT_END_NAMESPACE | 
|---|
| 327 |  | 
|---|
| 328 | QT_END_HEADER | 
|---|
| 329 |  | 
|---|
| 330 | #endif // QPRINTER_H | 
|---|