diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch) | |
tree | 67208f7c145782a7e90b123b982ca78d88cc2c87 /kaddressbook/printing | |
download | tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kaddressbook/printing')
23 files changed, 3279 insertions, 0 deletions
diff --git a/kaddressbook/printing/Makefile.am b/kaddressbook/printing/Makefile.am new file mode 100644 index 000000000..86e7d2793 --- /dev/null +++ b/kaddressbook/printing/Makefile.am @@ -0,0 +1,32 @@ +INCLUDES = -I$(top_srcdir) -I$(top_builddir)/kaddressbook -I$(top_srcdir)/kaddressbook \ + -I$(top_srcdir)/kaddressbook/details -I$(top_srcdir)/kaddressbook/common \ + -I$(top_builddir)/kaddressbook/common $(all_includes) + +noinst_LTLIBRARIES = libprinter.la + +libprinter_la_SOURCES = \ + detailledstyle.cpp \ + ds_appearance.ui \ + kabentrypainter.cpp \ + mikesstyle.cpp \ + printingwizard.cpp \ + printprogress.cpp \ + printstyle.cpp \ + selectionpage.cpp \ + stylepage.cpp \ + printsortmode.cpp +libprinter_la_COMPILE_FIRST = $(top_builddir)/kaddressbook/common/kabprefs_base.h + +EXTRA_DIST = \ + detailledstyle.cpp detailledstyle.h kabentrypainter.h \ + mikesstyle.cpp mikesstyle.h \ + printingwizard.cpp printingwizard.h \ + printprogress.cpp printprogress.h \ + printstyle.cpp printstyle.h rbs_appearance.ui.h \ + selectionpage.cpp selectionpage.h \ + stylepage.cpp stylepage.h + +libprinter_la_METASOURCES = AUTO + +previewdir = $(kde_datadir)/kaddressbook/printing +preview_DATA = detailed-style.png mike-style.png diff --git a/kaddressbook/printing/README b/kaddressbook/printing/README new file mode 100644 index 000000000..0c8951e18 --- /dev/null +++ b/kaddressbook/printing/README @@ -0,0 +1,15 @@ +This subdircetory implements the printing wizard that handles the +different styles of printing provided by kaddressbook. To see how +printing is handled, see printingwizard.h. See kaddressbookprinting.h +in the kaddressbook main directory, too. + +Have a look at printstyle.h if you want to create your own print +style. + +Files starting with ds_ are part of the detailed print style +implementation. + +----- +Feel free to add you comments here. + +--Mirko Boehm. diff --git a/kaddressbook/printing/detailed-style.png b/kaddressbook/printing/detailed-style.png Binary files differnew file mode 100644 index 000000000..c93602d4e --- /dev/null +++ b/kaddressbook/printing/detailed-style.png diff --git a/kaddressbook/printing/detailledstyle.cpp b/kaddressbook/printing/detailledstyle.cpp new file mode 100644 index 000000000..78283a080 --- /dev/null +++ b/kaddressbook/printing/detailledstyle.cpp @@ -0,0 +1,291 @@ +/* + This file is part of KAddressBook. + Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include <kapplication.h> +#include <qcheckbox.h> +#include <kcolorbutton.h> +#include <kconfig.h> +#include <kdebug.h> +#include <kdialog.h> +#include <kfontcombo.h> +#include <kglobalsettings.h> +#include <qlayout.h> +#include <klocale.h> +#include <knuminput.h> +#include <qpaintdevicemetrics.h> +#include <qpainter.h> +#include <kprinter.h> +#include <kstandarddirs.h> + +#include "ds_appearance.h" +#include "printingwizard.h" +#include "printprogress.h" +#include "printstyle.h" + +#include "detailledstyle.h" + +using namespace KABPrinting; + +const char *ConfigSectionName = "DetailedPrintStyle"; +const char *UseKDEFonts = "UseKDEFonts"; +const char *HeaderFont = "HeaderFont"; +const char *HeaderFontSize = "HeaderFontSize"; +const char *HeadlinesFont = "HeadlineFont"; +const char *HeadlinesFontSize = "HeadlineFontSize"; +const char *BodyFont = "BodyFont"; +const char *BodyFontSize = "BodyFontSize"; +const char *DetailsFont = "DetailsFont"; +const char *DetailsFontSize = "DetailsFontSize"; +const char *FixedFont = "FixedFont"; +const char *FixedFontSize = "FixedFontSize"; +const char *ColoredContactHeaders = "UseColoredContactHeaders"; +const char *ContactHeaderForeColor = "ContactHeaderForeColor"; +const char *ContactHeaderBGColor = "ContactHeaderBGColor"; + + +DetailledPrintStyle::DetailledPrintStyle( PrintingWizard *parent, const char *name ) + : PrintStyle( parent, name ), + mPageAppearance( new AppearancePage( parent, "AppearancePage" ) ), + mPainter( 0 ), + mPrintProgress( 0 ) +{ + KConfig *config; + QFont font; + bool kdeFonts; + QFont standard = KGlobalSettings::generalFont(); + QFont fixed = KGlobalSettings::fixedFont(); + + setPreview( "detailed-style.png" ); + + addPage( mPageAppearance, i18n( "Detailed Print Style - Appearance" ) ); + + config = kapp->config(); + config->setGroup( ConfigSectionName ); + + kdeFonts = config->readBoolEntry( UseKDEFonts, true ); + mPageAppearance->cbStandardFonts->setChecked( kdeFonts ); + + font = config->readFontEntry( HeaderFont, &standard ); + mPageAppearance->kfcHeaderFont->setCurrentFont( font.family() ); + mPageAppearance->kisbHeaderFontSize->setValue( font.pointSize() ); + + font = config->readFontEntry( HeadlinesFont, &standard ); + mPageAppearance->kfcHeadlineFont->setCurrentFont( font.family() ); + mPageAppearance->kisbHeadlineFontSize->setValue( font.pointSize() ); + + font = config->readFontEntry( BodyFont, &standard ); + mPageAppearance->kfcBodyFont->setCurrentFont( font.family() ); + mPageAppearance->kisbBodyFontSize->setValue( font.pointSize() ); + + font = config->readFontEntry( DetailsFont, &standard ); + mPageAppearance->kfcDetailsFont->setCurrentFont( font.family() ); + mPageAppearance->kisbDetailsFontSize->setValue( font.pointSize() ); + + font = config->readFontEntry( FixedFont, &fixed ); + mPageAppearance->kfcFixedFont->setCurrentFont( font.family() ); + mPageAppearance->kisbFixedFontSize->setValue( font.pointSize() ); + + mPageAppearance->cbBackgroundColor->setChecked( + config->readBoolEntry( ColoredContactHeaders, true ) ); + mPageAppearance->kcbHeaderBGColor->setColor( + config->readColorEntry( ContactHeaderBGColor, &Qt::black ) ); + mPageAppearance->kcbHeaderTextColor->setColor( + config->readColorEntry( ContactHeaderForeColor, &Qt::white ) ); + + mPageAppearance->layout()->setMargin( KDialog::marginHint() ); + mPageAppearance->layout()->setSpacing( KDialog::spacingHint() ); +} + +DetailledPrintStyle::~DetailledPrintStyle() +{ + delete mPainter; + mPainter = 0; +} + +void DetailledPrintStyle::print( const KABC::Addressee::List &contacts, PrintProgress *progress ) +{ + mPrintProgress = progress; + + progress->addMessage( i18n( "Setting up fonts and colors" ) ); + progress->setProgress( 0 ); + + bool useKDEFonts; + QFont font; + QColor foreColor = Qt::black; + QColor headerColor = Qt::white; + bool useHeaderColor = true; + QColor backColor = Qt::black; + bool useBGColor; + + // save, always available defaults: + QFont header = QFont("Helvetica", 12, QFont::Normal); + QFont headlines = QFont("Helvetica", 12, QFont::Normal, true); + QFont body = QFont("Helvetica", 12, QFont::Normal); + QFont fixed = QFont("Courier", 12, QFont::Normal); + QFont comment = QFont("Helvetica", 10, QFont::Normal); + + // store the configuration settings: + KConfig *config = kapp->config(); + config->setGroup( ConfigSectionName ); + useKDEFonts = mPageAppearance->cbStandardFonts->isChecked(); + config->writeEntry( UseKDEFonts, useKDEFonts ); + + // read the font and color selections from the wizard pages: + useBGColor=mPageAppearance->cbBackgroundColor->isChecked(); + config->writeEntry( ColoredContactHeaders, useBGColor ); + + // use colored contact headers, otherwise use plain black and white): + if ( useBGColor ) { + headerColor = mPageAppearance->kcbHeaderTextColor->color(); + backColor = mPageAppearance->kcbHeaderBGColor->color(); + config->writeEntry( ContactHeaderForeColor, headerColor ); + config->writeEntry( ContactHeaderBGColor, backColor ); + } + + if ( mPageAppearance->cbStandardFonts->isChecked() ) { + QFont standard = KGlobalSettings::generalFont(); + header = standard; + headlines = standard; + body = standard; + fixed = KGlobalSettings::fixedFont(); + comment = standard; + } else { + header.setFamily( mPageAppearance->kfcHeaderFont->currentText() ); + header.setPointSize( mPageAppearance->kisbHeaderFontSize->value() ); + config->writeEntry( HeaderFont, header ); + + // headlines: + headlines.setFamily( mPageAppearance->kfcHeadlineFont->currentText() ); + headlines.setPointSize( mPageAppearance->kisbHeadlineFontSize->value() ); + config->writeEntry( HeadlinesFont, headlines ); + + // body: + body.setFamily( mPageAppearance->kfcBodyFont->currentText() ); + body.setPointSize( mPageAppearance->kisbBodyFontSize->value() ); + config->writeEntry( BodyFont, body ); + + // details: + comment.setFamily( mPageAppearance->kfcDetailsFont->currentText() ); + comment.setPointSize( mPageAppearance->kisbDetailsFontSize->value() ); + config->writeEntry( DetailsFont, comment ); + + // fixed: + fixed.setFamily( mPageAppearance->kfcFixedFont->currentText() ); + fixed.setPointSize( mPageAppearance->kisbFixedFontSize->value() ); + config->writeEntry( FixedFont, fixed ); + } + + mPainter = new KABEntryPainter; + mPainter->setForegroundColor( foreColor ); + mPainter->setHeaderColor( headerColor ); + mPainter->setBackgroundColor( backColor ); + mPainter->setUseHeaderColor( useHeaderColor ); + mPainter->setHeaderFont( header ); + mPainter->setHeadLineFont( headlines ); + mPainter->setBodyFont( body ); + mPainter->setFixedFont( fixed ); + mPainter->setCommentFont( comment ); + + KPrinter *printer = wizard()->printer(); + + QPainter painter; + progress->addMessage( i18n( "Setting up margins and spacing" ) ); + int marginTop = 0, + marginLeft = 64, // to allow stapling, need refinement with two-side prints + marginRight = 0, + marginBottom = 0; + + register int left, top, width, height; + + painter.begin( printer ); + printer->setFullPage( true ); // use whole page + + QPaintDeviceMetrics metrics( printer ); + + left = QMAX( printer->margins().width(), marginLeft ); + top = QMAX( printer->margins().height(), marginTop ); + width = metrics.width() - left - QMAX( printer->margins().width(), marginRight ); + height = metrics.height() - top - QMAX( printer->margins().height(), marginBottom ); + + painter.setViewport( left, top, width, height ); + progress->addMessage( i18n( "Printing" ) ); + + printEntries( contacts, printer, &painter, + QRect( 0, 0, metrics.width(), metrics.height() ) ); + + progress->addMessage( i18n( "Done" ) ); + painter.end(); + + config->sync(); +} + +bool DetailledPrintStyle::printEntries( const KABC::Addressee::List &contacts, + KPrinter *printer, + QPainter *painter, + const QRect &window) +{ + QRect brect; + int ypos = 0, count = 0; + + KABC::Addressee::List::ConstIterator it; + for ( it = contacts.begin(); it != contacts.end(); ++it ) { + if ( !(*it).isEmpty() ) { + // do a faked print to get the bounding rect: + if ( !mPainter->printAddressee( *it, window, painter, ypos, true, &brect) ) { + // it does not fit on the page beginning at ypos: + printer->newPage(); + + // WORK_TO_DO: this assumes the entry fits on the whole page + // (dunno how to fix this without being illogical) + ypos = 0; + } + + mPainter->printAddressee( *it, window, painter, ypos, false, &brect ); + ypos += brect.height(); + } + + mPrintProgress->setProgress( (count++ * 100) / contacts.count() ); + } + + mPrintProgress->setProgress( 100 ); + + return true; +} + +DetailledPrintStyleFactory::DetailledPrintStyleFactory( PrintingWizard *parent, + const char *name ) + : PrintStyleFactory( parent, name ) +{ +} + +PrintStyle *DetailledPrintStyleFactory::create() const +{ + return new DetailledPrintStyle( mParent, mName ); +} + +QString DetailledPrintStyleFactory::description() const +{ + return i18n( "Detailed Style" ); +} + +#include "detailledstyle.moc" diff --git a/kaddressbook/printing/detailledstyle.h b/kaddressbook/printing/detailledstyle.h new file mode 100644 index 000000000..91c6dfe19 --- /dev/null +++ b/kaddressbook/printing/detailledstyle.h @@ -0,0 +1,68 @@ +/* + This file is part of KAddressBook. + Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#ifndef DETAILLEDSTYLE_H +#define DETAILLEDSTYLE_H + +#include <kabc/addressee.h> + +#include "printstyle.h" +#include "kabentrypainter.h" + +class AppearancePage; + +namespace KABPrinting { + +class DetailledPrintStyle : public PrintStyle +{ + Q_OBJECT + + public: + DetailledPrintStyle( PrintingWizard *parent, const char *name = 0 ); + ~DetailledPrintStyle(); + + void print( const KABC::Addressee::List &contacts, PrintProgress* ); + + protected: + bool printEntries( const KABC::Addressee::List &contacts, KPrinter *printer, + QPainter *painter, const QRect &window ); + bool printEntry( const KABC::Addressee &contact, const QRect &window, + QPainter *painter, int top, bool fake, QRect *brect ); + private: + AppearancePage *mPageAppearance; + KABEntryPainter *mPainter; + PrintProgress *mPrintProgress; +}; + +class DetailledPrintStyleFactory : public PrintStyleFactory +{ + public: + DetailledPrintStyleFactory( PrintingWizard *parent, const char *name = 0 ); + + PrintStyle *create() const; + QString description() const; +}; + +} + +#endif diff --git a/kaddressbook/printing/ds_appearance.ui b/kaddressbook/printing/ds_appearance.ui new file mode 100644 index 000000000..2fe5ce208 --- /dev/null +++ b/kaddressbook/printing/ds_appearance.ui @@ -0,0 +1,479 @@ +<!DOCTYPE UI><UI version="3.0" stdsetdef="1"> +<class>AppearancePage</class> +<widget class="QWidget"> + <property name="name"> + <cstring>AppearancePage</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>597</width> + <height>437</height> + </rect> + </property> + <property name="caption"> + <string>Appearance Page</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>labelHeader</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="paletteForegroundColor"> + <color> + <red>0</red> + <green>0</green> + <blue>90</blue> + </color> + </property> + <property name="paletteBackgroundColor"> + <color> + <red>255</red> + <green>170</green> + <blue>127</blue> + </color> + </property> + <property name="font"> + <font> + <bold>1</bold> + </font> + </property> + <property name="frameShape"> + <enum>Panel</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="text"> + <string>Detailed Print Style - Appearance</string> + </property> + <property name="scaledContents"> + <bool>false</bool> + </property> + <property name="alignment"> + <set>AlignVCenter|AlignLeft</set> + </property> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>gbFont</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>3</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Font Settings</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QCheckBox"> + <property name="name"> + <cstring>cbStandardFonts</cstring> + </property> + <property name="text"> + <string>Use standard KDE fonts</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + <widget class="QFrame"> + <property name="name"> + <cstring>frameFonts</cstring> + </property> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>labelDetailsFont</cstring> + </property> + <property name="text"> + <string>Details font:</string> + </property> + <property name="alignment"> + <set>AlignVCenter|AlignRight</set> + </property> + </widget> + <widget class="QLabel" row="3" column="2"> + <property name="name"> + <cstring>labelDetailsFontSize</cstring> + </property> + <property name="text"> + <string>Size:</string> + </property> + <property name="alignment"> + <set>AlignVCenter|AlignRight</set> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>labelBodyFont</cstring> + </property> + <property name="text"> + <string>Body font:</string> + </property> + <property name="alignment"> + <set>AlignVCenter|AlignRight</set> + </property> + </widget> + <widget class="QLabel" row="4" column="2"> + <property name="name"> + <cstring>labelFixedFontSize</cstring> + </property> + <property name="text"> + <string>Size:</string> + </property> + <property name="alignment"> + <set>AlignVCenter|AlignRight</set> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>labelFixed</cstring> + </property> + <property name="text"> + <string>Fixed font:</string> + </property> + <property name="alignment"> + <set>AlignVCenter|AlignRight</set> + </property> + </widget> + <widget class="KIntSpinBox" row="3" column="3"> + <property name="name"> + <cstring>kisbDetailsFontSize</cstring> + </property> + </widget> + <widget class="KIntSpinBox" row="4" column="3"> + <property name="name"> + <cstring>kisbFixedFontSize</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="2"> + <property name="name"> + <cstring>labelBodyFontSize</cstring> + </property> + <property name="text"> + <string>Size:</string> + </property> + <property name="alignment"> + <set>AlignVCenter|AlignRight</set> + </property> + </widget> + <widget class="KFontCombo" row="2" column="1"> + <property name="name"> + <cstring>kfcBodyFont</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="KFontCombo" row="3" column="1"> + <property name="name"> + <cstring>kfcDetailsFont</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="KFontCombo" row="4" column="1"> + <property name="name"> + <cstring>kfcFixedFont</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>labelHeaderFont</cstring> + </property> + <property name="text"> + <string>Contact header font:</string> + </property> + <property name="alignment"> + <set>AlignVCenter|AlignRight</set> + </property> + </widget> + <widget class="KFontCombo" row="0" column="1"> + <property name="name"> + <cstring>kfcHeaderFont</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="KFontCombo" row="1" column="1"> + <property name="name"> + <cstring>kfcHeadlineFont</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="2"> + <property name="name"> + <cstring>labelHeaderFontSize</cstring> + </property> + <property name="text"> + <string>Size:</string> + </property> + <property name="alignment"> + <set>AlignVCenter|AlignRight</set> + </property> + </widget> + <widget class="QLabel" row="1" column="2"> + <property name="name"> + <cstring>labelHeaderFontSize_2</cstring> + </property> + <property name="text"> + <string>Size:</string> + </property> + <property name="alignment"> + <set>AlignVCenter|AlignRight</set> + </property> + </widget> + <widget class="KIntSpinBox" row="2" column="3"> + <property name="name"> + <cstring>kisbBodyFontSize</cstring> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>labelHeadlines</cstring> + </property> + <property name="text"> + <string>Headlines:</string> + </property> + <property name="alignment"> + <set>AlignVCenter|AlignRight</set> + </property> + </widget> + <widget class="KIntSpinBox" row="0" column="3"> + <property name="name"> + <cstring>kisbHeaderFontSize</cstring> + </property> + </widget> + <widget class="KIntSpinBox" row="1" column="3"> + <property name="name"> + <cstring>kisbHeadlineFontSize</cstring> + </property> + </widget> + </grid> + </widget> + </vbox> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>gbHeadline</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Contact Headers</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QCheckBox"> + <property name="name"> + <cstring>cbBackgroundColor</cstring> + </property> + <property name="text"> + <string>Use colored contact headers</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + <widget class="QFrame"> + <property name="name"> + <cstring>frameBGColor</cstring> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="KColorButton" row="0" column="1"> + <property name="name"> + <cstring>kcbHeaderBGColor</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string></string> + </property> + <property name="color"> + <color> + <red>0</red> + <green>0</green> + <blue>0</blue> + </color> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>tlBackgroundColor</cstring> + </property> + <property name="text"> + <string>Headline background color:</string> + </property> + <property name="alignment"> + <set>AlignVCenter|AlignRight</set> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>tlHeaderColor</cstring> + </property> + <property name="text"> + <string>Headline text color:</string> + </property> + <property name="alignment"> + <set>AlignVCenter|AlignRight</set> + </property> + </widget> + <widget class="KColorButton" row="1" column="1"> + <property name="name"> + <cstring>kcbHeaderTextColor</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string></string> + </property> + <property name="color"> + <color> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </property> + </widget> + <spacer row="0" column="2"> + <property name="name"> + <cstring>Spacer3</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + </spacer> + </grid> + </widget> + </vbox> + </widget> + <spacer> + <property name="name"> + <cstring>Spacer4</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + </spacer> + </vbox> +</widget> +<connections> + <connection> + <sender>cbBackgroundColor</sender> + <signal>toggled(bool)</signal> + <receiver>frameBGColor</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>cbStandardFonts</sender> + <signal>toggled(bool)</signal> + <receiver>frameFonts</receiver> + <slot>setDisabled(bool)</slot> + </connection> +</connections> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kaddressbook/printing/kabentrypainter.cpp b/kaddressbook/printing/kabentrypainter.cpp new file mode 100644 index 000000000..6ae163de8 --- /dev/null +++ b/kaddressbook/printing/kabentrypainter.cpp @@ -0,0 +1,521 @@ +/* + This file is part of KAddressBook. + Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + + +#include <qpaintdevicemetrics.h> +#include <qpainter.h> + +#include <kdebug.h> +#include <kglobal.h> +#include <klocale.h> +#include <knotifyclient.h> +#include <kprinter.h> +#include <kurl.h> + +#include "kabentrypainter.h" + +KABEntryPainter::KABEntryPainter() + : mShowAddresses( true ), mShowEmails( true ), mShowPhones( true ), + mShowURLs( true ) +{ +} + +KABEntryPainter::~KABEntryPainter() +{ + mEmailRects.clear(); + mPhoneRects.clear(); + mURLRects.clear(); + mTalkRects.clear(); +} + +void KABEntryPainter::setForegroundColor( const QColor &color ) +{ + mForegroundColor = color; +} + +void KABEntryPainter::setBackgroundColor( const QColor &color ) +{ + mBackgroundColor = color; +} + +void KABEntryPainter::setHeaderColor( const QColor &color ) +{ + mHeaderColor = color; +} + +void KABEntryPainter::setHeaderFont( const QFont &font ) +{ + mHeaderFont = font; +} + +void KABEntryPainter::setHeadLineFont( const QFont &font ) +{ + mHeadLineFont = font; +} + +void KABEntryPainter::setBodyFont( const QFont &font ) +{ + mBodyFont = font; +} + +void KABEntryPainter::setFixedFont( const QFont &font ) +{ + mFixedFont = font; +} + +void KABEntryPainter::setCommentFont( const QFont &font ) +{ + mCommentFont = font; +} + +void KABEntryPainter::setUseHeaderColor( bool value ) +{ + mUseHeaderColor = value; +} + +void KABEntryPainter::setShowAddresses( bool value ) +{ + mShowAddresses = value; +} + +void KABEntryPainter::setShowEmails( bool value ) +{ + mShowEmails = value; +} + +void KABEntryPainter::setShowPhones( bool value ) +{ + mShowPhones = value; +} + +void KABEntryPainter::setShowURLs( bool value ) +{ + mShowURLs = value; +} + +int KABEntryPainter::hitsEmail( const QPoint &p ) +{ + return hits( mEmailRects, p ); +} + +int KABEntryPainter::hitsURL( const QPoint &p ) +{ + return hits( mURLRects, p ); +} + +int KABEntryPainter::hitsPhone( const QPoint &p ) +{ + return hits( mPhoneRects, p ); +} + +int KABEntryPainter::hitsTalk( const QPoint &p ) +{ + return hits( mTalkRects, p ); +} + +int KABEntryPainter::hits( const QRectList& list, const QPoint &p ) +{ + QRectList::const_iterator pos; + int count = 0; + + for ( pos = list.begin(); pos != list.end(); ++pos ) { + if ( (*pos).contains( p ) ) + return count; + + ++count; + } + + return -1; +} + +bool KABEntryPainter::printAddressee( const KABC::Addressee &addr, + const QRect &window, QPainter *painter, + int top, bool fake, QRect *brect ) +{ + // TODO: custom fields, custom (?) for Entry + const int Width = window.width(); + const int Height = window.height(); + const int Ruler1 = Width/32; + const int Ruler2 = 2 * Ruler1; + const int Ruler3 = 3 * Ruler1; + QString text, line1, line2, line3, line4; + QRect rect; + + // settings derived from the options: + QFontMetrics fmHeader( mHeaderFont ); + QFontMetrics fmHeadLine( mHeadLineFont ); + QFontMetrics fmBody( mBodyFont ); + QFontMetrics fmFixed( mFixedFont ); + QFontMetrics fmComment( mCommentFont ); + + int y = top; + KABC::Address address; + + // this is used to prepare some fields for printing and decide about + // the layout later: + QValueList<QStringList> parts; + QValueList<QRectList*> contents; + + mEmailRects.clear(); + mPhoneRects.clear(); + mURLRects.clear(); + + // set window the painter works on: + painter->setWindow( window ); + + // first draw a black rectangle on top, containing the entries name, centered: + painter->setFont( mHeaderFont ); + painter->setBrush( QBrush( mBackgroundColor ) ); + painter->setPen( mBackgroundColor ); + text = addr.realName(); + + // replacement for: api->addressbook()->literalName(entry, text); + rect = painter->boundingRect( Ruler1, y, Width, Height, + Qt::AlignVCenter | Qt::AlignLeft, text ); + rect.setHeight( (int)( 1.25 * rect.height() ) ); + + if ( !fake && mUseHeaderColor ) + painter->drawRect( 0, y, Width, rect.height() ); + + painter->setPen( mUseHeaderColor ? mHeaderColor : mForegroundColor ); + if ( !fake ) { + // create a little (1/8) space on top of the letters: + float ypos = y + ( (float)rect.height() ) * 0.125; + painter->drawText( Ruler1, (int)ypos, Width, rect.height(), + Qt::AlignVCenter | Qt::AlignLeft, text ); + } + + // paint the birthday to the right: + QDateTime dt = addr.birthday(); + if ( dt.isValid() ) { + line1 = KGlobal::locale()->formatDate( dt.date(), true ); + if ( !fake ) { + // create a little (1/8) space on top of the letters: + float ypos = y + ( (float)rect.height() ) * 0.125; + painter->drawText( 0, (int)ypos, Width-Ruler1, rect.height(), + Qt::AlignVCenter | Qt::AlignRight, line1 ); + } + } + + y += rect.height(); + + // now draw the data according to the person: + painter->setFont( mBodyFont ); + y += fmBody.lineSpacing() / 2; + + painter->setPen( mForegroundColor ); + if ( !addr.prefix().isEmpty() ) { + line1 = addr.prefix().stripWhiteSpace(); + + if ( fake ) { + rect = painter->boundingRect( Ruler1, y, Width-Ruler1, Height, + Qt::AlignTop | Qt::AlignLeft, line1 ); + } else { + painter->drawText( Ruler1, y, Width-Ruler1, Height, Qt::AlignTop | Qt::AlignLeft, + line1, -1, &rect ); + } + + y += rect.height(); + } + + if ( !( addr.prefix().isEmpty() ) ) + y += fmBody.lineSpacing() / 2; + + // fill the parts stringlist, it contains "parts" (printable areas) + // that will be combined to fill the page as effectively as possible: + // Email addresses: + if ( !addr.emails().isEmpty() && mShowEmails ) { + contents.push_back( &mEmailRects ); + QStringList list; + + list.append( addr.emails().count() == 1 ? i18n( "Email address:" ) + : i18n( "Email addresses:" ) ); + list += addr.emails(); + parts.push_back( list ); + } + + // Telephones: + const KABC::PhoneNumber::List phoneNumbers( addr.phoneNumbers() ); + if ( !phoneNumbers.isEmpty() && mShowPhones ) { + contents.push_back( &mPhoneRects ); + QStringList list; + QString line; + + list.append( phoneNumbers.count() == 1 ? i18n( "Telephone:" ) + : i18n( "Telephones:" ) ); + + KABC::PhoneNumber::List::ConstIterator it; + for ( it = phoneNumbers.begin(); it != phoneNumbers.end(); ++it ) { + line = (*it).typeLabel(); + line += ": " + (*it).number(); + list.append( line.stripWhiteSpace() ); + } + + parts.push_back( list ); + } + + // Web pages/URLs: + if ( !addr.url().isEmpty() && addr.url().isValid() && mShowURLs ) { + contents.push_back( &mURLRects ); + QStringList list; + + list.append( i18n( "Web page:" ) ); + list += addr.url().prettyURL(); + parts.push_back( list ); + } + + /* + // Talk addresses: + if ( !addr.talk.isEmpty() ) { + contents.push_back( &mTalkRects ); + QStringList list; + + list.append( addr.talk.count() == 1 ? i18n( "Talk address:" ) + : i18n( "Talk addresses:" ) ); + list += addr.talk; + parts.push_back( list ); + } + */ + + QRect limits[] = { QRect( 0, y, Width / 2, Height ), + QRect( Width / 2, y, Width / 2, Height ), + QRect( 0, y, Width / 2, Height ), + QRect( Width / 2, y, Width / 2, Height ) }; + int heights[ 4 ]= { 0, 0, 0, 0 }; + + QValueList<QStringList>::iterator pos = parts.begin(); + QValueList<QRectList*>::iterator rpos = contents.begin(); + + for ( uint counter = 0; counter < parts.count(); ++counter ) { + const int Offset = counter > 1 ? QMAX( heights[ 0 ], heights[ 1 ] ) : 0; + QStringList list = *pos; + + painter->setFont( mHeadLineFont ); + if ( fake ) { + rect = painter->boundingRect( limits[ counter ].left(), + limits[ counter ].top() + heights[counter] + + Offset, limits[ counter ].width(), + limits[ counter ].height(), + Qt::AlignTop | Qt::AlignLeft, *list.at( 0 ) ); + } else { + painter->drawText( limits[ counter ].left(), limits[ counter ].top() + + heights[ counter ] + Offset, limits[ counter ].width(), + limits[ counter ].height(), Qt::AlignTop | Qt::AlignLeft, + *list.at( 0 ), -1, &rect ); + } + + heights[ counter ] += rect.height(); + + // paint the other elements at Ruler1: + painter->setFont( mFixedFont ); + for ( uint c2 = 1; c2 < list.count(); ++c2 ) { + // TODO: implement proper line breaking! + if ( fake ) { + rect = painter->boundingRect ( limits[ counter ].left() + Ruler1, + limits[ counter ].top() + heights[ counter ] + + Offset, limits[ counter ].width() - Ruler1, + limits[ counter ].height(), Qt::AlignTop | Qt::AlignLeft, + *list.at( c2 ) ); + } else { + painter->drawText( limits[ counter ].left() + Ruler1, limits[ counter ].top() + + heights[ counter ] + Offset, limits[ counter ].width() + - Ruler1, limits[ counter ].height(), Qt::AlignTop | Qt::AlignLeft, + *list.at( c2 ), -1, &rect ); + } + (*rpos)->push_back( rect ); + heights[ counter ] += rect.height(); + } + + ++pos; + ++rpos; + } + + y = y + QMAX( heights[ 0 ], heights[ 1 ] ) + QMAX( heights[ 2 ], heights[ 3 ] ); + // ^^^^^ done with emails, telephone, URLs and talk addresses + + // now print the addresses: + KABC::Address::List addresses = addr.addresses(); + if ( addresses.count() > 0 && mShowAddresses ) { + y += fmBody.lineSpacing() / 2; + painter->setFont( mHeadLineFont ); + if ( fake ) { + rect = painter->boundingRect( 0, y, Width, Height, Qt::AlignTop | Qt::AlignLeft, + addresses.count() == 1 ? i18n( "Address:" ) + : i18n( "Addresses:" ) ); + } else { + painter->drawText( 0, y, Width, Height, Qt::AlignTop | Qt::AlignLeft, + addresses.count() == 1 ? i18n( "Address:" ) + : i18n( "Addresses:" ), -1, &rect ); + } + + y += rect.height(); + y += fmBody.lineSpacing() / 4; + painter->setFont( mBodyFont ); + + KABC::Address::List::ConstIterator it; + for ( it = addresses.begin(); it != addresses.end(); ++it ) { + address = *it; + switch ( address.type() ) { + case KABC::Address::Dom: + line1 = i18n( "Domestic Address" ); + break; + case KABC::Address::Intl: + line1 = i18n( "International Address" ); + break; + case KABC::Address::Postal: + line1 = i18n( "Postal Address" ); + break; + case KABC::Address::Parcel: + line1 = i18n( "Parcel Address" ); + break; + case KABC::Address::Home: + line1 = i18n( "Home Address" ); + break; + case KABC::Address::Work: + line1 = i18n( "Work Address" ); + break; + case KABC::Address::Pref: + default: + line1 = i18n( "Preferred Address" ); + } + + line1 += QString::fromLatin1( ":" ); + text = QString::null; + + if ( !address.extended().isEmpty() ) + text = address.extended().stripWhiteSpace(); + + if ( !text.isEmpty() ) { + line1 = line1 + QString::fromLatin1( " (" ) + text + + QString::fromLatin1( ")" ); + } + + line1 = line1.stripWhiteSpace(); + line2 = address.street(); + if ( !address.postOfficeBox().isEmpty() ) + line2 += QString::fromLatin1( " - " ) + address.postOfficeBox(); + + // print address in american style, this will need localisation: + line3 = address.locality() + ( address.region().isEmpty() ? + QString::fromLatin1( "" ) : QString::fromLatin1( ", " ) + + address.region() ) + ( address.postalCode().isEmpty() + ? QString::fromLatin1( "" ) : QString::fromLatin1( " " ) + + address.postalCode() ); + line4 = address.country(); + + if ( fake ) { + rect = painter->boundingRect( Ruler1, y, Width - Ruler1, Height, + Qt::AlignTop | Qt::AlignLeft, line1 ); + } else { + painter->drawText( Ruler1, y, Width - Ruler1, Height, + Qt::AlignTop | Qt::AlignLeft, line1, -1, &rect ); + } + + y += rect.height(); + if ( !line2.isEmpty() ) { + if ( fake ) { + rect = painter->boundingRect( Ruler2, y, Width - Ruler2, Height, + Qt::AlignTop | Qt::AlignLeft, line2 ); + } else { + painter->drawText( Ruler2, y, Width - Ruler2, Height, + Qt::AlignTop | Qt::AlignLeft, line2, -1, &rect ); + } + y += rect.height(); + } + + if ( !line3.isEmpty() ) { + if ( fake ) { + rect = painter->boundingRect( Ruler2, y, Width - Ruler2, Height, + Qt::AlignTop | Qt::AlignLeft, line3 ); + } else { + painter->drawText( Ruler2, y, Width - Ruler2, Height, + Qt::AlignTop | Qt::AlignLeft, line3, -1, &rect ); + } + y += rect.height(); + } + + if ( !line4.isEmpty() ) { + if ( fake ) { + rect = painter->boundingRect( Ruler2, y, Width - Ruler2, Height, + Qt::AlignTop | Qt::AlignLeft, line4 ); + } else { + painter->drawText( Ruler2, y, Width - Ruler2, Height, + Qt::AlignTop | Qt::AlignLeft, line4, -1, &rect ); + } + y += rect.height(); + } + + y += fmBody.lineSpacing() / 4; + if ( !address.label().isEmpty() ) { + if ( fake ) { + rect = painter->boundingRect( Ruler2, y, Width - Ruler2, Height, + Qt::AlignTop | Qt::AlignLeft, + i18n( "(Deliver to:)" ) ); + } else { + painter->drawText( Ruler2, y, Width - Ruler2, Height, + Qt::AlignTop | Qt::AlignLeft, + i18n( "(Deliver to:)" ), -1, &rect ); + } + + y += rect.height(); + y += fmBody.lineSpacing() / 4; + if ( fake ) { + rect = painter->boundingRect( Ruler3, y, Width - Ruler3, Height, + Qt::AlignTop | Qt::AlignLeft, address.label() ); + } else { + painter->drawText( Ruler3, y, Width - Ruler3, Height, + Qt::AlignTop | Qt::AlignLeft, address.label(), -1, &rect ); + } + + y += rect.height(); + y += fmBody.lineSpacing() / 2; + } + } + } + + if ( !addr.note().isEmpty() ) { + painter->setFont( mCommentFont ); + y += fmBody.lineSpacing() / 2; + if ( fake ) { + rect = painter->boundingRect( 0, y, Width, Height, + Qt::AlignTop | Qt::AlignLeft | Qt::WordBreak, + addr.note() ); + } else { + painter->drawText( 0, y, Width, Height, + Qt::AlignTop | Qt::AlignLeft | Qt::WordBreak, + addr.note(), -1, &rect ); + } + + y += rect.height(); + } + + y += fmBody.lineSpacing() / 2; + + if ( brect != 0 ) + *brect = QRect( 0, top, Width, y - top ); + + if ( y < Height ) + return true; + else + return false; +} diff --git a/kaddressbook/printing/kabentrypainter.h b/kaddressbook/printing/kabentrypainter.h new file mode 100644 index 000000000..6c5b8dca9 --- /dev/null +++ b/kaddressbook/printing/kabentrypainter.h @@ -0,0 +1,133 @@ +/* + This file is part of KAddressBook. + Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#ifndef KABENTRYPAINTER_H +#define KABENTRYPAINTER_H + +#include <kabc/addressbook.h> + +#include <qcolor.h> +#include <qfont.h> +#include <qrect.h> +#include <qvaluelist.h> + +typedef QValueList<QRect> QRectList; + +class KABEntryPainter +{ + public: + KABEntryPainter(); + ~KABEntryPainter(); + + /** + Paint one entry using the given painter. May not only be used on + printer objects but on any suitable QPaintDevice. + The function does not paint a background, just the contents of the + addressee. + + @param addr The addressee that should be printed. + @param window The rectangle where the addressee should be printed to. + @param p A painter object to print it. + @param top The starting pixel in vertical direction (coordinate + system origin in the upper left corner), it is zero by + default, but may be larger than this to place another + addressee below an already printed one. + @param fake If this is true, the addressee is not really printed, + it only calculates the space needed to draw this entry + onto the given window. + + @returns false if some error happens, otherwise true. + */ + bool printAddressee( const KABC::Addressee &addr, const QRect &window, + QPainter *p, int top = 0, bool fake = false, + QRect *rect = 0 ); + + void setForegroundColor( const QColor &color = Qt::black ); + void setBackgroundColor( const QColor &color = Qt::black ); + void setHeaderColor( const QColor &color = Qt::white ); + + void setHeaderFont( const QFont &font = QFont( "Helvetica", 12, QFont::Normal, true ) ); + void setHeadLineFont( const QFont &font = QFont( "Helvetica", 12, QFont::Normal, true ) ); + void setBodyFont( const QFont &font = QFont( "Helvetica", 12, QFont::Normal, true ) ); + void setFixedFont( const QFont &font = QFont( "Courier", 12, QFont::Normal, true ) ); + void setCommentFont( const QFont &font = QFont( "Helvetica", 10, QFont::Normal, true ) ); + + void setUseHeaderColor( bool value = true ); + + void setShowAddresses( bool value = true ); + void setShowEmails( bool value = true ); + void setShowPhones( bool value = true ); + void setShowURLs( bool value = true ); + + /** + Returns the index of the rectangle if the point p is inside of + one of the email addresses. The index is the position of the + email address in the emails list. If it does not point at one of + the email addresses, -1 is returned. + */ + int hitsEmail( const QPoint &p ); + + /** + Returns the index of the rectangle if the point p is inside of + one of the telephone numbers. See hitsEmail + */ + int hitsPhone( const QPoint &p ); + + /** + Returns the index of the rectangle if the point p is inside of + one of the telephone numbers. See hitsEmail + */ + int hitsTalk( const QPoint &p ); + + /** + Returns the index of the rectangle if the point p is inside of + one of the telephone numbers. See hitsEmail + */ + int hitsURL( const QPoint &p ); + + private: + int hits( const QRectList& rects, const QPoint &p ); + + QColor mForegroundColor; + QColor mBackgroundColor; + QColor mHeaderColor; + + QFont mHeaderFont; + QFont mHeadLineFont; + QFont mBodyFont; + QFont mFixedFont; + QFont mCommentFont; + + bool mUseHeaderColor; + bool mShowAddresses; + bool mShowEmails; + bool mShowPhones; + bool mShowURLs; + + QRectList mEmailRects; + QRectList mPhoneRects; + QRectList mURLRects; + QRectList mTalkRects; +}; + +#endif diff --git a/kaddressbook/printing/mike-style.png b/kaddressbook/printing/mike-style.png Binary files differnew file mode 100644 index 000000000..7d3fd2e3b --- /dev/null +++ b/kaddressbook/printing/mike-style.png diff --git a/kaddressbook/printing/mikesstyle.cpp b/kaddressbook/printing/mikesstyle.cpp new file mode 100644 index 000000000..1eae4281c --- /dev/null +++ b/kaddressbook/printing/mikesstyle.cpp @@ -0,0 +1,262 @@ +/* + This file is part of KAddressBook. + Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org> + 2002 Mike Pilone <mpilone@slac.com> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include <qpaintdevicemetrics.h> +#include <qpainter.h> + +#include <kabc/addressee.h> +#include <kapplication.h> +#include <kdebug.h> +#include <kglobal.h> +#include <klocale.h> +#include <kprinter.h> +#include <kprogress.h> + +#include "printingwizard.h" +#include "printprogress.h" +#include "printstyle.h" + +#include "mikesstyle.h" + +using namespace KABPrinting; + +const int mFieldSpacingHint = 2; + +MikesStyle::MikesStyle( PrintingWizard *parent, const char *name ) + : PrintStyle( parent, name ) +{ + setPreview( "mike-style.png" ); +} + +MikesStyle::~MikesStyle() +{ +} + +void MikesStyle::print( const KABC::Addressee::List &contacts, PrintProgress *progress ) +{ + QFont mFont; + QFont mBoldFont; + QPainter p; + + p.begin( wizard()->printer() ); + int yPos = 0, count = 0; + int spacingHint = 10; + + // Now do the actual printing + mFont = p.font(); + mBoldFont = p.font(); + mBoldFont.setBold( true ); + QFontMetrics fm( mFont ); + QPaintDeviceMetrics metrics( p.device() ); + + int height = 0; + KABC::Addressee::List::ConstIterator it; + + progress->addMessage( i18n( "Preparing" ) ); + progress->addMessage( i18n( "Printing" ) ); + + for ( it = contacts.begin(); it != contacts.end(); ++it ) { + progress->setProgress( (count++ * 100) / contacts.count() ); + kapp->processEvents(); + + // Get the total height so we know if it will fit on the current page + height = calcHeight( *it, mFont, mBoldFont ); + if ( (yPos + spacingHint + height) > (metrics.height() - fm.height() - 5) ) { + p.save(); + p.translate( 0, metrics.height() - fm.height() - 5 ); + paintTagLine( p, mFont ); + p.restore(); + + wizard()->printer()->newPage(); + yPos = 0; + } + + // Move the painter to the proper position and then paint the addressee + yPos += spacingHint; + p.save(); + p.translate( 0, yPos ); + doPaint( p, *it, height, mFont, mBoldFont ); + p.restore(); + + yPos += height; + } + + progress->addMessage( i18n( "Done" ) ); + + // print the tag line on the last page + p.save(); + p.translate( 0, metrics.height() - fm.height() - 5 ); + paintTagLine( p, mFont ); + p.restore(); + + // send to the printer + p.end(); +} + +QString MikesStyle::trimString( const QString &text, int width, QFontMetrics &fm ) +{ + if ( fm.width( text ) <= width ) + return text; + + QString dots = "..."; + int dotWidth = fm.width( dots ); + QString trimmed; + int charNum = 0; + + while ( fm.width( trimmed ) + dotWidth < width ) { + trimmed += text[ charNum ]; + charNum++; + } + + // Now trim the last char, since it put the width over the top + trimmed = trimmed.left( trimmed.length() - 1 ); + trimmed += dots; + + return trimmed; +} + +void MikesStyle::doPaint( QPainter &painter, const KABC::Addressee &addr, + int maxHeight, const QFont &font, const QFont &bFont ) +{ + QFontMetrics fm( font ); + QFontMetrics bfm( bFont ); + QPaintDeviceMetrics metrics( painter.device() ); + int margin = 10; + int width = metrics.width() - 10; + int xPos = 5; + int yPos = 0; + QBrush brush( Qt::lightGray ); + + painter.setPen( Qt::black ); + painter.drawRect( xPos, yPos, width, maxHeight ); + + // The header + painter.fillRect( xPos + 1, yPos + 1, width - 2, + bfm.height() + 2 * mFieldSpacingHint - 2, brush ); + painter.setFont( bFont ); + xPos += mFieldSpacingHint; + painter.drawText( xPos, yPos + bfm.height(), addr.formattedName() ); + + yPos += bfm.height() + 2 * mFieldSpacingHint; + xPos = margin; + + // now the fields, in two halves + painter.setFont( font ); + + KABC::Field::List fields = wizard()->addressBook()->fields(); + int numFields = fields.count(); + QString label; + QString value; + + for ( int i = 0; i < numFields / 2; i++ ) { + label = fields[ i ]->label(); + value = trimString( fields[ i ]->value( addr ), (width - 10) / 4, fm ); + + yPos += fm.height(); + painter.drawText( xPos, yPos, label + ":" ); + + xPos += (width - (2 * margin)) / 4; + painter.drawText( xPos, yPos, value ); + + yPos += mFieldSpacingHint; + xPos = margin; + } + + yPos = bfm.height() + 2 * mFieldSpacingHint; + xPos = margin + width / 2; + for ( int i = numFields / 2; i < numFields; i++ ) { + label = fields[ i ]->label(); + value = value = trimString( fields[ i ]->value( addr ), (width - 10) / 4, fm ); + + yPos += fm.height(); + painter.drawText( xPos, yPos, label + ":" ); + + xPos += (width - (2 * margin)) / 4; + painter.drawText( xPos, yPos, value ); + + yPos += mFieldSpacingHint; + xPos = margin + width / 2; + } +} + +void MikesStyle::paintTagLine( QPainter &p, const QFont &font ) +{ + QFontMetrics fm( font ); + + QString text = i18n( "Printed on %1 by KAddressBook (http://www.kde.org)" ) + .arg( KGlobal::locale()->formatDateTime( QDateTime::currentDateTime() ) ); + + p.setPen( Qt::black ); + p.drawText( 0, fm.height(), text ); +} + +int MikesStyle::calcHeight( const KABC::Addressee &addr, + const QFont &font, const QFont &bFont ) +{ + QFontMetrics fm( font ); + QFontMetrics bfm( bFont ); + + int height = 0; + + // get the fields + KABC::Field::List fieldList = wizard()->addressBook()->fields(); + int numFields = fieldList.count(); + int halfHeight = 0; + + // Determine which half of the fields is higher + for ( int i = 0; i < numFields / 2; i++ ) + halfHeight += fm.height() * (fieldList[ i ]->value( addr ).contains( '\n' ) + 1); + + height = halfHeight; + + // now the second half + halfHeight = 0; + for ( int i = numFields / 2; i < numFields; i++ ) + halfHeight += fm.height() * (fieldList[ i ]->value( addr ).contains( '\n' ) + 1); + + height = QMAX( height, halfHeight ); + + // Add the title and the spacing + height += bfm.height() + ((numFields / 2 + 3) * mFieldSpacingHint); + + return height; +} + + +MikesStyleFactory::MikesStyleFactory( PrintingWizard *parent, const char *name ) + : PrintStyleFactory( parent, name ) +{ +} + +PrintStyle *MikesStyleFactory::create() const +{ + return new MikesStyle( mParent, mName ); +} + +QString MikesStyleFactory::description() const +{ + return i18n( "Mike's Printing Style" ); +} + +#include "mikesstyle.moc" diff --git a/kaddressbook/printing/mikesstyle.h b/kaddressbook/printing/mikesstyle.h new file mode 100644 index 000000000..52278d390 --- /dev/null +++ b/kaddressbook/printing/mikesstyle.h @@ -0,0 +1,65 @@ +/* + This file is part of KAddressBook. + Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org> + 2002 Mike Pilone <mpilone@slac.com> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#ifndef MIKESSTYLE_H +#define MIKESSTYLE_H + +#include <qfont.h> + +#include "printstyle.h" + +namespace KABPrinting { + +class PrintProgress; + +class MikesStyle : public PrintStyle +{ + Q_OBJECT + + public: + MikesStyle( PrintingWizard *parent, const char *name ); + ~MikesStyle(); + + void print( const KABC::Addressee::List&, PrintProgress* ); + + protected: + void doPaint( QPainter &painter, const KABC::Addressee &addr, int maxHeight, + const QFont &font, const QFont &bFont ); + int calcHeight( const KABC::Addressee &addr, const QFont &font, const QFont &bFont); + void paintTagLine( QPainter &p, const QFont &font); + QString trimString( const QString &text, int width, QFontMetrics &fm); +}; + +class MikesStyleFactory : public PrintStyleFactory +{ + public: + MikesStyleFactory( PrintingWizard *parent, const char *name = 0 ); + + PrintStyle *create() const; + QString description() const; +}; + +} + +#endif diff --git a/kaddressbook/printing/printingwizard.cpp b/kaddressbook/printing/printingwizard.cpp new file mode 100644 index 000000000..a961ac5fc --- /dev/null +++ b/kaddressbook/printing/printingwizard.cpp @@ -0,0 +1,220 @@ +/* + This file is part of KAddressBook. + Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org> + Tobias Koenig <tokoe@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include <qcombobox.h> +#include <qheader.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qlistview.h> +#include <qpixmap.h> +#include <qpushbutton.h> +#include <qradiobutton.h> + +#include <kabc/addresseelist.h> +#include <kapplication.h> +#include <kdebug.h> +#include <kdialog.h> +#include <kdialogbase.h> +#include <klocale.h> +#include <kprinter.h> + +// including the styles +#include "detailledstyle.h" +#include "mikesstyle.h" + +#include "kabprefs.h" +#include "printprogress.h" +#include "printstyle.h" +#include "printsortmode.h" + +#include "printingwizard.h" + +using namespace KABPrinting; + +PrintingWizard::PrintingWizard( KPrinter *printer, KABC::AddressBook* ab, + const QStringList& selection, QWidget *parent, + const char* name ) + : KWizard( parent, name ), mPrinter( printer ), mAddressBook( ab ), + mSelection( selection ), mStyle( 0 ) +{ + mSelectionPage = new SelectionPage( this ); + mSelectionPage->setUseSelection( !selection.isEmpty() ); + insertPage( mSelectionPage, i18n("Choose Contacts to Print"), -1 ); + + mFilters = Filter::restore( kapp->config(), "Filter" ); + QStringList filters; + for ( Filter::List::ConstIterator it = mFilters.begin(); it != mFilters.end(); ++it ) + filters.append( (*it).name() ); + + mSelectionPage->setFilters( filters ); + + mSelectionPage->setCategories( KABPrefs::instance()->customCategories() ); + + setAppropriate( mSelectionPage, true ); + + + mStylePage = new StylePage( mAddressBook, this ); + connect( mStylePage, SIGNAL( styleChanged(int) ), SLOT( slotStyleSelected(int) ) ); + insertPage( mStylePage, i18n("Choose Printing Style"), -1 ); + + registerStyles(); + + if ( mStyleFactories.count() > 0 ) + slotStyleSelected( 0 ); +} + +PrintingWizard::~PrintingWizard() +{ +} + +void PrintingWizard::accept() +{ + print(); + close(); +} + +void PrintingWizard::registerStyles() +{ + mStyleFactories.append( new DetailledPrintStyleFactory( this ) ); + mStyleFactories.append( new MikesStyleFactory( this ) ); + + mStylePage->clearStyleNames(); + for ( uint i = 0; i < mStyleFactories.count(); ++i ) + mStylePage->addStyleName( mStyleFactories.at( i )->description() ); +} + +void PrintingWizard::slotStyleSelected( int index ) +{ + if ( index < 0 || (uint)index >= mStyleFactories.count() ) + return; + + setFinishEnabled( mStylePage, false ); + + if ( mStyle ) + mStyle->hidePages(); + + if ( mStyleList.at( index ) != 0 ) + mStyle = mStyleList.at( index ); + else { + PrintStyleFactory *factory = mStyleFactories.at( index ); + kdDebug(5720) << "PrintingWizardImpl::slotStyleSelected: " + << "creating print style " + << factory->description() << endl; + mStyle = factory->create(); + mStyleList.insert( index, mStyle ); + } + + mStyle->showPages(); + + mStylePage->setPreview( mStyle->preview() ); + + setFinishEnabled( page( pageCount() - 1 ), true ); + + if ( mStyle->preferredSortField() != 0 ) { + mStylePage->setSortField( mStyle->preferredSortField() ); + mStylePage->setSortAscending( mStyle->preferredSortType() ); + } +} + +KABC::AddressBook* PrintingWizard::addressBook() +{ + return mAddressBook; +} + +KPrinter* PrintingWizard::printer() +{ + return mPrinter; +} + +void PrintingWizard::print() +{ + // create and show print progress widget: + PrintProgress *progress = new PrintProgress( this ); + insertPage( progress, i18n( "Print Progress" ), -1 ); + showPage( progress ); + kapp->processEvents(); + + // prepare list of contacts to print: + + KABC::AddresseeList list; + if ( mStyle != 0 ) { + if ( mSelectionPage->useSelection() ) { + QStringList::ConstIterator it; + for ( it = mSelection.begin(); it != mSelection.end(); ++it ) { + KABC::Addressee addr = addressBook()->findByUid( *it ); + if ( !addr.isEmpty() ) + list.append( addr ); + } + } else if ( mSelectionPage->useFilters() ) { + // find contacts that can pass selected filter + Filter::List::ConstIterator filterIt; + for ( filterIt = mFilters.begin(); filterIt != mFilters.end(); ++filterIt ) + if ( (*filterIt).name() == mSelectionPage->filter() ) + break; + + KABC::AddressBook::ConstIterator it; + for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { + if ( (*filterIt).filterAddressee( *it ) ) + list.append( *it ); + } + + } else if ( mSelectionPage->useCategories() ) { + QStringList categories = mSelectionPage->categories(); + KABC::AddressBook::ConstIterator it; + for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { + const QStringList tmp( (*it).categories() ); + QStringList::ConstIterator tmpIt; + for ( tmpIt = tmp.begin(); tmpIt != tmp.end(); ++tmpIt ) + if ( categories.contains( *tmpIt ) ) { + list.append( *it ); + break; + } + } + } else { + // create a string list of all entries: + KABC::AddressBook::ConstIterator it; + for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) + list.append( *it ); + } + + list.setReverseSorting( !mStylePage->sortAscending() ); + +#if KDE_IS_VERSION(3,3,91) + PrintSortMode sortMode( mStylePage->sortField() ); + list.sortByMode( &sortMode ); +#else + list.sortByField( mStylePage->sortField() ); +#endif + } + + kdDebug(5720) << "PrintingWizardImpl::print: printing " + << list.count() << " contacts." << endl; + + // ... print: + setBackEnabled( progress, false ); + cancelButton()->setEnabled( false ); + mStyle->print( list, progress ); +} + +#include "printingwizard.moc" diff --git a/kaddressbook/printing/printingwizard.h b/kaddressbook/printing/printingwizard.h new file mode 100644 index 000000000..528aac71f --- /dev/null +++ b/kaddressbook/printing/printingwizard.h @@ -0,0 +1,115 @@ +/* + This file is part of KAddressBook. + Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org> + Tobias Koenig <tokoe@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#ifndef PRINTINGWIZARD_H +#define PRINTINGWIZARD_H + +#include <qptrlist.h> +#include <qstringlist.h> + +#include <kwizard.h> + +#include "common/filter.h" +#include "kabc/addressbook.h" +#include "printstyle.h" + +#include "selectionpage.h" +#include "stylepage.h" + + +class KPrinter; +class QVBoxLayout; + +namespace KABPrinting { + +/** + The PrintingWizard combines pages common for all print styles + and those provided by the respective style. +*/ +class PrintingWizard : public KWizard +{ + Q_OBJECT + + public: + /** + Construct a printing wizard. Give the addressbook instance to print. + */ + PrintingWizard( KPrinter *printer, + KABC::AddressBook* ab, + const QStringList& selection, + QWidget *parent = 0, const char *name = 0 ); + ~PrintingWizard(); + + /** + Modify this method to add a new PrintStyle. + */ + void registerStyles(); + + /** + Perform the actual printing. + */ + void print(); + + /** + Retrieve the document object. + */ + KABC::AddressBook *addressBook(); + + /** + Retrieve the printer to be used. + */ + KPrinter* printer(); + + protected slots: + /** + A print style has been selected. The argument is the index + in the cbStyle combo and in styles. + */ + void slotStyleSelected(int); + + protected: + QPtrList<PrintStyleFactory> mStyleFactories; + QPtrList<PrintStyle> mStyleList; + Filter::List mFilters; + KPrinter *mPrinter; + KABC::AddressBook *mAddressBook; + QStringList mSelection; + PrintStyle *mStyle; + + StylePage *mStylePage; + SelectionPage *mSelectionPage; + + /** + Overloaded accept slot. This is used to do the actual + printing without having the wizard disappearing + before. What happens is actually up to the print style, + since it does the printing. It could display a progress + window, for example (hint, hint). + */ + void accept(); +}; + +} + +#endif diff --git a/kaddressbook/printing/printprogress.cpp b/kaddressbook/printing/printprogress.cpp new file mode 100644 index 000000000..cb4a91d85 --- /dev/null +++ b/kaddressbook/printing/printprogress.cpp @@ -0,0 +1,83 @@ +/* + This file is part of KAddressBook. + Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include <qlayout.h> +#include <qprogressbar.h> +#include <qtextbrowser.h> + +#include <kapplication.h> +#include <kdebug.h> +#include <kdialog.h> +#include <klocale.h> + +#include "printprogress.h" + +using namespace KABPrinting; + +PrintProgress::PrintProgress( QWidget *parent, const char *name ) + : QWidget( parent, name ) +{ + setCaption( i18n( "Printing: Progress" ) ); + + QGridLayout *topLayout = new QGridLayout( this, 1, 1, KDialog::marginHint(), + KDialog::spacingHint() ); + + mLogBrowser = new QTextBrowser( this ); + topLayout->addWidget( mLogBrowser, 0, 0 ); + + mProgressBar = new QProgressBar( this ); + mProgressBar->setProgress( 0 ); + topLayout->addWidget( mProgressBar, 1, 0 ); + + resize( QSize( 370, 220 ).expandedTo( minimumSizeHint() ) ); +} + +PrintProgress::~PrintProgress() +{ +} + +void PrintProgress::addMessage( const QString &msg ) +{ + mMessages.append( msg ); + + QString head = QString( "<qt><b>" ) + i18n( "Progress" ) + + QString( ":</b><ul>" ); + + QString foot = QString( "</ul></qt>" ); + + QString body; + QStringList::ConstIterator it; + for ( it = mMessages.begin(); it != mMessages.end(); ++it ) + body.append( QString( "<li>" ) + (*it) + QString( "</li>" ) ); + + mLogBrowser->setText( head + body + foot ); + kapp->processEvents(); +} + +void PrintProgress::setProgress( int step ) +{ + mProgressBar->setProgress( step ); + kapp->processEvents(); +} + +#include "printprogress.moc" diff --git a/kaddressbook/printing/printprogress.h b/kaddressbook/printing/printprogress.h new file mode 100644 index 000000000..fd2a494f8 --- /dev/null +++ b/kaddressbook/printing/printprogress.h @@ -0,0 +1,67 @@ +/* + This file is part of KAddressBook. + Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#ifndef PRINTPROGRESS_H +#define PRINTPROGRESS_H + +#include <qwidget.h> + +class QProgressBar; +class QString; +class QTextBrowser; + +namespace KABPrinting { + +/** + This defines a simple widget to display print progress + information. It is provided to all print styles during a print + process. It displays messages and a a progress bar. + */ +class PrintProgress : public QWidget +{ + Q_OBJECT + + public: + PrintProgress( QWidget *parent, const char *name = 0 ); + ~PrintProgress(); + + /** + Add a message to the message log. Give the user something to admire :-) + */ + void addMessage( const QString& ); + + /** + Set the progress to a certain amount. Steps are from 0 to 100. + */ + void setProgress( int ); + + private: + QStringList mMessages; + + QTextBrowser* mLogBrowser; + QProgressBar* mProgressBar; +}; + +} + +#endif diff --git a/kaddressbook/printing/printsortmode.cpp b/kaddressbook/printing/printsortmode.cpp new file mode 100644 index 000000000..49ae25557 --- /dev/null +++ b/kaddressbook/printing/printsortmode.cpp @@ -0,0 +1,76 @@ +/* + This file is part of KAddressBook. + Copyright (c) 2005 Tobias Koenig <tokoe@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include <kabc/field.h> + +#include "printsortmode.h" + +#if KDE_IS_VERSION(3,3,91) + +PrintSortMode::PrintSortMode( KABC::Field *field, bool ascending ) + : mSortField( field ), mAscending( ascending ) +{ + const KABC::Field::List fields = KABC::Field::allFields(); + KABC::Field::List::ConstIterator it; + for ( it = fields.begin(); it != fields.end(); ++it ) { + if ( (*it)->label() == KABC::Addressee::givenNameLabel() ) + mGivenNameField = *it; + else if ( (*it)->label() == KABC::Addressee::familyNameLabel() ) + mFamilyNameField = *it; + else if ( (*it)->label() == KABC::Addressee::formattedNameLabel() ) + mFormattedNameField = *it; + } +} + +bool PrintSortMode::lesser( const KABC::Addressee &first, + const KABC::Addressee &second ) const +{ + if ( !mSortField ) + return false; + + int result = QString::localeAwareCompare( mSortField->value( first ), + mSortField->value( second ) ); + if ( result == 0 ) { + int givenNameResult = QString::localeAwareCompare( mGivenNameField->value( first ), + mGivenNameField->value( second ) ); + if ( givenNameResult == 0 ) { + int familyNameResult = QString::localeAwareCompare( mFamilyNameField->value( first ), + mFamilyNameField->value( second ) ); + if ( familyNameResult == 0 ) { + result = QString::localeAwareCompare( mFormattedNameField->value( first ), + mFormattedNameField->value( second ) ); + } else + result = familyNameResult; + } else + result = givenNameResult; + } + + bool lesser = result < 0; + + if ( !mAscending ) + lesser = !lesser; + + return lesser; +} + +#endif diff --git a/kaddressbook/printing/printsortmode.h b/kaddressbook/printing/printsortmode.h new file mode 100644 index 000000000..a7992cc6c --- /dev/null +++ b/kaddressbook/printing/printsortmode.h @@ -0,0 +1,50 @@ +/* + This file is part of KAddressBook. + Copyright (c) 2005 Tobias Koenig <tokoe@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#ifndef PRINTSORTMODE_H +#define PRINTSORTMODE_H + +#include <kdeversion.h> + +#if KDE_IS_VERSION(3,3,91) + +#include <kabc/sortmode.h> + +class PrintSortMode : public KABC::SortMode +{ + public: + PrintSortMode( KABC::Field *field, bool ascending = true ); + + virtual bool lesser( const KABC::Addressee&, const KABC::Addressee& ) const; + + private: + KABC::Field *mSortField; + KABC::Field *mGivenNameField; + KABC::Field *mFamilyNameField; + KABC::Field *mFormattedNameField; + bool mAscending; +}; + +#endif // KDE_IS_VERSION + +#endif // PRINTSORTMODE_H diff --git a/kaddressbook/printing/printstyle.cpp b/kaddressbook/printing/printstyle.cpp new file mode 100644 index 000000000..a3cf537d4 --- /dev/null +++ b/kaddressbook/printing/printstyle.cpp @@ -0,0 +1,130 @@ +/* + This file is part of KAddressBook. + Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include <kstandarddirs.h> +#include <kdebug.h> + +#include <qwidget.h> + +#include "printstyle.h" +#include "printingwizard.h" + +using namespace KABPrinting; + + +PrintStyle::PrintStyle( PrintingWizard* parent, const char* name ) + : QObject( parent, name ), mWizard( parent ), mSortField( 0 ) +{ +} + +PrintStyle::~PrintStyle() +{ +} + +const QPixmap& PrintStyle::preview() +{ + return mPreview; +} + +void PrintStyle::setPreview( const QPixmap& image ) +{ + mPreview = image; +} + +bool PrintStyle::setPreview( const QString& fileName ) +{ + QPixmap preview; + QString path = locate( "appdata", "printing/" + fileName ); + if ( path.isEmpty() ) { + kdDebug(5720) << "PrintStyle::setPreview: preview not locatable." << endl; + return false; + } else { + if ( preview.load( path ) ) { + setPreview( preview ); + return true; + } else { + kdDebug(5720) << "PrintStyle::setPreview: preview at '" << path << "' cannot be loaded." << endl; + return false; + } + } +} + +PrintingWizard *PrintStyle::wizard() +{ + return mWizard; +} + +void PrintStyle::addPage( QWidget *page, const QString &title ) +{ + if ( mPageList.find( page ) == -1 ) { // not yet in the list + mPageList.append( page ); + mPageTitles.append( title ); + } +} + +void PrintStyle::showPages() +{ + QWidget *wdg = 0; + int i = 0; + for ( wdg = mPageList.first(); wdg; wdg = mPageList.next(), ++i ) { + mWizard->addPage( wdg, mPageTitles[ i ] ); + if ( i == 0 ) + mWizard->setAppropriate( wdg, true ); + } + + if ( wdg ) + mWizard->setFinishEnabled( wdg, true ); +} + +void PrintStyle::hidePages() +{ + for ( QWidget *wdg = mPageList.first(); wdg; wdg = mPageList.next() ) + mWizard->removePage( wdg ); +} + +void PrintStyle::setPreferredSortOptions( KABC::Field *field, bool ascending ) +{ + mSortField = field; + mSortType = ascending; +} + +KABC::Field* PrintStyle::preferredSortField() +{ + return mSortField; +} + +bool PrintStyle::preferredSortType() +{ + return mSortType; +} + +PrintStyleFactory::PrintStyleFactory( PrintingWizard* parent, const char* name ) + : mParent( parent ), mName( name ) +{ +} + +PrintStyleFactory::~PrintStyleFactory() +{ +} + +#include "printstyle.moc" diff --git a/kaddressbook/printing/printstyle.h b/kaddressbook/printing/printstyle.h new file mode 100644 index 000000000..217b80b99 --- /dev/null +++ b/kaddressbook/printing/printstyle.h @@ -0,0 +1,171 @@ +/* + This file is part of KAddressBook. + Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#ifndef PRINTSTYLE_H +#define PRINTSTYLE_H + +#include <qwidget.h> +#include <qstringlist.h> +#include <qpixmap.h> + +#include <kabc/field.h> + +namespace KABPrinting { + +class PrintingWizard; +class PrintProgress; + +/** + The class PrintStyle implements the abstract interface to the + PrintingWizards style objects. + To implement a print style, derive from this class and read + the information in printingwizard.h to see how this two pieces + work together. Basically, the print style gets the contacts it + is supposed to print from the PrintingWizard is will not + change this set - neither its content nor its order. + To register your new style in the printing wizard, you need to + define a PrintStyleFactory that handles how your objects are + created and deleted. See the existing print styles for + examples. + A print style should have a preview image that gives the user + a basic impression on how it will look. Add this image to the + printing folder (right here :-), and edit Makefile.am to have + it installed along with kaddressbook. Load it using + setPreview(QString). + Your print style is supposed to add its options as pages to + the printing wizard. The method wizard() gives you a pointer + to the wizard object. + */ + +class PrintStyle : public QObject +{ + Q_OBJECT + + public: + PrintStyle( PrintingWizard* parent, const char* name = 0 ); + virtual ~PrintStyle(); + + /** + Reimplement this method to actually print. + */ + virtual void print( const KABC::Addressee::List &contacts, PrintProgress* ) = 0; + + /** + Reimplement this method to provide a preview of what will + be printed. It returns an invalid QPixmap by default, + resulting in a message that no preview is available. + */ + const QPixmap& preview(); + + /** + Hide all style specific pages in the wizard. + */ + void hidePages(); + + /** + Show all style specific pages in the wizard. + */ + void showPages(); + + /** + Returns the preferred sort criterion field. + */ + KABC::Field* preferredSortField(); + + /** + Returns the preferred sort type. + + true = ascending + false = descending + */ + bool preferredSortType(); + + protected: + /** + Load the preview image from the kaddressbook data + directory. The image should be located in the subdirectory + "printing". Give only the file name without any prefix as + the parameter. + */ + bool setPreview( const QString& fileName ); + + /** + Set the preview image. + */ + void setPreview( const QPixmap& image ); + + /** + Set preferred sort options for this printing style. + */ + void setPreferredSortOptions( KABC::Field *field, bool ascending = true ); + + /** + Return the wizard object. + */ + PrintingWizard *wizard(); + + /** + Add additional page to the wizard e.g. a configuration page for + the style. + */ + void addPage( QWidget *page, const QString &title ); + + private: + PrintingWizard *mWizard; + QPixmap mPreview; + QPtrList<QWidget> mPageList; + QStringList mPageTitles; + + KABC::Field *mSortField; + bool mSortType; +}; + + +/** + The factories are used to have all object of the respective + print style created in one place. + This will maybe be changed to a template because of its simple + nature :-) +*/ +class PrintStyleFactory +{ + public: + PrintStyleFactory( PrintingWizard* parent, const char* name = 0 ); + virtual ~PrintStyleFactory(); + + virtual PrintStyle *create() const = 0; + + /** + Overload this method to provide a one-liner description + for your print style. + */ + virtual QString description() const = 0; + + protected: + PrintingWizard* mParent; + const char* mName; +}; + +} + +#endif diff --git a/kaddressbook/printing/selectionpage.cpp b/kaddressbook/printing/selectionpage.cpp new file mode 100644 index 000000000..bf6d71e00 --- /dev/null +++ b/kaddressbook/printing/selectionpage.cpp @@ -0,0 +1,169 @@ +/* + This file is part of KAddressBook. + Copyright (c) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk> + Tobias Koenig <tokoe@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include <kdialog.h> +#include <klocale.h> + +#include <qbuttongroup.h> +#include <qcombobox.h> +#include <qheader.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qlistview.h> +#include <qpushbutton.h> +#include <qradiobutton.h> +#include <qstringlist.h> +#include <qwhatsthis.h> + +#include "selectionpage.h" + +SelectionPage::SelectionPage( QWidget* parent, const char* name ) + : QWidget( parent, name ) +{ + setCaption( i18n( "Choose Which Contacts to Print" ) ); + + QVBoxLayout *topLayout = new QVBoxLayout( this, KDialog::marginHint(), + KDialog::spacingHint() ); + + QLabel *label = new QLabel( i18n( "Which contacts do you want to print?" ), this ); + topLayout->addWidget( label ); + + mButtonGroup = new QButtonGroup( this ); + mButtonGroup->setFrameShape( QButtonGroup::NoFrame ); + mButtonGroup->setColumnLayout( 0, Qt::Vertical ); + mButtonGroup->layout()->setSpacing( KDialog::spacingHint() ); + mButtonGroup->layout()->setMargin( KDialog::marginHint() ); + + QGridLayout *groupLayout = new QGridLayout( mButtonGroup->layout() ); + groupLayout->setAlignment( Qt::AlignTop ); + + mUseWholeBook = new QRadioButton( i18n( "&All contacts" ), mButtonGroup ); + mUseWholeBook->setChecked( true ); + QWhatsThis::add( mUseWholeBook, i18n( "Print the entire address book" ) ); + groupLayout->addWidget( mUseWholeBook, 0, 0 ); + + mUseSelection = new QRadioButton( i18n( "&Selected contacts" ), mButtonGroup ); + QWhatsThis::add( mUseSelection, i18n( "Only print contacts selected in KAddressBook.\n" + "This option is disabled if no contacts are selected." ) ); + groupLayout->addWidget( mUseSelection, 1, 0 ); + + mUseFilters = new QRadioButton( i18n( "Contacts matching &filter" ), mButtonGroup ); + QWhatsThis::add( mUseFilters, i18n( "Only print contacts matching the selected filter.\n" + "This option is disabled if you have not defined any filters." ) ); + groupLayout->addWidget( mUseFilters, 2, 0 ); + + mUseCategories = new QRadioButton( i18n( "Category &members" ), mButtonGroup ); + QWhatsThis::add( mUseCategories, i18n( "Only print contacts who are members of a category that is checked on the list to the left.\n" + "This option is disabled if you have no categories." ) ); + groupLayout->addWidget( mUseCategories, 3, 0, Qt::AlignTop ); + + mFiltersCombo = new QComboBox( false, mButtonGroup ); + QWhatsThis::add( mFiltersCombo, i18n( "Select a filter to decide which contacts to print." ) ); + groupLayout->addWidget( mFiltersCombo, 2, 1 ); + + mCategoriesView = new QListView( mButtonGroup ); + mCategoriesView->addColumn( "" ); + mCategoriesView->header()->hide(); + QWhatsThis::add( mCategoriesView, i18n( "Check the categories whose members you want to print." ) ); + groupLayout->addWidget( mCategoriesView, 3, 1 ); + + topLayout->addWidget( mButtonGroup ); + + connect( mFiltersCombo, SIGNAL( activated(int) ), SLOT( filterChanged(int) ) ); + connect( mCategoriesView, SIGNAL( clicked(QListViewItem*) ), SLOT( categoryClicked(QListViewItem*) ) ); +} + +SelectionPage::~SelectionPage() +{ +} + +void SelectionPage::setFilters( const QStringList& filters ) +{ + mFiltersCombo->clear(); + mFiltersCombo->insertStringList( filters ); + + mUseFilters->setEnabled( filters.count() > 0 ); +} + +QString SelectionPage::filter() const +{ + return mFiltersCombo->currentText(); +} + +bool SelectionPage::useFilters() const +{ + return mUseFilters->isChecked(); +} + +void SelectionPage::setCategories( const QStringList& list ) +{ + QStringList::ConstIterator it; + for ( it = list.begin(); it != list.end(); ++it ) + new QCheckListItem( mCategoriesView, *it, QCheckListItem::CheckBox ); + + mUseCategories->setEnabled( list.count() > 0 ); +} + +QStringList SelectionPage::categories() const +{ + QStringList list; + + QListViewItemIterator it( mCategoriesView ); + for ( ; it.current(); ++it ) { + QCheckListItem *qcli = static_cast<QCheckListItem*>(it.current()); + if ( qcli->isOn() ) + list.append( it.current()->text( 0 ) ); + } + + return list; +} + +bool SelectionPage::useCategories() +{ + return mUseCategories->isChecked(); +} + +void SelectionPage::setUseSelection( bool value ) +{ + mUseSelection->setEnabled( value ); +} + +bool SelectionPage::useSelection() const +{ + return mUseSelection->isChecked(); +} + +void SelectionPage::filterChanged( int ) +{ + mUseFilters->setChecked( true ); +} + +void SelectionPage::categoryClicked( QListViewItem *i ) +{ + QCheckListItem *qcli = static_cast<QCheckListItem*>( i ); + if ( i && qcli->isOn() ) + mUseCategories->setChecked( true ); +} + +#include "selectionpage.moc" diff --git a/kaddressbook/printing/selectionpage.h b/kaddressbook/printing/selectionpage.h new file mode 100644 index 000000000..b4dab1f6c --- /dev/null +++ b/kaddressbook/printing/selectionpage.h @@ -0,0 +1,68 @@ +/* + This file is part of KAddressBook. + Copyright (c) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk> + Tobias Koenig <tokoe@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ +#ifndef SELECTIONPAGE_H +#define SELECTIONPAGE_H + +#include <qwidget.h> + +class QButtonGroup; +class QComboBox; +class QListView; +class QListViewItem; +class QRadioButton; + +class SelectionPage : public QWidget +{ + Q_OBJECT + + public: + SelectionPage( QWidget* parent = 0, const char* name = 0 ); + ~SelectionPage(); + + void setFilters( const QStringList& ); + QString filter() const; + bool useFilters() const; + + void setCategories( const QStringList& ); + QStringList categories() const; + bool useCategories(); + + void setUseSelection( bool value ); + bool useSelection() const; + + private slots: + void filterChanged( int ); + void categoryClicked( QListViewItem * i ); + + private: + QButtonGroup* mButtonGroup; + QRadioButton* mUseCategories; + QRadioButton* mUseFilters; + QRadioButton* mUseWholeBook; + QRadioButton* mUseSelection; + QComboBox* mFiltersCombo; + QListView* mCategoriesView; +}; + +#endif // SELECTIONPAGE_H diff --git a/kaddressbook/printing/stylepage.cpp b/kaddressbook/printing/stylepage.cpp new file mode 100644 index 000000000..9e1be7bd1 --- /dev/null +++ b/kaddressbook/printing/stylepage.cpp @@ -0,0 +1,162 @@ +/* + This file is part of KAddressBook. + Copyright (c) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk> + Tobias Koenig <tokoe@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include <qbuttongroup.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qpixmap.h> +#include <qradiobutton.h> + +#include <kcombobox.h> +#include <kdialog.h> +#include <klocale.h> + +#include "stylepage.h" + +StylePage::StylePage( KABC::AddressBook *ab, QWidget* parent, const char* name ) + : QWidget( parent, name ), mAddressBook( ab ) +{ + initGUI(); + + initFieldCombo(); + + mSortTypeCombo->insertItem( i18n( "Ascending" ) ); + mSortTypeCombo->insertItem( i18n( "Descending" ) ); + + connect( mStyleCombo, SIGNAL( activated( int ) ), SIGNAL( styleChanged( int ) ) ); +} + +StylePage::~StylePage() +{ +} + +void StylePage::setPreview( const QPixmap &pixmap ) +{ + if ( pixmap.isNull() ) + mPreview->setText( i18n( "(No preview available.)" ) ); + else + mPreview->setPixmap( pixmap ); +} + +void StylePage::addStyleName( const QString &name ) +{ + mStyleCombo->insertItem( name ); +} + +void StylePage::clearStyleNames() +{ + mStyleCombo->clear(); +} + +void StylePage::setSortField( KABC::Field *field ) +{ + mFieldCombo->setCurrentText( field->label() ); +} + +void StylePage::setSortAscending( bool value ) +{ + if ( value ) + mSortTypeCombo->setCurrentItem( 0 ); + else + mSortTypeCombo->setCurrentItem( 1 ); +} + +KABC::Field* StylePage::sortField() +{ + if ( mFieldCombo->currentItem() == -1 ) + return mFields[ 0 ]; + + return mFields[ mFieldCombo->currentItem() ]; +} + +bool StylePage::sortAscending() +{ + return ( mSortTypeCombo->currentItem() == 0 ); +} + +void StylePage::initFieldCombo() +{ + if ( !mAddressBook ) + return; + + mFieldCombo->clear(); + + mFields = mAddressBook->fields( KABC::Field::All ); + KABC::Field::List::ConstIterator it; + for ( it = mFields.begin(); it != mFields.end(); ++it ) + mFieldCombo->insertItem( (*it)->label() ); +} + +void StylePage::initGUI() +{ + setCaption( i18n( "Choose Printing Style" ) ); + + QGridLayout *topLayout = new QGridLayout( this, 2, 2, KDialog::marginHint(), + KDialog::spacingHint() ); + + QLabel *label = new QLabel( i18n( "What should the print look like?\n" + "KAddressBook has several printing styles, designed for different purposes.\n" + "Choose the style that suits your needs below." ), this ); + topLayout->addMultiCellWidget( label, 0, 0, 0, 1 ); + + QButtonGroup *group = new QButtonGroup( i18n( "Sorting" ), this ); + group->setColumnLayout( 0, Qt::Vertical ); + QGridLayout *sortLayout = new QGridLayout( group->layout(), 2, 2, + KDialog::spacingHint() ); + sortLayout->setAlignment( Qt::AlignTop ); + + label = new QLabel( i18n( "Criterion:" ), group ); + sortLayout->addWidget( label, 0, 0 ); + + mFieldCombo = new KComboBox( false, group ); + sortLayout->addWidget( mFieldCombo, 0, 1 ); + + label = new QLabel( i18n( "Order:" ), group ); + sortLayout->addWidget( label, 1, 0 ); + + mSortTypeCombo = new KComboBox( false, group ); + sortLayout->addWidget( mSortTypeCombo, 1, 1 ); + + topLayout->addWidget( group, 1, 0 ); + + group = new QButtonGroup( i18n( "Print Style" ), this ); + group->setColumnLayout( 0, Qt::Vertical ); + QVBoxLayout *styleLayout = new QVBoxLayout( group->layout(), + KDialog::spacingHint() ); + + mStyleCombo = new KComboBox( false, group ); + styleLayout->addWidget( mStyleCombo ); + + mPreview = new QLabel( group ); + QFont font( mPreview->font() ); + font.setPointSize( 20 ); + mPreview->setFont( font ); + mPreview->setScaledContents( true ); + mPreview->setAlignment( int( QLabel::WordBreak | QLabel::AlignCenter ) ); + styleLayout->addWidget( mPreview ); + + topLayout->addWidget( group, 1, 1 ); +} + +#include "stylepage.moc" diff --git a/kaddressbook/printing/stylepage.h b/kaddressbook/printing/stylepage.h new file mode 100644 index 000000000..d84394979 --- /dev/null +++ b/kaddressbook/printing/stylepage.h @@ -0,0 +1,102 @@ +/* + This file is part of KAddressBook. + Copyright (c) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk> + Tobias Koenig <tokoe@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#ifndef STYLEPAGE_H +#define STYLEPAGE_H + +#include <qwidget.h> + +#include <kabc/addressbook.h> +#include <kabc/field.h> + +class QLabel; +class QPixmap; +class QRadioButton; +class KComboBox; + +class StylePage : public QWidget +{ + Q_OBJECT + + public: + StylePage( KABC::AddressBook *ab, QWidget* parent = 0, const char* name = 0 ); + ~StylePage(); + + /** + * Set a preview image. If @ref pixmap is 'null' a text will + * be displayed instead. + */ + void setPreview( const QPixmap &pixmap ); + + /** + * Add a style name. + */ + void addStyleName( const QString &name ); + + /** + * Clear the style name list. + */ + void clearStyleNames(); + + /** + * Set the sort criterion field. + */ + void setSortField( KABC::Field *field ); + + /** + * Returns the sort criterion field. + */ + KABC::Field* sortField(); + + /** + * Set the sort type. + */ + void setSortAscending( bool value = true ); + + /** + * Returns whether the sort type is ascending. + */ + bool sortAscending(); + + signals: + /** + * This signal is emmited when the user selects a new style in the + * style combo box. + */ + void styleChanged( int index ); + + private: + void initGUI(); + void initFieldCombo(); + + KComboBox *mFieldCombo; + KComboBox *mSortTypeCombo; + KComboBox *mStyleCombo; + QLabel *mPreview; + + KABC::AddressBook *mAddressBook; + KABC::Field::List mFields; +}; + +#endif // STYLEPAGE_H |