Main Page Modules Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members Related Pages
KWordWrap Class Reference
#include <kwordwrap.h>
List of all members.
|
Public Methods |
| QRect | boundingRect () const |
| QString | wrappedString () const |
| QString | truncatedString (bool dots=true) const |
| void | drawText (QPainter *painter, int x, int y, int flags=Qt::AlignAuto) const |
Static Public Methods |
| KWordWrap * | formatText (QFontMetrics &fm, const QRect &r, int flags, const QString &str, int len=-1) |
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.
Definition at line 40 of file kwordwrap.h.
Member Function Documentation
| QRect KWordWrap::boundingRect |
( |
|
) |
const [inline] |
|
|
|
- Returns:
-
the bounding rect, calculated by formatText.
Definition at line 58 of file kwordwrap.h. |
| void KWordWrap::drawText |
( |
QPainter * |
painter, |
|
|
int |
x, |
|
|
int |
y, |
|
|
int |
flags = Qt::AlignAuto |
|
) |
const |
|
|
|
Draw the text that has been previously wrapped, at position x,y. Flags are for alignment, e.g. AlignHCenter. Default is AlignAuto. |
| KWordWrap* KWordWrap::formatText |
( |
QFontMetrics & |
fm, |
|
|
const QRect & |
r, |
|
|
int |
flags, |
|
|
const QString & |
str, |
|
|
int |
len = -1 |
|
) |
[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.
|
| QString KWordWrap::truncatedString |
( |
bool |
dots = true |
) |
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. |
| QString KWordWrap::wrappedString |
( |
|
) |
|
|
|
|
- Returns:
-
the original string, with '
' inserted where the text is broken by the wordwrap algorithm. |
The documentation for this class was generated from the following file:
Generated on Wed Aug 13 23:30:28 2003 for kdelibs by
1.2.18