30 #include "ui_ds_appearance.h"
36 #include <KLocalizedString>
40 #include <QTextDocument>
42 using namespace KABPrinting;
71 content +=
QLatin1String(
" font-family: Fixed, monospace;\n");
76 foreach (
const KABC::Addressee &contact, contacts ) {
77 QString name = contact.realName();
78 if ( !contact.title().isEmpty() || !contact.role().isEmpty() ) {
80 if ( !contact.title().isEmpty() ) {
81 content << contact.title();
83 if ( !contact.role().isEmpty() ) {
84 content << contact.role();
89 const QString birthday = KGlobal::locale()->formatDate( contact.birthday().date(),
94 if ( !contact.organization().isEmpty() ) {
96 block.header = i18n(
"Organization:" );
97 block.entries.append( contact.organization() );
102 if ( !contact.emails().isEmpty() ) {
104 block.header = ( contact.emails().count() == 1 ?
105 i18n(
"Email address:" ) :
106 i18n(
"Email addresses:" ) );
107 block.entries = contact.emails();
112 if ( !contact.phoneNumbers().isEmpty() ) {
113 const KABC::PhoneNumber::List numbers = contact.phoneNumbers();
116 block.header = ( numbers.count() == 1 ?
117 i18n(
"Telephone:" ) :
118 i18n(
"Telephones:" ) );
120 foreach (
const KABC::PhoneNumber &number, numbers ) {
122 block.entries.append( line );
128 if ( contact.url().isValid() ) {
130 block.header = i18n(
"Web page:" );
131 block.entries.append( contact.url().prettyUrl() );
136 if ( !contact.addresses().isEmpty() ) {
137 const KABC::Address::List addresses = contact.addresses();
139 foreach (
const KABC::Address &address, addresses ) {
142 switch ( address.type() ) {
143 case KABC::Address::Dom:
144 block.header = i18n(
"Domestic Address" );
146 case KABC::Address::Intl:
147 block.header = i18n(
"International Address" );
149 case KABC::Address::Postal:
150 block.header = i18n(
"Postal Address" );
152 case KABC::Address::Parcel:
153 block.header = i18n(
"Parcel Address" );
155 case KABC::Address::Home:
156 block.header = i18n(
"Home Address" );
158 case KABC::Address::Work:
159 block.header = i18n(
"Work Address" );
161 case KABC::Address::Pref:
163 block.header = i18n(
"Preferred Address" );
167 block.entries = address.formattedAddress().split(
QLatin1Char(
'\n'), QString::KeepEmptyParts );
172 if ( !contact.note().isEmpty() ) {
174 block.header = i18n(
"Notes:" );
175 block.entries = contact.note().split(
QLatin1Char(
'\n'), QString::KeepEmptyParts );
181 content +=
QLatin1String(
" <table style=\"border-width: 0px; border-spacing: 0px; "
182 "page-break-inside: avoid\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n");
184 content +=
QLatin1String(
" <td style=\"color: ") + settings.headerTextColor +
185 QLatin1String(
";\" bgcolor=\"") + settings.headerBackgroundColor +
188 content += QLatin1String(
" <td style=\"color: ") + settings.headerTextColor +
189 QLatin1String(
";\" align=\"right\" bgcolor=\"") + settings.headerBackgroundColor +
190 QLatin1String(
"\" style=\"padding-right: 20px\">") +
191 birthday + QLatin1String(
"</td>\n");
192 content += QLatin1String(
" </tr>\n");
194 for (
int i = 0; i < blocks.
count(); i += 2 ) {
196 content += QLatin1String(
" <tr>\n");
197 content += QLatin1String(
" <td> </td>\n");
198 content += QLatin1String(
" <td> </td>\n");
199 content += QLatin1String(
" </tr>\n");
202 const ContactBlock leftBlock = blocks.
at( i );
203 const ContactBlock rightBlock = ( ( i + 1 < blocks.
count() ) ?
207 content += QLatin1String(
" <tr>\n");
208 content += QLatin1String(
" <td>") + leftBlock.header + QLatin1String(
"</td>\n");
209 content += QLatin1String(
" <td>") + rightBlock.header + QLatin1String(
"</td>\n");
210 content += QLatin1String(
" </tr>\n");
212 const int maxLines = qMax( leftBlock.entries.count(), rightBlock.entries.count() );
213 for (
int j = 0; j < maxLines; ++j ) {
216 if ( j < leftBlock.entries.count() ) {
217 leftLine = leftBlock.entries.at( j );
220 if ( j < rightBlock.entries.count() ) {
221 rightLine = rightBlock.entries.at( j );
224 content += QLatin1String(
" <tr>\n");
225 content += QLatin1String(
" <td class=\"indented\">") + leftLine + QLatin1String(
"</td>\n");
226 content += QLatin1String(
" <td class=\"indented\">") + rightLine + QLatin1String(
"</td>\n");
227 content += QLatin1String(
" </tr>\n");
232 content += QLatin1String(
" <tr>\n");
233 content += QLatin1String(
" <td> </td>\n");
234 content += QLatin1String(
" <td> </td>\n");
235 content += QLatin1String(
" </tr>\n");
236 content += QLatin1String(
" </table>\n");
244 class KABPrinting::AppearancePage :
public QWidget,
public Ui::AppearancePage_Base
247 AppearancePage(
QWidget *parent )
256 :
PrintStyle( parent ), mPageAppearance( new AppearancePage( parent ) )
261 addPage( mPageAppearance, i18n(
"Detailed Print Style - Appearance" ) );
265 mPageAppearance->kcbHeaderBGColor->
268 mPageAppearance->kcbHeaderTextColor->
271 mPageAppearance->layout()->setMargin( KDialog::marginHint() );
272 mPageAppearance->layout()->setSpacing( KDialog::spacingHint() );
281 progress->
addMessage( i18n(
"Setting up colors" ) );
284 const QColor headerBackgroundColor = mPageAppearance->kcbHeaderBGColor->color();
285 const QColor headerForegroundColor = mPageAppearance->kcbHeaderTextColor->color();
292 ColorSettings settings;
293 settings.headerBackgroundColor = headerBackgroundColor.
name();
294 settings.headerTextColor = headerForegroundColor.
name();
298 progress->
addMessage( i18n(
"Setting up document" ) );
307 document.
print( printer );
309 progress->
addMessage( i18nc(
"Finished printing",
"Done" ) );
324 return i18n(
"Detailed Style" );
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...
const T & at(int i) const
QString join(const QString &separator) const
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.
int count(const T &value) const
void append(const T &value)
const char * ContactHeaderBGColor
The abstract interface to the PrintingWizards style objects.
void setObjectName(const QString &name)
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.
void setHtml(const QString &html)
The factories are used to have all object of the respective print style created in one place...
QString fromLatin1(const char *str, int size)
void print(QPrinter *printer) const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
const char * ContactHeaderForeColor
QPrinter * printer()
Returns the printer to use for printing.
DetailledPrintStyle(PrintingWizard *parent)