diff --git a/src/printing/detailled/detailledstyle.cpp b/src/printing/detailled/detailledstyle.cpp index 2ae36440..8f26cc61 100644 --- a/src/printing/detailled/detailledstyle.cpp +++ b/src/printing/detailled/detailledstyle.cpp @@ -1,325 +1,325 @@ /* This file is part of KAddressBook. Copyright (c) 1996-2002 Mirko Boehm 2009 Tobias Koenig 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 "detailledstyle.h" #include "printingwizard.h" #include "printprogress.h" #include "printstyle.h" #include "ui_ds_appearance.h" #include #include #include #include #include #include #include #include using namespace KABPrinting; static const char ConfigSectionName[] = "DetailedPrintStyle"; static const char ContactHeaderForeColor[] = "ContactHeaderForeColor"; static const char ContactHeaderBGColor[] = "ContactHeaderBGColor"; struct ContactBlock { typedef QVector List; QString header; QStringList entries; }; struct ColorSettings { QString headerTextColor; QString headerBackgroundColor; }; QString contactsToHtml(const KContacts::Addressee::List &contacts, const ColorSettings &settings) { QString content = QLatin1String("\n"); content += QLatin1String(" \n"); content += QLatin1String(" \n"); content += QLatin1String(" \n"); content += QLatin1String(" \n"); for (const KContacts::Addressee &contact : contacts) { QString name = contact.realName(); if (!contact.title().isEmpty() || !contact.role().isEmpty()) { - QStringList content; + QStringList contentAddress; if (!contact.title().isEmpty()) { - content << contact.title(); + contentAddress << contact.title(); } if (!contact.role().isEmpty()) { - content << contact.role(); + contentAddress << contact.role(); } - name += QStringLiteral(" (%1)").arg(content.join(QStringLiteral(", "))); + name += QStringLiteral(" (%1)").arg(contentAddress.join(QStringLiteral(", "))); } const QString birthday = QLocale().toString(contact.birthday().date(), QLocale::ShortFormat); ContactBlock::List blocks; if (!contact.organization().isEmpty()) { ContactBlock block; block.header = i18n("Organization:"); block.entries.append(contact.organization()); blocks.append(block); } if (!contact.emails().isEmpty()) { ContactBlock block; block.header = (contact.emails().count() == 1 ? i18n("Email address:") : i18n("Email addresses:")); block.entries = contact.emails(); blocks.append(block); } if (!contact.phoneNumbers().isEmpty()) { const KContacts::PhoneNumber::List numbers = contact.phoneNumbers(); ContactBlock block; block.header = (numbers.count() == 1 ? i18n("Telephone:") : i18n("Telephones:")); for (const KContacts::PhoneNumber &number : numbers) { const QString line = number.typeLabel() + QLatin1String(": ") + number.number(); block.entries.append(line); } blocks.append(block); } if (contact.url().isValid()) { ContactBlock block; block.header = i18n("Web page:"); block.entries.append(contact.url().url().toDisplayString()); blocks.append(block); } if (!contact.addresses().isEmpty()) { const KContacts::Address::List addresses = contact.addresses(); for (const KContacts::Address &address : addresses) { ContactBlock block; switch (address.type()) { case KContacts::Address::Dom: block.header = i18n("Domestic Address"); break; case KContacts::Address::Intl: block.header = i18n("International Address"); break; case KContacts::Address::Postal: block.header = i18n("Postal Address"); break; case KContacts::Address::Parcel: block.header = i18n("Parcel Address"); break; case KContacts::Address::Home: block.header = i18n("Home Address"); break; case KContacts::Address::Work: block.header = i18n("Work Address"); break; case KContacts::Address::Pref: default: block.header = i18n("Preferred Address"); } block.header += QLatin1Char(':'); #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) block.entries = address.formattedAddress().split(QLatin1Char('\n'), QString::KeepEmptyParts); #else block.entries = address.formattedAddress().split(QLatin1Char('\n'), Qt::KeepEmptyParts); #endif blocks.append(block); } } if (!contact.note().isEmpty()) { ContactBlock block; block.header = i18n("Notes:"); #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) block.entries = contact.note().split(QLatin1Char('\n'), QString::KeepEmptyParts); #else block.entries = contact.note().split(QLatin1Char('\n'), Qt::KeepEmptyParts); #endif blocks.append(block); } // add header content += QLatin1String(" \n"); content += QLatin1String(" \n"); content += QLatin1String(" \n"); content += QLatin1String(" \n"); content += QLatin1String(" \n"); for (int i = 0; i < blocks.count(); i += 2) { // add empty line for spacing content += QLatin1String(" \n"); content += QLatin1String(" \n"); content += QLatin1String(" \n"); content += QLatin1String(" \n"); // add real block data const ContactBlock leftBlock = blocks.at(i); const ContactBlock rightBlock = ((i + 1 < blocks.count()) ? blocks.at(i + 1) : ContactBlock()); content += QLatin1String(" \n"); content += QLatin1String(" \n"); content += QLatin1String(" \n"); content += QLatin1String(" \n"); const int maxLines = qMax(leftBlock.entries.count(), rightBlock.entries.count()); for (int j = 0; j < maxLines; ++j) { QString leftLine, rightLine; if (j < leftBlock.entries.count()) { leftLine = leftBlock.entries.at(j); } if (j < rightBlock.entries.count()) { rightLine = rightBlock.entries.at(j); } content += QLatin1String(" \n"); content += QLatin1String(" \n"); content += QLatin1String(" \n"); content += QLatin1String(" \n"); } } // add empty line for spacing content += QLatin1String(" \n"); content += QLatin1String(" \n"); content += QLatin1String(" \n"); content += QLatin1String(" \n"); content += QLatin1String("
") +name + QLatin1String("") +birthday + QLatin1String("
  
") + leftBlock.header + QLatin1String("") + rightBlock.header + QLatin1String("
") + leftLine + QLatin1String("") + rightLine + QLatin1String("
  
\n"); } content += QLatin1String(" \n"); content += QLatin1String("\n"); return content; } class KABPrinting::AppearancePage : public QWidget, public Ui::AppearancePage_Base { public: AppearancePage(QWidget *parent) : QWidget(parent) { setupUi(this); setObjectName(QStringLiteral("AppearancePage")); } }; DetailledPrintStyle::DetailledPrintStyle(PrintingWizard *parent) : PrintStyle(parent) , mPageAppearance(new AppearancePage(parent)) { setPreview(QStringLiteral("detailed-style.png")); setPreferredSortOptions(KAddressBookImportExport::KAddressBookImportExportContactFields::FormattedName, Qt::AscendingOrder); addPage(mPageAppearance, i18n("Detailed Print Style - Appearance")); KConfigGroup config(KSharedConfig::openConfig(), ConfigSectionName); mPageAppearance->kcbHeaderBGColor-> setColor(config.readEntry(ContactHeaderBGColor, QColor(Qt::black))); mPageAppearance->kcbHeaderTextColor-> setColor(config.readEntry(ContactHeaderForeColor, QColor(Qt::white))); } DetailledPrintStyle::~DetailledPrintStyle() { } void DetailledPrintStyle::print(const KContacts::Addressee::List &contacts, PrintProgress *progress) { progress->addMessage(i18n("Setting up colors")); progress->setProgress(0); const QColor headerBackgroundColor = mPageAppearance->kcbHeaderBGColor->color(); const QColor headerForegroundColor = mPageAppearance->kcbHeaderTextColor->color(); KConfigGroup config(KSharedConfig::openConfig(), ConfigSectionName); config.writeEntry(ContactHeaderForeColor, headerForegroundColor); config.writeEntry(ContactHeaderBGColor, headerBackgroundColor); config.sync(); ColorSettings settings; settings.headerBackgroundColor = headerBackgroundColor.name(); settings.headerTextColor = headerForegroundColor.name(); QPrinter *printer = wizard()->printer(); progress->addMessage(i18n("Setting up document")); const QString html = contactsToHtml(contacts, settings); QTextDocument document; document.setHtml(html); progress->addMessage(i18n("Printing")); document.print(printer); progress->addMessage(i18nc("Finished printing", "Done")); } DetailledPrintStyleFactory::DetailledPrintStyleFactory(PrintingWizard *parent) : PrintStyleFactory(parent) { } PrintStyle *DetailledPrintStyleFactory::create() const { return new DetailledPrintStyle(mParent); } QString DetailledPrintStyleFactory::description() const { return i18n("Detailed Style"); } diff --git a/src/printing/printstyle.cpp b/src/printing/printstyle.cpp index 32e8f78e..9396b67c 100644 --- a/src/printing/printstyle.cpp +++ b/src/printing/printstyle.cpp @@ -1,137 +1,137 @@ /* This file is part of KAddressBook. Copyright (c) 1996-2002 Mirko Boehm 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 "printstyle.h" #include "printingwizard.h" #include "kaddressbook_debug.h" #include #include #include #include using namespace KABPrinting; PrintStyle::PrintStyle(PrintingWizard *parent) : QObject(parent) , mWizard(parent) + , mSortField(KAddressBookImportExport::KAddressBookImportExportContactFields::GivenName) + , mSortOrder(Qt::AscendingOrder) { - mSortField = KAddressBookImportExport::KAddressBookImportExportContactFields::GivenName; - mSortOrder = Qt::AscendingOrder; } PrintStyle::~PrintStyle() { } const QPixmap &PrintStyle::preview() const { return mPreview; } void PrintStyle::setPreview(const QPixmap &image) { mPreview = image; } bool PrintStyle::setPreview(const QString &fileName) { QPixmap preview; const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("kaddressbook/printing/") + fileName); if (path.isEmpty()) { qCDebug(KADDRESSBOOK_LOG) << "cannot locate preview image " << fileName << " in appdata"; return false; } else { if (preview.load(path)) { setPreview(preview); return true; } else { qCDebug(KADDRESSBOOK_LOG) << "preview at '" << path << "' cannot be loaded."; return false; } } } PrintingWizard *PrintStyle::wizard() const { return mWizard; } void PrintStyle::addPage(QWidget *page, const QString &title) { if (!mPageList.contains(page)) { // not yet in the list mPageList.append(page); mPageTitles.append(title); KPageWidgetItem *item = new KPageWidgetItem(page, title); mPageItems.insert(page, item); mWizard->addPage(item); mWizard->setAppropriate(item, false); } } void PrintStyle::showPages() { QWidget *wdg = nullptr; for (QWidget *wdg2 : qAsConst(mPageList)) { mWizard->setAppropriate(mPageItems[ wdg2 ], true); wdg = wdg2; } mWizard->nextButton()->setEnabled(wdg); mWizard->finishButton()->setEnabled(!wdg); } void PrintStyle::hidePages() { for (QWidget *wdg : qAsConst(mPageList)) { mWizard->setAppropriate(mPageItems[ wdg ], false); } } void PrintStyle::setPreferredSortOptions(KAddressBookImportExport::KAddressBookImportExportContactFields::Field field, Qt::SortOrder sortOrder) { mSortField = field; mSortOrder = sortOrder; } KAddressBookImportExport::KAddressBookImportExportContactFields::Field PrintStyle::preferredSortField() const { return mSortField; } Qt::SortOrder PrintStyle::preferredSortOrder() const { return mSortOrder; } PrintStyleFactory::PrintStyleFactory(PrintingWizard *parent) : mParent(parent) { } PrintStyleFactory::~PrintStyleFactory() { }