00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "detailledstyle.h"
00025
00026 #include <QtGui/QCheckBox>
00027 #include <QtGui/QPainter>
00028 #include <QtGui/QPrinter>
00029
00030 #include <kapplication.h>
00031 #include <kcolorbutton.h>
00032 #include <kconfig.h>
00033 #include <kdebug.h>
00034 #include <kdialog.h>
00035 #include <kglobal.h>
00036 #include <kglobalsettings.h>
00037 #include <klocale.h>
00038 #include <knuminput.h>
00039 #include <kstandarddirs.h>
00040
00041 #include "ui_ds_appearance.h"
00042 #include "printingwizard.h"
00043 #include "printprogress.h"
00044 #include "printstyle.h"
00045
00046 using namespace KABPrinting;
00047
00048 const char *ConfigSectionName = "DetailedPrintStyle";
00049 const char *UseKDEFonts = "UseKDEFonts";
00050 const char *HeaderFont = "HeaderFont";
00051 const char *HeaderFontSize = "HeaderFontSize";
00052 const char *HeadlinesFont = "HeadlineFont";
00053 const char *HeadlinesFontSize = "HeadlineFontSize";
00054 const char *BodyFont = "BodyFont";
00055 const char *BodyFontSize = "BodyFontSize";
00056 const char *DetailsFont = "DetailsFont";
00057 const char *DetailsFontSize = "DetailsFontSize";
00058 const char *FixedFont = "FixedFont";
00059 const char *FixedFontSize = "FixedFontSize";
00060 const char *ColoredContactHeaders = "UseColoredContactHeaders";
00061 const char *ContactHeaderForeColor = "ContactHeaderForeColor";
00062 const char *ContactHeaderBGColor = "ContactHeaderBGColor";
00063
00064 class KABPrinting::AppearancePage : public QWidget, public Ui::AppearancePage_Base
00065 {
00066 public:
00067 AppearancePage( QWidget* parent ) : QWidget( parent )
00068 {
00069 setupUi( this );
00070 setObjectName( "AppearancePage" );
00071 }
00072 };
00073
00074 DetailledPrintStyle::DetailledPrintStyle( PrintingWizard *parent, const char *name )
00075 : PrintStyle( parent, name ),
00076 mPageAppearance( new AppearancePage( parent ) ),
00077 mPainter( 0 ),
00078 mPrintProgress( 0 )
00079 {
00080 QFont font;
00081 bool kdeFonts;
00082 QFont standard = KGlobalSettings::generalFont();
00083 QFont fixed = KGlobalSettings::fixedFont();
00084
00085 setPreview( "detailed-style.png" );
00086
00087 addPage( mPageAppearance, i18n( "Detailed Print Style - Appearance" ) );
00088
00089 KConfigGroup config(KGlobal::config(), ConfigSectionName );
00090
00091 kdeFonts = config.readEntry( UseKDEFonts, true );
00092 mPageAppearance->cbStandardFonts->setChecked( kdeFonts );
00093
00094 font = config.readEntry( HeaderFont, standard );
00095 mPageAppearance->kfcHeaderFont->setCurrentFont( font.family() );
00096 mPageAppearance->kisbHeaderFontSize->setValue( font.pointSize() );
00097
00098 font = config.readEntry( HeadlinesFont, standard );
00099 mPageAppearance->kfcHeadlineFont->setCurrentFont( font.family() );
00100 mPageAppearance->kisbHeadlineFontSize->setValue( font.pointSize() );
00101
00102 font = config.readEntry( BodyFont, standard );
00103 mPageAppearance->kfcBodyFont->setCurrentFont( font.family() );
00104 mPageAppearance->kisbBodyFontSize->setValue( font.pointSize() );
00105
00106 font = config.readEntry( DetailsFont, standard );
00107 mPageAppearance->kfcDetailsFont->setCurrentFont( font.family() );
00108 mPageAppearance->kisbDetailsFontSize->setValue( font.pointSize() );
00109
00110 font = config.readEntry( FixedFont, fixed );
00111 mPageAppearance->kfcFixedFont->setCurrentFont( font.family() );
00112 mPageAppearance->kisbFixedFontSize->setValue( font.pointSize() );
00113
00114 mPageAppearance->cbBackgroundColor->setChecked(
00115 config.readEntry( ColoredContactHeaders, true ) );
00116 QColor col(Qt::black);
00117 mPageAppearance->kcbHeaderBGColor->setColor(
00118 config.readEntry( ContactHeaderBGColor, col ) );
00119 col = QColor(Qt::white);
00120 mPageAppearance->kcbHeaderTextColor->setColor(
00121 config.readEntry( ContactHeaderForeColor, col ) );
00122
00123 mPageAppearance->layout()->setMargin( KDialog::marginHint() );
00124 mPageAppearance->layout()->setSpacing( KDialog::spacingHint() );
00125 }
00126
00127 DetailledPrintStyle::~DetailledPrintStyle()
00128 {
00129 delete mPainter;
00130 mPainter = 0;
00131 }
00132
00133 void DetailledPrintStyle::print( const KABC::Addressee::List &contacts, PrintProgress *progress )
00134 {
00135 mPrintProgress = progress;
00136
00137 progress->addMessage( i18n( "Setting up fonts and colors" ) );
00138 progress->setProgress( 0 );
00139
00140 bool useKDEFonts;
00141 QFont font;
00142 QColor foreColor = Qt::black;
00143 QColor headerColor = Qt::white;
00144 bool useHeaderColor = true;
00145 QColor backColor = Qt::black;
00146 bool useBGColor;
00147
00148
00149 QFont header = QFont("Helvetica", 12, QFont::Normal);
00150 QFont headlines = QFont("Helvetica", 12, QFont::Normal, true);
00151 QFont body = QFont("Helvetica", 12, QFont::Normal);
00152 QFont fixed = QFont("Courier", 12, QFont::Normal);
00153 QFont comment = QFont("Helvetica", 10, QFont::Normal);
00154
00155
00156 KConfigGroup config = KGlobal::config()->group(ConfigSectionName);
00157 useKDEFonts = mPageAppearance->cbStandardFonts->isChecked();
00158 config.writeEntry( UseKDEFonts, useKDEFonts );
00159
00160
00161 useBGColor=mPageAppearance->cbBackgroundColor->isChecked();
00162 config.writeEntry( ColoredContactHeaders, useBGColor );
00163
00164
00165 if ( useBGColor ) {
00166 headerColor = mPageAppearance->kcbHeaderTextColor->color();
00167 backColor = mPageAppearance->kcbHeaderBGColor->color();
00168 config.writeEntry( ContactHeaderForeColor, headerColor );
00169 config.writeEntry( ContactHeaderBGColor, backColor );
00170 }
00171
00172 if ( mPageAppearance->cbStandardFonts->isChecked() ) {
00173 QFont standard = KGlobalSettings::generalFont();
00174 header = standard;
00175 headlines = standard;
00176 body = standard;
00177 fixed = KGlobalSettings::fixedFont();
00178 comment = standard;
00179 } else {
00180 header.setFamily( mPageAppearance->kfcHeaderFont->currentText() );
00181 header.setPointSize( mPageAppearance->kisbHeaderFontSize->value() );
00182 config.writeEntry( HeaderFont, header );
00183
00184
00185 headlines.setFamily( mPageAppearance->kfcHeadlineFont->currentText() );
00186 headlines.setPointSize( mPageAppearance->kisbHeadlineFontSize->value() );
00187 config.writeEntry( HeadlinesFont, headlines );
00188
00189
00190 body.setFamily( mPageAppearance->kfcBodyFont->currentText() );
00191 body.setPointSize( mPageAppearance->kisbBodyFontSize->value() );
00192 config.writeEntry( BodyFont, body );
00193
00194
00195 comment.setFamily( mPageAppearance->kfcDetailsFont->currentText() );
00196 comment.setPointSize( mPageAppearance->kisbDetailsFontSize->value() );
00197 config.writeEntry( DetailsFont, comment );
00198
00199
00200 fixed.setFamily( mPageAppearance->kfcFixedFont->currentText() );
00201 fixed.setPointSize( mPageAppearance->kisbFixedFontSize->value() );
00202 config.writeEntry( FixedFont, fixed );
00203 }
00204
00205 mPainter = new KABEntryPainter;
00206 mPainter->setForegroundColor( foreColor );
00207 mPainter->setHeaderColor( headerColor );
00208 mPainter->setBackgroundColor( backColor );
00209 mPainter->setUseHeaderColor( useHeaderColor );
00210 mPainter->setHeaderFont( header );
00211 mPainter->setHeadLineFont( headlines );
00212 mPainter->setBodyFont( body );
00213 mPainter->setFixedFont( fixed );
00214 mPainter->setCommentFont( comment );
00215
00216 QPrinter *printer = wizard()->printer();
00217
00218 QPainter painter;
00219 progress->addMessage( i18n( "Setting up margins and spacing" ) );
00220 int marginTop = 0,
00221 marginLeft = 64,
00222 marginRight = 0,
00223 marginBottom = 0;
00224
00225 register int left, top, width, height;
00226
00227 painter.begin( printer );
00228 printer->setFullPage( true );
00229
00230
00231 left = qMax( printer->paperRect().left() - printer->pageRect().left(), marginLeft );
00232 top = qMax( printer->paperRect().top() - printer->pageRect().top(), marginTop );
00233 width = printer->width() - left - qMax( printer->paperRect().right() - printer->pageRect().right(), marginRight );
00234 height = printer->height() - top - qMax( printer->paperRect().bottom() - printer->pageRect().bottom(), marginBottom );
00235
00236 painter.setViewport( left, top, width, height );
00237 progress->addMessage( i18n( "Printing" ) );
00238
00239 printEntries( contacts, printer, &painter,
00240 QRect( 0, 0, printer->width(), printer->height() ) );
00241
00242 progress->addMessage( i18n( "Done" ) );
00243 painter.end();
00244
00245 config.sync();
00246 }
00247
00248 bool DetailledPrintStyle::printEntries( const KABC::Addressee::List &contacts,
00249 QPrinter *printer,
00250 QPainter *painter,
00251 const QRect &window)
00252 {
00253 QRect brect;
00254 int ypos = 0, count = 0;
00255
00256 KABC::Addressee::List::ConstIterator it;
00257 for ( it = contacts.begin(); it != contacts.end(); ++it ) {
00258 if ( !(*it).isEmpty() ) {
00259
00260 if ( !mPainter->printAddressee( *it, window, painter, ypos, true, &brect) ) {
00261
00262 printer->newPage();
00263
00264
00265
00266 ypos = 0;
00267 }
00268
00269 mPainter->printAddressee( *it, window, painter, ypos, false, &brect );
00270 ypos += brect.height();
00271 }
00272
00273 mPrintProgress->setProgress( (count++ * 100) / contacts.count() );
00274 }
00275
00276 mPrintProgress->setProgress( 100 );
00277
00278 return true;
00279 }
00280
00281 DetailledPrintStyleFactory::DetailledPrintStyleFactory( PrintingWizard *parent,
00282 const char *name )
00283 : PrintStyleFactory( parent, name )
00284 {
00285 }
00286
00287 PrintStyle *DetailledPrintStyleFactory::create() const
00288 {
00289 return new DetailledPrintStyle( mParent, mName );
00290 }
00291
00292 QString DetailledPrintStyleFactory::description() const
00293 {
00294 return i18n( "Detailed Style" );
00295 }
00296
00297 #include "detailledstyle.moc"