| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 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 have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at qt-info@nokia.com.
|
|---|
| 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 |
|
|---|
| 49 | QT_BEGIN_HEADER
|
|---|
| 50 |
|
|---|
| 51 | QT_BEGIN_NAMESPACE
|
|---|
| 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 |
|
|---|
| 66 | class Q_GUI_EXPORT QPrinter : public QPaintDevice
|
|---|
| 67 | {
|
|---|
| 68 | Q_DECLARE_PRIVATE(QPrinter)
|
|---|
| 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 |
|
|---|
| 100 | enum ColorMode { GrayScale,
|
|---|
| 101 | Color };
|
|---|
| 102 |
|
|---|
| 103 | enum PaperSource { OnlyOne,
|
|---|
| 104 | Lower,
|
|---|
| 105 | Middle,
|
|---|
| 106 | Manual,
|
|---|
| 107 | Envelope,
|
|---|
| 108 | EnvelopeManual,
|
|---|
| 109 | Auto,
|
|---|
| 110 | Tractor,
|
|---|
| 111 | SmallFormat,
|
|---|
| 112 | LargeFormat,
|
|---|
| 113 | LargeCapacity,
|
|---|
| 114 | Cassette,
|
|---|
| 115 | FormSource,
|
|---|
| 116 | MaxPageSource
|
|---|
| 117 | };
|
|---|
| 118 |
|
|---|
| 119 | enum PrinterState { Idle,
|
|---|
| 120 | Active,
|
|---|
| 121 | Aborted,
|
|---|
| 122 | Error };
|
|---|
| 123 |
|
|---|
| 124 | enum OutputFormat { NativeFormat, PdfFormat, PostScriptFormat };
|
|---|
| 125 |
|
|---|
| 126 | // ### Qt 5: Merge with QAbstractPrintDialog::PrintRange
|
|---|
| 127 | enum PrintRange { AllPages, Selection, PageRange };
|
|---|
| 128 |
|
|---|
| 129 | enum Unit {
|
|---|
| 130 | Millimeter,
|
|---|
| 131 | Point,
|
|---|
| 132 | Inch,
|
|---|
| 133 | Pica,
|
|---|
| 134 | Didot,
|
|---|
| 135 | Cicero,
|
|---|
| 136 | DevicePixel
|
|---|
| 137 | };
|
|---|
| 138 |
|
|---|
| 139 | enum DuplexMode {
|
|---|
| 140 | DuplexNone = 0,
|
|---|
| 141 | DuplexAuto,
|
|---|
| 142 | DuplexLongSide,
|
|---|
| 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 setPaperSource(PaperSource);
|
|---|
| 203 | PaperSource paperSource() const;
|
|---|
| 204 |
|
|---|
| 205 | void setDuplex(DuplexMode duplex);
|
|---|
| 206 | DuplexMode duplex() const;
|
|---|
| 207 |
|
|---|
| 208 | QList<int> supportedResolutions() const;
|
|---|
| 209 |
|
|---|
| 210 | #ifdef Q_WS_WIN
|
|---|
| 211 | QList<PaperSource> supportedPaperSources() const;
|
|---|
| 212 | #endif
|
|---|
| 213 |
|
|---|
| 214 | void setFontEmbeddingEnabled(bool enable);
|
|---|
| 215 | bool fontEmbeddingEnabled() const;
|
|---|
| 216 |
|
|---|
| 217 | void setDoubleSidedPrinting(bool enable);
|
|---|
| 218 | bool doubleSidedPrinting() const;
|
|---|
| 219 |
|
|---|
| 220 | #ifdef Q_WS_WIN
|
|---|
| 221 | void setWinPageSize(int winPageSize);
|
|---|
| 222 | int winPageSize() const;
|
|---|
| 223 | #endif
|
|---|
| 224 |
|
|---|
| 225 | QRect paperRect() const;
|
|---|
| 226 | QRect pageRect() const;
|
|---|
| 227 | QRectF paperRect(Unit) const;
|
|---|
| 228 | QRectF pageRect(Unit) const;
|
|---|
| 229 |
|
|---|
| 230 | #if !defined(Q_WS_WIN) || defined(qdoc)
|
|---|
| 231 | QString printerSelectionOption() const;
|
|---|
| 232 | void setPrinterSelectionOption(const QString &);
|
|---|
| 233 | #endif
|
|---|
| 234 |
|
|---|
| 235 | bool newPage();
|
|---|
| 236 | bool abort();
|
|---|
| 237 |
|
|---|
| 238 | PrinterState printerState() const;
|
|---|
| 239 |
|
|---|
| 240 | QPaintEngine *paintEngine() const;
|
|---|
| 241 | QPrintEngine *printEngine() const;
|
|---|
| 242 |
|
|---|
| 243 | #ifdef Q_WS_WIN
|
|---|
| 244 | HDC getDC() const;
|
|---|
| 245 | void releaseDC(HDC hdc) const;
|
|---|
| 246 | #endif
|
|---|
| 247 |
|
|---|
| 248 | void setFromTo(int fromPage, int toPage);
|
|---|
| 249 | int fromPage() const;
|
|---|
| 250 | int toPage() const;
|
|---|
| 251 |
|
|---|
| 252 | void setPrintRange(PrintRange range);
|
|---|
| 253 | PrintRange printRange() const;
|
|---|
| 254 |
|
|---|
| 255 | void setPageMargins(qreal left, qreal top, qreal right, qreal bottom, Unit unit);
|
|---|
| 256 | void getPageMargins(qreal *left, qreal *top, qreal *right, qreal *bottom, Unit unit) const;
|
|---|
| 257 |
|
|---|
| 258 | #ifdef QT3_SUPPORT
|
|---|
| 259 | #ifdef Q_WS_MAC
|
|---|
| 260 | QT3_SUPPORT bool pageSetup(QWidget *parent = 0);
|
|---|
| 261 | QT3_SUPPORT bool printSetup(QWidget *parent = 0);
|
|---|
| 262 | #endif
|
|---|
| 263 |
|
|---|
| 264 | QT3_SUPPORT bool setup(QWidget *parent = 0);
|
|---|
| 265 |
|
|---|
| 266 | QT3_SUPPORT void setMinMax(int minPage, int maxPage);
|
|---|
| 267 | QT3_SUPPORT int minPage() const;
|
|---|
| 268 | QT3_SUPPORT int maxPage() const;
|
|---|
| 269 |
|
|---|
| 270 | QT3_SUPPORT void setCollateCopiesEnabled(bool);
|
|---|
| 271 | QT3_SUPPORT bool collateCopiesEnabled() const;
|
|---|
| 272 |
|
|---|
| 273 | QT3_SUPPORT void setOptionEnabled(PrinterOption, bool enable);
|
|---|
| 274 | QT3_SUPPORT bool isOptionEnabled(PrinterOption) const;
|
|---|
| 275 |
|
|---|
| 276 | inline QT3_SUPPORT QSize margins() const;
|
|---|
| 277 | inline QT3_SUPPORT void margins(uint *top, uint *left, uint *bottom, uint *right) const;
|
|---|
| 278 |
|
|---|
| 279 | inline QT3_SUPPORT bool aborted() { return printerState() == Aborted; }
|
|---|
| 280 |
|
|---|
| 281 | QT3_SUPPORT void setOutputToFile(bool);
|
|---|
| 282 | inline QT3_SUPPORT bool outputToFile() const { return !outputFileName().isEmpty(); }
|
|---|
| 283 | #endif
|
|---|
| 284 |
|
|---|
| 285 | protected:
|
|---|
| 286 | int metric(PaintDeviceMetric) const;
|
|---|
| 287 | void setEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine);
|
|---|
| 288 |
|
|---|
| 289 | private:
|
|---|
| 290 | void init(PrinterMode mode);
|
|---|
| 291 |
|
|---|
| 292 | Q_DISABLE_COPY(QPrinter)
|
|---|
| 293 |
|
|---|
| 294 | QScopedPointer<QPrinterPrivate> d_ptr;
|
|---|
| 295 |
|
|---|
| 296 | friend class QPrintDialogPrivate;
|
|---|
| 297 | friend class QAbstractPrintDialog;
|
|---|
| 298 | friend class QAbstractPrintDialogPrivate;
|
|---|
| 299 | friend class QPrintPreviewWidgetPrivate;
|
|---|
| 300 | friend class QTextDocument;
|
|---|
| 301 | friend class QPageSetupWidget;
|
|---|
| 302 | };
|
|---|
| 303 |
|
|---|
| 304 | #ifdef QT3_SUPPORT
|
|---|
| 305 | inline QSize QPrinter::margins() const
|
|---|
| 306 | {
|
|---|
| 307 | QRect page = pageRect();
|
|---|
| 308 | QRect paper = paperRect();
|
|---|
| 309 | return QSize(page.left() - paper.left(), page.top() - paper.top());
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | inline void QPrinter::margins(uint *top, uint *left, uint *bottom, uint *right) const
|
|---|
| 313 | {
|
|---|
| 314 | QRect page = pageRect();
|
|---|
| 315 | QRect paper = paperRect();
|
|---|
| 316 | if (top)
|
|---|
| 317 | *top = page.top() - paper.top();
|
|---|
| 318 | if (left)
|
|---|
| 319 | *left = page.left() - paper.left();
|
|---|
| 320 | if (bottom)
|
|---|
| 321 | *bottom = paper.bottom() - page.bottom();
|
|---|
| 322 | if (right)
|
|---|
| 323 | *right = paper.right() - page.right();
|
|---|
| 324 | }
|
|---|
| 325 | #endif
|
|---|
| 326 |
|
|---|
| 327 | #endif // QT_NO_PRINTER
|
|---|
| 328 |
|
|---|
| 329 | QT_END_NAMESPACE
|
|---|
| 330 |
|
|---|
| 331 | QT_END_HEADER
|
|---|
| 332 |
|
|---|
| 333 | #endif // QPRINTER_H
|
|---|