KWordWrap class Reference (kdeui Library)

| # kdeui Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# KWordWrap Class Reference

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...

`#include <kwordwrap.h>`

Collaboration diagram for KWordWrap:

[legend]
List of all members.

## Public Member Functions
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
| Draw the text that has been previously wrapped, at position x,y.
## Static Public Member Functions
KWordWrap * | formatText (QFontMetrics &fm, const QRect &r, int flags, const QString &str, int len=-1)
| Main method for wrapping text.

## 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

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. Definition at line 22 of file kwordwrap.cpp. References QValueList< int >::append(), QFontMetrics::charWidth(), QFontMetrics::height(), QChar::isPunct(), QChar::isSpace(), QChar::isSymbol(), QString::left(), QString::length(), m_boundingRect, m_breakPositions, m_lineWidths, m_text, QRect::setRect(), and QRect::width().

QRect KWordWrap::boundingRect | ( |  | ) | const`[inline]`

| Returns: the bounding rect, calculated by formatText. Definition at line 58 of file kwordwrap.h.

QString KWordWrap::wrappedString | ( |  | ) | const

| Returns: the original string, with ' ' inserted where the text is broken by the wordwrap algorithm. Definition at line 94 of file kwordwrap.cpp. References QValueList< int >::begin(), KStdAccel::end(), QValueList< int >::end(), and QString::mid().

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. Definition at line 110 of file kwordwrap.cpp. References QValueList< int >::begin(), QValueList< int >::end(), and QString::left().

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. Definition at line 125 of file kwordwrap.cpp. References QFontMetrics::ascent(), QValueList< int >::begin(), QPainter::drawText(), KStdAccel::end(), QValueList< int >::end(), QPainter::fontMetrics(), QFontMetrics::height(), QString::mid(), and QRect::width().

The documentation for this class was generated from the following files:

- kwordwrap.h
- kwordwrap.cpp

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:05:25 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001