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
qtextlayout.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#ifndef QTEXTLAYOUT_H
4#define QTEXTLAYOUT_H
5
6#include <QtGui/qcolor.h>
7#include <QtGui/qevent.h>
8#include <QtGui/qglyphrun.h>
9#include <QtGui/qtextcursor.h>
10#include <QtGui/qtextformat.h>
11#include <QtGui/qtguiglobal.h>
12
13#include <QtCore/qlist.h>
14#include <QtCore/qnamespace.h>
15#include <QtCore/qobject.h>
16#include <QtCore/qrect.h>
17#include <QtCore/qstring.h>
18
20
21
22class QTextEngine;
23class QFont;
24#ifndef QT_NO_RAWFONT
25class QRawFont;
26#endif
27class QRect;
28class QRegion;
29class QTextFormat;
30class QPalette;
31class QPainter;
32
33class Q_GUI_EXPORT QTextInlineObject
34{
35public:
36 QTextInlineObject(int i, QTextEngine *e) : itm(i), eng(e) {}
37 inline QTextInlineObject() : itm(0), eng(nullptr) {}
38 inline bool isValid() const { return eng; }
39
40 QRectF rect() const;
41 qreal width() const;
42 qreal ascent() const;
43 qreal descent() const;
44 qreal height() const;
45
46 Qt::LayoutDirection textDirection() const;
47
48 void setWidth(qreal w);
49 void setAscent(qreal a);
50 void setDescent(qreal d);
51
52 int textPosition() const;
53
54 int formatIndex() const;
55 QTextFormat format() const;
56
57private:
58 friend class QTextLayout;
59 int itm;
60 QTextEngine *eng;
61};
62
63class QPaintDevice;
64class QTextFormat;
65class QTextLine;
66class QTextBlock;
67class QTextOption;
68
69class Q_GUI_EXPORT QTextLayout
70{
71public:
73 RetrieveGlyphIndexes = 0x1,
74 RetrieveGlyphPositions = 0x2,
75 RetrieveStringIndexes = 0x4,
76 RetrieveString = 0x8,
77
78 DefaultRetrievalFlags = RetrieveGlyphIndexes | RetrieveGlyphPositions,
79 RetrieveAll = 0xffff
80 };
81 Q_DECLARE_FLAGS(GlyphRunRetrievalFlags, GlyphRunRetrievalFlag)
82
83 // does itemization
85 QTextLayout(const QString& text);
86 QTextLayout(const QString &text, const QFont &font, const QPaintDevice *paintdevice = nullptr);
87 QTextLayout(const QTextBlock &b);
89
90 void setFont(const QFont &f);
91 QFont font() const;
92
93#ifndef QT_NO_RAWFONT
94 void setRawFont(const QRawFont &rawFont);
95#endif
96
97 void setText(const QString& string);
98 QString text() const;
99
100 void setTextOption(const QTextOption &option);
101 const QTextOption &textOption() const;
102
103 void setPreeditArea(int position, const QString &text);
104 int preeditAreaPosition() const;
105 QString preeditAreaText() const;
106
107 struct FormatRange {
108 int start;
111
112 friend bool operator==(const FormatRange &lhs, const FormatRange &rhs)
113 { return lhs.start == rhs.start && lhs.length == rhs.length && lhs.format == rhs.format; }
114 friend bool operator!=(const FormatRange &lhs, const FormatRange &rhs)
115 { return !operator==(lhs, rhs); }
116 };
117 void setFormats(const QList<FormatRange> &overrides);
118 QList<FormatRange> formats() const;
119 void clearFormats();
120
121 void setCacheEnabled(bool enable);
122 bool cacheEnabled() const;
123
124 void setCursorMoveStyle(Qt::CursorMoveStyle style);
125 Qt::CursorMoveStyle cursorMoveStyle() const;
126
127 void beginLayout();
128 void endLayout();
129 void clearLayout();
130
131 QTextLine createLine();
132
133 int lineCount() const;
134 QTextLine lineAt(int i) const;
135 QTextLine lineForTextPosition(int pos) const;
136
139 SkipWords
140 };
141 bool isValidCursorPosition(int pos) const;
142 int nextCursorPosition(int oldPos, CursorMode mode = SkipCharacters) const;
143 int previousCursorPosition(int oldPos, CursorMode mode = SkipCharacters) const;
144 int leftCursorPosition(int oldPos) const;
145 int rightCursorPosition(int oldPos) const;
146
147 void draw(QPainter *p, const QPointF &pos,
148 const QList<FormatRange> &selections = QList<FormatRange>(),
149 const QRectF &clip = QRectF()) const;
150 void drawCursor(QPainter *p, const QPointF &pos, int cursorPosition) const;
151 void drawCursor(QPainter *p, const QPointF &pos, int cursorPosition, int width) const;
152
153 QPointF position() const;
154 void setPosition(const QPointF &p);
155
156 QRectF boundingRect() const;
157
158 qreal minimumWidth() const;
159 qreal maximumWidth() const;
160
161#if !defined(QT_NO_RAWFONT)
162
163# if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
164 QList<QGlyphRun> glyphRuns(int from, int length, GlyphRunRetrievalFlags flags) const;
165 QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
166# else
167 QList<QGlyphRun> glyphRuns(int from = -1,
168 int length = -1,
169 GlyphRunRetrievalFlags flags = DefaultRetrievalFlags) const;
170# endif
171#endif
172
173 QTextEngine *engine() const { return d; }
174 void setFlags(int flags);
175private:
176 QTextLayout(QTextEngine *e) : d(e) {}
177 Q_DISABLE_COPY(QTextLayout)
178
179 friend class QPainter;
182 friend void qt_format_text(const QFont &font, const QRectF &_r, int tf, const QTextOption *, const QString& str,
183 QRectF *brect, int tabstops, int* tabarray, int tabarraylen,
185 QTextEngine *d;
186};
188Q_DECLARE_OPERATORS_FOR_FLAGS(QTextLayout::GlyphRunRetrievalFlags)
189
190class Q_GUI_EXPORT QTextLine
191{
192public:
193 inline QTextLine() : index(0), eng(nullptr) {}
194 inline bool isValid() const { return eng; }
195
196 QRectF rect() const;
197 qreal x() const;
198 qreal y() const;
199 qreal width() const;
200 qreal ascent() const;
201 qreal descent() const;
202 qreal height() const;
203 qreal leading() const;
204
205 void setLeadingIncluded(bool included);
206 bool leadingIncluded() const;
207
208 qreal naturalTextWidth() const;
209 qreal horizontalAdvance() const;
210 QRectF naturalTextRect() const;
211
212 enum Edge {
214 Trailing
215 };
218 CursorOnCharacter
219 };
220
221 /* cursorPos gets set to the valid position */
222 qreal cursorToX(int *cursorPos, Edge edge = Leading) const;
223 inline qreal cursorToX(int cursorPos, Edge edge = Leading) const { return cursorToX(&cursorPos, edge); }
224 int xToCursor(qreal x, CursorPosition = CursorBetweenCharacters) const;
225
227 void setNumColumns(int columns);
228 void setNumColumns(int columns, qreal alignmentWidth);
229
230 void setPosition(const QPointF &pos);
231 QPointF position() const;
232
233 int textStart() const;
234 int textLength() const;
235
236 int lineNumber() const { return index; }
237
238 void draw(QPainter *painter, const QPointF &position) const;
239
240#if !defined(QT_NO_RAWFONT)
241# if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
242 QList<QGlyphRun> glyphRuns(int from, int length, QTextLayout::GlyphRunRetrievalFlags flags) const;
243 QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
244# else
245 QList<QGlyphRun> glyphRuns(int from = -1,
246 int length = -1,
247 QTextLayout::GlyphRunRetrievalFlags flags = QTextLayout::DefaultRetrievalFlags) const;
248# endif
249#endif
250
251private:
252 QTextLine(int line, QTextEngine *e) : index(line), eng(e) {}
253 void layout_helper(int numGlyphs);
254 void draw_internal(QPainter *p, const QPointF &pos,
256
257 friend class QTextLayout;
258 friend class QTextFragment;
259 int index;
260 QTextEngine *eng;
261};
262
264
265#endif // QTEXTLAYOUT_H
\reentrant
Definition qfont.h:22
The QGraphicsSimpleTextItem class provides a simple text path item that you can add to a QGraphicsSce...
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
\inmodule QtCore\reentrant
Definition qpoint.h:217
The QRawFont class provides access to a single physical instance of a font.
Definition qrawfont.h:24
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore\reentrant
Definition qrect.h:30
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\reentrant
\reentrant
Definition qtextformat.h:90
\reentrant
QTextInlineObject(int i, QTextEngine *e)
Definition qtextlayout.h:36
bool isValid() const
Returns true if this inline object is valid; otherwise returns false.
Definition qtextlayout.h:38
\reentrant
Definition qtextlayout.h:70
QTextEngine * engine() const
@ DefaultRetrievalFlags
Definition qtextlayout.h:78
CursorMode
\value SkipCharacters \value SkipWords
\reentrant
qreal cursorToX(int cursorPos, Edge edge=Leading) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QTextLine()
Creates an invalid line.
Edge
\value Leading \value Trailing
CursorPosition
\value CursorBetweenCharacters \value CursorOnCharacter
@ CursorBetweenCharacters
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
int lineNumber() const
Returns the position of the line in the text engine.
\reentrant
Definition qtextoption.h:18
QString str
[2]
QString text
rect
[4]
EGLint EGLint * formats
Combined button and popup list for selecting options.
LayoutDirection
CursorMoveStyle
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
n void setPosition(void) \n\
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLenum GLuint GLenum GLsizei length
GLenum const void GLbitfield GLsizei numGlyphs
GLfloat GLfloat f
GLint GLsizei width
GLbitfield flags
GLboolean enable
GLint GLsizei GLsizei GLenum format
GLint y
GLfloat GLfloat p
[1]
GLuint GLenum option
static const QRectF boundingRect(const QPointF *points, int pointCount)
QT_BEGIN_NAMESPACE void qt_format_text(const QFont &fnt, const QRectF &_r, int tf, const QTextOption *opt, const QString &str, QRectF *brect, int tabstops, int *, int tabarraylen, QPainter *painter)
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Definition qrandom.cpp:1220
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:158
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
unsigned short quint16
Definition qtypes.h:48
double qreal
Definition qtypes.h:187
QObject::connect nullptr
myFilter draw(painter, QPoint(0, 0), originalPixmap)
QItemSelection * selection
[0]
QPainter painter(this)
[7]
insertRed setText("insert red text")
label setLineWidth(2)
QTextCharFormat format
friend bool operator==(const FormatRange &lhs, const FormatRange &rhs)
\variable QTextLayout::FormatRange::start Specifies the beginning of the format range within the text...
friend bool operator!=(const FormatRange &lhs, const FormatRange &rhs)
Returns true if any of the {start}, {length}, or {format} fields in lhs and rhs contain different val...