25#include <tqpaintdevicemetrics.h>
28#include <tdeabc/addressee.h>
29#include <tdeapplication.h>
36#include "printingwizard.h"
37#include "printprogress.h"
38#include "printstyle.h"
40#include "mikesstyle.h"
42using namespace KABPrinting;
44const int mFieldSpacingHint = 2;
49 setPreview(
"mike-style.png" );
52MikesStyle::~MikesStyle()
56void MikesStyle::print(
const TDEABC::Addressee::List &contacts,
PrintProgress *progress )
62 p.begin(
wizard()->printer() );
63 int yPos = 0, count = 0;
69 mBoldFont.setBold(
true );
70 TQFontMetrics fm( mFont );
71 TQPaintDeviceMetrics metrics( p.device() );
74 TDEABC::Addressee::List::ConstIterator it;
79 for ( it = contacts.begin(); it != contacts.end(); ++it ) {
80 progress->
setProgress( (count++ * 100) / contacts.count() );
81 kapp->processEvents();
84 height = calcHeight( *it, mFont, mBoldFont );
85 if ( (yPos + spacingHint + height) > (metrics.height() - fm.height() - 5) ) {
87 p.translate( 0, metrics.height() - fm.height() - 5 );
88 paintTagLine( p, mFont );
98 p.translate( 0, yPos );
99 doPaint( p, *it, height, mFont, mBoldFont );
109 p.translate( 0, metrics.height() - fm.height() - 5 );
110 paintTagLine( p, mFont );
117TQString MikesStyle::trimString(
const TQString &text,
int width, TQFontMetrics &fm )
119 if ( fm.width( text ) <= width )
122 TQString dots =
"...";
123 int dotWidth = fm.width( dots );
127 while ( fm.width( trimmed ) + dotWidth < width ) {
128 trimmed += text[ charNum ];
133 trimmed = trimmed.left( trimmed.length() - 1 );
139void MikesStyle::doPaint( TQPainter &painter,
const TDEABC::Addressee &addr,
140 int maxHeight,
const TQFont &font,
const TQFont &bFont )
142 TQFontMetrics fm( font );
143 TQFontMetrics bfm( bFont );
144 TQPaintDeviceMetrics metrics( painter.device() );
146 int width = metrics.width() - 10;
149 TQBrush brush( TQt::lightGray );
151 painter.setPen( TQt::black );
152 painter.drawRect( xPos, yPos, width, maxHeight );
155 painter.fillRect( xPos + 1, yPos + 1, width - 2,
156 bfm.height() + 2 * mFieldSpacingHint - 2, brush );
157 painter.setFont( bFont );
158 xPos += mFieldSpacingHint;
159 painter.drawText( xPos, yPos + bfm.height(), addr.formattedName() );
161 yPos += bfm.height() + 2 * mFieldSpacingHint;
165 painter.setFont( font );
168 int numFields = fields.count();
172 for (
int i = 0; i < numFields / 2; i++ ) {
173 label = fields[ i ]->label();
174 value = trimString( fields[ i ]->value( addr ), (width - 10) / 4, fm );
177 painter.drawText( xPos, yPos, label +
":" );
179 xPos += (width - (2 * margin)) / 4;
180 painter.drawText( xPos, yPos, value );
182 yPos += mFieldSpacingHint;
186 yPos = bfm.height() + 2 * mFieldSpacingHint;
187 xPos = margin + width / 2;
188 for (
int i = numFields / 2; i < numFields; i++ ) {
189 label = fields[ i ]->label();
190 value = value = trimString( fields[ i ]->value( addr ), (width - 10) / 4, fm );
193 painter.drawText( xPos, yPos, label +
":" );
195 xPos += (width - (2 * margin)) / 4;
196 painter.drawText( xPos, yPos, value );
198 yPos += mFieldSpacingHint;
199 xPos = margin + width / 2;
203void MikesStyle::paintTagLine( TQPainter &p,
const TQFont &font )
205 TQFontMetrics fm( font );
207 TQString text = i18n(
"Printed on %1 by KAddressBook (http://www.kde.org)" )
208 .arg( TDEGlobal::locale()->formatDateTime( TQDateTime::currentDateTime() ) );
210 p.setPen( TQt::black );
211 p.drawText( 0, fm.height(), text );
214int MikesStyle::calcHeight(
const TDEABC::Addressee &addr,
215 const TQFont &font,
const TQFont &bFont )
217 TQFontMetrics fm( font );
218 TQFontMetrics bfm( bFont );
224 int numFields = fieldList.count();
228 for (
int i = 0; i < numFields / 2; i++ )
229 halfHeight += fm.height() * (fieldList[ i ]->value( addr ).contains(
'\n' ) + 1);
235 for (
int i = numFields / 2; i < numFields; i++ )
236 halfHeight += fm.height() * (fieldList[ i ]->value( addr ).contains(
'\n' ) + 1);
238 height = TQMAX( height, halfHeight );
241 height += bfm.height() + ((numFields / 2 + 3) * mFieldSpacingHint);
247MikesStyleFactory::MikesStyleFactory(
PrintingWizard *parent,
const char *name )
254 return new MikesStyle( mParent, mName );
259 return i18n(
"Mike's Printing Style" );
262#include "mikesstyle.moc"
This defines a simple widget to display print progress information.
void addMessage(const TQString &)
Add a message to the message log.
void setProgress(int)
Set the progress to a certain amount.
The factories are used to have all object of the respective print style created in one place.
virtual TQString description() const =0
Overload this method to provide a one-liner description for your print style.
The class PrintStyle implements the abstract interface to the PrintingWizards style objects.
PrintingWizard * wizard()
Return the wizard object.
The PrintingWizard combines pages common for all print styles and those provided by the respective st...
TDEABC::AddressBook * addressBook()
Retrieve the document object.
KPrinter * printer()
Retrieve the printer to be used.