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, QTextCharFormat::UnderlineStyle us,
67 const QColor &c, const QColor &bc, const QColor &dc,
68 const QPointF &pos, qreal a);
69
76 QColor color;
82
85
86 QList<std::pair<int, int> > ranges;
87
88 static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const QRectF &rect, const QImage &image, qreal ascent, SelectionState selectionState)
89 { insert(binaryTree, BinaryTreeNode(rect, image, selectionState, ascent)); }
90
91 static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree,
92 const QGlyphRun &glyphRun, SelectionState selectionState,
93 Decorations decorations, QTextCharFormat::UnderlineStyle underlineStyle,
94 const QColor &textColor, const QColor &backgroundColor,
95 const QColor &underlineColor, const QPointF &position);
96 static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const BinaryTreeNode &binaryTreeNode);
97 static void inOrder(const QVarLengthArray<BinaryTreeNode, 16> &binaryTree, QVarLengthArray<int> *sortedIndexes, int currentIndex = 0);
98 };
99
101 {
103
104 bool operator==(const BinaryTreeNodeKey &otherKey) const
105 {
106 return fontEngine == otherKey.fontEngine
107 && clipNode == otherKey.clipNode
108 && color == otherKey.color
109 && selectionState == otherKey.selectionState;
110 }
111
116 };
117
120 , m_hasSelection(false)
121 , m_hasContents(false)
122 {}
123
124 bool hasContents() const { return m_hasContents; }
125 void addTextBlock(QTextDocument *, const QTextBlock &, const QPointF &position, const QColor &textColor,
126 const QColor& anchorColor, int selectionStart, int selectionEnd, const QRectF &viewport = QRectF());
127 QTextLine currentLine() const { return m_currentLine; }
128
129 void setCurrentLine(const QTextLine &currentLine)
130 {
131 if (m_currentLine.isValid())
132 processCurrentLine();
133
134 m_currentLine = currentLine;
135 }
136
137 void setCurrentTextDirection(Qt::LayoutDirection textDirection)
138 {
139 m_currentTextDirection = textDirection;
140 }
141
142 void addBorder(const QRectF &rect, qreal border, QTextFrameFormat::BorderStyle borderStyle,
143 const QBrush &borderBrush);
144 void addFrameDecorations(QTextDocument *document, QTextFrame *frame);
145 void addImage(const QRectF &rect, const QImage &image, qreal ascent,
146 SelectionState selectionState,
147 QTextFrameFormat::Position layoutPosition);
148 int addText(const QTextBlock &block,
149 const QTextCharFormat &charFormat,
150 const QColor &textColor,
151 const QVarLengthArray<QTextLayout::FormatRange> &colorChanges,
152 int textPos, int fragmentEnd,
153 int selectionStart, int selectionEnd);
154 void addTextObject(const QTextBlock &block, const QPointF &position, const QTextCharFormat &format,
155 SelectionState selectionState,
156 QTextDocument *textDocument, int pos,
157 QTextFrameFormat::Position layoutPosition = QTextFrameFormat::InFlow);
158 void addSelectedGlyphs(const QGlyphRun &glyphRun);
159 void addUnselectedGlyphs(const QGlyphRun &glyphRun);
160 void addGlyphsInRange(int rangeStart, int rangeEnd,
161 QTextCharFormat::UnderlineStyle underlineStyle,
162 const QColor &color, const QColor &backgroundColor,
163 const QColor &underlineColor, int selectionStart, int selectionEnd);
164 void addGlyphsForRanges(const QVarLengthArray<QTextLayout::FormatRange> &ranges,
165 int start, int end,
166 int selectionStart, int selectionEnd);
167
168 void mergeProcessedNodes(QList<BinaryTreeNode *> *regularNodes,
169 QList<BinaryTreeNode *> *imageNodes);
170 void addToSceneGraph(QSGInternalTextNode *parent,
171 QQuickText::TextStyle style = QQuickText::Normal,
172 const QColor &styleColor = QColor());
173
174 void setSelectionColor(const QColor &selectionColor)
175 {
176 m_selectionColor = selectionColor;
177 }
178
179 void setSelectedTextColor(const QColor &selectedTextColor)
180 {
181 m_selectedTextColor = selectedTextColor;
182 }
183
184 void setTextColor(const QColor &textColor)
185 {
186 m_textColor = textColor;
187 }
188
189 void setAnchorColor(const QColor &anchorColor)
190 {
191 m_anchorColor = anchorColor;
192 }
193
194 void setPosition(const QPointF &position)
195 {
196 m_position = position;
197 }
198
199 void setDevicePixelRatio(qreal dpr)
200 {
201 m_devicePixelRatio = dpr;
202 }
203
204private:
205 struct TextDecoration
206 {
207 TextDecoration() : selectionState(Unselected) {}
208 TextDecoration(const SelectionState &s, const QRectF &r, const QColor &c,
209 QTextCharFormat::UnderlineStyle us = QTextCharFormat::NoUnderline)
210 : selectionState(s), underlineStyle(us), rect(r), color(c)
211 {
212 }
213
214 SelectionState selectionState;
215 QTextCharFormat::UnderlineStyle underlineStyle = QTextCharFormat::NoUnderline;
216 QRectF rect;
217 QColor color;
218 };
219
220 void processCurrentLine();
221 void addTextDecorations(const QVarLengthArray<TextDecoration> &textDecorations, qreal offset, qreal thickness);
222 void mergeFormats(QTextLayout *textLayout, QVarLengthArray<QTextLayout::FormatRange> *mergedFormats);
223
224 QColor m_selectionColor;
225 QColor m_textColor;
226 QColor m_backgroundColor;
227 QColor m_decorationColor;
228 QColor m_selectedTextColor;
229 QColor m_anchorColor;
230 QPointF m_position;
231 QTextCharFormat::UnderlineStyle m_underlineStyle = QTextCharFormat::NoUnderline;
232
233 QTextLine m_currentLine;
234 Qt::LayoutDirection m_currentTextDirection;
235
237 QList<QRectF> m_selectionRects;
238 QVarLengthArray<BinaryTreeNode, 16> m_currentLineTree;
239
240 QList<TextDecoration> m_lines;
241 QList<BinaryTreeNode> m_processedNodes;
242
243 qreal m_devicePixelRatio = 1.0;
244
245 bool m_hasSelection : 1;
246 bool m_hasContents : 1;
247 friend class QSGInternalTextNode;
248
249};
250
251QT_END_NAMESPACE
252
253#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 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)