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#ifndef QQUICKTEXTNODEENGINE_P_H
16#define QQUICKTEXTNODEENGINE_P_H
17
18//
19// W A R N I N G
20// -------------
21//
22// This file is not part of the Qt API. It exists purely as an
23// implementation detail. This header file may change from version to
24// version without notice, or even be removed.
25//
26// We mean it.
27//
28
30
31// Engine that takes glyph runs as input, and produces a set of glyph nodes, clip nodes,
32// and rectangle nodes to represent the text, decorations and selection. Will try to minimize
33// number of nodes, and join decorations in neighbouring items
34
36public:
39 Underline = 0x1,
40 Overline = 0x2,
41 StrikeOut = 0x4,
43 };
44 Q_DECLARE_FLAGS(Decorations, Decoration)
45
50
52
58
59 BinaryTreeNode(const QRectF &brect, const QImage &i, SelectionState selState, qreal a)
62 {
63 }
64
65 BinaryTreeNode(const QGlyphRun &g, SelectionState selState, const QRectF &brect,
66 const Decorations &decs, const QColor &c, const QColor &bc, const QColor &dc,
67 const QPointF &pos, qreal a);
68
74 QColor color;
80
83
84 QList<std::pair<int, int> > ranges;
85
86 static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const QRectF &rect, const QImage &image, qreal ascent, SelectionState selectionState)
87 { insert(binaryTree, BinaryTreeNode(rect, image, selectionState, ascent)); }
88
89 static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const QGlyphRun &glyphRun, SelectionState selectionState,
90 Decorations decorations, const QColor &textColor, const QColor &backgroundColor, const QColor &underlineColor, const QPointF &position);
91 static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const BinaryTreeNode &binaryTreeNode);
92 static void inOrder(const QVarLengthArray<BinaryTreeNode, 16> &binaryTree, QVarLengthArray<int> *sortedIndexes, int currentIndex = 0);
93 };
94
96 {
98
99 bool operator==(const BinaryTreeNodeKey &otherKey) const
100 {
101 return fontEngine == otherKey.fontEngine
102 && clipNode == otherKey.clipNode
103 && color == otherKey.color
104 && selectionState == otherKey.selectionState;
105 }
106
111 };
112
115 , m_hasSelection(false)
116 , m_hasContents(false)
117 {}
118
119 bool hasContents() const { return m_hasContents; }
120 void addTextBlock(QTextDocument *, const QTextBlock &, const QPointF &position, const QColor &textColor,
121 const QColor& anchorColor, int selectionStart, int selectionEnd, const QRectF &viewport = QRectF());
122 QTextLine currentLine() const { return m_currentLine; }
123
124 void setCurrentLine(const QTextLine &currentLine)
125 {
126 if (m_currentLine.isValid())
127 processCurrentLine();
128
129 m_currentLine = currentLine;
130 }
131
132 void setCurrentTextDirection(Qt::LayoutDirection textDirection)
133 {
134 m_currentTextDirection = textDirection;
135 }
136
137 void addBorder(const QRectF &rect, qreal border, QTextFrameFormat::BorderStyle borderStyle,
138 const QBrush &borderBrush);
139 void addFrameDecorations(QTextDocument *document, QTextFrame *frame);
140 void addImage(const QRectF &rect, const QImage &image, qreal ascent,
141 SelectionState selectionState,
142 QTextFrameFormat::Position layoutPosition);
143 int addText(const QTextBlock &block,
144 const QTextCharFormat &charFormat,
145 const QColor &textColor,
146 const QVarLengthArray<QTextLayout::FormatRange> &colorChanges,
147 int textPos, int fragmentEnd,
148 int selectionStart, int selectionEnd);
149 void addTextObject(const QTextBlock &block, const QPointF &position, const QTextCharFormat &format,
150 SelectionState selectionState,
151 QTextDocument *textDocument, int pos,
152 QTextFrameFormat::Position layoutPosition = QTextFrameFormat::InFlow);
153 void addSelectedGlyphs(const QGlyphRun &glyphRun);
154 void addUnselectedGlyphs(const QGlyphRun &glyphRun);
155 void addGlyphsInRange(int rangeStart, int rangeEnd,
156 const QColor &color, const QColor &backgroundColor, const QColor &underlineColor,
157 int selectionStart, int selectionEnd);
158 void addGlyphsForRanges(const QVarLengthArray<QTextLayout::FormatRange> &ranges,
159 int start, int end,
160 int selectionStart, int selectionEnd);
161
162 void mergeProcessedNodes(QList<BinaryTreeNode *> *regularNodes,
163 QList<BinaryTreeNode *> *imageNodes);
164 void addToSceneGraph(QSGInternalTextNode *parent,
165 QQuickText::TextStyle style = QQuickText::Normal,
166 const QColor &styleColor = QColor());
167
168 void setSelectionColor(const QColor &selectionColor)
169 {
170 m_selectionColor = selectionColor;
171 }
172
173 void setSelectedTextColor(const QColor &selectedTextColor)
174 {
175 m_selectedTextColor = selectedTextColor;
176 }
177
178 void setTextColor(const QColor &textColor)
179 {
180 m_textColor = textColor;
181 }
182
183 void setAnchorColor(const QColor &anchorColor)
184 {
185 m_anchorColor = anchorColor;
186 }
187
188 void setPosition(const QPointF &position)
189 {
190 m_position = position;
191 }
192
193 void setDevicePixelRatio(qreal dpr)
194 {
195 m_devicePixelRatio = dpr;
196 }
197
198private:
199 struct TextDecoration
200 {
201 TextDecoration() : selectionState(Unselected) {}
202 TextDecoration(const SelectionState &s,
203 const QRectF &r,
204 const QColor &c)
205 : selectionState(s)
206 , rect(r)
207 , color(c)
208 {
209 }
210
211 SelectionState selectionState;
212 QRectF rect;
213 QColor color;
214 };
215
216 void processCurrentLine();
217 void addTextDecorations(const QVarLengthArray<TextDecoration> &textDecorations, qreal offset, qreal thickness);
218 void mergeFormats(QTextLayout *textLayout, QVarLengthArray<QTextLayout::FormatRange> *mergedFormats);
219
220 QColor m_selectionColor;
221 QColor m_textColor;
222 QColor m_backgroundColor;
223 QColor m_decorationColor;
224 QColor m_selectedTextColor;
225 QColor m_anchorColor;
226 QPointF m_position;
227
228 QTextLine m_currentLine;
229 Qt::LayoutDirection m_currentTextDirection;
230
232 QList<QRectF> m_selectionRects;
233 QVarLengthArray<BinaryTreeNode, 16> m_currentLineTree;
234
235 QList<TextDecoration> m_lines;
236 QVector<BinaryTreeNode> m_processedNodes;
237
238 qreal m_devicePixelRatio = 1.0;
239
240 bool m_hasSelection : 1;
241 bool m_hasContents : 1;
242 friend class QSGInternalTextNode;
243
244};
245
246QT_END_NAMESPACE
247
248#endif // QQUICKTEXTNODEENGINE_P_H
void addSelectedGlyphs(const QGlyphRun &glyphRun)
void addUnselectedGlyphs(const QGlyphRun &glyphRun)
void addTextObject(const QTextBlock &block, const QPointF &position, const QTextCharFormat &format, SelectionState selectionState, QTextDocument *textDocument, int pos, QTextFrameFormat::Position layoutPosition=QTextFrameFormat::InFlow)
void mergeProcessedNodes(QList< BinaryTreeNode * > *regularNodes, QList< BinaryTreeNode * > *imageNodes)
void addTextBlock(QTextDocument *, const QTextBlock &, const QPointF &position, const QColor &textColor, const QColor &anchorColor, int selectionStart, int selectionEnd, const QRectF &viewport=QRectF())
void addGlyphsInRange(int rangeStart, int rangeEnd, const QColor &color, const QColor &backgroundColor, const QColor &underlineColor, int selectionStart, int selectionEnd)
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 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)
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
#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
static void insert(QVarLengthArray< BinaryTreeNode, 16 > *binaryTree, const QRectF &rect, const QImage &image, qreal ascent, SelectionState selectionState)
BinaryTreeNode(const QGlyphRun &g, SelectionState selState, const QRectF &brect, const Decorations &decs, const QColor &c, const QColor &bc, const QColor &dc, const QPointF &pos, qreal a)
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)
static void insert(QVarLengthArray< BinaryTreeNode, 16 > *binaryTree, const QGlyphRun &glyphRun, SelectionState selectionState, Decorations decorations, const QColor &textColor, const QColor &backgroundColor, const QColor &underlineColor, const QPointF &position)