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 (not only at spaces)
- improved handling of (), [] and {}
- improved handling of '/' (e.g.
#include <kwordwrap.h>
Public Types | |
enum | { FadeOut = 0x10000000 } |
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 |
~KWordWrap () | |
Static Public Member Functions | |
KWordWrap * | formatText (QFontMetrics &fm, const QRect &r, int flags, const QString &str, int len=-1) |
void | drawFadeoutText (QPainter *p, int x, int y, int maxW, const QString &t) |
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 (not only at spaces)
- improved handling of (), [] and {}
- improved handling of '/' (e.g.
for paths)
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.
- Author:
- David Faure <faure@kde.org>
Definition at line 44 of file kwordwrap.h.
Member Enumeration Documentation
|
Use this flag in drawText() if you want to fade out the text if it does not fit into the constraining rectangle.
|
Constructor & Destructor Documentation
|
Destructor. Definition at line 134 of file kwordwrap.cpp. |
Member Function Documentation
|
Main method for wrapping text.
References QValueList::append(), QFontMetrics::charWidth(), QFontMetrics::height(), QString::left(), QString::length(), m_boundingRect, m_breakPositions, m_lineWidths, m_text, QString::remove(), QRect::setRect(), and QRect::width(). |
|
|
|
References QValueList::begin(), QValueList::end(), and QString::mid(). |
|
References QValueList::begin(), QValueList::end(), and QString::left(). |
|
Draw the text that has been previously wrapped, at position x,y. Flags are for alignment, e.g. Qt::AlignHCenter. Default is Qt::AlignAuto.
References QFontMetrics::ascent(), QValueList::begin(), drawFadeoutText(), QPainter::drawText(), QValueList::end(), QPainter::fontMetrics(), QFontMetrics::height(), QString::mid(), and QRect::width(). |
|
Draws the string
References QString::at(), QPainter::backgroundColor(), QFontMetrics::boundingRect(), QFontMetrics::charWidth(), QPainter::drawText(), QPainter::fontMetrics(), QString::left(), QString::length(), QPainter::pen(), QPainter::setPen(), and QFontMetrics::width(). Referenced by drawText(). |
The documentation for this class was generated from the following files: