49 enum NodeType : quint8 { GlyphNode, RectangleNode, ImageNode };
52 QSGVisitableNode *node;
56 RecycleBin() =
default;
59 Q_ASSERT(unusedNodes.isEmpty());
60 Q_ASSERT(unusedTextures.isEmpty());
67 QSGVisitableNode *takeNextReusableNode(NodeType type)
69 const UnusedNode *next = peekNextReusableNode(type);
77 QSGGlyphNode *takeNextReusableGlyphNode(QSGTextNode::RenderType renderType);
79 void stopReusing() { reuseStopped =
true; }
81 QVarLengthArray<UnusedNode, 8> unusedNodes;
82 qsizetype reusedNodes = 0;
83 bool reuseStopped =
false;
84 QList<QSGTexture *> unusedTextures;
87 const UnusedNode *peekNextReusableNode(NodeType type)
90 if (reusedNodes < unusedNodes.size()) {
91 const UnusedNode &next = unusedNodes.at(reusedNodes);
92 if (next.type == type)
100 Q_DISABLE_COPY(RecycleBin)
103 QSGInternalTextNode(QSGRenderContext *renderContext);
104 ~QSGInternalTextNode();
106 static bool isComplexRichText(QTextDocument *);
108 void setColor(QColor color) override
113 QColor color()
const override
118 void setTextStyle(TextStyle textStyle) override
120 m_textStyle = textStyle;
123 TextStyle textStyle() override
128 void setStyleColor(QColor styleColor) override
130 m_styleColor = styleColor;
133 QColor styleColor()
const override
138 void setLinkColor(QColor linkColor) override
140 m_linkColor = linkColor;
143 QColor linkColor()
const override
148 void setSelectionColor(QColor selectionColor) override
150 m_selectionColor = selectionColor;
153 QColor selectionColor()
const override
155 return m_selectionColor;
158 void setSelectionTextColor(QColor selectionTextColor) override
160 m_selectionTextColor = selectionTextColor;
163 QColor selectionTextColor()
const override
165 return m_selectionTextColor;
168 void setRenderTypeQuality(
int renderTypeQuality) override
170 m_renderTypeQuality = renderTypeQuality;
172 int renderTypeQuality()
const override
174 return m_renderTypeQuality;
177 void setRenderType(RenderType renderType) override
179 m_renderType = renderType;
182 RenderType renderType()
const override
187 bool containsUnscalableGlyphs()
const
189 return m_containsUnscalableGlyphs;
192 void setFiltering(QSGTexture::Filtering filtering) override
194 m_filtering = filtering;
197 QSGTexture::Filtering filtering()
const override
202 void setViewport(
const QRectF &viewport) override
204 m_viewport = viewport;
207 QRectF viewport()
const override
212 void setDevicePixelRatio(qreal dpr)
214 m_devicePixelRatio = dpr;
217 void setCursor(
const QRectF &rect,
const QColor &color, RecycleBin *recycleBin);
220 void addRectangleNode(
const QRectF &rect,
const QColor &color, RecycleBin *recycleBin);
221 virtual void addDecorationNode(
const QRectF &rect,
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,
231 RecycleBin *recycleBin,
232 QQuickText::TextStyle style = QQuickText::Normal,
233 const QColor &styleColor = QColor(),
234 QSGNode *parentNode = 0);
236 QSGInternalRectangleNode *cursorNode()
const {
return m_cursorNode; }
237 std::pair<
int,
int> renderedLineRange()
const {
return { m_firstLineInViewport, m_firstLinePastViewport }; }
239 void discardUnusedNodes(RecycleBin *recycleBin);
241 void addTextLayout(QPointF position,
243 RecycleBin *recycleBin,
244 int selectionStart = -1,
245 int selectionCount = -1,
249 doAddTextLayout(position, layout, selectionStart, selectionCount, lineStart, lineCount, recycleBin);
252 void addTextDocument(QPointF position,
253 QTextDocument *document,
254 RecycleBin *recycleBin,
255 int selectionStart = -1,
256 int selectionCount = -1)
258 doAddTextDocument(position, document, selectionStart, selectionCount, recycleBin);
262 void doAddTextLayout(QPointF position,
263 QTextLayout *textLayout,
268 RecycleBin *recycleBin);
270 void doAddTextLayout(QPointF position,
271 QTextLayout *textLayout,
275 int lineCount) override
277 doAddTextLayout(position, textLayout, selectionStart, selectionEnd, lineStart, lineCount,
nullptr);
280 void doAddTextDocument(QPointF position,
281 QTextDocument *textDocument,
284 RecycleBin *recycleBin);
285 void doAddTextDocument(QPointF position,
286 QTextDocument *textDocument,
288 int selectionEnd) override
290 doAddTextDocument(position, textDocument, selectionStart, selectionEnd,
nullptr);
294 QSGInternalImageNode *findOrCreateImageNode(RecycleBin *recycleBin);
295 QSGGlyphNode *findOrCreateGlyphNode(RenderType renderType,
296 RecycleBin *recycleBin,
297 QSGNode *parentNode);
298 QSGInternalRectangleNode *findOrCreateRectangleNode(RecycleBin *recycleBin);
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;
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;
318 friend class QQuickTextEdit;
319 friend class QQuickTextEditPrivate;
#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)