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
qquicktextnodeengine_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// Qt-Security score:significant reason:default
4
5#include <QtCore/qlist.h>
6#include <QtCore/qvarlengtharray.h>
7#include <QtGui/qcolor.h>
8#include <QtGui/qglyphrun.h>
9#include <QtGui/qimage.h>
10#include <QtGui/qtextdocument.h>
11#include <QtGui/qtextlayout.h>
14
15#include <QtCore/qspan.h>
16
17#ifndef QQUICKTEXTNODEENGINE_P_H
18#define QQUICKTEXTNODEENGINE_P_H
19
20//
21// W A R N I N G
22// -------------
23//
24// This file is not part of the Qt API. It exists purely as an
25// implementation detail. This header file may change from version to
26// version without notice, or even be removed.
27//
28// We mean it.
29//
30
32
33// Engine that takes glyph runs as input, and produces a set of glyph nodes, clip nodes,
34// and rectangle nodes to represent the text, decorations and selection. Will try to minimize
35// number of nodes, and join decorations in neighbouring items
36
38public:
41 Underline = 0x1,
42 Overline = 0x2,
43 StrikeOut = 0x4,
45 };
46 Q_DECLARE_FLAGS(Decorations, Decoration)
47
52
54
60
61 BinaryTreeNode(const QRectF &brect, const QImage &i, SelectionState selState, qreal a)
64 {
65 }
66
67 BinaryTreeNode(const QGlyphRun &g, SelectionState selState, const QRectF &brect,
68 const Decorations &decs, QTextCharFormat::UnderlineStyle us,
69 const QColor &c, const QColor &bc, const QColor &dc,
70 const QPointF &pos, qreal a);
71
78 QColor color;
84
87
88 QList<std::pair<int, int> > ranges;
89
90 static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const QRectF &rect, const QImage &image, qreal ascent, SelectionState selectionState)
91 { insert(binaryTree, BinaryTreeNode(rect, image, selectionState, ascent)); }
92
93 static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree,
94 const QGlyphRun &glyphRun, SelectionState selectionState,
95 Decorations decorations, QTextCharFormat::UnderlineStyle underlineStyle,
96 const QColor &textColor, const QColor &backgroundColor,
97 const QColor &underlineColor, const QPointF &position);
98 static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const BinaryTreeNode &binaryTreeNode);
99 static void inOrder(const QVarLengthArray<BinaryTreeNode, 16> &binaryTree, QVarLengthArray<int> *sortedIndexes, int currentIndex = 0);
100 };
101
103 {
105
106 bool operator==(const BinaryTreeNodeKey &otherKey) const
107 {
108 return fontEngine == otherKey.fontEngine
109 && clipNode == otherKey.clipNode
110 && color == otherKey.color
111 && selectionState == otherKey.selectionState;
112 }
113
118 };
119
122 , m_hasSelection(false)
123 , m_hasContents(false)
124 {}
125
126 bool hasContents() const { return m_hasContents; }
127 void addTextBlock(QTextDocument *, const QTextBlock &, const QPointF &position, const QColor &textColor,
128 const QColor& anchorColor, int selectionStart, int selectionEnd, const QRectF &viewport = QRectF());
129 QTextLine currentLine() const { return m_currentLine; }
130
131 void setCurrentLine(const QTextLine &currentLine)
132 {
133 if (m_currentLine.isValid())
134 processCurrentLine();
135
136 m_currentLine = currentLine;
137 }
138
139 void setCurrentTextDirection(Qt::LayoutDirection textDirection)
140 {
141 m_currentTextDirection = textDirection;
142 }
143
144 void addBorder(const QRectF &rect, qreal border, QTextFrameFormat::BorderStyle borderStyle,
145 const QBrush &borderBrush);
146 void addFrameDecorations(QTextDocument *document, QTextFrame *frame);
147 void addImage(const QRectF &rect, const QImage &image, qreal ascent,
148 SelectionState selectionState,
149 QTextFrameFormat::Position layoutPosition);
150 int addText(const QTextBlock &block,
151 const QTextCharFormat &charFormat,
152 const QColor &textColor,
153 const QVarLengthArray<QTextLayout::FormatRange> &colorChanges,
154 int textPos, int fragmentEnd,
155 int selectionStart, int selectionEnd);
156 void addTextObject(const QTextBlock &block, const QPointF &position, const QTextCharFormat &format,
157 SelectionState selectionState,
158 QTextDocument *textDocument, int pos,
159 QTextFrameFormat::Position layoutPosition = QTextFrameFormat::InFlow);
160 void addSelectedGlyphs(const QGlyphRun &glyphRun);
161 void addUnselectedGlyphs(const QGlyphRun &glyphRun);
162 void addGlyphsInRange(int rangeStart, int rangeEnd,
163 QTextCharFormat::UnderlineStyle underlineStyle,
164 const QColor &color, const QColor &backgroundColor,
165 const QColor &underlineColor, int selectionStart, int selectionEnd);
166 void addGlyphsForRanges(const QVarLengthArray<QTextLayout::FormatRange> &ranges,
167 int start, int end,
168 int selectionStart, int selectionEnd);
169
170 void mergeProcessedNodes(QVarLengthArray<BinaryTreeNode *, 8> *regularNodes,
171 QVarLengthArray<BinaryTreeNode *, 8> *imageNodes);
172 void addToSceneGraph(QSGInternalTextNode *parent,
173 QSGInternalTextNode::RecycleBin *recycleBin,
174 QQuickText::TextStyle style = QQuickText::Normal,
175 const QColor &styleColor = QColor());
176
177 void setSelectionColor(const QColor &selectionColor)
178 {
179 m_selectionColor = selectionColor;
180 }
181
182 void setSelectedTextColor(const QColor &selectedTextColor)
183 {
184 m_selectedTextColor = selectedTextColor;
185 }
186
187 void setTextColor(const QColor &textColor)
188 {
189 m_textColor = textColor;
190 }
191
192 void setAnchorColor(const QColor &anchorColor)
193 {
194 m_anchorColor = anchorColor;
195 }
196
197 void setPosition(const QPointF &position)
198 {
199 m_position = position;
200 }
201
202 void setDevicePixelRatio(qreal dpr)
203 {
204 m_devicePixelRatio = dpr;
205 }
206
207private:
208 struct TextDecoration
209 {
210 TextDecoration() : selectionState(Unselected) {}
211 TextDecoration(const SelectionState &s, const QRectF &r, const QColor &c,
212 QTextCharFormat::UnderlineStyle us = QTextCharFormat::NoUnderline)
213 : selectionState(s), underlineStyle(us), rect(r), color(c)
214 {
215 }
216
217 SelectionState selectionState;
218 QTextCharFormat::UnderlineStyle underlineStyle = QTextCharFormat::NoUnderline;
219 QRectF rect;
220 QColor color;
221 };
222
223 void processCurrentLine();
224 void addTextDecorations(QSpan<const TextDecoration> textDecorations, qreal offset, qreal thickness);
225 void mergeFormats(QTextLayout *textLayout, QVarLengthArray<QTextLayout::FormatRange> *mergedFormats);
226
227 QColor m_selectionColor;
228 QColor m_textColor;
229 QColor m_backgroundColor;
230 QColor m_decorationColor;
231 QColor m_selectedTextColor;
232 QColor m_anchorColor;
233 QPointF m_position;
234 QTextCharFormat::UnderlineStyle m_underlineStyle = QTextCharFormat::NoUnderline;
235
236 QTextLine m_currentLine;
237 Qt::LayoutDirection m_currentTextDirection;
238
240 QList<QRectF> m_selectionRects;
241 QVarLengthArray<BinaryTreeNode, 16> m_currentLineTree;
242
243 QList<TextDecoration> m_lines;
244 QList<BinaryTreeNode> m_processedNodes;
245
246 qreal m_devicePixelRatio = 1.0;
247
248 bool m_hasSelection : 1;
249 bool m_hasContents : 1;
250 friend class QSGInternalTextNode;
251
252};
253
254QT_END_NAMESPACE
255
256#endif // QQUICKTEXTNODEENGINE_P_H
void addSelectedGlyphs(const QGlyphRun &glyphRun)
void addUnselectedGlyphs(const QGlyphRun &glyphRun)
void mergeProcessedNodes(QVarLengthArray< BinaryTreeNode *, 8 > *regularNodes, QVarLengthArray< BinaryTreeNode *, 8 > *imageNodes)
void addTextObject(const QTextBlock &block, const QPointF &position, const QTextCharFormat &format, SelectionState selectionState, QTextDocument *textDocument, int pos, QTextFrameFormat::Position layoutPosition=QTextFrameFormat::InFlow)
void addTextBlock(QTextDocument *, const QTextBlock &, const QPointF &position, const QColor &textColor, const QColor &anchorColor, int selectionStart, int selectionEnd, const QRectF &viewport=QRectF())
void setTextColor(const QColor &textColor)
void setCurrentLine(const QTextLine &currentLine)
int addText(const QTextBlock &block, const QTextCharFormat &charFormat, const QColor &textColor, const QVarLengthArray< QTextLayout::FormatRange > &colorChanges, int textPos, int fragmentEnd, int selectionStart, int selectionEnd)
void setAnchorColor(const QColor &anchorColor)
void addImage(const QRectF &rect, const QImage &image, qreal ascent, SelectionState selectionState, QTextFrameFormat::Position layoutPosition)
void addBorder(const QRectF &rect, qreal border, QTextFrameFormat::BorderStyle borderStyle, const QBrush &borderBrush)
void setPosition(const QPointF &position)
void setDevicePixelRatio(qreal dpr)
void addGlyphsInRange(int rangeStart, int rangeEnd, QTextCharFormat::UnderlineStyle underlineStyle, const QColor &color, const QColor &backgroundColor, const QColor &underlineColor, int selectionStart, int selectionEnd)
void setSelectionColor(const QColor &selectionColor)
void addFrameDecorations(QTextDocument *document, QTextFrame *frame)
void setCurrentTextDirection(Qt::LayoutDirection textDirection)
void addGlyphsForRanges(const QVarLengthArray< QTextLayout::FormatRange > &ranges, int start, int end, int selectionStart, int selectionEnd)
void setSelectedTextColor(const QColor &selectedTextColor)
Combined button and popup list for selecting options.
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
#define QQUICKTEXT_LARGETEXT_THRESHOLD
static bool operator<(const TextNode &n1, const TextNode &n2)
void resetEngine(QQuickTextNodeEngine *engine, const QColor &textColor, const QColor &selectedTextColor, const QColor &selectionColor, qreal dpr)
static const int nodeBreakingSize
\qmlsignal QtQuick::TextEdit::linkActivated(string link)
static void updateNodeTransform(QSGInternalTextNode *node, const QPointF &topLeft)
QQuickTextEditPrivate::Node TextNode
QDebug Q_QUICK_EXPORT operator<<(QDebug debug, const QQuickWindow *item)
bool operator==(const BinaryTreeNodeKey &otherKey) const
BinaryTreeNode(const QGlyphRun &g, SelectionState selState, const QRectF &brect, const Decorations &decs, QTextCharFormat::UnderlineStyle us, const QColor &c, const QColor &bc, const QColor &dc, const QPointF &pos, qreal a)
QTextCharFormat::UnderlineStyle underlineStyle
static void insert(QVarLengthArray< BinaryTreeNode, 16 > *binaryTree, const QRectF &rect, const QImage &image, qreal ascent, SelectionState selectionState)
static void insert(QVarLengthArray< BinaryTreeNode, 16 > *binaryTree, const QGlyphRun &glyphRun, SelectionState selectionState, Decorations decorations, QTextCharFormat::UnderlineStyle underlineStyle, const QColor &textColor, const QColor &backgroundColor, const QColor &underlineColor, const QPointF &position)
static void inOrder(const QVarLengthArray< BinaryTreeNode, 16 > &binaryTree, QVarLengthArray< int > *sortedIndexes, int currentIndex=0)
BinaryTreeNode(const QRectF &brect, const QImage &i, SelectionState selState, qreal a)
static void insert(QVarLengthArray< BinaryTreeNode, 16 > *binaryTree, const BinaryTreeNode &binaryTreeNode)