30 #include "ui_ds_appearance.h"
32 #include <KApplication>
33 #include <KColorButton>
39 #include <KStandardDirs>
43 #include <QTextDocument>
45 using namespace KABPrinting;
53 typedef QList<ContactBlock> List;
61 QString headerTextColor;
62 QString headerBackgroundColor;
65 QString
contactsToHtml(
const KABC::Addressee::List &contacts,
const ColorSettings &settings )
69 content += QLatin1String(
"<html>\n");
70 content += QLatin1String(
" <head>\n");
71 content += QLatin1String(
" <style type=\"text/css\">\n");
72 content += QLatin1String(
" td.indented {\n");
73 content += QLatin1String(
" padding-left: 20px;\n");
74 content += QLatin1String(
" font-family: Fixed, monospace;\n");
75 content += QLatin1String(
" }\n");
76 content += QLatin1String(
" </style>\n");
77 content += QLatin1String(
" </head>\n");
78 content += QLatin1String(
" <body>\n");
79 foreach (
const KABC::Addressee &contact, contacts ) {
80 QString name = contact.realName();
81 if ( !contact.title().isEmpty() || !contact.role().isEmpty() ) {
83 if ( !contact.title().isEmpty() ) {
84 content << contact.title();
86 if ( !contact.role().isEmpty() ) {
87 content << contact.role();
89 name += QString::fromLatin1(
" (%1)" ).arg( content.join( QLatin1String(
", " ) ) );
92 const QString birthday = KGlobal::locale()->formatDate( contact.birthday().date(),
95 ContactBlock::List blocks;
97 if ( !contact.organization().isEmpty() ) {
99 block.header = i18n(
"Organization:" );
100 block.entries.append( contact.organization() );
102 blocks.append( block );
105 if ( !contact.emails().isEmpty() ) {
107 block.header = ( contact.emails().count() == 1 ?
108 i18n(
"Email address:" ) :
109 i18n(
"Email addresses:" ) );
110 block.entries = contact.emails();
112 blocks.append( block );
115 if ( !contact.phoneNumbers().isEmpty() ) {
116 const KABC::PhoneNumber::List numbers = contact.phoneNumbers();
119 block.header = ( numbers.count() == 1 ?
120 i18n(
"Telephone:" ) :
121 i18n(
"Telephones:" ) );
123 foreach (
const KABC::PhoneNumber &number, numbers ) {
124 const QString line = number.typeLabel() + QLatin1String(
": ") + number.number();
125 block.entries.append( line );
128 blocks.append( block );
131 if ( contact.url().isValid() ) {
133 block.header = i18n(
"Web page:" );
134 block.entries.append( contact.url().prettyUrl() );
136 blocks.append( block );
139 if ( !contact.addresses().isEmpty() ) {
140 const KABC::Address::List addresses = contact.addresses();
142 foreach (
const KABC::Address &address, addresses ) {
145 switch ( address.type() ) {
146 case KABC::Address::Dom:
147 block.header = i18n(
"Domestic Address" );
149 case KABC::Address::Intl:
150 block.header = i18n(
"International Address" );
152 case KABC::Address::Postal:
153 block.header = i18n(
"Postal Address" );
155 case KABC::Address::Parcel:
156 block.header = i18n(
"Parcel Address" );
158 case KABC::Address::Home:
159 block.header = i18n(
"Home Address" );
161 case KABC::Address::Work:
162 block.header = i18n(
"Work Address" );
164 case KABC::Address::Pref:
166 block.header = i18n(
"Preferred Address" );
168 block.header += QLatin1Char(
':');
170 block.entries = address.formattedAddress().split( QLatin1Char(
'\n'), QString::KeepEmptyParts );
171 blocks.append( block );
175 if ( !contact.note().isEmpty() ) {
177 block.header = i18n(
"Notes:" );
178 block.entries = contact.note().split( QLatin1Char(
'\n'), QString::KeepEmptyParts );
180 blocks.append( block );
184 content += QLatin1String(
" <table style=\"border-width: 0px; border-spacing: 0px; "
185 "page-break-inside: avoid\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n");
186 content += QLatin1String(
" <tr>\n");
187 content += QLatin1String(
" <td style=\"color: ") + settings.headerTextColor +
188 QLatin1String(
";\" bgcolor=\"") + settings.headerBackgroundColor +
189 QLatin1String(
"\" style=\"padding-left: 20px\">") +
190 name + QLatin1String(
"</td>\n");
191 content += QLatin1String(
" <td style=\"color: ") + settings.headerTextColor +
192 QLatin1String(
";\" align=\"right\" bgcolor=\"") + settings.headerBackgroundColor +
193 QLatin1String(
"\" style=\"padding-right: 20px\">") +
194 birthday + QLatin1String(
"</td>\n");
195 content += QLatin1String(
" </tr>\n");
197 for (
int i = 0; i < blocks.count(); i += 2 ) {
199 content += QLatin1String(
" <tr>\n");
200 content += QLatin1String(
" <td> </td>\n");
201 content += QLatin1String(
" <td> </td>\n");
202 content += QLatin1String(
" </tr>\n");
205 const ContactBlock leftBlock = blocks.at( i );
206 const ContactBlock rightBlock = ( ( i + 1 < blocks.count() ) ?
210 content += QLatin1String(
" <tr>\n");
211 content += QLatin1String(
" <td>") + leftBlock.header + QLatin1String(
"</td>\n");
212 content += QLatin1String(
" <td>") + rightBlock.header + QLatin1String(
"</td>\n");
213 content += QLatin1String(
" </tr>\n");
215 const int maxLines = qMax( leftBlock.entries.count(), rightBlock.entries.count() );
216 for (
int j = 0; j < maxLines; ++j ) {
217 QString leftLine, rightLine;
219 if ( j < leftBlock.entries.count() ) {
220 leftLine = leftBlock.entries.at( j );
223 if ( j < rightBlock.entries.count() ) {
224 rightLine = rightBlock.entries.at( j );
227 content += QLatin1String(
" <tr>\n");
228 content += QLatin1String(
" <td class=\"indented\">") + leftLine + QLatin1String(
"</td>\n");
229 content += QLatin1String(
" <td class=\"indented\">") + rightLine + QLatin1String(
"</td>\n");
230 content += QLatin1String(
" </tr>\n");
235 content += QLatin1String(
" <tr>\n");
236 content += QLatin1String(
" <td> </td>\n");
237 content += QLatin1String(
" <td> </td>\n");
238 content += QLatin1String(
" </tr>\n");
239 content += QLatin1String(
" </table>\n");
241 content += QLatin1String(
" </body>\n");
242 content += QLatin1String(
"</html>\n");
247 class KABPrinting::AppearancePage :
public QWidget,
public Ui::AppearancePage_Base
250 AppearancePage( QWidget *parent )
254 setObjectName( QLatin1String(
"AppearancePage") );
259 :
PrintStyle( parent ), mPageAppearance( new AppearancePage( parent ) )
261 setPreview( QLatin1String(
"detailed-style.png") );
264 addPage( mPageAppearance, i18n(
"Detailed Print Style - Appearance" ) );
268 mPageAppearance->kcbHeaderBGColor->
271 mPageAppearance->kcbHeaderTextColor->
274 mPageAppearance->layout()->setMargin( KDialog::marginHint() );
275 mPageAppearance->layout()->setSpacing( KDialog::spacingHint() );
284 progress->
addMessage( i18n(
"Setting up colors" ) );
287 const QColor headerBackgroundColor = mPageAppearance->kcbHeaderBGColor->color();
288 const QColor headerForegroundColor = mPageAppearance->kcbHeaderTextColor->color();
295 ColorSettings settings;
296 settings.headerBackgroundColor = headerBackgroundColor.name();
297 settings.headerTextColor = headerForegroundColor.name();
301 progress->
addMessage( i18n(
"Setting up document" ) );
305 QTextDocument document;
306 document.setHtml( html );
310 document.print( printer );
312 progress->
addMessage( i18nc(
"Finished printing",
"Done" ) );
327 return i18n(
"Detailed Style" );
330 #include "detailledstyle.moc"
PrintStyle * create() const
const char * ConfigSectionName
QString description() const
Overload this method to provide a one-liner description for your print style.
The PrintingWizard combines pages common for all print styles and those provided by the respective st...
void setPreferredSortOptions(ContactFields::Field, Qt::SortOrder sortOrder=Qt::AscendingOrder)
Sets the preferred sort options for this printing style.
QString contactsToHtml(const KABC::Addressee::List &contacts, const ColorSettings &settings)
void addPage(QWidget *page, const QString &title)
Adds an additional page to the printing wizard, e.g.
bool setPreview(const QString &fileName)
Loads the preview image from the kaddressbook data directory.
const char * ContactHeaderBGColor
The abstract interface to the PrintingWizards style objects.
DetailledPrintStyleFactory(PrintingWizard *parent)
PrintingWizard * wizard() const
Returns the printing wizard that is responsible for this style.
void addMessage(const QString &)
Add a message to the message log.
void print(const KABC::Addressee::List &contacts, PrintProgress *)
This method must be reimplemented to actually print something.
void setProgress(int)
Set the progress to a certain amount.
This defines a simple widget to display print progress information.
The factories are used to have all object of the respective print style created in one place...
const char * ContactHeaderForeColor
QPrinter * printer()
Returns the printer to use for printing.
DetailledPrintStyle(PrintingWizard *parent)