qprinter.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QPRINTER_H
00043 #define QPRINTER_H
00044 
00045 #include <QtCore/qstring.h>
00046 #include <QtCore/qscopedpointer.h>
00047 #include <QtGui/qpaintdevice.h>
00048 
00049 QT_BEGIN_HEADER
00050 
00051 QT_BEGIN_NAMESPACE
00052 
00053 QT_MODULE(Gui)
00054 
00055 #ifndef QT_NO_PRINTER
00056 
00057 #if defined(B0)
00058 #undef B0 // Terminal hang-up.  We assume that you do not want that.
00059 #endif
00060 
00061 class QPrinterPrivate;
00062 class QPaintEngine;
00063 class QPrintEngine;
00064 class QPrinterInfo;
00065 
00066 class Q_GUI_EXPORT QPrinter : public QPaintDevice
00067 {
00068     Q_DECLARE_PRIVATE(QPrinter)
00069 public:
00070     enum PrinterMode { ScreenResolution, PrinterResolution, HighResolution };
00071 
00072     explicit QPrinter(PrinterMode mode = ScreenResolution);
00073     explicit QPrinter(const QPrinterInfo& printer, PrinterMode mode = ScreenResolution);
00074     ~QPrinter();
00075 
00076     int devType() const;
00077 
00078     enum Orientation { Portrait, Landscape };
00079 
00080 #ifndef Q_QDOC
00081     enum PageSize { A4, B5, Letter, Legal, Executive,
00082                     A0, A1, A2, A3, A5, A6, A7, A8, A9, B0, B1,
00083                     B10, B2, B3, B4, B6, B7, B8, B9, C5E, Comm10E,
00084                     DLE, Folio, Ledger, Tabloid, Custom, NPageSize = Custom, NPaperSize = Custom };
00085     typedef PageSize PaperSize;
00086 #else
00087     enum PageSize { A4, B5, Letter, Legal, Executive,
00088                     A0, A1, A2, A3, A5, A6, A7, A8, A9, B0, B1,
00089                     B10, B2, B3, B4, B6, B7, B8, B9, C5E, Comm10E,
00090                     DLE, Folio, Ledger, Tabloid, Custom, NPageSize = Custom };
00091     enum PaperSize { A4, B5, Letter, Legal, Executive,
00092                      A0, A1, A2, A3, A5, A6, A7, A8, A9, B0, B1,
00093                      B10, B2, B3, B4, B6, B7, B8, B9, C5E, Comm10E,
00094                      DLE, Folio, Ledger, Tabloid, Custom, NPageSize = Custom, NPaperSize = Custom };
00095 #endif
00096 
00097     enum PageOrder   { FirstPageFirst,
00098                        LastPageFirst };
00099 
00100     enum ColorMode   { GrayScale,
00101                        Color };
00102 
00103     enum PaperSource { OnlyOne,
00104                        Lower,
00105                        Middle,
00106                        Manual,
00107                        Envelope,
00108                        EnvelopeManual,
00109                        Auto,
00110                        Tractor,
00111                        SmallFormat,
00112                        LargeFormat,
00113                        LargeCapacity,
00114                        Cassette,
00115                        FormSource,
00116                        MaxPageSource
00117     };
00118 
00119     enum PrinterState { Idle,
00120                         Active,
00121                         Aborted,
00122                         Error };
00123 
00124     enum OutputFormat { NativeFormat, PdfFormat, PostScriptFormat };
00125 
00126     // ### Qt 5: Merge with QAbstractPrintDialog::PrintRange
00127     enum PrintRange { AllPages, Selection, PageRange, CurrentPage };
00128 
00129     enum Unit {
00130         Millimeter,
00131         Point,
00132         Inch,
00133         Pica,
00134         Didot,
00135         Cicero,
00136         DevicePixel
00137     };
00138 
00139     enum DuplexMode {
00140         DuplexNone = 0,
00141         DuplexAuto,
00142         DuplexLongSide,
00143         DuplexShortSide
00144     };
00145 
00146 #ifdef QT3_SUPPORT
00147     enum PrinterOption { PrintToFile, PrintSelection, PrintPageRange };
00148 #endif // QT3_SUPPORT
00149 
00150     void setOutputFormat(OutputFormat format);
00151     OutputFormat outputFormat() const;
00152 
00153     void setPrinterName(const QString &);
00154     QString printerName() const;
00155 
00156     bool isValid() const;
00157 
00158     void setOutputFileName(const QString &);
00159     QString outputFileName()const;
00160 
00161     void setPrintProgram(const QString &);
00162     QString printProgram() const;
00163 
00164     void setDocName(const QString &);
00165     QString docName() const;
00166 
00167     void setCreator(const QString &);
00168     QString creator() const;
00169 
00170     void setOrientation(Orientation);
00171     Orientation orientation() const;
00172 
00173     void setPageSize(PageSize);
00174     PageSize pageSize() const;
00175 
00176     void setPaperSize(PaperSize);
00177     PaperSize paperSize() const;
00178 
00179     void setPaperSize(const QSizeF &paperSize, Unit unit);
00180     QSizeF paperSize(Unit unit) const;
00181 
00182     void setPageOrder(PageOrder);
00183     PageOrder pageOrder() const;
00184 
00185     void setResolution(int);
00186     int resolution() const;
00187 
00188     void setColorMode(ColorMode);
00189     ColorMode colorMode() const;
00190 
00191     void setCollateCopies(bool collate);
00192     bool collateCopies() const;
00193 
00194     void setFullPage(bool);
00195     bool fullPage() const;
00196 
00197     void setNumCopies(int);
00198     int numCopies() const;
00199 
00200     int actualNumCopies() const;
00201 
00202     void setCopyCount(int);
00203     int copyCount() const;
00204     bool supportsMultipleCopies() const;
00205 
00206     void setPaperSource(PaperSource);
00207     PaperSource paperSource() const;
00208 
00209     void setDuplex(DuplexMode duplex);
00210     DuplexMode duplex() const;
00211 
00212     QList<int> supportedResolutions() const;
00213 
00214 #ifdef Q_WS_WIN
00215     QList<PaperSource> supportedPaperSources() const;
00216 #endif
00217 
00218     void setFontEmbeddingEnabled(bool enable);
00219     bool fontEmbeddingEnabled() const;
00220 
00221     void setDoubleSidedPrinting(bool enable);
00222     bool doubleSidedPrinting() const;
00223 
00224 #ifdef Q_WS_WIN
00225     void setWinPageSize(int winPageSize);
00226     int winPageSize() const;
00227 #endif
00228 
00229     QRect paperRect() const;
00230     QRect pageRect() const;
00231     QRectF paperRect(Unit) const;
00232     QRectF pageRect(Unit) const;
00233 
00234 #if !defined(Q_WS_WIN) || defined(qdoc)
00235     QString printerSelectionOption() const;
00236     void setPrinterSelectionOption(const QString &);
00237 #endif
00238 
00239     bool newPage();
00240     bool abort();
00241 
00242     PrinterState printerState() const;
00243 
00244     QPaintEngine *paintEngine() const;
00245     QPrintEngine *printEngine() const;
00246 
00247 #ifdef Q_WS_WIN
00248     HDC getDC() const;
00249     void releaseDC(HDC hdc) const;
00250 #endif
00251 
00252     void setFromTo(int fromPage, int toPage);
00253     int fromPage() const;
00254     int toPage() const;
00255 
00256     void setPrintRange(PrintRange range);
00257     PrintRange printRange() const;
00258 
00259     void setPageMargins(qreal left, qreal top, qreal right, qreal bottom, Unit unit);
00260     void getPageMargins(qreal *left, qreal *top, qreal *right, qreal *bottom, Unit unit) const;
00261 
00262 #ifdef QT3_SUPPORT
00263 #ifdef Q_WS_MAC
00264     QT3_SUPPORT bool pageSetup(QWidget *parent = 0);
00265     QT3_SUPPORT bool printSetup(QWidget *parent = 0);
00266 #endif
00267 
00268     QT3_SUPPORT bool setup(QWidget *parent = 0);
00269 
00270     QT3_SUPPORT void setMinMax(int minPage, int maxPage);
00271     QT3_SUPPORT int minPage() const;
00272     QT3_SUPPORT int maxPage() const;
00273 
00274     QT3_SUPPORT void setCollateCopiesEnabled(bool);
00275     QT3_SUPPORT bool collateCopiesEnabled() const;
00276 
00277     QT3_SUPPORT void setOptionEnabled(PrinterOption, bool enable);
00278     QT3_SUPPORT bool isOptionEnabled(PrinterOption) const;
00279 
00280     inline QT3_SUPPORT QSize margins() const;
00281     inline QT3_SUPPORT void margins(uint *top, uint *left, uint *bottom, uint *right) const;
00282 
00283     inline QT3_SUPPORT bool aborted() { return printerState() == Aborted; }
00284 
00285     QT3_SUPPORT void setOutputToFile(bool);
00286     inline QT3_SUPPORT bool outputToFile() const { return !outputFileName().isEmpty(); }
00287 #endif
00288 
00289 protected:
00290     int metric(PaintDeviceMetric) const;
00291     void setEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine);
00292 
00293 private:
00294     void init(PrinterMode mode);
00295 
00296     Q_DISABLE_COPY(QPrinter)
00297 
00298     QScopedPointer<QPrinterPrivate> d_ptr;
00299 
00300     friend class QPrintDialogPrivate;
00301     friend class QAbstractPrintDialog;
00302     friend class QAbstractPrintDialogPrivate;
00303     friend class QPrintPreviewWidgetPrivate;
00304     friend class QTextDocument;
00305     friend class QPageSetupWidget;
00306 };
00307 
00308 #ifdef QT3_SUPPORT
00309 inline QSize QPrinter::margins() const
00310 {
00311     QRect page = pageRect();
00312     QRect paper = paperRect();
00313     return QSize(page.left() - paper.left(), page.top() - paper.top());
00314 }
00315 
00316 inline void QPrinter::margins(uint *top, uint *left, uint *bottom, uint *right) const
00317 {
00318     QRect page = pageRect();
00319     QRect paper = paperRect();
00320     if (top)
00321         *top = page.top() - paper.top();
00322     if (left)
00323         *left = page.left() - paper.left();
00324     if (bottom)
00325         *bottom = paper.bottom() - page.bottom();
00326     if (right)
00327         *right = paper.right() - page.right();
00328 }
00329 #endif
00330 
00331 #endif // QT_NO_PRINTER
00332 
00333 QT_END_NAMESPACE
00334 
00335 QT_END_HEADER
00336 
00337 #endif // QPRINTER_H