\section{KWord\-Wrap Class Reference}
\label{classKWordWrap}\index{KWordWrap@{KWordWrap}}
Word-wrap algorithm that takes into account beautifulness ;).  


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

Collaboration diagram for KWord\-Wrap:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=164pt]{classKWordWrap__coll__graph}
\end{center}
\end{figure}
\subsection*{Public Types}
\begin{CompactItemize}
\item 
enum \{ {\bf Fade\-Out} =  0x10000000, 
{\bf Truncate} =  0x20000000
 \}
\end{CompactItemize}
\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 
\item 
{\bf $\sim$KWord\-Wrap} ()
\end{CompactItemize}
\subsection*{Static Public Member Functions}
\begin{CompactItemize}
\item 
static {\bf KWord\-Wrap} $\ast$ {\bf format\-Text} ({\bf QFont\-Metrics} \&fm, const {\bf QRect} \&r, int flags, const {\bf QString} \&str, int len=-1)
\item 
static void {\bf draw\-Fadeout\-Text} ({\bf QPainter} $\ast$p, int x, int y, int max\-W, const {\bf QString} \&t)
\item 
static void {\bf draw\-Truncate\-Text} ({\bf QPainter} $\ast$p, int x, int y, int max\-W, const {\bf QString} \&t)
\end{CompactItemize}


\subsection{Detailed Description}
Word-wrap algorithm that takes into account beautifulness ;). 

That means: \begin{itemize}
\item not letting a letter alone on the last line, \item breaking at punctuation signs (not only at spaces) \item improved handling of (), [] and \{\} \item improved handling of '/' (e.g. for paths)\end{itemize}
Usage: call the static method, format\-Text, 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.

\begin{Desc}
\item[Author:]David Faure $<${\tt faure@kde.org}$>$ \end{Desc}




Definition at line 48 of file kwordwrap.h.

\subsection{Member Enumeration Documentation}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}anonymous enum}\label{classKWordWrap_w2}


Use this flag in {\bf draw\-Text()}{\rm (p.\,\pageref{classKWordWrap_a3})} if you want to fade out the text if it does not fit into the constraining rectangle. 

\begin{Desc}
\item[Since:]3.2 \end{Desc}


Definition at line 56 of file kwordwrap.h.

\subsection{Constructor \& Destructor Documentation}
\index{KWordWrap@{KWord\-Wrap}!~KWordWrap@{$\sim$KWordWrap}}
\index{~KWordWrap@{$\sim$KWordWrap}!KWordWrap@{KWord\-Wrap}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KWord\-Wrap::$\sim${\bf KWord\-Wrap} ()}\label{classKWordWrap_a4}


Destructor. 



Definition at line 144 of file kwordwrap.cpp.

\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} = {\tt -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. With negative height the complete text will be rendered \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 34 of file kwordwrap.cpp.

References QValue\-List::append(), QChar::is\-Punct(), QChar::is\-Space(), QChar::is\-Symbol(), QString::left(), QString::length(), m\_\-bounding\-Rect, m\_\-break\-Positions, m\_\-line\-Widths, m\_\-text, QString::remove(), and QRect::set\-Rect().\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. The width is the width of the widest text line, and never wider than the rectangle given to format\-Text. The height is the text block. X and Y are always 0. \end{Desc}


Definition at line 77 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 148 of file kwordwrap.cpp.

References QValue\-List::begin(), QValue\-List::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} = {\tt 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 164 of file kwordwrap.cpp.

References QValue\-List::first(), QValue\-List::is\-Empty(), 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} = {\tt Qt::AlignAuto}) const}\label{classKWordWrap_a3}


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

Flags are for alignment, e.g. Qt::Align\-HCenter. Default is Qt::Align\-Auto. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em painter}]the {\bf QPainter} to use. \item[{\em x}]the horizontal position of the text \item[{\em y}]the vertical position of the text \item[{\em flags}]the ORed text alignment flags from the {\bf Qt} namespace, ORed with Fade\-Out if you want the text to fade out if it does not fit (the {\tt painter's} background must be set accordingly) \end{description}
\end{Desc}


Definition at line 219 of file kwordwrap.cpp.

References QFont\-Metrics::ascent(), QValue\-List::begin(), draw\-Fadeout\-Text(), draw\-Truncate\-Text(), QValue\-List::end(), QFont\-Metrics::height(), QString::mid(), and QRect::width().\index{KWordWrap@{KWord\-Wrap}!drawFadeoutText@{drawFadeoutText}}
\index{drawFadeoutText@{drawFadeoutText}!KWordWrap@{KWord\-Wrap}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KWord\-Wrap::draw\-Fadeout\-Text ({\bf QPainter} $\ast$ {\em p}, int {\em x}, int {\em y}, int {\em max\-W}, const {\bf QString} \& {\em t})\hspace{0.3cm}{\tt  [static]}}\label{classKWordWrap_e1}


Draws the string {\tt t} at the given coordinates, if it does not {\tt fit} into {\tt max\-W} the text will be faded out. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em p}]the painter to use. Must have set the pen for the text color and the background for the color to fade out \item[{\em x}]the horizontal position of the text \item[{\em y}]the vertical position of the text \item[{\em max\-W}]the maximum width of the text (including the fade-out effect) \item[{\em t}]the text to draw \end{description}
\end{Desc}
\begin{Desc}
\item[Since:]3.2 \end{Desc}


Definition at line 181 of file kwordwrap.cpp.

References QFont\-Metrics::bounding\-Rect(), QFont\-Metrics::char\-Width(), and QFont\-Metrics::width().

Referenced by draw\-Text().\index{KWordWrap@{KWord\-Wrap}!drawTruncateText@{drawTruncateText}}
\index{drawTruncateText@{drawTruncateText}!KWordWrap@{KWord\-Wrap}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KWord\-Wrap::draw\-Truncate\-Text ({\bf QPainter} $\ast$ {\em p}, int {\em x}, int {\em y}, int {\em max\-W}, const {\bf QString} \& {\em t})\hspace{0.3cm}{\tt  [static]}}\label{classKWordWrap_e2}


Draws the string {\tt t} at the given coordinates, if it does not {\tt fit} into {\tt max\-W} the text will be truncated. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em p}]the painter to use \item[{\em x}]the horizontal position of the text \item[{\em y}]the vertical position of the text \item[{\em max\-W}]the maximum width of the text (including the '...') \item[{\em t}]the text to draw \end{description}
\end{Desc}
\begin{Desc}
\item[Since:]3.3 \end{Desc}


Definition at line 213 of file kwordwrap.cpp.

References KString\-Handler::r\-Pixel\-Squeeze().

Referenced by draw\-Text().

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