source: trunk/src/gui/painting/qprintengine_win_p.h@ 778

Last change on this file since 778 was 651, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 7.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
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 [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QPRINTENGINE_WIN_P_H
43#define QPRINTENGINE_WIN_P_H
44
45//
46// W A R N I N G
47// -------------
48//
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.
52//
53// We mean it.
54//
55
56#ifndef QT_NO_PRINTER
57
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"
63
64QT_BEGIN_NAMESPACE
65
66class QWin32PrintEnginePrivate;
67class QPrinterPrivate;
68class QPainterState;
69
70class QWin32PrintEngine : public QAlphaPaintEngine, public QPrintEngine
71{
72 Q_DECLARE_PRIVATE(QWin32PrintEngine)
73public:
74 QWin32PrintEngine(QPrinter::PrinterMode mode);
75
76 // override QWin32PaintEngine
77 bool begin(QPaintDevice *dev);
78 bool end();
79
80 void updateState(const QPaintEngineState &state);
81
82 void updateMatrix(const QTransform &matrix);
83 void updateClipPath(const QPainterPath &clip, Qt::ClipOperation op);
84
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);
88
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;
93
94 bool newPage();
95 bool abort();
96 int metric(QPaintDevice::PaintDeviceMetric) const;
97
98 QPrinter::PrinterState printerState() const;
99
100 QPaintEngine::Type type() const { return Windows; }
101
102 HDC getDC() const;
103 void releaseDC(HDC) const;
104
105 HDC getPrinterDC() const { return getDC(); }
106 void releasePrinterDC(HDC dc) const { releaseDC(dc); }
107
108private:
109 friend class QPrintDialog;
110 friend class QPageSetupDialog;
111 friend int qt_printerRealNumCopies(QPaintEngine *);
112};
113
114class QWin32PrintEnginePrivate : public QAlphaPaintEnginePrivate
115{
116 Q_DECLARE_PUBLIC(QWin32PrintEngine)
117public:
118 QWin32PrintEnginePrivate() :
119 hPrinter(0),
120 globalDevMode(0),
121 devMode(0),
122 pInfo(0),
123 hdc(0),
124 mode(QPrinter::ScreenResolution),
125 state(QPrinter::Idle),
126 resolution(0),
127 pageMarginsSet(false),
128 num_copies(1),
129 printToFile(false),
130 fullPage(false),
131 reinit(false),
132 has_custom_paper_size(false)
133 {
134 }
135
136 ~QWin32PrintEnginePrivate();
137
138
139 /* Reads the default printer name and its driver (printerProgram) into
140 the engines private data. */
141 void queryDefault();
142
143 /* Initializes the printer data based on the current printer name. This
144 function creates a DEVMODE struct, HDC and a printer handle. If these
145 structures are already in use, they are freed using release
146 */
147 void initialize();
148
149 /* Initializes data in the print engine whenever the HDC has been renewed
150 */
151 void initHDC();
152
153 /* Releases all the handles the printer currently holds, HDC, DEVMODE,
154 etc and resets the corresponding members to 0. */
155 void release();
156
157 /* Queries the resolutions for the current printer, and returns them
158 in a list. */
159 QList<QVariant> queryResolutions() const;
160
161 /* Resets the DC with changes in devmode. If the printer is active
162 this function only sets the reinit variable to true so it
163 is handled in the next begin or newpage. */
164 void doReinit();
165
166 /* Used by print/page setup dialogs */
167 HGLOBAL *createDevNames();
168
169 void readDevmode(HGLOBAL globalDevmode);
170 void readDevnames(HGLOBAL globalDevnames);
171
172 inline bool resetDC() {
173 hdc = ResetDC(hdc, devMode);
174 return hdc != 0;
175 }
176
177 void strokePath(const QPainterPath &path, const QColor &color);
178 void fillPath(const QPainterPath &path, const QColor &color);
179
180 void composeGdiPath(const QPainterPath &path);
181 void fillPath_dev(const QPainterPath &path, const QColor &color);
182 void strokePath_dev(const QPainterPath &path, const QColor &color, qreal width);
183
184 void updateOrigin();
185
186 void initDevRects();
187 void setPageMargins(int margin_left, int margin_top, int margin_right, int margin_bottom);
188 QRect getPageMargins() const;
189 void updateCustomPaperSize();
190
191 // Windows GDI printer references.
192 HANDLE hPrinter;
193
194 HGLOBAL globalDevMode;
195 DEVMODE *devMode;
196 PRINTER_INFO_2 *pInfo;
197 HGLOBAL hMem;
198
199 HDC hdc;
200
201 QPrinter::PrinterMode mode;
202
203 // Printer info
204 QString name;
205 QString program;
206 QString port;
207
208 // Document info
209 QString docName;
210 QString fileName;
211
212 QPrinter::PrinterState state;
213 int resolution;
214
215 // This QRect is used to store the exact values
216 // entered into the PageSetup Dialog because those are
217 // entered in mm but are since converted to device coordinates.
218 // If they were to be converted back when displaying the dialog
219 // again, there would be inaccuracies so when the user entered 10
220 // it may show up as 9.99 the next time the dialog is opened.
221 // We don't want that confusion.
222 QRect previousDialogMargins;
223
224 bool pageMarginsSet;
225 QRect devPageRect;
226 QRect devPhysicalPageRect;
227 QRect devPaperRect;
228 qreal stretch_x;
229 qreal stretch_y;
230 int origin_x;
231 int origin_y;
232
233 int dpi_x;
234 int dpi_y;
235 int dpi_display;
236 int num_copies;
237
238 uint printToFile : 1;
239 uint fullPage : 1;
240 uint reinit : 1;
241
242 uint complex_xform : 1;
243 uint has_pen : 1;
244 uint has_brush : 1;
245 uint has_custom_paper_size : 1;
246
247 uint txop;
248
249 QColor brush_color;
250 QPen pen;
251 QColor pen_color;
252 QSizeF paper_size;
253
254 QTransform painterMatrix;
255 QTransform matrix;
256};
257
258QT_END_NAMESPACE
259
260#endif // QT_NO_PRINTER
261
262#endif // QPRINTENGINE_WIN_P_H
Note: See TracBrowser for help on using the repository browser.