⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qprinter.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qprinter_p.h"#include "qprinter.h"#include "qprintengine.h"#include "qlist.h"#include <qpagesetupdialog.h>#include <qapplication.h>#include <qfileinfo.h>#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)#include "private/qcups_p.h"#endif#ifndef QT_NO_PRINTER#if defined (Q_WS_WIN)#include <private/qprintengine_win_p.h>#elif defined (Q_WS_MAC)#include <private/qprintengine_mac_p.h>#elif defined (QTOPIA_PRINTENGINE)#include <private/qprintengine_qws_p.h>#endif#include <private/qprintengine_ps_p.h>#ifndef QT_NO_PDF#include "qprintengine_pdf_p.h"#endif#if defined(QT3_SUPPORT)#  include "qprintdialog.h"#endif // QT3_SUPPORT#define ABORT_IF_ACTIVE(location) \    if (d->printEngine->printerState() == QPrinter::Active) { \        qWarning("%s: Cannot be changed while printer is active", location); \        return; \    }void QPrinterPrivate::createDefaultEngines(){    QPrinter::OutputFormat realOutputFormat = outputFormat;#if !defined (QTOPIA_PRINTENGINE)#if defined (Q_OS_UNIX) && ! defined (Q_WS_MAC)    if(outputFormat == QPrinter::NativeFormat) {        realOutputFormat = QPrinter::PostScriptFormat;    }#endif#endif    switch (realOutputFormat) {    case QPrinter::NativeFormat: {#if defined (Q_WS_WIN)        QWin32PrintEngine *winEngine = new QWin32PrintEngine(printerMode);        paintEngine = winEngine;        printEngine = winEngine;#elif defined (Q_WS_MAC)        QMacPrintEngine *macEngine = new QMacPrintEngine(printerMode);        paintEngine = macEngine;        printEngine = macEngine;#elif defined (QTOPIA_PRINTENGINE)        QtopiaPrintEngine *qwsEngine = new QtopiaPrintEngine(printerMode);        paintEngine = qwsEngine;        printEngine = qwsEngine;#elif defined (Q_OS_UNIX)        Q_ASSERT(false);#endif        }        break;    case QPrinter::PdfFormat: {        QPdfEngine *pdfEngine = new QPdfEngine(printerMode);        paintEngine = pdfEngine;        printEngine = pdfEngine;    }        break;    case QPrinter::PostScriptFormat: {        QPSPrintEngine *psEngine = new QPSPrintEngine(printerMode);        paintEngine = psEngine;        printEngine = psEngine;    }        break;    }    use_default_engine = true;}/*!  \class QPrinter  \brief The QPrinter class is a paint device that paints on a printer.  \ingroup multimedia  \mainclass  This device represents a series of pages of printed output, and is  used in almost exactly the same way as other paint devices such as  QWidget and QPixmap.  A set of additional functions are provided to manage device-specific  features, such as orientation and resolution, and to step through  the pages in a document as it is generated.  When printing directly to a printer on Windows or Mac OS X, QPrinter uses  the built-in printer drivers. On X11, QPrinter uses the  \l{Common Unix Printing System (CUPS)} or the standard Unix \l lpr utility  to send PostScript or PDF output to the printer. As an alternative,  the printProgram() function can be used to specify the command or utility  to use instead of the system default.  QPrinter supports a number of parameters, most of which can be  changed by the end user through a \l{QPrintDialog}{print dialog}. In  general, QPrinter passes these functions onto the underlying QPrintEngine.  The most important parameters are:  \list  \i setOrientation() tells QPrinter which page orientation to use.  \i setPageSize() tells QPrinter what page size to expect from the  printer.  \i setResolution() tells QPrinter what resolution you wish the  printer to provide, in dots per inch (DPI).  \i setFullPage() tells QPrinter whether you want to deal with the  full page or just with the part the printer can draw on.  \i setNumCopies() tells QPrinter how many copies of the document  it should print.  \endlist  Many of these functions can only be called before the actual printing  begins (i.e., before QPainter::begin() is called). This usually makes  sense because, for example, it's not possible to change the number of  copies when you are halfway through printing. There are also some  settings that the user sets (through the printer dialog) and that  applications are expected to obey. See QAbstractPrintDialog's  documentation for more details.  When QPainter::begin() is called, the QPrinter it operates on is prepared for  a new page, enabling the QPainter to be used immediately to paint the first  page in a document. Once the first page has been painted, newPage() can be  called to request a new blank page to paint on, or QPainter::end() can be  called to finish printing. The second page and all following pages are  prepared using a call to newPage() before they are painted.  The first page in a document does not need to be preceded by a call to  newPage(). You only need to calling newPage() after QPainter::begin() if you  need to insert a blank page at the beginning of a printed document.  Similarly, calling newPage() after the last page in a document is painted will  result in a trailing blank page appended to the end of the printed document.  If you want to abort the print job, abort() will try its best to  stop printing. It may cancel the entire job or just part of it.  Since QPrinter can print to any QPrintEngine subclass, it is possible to  extend printing support to cover new types of printing subsystem by  subclassing QPrintEngine and reimplementing its interface.  \sa QPrintDialog, {Printing with Qt}*//*!    \enum QPrinter::PrinterState    \value Idle    \value Active    \value Aborted    \value Error*//*!    \enum QPrinter::PrinterMode    This enum describes the mode the printer should work in. It    basically presets a certain resolution and working mode.    \value ScreenResolution Sets the resolution of the print device to    the screen resolution. This has the big advantage that the results    obtained when painting on the printer will match more or less    exactly the visible output on the screen. It is the easiest to    use, as font metrics on the screen and on the printer are the    same. This is the default value. ScreenResolution will produce a    lower quality output than HighResolution and should only be used    for drafts.    \value PrinterResolution This value is deprecated. Is is    equivalent to ScreenResolution on Unix and HighResolution on    Windows and Mac. Due do the difference between ScreenResolution    and HighResolution, use of this value may lead to non-portable    printer code.    \value HighResolution On Windows, sets the printer resolution to that    defined for the printer in use. For PostScript printing, sets the    resolution of the PostScript driver to 1200 dpi.    \note When rendering text on a QPrinter device, it is important    to realize that the size of text, when specified in points, is    independent of the resolution specified for the device itself.    Therefore, it may be useful to specify the font size in pixels    when combining text with graphics to ensure that their relative    sizes are what you expect.*//*!  \enum QPrinter::Orientation  This enum type (not to be confused with \c Orientation) is used  to specify each page's orientation.  \value Portrait the page's height is greater than its width.  \value Landscape the page's width is greater than its height.  This type interacts with \l QPrinter::PageSize and  QPrinter::setFullPage() to determine the final size of the page  available to the application.*//*!    \enum QPrinter::PrintRange    Used to specify the print range selection option.    \value AllPages All pages should be printed.    \value Selection Only the selection should be printed.    \value PageRange The specified page range should be printed.    \sa QAbstractPrintDialog::PrintRange*//*!    \enum QPrinter::PrinterOption    \compat    Use QAbstractPrintDialog::PrintDialogOption instead.    \value PrintToFile    \value PrintSelection    \value PrintPageRange*//*!  \enum QPrinter::PageSize  This enum type specifies what paper size QPrinter should use.  QPrinter does not check that the paper size is available; it just  uses this information, together with QPrinter::Orientation and  QPrinter::setFullPage(), to determine the printable area.  The defined sizes (with setFullPage(true)) are:  \value A0 841 x 1189 mm  \value A1 594 x 841 mm  \value A2 420 x 594 mm  \value A3 297 x 420 mm  \value A4 210 x 297 mm, 8.26 x 11.69 inches  \value A5 148 x 210 mm  \value A6 105 x 148 mm  \value A7 74 x 105 mm  \value A8 52 x 74 mm  \value A9 37 x 52 mm  \value B0 1030 x 1456 mm  \value B1 728 x 1030 mm  \value B10 32 x 45 mm  \value B2 515 x 728 mm  \value B3 364 x 515 mm  \value B4 257 x 364 mm  \value B5 182 x 257 mm, 7.17 x 10.13 inches  \value B6 128 x 182 mm  \value B7 91 x 128 mm  \value B8 64 x 91 mm  \value B9 45 x 64 mm  \value C5E 163 x 229 mm  \value Comm10E 105 x 241 mm, U.S. Common 10 Envelope  \value DLE 110 x 220 mm  \value Executive 7.5 x 10 inches, 191 x 254 mm  \value Folio 210 x 330 mm  \value Ledger 432 x 279 mm  \value Legal 8.5 x 14 inches, 216 x 356 mm  \value Letter 8.5 x 11 inches, 216 x 279 mm  \value Tabloid 279 x 432 mm  \value Custom Unknown size  With setFullPage(false) (the default), the metrics will be a bit  smaller; how much depends on the printer in use.  \omitvalue NPageSize*//*!  \enum QPrinter::PageOrder  This enum type is used by QPrinter to tell the application program  how to print.  \value FirstPageFirst  the lowest-numbered page should be printed  first.  \value LastPageFirst  the highest-numbered page should be printed  first.*//*!  \enum QPrinter::ColorMode  This enum type is used to indicate whether QPrinter should print  in color or not.  \value Color  print in color if available, otherwise in grayscale.  \value GrayScale  print in grayscale, even on color printers.*//*!  \enum QPrinter::PaperSource  This enum type specifies what paper source QPrinter is to use.  QPrinter does not check that the paper source is available; it  just uses this information to try and set the paper source.  Whether it will set the paper source depends on whether the  printer has that particular source.  \warning This is currently only implemented for Windows.  \value Auto  \value Cassette  \value Envelope  \value EnvelopeManual  \value FormSource  \value LargeCapacity  \value LargeFormat  \value Lower  \value MaxPageSource  \value Middle  \value Manual  \value OnlyOne  \value Tractor  \value SmallFormat*//*  \enum QPrinter::PrintRange  This enum is used to specify which print range the application  should use to print.  \value AllPages All the pages should be printed.  \value Selection Only the selection should be printed.  \value PageRange Print according to the from page and to page options.  \sa setPrintRange(), printRange()*//*  \enum QPrinter::PrinterOption  This enum describes various printer options that appear in the  printer setup dialog. It is used to enable and disable these  options in the setup dialog.  \value PrintToFile Describes if print to file should be enabled.  \value PrintSelection Describes if printing selections should be enabled.  \value PrintPageRange Describes if printing page ranges (from, to) should  be enabled  \sa setOptionEnabled(), isOptionEnabled()*//*!    Creates a new printer object with the given \a mode.*/QPrinter::QPrinter(PrinterMode mode)    : QPaintDevice(),      d_ptr(new QPrinterPrivate(this)){    if (!qApp) {        qFatal("QPrinter: Must construct a QApplication before a QPaintDevice");        return;    }    Q_D(QPrinter);    d->printerMode = mode;    d->outputFormat = QPrinter::NativeFormat;    d->createDefaultEngines();#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)    if (QCUPSSupport::cupsVersion() >= 10200 && QCUPSSupport().currentPPD()) {        setOutputFormat(QPrinter::PdfFormat);        d->outputFormat = QPrinter::NativeFormat;    }#endif}/*!    This function is used by subclasses of QPrinter to specify custom    print and paint engines (\a printEngine and \a paintEngine,    respectively).    QPrinter does not take ownership of the engines, so you need to    manage these engine instances yourself.    Note that changing the engines will reset the printer state and    all its properties.    \sa printEngine() paintEngine() setOutputFormat()    \since 4.1*/void QPrinter::setEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine){    Q_D(QPrinter);    if (d->use_default_engine)        delete d->printEngine;    d->printEngine = printEngine;    d->paintEngine = paintEngine;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -