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
4#ifndef QSGINTERNALTEXTNODE_P_H
5#define QSGINTERNALTEXTNODE_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 "qsgtextnode.h"
19#include "qquicktext_p.h"
20#include <qglyphrun.h>
21
22#include <QtGui/qcolor.h>
23#include <QtGui/qtextlayout.h>
24#include <QtCore/qvarlengtharray.h>
25#include <QtCore/qscopedpointer.h>
26
27QT_BEGIN_NAMESPACE
28
29class QSGGlyphNode;
30class QTextBlock;
31class QColor;
32class QTextDocument;
33class QSGContext;
34class QRawFont;
35class QSGInternalRectangleNode;
36class QSGClipNode;
37class QSGTexture;
38class QSGRenderContext;
39
40class QQuickTextNodeEngine;
41
42class Q_QUICK_EXPORT QSGInternalTextNode : public QSGTextNode
43{
44public:
45 QSGInternalTextNode(QSGRenderContext *renderContext);
46 ~QSGInternalTextNode();
47
48 static bool isComplexRichText(QTextDocument *);
49
50 void setColor(QColor color) override
51 {
52 m_color = color;
53 }
54
55 QColor color() const override
56 {
57 return m_color;
58 }
59
60 void setTextStyle(TextStyle textStyle) override
61 {
62 m_textStyle = textStyle;
63 }
64
65 TextStyle textStyle() override
66 {
67 return m_textStyle;
68 }
69
70 void setStyleColor(QColor styleColor) override
71 {
72 m_styleColor = styleColor;
73 }
74
75 QColor styleColor() const override
76 {
77 return m_styleColor;
78 }
79
80 void setLinkColor(QColor linkColor) override
81 {
82 m_linkColor = linkColor;
83 }
84
85 QColor linkColor() const override
86 {
87 return m_linkColor;
88 }
89
90 void setSelectionColor(QColor selectionColor) override
91 {
92 m_selectionColor = selectionColor;
93 }
94
95 QColor selectionColor() const override
96 {
97 return m_selectionColor;
98 }
99
100 void setSelectionTextColor(QColor selectionTextColor) override
101 {
102 m_selectionTextColor = selectionTextColor;
103 }
104
105 QColor selectionTextColor() const override
106 {
107 return m_selectionTextColor;
108 }
109
110 void setRenderTypeQuality(int renderTypeQuality) override
111 {
112 m_renderTypeQuality = renderTypeQuality;
113 }
114 int renderTypeQuality() const override
115 {
116 return m_renderTypeQuality;
117 }
118
119 void setRenderType(RenderType renderType) override
120 {
121 m_renderType = renderType;
122 }
123
124 RenderType renderType() const override
125 {
126 return m_renderType;
127 }
128
129 bool containsUnscalableGlyphs() const
130 {
131 return m_containsUnscalableGlyphs;
132 }
133
134 void setFiltering(QSGTexture::Filtering filtering) override
135 {
136 m_filtering = filtering;
137 }
138
139 QSGTexture::Filtering filtering() const override
140 {
141 return m_filtering;
142 }
143
144 void setViewport(const QRectF &viewport) override
145 {
146 m_viewport = viewport;
147 }
148
149 QRectF viewport() const override
150 {
151 return m_viewport;
152 }
153
154 void setDevicePixelRatio(qreal dpr)
155 {
156 m_devicePixelRatio = dpr;
157 }
158
159 void setCursor(const QRectF &rect, const QColor &color);
160 void clearCursor();
161
162 void addRectangleNode(const QRectF &rect, const QColor &color);
163 virtual void addDecorationNode(const QRectF &rect, const QColor &color);
164 void addImage(const QRectF &rect, const QImage &image);
165 void clear() override;
166 QSGGlyphNode *addGlyphs(const QPointF &position, const QGlyphRun &glyphs, const QColor &color,
167 QQuickText::TextStyle style = QQuickText::Normal, const QColor &styleColor = QColor(),
168 QSGNode *parentNode = 0);
169
170 QSGInternalRectangleNode *cursorNode() const { return m_cursorNode; }
171 std::pair<int, int> renderedLineRange() const { return { m_firstLineInViewport, m_firstLinePastViewport }; }
172
173protected:
174 void doAddTextLayout(QPointF position,
175 QTextLayout *textLayout,
176 int selectionStart,
177 int selectionEnd,
178 int lineStart,
179 int lineCount) override;
180
181 void doAddTextDocument(QPointF position,
182 QTextDocument *textDocument,
183 int selectionStart,
184 int selectionEnd) override;
185
186private:
187 QSGInternalRectangleNode *m_cursorNode = nullptr;
188 QList<QSGTexture *> m_textures;
189 QSGRenderContext *m_renderContext = nullptr;
190 RenderType m_renderType = QtRendering;
191 TextStyle m_textStyle = Normal;
192 QRectF m_viewport;
193 QColor m_color = QColor(0, 0, 0);
194 QColor m_styleColor = QColor(0, 0, 0);
195 QColor m_linkColor = QColor(0, 0, 255);
196 QColor m_selectionColor = QColor(0, 0, 128);
197 QColor m_selectionTextColor = QColor(255, 255, 255);
198 QSGTexture::Filtering m_filtering = QSGTexture::Nearest;
199 int m_renderTypeQuality = -1;
200 int m_firstLineInViewport = -1;
201 int m_firstLinePastViewport = -1;
202 bool m_containsUnscalableGlyphs = false;
203 qreal m_devicePixelRatio = 1.0;
204
205 friend class QQuickTextEdit;
206 friend class QQuickTextEditPrivate;
207};
208
209QT_END_NAMESPACE
210
211#endif // QSGINTERNALTEXTNODE_P_H
212

source code of qtdeclarative/src/quick/items/qsginternaltextnode_p.h