kaddressbook Library API Documentation

detailledstyle.cpp

00001 /* 00002 This file is part of KAddressBook. 00003 Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of Qt, and distribute the resulting executable, 00021 without including the source code for Qt in the source distribution. 00022 */ 00023 00024 #include <kdebug.h> 00025 #include <kapplication.h> 00026 #include <kstandarddirs.h> 00027 #include <kcolorbutton.h> 00028 #include <klocale.h> 00029 #include <kprinter.h> 00030 #include <kfontcombo.h> 00031 #include <kglobalsettings.h> 00032 #include <knuminput.h> 00033 #include <kdialog.h> 00034 #include <kconfig.h> 00035 #include <qpainter.h> 00036 #include <qcheckbox.h> 00037 #include <qlayout.h> 00038 #include <qpaintdevicemetrics.h> 00039 00040 #include "detailledstyle.h" 00041 #include "printingwizard.h" 00042 #include "printstyle.h" 00043 #include "printprogress.h" 00044 00045 // ----- the wizard pages: 00046 #include "ds_appearance.h" 00047 00048 namespace KABPrinting { 00049 00050 const char* ConfigSectionName="DetailedPrintStyle"; 00051 const char* UseKDEFonts="UseKDEFonts"; 00052 const char* HeaderFont="HeaderFont"; 00053 const char* HeaderFontSize="HeaderFontSize"; 00054 const char* HeadlinesFont="HeadlineFont"; 00055 const char* HeadlinesFontSize="HeadlineFontSize"; 00056 const char* BodyFont="BodyFont"; 00057 const char* BodyFontSize="BodyFontSize"; 00058 const char* DetailsFont="DetailsFont"; 00059 const char* DetailsFontSize="DetailsFontSize"; 00060 const char* FixedFont="FixedFont"; 00061 const char* FixedFontSize="FixedFontSize"; 00062 const char* ColoredContactHeaders="UseColoredContactHeaders"; 00063 const char* ContactHeaderForeColor="ContactHeaderForeColor"; 00064 const char* ContactHeaderBGColor="ContactHeaderBGColor"; 00065 00066 00067 DetailledPrintStyle::DetailledPrintStyle(PrintingWizard* parent, 00068 const char* name) 00069 : PrintStyle(parent, name), 00070 mPageAppearance(new AppearancePage(parent, "AppearancePage")), 00071 mEPntr(0), 00072 mPrintProgress(0) 00073 { 00074 KConfig *config; 00075 QFont font; 00076 bool kdeFonts; 00077 QFont standard=KGlobalSettings::generalFont(); 00078 QFont fixed=KGlobalSettings::fixedFont(); 00079 00080 setPreview( "detailed-style.png" ); 00081 00082 addPage( mPageAppearance, i18n( "Detailed Print Style - Appearance" ) ); 00083 // ----- set some values in the pages: 00084 // ----- now try to load previous settings from the 00085 // configuration file and set the UI items accordingly: 00086 config=kapp->config(); 00087 config->setGroup(ConfigSectionName); 00088 // use KDE fonts box: 00089 kdeFonts=config->readBoolEntry(UseKDEFonts, true); 00090 mPageAppearance->cbStandardFonts->setChecked(kdeFonts); 00091 // header font: 00092 font=config->readFontEntry(HeaderFont, &standard); 00093 mPageAppearance->kfcHeaderFont->setCurrentFont(font.family()); 00094 mPageAppearance->kisbHeaderFontSize->setValue(font.pointSize()); 00095 font=config->readFontEntry(HeadlinesFont, &standard); 00096 mPageAppearance->kfcHeadlineFont->setCurrentFont(font.family()); 00097 mPageAppearance->kisbHeadlineFontSize->setValue(font.pointSize()); 00098 font=config->readFontEntry(BodyFont, &standard); 00099 mPageAppearance->kfcBodyFont->setCurrentFont(font.family()); 00100 mPageAppearance->kisbBodyFontSize->setValue(font.pointSize()); 00101 font=config->readFontEntry(DetailsFont, &standard); 00102 mPageAppearance->kfcDetailsFont->setCurrentFont(font.family()); 00103 mPageAppearance->kisbDetailsFontSize->setValue(font.pointSize()); 00104 font=config->readFontEntry(FixedFont, &fixed); 00105 mPageAppearance->kfcFixedFont->setCurrentFont(font.family()); 00106 mPageAppearance->kisbFixedFontSize->setValue(font.pointSize()); 00107 // ----- contact header design: 00108 mPageAppearance->cbBackgroundColor 00109 ->setChecked(config->readBoolEntry(ColoredContactHeaders, true)); 00110 mPageAppearance->kcbHeaderBGColor 00111 ->setColor(config->readColorEntry(ContactHeaderBGColor, &Qt::black)); 00112 mPageAppearance->kcbHeaderTextColor 00113 ->setColor(config->readColorEntry(ContactHeaderForeColor, &Qt::white)); 00114 // ----- work around Qt Designer's fixed widget spacing: 00115 mPageAppearance->layout()->setMargin(KDialog::marginHint()); 00116 mPageAppearance->layout()->setSpacing(KDialog::spacingHint()); 00117 // ----- enable finish in our page: 00118 } 00119 00120 DetailledPrintStyle::~DetailledPrintStyle() 00121 { 00122 if( mEPntr != 0 ) 00123 delete mEPntr; 00124 mEPntr = 0; 00125 } 00126 00127 void DetailledPrintStyle::print( KABC::Addressee::List &contacts, PrintProgress *progress) 00128 { 00129 mPrintProgress=progress; 00130 progress->addMessage(i18n("Setting up fonts and colors")); 00131 progress->setProgress(0); 00132 bool useKDEFonts; 00133 KConfig *config; 00134 QFont font; 00135 QColor foreColor=Qt::black; 00136 QColor headerColor=Qt::white; 00137 bool useHeaderColor=true; 00138 QColor backColor=Qt::black; 00139 bool useBGColor; 00140 // save, always available defaults: 00141 QFont header=QFont("Helvetica", 12, QFont::Normal); 00142 QFont headlines=QFont("Helvetica", 12, QFont::Normal, true); 00143 QFont body=QFont("Helvetica", 12, QFont::Normal); 00144 QFont fixed=QFont("Courier", 12, QFont::Normal); 00145 QFont comment=QFont("Helvetica", 10, QFont::Normal); 00146 // ----- store the configuration settings: 00147 config=kapp->config(); 00148 config->setGroup(ConfigSectionName); 00149 useKDEFonts=mPageAppearance->cbStandardFonts->isChecked(); 00150 config->writeEntry(UseKDEFonts, useKDEFonts); 00151 // ----- read the font and color selections from the wizard pages: 00152 useBGColor=mPageAppearance->cbBackgroundColor->isChecked(); 00153 config->writeEntry(ColoredContactHeaders, useBGColor); 00154 if(useBGColor) 00155 { // use colored contact headers, otherwise use plain black and white): 00156 headerColor=mPageAppearance->kcbHeaderTextColor->color(); 00157 backColor=mPageAppearance->kcbHeaderBGColor->color(); 00158 config->writeEntry(ContactHeaderForeColor, headerColor); 00159 config->writeEntry(ContactHeaderBGColor, backColor); 00160 } 00161 if(mPageAppearance->cbStandardFonts->isChecked()) 00162 { 00163 QFont standard=KGlobalSettings::generalFont(); 00164 header=standard; 00165 headlines=standard; 00166 body=standard; 00167 fixed=KGlobalSettings::fixedFont(); 00168 comment=standard; 00169 } else { 00170 // ----- get header font settings and save for later 00171 // sessions: 00172 header.setFamily(mPageAppearance->kfcHeaderFont->currentText()); 00173 header.setPointSize(mPageAppearance->kisbHeaderFontSize->value()); 00174 config->writeEntry(HeaderFont, header); 00175 // ----- headlines: 00176 headlines.setFamily(mPageAppearance->kfcHeadlineFont->currentText()); 00177 headlines.setPointSize(mPageAppearance->kisbHeadlineFontSize->value()); 00178 config->writeEntry(HeadlinesFont, headlines); 00179 // ----- body: 00180 body.setFamily(mPageAppearance->kfcBodyFont->currentText()); 00181 body.setPointSize(mPageAppearance->kisbBodyFontSize->value()); 00182 config->writeEntry(BodyFont, body); 00183 // ----- details: 00184 comment.setFamily(mPageAppearance->kfcDetailsFont->currentText()); 00185 comment.setPointSize(mPageAppearance->kisbDetailsFontSize->value()); 00186 config->writeEntry(DetailsFont, comment); 00187 // ----- fixed: 00188 fixed.setFamily(mPageAppearance->kfcFixedFont->currentText()); 00189 fixed.setPointSize(mPageAppearance->kisbFixedFontSize->value()); 00190 config->writeEntry(FixedFont, fixed); 00191 } 00192 kdDebug(5720) << "DetailledPrintStyle::print: printing using" << endl 00193 << " header: " << header.family() << "(" 00194 << header.pointSize() << ")" << endl 00195 << " headline: " << headlines.family() << "(" 00196 << headlines.pointSize() << ")" << endl 00197 << " body: " << body.family() << "(" 00198 << body.pointSize() << ")" << endl 00199 << " fixed: " << fixed.family() << "(" 00200 << fixed.pointSize() << ")" << endl 00201 << " comment: " << comment.family() << "(" 00202 << comment.pointSize() << ")" << endl; 00203 00204 mEPntr = new KABEntryPainter; 00205 mEPntr->setForegroundColor( foreColor ); 00206 mEPntr->setHeaderColor( headerColor ); 00207 mEPntr->setBackgroundColor( backColor ); 00208 mEPntr->setUseHeaderColor( useHeaderColor ); 00209 mEPntr->setHeaderFont( header ); 00210 mEPntr->setHeadLineFont( headlines ); 00211 mEPntr->setBodyFont( body ); 00212 mEPntr->setFixedFont( fixed ); 00213 mEPntr->setCommentFont( comment ); 00214 00215 KPrinter *printer=wizard()->printer(); 00216 QPainter painter; 00217 // ----- variables used to define MINIMAL MARGINS entered by the user: 00218 progress->addMessage(i18n("Setting up margins and spacing")); 00219 int marginTop=0, 00220 marginLeft=64, // to allow stapling, need refinement with two-side prints 00221 marginRight=0, 00222 marginBottom=0; 00223 register int left, top, width, height; 00224 // ----- we expect the printer to be set up (it is, before the wizard is started): 00225 painter.begin(printer); 00226 printer->setFullPage(true); // use whole page 00227 QPaintDeviceMetrics metrics(printer); 00228 kdDebug(5720) << "DetailledPrintStyle::print: printing on a " 00229 << metrics.width() << "x" << metrics.height() 00230 << " size area," << endl << " " 00231 << "margins are " 00232 << printer->margins().width() << " (left/right) and " 00233 << printer->margins().height() << " (top/bottom)." << endl; 00234 left=QMAX(printer->margins().width(), marginLeft); // left margin 00235 top=QMAX(printer->margins().height(), marginTop); // top margin 00236 width=metrics.width()-left 00237 -QMAX(printer->margins().width(), marginRight); // page width 00238 height=metrics.height()-top 00239 -QMAX(printer->margins().height(), marginBottom); // page height 00240 // ----- now do the printing: 00241 // this prepares for, like, two-up etc: 00242 painter.setViewport(left, top, width, height); 00243 progress->addMessage(i18n("Printing")); 00244 printEntries(contacts, printer, &painter, 00245 QRect(0, 0, metrics.width(), metrics.height())); 00246 progress->addMessage(i18n("Done")); 00247 painter.end(); 00248 config->sync(); 00249 } 00250 00251 bool DetailledPrintStyle::printEntries( KABC::Addressee::List &contacts, 00252 KPrinter *printer, 00253 QPainter *painter, 00254 const QRect& window) 00255 { 00256 QRect brect; 00257 int ypos=0, count=0; 00258 00259 // ----- 00260 KABC::Addressee::List::Iterator it; 00261 for ( it = contacts.begin(); it != contacts.end(); ++it ) 00262 { 00263 if( !(*it).isEmpty()) 00264 { // print it: 00265 kdDebug(5720) << "DetailledPrintStyle::printEntries: printing addressee " 00266 << (*it).realName() << endl; 00267 // ----- do a faked print to get the bounding rect: 00268 if(!mEPntr->printAddressee((*it), window, painter, ypos, true, &brect)) 00269 { // it does not fit on the page beginning at ypos: 00270 printer->newPage(); 00271 // WORK_TO_DO: this assumes the entry fits on the whole page 00272 // (dunno how to fix this without being illogical) 00273 ypos=0; 00274 } 00275 mEPntr->printAddressee((*it), window, painter, ypos, false, &brect); 00276 ypos+=brect.height(); 00277 } else { 00278 kdDebug(5720) << "DetailledPrintStyle::printEntries: strange, addressee " 00279 << "with UID " << (*it).uid() << " not available." << endl; 00280 } 00281 // ----- set progress: 00282 mPrintProgress->setProgress((count++*100)/contacts.count()); 00283 } 00284 mPrintProgress->setProgress(100); 00285 return true; 00286 } 00287 00288 DetailledPrintStyleFactory::DetailledPrintStyleFactory( 00289 PrintingWizard* parent, 00290 const char* name) 00291 : PrintStyleFactory(parent, name) 00292 { 00293 } 00294 00295 00296 PrintStyle *DetailledPrintStyleFactory::create() 00297 { 00298 return new DetailledPrintStyle( mParent, mName ); 00299 } 00300 00301 QString DetailledPrintStyleFactory::description() 00302 { 00303 return i18n("Detailed Style"); 00304 } 00305 00306 } 00307 00308 #include "detailledstyle.moc"
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:19:04 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003