![]() |
Qt 6.x
The Qt SDK
|
\reentrant More...
#include <qtextlayout.h>
Public Types | |
enum | Edge { Leading , Trailing } |
\value Leading \value Trailing More... | |
enum | CursorPosition { CursorBetweenCharacters , CursorOnCharacter } |
\value CursorBetweenCharacters \value CursorOnCharacter More... | |
Public Member Functions | |
QTextLine () | |
Creates an invalid line. | |
bool | isValid () const |
Returns true if this text line is valid; otherwise returns false . | |
QRectF | rect () const |
Returns the line's bounding rectangle. | |
qreal | x () const |
Returns the line's x position. | |
qreal | y () const |
Returns the line's y position. | |
qreal | width () const |
Returns the line's width as specified by the layout() function. | |
qreal | ascent () const |
Returns the line's ascent. | |
qreal | descent () const |
Returns the line's descent. | |
qreal | height () const |
Returns the line's height. | |
qreal | leading () const |
void | setLeadingIncluded (bool included) |
bool | leadingIncluded () const |
qreal | naturalTextWidth () const |
Returns the width of the line that is occupied by text. | |
qreal | horizontalAdvance () const |
QRectF | naturalTextRect () const |
Returns the rectangle covered by the line. | |
qreal | cursorToX (int *cursorPos, Edge edge=Leading) const |
Converts the cursor position cursorPos to the corresponding x position inside the line, taking account of the edge. | |
qreal | cursorToX (int cursorPos, Edge edge=Leading) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
int | xToCursor (qreal x, CursorPosition=CursorBetweenCharacters) const |
Converts the x-coordinate x, to the nearest matching cursor position, depending on the cursor position type, cpos. | |
void | setLineWidth (qreal width) |
Lays out the line with the given width. | |
void | setNumColumns (int columns) |
Lays out the line. | |
void | setNumColumns (int columns, qreal alignmentWidth) |
Lays out the line. | |
void | setPosition (const QPointF &pos) |
Moves the line to position pos. | |
QPointF | position () const |
Returns the line's position relative to the text layout's position. | |
int | textStart () const |
Returns the start of the line from the beginning of the string passed to the QTextLayout. | |
int | textLength () const |
Returns the length of the text in the line. | |
int | lineNumber () const |
Returns the position of the line in the text engine. | |
void | draw (QPainter *painter, const QPointF &position) const |
Draws a line on the given painter at the specified position. | |
QList< QGlyphRun > | glyphRuns (int from=-1, int length=-1, QTextLayout::GlyphRunRetrievalFlags flags=QTextLayout::DefaultRetrievalFlags) const |
Returns the glyph indexes and positions for all glyphs in this QTextLine for characters in the range defined by from and length. | |
Friends | |
class | QTextLayout |
class | QTextFragment |
\reentrant
The QTextLine class represents a line of text inside a QTextLayout. \inmodule QtGui
A text line is usually created by QTextLayout::createLine().
After being created, the line can be filled using the setLineWidth() or setNumColumns() functions. A line has a number of attributes including the rectangle it occupies, rect(), its coordinates, x() and y(), its textLength(), width() and naturalTextWidth(), and its ascent() and descent() relative to the text. The position of the cursor in terms of the line is available from cursorToX() and its inverse from xToCursor(). A line can be moved with setPosition().
Definition at line 190 of file qtextlayout.h.
\value CursorBetweenCharacters \value CursorOnCharacter
Enumerator | |
---|---|
CursorBetweenCharacters | |
CursorOnCharacter |
Definition at line 216 of file qtextlayout.h.
enum QTextLine::Edge |
\value Leading \value Trailing
Enumerator | |
---|---|
Leading | |
Trailing |
Definition at line 212 of file qtextlayout.h.
|
inline |
Creates an invalid line.
Definition at line 193 of file qtextlayout.h.
qreal QTextLine::ascent | ( | ) | const |
Returns the line's ascent.
Definition at line 1505 of file qtextlayout.cpp.
References QScriptLine::ascent, QList< T >::at(), QTextEngine::lines, and QFixed::toReal().
Referenced by QQuickTextNodeEngine::addImage(), and QQuickTextPrivate::setupTextLayout().
Converts the cursor position cursorPos to the corresponding x position inside the line, taking account of the edge.
If cursorPos is not a valid cursor position, the nearest valid cursor position will be used instead, and cursorPos will be modified to point to this valid cursor position.
Definition at line 2883 of file qtextlayout.cpp.
References QTextEngine::alignLine(), QScriptItem::analysis, QGlyphLayout::attributes, QTextEngine::attributes(), QScriptAnalysis::bidiLevel, QTextEngine::bidiReorder(), QGlyphAttributes::clusterStart, QVarLengthArray< T, Prealloc >::data(), QGlyphLayout::effectiveAdvance(), QTextEngine::findItem(), QScriptAnalysis::flags, i, QTextEngine::isRightToLeft(), item, QTextEngine::itemize(), QTextEngine::LayoutData::items, QTextEngine::layoutData, QTextEngine::leadingSpaceWidth(), QString::length(), QTextEngine::length(), line, QTextEngine::lines, QTextEngine::logClusters(), QTextOption::NoWrap, QScriptItem::num_glyphs, QTextEngine::offsetInLigature(), QTextEngine::option, pos, QScriptItem::position, Q_ASSERT, qBound(), qMax(), qMin(), QTextEngine::shape(), QTextEngine::shapedGlyphs(), QTextEngine::shapeLine(), QList< T >::size(), QScriptAnalysis::TabOrObject, Trailing, QTextEngine::visualCursorMovement(), QScriptItem::width, and QTextOption::wrapMode().
Referenced by QQuickTextInputPrivate::anchorRectangle(), QQuickTextInput::cursorRectangle(), QTextLayout::drawCursor(), QQuickTextInputPrivate::ensureVisible(), QQuickTextInput::positionToRectangle(), and QWidgetLineControl::rectForPos().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 223 of file qtextlayout.h.
References cursorToX().
Referenced by cursorToX().
qreal QTextLine::descent | ( | ) | const |
Returns the line's descent.
Definition at line 1515 of file qtextlayout.cpp.
References QList< T >::at(), QScriptLine::descent, QTextEngine::lines, and QFixed::toReal().
Draws a line on the given painter at the specified position.
Definition at line 2630 of file qtextlayout.cpp.
References painter, and position().
Referenced by QTextLayout::draw().
QList< QGlyphRun > QTextLine::glyphRuns | ( | int | from = -1 , |
int | length = -1 , |
||
QTextLayout::GlyphRunRetrievalFlags | retrievalFlags = QTextLayout::DefaultRetrievalFlags |
||
) | const |
Returns the glyph indexes and positions for all glyphs in this QTextLine for characters in the range defined by from and length.
The from index is relative to the beginning of the text in the containing QTextLayout, and the range must be within the range of QTextLine as given by functions textStart() and textLength().
The retrievalFlags specifies which properties of the QGlyphRun will be retrieved from the layout. To minimize allocations and memory consumption, this should be set to include only the properties that you need to access later.
If from is negative, it will default to textStart(), and if length is negative it will default to the return value of textLength().
Definition at line 2423 of file qtextlayout.cpp.
References QGlyphLayout::advances, QScriptItem::analysis, QList< T >::at(), QGlyphLayout::attributes, QScriptAnalysis::bidiLevel, QGlyphAttributes::dontPrint, e, QFontEngineMulti::engine(), QFontPrivate::engineForScript(), QFontEngineMulti::ensureEngineAt(), QScriptAnalysis::flags, QTextEngine::font(), font, QTextEngine::fontEngine(), QFixed::fromFixed(), glyphRuns(), glyphRunWithInfo(), QGlyphLayout::glyphs, i, QGlyphRun::isEmpty(), QRawFont::isValid(), QGlyphLayout::justifications, QString::length(), QList< T >::length(), line, QTextEngine::lines, QTextEngine::logClusters(), QGlyphLayout::mid(), QFontEngine::Multi, QScriptItem::num_glyphs, QGlyphLayout::numGlyphs, QFont::overline(), QGlyphRun::Overline, pos, QScriptItem::position, qMax(), qMin(), QTextEngine::rawFont, QGlyphRun::RightToLeft, QScriptAnalysis::script, selection, QTextEngine::shapedGlyphs(), QGlyphJustification::space_18d6, QGlyphRun::SplitLigature, QFont::strikeOut(), QGlyphRun::StrikeOut, QScriptAnalysis::TabOrObject, QTextEngine::text, textLength(), textStart(), QFontEngine::type(), QFont::underline(), QGlyphRun::Underline, QTextEngine::useRawFont, width(), and x().
Referenced by QTextFragment::glyphRuns(), QTextLayout::glyphRuns(), and glyphRuns().
qreal QTextLine::height | ( | ) | const |
Returns the line's height.
This is equal to ascent() + descent() if leading is not included. If leading is included, this equals to ascent() + descent() + leading().
Definition at line 1527 of file qtextlayout.cpp.
References QList< T >::at(), QFixed::ceil(), QScriptLine::height(), QTextEngine::lines, and QFixed::toReal().
Referenced by QQuickTextInputPrivate::anchorRectangle(), QCommonStylePrivate::calculateElidedText(), QQC2::QCommonStylePrivate::calculateElidedText(), QQuickTextInput::cursorRectangle(), QQuickTextLine::height(), QQuickTextInput::positionToRectangle(), QWidgetLineControl::rectForPos(), and QQuickTextLine::setHeight().
qreal QTextLine::horizontalAdvance | ( | ) | const |
By adding the advance to the position of the text line and using this as the position of a second text line, you will be able to position the two lines side-by-side without gaps in-between.
Definition at line 1599 of file qtextlayout.cpp.
References QList< T >::at(), QTextEngine::lines, QScriptLine::textAdvance, and QFixed::toReal().
Referenced by QQuickTextPrivate::setupTextLayout(), and QQuickTextPrivate::updateSize().
|
inline |
Returns true
if this text line is valid; otherwise returns false
.
Definition at line 194 of file qtextlayout.h.
Referenced by QQuickTextNodeEngine::addTextBlock(), QQuickTextNodeEngine::addToSceneGraph(), QQuickTextInputPrivate::anchorRectangle(), QQuickTextInput::cursorRectangle(), QTextDocumentLayoutPrivate::drawListItem(), QQuickTextInputPrivate::ensureVisible(), QQuickTextInput::positionToRectangle(), QQuickTextNodeEngine::setCurrentLine(), QQuickTextPrivate::setupTextLayout(), QQuickTextInputPrivate::updateVerticalScroll(), viewItemTextLayout(), and QQC2::viewItemTextLayout().
qreal QTextLine::leading | ( | ) | const |
Returns the line's leading.
Definition at line 1539 of file qtextlayout.cpp.
References QList< T >::at(), QScriptLine::leading, QTextEngine::lines, and QFixed::toReal().
bool QTextLine::leadingIncluded | ( | ) | const |
Returns true
if positive leading is included into the line's height; otherwise returns false
.
By default, leading is not included.
Definition at line 1574 of file qtextlayout.cpp.
References QList< T >::at(), QScriptLine::leadingIncluded, and QTextEngine::lines.
|
inline |
Returns the position of the line in the text engine.
Definition at line 236 of file qtextlayout.h.
Referenced by QQuickTextLine::number(), and QWidgetTextControl::selectionRect().
QRectF QTextLine::naturalTextRect | ( | ) | const |
Returns the rectangle covered by the line.
Definition at line 1457 of file qtextlayout.cpp.
References QTextEngine::alignLine(), QList< T >::at(), QScriptLine::height(), QScriptLine::justified, QTextEngine::lines, QScriptLine::textWidth, QFixed::toReal(), QScriptLine::width, QScriptLine::x, and QScriptLine::y.
Referenced by QQuickTextNodeEngine::addTextBlock(), QTextLayout::draw(), QTextDocumentLayoutPrivate::drawListItem(), QPlainTextEditPrivate::ensureVisible(), QPlainTextEditPrivate::pageUpDown(), and QQuickTextPrivate::setupTextLayout().
qreal QTextLine::naturalTextWidth | ( | ) | const |
Returns the width of the line that is occupied by text.
This is always <= to width(), and is the minimum width that could be used by layout() without changing the line break position.
Definition at line 1584 of file qtextlayout.cpp.
References QList< T >::at(), QTextEngine::lines, QScriptLine::textWidth, and QFixed::toReal().
Referenced by QPlainTextDocumentLayout::blockBoundingRect(), QQuickTextInputPrivate::ensureVisible(), QQuickTextLine::implicitWidth(), QQuickTextLine::isLast(), QTextDocumentLayoutPrivate::layoutBlock(), and QTextDocumentLayoutPrivate::positionFloat().
QPointF QTextLine::position | ( | ) | const |
Returns the line's position relative to the text layout's position.
Definition at line 2200 of file qtextlayout.cpp.
References QList< T >::at(), QTextEngine::lines, QFixed::toReal(), QScriptLine::x, and QScriptLine::y.
Referenced by QQuickTextNodeEngine::addImage(), and draw().
QRectF QTextLine::rect | ( | ) | const |
Returns the line's bounding rectangle.
Definition at line 1448 of file qtextlayout.cpp.
References QList< T >::at(), QScriptLine::height(), QTextEngine::lines, QFixed::toReal(), QScriptLine::width, QScriptLine::x, and QScriptLine::y.
Referenced by QQuickTextNodeEngine::addImage(), QTextLayout::draw(), and QQuickTextInputPrivate::updateVerticalScroll().
void QTextLine::setLeadingIncluded | ( | bool | included | ) |
Includes positive leading into the line's height if included is true; otherwise does not include leading.
By default, leading is not included.
Note that negative leading is ignored, it must be handled in the code using the text lines by letting the lines overlap.
Definition at line 1558 of file qtextlayout.cpp.
References QTextEngine::lines.
Lays out the line with the given width.
The line is filled from its starting position with as many characters as will fit into the line. In case the text cannot be split at the end of the line, it will be filled with additional characters to the next whitespace or end of the text.
Definition at line 1611 of file qtextlayout.cpp.
References QFixed::fromReal(), QTextEngine::layoutData, QString::length(), line, QTextEngine::lines, qBound(), QFIXED_MAX, qWarning, QString::size(), and QTextEngine::LayoutData::string.
Referenced by QQuickTextLine::setWidth().
void QTextLine::setNumColumns | ( | int | numColumns | ) |
Lays out the line.
The line is filled from its starting position with as many characters as are specified by numColumns. In case the text cannot be split until numColumns characters, the line will be filled with as many characters to the next whitespace or end of the text.
Definition at line 1639 of file qtextlayout.cpp.
References QString::length(), line, QTextEngine::lines, and QFIXED_MAX.
Referenced by QTextLayout::createLine(), and QTextLayout::endLayout().
Lays out the line.
The line is filled from its starting position with as many characters as are specified by numColumns. In case the text cannot be split until numColumns characters, the line will be filled with as many characters to the next whitespace or end of the text. The provided alignmentWidth is used as reference width for alignment.
Definition at line 1656 of file qtextlayout.cpp.
References QFixed::fromReal(), QString::length(), line, and QTextEngine::lines.
Moves the line to position pos.
Definition at line 2191 of file qtextlayout.cpp.
References QFixed::fromReal(), QTextEngine::lines, and pos.
Referenced by QQuickTextLine::setHeight(), QQuickTextPrivate::setupTextLayout(), QQuickTextLine::setX(), and QQuickTextLine::setY().
int QTextLine::textLength | ( | ) | const |
Returns the length of the text in the line.
Definition at line 2226 of file qtextlayout.cpp.
References QList< T >::at(), QTextEngine::block, QTextOption::flags(), QTextBlock::isValid(), QScriptLine::length, QTextEngine::lines, QTextEngine::option, QTextOption::ShowLineAndParagraphSeparators, QList< T >::size(), and QScriptLine::trailingSpaces.
Referenced by QTextDocumentLayoutPrivate::drawBlock(), QQuickTextPrivate::elidedText(), glyphRuns(), QQuickTextLine::isLast(), QPlainTextEdit::paintEvent(), and xToCursor().
int QTextLine::textStart | ( | ) | const |
Returns the start of the line from the beginning of the string passed to the QTextLayout.
Definition at line 2216 of file qtextlayout.cpp.
References QList< T >::at(), QScriptLine::from, and QTextEngine::lines.
Referenced by QTextDocumentLayoutPrivate::drawBlock(), QWidgetTextControlPrivate::extendWordwiseSelection(), QQuickTextControlPrivate::extendWordwiseSelection(), glyphRuns(), QQuickTextLine::isLast(), QPlainTextEdit::paintEvent(), and QQuickTextPrivate::setupTextLayout().
qreal QTextLine::width | ( | ) | const |
Returns the line's width as specified by the layout() function.
Definition at line 1494 of file qtextlayout.cpp.
References QList< T >::at(), QTextEngine::lines, QFixed::toReal(), and QScriptLine::width.
Referenced by glyphRuns(), QQuickTextLine::isLast(), and QQuickTextLine::width().
qreal QTextLine::x | ( | ) | const |
Returns the line's x position.
Definition at line 1474 of file qtextlayout.cpp.
References QList< T >::at(), QTextEngine::lines, QFixed::toReal(), and QScriptLine::x.
Referenced by glyphRuns(), QQuickTextLine::setHeight(), QQuickTextLine::setY(), and QQuickTextLine::x().
int QTextLine::xToCursor | ( | qreal | x, |
CursorPosition | cpos = CursorBetweenCharacters |
||
) | const |
Converts the x-coordinate x, to the nearest matching cursor position, depending on the cursor position type, cpos.
Note that result cursor position includes possible preedit area text.
Definition at line 3045 of file qtextlayout.cpp.
References QTextEngine::alignLine(), QScriptItem::analysis, QGlyphLayout::attributes, QScriptAnalysis::bidiLevel, QTextEngine::bidiReorder(), QGlyphAttributes::clusterStart, CursorOnCharacter, QVarLengthArray< T, Prealloc >::data(), dist(), QGlyphLayout::effectiveAdvance(), QTextEngine::findItem(), QScriptAnalysis::flags, QFixed::fromReal(), i, QTextEngine::insertionPointsForLine(), QTextEngine::isRightToLeft(), item, QTextEngine::itemize(), QTextEngine::LayoutData::items, QTextEngine::layoutData, QTextEngine::length(), line, QTextEngine::lines, QTextEngine::logClusters(), QScriptItem::num_glyphs, pos, QScriptItem::position, QTextEngine::positionInLigature(), QTextEngine::previousLogicalPosition(), Q_ASSERT, qAbs(), qMax(), qMin(), QTextEngine::shapedGlyphs(), QTextEngine::shapeLine(), QList< T >::size(), QScriptAnalysis::TabOrObject, textLength(), QTextEngine::visualCursorMovement(), and QScriptItem::width.
Referenced by QWidgetLineControl::xToPos().
qreal QTextLine::y | ( | ) | const |
Returns the line's y position.
Definition at line 1484 of file qtextlayout.cpp.
References QList< T >::at(), QTextEngine::lines, QFixed::toReal(), and QScriptLine::y.
Referenced by QQuickTextInputPrivate::anchorRectangle(), QQuickTextInput::cursorRectangle(), QQuickTextInputPrivate::positionAt(), QQuickTextInput::positionToRectangle(), QQuickTextLine::setHeight(), QQuickTextPrivate::setupTextLayout(), QQuickTextLine::setX(), QQuickTextPrivate::updateSize(), and QQuickTextLine::y().
|
friend |
Definition at line 258 of file qtextlayout.h.
|
friend |
Definition at line 257 of file qtextlayout.h.