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 QSGClipNode;
39class QSGTexture;
40class QSGRenderContext;
41
43
44class Q_QUICK_EXPORT QSGInternalTextNode : public QSGTextNode
45{
46public:
47 struct RecycleBin {
48 RecycleBin() = default;
49 ~RecycleBin()
50 {
51 Q_ASSERT(unusedGlyphNodes.isEmpty());
52 Q_ASSERT(unusedRectangleNodes.isEmpty());
53 Q_ASSERT(unusedImageNodes.isEmpty());
54 Q_ASSERT(unusedTextures.isEmpty());
55 }
56
57 QVarLengthArray<QSGGlyphNode *, 8> unusedGlyphNodes;
58 QVarLengthArray<QSGInternalRectangleNode *, 8> unusedRectangleNodes;
59 QVarLengthArray<QSGInternalImageNode *, 8> unusedImageNodes;
60 QList<QSGTexture *> unusedTextures;
61
62 private:
63 Q_DISABLE_COPY(RecycleBin)
64 };
65
66 QSGInternalTextNode(QSGRenderContext *renderContext);
67 ~QSGInternalTextNode();
68
69 static bool isComplexRichText(QTextDocument *);
70
71 void setColor(QColor color) override
72 {
73 m_color = color;
74 }
75
76 QColor color() const override
77 {
78 return m_color;
79 }
80
81 void setTextStyle(TextStyle textStyle) override
82 {
83 m_textStyle = textStyle;
84 }
85
86 TextStyle textStyle() override
87 {
88 return m_textStyle;
89 }
90
91 void setStyleColor(QColor styleColor) override
92 {
93 m_styleColor = styleColor;
94 }
95
96 QColor styleColor() const override
97 {
98 return m_styleColor;
99 }
100
101 void setLinkColor(QColor linkColor) override
102 {
103 m_linkColor = linkColor;
104 }
105
106 QColor linkColor() const override
107 {
108 return m_linkColor;
109 }
110
111 void setSelectionColor(QColor selectionColor) override
112 {
113 m_selectionColor = selectionColor;
114 }
115
116 QColor selectionColor() const override
117 {
118 return m_selectionColor;
119 }
120
121 void setSelectionTextColor(QColor selectionTextColor) override
122 {
123 m_selectionTextColor = selectionTextColor;
124 }
125
126 QColor selectionTextColor() const override
127 {
128 return m_selectionTextColor;
129 }
130
131 void setRenderTypeQuality(int renderTypeQuality) override
132 {
133 m_renderTypeQuality = renderTypeQuality;
134 }
135 int renderTypeQuality() const override
136 {
137 return m_renderTypeQuality;
138 }
139
140 void setRenderType(RenderType renderType) override
141 {
142 m_renderType = renderType;
143 }
144
145 RenderType renderType() const override
146 {
147 return m_renderType;
148 }
149
150 bool containsUnscalableGlyphs() const
151 {
152 return m_containsUnscalableGlyphs;
153 }
154
155 void setFiltering(QSGTexture::Filtering filtering) override
156 {
157 m_filtering = filtering;
158 }
159
160 QSGTexture::Filtering filtering() const override
161 {
162 return m_filtering;
163 }
164
165 void setViewport(const QRectF &viewport) override
166 {
167 m_viewport = viewport;
168 }
169
170 QRectF viewport() const override
171 {
172 return m_viewport;
173 }
174
175 void setDevicePixelRatio(qreal dpr)
176 {
177 m_devicePixelRatio = dpr;
178 }
179
180 void setCursor(const QRectF &rect, const QColor &color, RecycleBin *recycleBin);
181 void clearCursor();
182
183 void addRectangleNode(const QRectF &rect, const QColor &color, RecycleBin *recycleBin);
184 virtual void addDecorationNode(const QRectF &rect,
185 const QColor &color,
186 QTextCharFormat::UnderlineStyle style,
187 RecycleBin *recycleBin);
188 void addImage(const QRectF &rect, const QImage &image, RecycleBin *recycleBin);
189 void clear() override;
190 void recycle(RecycleBin *recycleBin);
191 QSGGlyphNode *addGlyphs(const QPointF &position,
192 const QGlyphRun &glyphs,
193 const QColor &color,
194 RecycleBin *recycleBin,
195 QQuickText::TextStyle style = QQuickText::Normal,
196 const QColor &styleColor = QColor(),
197 QSGNode *parentNode = 0);
198
199 QSGInternalRectangleNode *cursorNode() const { return m_cursorNode; }
200 std::pair<int, int> renderedLineRange() const { return { m_firstLineInViewport, m_firstLinePastViewport }; }
201
202 void discardUnusedNodes(RecycleBin *recycleBin);
203
204 void addTextLayout(QPointF position,
205 QTextLayout *layout,
206 RecycleBin *recycleBin,
207 int selectionStart = -1,
208 int selectionCount = -1,
209 int lineStart = 0,
210 int lineCount = -1)
211 {
212 doAddTextLayout(position, layout, selectionStart, selectionCount, lineStart, lineCount, recycleBin);
213 }
214
215 void addTextDocument(QPointF position,
216 QTextDocument *document,
217 RecycleBin *recycleBin,
218 int selectionStart = -1,
219 int selectionCount = -1)
220 {
221 doAddTextDocument(position, document, selectionStart, selectionCount, recycleBin);
222 }
223
224protected:
225 void doAddTextLayout(QPointF position,
226 QTextLayout *textLayout,
227 int selectionStart,
228 int selectionEnd,
229 int lineStart,
230 int lineCount,
231 RecycleBin *recycleBin);
232
233 void doAddTextLayout(QPointF position,
234 QTextLayout *textLayout,
235 int selectionStart,
236 int selectionEnd,
237 int lineStart,
238 int lineCount) override
239 {
240 doAddTextLayout(position, textLayout, selectionStart, selectionEnd, lineStart, lineCount, nullptr);
241 }
242
243 void doAddTextDocument(QPointF position,
244 QTextDocument *textDocument,
245 int selectionStart,
246 int selectionEnd,
247 RecycleBin *recycleBin);
248 void doAddTextDocument(QPointF position,
249 QTextDocument *textDocument,
250 int selectionStart,
251 int selectionEnd) override
252 {
253 doAddTextDocument(position, textDocument, selectionStart, selectionEnd, nullptr);
254 }
255
256private:
257 QSGInternalImageNode *findOrCreateImageNode(RecycleBin *recycleBin);
258 QSGGlyphNode *findOrCreateGlyphNode(RenderType renderType, RecycleBin *recycleBin);
259 QSGInternalRectangleNode *findOrCreateRectangleNode(RecycleBin *recycleBin);
260
261 QSGInternalRectangleNode *m_cursorNode = nullptr;
262 QList<QSGTexture *> m_textures;
263 QSGRenderContext *m_renderContext = nullptr;
264 RenderType m_renderType = QtRendering;
265 TextStyle m_textStyle = Normal;
266 QRectF m_viewport;
267 QColor m_color = QColor(0, 0, 0);
268 QColor m_styleColor = QColor(0, 0, 0);
269 QColor m_linkColor = QColor(0, 0, 255);
270 QColor m_selectionColor = QColor(0, 0, 128);
271 QColor m_selectionTextColor = QColor(255, 255, 255);
272 QSGTexture::Filtering m_filtering = QSGTexture::Nearest;
273 int m_renderTypeQuality = -1;
274 int m_firstLineInViewport = -1;
275 int m_firstLinePastViewport = -1;
276 bool m_containsUnscalableGlyphs = false;
277 qreal m_devicePixelRatio = 1.0;
278
279 friend class QQuickTextEdit;
280 friend class QQuickTextEditPrivate;
281};
282
283QT_END_NAMESPACE
284
285#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)