1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QPRINTENGINE_WIN_P_H
43 #define QPRINTENGINE_WIN_P_H
49 // This file is not part of the Qt API. It exists for the convenience
50 // of other Qt classes. This header file may change from version to
51 // version without notice, or even be removed.
58 #include "QtGui/qprinter.h"
59 #include "QtGui/qprintengine.h"
60 #include "QtGui/qpaintengine.h"
61 #include "QtCore/qt_windows.h"
62 #include "private/qpaintengine_alpha_p.h"
66 class QWin32PrintEnginePrivate;
67 class QPrinterPrivate;
70 class QWin32PrintEngine : public QAlphaPaintEngine, public QPrintEngine
72 Q_DECLARE_PRIVATE(QWin32PrintEngine)
74 QWin32PrintEngine(QPrinter::PrinterMode mode);
76 // override QWin32PaintEngine
77 bool begin(QPaintDevice *dev);
80 void updateState(const QPaintEngineState &state);
82 void updateMatrix(const QTransform &matrix);
83 void updateClipPath(const QPainterPath &clip, Qt::ClipOperation op);
85 void drawPath(const QPainterPath &path);
86 void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
87 void drawTextItem(const QPointF &p, const QTextItem &textItem);
89 void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
90 void drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &p);
91 void setProperty(PrintEnginePropertyKey key, const QVariant &value);
92 QVariant property(PrintEnginePropertyKey key) const;
96 int metric(QPaintDevice::PaintDeviceMetric) const;
98 QPrinter::PrinterState printerState() const;
100 QPaintEngine::Type type() const { return Windows; }
103 void releaseDC(HDC) const;
105 HDC getPrinterDC() const { return getDC(); }
106 void releasePrinterDC(HDC dc) const { releaseDC(dc); }
109 friend class QPrintDialog;
110 friend class QPageSetupDialog;
113 class QWin32PrintEnginePrivate : public QAlphaPaintEnginePrivate
115 Q_DECLARE_PUBLIC(QWin32PrintEngine)
117 QWin32PrintEnginePrivate() :
123 mode(QPrinter::ScreenResolution),
124 state(QPrinter::Idle),
126 pageMarginsSet(false),
131 has_custom_paper_size(false)
135 ~QWin32PrintEnginePrivate();
138 /* Reads the default printer name and its driver (printerProgram) into
139 the engines private data. */
142 /* Initializes the printer data based on the current printer name. This
143 function creates a DEVMODE struct, HDC and a printer handle. If these
144 structures are already in use, they are freed using release
148 /* Initializes data in the print engine whenever the HDC has been renewed
152 /* Releases all the handles the printer currently holds, HDC, DEVMODE,
153 etc and resets the corresponding members to 0. */
156 /* Queries the resolutions for the current printer, and returns them
158 QList<QVariant> queryResolutions() const;
160 /* Resets the DC with changes in devmode. If the printer is active
161 this function only sets the reinit variable to true so it
162 is handled in the next begin or newpage. */
165 /* Used by print/page setup dialogs */
166 HGLOBAL *createDevNames();
168 void readDevmode(HGLOBAL globalDevmode);
169 void readDevnames(HGLOBAL globalDevnames);
171 inline bool resetDC() {
172 hdc = ResetDC(hdc, devMode);
176 void strokePath(const QPainterPath &path, const QColor &color);
177 void fillPath(const QPainterPath &path, const QColor &color);
179 void composeGdiPath(const QPainterPath &path);
180 void fillPath_dev(const QPainterPath &path, const QColor &color);
181 void strokePath_dev(const QPainterPath &path, const QColor &color, qreal width);
186 void setPageMargins(int margin_left, int margin_top, int margin_right, int margin_bottom);
187 QRect getPageMargins() const;
188 void updateCustomPaperSize();
190 // Windows GDI printer references.
193 HGLOBAL globalDevMode;
195 PRINTER_INFO_2 *pInfo;
200 QPrinter::PrinterMode mode;
211 QPrinter::PrinterState state;
214 // This QRect is used to store the exact values
215 // entered into the PageSetup Dialog because those are
216 // entered in mm but are since converted to device coordinates.
217 // If they were to be converted back when displaying the dialog
218 // again, there would be inaccuracies so when the user entered 10
219 // it may show up as 9.99 the next time the dialog is opened.
220 // We don't want that confusion.
221 QRect previousDialogMargins;
225 QRect devPhysicalPageRect;
237 uint printToFile : 1;
241 uint complex_xform : 1;
244 uint has_custom_paper_size : 1;
253 QTransform painterMatrix;
259 #endif // QT_NO_PRINTER
261 #endif // QPRINTENGINE_WIN_P_H