• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kaddressbook

  • sources
  • kde-4.14
  • kdepim
  • kaddressbook
  • printing
  • grantlee
grantleeprintstyle.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013-2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "grantleeprintstyle.h"
19 #include "contactfields.h"
20 #include "printingwizard.h"
21 #include "printprogress.h"
22 #include "printstyle.h"
23 #include "grantleeprint.h"
24 
25 #include <KABC/Addressee>
26 
27 #include <KDebug>
28 #include <KLocalizedString>
29 
30 #include <QPrinter>
31 #include <QTextDocument>
32 #include <QFile>
33 #include <QDir>
34 
35 using namespace KABPrinting;
36 
37 
38 GrantleePrintStyle::GrantleePrintStyle( const QString &themePath, PrintingWizard *parent )
39  : PrintStyle( parent )
40 {
41  mGrantleePrint = new GrantleePrint(themePath, this);
42  QFile previewFile(QString(themePath + QDir::separator() + QLatin1String("preview.png")));
43  if (previewFile.exists()) {
44  setPreview( previewFile.fileName() );
45  }
46  setPreferredSortOptions( ContactFields::FormattedName, Qt::AscendingOrder );
47 }
48 
49 GrantleePrintStyle::~GrantleePrintStyle()
50 {
51 }
52 
53 void GrantleePrintStyle::print( const KABC::Addressee::List &contacts, PrintProgress *progress )
54 {
55  QPrinter *printer = wizard()->printer();
56  printer->setPageMargins( 20, 20, 20, 20, QPrinter::DevicePixel );
57 
58  progress->addMessage( i18n( "Setting up document" ) );
59 
60  const QString html = mGrantleePrint->contactsToHtml( contacts );
61 
62  QTextDocument document;
63  document.setHtml( html );
64 
65  progress->addMessage( i18n( "Printing" ) );
66 
67  document.print( printer );
68 
69  progress->addMessage( i18nc( "Finished printing", "Done" ) );
70 }
71 
72 GrantleeStyleFactory::GrantleeStyleFactory( const QString &name,const QString &themePath, PrintingWizard *parent )
73  : PrintStyleFactory( parent ),
74  mThemePath(themePath),
75  mName(name)
76 {
77 }
78 
79 PrintStyle *GrantleeStyleFactory::create() const
80 {
81  return new GrantleePrintStyle( mThemePath, mParent );
82 }
83 
84 QString GrantleeStyleFactory::description() const
85 {
86  return mName;
87 }
88 
KABPrinting::PrintStyleFactory::mParent
PrintingWizard * mParent
Definition: printstyle.h:186
contactfields.h
QPrinter
KABPrinting::GrantleeStyleFactory::GrantleeStyleFactory
GrantleeStyleFactory(const QString &name, const QString &themePath, PrintingWizard *parent)
Definition: grantleeprintstyle.cpp:72
KABPrinting::PrintingWizard
The PrintingWizard combines pages common for all print styles and those provided by the respective st...
Definition: printingwizard.h:55
QFile::fileName
QString fileName() const
QFile::exists
bool exists() const
grantleeprint.h
KABPrinting::PrintStyle::setPreferredSortOptions
void setPreferredSortOptions(ContactFields::Field, Qt::SortOrder sortOrder=Qt::AscendingOrder)
Sets the preferred sort options for this printing style.
Definition: printstyle.cpp:112
QDir::separator
QChar separator()
QFile
KABPrinting::GrantleePrintStyle::GrantleePrintStyle
GrantleePrintStyle(const QString &themePath, PrintingWizard *parent)
Definition: grantleeprintstyle.cpp:38
KABPrinting::PrintStyle::setPreview
bool setPreview(const QString &fileName)
Loads the preview image from the kaddressbook data directory.
Definition: printstyle.cpp:56
KABPrinting::PrintStyle
The abstract interface to the PrintingWizards style objects.
Definition: printstyle.h:67
ContactFields::FormattedName
Definition: contactfields.h:36
printstyle.h
KABPrinting::GrantleeStyleFactory::create
PrintStyle * create() const
Definition: grantleeprintstyle.cpp:79
QString
KABPrinting::PrintStyle::wizard
PrintingWizard * wizard() const
Returns the printing wizard that is responsible for this style.
Definition: printstyle.cpp:75
KABPrinting::GrantleeStyleFactory::description
QString description() const
Overload this method to provide a one-liner description for your print style.
Definition: grantleeprintstyle.cpp:84
grantleeprintstyle.h
QPrinter::setPageMargins
void setPageMargins(qreal left, qreal top, qreal right, qreal bottom, Unit unit)
printprogress.h
printingwizard.h
KABPrinting::GrantleePrintStyle::print
void print(const KABC::Addressee::List &, PrintProgress *)
This method must be reimplemented to actually print something.
Definition: grantleeprintstyle.cpp:53
KABPrinting::PrintProgress::addMessage
void addMessage(const QString &)
Add a message to the message log.
Definition: printprogress.cpp:61
QLatin1String
QTextDocument
KABPrinting::PrintProgress
This defines a simple widget to display print progress information.
Definition: printprogress.h:41
KABPrinting::GrantleePrint::contactsToHtml
QString contactsToHtml(const KABC::Addressee::List &contacts)
Definition: grantleeprint.cpp:64
QTextDocument::setHtml
void setHtml(const QString &html)
KABPrinting::PrintStyleFactory
The factories are used to have all object of the respective print style created in one place...
Definition: printstyle.h:171
KABPrinting::GrantleePrintStyle
Definition: grantleeprintstyle.h:29
KABPrinting::GrantleePrintStyle::~GrantleePrintStyle
~GrantleePrintStyle()
Definition: grantleeprintstyle.cpp:49
QTextDocument::print
void print(QPrinter *printer) const
KABPrinting::PrintingWizard::printer
QPrinter * printer()
Returns the printer to use for printing.
Definition: printingwizard.cpp:203
KABPrinting::GrantleePrint
Definition: grantleeprint.h:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:34 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kaddressbook

Skip menu "kaddressbook"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal