\section{KWord\-Wrap Class Reference}
\label{classKWordWrap}\index{KWordWrap@{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.  


{\tt \#include $<$kwordwrap.h$>$}

Collaboration diagram for KWord\-Wrap:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=189pt]{classKWordWrap__coll__graph}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
{\bf QRect} {\bf bounding\-Rect} () const 
\item 
{\bf QString} {\bf wrapped\-String} () const 
\item 
{\bf QString} {\bf truncated\-String} (bool dots=true) const 
\item 
void {\bf draw\-Text} ({\bf QPainter} $\ast$painter, int x, int y, int flags=Qt::Align\-Auto) const 
\begin{CompactList}\small\item\em Draw the text that has been previously wrapped, at position x,y. \item\end{CompactList}\end{CompactItemize}
\subsection*{Static Public Member Functions}
\begin{CompactItemize}
\item 
{\bf KWord\-Wrap} $\ast$ {\bf format\-Text} ({\bf QFont\-Metrics} \&fm, const  {\bf QRect} \&r, int flags, const  {\bf QString} \&str, int len=-1)
\begin{CompactList}\small\item\em Main method for wrapping text. \item\end{CompactList}\end{CompactItemize}


\subsection{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, {\bf format\-Text}{\rm (p.\,\pageref{classKWordWrap_e0})}, with the text to wrap and the constraining rectangle etc., it will return an instance of KWord\-Wrap containing internal data, result of the word-wrapping. From that instance you can retrieve the bounding\-Rect, 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.

\subsection{Member Function Documentation}
\index{KWordWrap@{KWord\-Wrap}!formatText@{formatText}}
\index{formatText@{formatText}!KWordWrap@{KWord\-Wrap}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf KWord\-Wrap} $\ast$ KWord\-Wrap::format\-Text ({\bf QFont\-Metrics} \& {\em fm}, const {\bf QRect} \& {\em r}, int {\em flags}, const {\bf QString} \& {\em str}, int {\em len} = -1)\hspace{0.3cm}{\tt  [static]}}\label{classKWordWrap_e0}


Main method for wrapping text. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em fm}]Font metrics, for the chosen font. Better cache it, creating a {\bf QFont\-Metrics} is expensive. \item[{\em r}]Constraining rectangle. Only the width and height matter. \item[{\em flags}]- currently unused. \item[{\em str}]The text to be wrapped. \item[{\em len}]Length of text to wrap (default is -1 for all). \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]a KWord\-Wrap instance. The caller is responsible for storing and deleting the result. \end{Desc}


Definition at line 22 of file kwordwrap.cpp.

References QValue\-List$<$ int $>$::append(), QFont\-Metrics::char\-Width(), QFont\-Metrics::height(), QChar::is\-Punct(), QChar::is\-Space(), QChar::is\-Symbol(), QString::left(), QString::length(), m\_\-bounding\-Rect, m\_\-break\-Positions, m\_\-line\-Widths, m\_\-text, QRect::set\-Rect(), and QRect::width().\index{KWordWrap@{KWord\-Wrap}!boundingRect@{boundingRect}}
\index{boundingRect@{boundingRect}!KWordWrap@{KWord\-Wrap}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QRect} KWord\-Wrap::bounding\-Rect () const\hspace{0.3cm}{\tt  [inline]}}\label{classKWordWrap_a0}


\begin{Desc}
\item[Returns:]the bounding rect, calculated by format\-Text. \end{Desc}


Definition at line 58 of file kwordwrap.h.\index{KWordWrap@{KWord\-Wrap}!wrappedString@{wrappedString}}
\index{wrappedString@{wrappedString}!KWordWrap@{KWord\-Wrap}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QString} KWord\-Wrap::wrapped\-String () const}\label{classKWordWrap_a1}


\begin{Desc}
\item[Returns:]the original string, with '\par
' inserted where the text is broken by the wordwrap algorithm. \end{Desc}


Definition at line 94 of file kwordwrap.cpp.

References QValue\-List$<$ int $>$::begin(), KStd\-Accel::end(), QValue\-List$<$ int $>$::end(), and QString::mid().\index{KWordWrap@{KWord\-Wrap}!truncatedString@{truncatedString}}
\index{truncatedString@{truncatedString}!KWordWrap@{KWord\-Wrap}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QString} KWord\-Wrap::truncated\-String (bool {\em dots} = true) const}\label{classKWordWrap_a2}


\begin{Desc}
\item[Returns:]the original string, truncated to the first line. If {\tt dots} was set, '...' is appended in case the string was truncated. Bug: Note that the '...' come out of the bounding rect. \end{Desc}


Definition at line 110 of file kwordwrap.cpp.

References QValue\-List$<$ int $>$::begin(), QValue\-List$<$ int $>$::end(), and QString::left().\index{KWordWrap@{KWord\-Wrap}!drawText@{drawText}}
\index{drawText@{drawText}!KWordWrap@{KWord\-Wrap}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KWord\-Wrap::draw\-Text ({\bf QPainter} $\ast$ {\em painter}, int {\em x}, int {\em y}, int {\em flags} = Qt::Align\-Auto) const}\label{classKWordWrap_a3}


Draw the text that has been previously wrapped, at position x,y. 

Flags are for alignment, e.g. Align\-HCenter. Default is Align\-Auto. 

Definition at line 125 of file kwordwrap.cpp.

References QFont\-Metrics::ascent(), QValue\-List$<$ int $>$::begin(), QPainter::draw\-Text(), KStd\-Accel::end(), QValue\-List$<$ int $>$::end(), QPainter::font\-Metrics(), QFont\-Metrics::height(), QString::mid(), and QRect::width().

The documentation for this class was generated from the following files:\begin{CompactItemize}
\item 
kwordwrap.h\item 
kwordwrap.cpp\end{CompactItemize}
