kaddressbook Library API Documentation

kabentrypainter.cpp

00001 /* -*- C++ -*-
00002    This file implements kabīs printing methods. It is a part of the
00003    TopLevelWidget implementation.
00004 
00005    the KDE addressbook
00006 
00007    $ Author: Mirko Boehm $
00008    $ Copyright: (C) 1996-2001, Mirko Boehm $
00009    $ Contact: mirko@kde.org
00010          http://www.kde.org $
00011    $ License: GPL with the following explicit clarification:
00012          This code may be linked against any version of the Qt toolkit
00013          from Troll Tech, Norway. $
00014 
00015    $Revision: 1.1 $
00016 */
00017 
00018 // #include "kab_mainwidget.h"
00019 #include "kabentrypainter.h"
00020 #include "look_basic.h"
00021 
00022 #include <kprinter.h>
00023 #include <qpaintdevicemetrics.h>
00024 #include <qpainter.h>
00025 
00026 
00027 #include <klocale.h>
00028 #include <kglobal.h>
00029 #include <kdebug.h>
00030 #include <knotifyclient.h>
00031 #include <kurl.h>
00032 
00033 KABEntryPainter::KABEntryPainter(QColor foreColor_,
00034                                  QColor headerColor_,
00035                                  bool useHeaderColor_,
00036                                  QColor backColor_,
00037                                  QFont header_,
00038                                  QFont headlines_,
00039                                  QFont body_,
00040                                  QFont fixed_,
00041                                  QFont comment_,
00042                                  bool showAddresses_,
00043                                  bool showEmails_,
00044                                  bool showTelephones_,
00045                                  bool showURLs_)
00046   : foreColor(foreColor_),
00047     headerColor(headerColor_),
00048     useHeaderColor(useHeaderColor_),
00049     backColor(backColor_),
00050     header(header_),
00051     headlines(headlines_),
00052     body(body_),
00053     fixed(fixed_),
00054     comment(comment_),
00055     showAddresses(showAddresses_),
00056     showEmails(showEmails_),
00057     showTelephones(showTelephones_),
00058     showURLs(showURLs_)
00059 {
00060 }
00061 
00062 KABEntryPainter::~KABEntryPainter()
00063 {
00064   emails.clear();
00065   telephones.clear();
00066   URLs.clear();
00067 }
00068 
00069 void KABEntryPainter::setShowAddresses(bool b)
00070 {
00071     showAddresses=b;
00072 }
00073 
00074 void KABEntryPainter::setShowEmails(bool b)
00075 {
00076     showEmails=b;
00077 }
00078 
00079 void KABEntryPainter::setShowTelephones(bool b)
00080 {
00081     showTelephones=b;
00082 }
00083 
00084 void KABEntryPainter::setShowURLs(bool b)
00085 {
00086     showURLs=b;
00087 }
00088 
00089 int KABEntryPainter::hitsEmail(QPoint p)
00090 {
00091     return hits(emails, p);
00092 }
00093 
00094 int KABEntryPainter::hitsURLs(QPoint p)
00095 {
00096     return hits(URLs, p);
00097 }
00098 int KABEntryPainter::hitsTelephones(QPoint p)
00099 {
00100     return hits(telephones, p);
00101 }
00102 int KABEntryPainter::hitsTalkAddresses(QPoint p)
00103 {
00104     return hits(talk, p);
00105 }
00106 
00107 int KABEntryPainter::hits(const QRectList& list, QPoint p)
00108 {
00109     QRectList::const_iterator pos;
00110     int count=0;
00111     // -----
00112     for(pos=list.begin(); pos!=list.end(); ++pos)
00113     {
00114         if((*pos).contains(p))
00115         {
00116             return count;
00117         }
00118         ++count;
00119     }
00120     return -1;
00121 }
00122 
00123 bool KABEntryPainter::printEntry(const KABC::Addressee& entry,
00124                                  const QRect& window,
00125                                  QPainter *painter,
00126                                  int top, bool fake, QRect *brect)
00127 {
00128     // TODO: custom fields, custom (?) for Entry
00129     const int Width=window.width();
00130     const int Height=window.height();
00131     const int Ruler1=Width/32;
00132     const int Ruler2=2*Ruler1;
00133     const int Ruler3=3*Ruler1;
00134     QString text, line1, line2, line3, line4;
00135     QRect rect;
00136     // settings derived from the options:
00137     QFontMetrics fmheader(header);
00138     QFontMetrics fmheadline(headlines);
00139     QFontMetrics fmbody(body);
00140     QFontMetrics fmfixed(fixed);
00141     QFontMetrics fmcomment(comment);
00142     int y=top;
00143     KABC::Address address;
00144     // this is used to prepare some fields for printing and decide about
00145     // the layout later:
00146     QValueList<QStringList> parts;
00147     QValueList<QRectList*> contents;
00148 
00149     emails.clear(); telephones.clear(); URLs.clear();
00150 
00151     // ----- set window the painter works on:
00152     painter->setWindow(window);
00153     // ----- first draw a black rectangle on top, containing the entries
00154     //       name, centered:
00155     painter->setFont(header);
00156     painter->setBrush(QBrush(backColor));
00157     painter->setPen(backColor);
00158     text=entry.realName();
00159     // replacement for: api->addressbook()->literalName(entry, text);
00160     rect=painter->boundingRect(Ruler1, y, Width, Height,
00161                                Qt::AlignVCenter | Qt::AlignLeft, text);
00162     rect.setHeight((int)(1.25*rect.height()));
00163     if(!fake && useHeaderColor)
00164     {
00165         painter->drawRect(0, y, Width, rect.height());
00166     }
00167     painter->setPen(useHeaderColor ? headerColor : foreColor);
00168     if(!fake)
00169     {
00170         // create a little (1/8) space on top of the letters:
00171         float ypos=y+((float)rect.height())*0.125;
00172         painter->drawText(Ruler1, (int)ypos, Width, rect.height(),
00173                           Qt::AlignVCenter | Qt::AlignLeft, text);
00174     }
00175     //       paint the birthday to the right:
00176     QDateTime dt=entry.birthday();
00177     if(dt.isValid())
00178     {
00179         line1=KGlobal::locale()->formatDate(dt.date(), true);
00180         if(!fake)
00181         {
00182             // create a little (1/8) space on top of the letters:
00183             float ypos=y+((float)rect.height())*0.125;
00184             painter->drawText(0, (int)ypos, Width-Ruler1, rect.height(),
00185                               Qt::AlignVCenter | Qt::AlignRight, line1);
00186         }
00187     }
00188     y+=rect.height();
00189     // ----- now draw the data according to the person:
00190     painter->setFont(body);
00191     y+=fmbody.lineSpacing()/2;
00192     painter->setPen(foreColor);
00193     if(!entry.prefix().isEmpty())
00194     {
00195         line1=entry.prefix();
00196         line1=line1.stripWhiteSpace();
00197         if(fake)
00198         {
00199             rect=painter->boundingRect(Ruler1, y, Width-Ruler1, Height,
00200                                        Qt::AlignTop | Qt::AlignLeft,
00201                                        line1);
00202         } else {
00203             painter->drawText(Ruler1, y, Width-Ruler1, Height,
00204                               Qt::AlignTop | Qt::AlignLeft,
00205                               line1, -1, &rect);
00206         }
00207         y+=rect.height();
00208     }
00209     /*
00210       if(!entry.title.isEmpty())
00211       {
00212       line2=entry.title;
00213       line2=line2.stripWhiteSpace();
00214       if(fake)
00215       {
00216       rect=painter->boundingRect(Ruler1, y, Width-Ruler1, Height,
00217       Qt::AlignTop | Qt::AlignLeft,
00218       line2);
00219       } else {
00220       painter->drawText(Ruler1, y, Width-Ruler1, Height,
00221       Qt::AlignTop | Qt::AlignLeft,
00222       line2, -1, &rect);
00223       }
00224       y+=rect.height();
00225     }
00226     */
00227     if(!(entry.prefix().isEmpty()))    {
00228         y+=fmbody.lineSpacing()/2;
00229     }
00230     // ----- fill the parts stringlist, it contains "parts" (printable
00231     // areas) that will be combined to fill the page as effectively as
00232     // possible:
00233     //       Email addresses:
00234     if(!entry.emails().isEmpty() && showEmails)
00235     {
00236         contents.push_back(&emails);
00237         QStringList list;
00238         // -----
00239         list.append(entry.emails().count()==1
00240                     ? i18n("Email address:")
00241                     : i18n("Email addresses:"));
00242         list+=entry.emails();
00243         parts.push_back(list);
00244     }
00245     //       Telephones:
00246     KABC::PhoneNumber::List phoneNumbers=entry.phoneNumbers();
00247     if(!phoneNumbers.isEmpty() && showTelephones)
00248     {
00249         contents.push_back(&telephones);
00250         QStringList list;
00251         QString line;
00252         // -----
00253         list.append(phoneNumbers.count()==1
00254                     ? i18n("Telephone:")
00255                     : i18n("Telephones:"));
00256         // ----- this is more complex:
00257         for(KABC::PhoneNumber::List::Iterator it=phoneNumbers.begin();
00258             it!=phoneNumbers.end();
00259             ++it)
00260         {
00261             line=(*it).typeLabel();
00262             line+=": " + (*it).number();
00263             list.append(line.stripWhiteSpace());
00264         }
00265         parts.push_back(list);
00266     }
00267     //       Web pages/URLs:
00268     if(!entry.url().isEmpty() && entry.url().isValid() && showURLs)
00269     {
00270         contents.push_back(&URLs);
00271         QStringList list;
00272         // -----
00273 //         list.append(entry.URLs.count()==1
00274 //                     ? i18n("Web page:")
00275 //                     : i18n("Web pages:"));
00276         list.append(i18n("Web page:"));
00277         list+=entry.url().prettyURL();
00278         parts.push_back(list);
00279     }
00280     /*
00281     //       Talk addresses:
00282     if(!entry.talk.isEmpty())
00283     {
00284     contents.push_back(&talk);
00285     QStringList list;
00286     // -----
00287     list.append(entry.talk.count()==1
00288     ? i18n("Talk address:")
00289     : i18n("Talk addresses:"));
00290     list+=entry.talk;
00291     parts.push_back(list);
00292     }
00293     */
00294     // -----
00295     QRect limits[]= {
00296         QRect(0, y, Width/2, Height),
00297         QRect(Width/2, y, Width/2, Height),
00298         QRect(0, y, Width/2, Height),
00299         QRect(Width/2, y, Width/2, Height) };
00300     int heights[4]= { 0, 0, 0, 0 };
00301     // -----
00302     QValueList<QStringList>::iterator pos=parts.begin();
00303     QValueList<QRectList*>::iterator rpos=contents.begin();
00304     for(unsigned counter=0; counter<parts.count(); ++counter)
00305     {
00306         const int Offset=counter>1 ? QMAX(heights[0], heights[1]) : 0;
00307         QStringList list=*pos;
00308         // -----
00309         painter->setFont(headlines);
00310         if(fake)
00311         {
00312             rect=painter->boundingRect
00313                  (limits[counter].left(),
00314                   limits[counter].top()+heights[counter]+Offset,
00315                   limits[counter].width(),
00316                   limits[counter].height(),
00317                   Qt::AlignTop | Qt::AlignLeft,
00318                   *list.at(0));
00319         } else {
00320             painter->drawText
00321                 (limits[counter].left(),
00322                  limits[counter].top()+heights[counter]+Offset,
00323                  limits[counter].width(),
00324                  limits[counter].height(),
00325                  Qt::AlignTop | Qt::AlignLeft,
00326                  *list.at(0), -1, &rect);
00327         }
00328         heights[counter]+=rect.height();
00329         // ----- paint the other elements at Ruler1:
00330         painter->setFont(fixed);
00331         for(unsigned c2=1; c2<list.count(); ++c2)
00332         { // @todo: implement proper line breaking!
00333             if(fake)
00334             {
00335                 rect=painter->boundingRect
00336                      (limits[counter].left()+Ruler1,
00337                       limits[counter].top()+heights[counter]+Offset,
00338                       limits[counter].width()-Ruler1,
00339                       limits[counter].height(),
00340                       Qt::AlignTop | Qt::AlignLeft,
00341                       *list.at(c2));
00342             } else {
00343                 painter->drawText
00344                     (limits[counter].left()+Ruler1,
00345                      limits[counter].top()+heights[counter]+Offset,
00346                      limits[counter].width()-Ruler1,
00347                      limits[counter].height(),
00348                      Qt::AlignTop | Qt::AlignLeft,
00349                      *list.at(c2), -1, &rect);
00350             }
00351             (*rpos)->push_back(rect);
00352             heights[counter]+=rect.height();
00353         }
00354         // ----- done
00355         ++pos;
00356         ++rpos;
00357     }
00358     y=y+QMAX(heights[0], heights[1])+QMAX(heights[2], heights[3]);
00359     // ^^^^^ done with emails, telephone, URLs and talk addresses
00360     // ----- now print the addresses:
00361     KABC::Address::List addresses=entry.addresses();
00362     if(addresses.count()>0 && showAddresses)
00363     {
00364         y+=fmbody.lineSpacing()/2;
00365         painter->setFont(headlines);
00366         if(fake)
00367         {
00368             rect=painter->boundingRect
00369                  (0, y, Width, Height,
00370                   Qt::AlignTop | Qt::AlignLeft,
00371                   addresses.count()==1 ? i18n("Address:") : i18n("Addresses:"));
00372         } else {
00373             painter->drawText(0, y, Width, Height,
00374                               Qt::AlignTop | Qt::AlignLeft,
00375                               addresses.count()==1
00376                               ? i18n("Address:") : i18n("Addresses:"),
00377                               -1, &rect);
00378         }
00379         y+=rect.height();
00380         y+=fmbody.lineSpacing()/4;
00381         painter->setFont(body);
00382         for(KABC::Address::List::iterator it=addresses.begin();
00383             it!=addresses.end();
00384             ++it)
00385         {
00386             bool org; org=false;
00387             address=*it;
00388             switch(address.type())
00389             {
00390             case KABC::Address::Dom: // domestic
00391                 line1=i18n("Domestic Address");
00392                 break;
00393             case KABC::Address::Intl: // domestic
00394                 line1=i18n("International Address");
00395                 break;
00396             case KABC::Address::Postal:
00397                 line1=i18n("Postal Address");
00398                 break;
00399             case KABC::Address::Parcel:
00400                 line1=i18n("Parcel Address");
00401                 break;
00402             case KABC::Address::Home:
00403                 line1=i18n("Home Address");
00404                 break;
00405             case KABC::Address::Work:
00406                 line1=i18n("Work Address");
00407                 break;
00408             case KABC::Address::Pref:
00409             default:
00410                 line1=i18n("Preferred Address");
00411             };
00412             line1+=QString::fromLatin1(":");
00413             text=QString::null;
00414             /*
00415               if(!address.position.isEmpty())
00416               {
00417               text+=address.position;
00418               }
00419               if(!address.org.isEmpty())
00420               {
00421               if(!text.isEmpty())
00422               {
00423               text+=", ";
00424               }
00425               text+=address.org;
00426               org=true;
00427               }
00428               if(!address.orgUnit.isEmpty())
00429               {
00430               if(!org)
00431               {
00432               text+=", ";
00433               } else {
00434               text+=" / ";
00435               }
00436               text+=address.orgUnit;
00437               org=true;
00438               }
00439               if(!address.orgSubUnit.isEmpty())
00440               {
00441               if(!org)
00442               {
00443               text+=", ";
00444               } else {
00445               text+=" / ";
00446               }
00447               text+=address.orgSubUnit;
00448               org=true;
00449               }
00450             */
00451             if(!address.extended().isEmpty())
00452             {
00453                 text=address.extended();
00454             }
00455             text=text.stripWhiteSpace();
00456             if(!text.isEmpty())
00457             {
00458                 line1=line1+QString::fromLatin1(" (")
00459                       +text+QString::fromLatin1(")");
00460             }
00461             line1=line1.stripWhiteSpace();
00462             line2=address.street();
00463             if(!address.postOfficeBox().isEmpty())
00464             {
00465                 line2+=QString::fromLatin1(" - ") + address.postOfficeBox();
00466             }
00467             // ----- print address in american style, this will need
00468             // localisation:
00469             line3=address.locality()
00470                   +(address.region().isEmpty()
00471                     ? QString::fromLatin1("")
00472                     : QString::fromLatin1(", ")+address.region())
00473                   +(address.postalCode().isEmpty()
00474                     ? QString::fromLatin1("")
00475                     : QString::fromLatin1(" ")+address.postalCode());
00476             line4=address.country();
00477             // -----
00478             /*
00479               if(line1.isEmpty())
00480               {
00481               line1=i18n("Unnamed address:");
00482               }
00483             */
00484             if(fake)
00485             {
00486                 rect=painter->boundingRect(Ruler1, y, Width-Ruler1, Height,
00487                                            Qt::AlignTop | Qt::AlignLeft,
00488                                            line1);
00489             } else {
00490                 painter->drawText(Ruler1, y, Width-Ruler1, Height,
00491                                   Qt::AlignTop | Qt::AlignLeft,
00492                                   line1, -1, &rect);
00493             }
00494             y+=rect.height();
00495             if(!line2.isEmpty())
00496             {
00497                 if(fake)
00498                 {
00499                     rect=painter->boundingRect(Ruler2, y, Width-Ruler2, Height,
00500                                                Qt::AlignTop | Qt::AlignLeft,
00501                                                line2);
00502                 } else {
00503                     painter->drawText(Ruler2, y, Width-Ruler2, Height,
00504                                       Qt::AlignTop | Qt::AlignLeft,
00505                                       line2, -1, &rect);
00506                 }
00507                 y+=rect.height();
00508             }
00509             if(!line3.isEmpty())
00510             {
00511                 if(fake)
00512                 {
00513                     rect=painter->boundingRect(Ruler2, y, Width-Ruler2, Height,
00514                                                Qt::AlignTop | Qt::AlignLeft,
00515                                                line3);
00516                 } else {
00517                     painter->drawText(Ruler2, y, Width-Ruler2, Height,
00518                                       Qt::AlignTop | Qt::AlignLeft,
00519                                       line3, -1, &rect);
00520                 }
00521                 y+=rect.height();
00522             }
00523             if(!line4.isEmpty())
00524             {
00525                 if(fake)
00526                 {
00527                     rect=painter->boundingRect(Ruler2, y, Width-Ruler2, Height,
00528                                                Qt::AlignTop | Qt::AlignLeft,
00529                                                line4);
00530                 } else {
00531                     painter->drawText(Ruler2, y, Width-Ruler2, Height,
00532                                       Qt::AlignTop | Qt::AlignLeft,
00533                                       line4, -1, &rect);
00534                 }
00535                 y+=rect.height();
00536             }
00537             y+=fmbody.lineSpacing()/4;
00538             if(!address.label().isEmpty())
00539             {
00540                 if(fake)
00541                 {
00542                     rect=painter->boundingRect(Ruler2, y, Width-Ruler2, Height,
00543                                                Qt::AlignTop | Qt::AlignLeft,
00544                                                i18n("(Deliver to:)"));
00545                 } else {
00546                     painter->drawText(Ruler2, y, Width-Ruler2, Height,
00547                                       Qt::AlignTop | Qt::AlignLeft,
00548                                       i18n("(Deliver to:)"), -1, &rect);
00549                 }
00550                 y+=rect.height();
00551                 y+=fmbody.lineSpacing()/4;
00552                 if(fake)
00553                 {
00554                     rect=painter->boundingRect(Ruler3, y, Width-Ruler3, Height,
00555                                                Qt::AlignTop | Qt::AlignLeft,
00556                                                address.label());
00557                 } else {
00558                     painter->drawText(Ruler3, y, Width-Ruler3, Height,
00559                                       Qt::AlignTop | Qt::AlignLeft,
00560                                       address.label(), -1, &rect);
00561                 }
00562                 y+=rect.height();
00563                 y+=fmbody.lineSpacing()/2;
00564             }
00565         }
00566     }
00567     if(!entry.note().isEmpty())
00568     {
00569         painter->setFont(comment);
00570         y+=fmbody.lineSpacing()/2;
00571         if(fake)
00572         {
00573             rect=painter->boundingRect(0, y, Width, Height,
00574                                        Qt::AlignTop | Qt::AlignLeft | Qt::WordBreak,
00575                                        entry.note());
00576         } else {
00577             painter->drawText(0, y, Width, Height,
00578                               Qt::AlignTop | Qt::AlignLeft | Qt::WordBreak,
00579                               entry.note(), -1, &rect);
00580         }
00581         y+=rect.height();
00582     }
00583     y+=fmbody.lineSpacing()/2;
00584     // ----- we are done:
00585     if(brect!=0)
00586     {
00587         *brect=QRect(0, top, Width, y-top);
00588     }
00589     if(y<Height)
00590     {
00591         return true;
00592     } else {
00593         return false;
00594     }
00595     return true;
00596 }
00597 
00598 
00599 
00600 /*
00601   bool TopLevelWidget::printEntries(const BunchOfKeys keys)
00602   {
00603   KPrinter printer;
00604   QPainter painter;
00605   // QRect rect;
00606   // ----- variables used to define MINIMAL MARGINS entered by the user:
00607   int marginTop=0,
00608   marginLeft=64, // to allow stapling
00609   marginRight=0,
00610   marginBottom=0;
00611   register int left, top, width, height;
00612   // -----
00613   if(!printer.setup(this))
00614   {
00615   emit(setStatus(i18n("Rejected.")));
00616   KNotifyClient::beep();
00617   return false;
00618   }
00619   // ----- create the metrics in accordance to the selection:
00620   printer.setFullPage(true); // use whole page
00621   QPaintDeviceMetrics metrics(&printer);
00622   kdDebug() << "TopLevelWidget::slotPrintEntries: printing on a "
00623   << metrics.width() << "x" << metrics.height()
00624   << " size area," << endl << "   "
00625   << "margins are "
00626   << printer.margins().width() << " (left/right) and "
00627   << printer.margins().height() << " (top/bottom)." << endl;
00628   left=QMAX(printer.margins().width(), marginLeft); // left margin
00629   top=QMAX(printer.margins().height(), marginTop); // top margin
00630   width=metrics.width()-left
00631   -QMAX(printer.margins().width(), marginRight); // page width
00632   height=metrics.height()-top
00633   -QMAX(printer.margins().height(), marginBottom); // page height
00634   // -----
00635   painter.begin(&printer);
00636   painter.setViewport(left, top, width, height);
00637   return printEntries(keys, &printer, &painter,
00638   QRect(0, 0, metrics.width(), metrics.height()));
00639   painter.end();
00640   }
00641 
00642   bool TopLevelWidget::printEntries(const BunchOfKeys keys,
00643   KPrinter *printer,
00644   QPainter *painter,
00645   const QRect& window)
00646   {
00647   BunchOfKeys::const_iterator pos;
00648   AddressBook::Entry entry;
00649   QRect brect;
00650   int ypos=0;
00651   KABEntryPainter p(Qt::black, Qt::white, Qt::black,
00652   QFont("Utopia", 12, QFont::Normal, true),
00653   QFont("Utopia", 10, QFont::Bold, true),
00654   QFont("Utopia", 10, QFont::Normal, false),
00655   QFont("Helvetica", 10, QFont::Normal, false),
00656   QFont("Utopia", 8, QFont::Normal, false));
00657   // -----
00658   for(pos=keys.begin(); pos!=keys.end(); ++pos)
00659   {
00660   if(api->addressbook()->getEntry(*pos, entry)==AddressBook::NoError)
00661   {
00662   // ----- do a faked print to get the bounding rect:
00663   if(!p.printEntry(entry, window, painter, api, ypos, true, &brect))
00664   { // it does not fit on the page beginning at ypos:
00665   printer->newPage();
00666   ypos=0; // WORK_TO_DO: this assumes the entry fits on the whole page
00667   }
00668   p.printEntry(entry, window, painter, api, ypos, false, &brect);
00669   ypos+=brect.height();
00670   } else {
00671   kdDebug() << "TopLevelWidget::printEntries: cannot get entry "
00672   << (*pos).getKey() << ", skipping." << endl;
00673   }
00674   }
00675   return true;
00676   }
00677 
00678   void TopLevelWidget::slotPrintEntries()
00679   { // this slot prints all entries in the order they are displayed
00680   BunchOfKeys bunch;
00681   // -----
00682   KabKey key;
00683   for(unsigned counter=0; counter<api->addressbook()->noOfEntries(); ++counter)
00684   {
00685   if(api->addressbook()->getKey(counter, key)!=AddressBook::NoError)
00686   {
00687   kdDebug() << "TopLevelWidget::slotPrintEntries: cannot get entry at "
00688   << "index " << counter << "!" << endl;
00689   } else {
00690   bunch.push_back(key);
00691   }
00692   }
00693   printEntries(bunch);
00694   }
00695 
00696   void TopLevelWidget::slotPrintEntry()
00697   {
00698   KPrinter printer;
00699   QPainter painter;
00700   AddressBook::Entry entry;
00701   KABEntryPainter p(Qt::black, Qt::white, Qt::black,
00702   QFont("Utopia", 12, QFont::Normal, true),
00703   QFont("Utopia", 10, QFont::Bold, true),
00704   QFont("Utopia", 10, QFont::Normal, false),
00705   QFont("Helvetica", 10, QFont::Normal, false),
00706   QFont("Utopia", 8, QFont::Normal, false));
00707   // ----- variables used to define MINIMAL MARGINS entered by the user:
00708   int marginTop=0,
00709   marginLeft=64, // to allow stapling
00710   marginRight=0,
00711   marginBottom=0;
00712   register int left, top, width, height;
00713   // -----
00714   if(!printer.setup(this))
00715   {
00716   emit(setStatus(i18n("Rejected.")));
00717   KNotifyClient::beep();
00718   return;
00719   }
00720   // ----- create the metrics in accordance to the selection:
00721   printer.setFullPage(true); // use whole page
00722   QPaintDeviceMetrics metrics(&printer);
00723   kdDebug() << "TopLevelWidget::slotPrintEntry: printing on a "
00724   << metrics.width() << "x" << metrics.height()
00725   << " size area," << endl << "   "
00726   << "margins are "
00727   << printer.margins().width() << " (left/right) and "
00728   << printer.margins().height() << " (top/bottom)." << endl;
00729   left=QMAX(printer.margins().width(), marginLeft); // left margin
00730   top=QMAX(printer.margins().height(), marginTop); // top margin
00731   width=metrics.width()-left
00732   -QMAX(printer.margins().width(), marginRight); // page width
00733   height=metrics.height()-top
00734   -QMAX(printer.margins().height(), marginBottom); // page height
00735   // ----- get the current entry from the view:
00736   mainwidget->getView()->getEntry(entry);
00737   // ----- call the painting method:
00738   painter.begin(&printer);
00739   // ----- two per page:
00740   // painter.setViewport(left, top+height, height/2, width);
00741   // painter.rotate(270);
00742   // ----- four per page:
00743   // painter.setViewport(left, top, width/2, height/2);
00744   // one per page:
00745   painter.setViewport(left, top, width, height);
00746   if(p.printEntry(entry, QRect(0, 0, metrics.width(), metrics.height()),
00747   &painter, api, 0, false))
00748   {
00749   emit(setStatus(i18n("Printing finished.")));
00750   } else {
00751   emit(setStatus(i18n("Printing failed.")));
00752   }
00753   painter.end();
00754   }
00755 
00756 */
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:37 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001