Qyoto  4.0.5
Qyoto is a C# language binding for Qt
 All Classes Namespaces Functions Variables Typedefs Enumerations Properties
QtGui.QTextLayout Class Reference

The QTextLayout class is used to lay out and render text. More...

Inheritance diagram for QtGui.QTextLayout:
Collaboration diagram for QtGui.QTextLayout:

Classes

class  FormatRange
 The QTextLayout::FormatRange structure is used to apply extra formatting information for a specified area in the text layout's content. More...
 

Public Types

enum  CursorMode { SkipCharacters = 0, SkipWords = 1 }
 

Public Member Functions

 QTextLayout ()
 
 
 QTextLayout (QTextBlock b)
 
 
 QTextLayout (string text)
 
 
 QTextLayout (string text, QFont font, IQPaintDevice paintdevice=null)
 
 
virtual void CreateProxy ()
 
new void BeginLayout ()
 
 
new QRectF BoundingRect ()
 
 
new void ClearAdditionalFormats ()
 
 
new void ClearLayout ()
 
 
new QTextLine CreateLine ()
 
 
new void Draw (QPainter p, QPointF pos)
 
 
new void Draw (QPainter p, QPointF pos, System.Collections.Generic.List< QTextLayout.FormatRange > selections)
 
 
new void Draw (QPainter p, QPointF pos, System.Collections.Generic.List< QTextLayout.FormatRange > selections, QRectF clip)
 
 
new void DrawCursor (QPainter p, QPointF pos, int cursorPosition)
 
 
new void DrawCursor (QPainter p, QPointF pos, int cursorPosition, int width)
 
 
new void EndLayout ()
 
 
new
System.Collections.Generic.List
< QGlyphRun
GlyphRuns ()
 
 
new bool IsValidCursorPosition (int pos)
 
 
new int LeftCursorPosition (int oldPos)
 
 
new QTextLine LineAt (int i)
 
 
new int LineCount ()
 
 
new QTextLine LineForTextPosition (int pos)
 
 
new double MaximumWidth ()
 
 
new double MinimumWidth ()
 
 
new int NextCursorPosition (int oldPos, QTextLayout.CursorMode mode=QTextLayout.CursorMode.SkipCharacters)
 
 
new int PreeditAreaPosition ()
 
 
new string PreeditAreaText ()
 
 
new int PreviousCursorPosition (int oldPos, QTextLayout.CursorMode mode=QTextLayout.CursorMode.SkipCharacters)
 
 
new int RightCursorPosition (int oldPos)
 
 
new void SetFlags (int flags)
 
new void SetPreeditArea (int position, string text)
 
 
new void Dispose ()
 

Protected Member Functions

 QTextLayout (System.Type dummy)
 

Protected Attributes

SmokeInvocation interceptor
 

Properties

new
System.Collections.Generic.List
< QTextLayout.FormatRange
AdditionalFormats [get, set]
 
 
new bool CacheEnabled [get, set]
 
 
new Qt.CursorMoveStyle CursorMoveStyle [get, set]
 
 
new QFont Font [get, set]
 
 
new QPointF Position [get, set]
 
 
new string Text [get, set]
 
 
new QTextOption TextOption [get, set]
 
 
virtual System.IntPtr SmokeObject [get, set]
 

Detailed Description

The QTextLayout class is used to lay out and render text.

It offers many features expected from a modern text layout engine, including Unicode compliant rendering, line breaking and handling of cursor positioning. It can also produce and render device independent layout, something that is important for WYSIWYG applications.

The class has a rather low level API and unless you intend to implement your own text rendering for some specialized widget, you probably won't need to use it directly.

QTextLayout can be used with both plain and rich text.

QTextLayout can be used to create a sequence of QTextLine instances with given widths and can position them independently on the screen. Once the layout is done, these lines can be drawn on a paint device.

The text to be laid out can be provided in the constructor or set with setText().

The layout can be seen as a sequence of QTextLine objects; use createLine() to create a QTextLine instance, and lineAt() or lineForTextPosition() to retrieve created lines.

Here is a code snippet that demonstrates the layout phase:

int leading = fontMetrics.leading();

qreal height = 0;

textLayout.beginLayout();

while (1) {

QTextLine line = textLayout.createLine();

if (!line.isValid())

break;

line.setLineWidth(lineWidth);

height += leading;

line.setPosition(QPointF(0, height));

height += line.height();

}

textLayout.endLayout();

The text can then be rendered by calling the layout's draw() function:

QPainter painter(this);

textLayout.draw(&painter, QPoint(0, 0));

For a given position in the text you can find a valid cursor position with isValidCursorPosition(), nextCursorPosition(), and previousCursorPosition().

The QTextLayout itself can be positioned with setPosition(); it has a boundingRect(), and a minimumWidth() and a maximumWidth().

See also QStaticText.

Member Enumeration Documentation

Enumerator:
SkipCharacters 
SkipWords 

Constructor & Destructor Documentation

QtGui.QTextLayout.QTextLayout ( System.Type  dummy)
protected
QtGui.QTextLayout.QTextLayout ( )

Constructs an empty text layout.

See also setText().

QtGui.QTextLayout.QTextLayout ( QTextBlock  b)

Constructs an empty text layout.

See also setText().

QtGui.QTextLayout.QTextLayout ( string  text)

Constructs a text layout to lay out the given text.

QtGui.QTextLayout.QTextLayout ( string  text,
QFont  font,
IQPaintDevice  paintdevice = null 
)

Constructs a text layout to lay out the given text with the specified font.

All the metric and layout calculations will be done in terms of the paint device, paintdevice. If paintdevice is 0 the calculations will be done in screen metrics.

Member Function Documentation

new void QtGui.QTextLayout.BeginLayout ( )

Begins the layout process.

See also endLayout().

new QRectF QtGui.QTextLayout.BoundingRect ( )

The smallest rectangle that contains all the lines in the layout.

new void QtGui.QTextLayout.ClearAdditionalFormats ( )

Clears the list of additional formats supported by the text layout.

See also additionalFormats() and setAdditionalFormats().

new void QtGui.QTextLayout.ClearLayout ( )

Clears the line information in the layout. After having called this function, lineCount() returns 0.

This function was introduced in Qt 4.4.

new QTextLine QtGui.QTextLayout.CreateLine ( )

Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise returns an invalid text line.

The text layout creates a new line object that starts after the last line in the layout, or at the beginning if the layout is empty. The layout maintains an internal cursor, and each line is filled with text from the cursor position onwards when the QTextLine::setLineWidth() function is called.

Once QTextLine::setLineWidth() is called, a new line can be created and filled with text. Repeating this process will lay out the whole block of text contained in the QTextLayout. If there is no text left to be inserted into the layout, the QTextLine returned will not be valid (isValid() will return false).

virtual void QtGui.QTextLayout.CreateProxy ( )
virtual
new void QtGui.QTextLayout.Dispose ( )
new void QtGui.QTextLayout.Draw ( QPainter  p,
QPointF  pos 
)

Draws the whole layout on the painter p at the position specified by pos. The rendered layout includes the given selections and is clipped within the rectangle specified by clip.

new void QtGui.QTextLayout.Draw ( QPainter  p,
QPointF  pos,
System.Collections.Generic.List< QTextLayout.FormatRange selections 
)

Draws the whole layout on the painter p at the position specified by pos. The rendered layout includes the given selections and is clipped within the rectangle specified by clip.

new void QtGui.QTextLayout.Draw ( QPainter  p,
QPointF  pos,
System.Collections.Generic.List< QTextLayout.FormatRange selections,
QRectF  clip 
)

Draws the whole layout on the painter p at the position specified by pos. The rendered layout includes the given selections and is clipped within the rectangle specified by clip.

new void QtGui.QTextLayout.DrawCursor ( QPainter  p,
QPointF  pos,
int  cursorPosition 
)

This is an overloaded function.

Draws a text cursor with the current pen at the given position using the painter specified. The corresponding position within the text is specified by cursorPosition.

new void QtGui.QTextLayout.DrawCursor ( QPainter  p,
QPointF  pos,
int  cursorPosition,
int  width 
)

Draws a text cursor with the current pen and the specified width at the given position using the painter specified. The corresponding position within the text is specified by cursorPosition.

new void QtGui.QTextLayout.EndLayout ( )

Ends the layout process.

See also beginLayout().

new System.Collections.Generic.List<QGlyphRun> QtGui.QTextLayout.GlyphRuns ( )

Returns the glyph indexes and positions for all glyphs in this QTextLayout. This is an expensive function, and should not be called in a time sensitive context.

This function was introduced in Qt 4.8.

See also draw() and QPainter::drawGlyphRun().

new bool QtGui.QTextLayout.IsValidCursorPosition ( int  pos)

Returns true if position pos is a valid cursor position.

In a Unicode context some positions in the text are not valid cursor positions, because the position is inside a Unicode surrogate or a grapheme cluster.

A grapheme cluster is a sequence of two or more Unicode characters that form one indivisible entity on the screen. For example the latin character `&#196;' can be represented in Unicode by two characters, `A' (0x41), and the combining diaresis (0x308). A text cursor can only validly be positioned before or after these two characters, never between them since that wouldn't make sense. In indic languages every syllable forms a grapheme cluster.

new int QtGui.QTextLayout.LeftCursorPosition ( int  oldPos)

Returns the cursor position to the left of oldPos, next to it. The position is dependent on the visual position of characters, after bi-directional reordering.

This function was introduced in Qt 4.8.

See also rightCursorPosition() and previousCursorPosition().

new QTextLine QtGui.QTextLayout.LineAt ( int  i)

Returns the i-th line of text in this text layout.

See also lineCount() and lineForTextPosition().

new int QtGui.QTextLayout.LineCount ( )

Returns the number of lines in this text layout.

See also lineAt().

new QTextLine QtGui.QTextLayout.LineForTextPosition ( int  pos)

Returns the line that contains the cursor position specified by pos.

See also isValidCursorPosition() and lineAt().

new double QtGui.QTextLayout.MaximumWidth ( )

The maximum width the layout could expand to; this is essentially the width of the entire text.

Warning: This function only returns a valid value after the layout has been done.

See also minimumWidth().

new double QtGui.QTextLayout.MinimumWidth ( )

The minimum width the layout needs. This is the width of the layout's smallest non-breakable substring.

Warning: This function only returns a valid value after the layout has been done.

See also maximumWidth().

new int QtGui.QTextLayout.NextCursorPosition ( int  oldPos,
QTextLayout.CursorMode  mode = QTextLayout.CursorMode.SkipCharacters 
)

Returns the next valid cursor position after oldPos that respects the given cursor mode. Returns value of oldPos, if oldPos is not a valid cursor position.

See also isValidCursorPosition() and previousCursorPosition().

new int QtGui.QTextLayout.PreeditAreaPosition ( )

Returns the position of the area in the text layout that will be processed before editing occurs.

See also preeditAreaText().

new string QtGui.QTextLayout.PreeditAreaText ( )

Returns the text that is inserted in the layout before editing occurs.

See also preeditAreaPosition().

new int QtGui.QTextLayout.PreviousCursorPosition ( int  oldPos,
QTextLayout.CursorMode  mode = QTextLayout.CursorMode.SkipCharacters 
)

Returns the first valid cursor position before oldPos that respects the given cursor mode. Returns value of oldPos, if oldPos is not a valid cursor position.

See also isValidCursorPosition() and nextCursorPosition().

new int QtGui.QTextLayout.RightCursorPosition ( int  oldPos)

Returns the cursor position to the right of oldPos, next to it. The position is dependent on the visual position of characters, after bi-directional reordering.

This function was introduced in Qt 4.8.

See also leftCursorPosition() and nextCursorPosition().

new void QtGui.QTextLayout.SetFlags ( int  flags)
new void QtGui.QTextLayout.SetPreeditArea ( int  position,
string  text 
)

Sets the position and text of the area in the layout that is processed before editing occurs.

See also preeditAreaPosition() and preeditAreaText().

Member Data Documentation

SmokeInvocation QtGui.QTextLayout.interceptor
protected

Property Documentation

new System.Collections.Generic.List<QTextLayout.FormatRange> QtGui.QTextLayout.AdditionalFormats
getsetadd

Returns the list of additional formats supported by the text layout.

Sets the additional formats supported by the text layout to formatList.

new bool QtGui.QTextLayout.CacheEnabled
getset

Returns true if the complete layout information is cached; otherwise returns false.

Enables caching of the complete layout information if enable is true; otherwise disables layout caching. Usually QTextLayout throws most of the layouting information away after a call to endLayout() to reduce memory consumption. If you however want to draw the laid out text directly afterwards enabling caching might speed up drawing significantly.

new Qt.CursorMoveStyle QtGui.QTextLayout.CursorMoveStyle
getset

The cursor movement style of this QTextLayout. The default is Qt::LogicalMoveStyle.

This function was introduced in Qt 4.8.

Set the cursor movement style. If the QTextLayout is backed by a document, you can ignore this and use the option in QTextDocument, this option is for widgets like QLineEdit or custom widgets without a QTextDocument. Default value is Qt::LogicalMoveStyle.

This function was introduced in Qt 4.8.

new QFont QtGui.QTextLayout.Font
getset

Returns the current font that is used for the layout, or a default font if none is set.

Sets the layout's font to the given font. The layout is invalidated and must be laid out again.

new QPointF QtGui.QTextLayout.Position
getset

The global position of the layout. This is independent of the bounding rectangle and of the layout process.

This function was introduced in Qt 4.2.

Moves the text layout to point p.

virtual System.IntPtr QtGui.QTextLayout.SmokeObject
getset
new string QtGui.QTextLayout.Text
getset

Returns the layout's text.

Sets the layout's text to the given string. The layout is invalidated and must be laid out again.

Notice that when using this QTextLayout as part of a QTextDocument this method will have no effect.

new QTextOption QtGui.QTextLayout.TextOption
getset

Returns the current text option used to control the layout process.

Sets the text option structure that controls the layout process to the given option.