QtBase
v6.3.1
|
The QTextLine class represents a line of text inside a QTextLayout. \inmodule QtGui. More...
#include <qtextlayout.h>
Public Types | |
enum | Edge { Leading , Trailing } |
enum | CursorPosition { CursorBetweenCharacters , CursorOnCharacter } |
Public Member Functions | |
QTextLine () | |
bool | isValid () const |
QRectF | rect () const |
qreal | x () const |
qreal | y () const |
qreal | width () const |
qreal | ascent () const |
qreal | descent () const |
qreal | height () const |
qreal | leading () const |
void | setLeadingIncluded (bool included) |
bool | leadingIncluded () const |
qreal | naturalTextWidth () const |
qreal | horizontalAdvance () const |
QRectF | naturalTextRect () const |
qreal | cursorToX (int *cursorPos, Edge edge=Leading) const |
qreal | cursorToX (int cursorPos, Edge edge=Leading) const |
int | xToCursor (qreal x, CursorPosition=CursorBetweenCharacters) const |
void | setLineWidth (qreal width) |
void | setNumColumns (int columns) |
void | setNumColumns (int columns, qreal alignmentWidth) |
void | setPosition (const QPointF &pos) |
QPointF | position () const |
int | textStart () const |
int | textLength () const |
int | lineNumber () const |
void | draw (QPainter *painter, const QPointF &position) const |
QList< QGlyphRun > | glyphRuns (int from=-1, int length=-1) const |
Friends | |
class | QTextLayout |
class | QTextFragment |
The QTextLine class represents a line of text inside a QTextLayout. \inmodule QtGui.
\reentrant
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 207 of file qtextlayout.h.
\value CursorBetweenCharacters \value CursorOnCharacter
Enumerator | |
---|---|
CursorBetweenCharacters | |
CursorOnCharacter |
Definition at line 233 of file qtextlayout.h.
enum QTextLine::Edge |
\value Leading \value Trailing
Enumerator | |
---|---|
Leading | |
Trailing |
Definition at line 229 of file qtextlayout.h.
|
inline |
Creates an invalid line.
Definition at line 210 of file qtextlayout.h.
qreal QTextLine::ascent | ( | ) | const |
Returns the line's ascent.
Definition at line 1466 of file qtextlayout.cpp.
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 2748 of file qtextlayout.cpp.
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 240 of file qtextlayout.h.
qreal QTextLine::descent | ( | ) | const |
Returns the line's descent.
Definition at line 1476 of file qtextlayout.cpp.
Draws a line on the given painter at the specified position.
Definition at line 2502 of file qtextlayout.cpp.
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().
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 2313 of file qtextlayout.cpp.
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 1488 of file qtextlayout.cpp.
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 1560 of file qtextlayout.cpp.
|
inline |
Returns true
if this text line is valid; otherwise returns false
.
Definition at line 211 of file qtextlayout.h.
qreal QTextLine::leading | ( | ) | const |
Returns the line's leading.
Definition at line 1500 of file qtextlayout.cpp.
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 1535 of file qtextlayout.cpp.
|
inline |
Returns the position of the line in the text engine.
Definition at line 253 of file qtextlayout.h.
QRectF QTextLine::naturalTextRect | ( | ) | const |
Returns the rectangle covered by the line.
Definition at line 1418 of file qtextlayout.cpp.
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 1545 of file qtextlayout.cpp.
QPointF QTextLine::position | ( | ) | const |
Returns the line's position relative to the text layout's position.
Definition at line 2159 of file qtextlayout.cpp.
QRectF QTextLine::rect | ( | ) | const |
Returns the line's bounding rectangle.
Definition at line 1409 of file qtextlayout.cpp.
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 1519 of file qtextlayout.cpp.
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 1572 of file qtextlayout.cpp.
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 1603 of file qtextlayout.cpp.
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 1620 of file qtextlayout.cpp.
Moves the line to position pos.
Definition at line 2150 of file qtextlayout.cpp.
int QTextLine::textLength | ( | ) | const |
Returns the length of the text in the line.
Definition at line 2185 of file qtextlayout.cpp.
int QTextLine::textStart | ( | ) | const |
Returns the start of the line from the beginning of the string passed to the QTextLayout.
Definition at line 2175 of file qtextlayout.cpp.
qreal QTextLine::width | ( | ) | const |
Returns the line's width as specified by the layout() function.
Definition at line 1455 of file qtextlayout.cpp.
qreal QTextLine::x | ( | ) | const |
Returns the line's x position.
Definition at line 1435 of file qtextlayout.cpp.
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 2910 of file qtextlayout.cpp.
qreal QTextLine::y | ( | ) | const |
Returns the line's y position.
Definition at line 1445 of file qtextlayout.cpp.
|
friend |
Definition at line 268 of file qtextlayout.h.
|
friend |
Definition at line 267 of file qtextlayout.h.