Qt 4.8
qprintengine_win_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 
65 
67 class QPrinterPrivate;
68 class QPainterState;
69 
71 {
73 public:
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);
93 
94  bool newPage();
95  bool abort();
97 
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 
108 private:
109  friend class QPrintDialog;
110  friend class QPageSetupDialog;
111 };
112 
114 {
116 public:
118  hPrinter(0),
119  globalDevMode(0),
120  devMode(0),
121  pInfo(0),
122  hdc(0),
123  mode(QPrinter::ScreenResolution),
124  state(QPrinter::Idle),
125  resolution(0),
126  pageMarginsSet(false),
127  num_copies(1),
128  printToFile(false),
129  fullPage(false),
130  reinit(false),
131  has_custom_paper_size(false)
132  {
133  }
134 
136 
137 
138  /* Reads the default printer name and its driver (printerProgram) into
139  the engines private data. */
140  void queryDefault();
141 
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
145  */
146  void initialize();
147 
148  /* Initializes data in the print engine whenever the HDC has been renewed
149  */
150  void initHDC();
151 
152  /* Releases all the handles the printer currently holds, HDC, DEVMODE,
153  etc and resets the corresponding members to 0. */
154  void release();
155 
156  /* Queries the resolutions for the current printer, and returns them
157  in a list. */
158  QList<QVariant> queryResolutions() const;
159 
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. */
163  void doReinit();
164 
165  /* Used by print/page setup dialogs */
166  HGLOBAL *createDevNames();
167 
168  void readDevmode(HGLOBAL globalDevmode);
169  void readDevnames(HGLOBAL globalDevnames);
170 
171  inline bool resetDC() {
172  hdc = ResetDC(hdc, devMode);
173  return hdc != 0;
174  }
175 
176  void strokePath(const QPainterPath &path, const QColor &color);
177  void fillPath(const QPainterPath &path, const QColor &color);
178 
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);
182 
183  void updateOrigin();
184 
185  void initDevRects();
186  void setPageMargins(int margin_left, int margin_top, int margin_right, int margin_bottom);
187  QRect getPageMargins() const;
188  void updateCustomPaperSize();
189 
190  // Windows GDI printer references.
192 
193  HGLOBAL globalDevMode;
194  DEVMODE *devMode;
195  PRINTER_INFO_2 *pInfo;
196  HGLOBAL hMem;
197 
198  HDC hdc;
199 
201 
202  // Printer info
206 
207  // Document info
210 
213 
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.
222 
229  int origin_x;
230  int origin_y;
231 
232  int dpi_x;
233  int dpi_y;
236 
240 
245 
247 
252 
255 };
256 
258 
259 #endif // QT_NO_PRINTER
260 
261 #endif // QPRINTENGINE_WIN_P_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double qreal
Definition: qglobal.h:1193
PrinterState
Definition: qprinter.h:119
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QPaintEngineState * state
Definition: qpaintengine.h:239
void releaseDC(HDC) const
Empty default implementation.
PrinterMode
This enum describes the mode the printer should work in.
Definition: qprinter.h:70
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void updateState(const QPaintEngineState &state)
Reimplement this function to update the state of a paint engine.
bool begin(QPaintDevice *dev)
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
The QString class provides a Unicode character string.
Definition: qstring.h:83
void drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &p)
Reimplement this function to draw the pixmap in the given rect, starting at the given p...
QPrinter::PrinterMode mode
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
QVariant property(PrintEnginePropertyKey key) const
Returns the print engine&#39;s property specified by key.
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
QPrinter::PrinterState printerState() const
Returns the current state of the printer being used by the print engine.
void updateMatrix(const QTransform &matrix)
The QPrintDialog class provides a dialog for specifying the printer&#39;s configuration.
Definition: qprintdialog.h:81
The QPageSetupDialog class provides a configuration dialog for the page-related options on a printer...
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
bool newPage()
Instructs the print engine to start a new page.
The QPrintEngine class defines an interface for how QPrinter interacts with a given printing subsyste...
Definition: qprintengine.h:56
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
int metric(QPaintDevice::PaintDeviceMetric) const
Returns the metric for the given id.
unsigned int uint
Definition: qglobal.h:996
void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r...
void * HANDLE
Definition: qnamespace.h:1671
void updateClipPath(const QPainterPath &clip, Qt::ClipOperation op)
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
bool abort()
Instructs the print engine to abort the printing process.
bool end()
Reimplement this function to finish painting on the current paint device.
int key
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void releasePrinterDC(HDC dc) const
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
HDC getDC() const
Empty default implementation.
The QPaintEngineState class provides information about the active paint engine&#39;s current state...
Definition: qpaintengine.h:289
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
The QTextItem class provides all the information required to draw text in a custom paint engine...
Definition: qpaintengine.h:68
void drawTextItem(const QPointF &p, const QTextItem &textItem)
This function draws the text item textItem at position p.
void setProperty(PrintEnginePropertyKey key, const QVariant &value)
Sets the print engine&#39;s property specified by key to the given value.
void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
Reimplement this virtual function to draw the polygon defined by the pointCount first points in point...
QPrinter::PrinterState state
QWin32PrintEngine(QPrinter::PrinterMode mode)
QPaintEngine::Type type() const
Reimplement this function to return the paint engine Type.
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
PrintEnginePropertyKey
This enum is used to communicate properties between the print engine and QPrinter.
Definition: qprintengine.h:60
ClipOperation
Definition: qnamespace.h:1495
void drawPath(const QPainterPath &path)
The default implementation ignores the path and does nothing.