|
|
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:
fm | Font metrics, for the chosen font. Better cache it, creating a QFontMetrics is expensive. |
r | Constraining rectangle. Only the width and height matter. |
flags | - currently unused. |
str | The text to be wrapped. |
len | Length 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: caleb on tcdevel on Tue Jan 28 12:54:10 2003, using kdoc $. |