25 #include <tqpaintdevicemetrics.h>
26 #include <tqpainter.h>
29 #include <tdeglobal.h>
30 #include <tdelocale.h>
31 #include <knotifyclient.h>
35 #include "kabentrypainter.h"
37 KABEntryPainter::KABEntryPainter()
38 : mShowAddresses( true ), mShowEmails( true ), mShowPhones( true ),
43 KABEntryPainter::~KABEntryPainter()
51 void KABEntryPainter::setForegroundColor(
const TQColor &color )
53 mForegroundColor = color;
56 void KABEntryPainter::setBackgroundColor(
const TQColor &color )
58 mBackgroundColor = color;
61 void KABEntryPainter::setHeaderColor(
const TQColor &color )
66 void KABEntryPainter::setHeaderFont(
const TQFont &font )
71 void KABEntryPainter::setHeadLineFont(
const TQFont &font )
76 void KABEntryPainter::setBodyFont(
const TQFont &font )
81 void KABEntryPainter::setFixedFont(
const TQFont &font )
86 void KABEntryPainter::setCommentFont(
const TQFont &font )
91 void KABEntryPainter::setUseHeaderColor(
bool value )
93 mUseHeaderColor = value;
96 void KABEntryPainter::setShowAddresses(
bool value )
98 mShowAddresses = value;
101 void KABEntryPainter::setShowEmails(
bool value )
106 void KABEntryPainter::setShowPhones(
bool value )
111 void KABEntryPainter::setShowURLs(
bool value )
116 int KABEntryPainter::hitsEmail(
const TQPoint &p )
118 return hits( mEmailRects, p );
121 int KABEntryPainter::hitsURL(
const TQPoint &p )
123 return hits( mURLRects, p );
126 int KABEntryPainter::hitsPhone(
const TQPoint &p )
128 return hits( mPhoneRects, p );
131 int KABEntryPainter::hitsTalk(
const TQPoint &p )
133 return hits( mTalkRects, p );
136 int KABEntryPainter::hits(
const TQRectList& list,
const TQPoint &p )
138 TQRectList::const_iterator pos;
141 for ( pos = list.begin(); pos != list.end(); ++pos ) {
142 if ( (*pos).contains( p ) )
151 bool KABEntryPainter::printAddressee(
const TDEABC::Addressee &addr,
152 const TQRect &window, TQPainter *painter,
153 int top,
bool fake, TQRect *brect )
156 const int Width = window.width();
157 const int Height = window.height();
158 const int Ruler1 = Width/32;
159 const int Ruler2 = 2 * Ruler1;
160 const int Ruler3 = 3 * Ruler1;
161 TQString text, line1, line2, line3, line4;
165 TQFontMetrics fmHeader( mHeaderFont );
166 TQFontMetrics fmHeadLine( mHeadLineFont );
167 TQFontMetrics fmBody( mBodyFont );
168 TQFontMetrics fmFixed( mFixedFont );
169 TQFontMetrics fmComment( mCommentFont );
172 TDEABC::Address address;
176 TQValueList<TQStringList> parts;
177 TQValueList<TQRectList*> contents;
184 painter->setWindow( window );
187 painter->setFont( mHeaderFont );
188 painter->setBrush( TQBrush( mBackgroundColor ) );
189 painter->setPen( mBackgroundColor );
190 text = addr.realName();
193 rect = painter->boundingRect( Ruler1, y, Width, Height,
194 TQt::AlignVCenter | TQt::AlignLeft, text );
195 rect.setHeight( (
int)( 1.25 * rect.height() ) );
197 if ( !fake && mUseHeaderColor )
198 painter->drawRect( 0, y, Width, rect.height() );
200 painter->setPen( mUseHeaderColor ? mHeaderColor : mForegroundColor );
203 float ypos = y + ( (float)rect.height() ) * 0.125;
204 painter->drawText( Ruler1, (
int)ypos, Width, rect.height(),
205 TQt::AlignVCenter | TQt::AlignLeft, text );
209 TQDateTime dt = addr.birthday();
210 if ( dt.isValid() ) {
211 line1 = TDEGlobal::locale()->formatDate( dt.date(),
true );
214 float ypos = y + ( (float)rect.height() ) * 0.125;
215 painter->drawText( 0, (
int)ypos, Width-Ruler1, rect.height(),
216 TQt::AlignVCenter | TQt::AlignRight, line1 );
223 painter->setFont( mBodyFont );
224 y += fmBody.lineSpacing() / 2;
226 painter->setPen( mForegroundColor );
227 if ( !addr.prefix().isEmpty() ) {
228 line1 = addr.prefix().stripWhiteSpace();
231 rect = painter->boundingRect( Ruler1, y, Width-Ruler1, Height,
232 TQt::AlignTop | TQt::AlignLeft, line1 );
234 painter->drawText( Ruler1, y, Width-Ruler1, Height, TQt::AlignTop | TQt::AlignLeft,
241 if ( !( addr.prefix().isEmpty() ) )
242 y += fmBody.lineSpacing() / 2;
247 if ( !addr.emails().isEmpty() && mShowEmails ) {
248 contents.push_back( &mEmailRects );
251 list.append( addr.emails().count() == 1 ? i18n(
"Email address:" )
252 : i18n(
"Email addresses:" ) );
253 list += addr.emails();
254 parts.push_back( list );
258 const TDEABC::PhoneNumber::List phoneNumbers( addr.phoneNumbers() );
259 if ( !phoneNumbers.isEmpty() && mShowPhones ) {
260 contents.push_back( &mPhoneRects );
264 list.append( phoneNumbers.count() == 1 ? i18n(
"Telephone:" )
265 : i18n(
"Telephones:" ) );
267 TDEABC::PhoneNumber::List::ConstIterator it;
268 for ( it = phoneNumbers.begin(); it != phoneNumbers.end(); ++it ) {
269 line = (*it).typeLabel();
270 line +=
": " + (*it).number();
271 list.append( line.stripWhiteSpace() );
274 parts.push_back( list );
278 if ( !addr.url().isEmpty() && addr.url().isValid() && mShowURLs ) {
279 contents.push_back( &mURLRects );
282 list.append( i18n(
"Web page:" ) );
283 list += addr.url().prettyURL();
284 parts.push_back( list );
300 TQRect limits[] = { TQRect( 0, y, Width / 2, Height ),
301 TQRect( Width / 2, y, Width / 2, Height ),
302 TQRect( 0, y, Width / 2, Height ),
303 TQRect( Width / 2, y, Width / 2, Height ) };
304 int heights[ 4 ]= { 0, 0, 0, 0 };
306 TQValueList<TQStringList>::iterator pos = parts.begin();
307 TQValueList<TQRectList*>::iterator rpos = contents.begin();
309 for ( uint counter = 0; counter < parts.count(); ++counter ) {
310 const int Offset = counter > 1 ? TQMAX( heights[ 0 ], heights[ 1 ] ) : 0;
311 TQStringList list = *pos;
313 painter->setFont( mHeadLineFont );
315 rect = painter->boundingRect( limits[ counter ].left(),
316 limits[ counter ].top() + heights[counter]
317 + Offset, limits[ counter ].width(),
318 limits[ counter ].height(),
319 TQt::AlignTop | TQt::AlignLeft, *list.at( 0 ) );
321 painter->drawText( limits[ counter ].left(), limits[ counter ].top() +
322 heights[ counter ] + Offset, limits[ counter ].width(),
323 limits[ counter ].height(), TQt::AlignTop | TQt::AlignLeft,
324 *list.at( 0 ), -1, &rect );
327 heights[ counter ] += rect.height();
330 painter->setFont( mFixedFont );
331 for ( uint c2 = 1; c2 < list.count(); ++c2 ) {
334 rect = painter->boundingRect ( limits[ counter ].left() + Ruler1,
335 limits[ counter ].top() + heights[ counter ]
336 + Offset, limits[ counter ].width() - Ruler1,
337 limits[ counter ].height(), TQt::AlignTop | TQt::AlignLeft,
340 painter->drawText( limits[ counter ].left() + Ruler1, limits[ counter ].top()
341 + heights[ counter ] + Offset, limits[ counter ].width()
342 - Ruler1, limits[ counter ].height(), TQt::AlignTop | TQt::AlignLeft,
343 *list.at( c2 ), -1, &rect );
345 (*rpos)->push_back( rect );
346 heights[ counter ] += rect.height();
353 y = y + TQMAX( heights[ 0 ], heights[ 1 ] ) + TQMAX( heights[ 2 ], heights[ 3 ] );
357 TDEABC::Address::List addresses = addr.addresses();
358 if ( addresses.count() > 0 && mShowAddresses ) {
359 y += fmBody.lineSpacing() / 2;
360 painter->setFont( mHeadLineFont );
362 rect = painter->boundingRect( 0, y, Width, Height, TQt::AlignTop | TQt::AlignLeft,
363 addresses.count() == 1 ? i18n(
"Address:" )
364 : i18n(
"Addresses:" ) );
366 painter->drawText( 0, y, Width, Height, TQt::AlignTop | TQt::AlignLeft,
367 addresses.count() == 1 ? i18n(
"Address:" )
368 : i18n(
"Addresses:" ), -1, &rect );
372 y += fmBody.lineSpacing() / 4;
373 painter->setFont( mBodyFont );
375 TDEABC::Address::List::ConstIterator it;
376 for ( it = addresses.begin(); it != addresses.end(); ++it ) {
378 switch ( address.type() ) {
379 case TDEABC::Address::Dom:
380 line1 = i18n(
"Domestic Address" );
382 case TDEABC::Address::Intl:
383 line1 = i18n(
"International Address" );
385 case TDEABC::Address::Postal:
386 line1 = i18n(
"Postal Address" );
388 case TDEABC::Address::Parcel:
389 line1 = i18n(
"Parcel Address" );
391 case TDEABC::Address::Home:
392 line1 = i18n(
"Home Address" );
394 case TDEABC::Address::Work:
395 line1 = i18n(
"Work Address" );
397 case TDEABC::Address::Pref:
399 line1 = i18n(
"Preferred Address" );
402 line1 += TQString::fromLatin1(
":" );
405 if ( !address.extended().isEmpty() )
406 text = address.extended().stripWhiteSpace();
408 if ( !text.isEmpty() ) {
409 line1 = line1 + TQString::fromLatin1(
" (" ) + text +
410 TQString::fromLatin1(
")" );
413 line1 = line1.stripWhiteSpace();
414 line2 = address.street();
415 if ( !address.postOfficeBox().isEmpty() )
416 line2 += TQString::fromLatin1(
" - " ) + address.postOfficeBox();
419 line3 = address.locality() + ( address.region().isEmpty() ?
420 TQString::fromLatin1(
"" ) : TQString::fromLatin1(
", " ) +
421 address.region() ) + ( address.postalCode().isEmpty()
422 ? TQString::fromLatin1(
"" ) : TQString::fromLatin1(
" " )
423 + address.postalCode() );
424 line4 = address.country();
427 rect = painter->boundingRect( Ruler1, y, Width - Ruler1, Height,
428 TQt::AlignTop | TQt::AlignLeft, line1 );
430 painter->drawText( Ruler1, y, Width - Ruler1, Height,
431 TQt::AlignTop | TQt::AlignLeft, line1, -1, &rect );
435 if ( !line2.isEmpty() ) {
437 rect = painter->boundingRect( Ruler2, y, Width - Ruler2, Height,
438 TQt::AlignTop | TQt::AlignLeft, line2 );
440 painter->drawText( Ruler2, y, Width - Ruler2, Height,
441 TQt::AlignTop | TQt::AlignLeft, line2, -1, &rect );
446 if ( !line3.isEmpty() ) {
448 rect = painter->boundingRect( Ruler2, y, Width - Ruler2, Height,
449 TQt::AlignTop | TQt::AlignLeft, line3 );
451 painter->drawText( Ruler2, y, Width - Ruler2, Height,
452 TQt::AlignTop | TQt::AlignLeft, line3, -1, &rect );
457 if ( !line4.isEmpty() ) {
459 rect = painter->boundingRect( Ruler2, y, Width - Ruler2, Height,
460 TQt::AlignTop | TQt::AlignLeft, line4 );
462 painter->drawText( Ruler2, y, Width - Ruler2, Height,
463 TQt::AlignTop | TQt::AlignLeft, line4, -1, &rect );
468 y += fmBody.lineSpacing() / 4;
469 if ( !address.label().isEmpty() ) {
471 rect = painter->boundingRect( Ruler2, y, Width - Ruler2, Height,
472 TQt::AlignTop | TQt::AlignLeft,
473 i18n(
"(Deliver to:)" ) );
475 painter->drawText( Ruler2, y, Width - Ruler2, Height,
476 TQt::AlignTop | TQt::AlignLeft,
477 i18n(
"(Deliver to:)" ), -1, &rect );
481 y += fmBody.lineSpacing() / 4;
483 rect = painter->boundingRect( Ruler3, y, Width - Ruler3, Height,
484 TQt::AlignTop | TQt::AlignLeft, address.label() );
486 painter->drawText( Ruler3, y, Width - Ruler3, Height,
487 TQt::AlignTop | TQt::AlignLeft, address.label(), -1, &rect );
491 y += fmBody.lineSpacing() / 2;
496 if ( !addr.note().isEmpty() ) {
497 painter->setFont( mCommentFont );
498 y += fmBody.lineSpacing() / 2;
500 rect = painter->boundingRect( 0, y, Width, Height,
501 TQt::AlignTop | TQt::AlignLeft | TQt::WordBreak,
504 painter->drawText( 0, y, Width, Height,
505 TQt::AlignTop | TQt::AlignLeft | TQt::WordBreak,
506 addr.note(), -1, &rect );
512 y += fmBody.lineSpacing() / 2;
515 *brect = TQRect( 0, top, Width, y - top );