Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qpainter_p.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 QPAINTER_P_H
5#define QPAINTER_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 purely as an
12// implementation detail. 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 <QtCore/qvarlengtharray.h>
19#include <QtGui/private/qtguiglobal_p.h>
20#include "QtGui/qbrush.h"
21#include "QtGui/qcolorspace.h"
22#include "QtGui/qcolortransform.h"
23#include "QtGui/qfont.h"
24#include "QtGui/qpen.h"
25#include "QtGui/qregion.h"
26#include "QtGui/qpainter.h"
27#include "QtGui/qpainterpath.h"
28#include "QtGui/qpaintengine.h"
29
30#include <private/qpen_p.h>
31
32#include <memory>
33#include <stack>
34
35QT_BEGIN_NAMESPACE
36
37class QPaintEngine;
38class QEmulationPaintEngine;
39class QPaintEngineEx;
40struct QFixedPoint;
41
42struct QTLWExtra;
43
45 void *ptr;
46};
47
48inline const void *data_ptr(const QTransform &t) { return (const DataPtrContainer *) &t; }
49inline bool qtransform_fast_equals(const QTransform &a, const QTransform &b) { return data_ptr(a) == data_ptr(b); }
50
51// QPen inline functions...
52inline QPen::DataPtr &data_ptr(const QPen &p) { return const_cast<QPen &>(p).data_ptr(); }
53inline bool qpen_fast_equals(const QPen &a, const QPen &b) { return data_ptr(a) == data_ptr(b); }
54inline QBrush qpen_brush(const QPen &p) { return data_ptr(p)->brush; }
55inline qreal qpen_widthf(const QPen &p) { return data_ptr(p)->width; }
56inline Qt::PenStyle qpen_style(const QPen &p) { return data_ptr(p)->style; }
57inline Qt::PenCapStyle qpen_capStyle(const QPen &p) { return data_ptr(p)->capStyle; }
58inline Qt::PenJoinStyle qpen_joinStyle(const QPen &p) { return data_ptr(p)->joinStyle; }
59
60// QBrush inline functions...
61inline QBrush::DataPtr &data_ptr(const QBrush &p) { return const_cast<QBrush &>(p).data_ptr(); }
62inline bool qbrush_fast_equals(const QBrush &a, const QBrush &b) { return data_ptr(a) == data_ptr(b); }
63inline Qt::BrushStyle qbrush_style(const QBrush &b) { return data_ptr(b)->style; }
64inline const QColor &qbrush_color(const QBrush &b) { return data_ptr(b)->color; }
65inline bool qbrush_has_transform(const QBrush &b) { return data_ptr(b)->transform.type() > QTransform::TxNone; }
66
68{
69public:
70 QPainterClipInfo() { } // for QList, don't use
72
73 QPainterClipInfo(const QPainterPath &p, Qt::ClipOperation op, const QTransform &m) :
75
76 QPainterClipInfo(const QRegion &r, Qt::ClipOperation op, const QTransform &m) :
78
79 QPainterClipInfo(const QRect &r, Qt::ClipOperation op, const QTransform &m) :
81
82 QPainterClipInfo(const QRectF &r, Qt::ClipOperation op, const QTransform &m) :
84
88 QPainterPath path;
91 QRectF rectf;
92
93 // ###
94// union {
95// QRegionData *d;
96// QPainterPathPrivate *pathData;
97
98// struct {
99// int x, y, w, h;
100// } rectData;
101// struct {
102// qreal x, y, w, h;
103// } rectFData;
104// };
105
106};
107
109
110class Q_GUI_EXPORT QPainterState : public QPaintEngineState
111{
112public:
113 QPainterState();
114 QPainterState(const QPainterState *s);
115 virtual ~QPainterState();
116 void init(QPainter *p);
117
118 QPointF brushOrigin;
119 QFont font;
120 QFont deviceFont;
121 QPen pen;
122 QBrush brush;
123 QBrush bgBrush = Qt::white; // background brush
124 QRegion clipRegion;
125 QPainterPath clipPath;
126 Qt::ClipOperation clipOperation = Qt::NoClip;
127 QPainter::RenderHints renderHints;
128 QList<QPainterClipInfo> clipInfo; // ### Make me smaller and faster to copy around...
129 QTransform worldMatrix; // World transformation matrix, not window and viewport
130 QTransform matrix; // Complete transformation matrix,
131 QTransform redirectionMatrix;
132 int wx = 0, wy = 0, ww = 0, wh = 0; // window rectangle
133 int vx = 0, vy = 0, vw = 0, vh = 0; // viewport rectangle
134 qreal opacity = 1;
135
136 uint WxF:1; // World transformation
137 uint VxF:1; // View transformation
138 uint clipEnabled:1;
139
140 Qt::BGMode bgMode = Qt::TransparentMode;
141 QPainter *painter = nullptr;
142 Qt::LayoutDirection layoutDirection;
143 QPainter::CompositionMode composition_mode = QPainter::CompositionMode_SourceOver;
144 uint emulationSpecifier = 0;
145 uint changeFlags = 0;
146};
147
155
156class QRawFont;
158{
159 Q_DECLARE_PUBLIC(QPainter)
160public:
163
165 // Allocate space for 4 d-pointers (enough for up to 4 sub-sequent
166 // redirections within the same paintEvent(), which should be enough
167 // in 99% of all cases). E.g: A renders B which renders C which renders D.
168 static constexpr qsizetype NDPtrs = 4;
170
172 template <typename T, std::size_t N = 8>
174 void clear() { this->c.clear(); }
175 };
177
179
184
189
191 if (!dummyState)
192 dummyState = std::make_unique<QPainterDummyState>();
193 return dummyState.get();
194 }
195
196 void updateEmulationSpecifier(QPainterState *s);
197 void updateStateImpl(QPainterState *state);
198 void updateState(QPainterState *state);
199 void updateState(std::unique_ptr<QPainterState> &state) { updateState(state.get()); }
200
201 void draw_helper(const QPainterPath &path, DrawOperation operation = StrokeAndFillDraw);
202 void drawStretchedGradient(const QPainterPath &path, DrawOperation operation);
203 void drawOpaqueBackground(const QPainterPath &path, DrawOperation operation);
204 void drawTextItem(const QPointF &p, const QTextItem &_ti, QTextEngine *textEngine);
205
206#if !defined(QT_NO_RAWFONT)
207 void drawGlyphs(const QPointF &decorationPosition, const quint32 *glyphArray, QFixedPoint *positionArray, int glyphCount,
208 QFontEngine *fontEngine, bool overline = false, bool underline = false,
209 bool strikeOut = false);
210#endif
211
212 void updateMatrix();
213 void updateInvMatrix();
214
215 void checkEmulation();
216
217 static QPainterPrivate *get(QPainter *painter)
218 {
219 return painter->d_ptr.get();
220 }
221
225 static bool attachPainterPrivate(QPainter *q, QPaintDevice *pdev);
227 void initFrom(const QPaintDevice *device);
228
229 QPaintDevice *device = nullptr;
230 QPaintDevice *original_device = nullptr;
231 QPaintDevice *helper_device = nullptr;
232
234 void operator()(QPaintEngine *pe) const noexcept
235 {
236 if (pe && pe->autoDestruct())
237 delete pe;
238 }
239 };
241
243 QPaintEngineEx *extended = nullptr;
244 QBrush colorBrush; // for fill with solid color
245};
246
247Q_GUI_EXPORT void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, QPainterPrivate::DrawOperation operation);
248
249QString qt_generate_brush_key(const QBrush &brush);
250
251
252QT_END_NAMESPACE
253
254#endif // QPAINTER_P_H
QObject * q_ptr
Definition qobject.h:72
void setSystemViewport(const QRegion &region)
void setSystemTransform(const QTransform &xform)
QPaintDevice * currentClipDevice
QTransform systemTransform
static QPaintEnginePrivate * get(QPaintEngine *paintEngine)
virtual void systemStateChanged()
void setSystemTransformAndViewport(const QTransform &xform, const QRegion &region)
QPaintDevice * pdev
void drawBoxTextItem(const QPointF &p, const QTextItemInt &ti)
virtual Qt::HANDLE nativeHandle()
virtual QPaintEngine * aggregateEngine()
friend class QPainter
QPainterClipInfo(const QRectF &r, Qt::ClipOperation op, const QTransform &m)
Definition qpainter_p.h:82
QTransform matrix
Definition qpainter_p.h:86
ClipType clipType
Definition qpainter_p.h:85
QPainterClipInfo(const QRegion &r, Qt::ClipOperation op, const QTransform &m)
Definition qpainter_p.h:76
QPainterPath path
Definition qpainter_p.h:88
Qt::ClipOperation operation
Definition qpainter_p.h:87
QPainterClipInfo(const QPainterPath &p, Qt::ClipOperation op, const QTransform &m)
Definition qpainter_p.h:73
void drawOpaqueBackground(const QPainterPath &path, DrawOperation operation)
Definition qpainter.cpp:474
void updateEmulationSpecifier(QPainterState *s)
Definition qpainter.cpp:656
QTransform invMatrix
Definition qpainter_p.h:180
QPaintDevice * original_device
Definition qpainter_p.h:230
QPainterDummyState * fakeState() const
Definition qpainter_p.h:190
QPaintEngineEx * extended
Definition qpainter_p.h:243
QPaintDevice * helper_device
Definition qpainter_p.h:231
void initFrom(const QPaintDevice *device)
static constexpr qsizetype NDPtrs
Definition qpainter_p.h:168
void updateMatrix()
Definition qpainter.cpp:627
void updateInvMatrix()
Definition qpainter.cpp:647
SmallStack< std::unique_ptr< QPainterState > > savedStates
Definition qpainter_p.h:176
static QPainterPrivate * get(QPainter *painter)
Definition qpainter_p.h:217
std::unique_ptr< QPaintEngine, QPaintEngineDestructor > engine
Definition qpainter_p.h:240
void updateState(QPainterState *state)
Definition qpainter.cpp:893
std::unique_ptr< QEmulationPaintEngine > emulationEngine
Definition qpainter_p.h:242
void draw_helper(const QPainterPath &path, DrawOperation operation=StrokeAndFillDraw)
Definition qpainter.cpp:318
QPainter * q_ptr
Definition qpainter_p.h:164
void drawTextItem(const QPointF &p, const QTextItem &_ti, QTextEngine *textEngine)
void drawStretchedGradient(const QPainterPath &path, DrawOperation operation)
Definition qpainter.cpp:512
void updateState(std::unique_ptr< QPainterState > &state)
Definition qpainter_p.h:199
QTransform hidpiScaleTransform() const
Definition qpainter.cpp:229
void detachPainterPrivate(QPainter *q)
Definition qpainter.cpp:291
QPaintDevice * device
Definition qpainter_p.h:229
QTransform viewTransform() const
Definition qpainter.cpp:209
qreal effectiveDevicePixelRatio() const
Definition qpainter.cpp:220
std::unique_ptr< QPainterDummyState > dummyState
Definition qpainter_p.h:178
void checkEmulation()
Definition qpainter.cpp:173
std::unique_ptr< QPainterState > state
Definition qpainter_p.h:171
void updateStateImpl(QPainterState *state)
Definition qpainter.cpp:861
static bool attachPainterPrivate(QPainter *q, QPaintDevice *pdev)
Definition qpainter.cpp:239
void drawGlyphs(const QPointF &decorationPosition, const quint32 *glyphArray, QFixedPoint *positionArray, int glyphCount, QFontEngine *fontEngine, bool overline=false, bool underline=false, bool strikeOut=false)
QVarLengthArray< std::unique_ptr< QPainterPrivate >, NDPtrs > d_ptrs
Definition qpainter_p.h:169
friend class QFontEngine
Definition qpainter.h:432
friend class QPaintEngine
Definition qpainter.h:437
\inmodule QtCore\reentrant
Definition qpoint.h:231
Internal QTextItem.
Q_DECLARE_TYPEINFO(QT_PointF, Q_PRIMITIVE_TYPE)
Q_GUI_EXPORT void qt_draw_tile(QPaintEngine *gc, qreal x, qreal y, qreal w, qreal h, const QPixmap &pixmap, qreal xOffset, qreal yOffset)
void qt_fill_tile(QPixmap *tile, const QPixmap &pixmap)
Q_DECLARE_TYPEINFO(QT_Point, Q_PRIMITIVE_TYPE)
static QPaintEngine * qt_polygon_recursion
qreal qpen_widthf(const QPen &p)
Definition qpainter_p.h:55
Qt::BrushStyle qbrush_style(const QBrush &b)
Definition qpainter_p.h:63
bool qpen_fast_equals(const QPen &a, const QPen &b)
Definition qpainter_p.h:53
Qt::PenStyle qpen_style(const QPen &p)
Definition qpainter_p.h:56
const QColor & qbrush_color(const QBrush &b)
Definition qpainter_p.h:64
const void * data_ptr(const QTransform &t)
Definition qpainter_p.h:48
QString qt_generate_brush_key(const QBrush &brush)
Q_DECLARE_TYPEINFO(QPainterClipInfo, Q_RELOCATABLE_TYPE)
Qt::PenCapStyle qpen_capStyle(const QPen &p)
Definition qpainter_p.h:57
Qt::PenJoinStyle qpen_joinStyle(const QPen &p)
Definition qpainter_p.h:58
QBrush qpen_brush(const QPen &p)
Definition qpainter_p.h:54
bool qbrush_fast_equals(const QBrush &a, const QBrush &b)
Definition qpainter_p.h:62
bool qtransform_fast_equals(const QTransform &a, const QTransform &b)
Definition qpainter_p.h:49
Q_GUI_EXPORT void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, QPainterPrivate::DrawOperation operation)
bool qbrush_has_transform(const QBrush &b)
Definition qpainter_p.h:65
QTransform transform
Definition qpainter_p.h:153
void operator()(QPaintEngine *pe) const noexcept
Definition qpainter_p.h:234