1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #ifndef QPAINTENGINE_H
41 #define QPAINTENGINE_H
42
43 #include <QtGui/qtguiglobal.h>
44 #include <QtCore/qnamespace.h>
45 #include <QtCore/qobjectdefs.h>
46 #include <QtCore/qscopedpointer.h>
47 #include <QtGui/qpainter.h>
48
49 QT_BEGIN_NAMESPACE
50
51
52 class QFontEngine;
53 class QLineF;
54 class QPaintDevice;
55 class QPaintEnginePrivate;
56 class QPainterPath;
57 class QPointF;
58 class QPolygonF;
59 class QRectF;
60 struct QGlyphLayout;
61 class QTextItemInt;
62 class QPaintEngineState;
63
64 class Q_GUI_EXPORT QTextItem {
65 public:
66 enum RenderFlag {
67 RightToLeft = 0x1,
68 Overline = 0x10,
69 Underline = 0x20,
70 StrikeOut = 0x40,
71
72 Dummy = 0xffffffff
73 };
74 Q_DECLARE_FLAGS(RenderFlags, RenderFlag)
75 qreal descent() const;
76 qreal ascent() const;
77 qreal width() const;
78
79 RenderFlags renderFlags() const;
80 QString text() const;
81 QFont font() const;
82 };
83 Q_DECLARE_TYPEINFO(QTextItem, Q_PRIMITIVE_TYPE);
84
85
86 class Q_GUI_EXPORT QPaintEngine
87 {
88 Q_DECLARE_PRIVATE(QPaintEngine)
89 public:
90 enum PaintEngineFeature {
91 PrimitiveTransform = 0x00000001, // Can transform primitives brushes
92 PatternTransform = 0x00000002, // Can transform pattern brushes
93 PixmapTransform = 0x00000004, // Can transform pixmaps
94 PatternBrush = 0x00000008, // Can fill with pixmaps and standard patterns
95 LinearGradientFill = 0x00000010, // Can fill gradient areas
96 RadialGradientFill = 0x00000020, // Can render radial gradients
97 ConicalGradientFill = 0x00000040, // Can render conical gradients
98 AlphaBlend = 0x00000080, // Can do source over alpha blend
99 PorterDuff = 0x00000100, // Can do general porter duff compositions
100 PainterPaths = 0x00000200, // Can fill, outline and clip paths
101 Antialiasing = 0x00000400, // Can antialias lines
102 BrushStroke = 0x00000800, // Can render brush based pens
103 ConstantOpacity = 0x00001000, // Can render at constant opacity
104 MaskedBrush = 0x00002000, // Can fill with textures that has an alpha channel or mask
105 PerspectiveTransform = 0x00004000, // Can do perspective transformations
106 BlendModes = 0x00008000, // Can do extended Porter&Duff composition
107 ObjectBoundingModeGradients = 0x00010000, // Can do object bounding mode gradients
108 RasterOpModes = 0x00020000, // Can do logical raster operations
109 PaintOutsidePaintEvent = 0x20000000, // Engine is capable of painting outside paint events
110 /* 0x10000000, // Used for emulating
111 QGradient::StretchToDevice,
112 defined in qpainter.cpp
113
114 0x40000000, // Used internally for emulating opaque backgrounds
115 */
116
117 AllFeatures = 0xffffffff // For convenience
118 };
119 Q_DECLARE_FLAGS(PaintEngineFeatures, PaintEngineFeature)
120
121 enum DirtyFlag {
122 DirtyPen = 0x0001,
123 DirtyBrush = 0x0002,
124 DirtyBrushOrigin = 0x0004,
125 DirtyFont = 0x0008,
126 DirtyBackground = 0x0010,
127 DirtyBackgroundMode = 0x0020,
128 DirtyTransform = 0x0040,
129 DirtyClipRegion = 0x0080,
130 DirtyClipPath = 0x0100,
131 DirtyHints = 0x0200,
132 DirtyCompositionMode = 0x0400,
133 DirtyClipEnabled = 0x0800,
134 DirtyOpacity = 0x1000,
135
136 AllDirty = 0xffff
137 };
138 Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)
139
140 enum PolygonDrawMode {
141 OddEvenMode,
142 WindingMode,
143 ConvexMode,
144 PolylineMode
145 };
146
147 explicit QPaintEngine(PaintEngineFeatures features=PaintEngineFeatures());
148 virtual ~QPaintEngine();
149
isActive()150 bool isActive() const { return active; }
setActive(bool newState)151 void setActive(bool newState) { active = newState; }
152
153 virtual bool begin(QPaintDevice *pdev) = 0;
154 virtual bool end() = 0;
155
156 virtual void updateState(const QPaintEngineState &state) = 0;
157
158 virtual void drawRects(const QRect *rects, int rectCount);
159 virtual void drawRects(const QRectF *rects, int rectCount);
160
161 virtual void drawLines(const QLine *lines, int lineCount);
162 virtual void drawLines(const QLineF *lines, int lineCount);
163
164 virtual void drawEllipse(const QRectF &r);
165 virtual void drawEllipse(const QRect &r);
166
167 virtual void drawPath(const QPainterPath &path);
168
169 virtual void drawPoints(const QPointF *points, int pointCount);
170 virtual void drawPoints(const QPoint *points, int pointCount);
171
172 virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
173 virtual void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode);
174
175 virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) = 0;
176 virtual void drawTextItem(const QPointF &p, const QTextItem &textItem);
177 virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
178 virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
179 Qt::ImageConversionFlags flags = Qt::AutoColor);
180
181 void setPaintDevice(QPaintDevice *device);
182 QPaintDevice *paintDevice() const;
183
184 void setSystemClip(const QRegion &baseClip);
185 QRegion systemClip() const;
186
187 void setSystemRect(const QRect &rect);
188 QRect systemRect() const;
189
190
191 virtual QPoint coordinateOffset() const;
192
193 enum Type {
194 X11,
195 Windows,
196 QuickDraw, CoreGraphics, MacPrinter,
197 QWindowSystem,
198 PostScript, // ### Qt 6: Remove, update documentation
199 OpenGL,
200 Picture,
201 SVG,
202 Raster,
203 Direct3D,
204 Pdf,
205 OpenVG,
206 OpenGL2,
207 PaintBuffer,
208 Blitter,
209 Direct2D,
210
211 User = 50, // first user type id
212 MaxUser = 100 // last user type id
213 };
214 virtual Type type() const = 0;
215
216 inline void fix_neg_rect(int *x, int *y, int *w, int *h);
217
218 inline bool testDirty(DirtyFlags df);
219 inline void setDirty(DirtyFlags df);
220 inline void clearDirty(DirtyFlags df);
221
hasFeature(PaintEngineFeatures feature)222 bool hasFeature(PaintEngineFeatures feature) const { return gccaps & feature; }
223
224 QPainter *painter() const;
225
226 void syncState();
isExtended()227 inline bool isExtended() const { return extended; }
228
229 protected:
230 QPaintEngine(QPaintEnginePrivate &data, PaintEngineFeatures devcaps=PaintEngineFeatures());
231
232 QPaintEngineState *state;
233 PaintEngineFeatures gccaps;
234
235 uint active : 1;
236 uint selfDestruct : 1;
237 uint extended : 1;
238
239 QScopedPointer<QPaintEnginePrivate> d_ptr;
240
241 private:
setAutoDestruct(bool autoDestr)242 void setAutoDestruct(bool autoDestr) { selfDestruct = autoDestr; }
autoDestruct()243 bool autoDestruct() const { return selfDestruct; }
244 Q_DISABLE_COPY(QPaintEngine)
245
246 friend class QPainterReplayer;
247 friend class QFontEngineBox;
248 friend class QFontEngineMac;
249 friend class QFontEngineWin;
250 friend class QMacPrintEngine;
251 friend class QMacPrintEnginePrivate;
252 friend class QFontEngineQPF2;
253 friend class QPainter;
254 friend class QPainterPrivate;
255 friend class QWidget;
256 friend class QWidgetPrivate;
257 friend class QWin32PaintEngine;
258 friend class QWin32PaintEnginePrivate;
259 friend class QMacCGContext;
260 friend class QPreviewPaintEngine;
261 friend class QX11GLPlatformPixmap;
262 };
263
264
265 class Q_GUI_EXPORT QPaintEngineState
266 {
267 public:
state()268 QPaintEngine::DirtyFlags state() const { return dirtyFlags; }
269
270 QPen pen() const;
271 QBrush brush() const;
272 QPointF brushOrigin() const;
273 QBrush backgroundBrush() const;
274 Qt::BGMode backgroundMode() const;
275 QFont font() const;
276 #if QT_DEPRECATED_SINCE(5, 15)
277 QT_DEPRECATED_X("Use transform()") QMatrix matrix() const;
278 #endif // QT_DEPRECATED_SINCE(5, 15)
279 QTransform transform() const;
280
281 Qt::ClipOperation clipOperation() const;
282 QRegion clipRegion() const;
283 QPainterPath clipPath() const;
284 bool isClipEnabled() const;
285
286 QPainter::RenderHints renderHints() const;
287 QPainter::CompositionMode compositionMode() const;
288 qreal opacity() const;
289
290 QPainter *painter() const;
291
292 bool brushNeedsResolving() const;
293 bool penNeedsResolving() const;
294
295 protected:
296 friend class QPaintEngine;
297 friend class QRasterPaintEngine;
298 friend class QWidget;
299 friend class QPainter;
300 friend class QPainterPrivate;
301 friend class QMacPrintEnginePrivate;
302
303 QPaintEngine::DirtyFlags dirtyFlags;
304 };
305
306 //
307 // inline functions
308 //
309
fix_neg_rect(int * x,int * y,int * w,int * h)310 inline void QPaintEngine::fix_neg_rect(int *x, int *y, int *w, int *h)
311 {
312 if (*w < 0) {
313 *w = -*w;
314 *x -= *w - 1;
315 }
316 if (*h < 0) {
317 *h = -*h;
318 *y -= *h - 1;
319 }
320 }
321
testDirty(DirtyFlags df)322 inline bool QPaintEngine::testDirty(DirtyFlags df) {
323 Q_ASSERT(state);
324 return state->dirtyFlags & df;
325 }
326
setDirty(DirtyFlags df)327 inline void QPaintEngine::setDirty(DirtyFlags df) {
328 Q_ASSERT(state);
329 state->dirtyFlags |= df;
330 }
331
clearDirty(DirtyFlags df)332 inline void QPaintEngine::clearDirty(DirtyFlags df)
333 {
334 Q_ASSERT(state);
335 state->dirtyFlags &= ~static_cast<uint>(df);
336 }
337
338 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextItem::RenderFlags)
339 Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::PaintEngineFeatures)
340 Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::DirtyFlags)
341
342 QT_END_NAMESPACE
343
344 #endif // QPAINTENGINE_H
345