Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qprintengine_win_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPRINTENGINE_WIN_P_H
5#define QPRINTENGINE_WIN_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtPrintSupport/private/qtprintsupportglobal_p.h>
19
20#ifndef QT_NO_PRINTER
21
22#include <QtGui/qpaintengine.h>
23#include <QtGui/qpagelayout.h>
24#include <QtPrintSupport/QPrintEngine>
25#include <QtPrintSupport/QPrinter>
26#include <private/qpaintengine_alpha_p.h>
27#include <private/qprintdevice_p.h>
28#include <QtCore/qt_windows.h>
29
31
33class QPrinterPrivate;
34class QPainterState;
35
36class Q_PRINTSUPPORT_EXPORT QWin32PrintEngine : public QAlphaPaintEngine, public QPrintEngine
37{
38 Q_DECLARE_PRIVATE(QWin32PrintEngine)
39public:
41
42 // override QWin32PaintEngine
43 bool begin(QPaintDevice *dev) override;
44 bool end() override;
45
46 void updateState(const QPaintEngineState &state) override;
47
48 void updateMatrix(const QTransform &matrix);
49 void updateClipPath(const QPainterPath &clip, Qt::ClipOperation op);
50
51 void drawPath(const QPainterPath &path) override;
52 void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) override;
53 void drawTextItem(const QPointF &p, const QTextItem &textItem) override;
54
55 void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) override;
56 void drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &p) override;
59
60 bool newPage() override;
61 bool abort() override;
62 int metric(QPaintDevice::PaintDeviceMetric) const override;
63
64 QPrinter::PrinterState printerState() const override;
65
66 QPaintEngine::Type type() const override { return Windows; }
67
68 HDC getDC() const;
69 void releaseDC(HDC) const;
70
71 /* Used by print/page setup dialogs */
72 void setGlobalDevMode(HGLOBAL globalDevNames, HGLOBAL globalDevMode);
73 HGLOBAL *createGlobalDevNames();
74 HGLOBAL globalDevMode();
75
76private:
77 friend class QPrintDialog;
78 friend class QPageSetupDialog;
79};
80
82{
83 Q_DECLARE_PUBLIC(QWin32PrintEngine)
84public:
86 hPrinter(0),
88 devMode(0),
89 pInfo(0),
90 hMem(0),
91 hdc(0),
93 mode(QPrinter::ScreenResolution),
94 state(QPrinter::Idle),
95 resolution(0),
96 m_pageLayout(QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(0, 0, 0, 0))),
97 stretch_x(1), stretch_y(1), origin_x(0), origin_y(0),
98 dpi_x(96), dpi_y(96), dpi_display(96),
99 num_copies(1),
101 reinit(false),
103 embed_fonts(true),
104 txop(0 /* QTransform::TxNone */)
105 {
106 }
107
109
110
111 /* Initializes the printer data based on the current printer name. This
112 function creates a DEVMODE struct, HDC and a printer handle. If these
113 structures are already in use, they are freed using release
114 */
115 void initialize();
116
117 /* Initializes data in the print engine whenever the HDC has been renewed
118 */
119 void initHDC();
120
121 /* Releases all the handles the printer currently holds, HDC, DEVMODE,
122 etc and resets the corresponding members to 0. */
123 void release();
124
125 /* Resets the DC with changes in devmode. If the printer is active
126 this function only sets the reinit variable to true so it
127 is handled in the next begin or newpage. */
128 void doReinit();
129
130 bool resetDC();
131
132 void strokePath(const QPainterPath &path, const QColor &color);
133 void fillPath(const QPainterPath &path, const QColor &color);
134
135 void composeGdiPath(const QPainterPath &path);
136 void fillPath_dev(const QPainterPath &path, const QColor &color);
137 void strokePath_dev(const QPainterPath &path, const QColor &color, qreal width);
138
139 void setPageSize(const QPageSize &pageSize);
140 void updatePageLayout();
141 void updateMetrics();
142 void debugMetrics() const;
143
144 // Windows GDI printer references.
145 HANDLE hPrinter;
146
148 DEVMODE *devMode;
149 PRINTER_INFO_2 *pInfo;
150 HGLOBAL hMem;
151
152 HDC hdc;
153
154 // True if devMode was allocated separately from pInfo.
156
158
159 // Print Device
161
162 // Document info
166
169
170 // Page Layout
172
173 // Page metrics cache
176
177 // Windows painting
182
183 int dpi_x;
184 int dpi_y;
187
190
196
198
202 QSizeF paper_size; // In points
203
206};
207
209
210#endif // QT_NO_PRINTER
211
212#endif // QPRINTENGINE_WIN_P_H
void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) override
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r.
bool end() override
Reimplement this function to finish painting on the current paint device.
void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) override
Reimplement this virtual function to draw the polygon defined by the pointCount first points in point...
void drawTextItem(const QPointF &p, const QTextItem &textItem) override
This function draws the text item textItem at position p.
bool begin(QPaintDevice *pdev) override
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s) override
Reimplement this function to draw the pixmap in the given rect, starting at the given p.
void updateState(const QPaintEngineState &state) override
Reimplement this function to update the state of a paint engine.
void drawPath(const QPainterPath &path) override
The default implementation ignores the path and does nothing.
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtCore
Definition qmargins.h:274
\inmodule QtGui
Definition qpagelayout.h:20
The QPageSetupDialog class provides a configuration dialog for the page-related options on a printer.
\inmodule QtGui
Definition qpagesize.h:22
The QPaintEngineState class provides information about the active paint engine's current state....
PolygonDrawMode
\value OddEvenMode The polygon should be drawn using OddEven fill rule.
Type
\value X11 \value Windows \value MacPrinter \value CoreGraphics \macos's Quartz2D (CoreGraphics) \val...
\inmodule QtGui
\inmodule QtGui
Definition qpen.h:25
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\inmodule QtCore\reentrant
Definition qpoint.h:214
The QPrintDialog class provides a dialog for specifying the printer's configuration.
\reentrant
virtual QPrinter::PrinterState printerState() const =0
Returns the current state of the printer being used by the print engine.
PrintEnginePropertyKey
This enum is used to communicate properties between the print engine and QPrinter.
virtual bool newPage()=0
Instructs the print engine to start a new page.
virtual int metric(QPaintDevice::PaintDeviceMetric) const =0
Returns the metric for the given id.
virtual bool abort()=0
Instructs the print engine to abort the printing process.
\reentrant
Definition qprinter.h:28
PrinterMode
This enum describes the mode the printer should work in.
Definition qprinter.h:31
PrinterState
\value Idle \value Active \value Aborted \value Error
Definition qprinter.h:64
\inmodule QtCore\reentrant
Definition qrect.h:483
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtCore
Definition qsize.h:207
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtGui
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
\inmodule QtCore
Definition qvariant.h:64
QPrinter::PrinterState state
void fillPath_dev(const QPainterPath &path, const QColor &color)
void strokePath_dev(const QPainterPath &path, const QColor &color, qreal width)
void composeGdiPath(const QPainterPath &path)
void strokePath(const QPainterPath &path, const QColor &color)
void setPageSize(const QPageSize &pageSize)
void fillPath(const QPainterPath &path, const QColor &color)
QPrinter::PrinterMode mode
QPaintEngine::Type type() const override
Reimplement this function to return the paint engine \l{Type}.
object setProperty("down", true)
else opt state
[0]
Combined button and popup list for selecting options.
ClipOperation
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum mode
GLuint64 key
GLboolean r
[2]
GLint GLsizei width
GLfixed GLfixed GLint GLint GLfixed points
GLuint GLenum matrix
GLsizei const GLchar *const * path
GLfloat GLfloat p
[1]
unsigned int uint
Definition qtypes.h:29
double qreal
Definition qtypes.h:92
const char property[13]
Definition qwizard.cpp:101