class KWordWrap

Word-wrap algorithm that takes into account beautifulness ;) That means: not letting a letter alone on the last line, breaking at punctuation signs, etc. More...

Definition#include <kwordwrap.h>
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Methods

Public Static Methods


Detailed Description

Word-wrap algorithm that takes into account beautifulness ;) That means: not letting a letter alone on the last line, breaking at punctuation signs, etc.

Usage: call the static method, formatText, with the text to wrap and the constraining rectangle etc., it will return an instance of KWordWrap containing internal data, result of the word-wrapping. From that instance you can retrieve the boundingRect, and invoke drawing.

This design allows to call the word-wrap algorithm only when the text changes and not every time we want to know the bounding rect or draw the text.

KWordWrap*  formatText ( QFontMetrics &fm, const QRect & r, int flags, const QString & str, int len = -1 )

formatText

[static]

Main method for wrapping text.

Parameters:
fmFont metrics, for the chosen font. Better cache it, creating a QFontMetrics is expensive.
rConstraining rectangle. Only the width and height matter.
flags- currently unused.
strThe text to be wrapped.
lenLength of text to wrap (default is -1 for all).

Returns: a KWordWrap instance. The caller is responsible for storing and deleting the result.

QRect  boundingRect ()

boundingRect

[const]

Returns: the bounding rect, calculated by formatText.

QString  wrappedString ()

wrappedString

[const]

Returns: the original string, with '\n' inserted where the text is broken by the wordwrap algorithm.

QString  truncatedString ( bool dots = true )

truncatedString

[const]

Returns: the original string, truncated to the first line. If dots was set, '...' is appended in case the string was truncated. Bug: Note that the '...' come out of the bounding rect.

void  drawText ( QPainter *painter, int x, int y, int flags = Qt::AlignAuto )

drawText

[const]

Draw the text that has been previously wrapped, at position x,y. Flags are for alignment, e.g. AlignHCenter. Default is AlignAuto.


Generated by: dfaure on faure on Tue Apr 16 08:49:25 2002, using kdoc 2.0a53.