src/gui/painting/qprinter.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the QtGui module of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef QPRINTER_H
00025 #define QPRINTER_H
00026 
00027 #include <QtGui/qpaintdevice.h>
00028 #include <QtCore/qstring.h>
00029 
00030 QT_BEGIN_HEADER
00031 
00032 QT_MODULE(Gui)
00033 
00034 #ifndef QT_NO_PRINTER
00035 
00036 #if defined(B0)
00037 #undef B0 // Terminal hang-up.  We assume that you do not want that.
00038 #endif
00039 
00040 class QPrinterPrivate;
00041 class QPaintEngine;
00042 class QPrintEngine;
00043 
00044 class Q_GUI_EXPORT QPrinter : public QPaintDevice
00045 {
00046     Q_DECLARE_PRIVATE(QPrinter)
00047 public:
00048     enum PrinterMode { ScreenResolution, PrinterResolution, HighResolution };
00049 
00050     explicit QPrinter(PrinterMode mode = ScreenResolution);
00051     ~QPrinter();
00052 
00053     int devType() const;
00054 
00055     enum Orientation { Portrait, Landscape };
00056 
00057     enum PageSize    { A4, B5, Letter, Legal, Executive,
00058            A0, A1, A2, A3, A5, A6, A7, A8, A9, B0, B1,
00059            B10, B2, B3, B4, B6, B7, B8, B9, C5E, Comm10E,
00060            DLE, Folio, Ledger, Tabloid, Custom, NPageSize = Custom };
00061 
00062     enum PageOrder   { FirstPageFirst,
00063            LastPageFirst };
00064 
00065     enum ColorMode   { GrayScale,
00066            Color };
00067 
00068     enum PaperSource { OnlyOne,
00069            Lower,
00070            Middle,
00071            Manual,
00072            Envelope,
00073                        EnvelopeManual,
00074            Auto,
00075            Tractor,
00076            SmallFormat,
00077                        LargeFormat,
00078            LargeCapacity,
00079            Cassette,
00080            FormSource };
00081 
00082     enum PrinterState { Idle,
00083                         Active,
00084                         Aborted,
00085                         Error };
00086 
00087     enum OutputFormat { NativeFormat, PdfFormat, PostScriptFormat };
00088 
00089     // ### Qt 5: Merge with QAbstractPrintDialog::PrintRange
00090     enum PrintRange { AllPages, Selection, PageRange };
00091 
00092 #ifdef QT3_SUPPORT
00093     enum PrinterOption { PrintToFile, PrintSelection, PrintPageRange };
00094 #endif // QT3_SUPPORT
00095 
00096     void setOutputFormat(OutputFormat format);
00097     OutputFormat outputFormat() const;
00098 
00099     void setPrinterName(const QString &);
00100     QString printerName() const;
00101 
00102     void setOutputFileName(const QString &);
00103     QString outputFileName()const;
00104 
00105     void setPrintProgram(const QString &);
00106     QString printProgram() const;
00107 
00108     void setDocName(const QString &);
00109     QString docName() const;
00110 
00111     void setCreator(const QString &);
00112     QString creator() const;
00113 
00114     void setOrientation(Orientation);
00115     Orientation orientation() const;
00116 
00117     void setPageSize(PageSize);
00118     PageSize pageSize() const;
00119 
00120     void setPageOrder(PageOrder);
00121     PageOrder pageOrder() const;
00122 
00123     void setResolution(int);
00124     int resolution() const;
00125 
00126     void setColorMode(ColorMode);
00127     ColorMode colorMode() const;
00128 
00129     void setCollateCopies(bool collate);
00130     bool collateCopies() const;
00131 
00132     void setFullPage(bool);
00133     bool fullPage() const;
00134 
00135     void setNumCopies(int);
00136     int numCopies() const;
00137 
00138     void setPaperSource(PaperSource);
00139     PaperSource paperSource() const;
00140 
00141     QList<int> supportedResolutions() const;
00142 
00143     void setFontEmbeddingEnabled(bool enable);
00144     bool fontEmbeddingEnabled() const;
00145 
00146     void setDoubleSidedPrinting(bool enable);
00147     bool doubleSidedPrinting() const;
00148 
00149 #ifdef Q_WS_WIN
00150     void setWinPageSize(int winPageSize);
00151     int winPageSize() const;
00152 #endif
00153 
00154     QRect paperRect() const;
00155     QRect pageRect() const;
00156 
00157 #if !defined(Q_WS_WIN) || defined(qdoc)
00158     QString printerSelectionOption() const;
00159     void setPrinterSelectionOption(const QString &);
00160 #endif
00161 
00162     bool newPage();
00163     bool abort();
00164 
00165     PrinterState printerState() const;
00166 
00167     QPaintEngine *paintEngine() const;
00168     QPrintEngine *printEngine() const;
00169 
00170 #ifdef Q_WS_WIN
00171     HDC getDC() const;
00172     void releaseDC(HDC hdc) const;
00173 #endif
00174 
00175     void setFromTo(int fromPage, int toPage);
00176     int fromPage() const;
00177     int toPage() const;
00178 
00179 #ifndef QT_NO_PRINTDIALOG
00180     void setPrintRange(PrintRange range);
00181     PrintRange printRange() const;
00182 #endif
00183 
00184 #ifdef QT3_SUPPORT
00185 #ifdef Q_WS_MAC
00186     QT3_SUPPORT bool pageSetup(QWidget *parent = 0);
00187     QT3_SUPPORT bool printSetup(QWidget *parent = 0);
00188 #endif
00189 
00190     QT3_SUPPORT bool setup(QWidget *parent = 0);
00191 
00192     QT3_SUPPORT void setMinMax(int minPage, int maxPage);
00193     QT3_SUPPORT int minPage() const;
00194     QT3_SUPPORT int maxPage() const;
00195 
00196     QT3_SUPPORT void setCollateCopiesEnabled(bool);
00197     QT3_SUPPORT bool collateCopiesEnabled() const;
00198 
00199     QT3_SUPPORT void setOptionEnabled(PrinterOption, bool enable);
00200     QT3_SUPPORT bool isOptionEnabled(PrinterOption) const;
00201 
00202     inline QT3_SUPPORT QSize margins() const;
00203     inline QT3_SUPPORT void margins(uint *top, uint *left, uint *bottom, uint *right) const;
00204 
00205     inline QT3_SUPPORT bool aborted() { return printerState() == Aborted; }
00206 
00207     QT3_SUPPORT void setOutputToFile(bool);
00208     inline QT3_SUPPORT bool outputToFile() const { return !outputFileName().isEmpty(); }
00209 #endif
00210 
00211 protected:
00212     int metric(PaintDeviceMetric) const;
00213     void setEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine);
00214 
00215 private:
00216     Q_DISABLE_COPY(QPrinter)
00217 
00218     QPrinterPrivate *d_ptr;
00219 
00220     friend class QPrintDialogWin;
00221     friend class QAbstractPrintDialog;
00222 };
00223 
00224 #ifdef QT3_SUPPORT
00225 inline QSize QPrinter::margins() const
00226 {
00227     QRect page = pageRect();
00228     QRect paper = paperRect();
00229     return QSize(page.left() - paper.left(), page.top() - paper.top());
00230 }
00231 
00232 inline void QPrinter::margins(uint *top, uint *left, uint *bottom, uint *right) const
00233 {
00234     QRect page = pageRect();
00235     QRect paper = paperRect();
00236     if (top)
00237         *top = page.top() - paper.top();
00238     if (left)
00239         *left = page.left() - paper.left();
00240     if (bottom)
00241         *bottom = paper.bottom() - page.bottom();
00242     if (right)
00243         *right = paper.right() - page.right();
00244 }
00245 #endif
00246 
00247 #endif // QT_NO_PRINTER
00248 
00249 QT_END_HEADER
00250 
00251 #endif // QPRINTER_H

Generated on Thu Mar 15 11:55:35 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1