Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#include <QtCore/qlist.h>
5#include <QtCore/qvarlengtharray.h>
6#include <QtGui/qcolor.h>
7#include <QtGui/qglyphrun.h>
8#include <QtGui/qimage.h>
9#include <QtGui/qtextdocument.h>
10#include <QtGui/qtextlayout.h>
11#include "qquickclipnode_p.h"
13
14#ifndef QQUICKTEXTNODEENGINE_P_H
15#define QQUICKTEXTNODEENGINE_P_H
16
17//
18// W A R N I N G
19// -------------
20//
21// This file is not part of the Qt API. It exists purely as an
22// implementation detail. This header file may change from version to
23// version without notice, or even be removed.
24//
25// We mean it.
26//
27
29
30// Engine that takes glyph runs as input, and produces a set of glyph nodes, clip nodes,
31// and rectangle nodes to represent the text, decorations and selection. Will try to minimize
32// number of nodes, and join decorations in neighbouring items
33
35public:
38 Underline = 0x1,
39 Overline = 0x2,
40 StrikeOut = 0x4,
41 Background = 0x8
42 };
43 Q_DECLARE_FLAGS(Decorations, Decoration)
44
49
51
57
58 BinaryTreeNode(const QRectF &brect, const QImage &i, SelectionState selState, qreal a)
61 {
62 }
63
64 BinaryTreeNode(const QGlyphRun &g, SelectionState selState, const QRectF &brect,
65 const Decorations &decs, const QColor &c, const QColor &bc, const QColor &dc,
66 const QPointF &pos, qreal a);
67
72 Decorations decorations;
79
82
83 QList<QPair<int, int> > ranges;
84
85 static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const QRectF &rect, const QImage &image, qreal ascent, SelectionState selectionState)
87
88 static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const QGlyphRun &glyphRun, SelectionState selectionState,
89 Decorations decorations, const QColor &textColor, const QColor &backgroundColor, const QColor &underlineColor, const QPointF &position);
90 static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const BinaryTreeNode &binaryTreeNode);
91 static void inOrder(const QVarLengthArray<BinaryTreeNode, 16> &binaryTree, QVarLengthArray<int> *sortedIndexes, int currentIndex = 0);
92 };
93
95 {
97
98 bool operator==(const BinaryTreeNodeKey &otherKey) const
99 {
100 return fontEngine == otherKey.fontEngine
101 && clipNode == otherKey.clipNode
102 && color == otherKey.color
103 && selectionState == otherKey.selectionState;
104 }
105
110 };
111
113 : m_currentTextDirection(Qt::LeftToRight)
114 , m_hasSelection(false)
115 , m_hasContents(false)
116 {}
117
118 bool hasContents() const { return m_hasContents; }
119 void addTextBlock(QTextDocument *, const QTextBlock &, const QPointF &position, const QColor &textColor,
120 const QColor& anchorColor, int selectionStart, int selectionEnd, const QRectF &viewport = QRectF());
121 QTextLine currentLine() const { return m_currentLine; }
122
124 {
125 if (m_currentLine.isValid())
126 processCurrentLine();
127
128 m_currentLine = currentLine;
129 }
130
132 {
133 m_currentTextDirection = textDirection;
134 }
135
137 const QBrush &borderBrush);
139 void addImage(const QRectF &rect, const QImage &image, qreal ascent,
140 SelectionState selectionState,
141 QTextFrameFormat::Position layoutPosition);
142 int addText(const QTextBlock &block,
143 const QTextCharFormat &charFormat,
144 const QColor &textColor,
145 const QVarLengthArray<QTextLayout::FormatRange> &colorChanges,
146 int textPos, int fragmentEnd,
147 int selectionStart, int selectionEnd);
148 void addTextObject(const QTextBlock &block, const QPointF &position, const QTextCharFormat &format,
149 SelectionState selectionState,
150 QTextDocument *textDocument, int pos,
152 void addSelectedGlyphs(const QGlyphRun &glyphRun);
153 void addUnselectedGlyphs(const QGlyphRun &glyphRun);
154 void addGlyphsInRange(int rangeStart, int rangeEnd,
155 const QColor &color, const QColor &backgroundColor, const QColor &underlineColor,
156 int selectionStart, int selectionEnd);
157 void addGlyphsForRanges(const QVarLengthArray<QTextLayout::FormatRange> &ranges,
158 int start, int end,
159 int selectionStart, int selectionEnd);
160
161 void mergeProcessedNodes(QList<BinaryTreeNode *> *regularNodes,
162 QList<BinaryTreeNode *> *imageNodes);
165 const QColor &styleColor = QColor());
166
167 void setSelectionColor(const QColor &selectionColor)
168 {
169 m_selectionColor = selectionColor;
170 }
171
172 void setSelectedTextColor(const QColor &selectedTextColor)
173 {
174 m_selectedTextColor = selectedTextColor;
175 }
176
177 void setTextColor(const QColor &textColor)
178 {
179 m_textColor = textColor;
180 }
181
182 void setAnchorColor(const QColor &anchorColor)
183 {
184 m_anchorColor = anchorColor;
185 }
186
188 {
189 m_position = position;
190 }
191
192
193
194private:
195 struct TextDecoration
196 {
197 TextDecoration() : selectionState(Unselected) {}
198 TextDecoration(const SelectionState &s,
199 const QRectF &r,
200 const QColor &c)
201 : selectionState(s)
202 , rect(r)
203 , color(c)
204 {
205 }
206
207 SelectionState selectionState;
208 QRectF rect;
210 };
211
212 void processCurrentLine();
213 void addTextDecorations(const QVarLengthArray<TextDecoration> &textDecorations, qreal offset, qreal thickness);
214 void mergeFormats(QTextLayout *textLayout, QVarLengthArray<QTextLayout::FormatRange> *mergedFormats);
215
216 QColor m_selectionColor;
217 QColor m_textColor;
218 QColor m_backgroundColor;
219 QColor m_decorationColor;
220 QColor m_selectedTextColor;
221 QColor m_anchorColor;
222 QPointF m_position;
223
224 QTextLine m_currentLine;
225 Qt::LayoutDirection m_currentTextDirection;
226
227 QList<QPair<QRectF, QColor> > m_backgrounds;
228 QList<QRectF> m_selectionRects;
229 QVarLengthArray<BinaryTreeNode, 16> m_currentLineTree;
230
231 QList<TextDecoration> m_lines;
232 QVector<BinaryTreeNode> m_processedNodes;
233
234 bool m_hasSelection : 1;
235 bool m_hasContents : 1;
237
238};
239
241
242#endif // QQUICKTEXTNODEENGINE_P_H
\inmodule QtGui
Definition qbrush.h:30
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
The QGlyphRun class provides direct access to the internal glyphs in a font.
Definition qglyphrun.h:20
\inmodule QtGui
Definition qimage.h:37
\inmodule QtCore\reentrant
Definition qpoint.h:217
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 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)
void addToSceneGraph(QSGInternalTextNode *parent, QQuickText::TextStyle style=QQuickText::Normal, const QColor &styleColor=QColor())
\inmodule QtCore\reentrant
Definition qrect.h:484
\reentrant
\reentrant \inmodule QtGui
Position
This enum describes how a frame is located relative to the surrounding text.
\reentrant
Definition qtextobject.h:81
\reentrant
Definition qtextlayout.h:70
\reentrant
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
rect
[4]
Combined button and popup list for selecting options.
Definition qcompare.h:63
LayoutDirection
Definition image.cpp:4
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
GLboolean GLboolean GLboolean GLboolean a
[7]
GLboolean r
[2]
GLuint GLuint end
GLint GLenum GLsizei GLsizei GLsizei GLint border
GLuint color
[2]
GLuint start
GLenum GLuint GLintptr offset
GLboolean GLboolean g
GLint GLsizei GLsizei GLenum format
GLdouble s
[6]
Definition qopenglext.h:235
const GLubyte * c
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
Definition qrgb.h:13
double qreal
Definition qtypes.h:187
view viewport() -> scroll(dx, dy, deviceRect)
QFrame frame
[0]
bool operator==(const BinaryTreeNodeKey &otherKey) const
static void insert(QVarLengthArray< BinaryTreeNode, 16 > *binaryTree, const QRectF &rect, const QImage &image, qreal ascent, SelectionState selectionState)
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)