Qt 4.8
|
The QTextLine class represents a line of text inside a QTextLayout. More...
#include <qtextlayout.h>
Public Types | |
enum | CursorPosition { CursorBetweenCharacters, CursorOnCharacter } |
enum | Edge { Leading, Trailing } |
Public Functions | |
qreal | ascent () const |
Returns the line's ascent. More... | |
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. More... | |
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. More... | |
qreal | descent () const |
Returns the line's descent. More... | |
void | draw (QPainter *p, const QPointF &point, const QTextLayout::FormatRange *selection=0) const |
Draws a line on the given painter at the specified position. More... | |
qreal | height () const |
Returns the line's height. More... | |
qreal | horizontalAdvance () const |
Returns the horizontal advance of the text. More... | |
bool | isValid () const |
Returns true if this text line is valid; otherwise returns false. More... | |
qreal | leading () const |
Returns the line's leading. More... | |
bool | leadingIncluded () const |
Returns true if positive leading is included into the line's height; otherwise returns false. More... | |
int | lineNumber () const |
Returns the position of the line in the text engine. More... | |
QRectF | naturalTextRect () const |
Returns the rectangle covered by the line. More... | |
qreal | naturalTextWidth () const |
Returns the width of the line that is occupied by text. More... | |
QPointF | position () const |
Returns the line's position relative to the text layout's position. More... | |
QTextLine () | |
Creates an invalid line. More... | |
QRectF | rect () const |
Returns the line's bounding rectangle. More... | |
void | setLeadingIncluded (bool included) |
Includes positive leading into the line's height if included is true; otherwise does not include leading. More... | |
void | setLineWidth (qreal width) |
Lays out the line with the given width. More... | |
void | setNumColumns (int columns) |
Lays out the line. More... | |
void | setNumColumns (int columns, qreal alignmentWidth) |
Lays out the line. More... | |
void | setPosition (const QPointF &pos) |
Moves the line to position pos. More... | |
int | textLength () const |
Returns the length of the text in the line. More... | |
int | textStart () const |
Returns the start of the line from the beginning of the string passed to the QTextLayout. More... | |
qreal | width () const |
Returns the line's width as specified by the layout() function. More... | |
qreal | x () const |
Returns the line's x position. More... | |
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. More... | |
qreal | y () const |
Returns the line's y position. More... | |
Private Functions | |
QList< QGlyphRun > | glyphs (int from, int length) const |
Returns the glyph indexes and positions for all glyphs in this QTextLine which reside in QScriptItems that overlap with the range defined by from and length. More... | |
void | layout_helper (int numGlyphs) |
QTextLine (int line, QTextEngine *e) | |
Properties | |
QTextEngine * | eng |
int | i |
Friends | |
class | QTextFragment |
class | QTextLayout |
The QTextLine class represents a line of text inside a QTextLayout.
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 decent() 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 197 of file qtextlayout.h.
Enumerator | |
---|---|
CursorBetweenCharacters | |
CursorOnCharacter |
Definition at line 223 of file qtextlayout.h.
enum QTextLine::Edge |
Enumerator | |
---|---|
Leading | |
Trailing |
Definition at line 219 of file qtextlayout.h.
|
inline |
|
inlineprivate |
Constructs a new text line using the line at position line in the text engine e.
Definition at line 248 of file qtextlayout.h.
qreal QTextLine::ascent | ( | ) | const |
Returns the line's ascent.
Definition at line 1461 of file qtextlayout.cpp.
Referenced by QSvgText::draw(), getLineHeightParams(), QLineControl::updateDisplayText(), and QCommonStylePrivate::viewItemDrawText().
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 cpos will be modified to point to this valid cursor position.
Definition at line 2570 of file qtextlayout.cpp.
Referenced by QAccessibleTextWidget::characterRect(), QLineControl::cursorRect(), QTextLayout::drawCursor(), QTextControlPrivate::extendWordwiseSelection(), QTextControlPrivate::rectForPosition(), and QTextCursorPrivate::setX().
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 230 of file qtextlayout.h.
Referenced by cursorToX().
qreal QTextLine::descent | ( | ) | const |
void QTextLine::draw | ( | QPainter * | painter, |
const QPointF & | position, | ||
const QTextLayout::FormatRange * | selection = 0 |
||
) | const |
Draws a line on the given painter at the specified position.
The selection is reserved for internal use.
Definition at line 2361 of file qtextlayout.cpp.
Referenced by QTextLayout::draw(), qt_format_text(), and QCommonStylePrivate::viewItemDrawText().
Returns the glyph indexes and positions for all glyphs in this QTextLine which reside in QScriptItems that overlap with the range defined by from and length.
The arguments specify characters, relative to the text in the layout. Note that it is not possible to use this function to retrieve a subset of the glyphs in a QScriptItem.
Definition at line 2197 of file qtextlayout.cpp.
Referenced by QTextLayout::glyphRuns(), and QTextFragment::glyphRuns().
qreal QTextLine::height | ( | ) | const |
Returns the line's height.
This is equal to ascent() + descent() + 1 if leading is not included. If leading is included, this equals to ascent() + descent() + leading() + 1.
Definition at line 1483 of file qtextlayout.cpp.
Referenced by QAccessibleTextWidget::characterRect(), QLineControl::cursorRect(), QCommandLinkButtonPrivate::descriptionHeight(), QItemDelegatePrivate::doTextLayout(), QSvgText::draw(), getLineHeightParams(), QPlainTextDocumentLayout::layoutBlock(), QTextDocumentLayoutPrivate::layoutFlow(), QStaticTextPrivate::paintText(), qt_format_text(), QTextControlPrivate::rectForPosition(), QDeclarativeTextPrivate::setupTextLayout(), setupTextLayout(), QCommonStylePrivate::viewItemDrawText(), QCommonStylePrivate::viewItemSize(), and viewItemTextLayout().
qreal QTextLine::horizontalAdvance | ( | ) | const |
Returns the horizontal advance of the text.
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 1567 of file qtextlayout.cpp.
Referenced by qt_format_text().
|
inline |
Returns true if this text line is valid; otherwise returns false.
Definition at line 201 of file qtextlayout.h.
Referenced by QAccessibleTextWidget::characterRect(), QTextCursor::columnNumber(), QTextControlPrivate::cursorMoveKeyEvent(), QCommandLinkButtonPrivate::descriptionHeight(), QItemDelegatePrivate::doTextLayout(), QSvgText::draw(), QTextDocumentLayoutPrivate::drawListItem(), QPlainTextEditPrivate::ensureVisible(), QTextControlPrivate::extendWordwiseSelection(), QPlainTextDocumentLayout::layoutBlock(), QTextDocumentLayoutPrivate::layoutBlock(), QTextControlPrivate::mouseDoubleClickEvent(), QTextCursorPrivate::movePosition(), QStaticTextPrivate::paintText(), QTextDocumentLayout::positionInlineObject(), qt_format_text(), QTextControlPrivate::rectForPosition(), QDeclarativeTextPrivate::setupTextLayout(), setupTextLayout(), QTextCursorPrivate::setX(), QCommonStylePrivate::viewItemSize(), and viewItemTextLayout().
|
private |
Definition at line 1782 of file qtextlayout.cpp.
qreal QTextLine::leading | ( | ) | const |
Returns the line's leading.
Definition at line 1498 of file qtextlayout.cpp.
Referenced by QAccessibleTextWidget::characterRect(), and getLineHeightParams().
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 1539 of file qtextlayout.cpp.
Referenced by QAccessibleTextWidget::characterRect().
|
inline |
Returns the position of the line in the text engine.
Definition at line 243 of file qtextlayout.h.
Referenced by QTextControlPrivate::cursorMoveKeyEvent(), QPlainTextEditPrivate::ensureVisible(), QTextCursorPrivate::movePosition(), qt_format_text(), and QTextControl::selectionRect().
QRectF QTextLine::naturalTextRect | ( | ) | const |
Returns the rectangle covered by the line.
Definition at line 1413 of file qtextlayout.cpp.
Referenced by QPlainTextEditPrivate::_q_adjustScrollbars(), QTextLayout::draw(), QTextDocumentLayoutPrivate::drawListItem(), QPlainTextEditPrivate::ensureVisible(), QPlainTextEditControl::hitTest(), QTextDocumentLayoutPrivate::hitTest(), QPlainTextEditPrivate::pageUpDown(), QDeclarativeTextPrivate::setupTextLayout(), and QPlainTextEditPrivate::verticalOffset().
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 1549 of file qtextlayout.cpp.
Referenced by QPlainTextDocumentLayout::blockBoundingRect(), QPlainTextDocumentLayout::blockWidth(), QItemDelegatePrivate::doTextLayout(), QSvgText::draw(), QPlainTextDocumentLayout::layoutBlock(), QTextDocumentLayoutPrivate::layoutBlock(), QTextDocumentLayoutPrivate::positionFloat(), qt_format_text(), setupTextLayout(), QCommonStylePrivate::viewItemDrawText(), QCommonStylePrivate::viewItemSize(), and viewItemTextLayout().
QPointF QTextLine::position | ( | ) | const |
Returns the line's position relative to the text layout's position.
Definition at line 2042 of file qtextlayout.cpp.
Referenced by QTextDocumentLayoutPrivate::layoutBlock(), and QDeclarativeTextPrivate::setupTextLayout().
QRectF QTextLine::rect | ( | ) | const |
Returns the line's bounding rectangle.
Definition at line 1404 of file qtextlayout.cpp.
Referenced by QTextLayout::draw(), and QTextObjectInterface::~QTextObjectInterface().
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 1520 of file qtextlayout.cpp.
Referenced by QTextDocumentLayoutPrivate::drawListItem(), QPlainTextDocumentLayout::layoutBlock(), and QTextDocumentLayoutPrivate::layoutBlock().
void QTextLine::setLineWidth | ( | qreal | width | ) |
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 1579 of file qtextlayout.cpp.
Referenced by QCommandLinkButtonPrivate::descriptionHeight(), QItemDelegatePrivate::doTextLayout(), QSvgText::draw(), QPlainTextDocumentLayout::layoutBlock(), QTextDocumentLayoutPrivate::layoutBlock(), QStaticTextPrivate::paintText(), qt_format_text(), QDeclarativeTextPrivate::setupTextLayout(), QCommonStylePrivate::viewItemSize(), and viewItemTextLayout().
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 1610 of file qtextlayout.cpp.
Referenced by QTextLayout::createLine(), QTextLayout::endLayout(), and QTextDocumentLayoutPrivate::layoutBlock().
void QTextLine::setNumColumns | ( | int | numColumns, |
qreal | alignmentWidth | ||
) |
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 1627 of file qtextlayout.cpp.
void QTextLine::setPosition | ( | const QPointF & | pos | ) |
Moves the line to position pos.
Definition at line 2033 of file qtextlayout.cpp.
Referenced by QCommandLinkButtonPrivate::descriptionHeight(), QItemDelegatePrivate::doTextLayout(), QSvgText::draw(), QPlainTextDocumentLayout::layoutBlock(), QTextDocumentLayoutPrivate::layoutBlock(), QTextDocumentLayoutPrivate::layoutFlow(), QStaticTextPrivate::paintText(), qt_format_text(), QDeclarativeTextPrivate::setupTextLayout(), setupTextLayout(), QCommonStylePrivate::viewItemSize(), and viewItemTextLayout().
int QTextLine::textLength | ( | ) | const |
Returns the length of the text in the line.
Definition at line 2068 of file qtextlayout.cpp.
Referenced by QAccessibleTextWidget::characterRect(), QTextDocumentLayoutPrivate::drawBlock(), QPlainTextEditControl::hitTest(), QTextDocumentLayoutPrivate::hitTest(), QTextControlPrivate::mouseDoubleClickEvent(), QTextCursorPrivate::movePosition(), QPlainTextEdit::paintEvent(), QTextControlPrivate::rectForPosition(), QDeclarativeTextPrivate::setupTextLayout(), and QCommonStylePrivate::viewItemDrawText().
int QTextLine::textStart | ( | ) | const |
Returns the start of the line from the beginning of the string passed to the QTextLayout.
Definition at line 2058 of file qtextlayout.cpp.
Referenced by QAccessibleTextWidget::characterRect(), QTextCursor::columnNumber(), QTextDocumentLayoutPrivate::drawBlock(), QTextControlPrivate::extendWordwiseSelection(), QPlainTextEditControl::hitTest(), QTextDocumentLayoutPrivate::hitTest(), QTextCursorPrivate::movePosition(), QPlainTextEdit::paintEvent(), QTextControlPrivate::rectForPosition(), QDeclarativeTextPrivate::setupTextLayout(), and QCommonStylePrivate::viewItemDrawText().
qreal QTextLine::width | ( | ) | const |
Returns the line's width as specified by the layout() function.
Definition at line 1450 of file qtextlayout.cpp.
Referenced by QCommonStylePrivate::viewItemDrawText().
qreal QTextLine::x | ( | ) | const |
Returns the line's x position.
Definition at line 1430 of file qtextlayout.cpp.
Referenced by QTextDocumentLayoutPrivate::layoutBlock(), and QCommonStylePrivate::viewItemDrawText().
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.
Definition at line 2718 of file qtextlayout.cpp.
Referenced by QPlainTextEditControl::hitTest(), QTextDocumentLayoutPrivate::hitTest(), QTextCursorPrivate::movePosition(), and QLineControl::xToPos().
qreal QTextLine::y | ( | ) | const |
Returns the line's y position.
Definition at line 1440 of file qtextlayout.cpp.
Referenced by QAccessibleTextWidget::characterRect(), flowPosition(), QTextControlPrivate::rectForPosition(), and QCommonStylePrivate::viewItemDrawText().
|
friend |
Definition at line 256 of file qtextlayout.h.
|
friend |
Definition at line 255 of file qtextlayout.h.
|
private |
Definition at line 258 of file qtextlayout.h.
|
private |
Definition at line 257 of file qtextlayout.h.