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
qsginternaltextnode_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 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// Qt-Security score:significant reason:default
4
5#ifndef QSGINTERNALTEXTNODE_P_H
6#define QSGINTERNALTEXTNODE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include "qsgtextnode.h"
20#include "qquicktext_p.h"
21#include <qglyphrun.h>
22
23#include <QtGui/qcolor.h>
24#include <QtGui/qtextlayout.h>
25#include <QtCore/qvarlengtharray.h>
26#include <QtCore/qscopedpointer.h>
27
28QT_BEGIN_NAMESPACE
29
30class QSGGlyphNode;
31class QTextBlock;
32class QColor;
33class QTextDocument;
34class QSGContext;
35class QRawFont;
36class QSGInternalImageNode;
37class QSGInternalRectangleNode;
38class QSGVisitableNode;
39class QSGClipNode;
40class QSGTexture;
41class QSGRenderContext;
42
44
45class Q_QUICK_EXPORT QSGInternalTextNode : public QSGTextNode
46{
47public:
48 struct RecycleBin {
49 enum NodeType : quint8 { GlyphNode, RectangleNode, ImageNode };
50
51 struct UnusedNode {
52 QSGVisitableNode *node;
53 NodeType type;
54 };
55
56 RecycleBin() = default;
57 ~RecycleBin()
58 {
59 Q_ASSERT(unusedNodes.isEmpty());
60 Q_ASSERT(unusedTextures.isEmpty());
61 }
62
63 // Reusing a node leaves it where it already is in the child list, and the child list is
64 // the draw order, so nodes can only be handed out in the order they were collected and
65 // only as children of the text node itself. Once the requests diverge from that, the
66 // rest of the bin has to be discarded instead of reused.
67 QSGVisitableNode *takeNextReusableNode(NodeType type)
68 {
69 const UnusedNode *next = peekNextReusableNode(type);
70 if (next == nullptr)
71 return nullptr;
72
73 ++reusedNodes;
74 return next->node;
75 }
76
77 QSGGlyphNode *takeNextReusableGlyphNode(QSGTextNode::RenderType renderType);
78
79 void stopReusing() { reuseStopped = true; }
80
81 QVarLengthArray<UnusedNode, 8> unusedNodes;
82 qsizetype reusedNodes = 0;
83 bool reuseStopped = false;
84 QList<QSGTexture *> unusedTextures;
85
86 private:
87 const UnusedNode *peekNextReusableNode(NodeType type)
88 {
89 if (!reuseStopped) {
90 if (reusedNodes < unusedNodes.size()) {
91 const UnusedNode &next = unusedNodes.at(reusedNodes);
92 if (next.type == type)
93 return &next;
94 }
95 stopReusing();
96 }
97 return nullptr;
98 }
99
100 Q_DISABLE_COPY(RecycleBin)
101 };
102
103 QSGInternalTextNode(QSGRenderContext *renderContext);
104 ~QSGInternalTextNode();
105
106 static bool isComplexRichText(QTextDocument *);
107
108 void setColor(QColor color) override
109 {
110 m_color = color;
111 }
112
113 QColor color() const override
114 {
115 return m_color;
116 }
117
118 void setTextStyle(TextStyle textStyle) override
119 {
120 m_textStyle = textStyle;
121 }
122
123 TextStyle textStyle() override
124 {
125 return m_textStyle;
126 }
127
128 void setStyleColor(QColor styleColor) override
129 {
130 m_styleColor = styleColor;
131 }
132
133 QColor styleColor() const override
134 {
135 return m_styleColor;
136 }
137
138 void setLinkColor(QColor linkColor) override
139 {
140 m_linkColor = linkColor;
141 }
142
143 QColor linkColor() const override
144 {
145 return m_linkColor;
146 }
147
148 void setSelectionColor(QColor selectionColor) override
149 {
150 m_selectionColor = selectionColor;
151 }
152
153 QColor selectionColor() const override
154 {
155 return m_selectionColor;
156 }
157
158 void setSelectionTextColor(QColor selectionTextColor) override
159 {
160 m_selectionTextColor = selectionTextColor;
161 }
162
163 QColor selectionTextColor() const override
164 {
165 return m_selectionTextColor;
166 }
167
168 void setRenderTypeQuality(int renderTypeQuality) override
169 {
170 m_renderTypeQuality = renderTypeQuality;
171 }
172 int renderTypeQuality() const override
173 {
174 return m_renderTypeQuality;
175 }
176
177 void setRenderType(RenderType renderType) override
178 {
179 m_renderType = renderType;
180 }
181
182 RenderType renderType() const override
183 {
184 return m_renderType;
185 }
186
187 bool containsUnscalableGlyphs() const
188 {
189 return m_containsUnscalableGlyphs;
190 }
191
192 void setFiltering(QSGTexture::Filtering filtering) override
193 {
194 m_filtering = filtering;
195 }
196
197 QSGTexture::Filtering filtering() const override
198 {
199 return m_filtering;
200 }
201
202 void setViewport(const QRectF &viewport) override
203 {
204 m_viewport = viewport;
205 }
206
207 QRectF viewport() const override
208 {
209 return m_viewport;
210 }
211
212 void setDevicePixelRatio(qreal dpr)
213 {
214 m_devicePixelRatio = dpr;
215 }
216
217 void setCursor(const QRectF &rect, const QColor &color, RecycleBin *recycleBin);
218 void clearCursor();
219
220 void addRectangleNode(const QRectF &rect, const QColor &color, RecycleBin *recycleBin);
221 virtual void addDecorationNode(const QRectF &rect,
222 const QColor &color,
223 QTextCharFormat::UnderlineStyle style,
224 RecycleBin *recycleBin);
225 void addImage(const QRectF &rect, const QImage &image, RecycleBin *recycleBin);
226 void clear() override;
227 void recycle(RecycleBin *recycleBin);
228 QSGGlyphNode *addGlyphs(const QPointF &position,
229 const QGlyphRun &glyphs,
230 const QColor &color,
231 RecycleBin *recycleBin,
232 QQuickText::TextStyle style = QQuickText::Normal,
233 const QColor &styleColor = QColor(),
234 QSGNode *parentNode = 0);
235
236 QSGInternalRectangleNode *cursorNode() const { return m_cursorNode; }
237 std::pair<int, int> renderedLineRange() const { return { m_firstLineInViewport, m_firstLinePastViewport }; }
238
239 void discardUnusedNodes(RecycleBin *recycleBin);
240
241 void addTextLayout(QPointF position,
242 QTextLayout *layout,
243 RecycleBin *recycleBin,
244 int selectionStart = -1,
245 int selectionCount = -1,
246 int lineStart = 0,
247 int lineCount = -1)
248 {
249 doAddTextLayout(position, layout, selectionStart, selectionCount, lineStart, lineCount, recycleBin);
250 }
251
252 void addTextDocument(QPointF position,
253 QTextDocument *document,
254 RecycleBin *recycleBin,
255 int selectionStart = -1,
256 int selectionCount = -1)
257 {
258 doAddTextDocument(position, document, selectionStart, selectionCount, recycleBin);
259 }
260
261protected:
262 void doAddTextLayout(QPointF position,
263 QTextLayout *textLayout,
264 int selectionStart,
265 int selectionEnd,
266 int lineStart,
267 int lineCount,
268 RecycleBin *recycleBin);
269
270 void doAddTextLayout(QPointF position,
271 QTextLayout *textLayout,
272 int selectionStart,
273 int selectionEnd,
274 int lineStart,
275 int lineCount) override
276 {
277 doAddTextLayout(position, textLayout, selectionStart, selectionEnd, lineStart, lineCount, nullptr);
278 }
279
280 void doAddTextDocument(QPointF position,
281 QTextDocument *textDocument,
282 int selectionStart,
283 int selectionEnd,
284 RecycleBin *recycleBin);
285 void doAddTextDocument(QPointF position,
286 QTextDocument *textDocument,
287 int selectionStart,
288 int selectionEnd) override
289 {
290 doAddTextDocument(position, textDocument, selectionStart, selectionEnd, nullptr);
291 }
292
293private:
294 QSGInternalImageNode *findOrCreateImageNode(RecycleBin *recycleBin);
295 QSGGlyphNode *findOrCreateGlyphNode(RenderType renderType,
296 RecycleBin *recycleBin,
297 QSGNode *parentNode);
298 QSGInternalRectangleNode *findOrCreateRectangleNode(RecycleBin *recycleBin);
299
300 QSGInternalRectangleNode *m_cursorNode = nullptr;
301 QList<QSGTexture *> m_textures;
302 QSGRenderContext *m_renderContext = nullptr;
303 RenderType m_renderType = QtRendering;
304 TextStyle m_textStyle = Normal;
305 QRectF m_viewport;
306 QColor m_color = QColor(0, 0, 0);
307 QColor m_styleColor = QColor(0, 0, 0);
308 QColor m_linkColor = QColor(0, 0, 255);
309 QColor m_selectionColor = QColor(0, 0, 128);
310 QColor m_selectionTextColor = QColor(255, 255, 255);
311 QSGTexture::Filtering m_filtering = QSGTexture::Nearest;
312 int m_renderTypeQuality = -1;
313 int m_firstLineInViewport = -1;
314 int m_firstLinePastViewport = -1;
315 bool m_containsUnscalableGlyphs = false;
316 qreal m_devicePixelRatio = 1.0;
317
318 friend class QQuickTextEdit;
319 friend class QQuickTextEditPrivate;
320};
321
322QT_END_NAMESPACE
323
324#endif // QSGINTERNALTEXTNODE_P_H
Combined button and popup list for selecting options.
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
#define QQUICKTEXT_LARGETEXT_THRESHOLD
static void positionInlineImage(QQuickStyledTextImgTag *image, int textPos, const QTextLine &line)
static void getLinks_helper(const QTextLayout *layout, QList< QQuickTextPrivate::LinkDesc > *links)