Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qpaintengine.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QPAINTENGINE_H
5#define QPAINTENGINE_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/qnamespace.h>
9#include <QtCore/qobjectdefs.h>
10#include <QtCore/qscopedpointer.h>
11#include <QtGui/qpainter.h>
12
14
15
16class QFontEngine;
17class QLineF;
18class QPaintDevice;
20class QPainterPath;
21class QPointF;
22class QPolygonF;
23class QRectF;
24struct QGlyphLayout;
25class QTextItemInt;
27
28class Q_GUI_EXPORT QTextItem {
29public:
31 RightToLeft = 0x1,
32 Overline = 0x10,
33 Underline = 0x20,
34 StrikeOut = 0x40,
35
36 Dummy = 0xffffffff
37 };
38 Q_DECLARE_FLAGS(RenderFlags, RenderFlag)
39 qreal descent() const;
40 qreal ascent() const;
41 qreal width() const;
42
43 RenderFlags renderFlags() const;
44 QString text() const;
45 QFont font() const;
46};
48
49
50class Q_GUI_EXPORT QPaintEngine
51{
52 Q_DECLARE_PRIVATE(QPaintEngine)
53public:
55 PrimitiveTransform = 0x00000001, // Can transform primitives brushes
56 PatternTransform = 0x00000002, // Can transform pattern brushes
57 PixmapTransform = 0x00000004, // Can transform pixmaps
58 PatternBrush = 0x00000008, // Can fill with pixmaps and standard patterns
59 LinearGradientFill = 0x00000010, // Can fill gradient areas
60 RadialGradientFill = 0x00000020, // Can render radial gradients
61 ConicalGradientFill = 0x00000040, // Can render conical gradients
62 AlphaBlend = 0x00000080, // Can do source over alpha blend
63 PorterDuff = 0x00000100, // Can do general porter duff compositions
64 PainterPaths = 0x00000200, // Can fill, outline and clip paths
65 Antialiasing = 0x00000400, // Can antialias lines
66 BrushStroke = 0x00000800, // Can render brush based pens
67 ConstantOpacity = 0x00001000, // Can render at constant opacity
68 MaskedBrush = 0x00002000, // Can fill with textures that has an alpha channel or mask
69 PerspectiveTransform = 0x00004000, // Can do perspective transformations
70 BlendModes = 0x00008000, // Can do extended Porter&Duff composition
71 ObjectBoundingModeGradients = 0x00010000, // Can do object bounding mode gradients
72 RasterOpModes = 0x00020000, // Can do logical raster operations
73 PaintOutsidePaintEvent = 0x20000000, // Engine is capable of painting outside paint events
74 /* 0x10000000, // Used for emulating
75 QGradient::StretchToDevice,
76 defined in qpainter.cpp
77
78 0x40000000, // Used internally for emulating opaque backgrounds
79 */
80
81 AllFeatures = 0xffffffff // For convenience
82 };
83 Q_DECLARE_FLAGS(PaintEngineFeatures, PaintEngineFeature)
84
85 enum DirtyFlag {
86 DirtyPen = 0x0001,
87 DirtyBrush = 0x0002,
88 DirtyBrushOrigin = 0x0004,
89 DirtyFont = 0x0008,
90 DirtyBackground = 0x0010,
91 DirtyBackgroundMode = 0x0020,
92 DirtyTransform = 0x0040,
93 DirtyClipRegion = 0x0080,
94 DirtyClipPath = 0x0100,
95 DirtyHints = 0x0200,
96 DirtyCompositionMode = 0x0400,
97 DirtyClipEnabled = 0x0800,
98 DirtyOpacity = 0x1000,
99
100 AllDirty = 0xffff
101 };
102 Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)
103
110
111 explicit QPaintEngine(PaintEngineFeatures features=PaintEngineFeatures());
112 virtual ~QPaintEngine();
113
114 bool isActive() const { return active; }
115 void setActive(bool newState) { active = newState; }
116
117 virtual bool begin(QPaintDevice *pdev) = 0;
118 virtual bool end() = 0;
119
120 virtual void updateState(const QPaintEngineState &state) = 0;
121
122 virtual void drawRects(const QRect *rects, int rectCount);
123 virtual void drawRects(const QRectF *rects, int rectCount);
124
125 virtual void drawLines(const QLine *lines, int lineCount);
126 virtual void drawLines(const QLineF *lines, int lineCount);
127
128 virtual void drawEllipse(const QRectF &r);
129 virtual void drawEllipse(const QRect &r);
130
131 virtual void drawPath(const QPainterPath &path);
132
133 virtual void drawPoints(const QPointF *points, int pointCount);
134 virtual void drawPoints(const QPoint *points, int pointCount);
135
136 virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
137 virtual void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode);
138
139 virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) = 0;
140 virtual void drawTextItem(const QPointF &p, const QTextItem &textItem);
141 virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
142 virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
143 Qt::ImageConversionFlags flags = Qt::AutoColor);
144
145 void setPaintDevice(QPaintDevice *device);
146 QPaintDevice *paintDevice() const;
147
148 void setSystemClip(const QRegion &baseClip);
149 QRegion systemClip() const;
150
151 void setSystemRect(const QRect &rect);
152 QRect systemRect() const;
153
154
155 virtual QPoint coordinateOffset() const;
156
157 enum Type {
160 QuickDraw, CoreGraphics, MacPrinter,
173
174 User = 50, // first user type id
175 MaxUser = 100 // last user type id
176 };
177 virtual Type type() const = 0;
178
179 inline void fix_neg_rect(int *x, int *y, int *w, int *h);
180
181 inline bool testDirty(DirtyFlags df);
182 inline void setDirty(DirtyFlags df);
183 inline void clearDirty(DirtyFlags df);
184
185 bool hasFeature(PaintEngineFeatures feature) const { return bool(gccaps & feature); }
186
187 QPainter *painter() const;
188
189 void syncState();
190 inline bool isExtended() const { return extended; }
191
192 virtual QPixmap createPixmap(QSize size);
193 virtual QPixmap createPixmapFromImage(QImage image, Qt::ImageConversionFlags flags = Qt::AutoColor);
194
195protected:
196 QPaintEngine(QPaintEnginePrivate &data, PaintEngineFeatures devcaps=PaintEngineFeatures());
197
199 PaintEngineFeatures gccaps;
200
204
205 QScopedPointer<QPaintEnginePrivate> d_ptr;
206
207private:
208 void setAutoDestruct(bool autoDestr) { selfDestruct = autoDestr; }
209 bool autoDestruct() const { return selfDestruct; }
210 Q_DISABLE_COPY(QPaintEngine)
211
212 friend class QPainterReplayer;
213 friend class QFontEngineBox;
214 friend class QFontEngineMac;
215 friend class QFontEngineWin;
216 friend class QMacPrintEngine;
218 friend class QFontEngineQPF2;
219 friend class QPainter;
220 friend class QPainterPrivate;
221 friend class QWidget;
222 friend class QWidgetPrivate;
223 friend class QWin32PaintEngine;
224 friend class QWin32PaintEnginePrivate;
225 friend class QMacCGContext;
227 friend class QX11GLPlatformPixmap;
228};
229
230
231class Q_GUI_EXPORT QPaintEngineState
232{
233public:
234 QPaintEngine::DirtyFlags state() const { return dirtyFlags; }
235
236 QPen pen() const;
237 QBrush brush() const;
238 QPointF brushOrigin() const;
239 QBrush backgroundBrush() const;
240 Qt::BGMode backgroundMode() const;
241 QFont font() const;
242 QTransform transform() const;
243
244 Qt::ClipOperation clipOperation() const;
245 QRegion clipRegion() const;
246 QPainterPath clipPath() const;
247 bool isClipEnabled() const;
248
249 QPainter::RenderHints renderHints() const;
250 QPainter::CompositionMode compositionMode() const;
251 qreal opacity() const;
252
253 QPainter *painter() const;
254
255 bool brushNeedsResolving() const;
256 bool penNeedsResolving() const;
257
258protected:
259 friend class QPaintEngine;
260 friend class QRasterPaintEngine;
261 friend class QWidget;
262 friend class QPainter;
263 friend class QPainterPrivate;
265
266 QPaintEngine::DirtyFlags dirtyFlags;
267};
268
269//
270// inline functions
271//
272
273inline void QPaintEngine::fix_neg_rect(int *x, int *y, int *w, int *h)
274{
275 if (*w < 0) {
276 *w = -*w;
277 *x -= *w - 1;
278 }
279 if (*h < 0) {
280 *h = -*h;
281 *y -= *h - 1;
282 }
283}
284
285inline bool QPaintEngine::testDirty(DirtyFlags df) {
287 return bool(state->dirtyFlags & df);
288}
289
290inline void QPaintEngine::setDirty(DirtyFlags df) {
292 state->dirtyFlags |= df;
293}
294
295inline void QPaintEngine::clearDirty(DirtyFlags df)
296{
298 state->dirtyFlags &= ~df;
299}
300
301Q_DECLARE_OPERATORS_FOR_FLAGS(QTextItem::RenderFlags)
302Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::PaintEngineFeatures)
303Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::DirtyFlags)
304
306
307#endif // QPAINTENGINE_H
IOBluetoothDevice * device
\inmodule QtGui
Definition qbrush.h:30
\reentrant
Definition qfont.h:22
\inmodule QtGui
Definition qimage.h:37
\inmodule QtCore\compares equality \compareswith equality QLine \endcompareswith
Definition qline.h:192
\inmodule QtCore\compares equality \compareswith equality QLineF \endcompareswith
Definition qline.h:18
The QPaintEngineState class provides information about the active paint engine's current state....
QPaintEngine::DirtyFlags dirtyFlags
QPaintEngine::DirtyFlags state() const
Returns a combination of flags identifying the set of properties that need to be updated when updatin...
\inmodule QtGui
void setActive(bool newState)
Sets the active state of the paint engine to state.
virtual void updateState(const QPaintEngineState &state)=0
Reimplement this function to update the state of a paint engine.
PolygonDrawMode
\value OddEvenMode The polygon should be drawn using OddEven fill rule.
virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)=0
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r.
virtual bool begin(QPaintDevice *pdev)=0
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
void fix_neg_rect(int *x, int *y, int *w, int *h)
PaintEngineFeature
This enum is used to describe the features or capabilities that the paint engine has.
void setDirty(DirtyFlags df)
QPaintEngineState * state
PaintEngineFeatures gccaps
virtual bool end()=0
Reimplement this function to finish painting on the current paint device.
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
void clearDirty(DirtyFlags df)
bool hasFeature(PaintEngineFeatures feature) const
Returns true if the paint engine supports the specified feature; otherwise returns false.
virtual Type type() const =0
Reimplement this function to return the paint engine \l{Type}.
bool isExtended() const
bool testDirty(DirtyFlags df)
DirtyFlag
\value DirtyPen The pen is dirty and needs to be updated.
QScopedPointer< QPaintEnginePrivate > d_ptr
\inmodule QtGui
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
CompositionMode
Defines the modes supported for digital image compositing.
Definition qpainter.h:97
\inmodule QtGui
Definition qpen.h:28
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:217
\inmodule QtCore\reentrant
Definition qpoint.h:25
The QPolygonF class provides a list of points using floating point precision.
Definition qpolygon.h:96
The QRasterPaintEngine class enables hardware acceleration of painting operations in Qt for Embedded ...
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore\reentrant
Definition qrect.h:30
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Internal QTextItem.
\inmodule QtGui
RenderFlag
\value RightToLeft Render the text from right to left.
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QString text
rect
[4]
else opt state
[0]
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
Combined button and popup list for selecting options.
@ AutoColor
Definition qnamespace.h:478
ClipOperation
Definition brush.cpp:5
Definition image.cpp:4
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
@ User
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLboolean r
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei width
GLbitfield flags
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLuint GLenum GLenum transform
GLfixed GLfixed GLint GLint GLfixed points
GLdouble s
[6]
Definition qopenglext.h:235
GLsizei const GLchar *const * path
GLfloat GLfloat p
[1]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
@ Q_PRIMITIVE_TYPE
Definition qtypeinfo.h:157
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
p drawImage(offset, thumbnail)
widget render & pixmap
QPainter painter(this)
[7]
Definition moc.h:23