Commit 9906d789 authored by Allen Winter's avatar Allen Winter
Browse files

Add a new "compact" print style

Code by Mario, Thanks!

REVIEW: 103868
MERGE: None
BUG: 290438
FIXED-IN: 4.9
parent 040c19f4
......@@ -30,12 +30,14 @@ set(kaddressbook_printing_SRCS
printing/printprogress.cpp
printing/printstyle.cpp
printing/ringbinderstyle.cpp
printing/compactstyle.cpp
printing/stylepage.cpp
)
kde4_add_ui_files(kaddressbook_printing_SRCS
printing/rbs_appearance.ui
printing/ds_appearance.ui
printing/compactstyle.ui
)
set(kaddressbook_xxport_SRCS
......
/*
This file is part of KAddressBook.
Copyright (c) 2011 Mario Scheel <zweistein12@gmx.de>
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 <QtGui/QPrinter>
#include <QtGui/QTextDocument>
#include <QtGui/QCheckBox>
#include <QCheckBox>
#include <kabc/addressee.h>
#include <kdebug.h>
#include <klocale.h>
#include "contactfields.h"
#include "printingwizard.h"
#include "printprogress.h"
#include "printstyle.h"
#include "compactstyle.h"
#include "ui_compactstyle.h"
using namespace KABPrinting;
const char *CompactStyleConfigSectionName = "CompactStyle";
const char *WithAlternating = "WithAlternating";
const char *WithHomeAddress = "WithHomeAddress";
const char *WithBusinessAddress = "WithBusinessAddress";
const char *WithBirthday = "WithBirthday";
const char *WithEMail = "WithEMail";
const char *FirstColor = "FirstColor";
const char *SecondColor = "SecondColor";
namespace KABPrinting
{
class CompactStyleForm : public QWidget, public Ui::CompactStyleForm_Base
{
public:
explicit CompactStyleForm( QWidget *parent )
: QWidget( parent )
{
setObjectName( "AppearancePage" );
setupUi( this );
}
};
}
QString CompactStyle::contactsToHtml( const KABC::Addressee::List &contacts ) const
{
// collect the fields are need to print
ContactFields::Fields fields;
fields << ContactFields::FormattedName;
if (this->withHomeAddress) {
fields << ContactFields::HomeAddressStreet
<< ContactFields::HomeAddressPostalCode
<< ContactFields::HomeAddressLocality
<< ContactFields::HomePhone
<< ContactFields::MobilePhone;
};
if (this->withBusinessAddress) {
fields << ContactFields::BusinessAddressStreet
<< ContactFields::BusinessAddressPostalCode
<< ContactFields::BusinessAddressLocality
<< ContactFields::BusinessPhone;
};
if (this->withEMail) {
fields << ContactFields::PreferredEmail
<< ContactFields::Email2;
};
if (this->withBirthday) {
fields << ContactFields::Birthday;
};
QString content;
content += "<html>\n";
content += " <body>\n";
content += " <table style=\"font-size:50%; border-width: 0px; \"width=\"100%\">\n";
bool odd = false;
foreach ( const KABC::Addressee &contact, contacts ) {
// get the values
QStringList values;
foreach ( const ContactFields::Field field, fields) {
// we need only values with content
QString value = ContactFields::value( field, contact ).trimmed();
if (value.size() > 0)
values << value;
}
content += " <tr>\n";
QString style = "background-color:";
if ( this->withAlternating )
style += ( odd ) ? this->firstColor.name() : this->secondColor.name();
else
style += "#ffffff";
content += " <td style=\""+ style + ";\">" + values.join("; ") + "</td>\n";
content += " </tr>\n";
odd = !odd;
}
content += " </table>\n";
content += " </body>\n";
content += "</html>\n";
return content;
}
CompactStyle::CompactStyle( PrintingWizard *parent )
: PrintStyle( parent ),
mPageSettings( new CompactStyleForm( parent ) )
{
setPreview( "compact-style.png" );
setPreferredSortOptions( ContactFields::FormattedName, Qt::AscendingOrder );
addPage( mPageSettings, i18n( "Compact Style" ) );
connect(mPageSettings->cbAlternating, SIGNAL(clicked()), this, SLOT(setAlternatingColors()) );
// set the controls, with the values in config
KConfigGroup config( KGlobal::config(), CompactStyleConfigSectionName );
withAlternating = config.readEntry( WithAlternating, true );
withHomeAddress = config.readEntry( WithHomeAddress, true );
withBusinessAddress = config.readEntry( WithBusinessAddress, false );
withBirthday = config.readEntry( WithBirthday, true );
withEMail = config.readEntry( WithEMail, true );
mPageSettings->cbFirst->setColor( config.readEntry( FirstColor, QColor( 220, 220, 220 ) ) );
mPageSettings->cbSecond->setColor( config.readEntry( SecondColor, QColor( 255, 255, 255 ) ) );
mPageSettings->cbAlternating->setChecked( withAlternating );
mPageSettings->cbWithHomeAddress->setChecked( withHomeAddress );
mPageSettings->cbWithBusinessAddress->setChecked( withBusinessAddress );
mPageSettings->cbWithBirthday->setChecked( withBirthday );
mPageSettings->cbWithEMail->setChecked( withEMail );
// set up the color boxes
setAlternatingColors();
}
CompactStyle::~CompactStyle()
{
}
void CompactStyle::print( const KABC::Addressee::List &contacts, PrintProgress *progress )
{
// from UI to members
withAlternating = mPageSettings->cbAlternating->isChecked();
firstColor = mPageSettings->cbFirst->color();
secondColor = mPageSettings->cbSecond->color();
withHomeAddress = mPageSettings->cbWithHomeAddress->isChecked();
withBusinessAddress = mPageSettings->cbWithBusinessAddress->isChecked();
withBirthday = mPageSettings->cbWithBirthday->isChecked();
withEMail = mPageSettings->cbWithEMail->isChecked();
// to config
KConfigGroup config( KGlobal::config(), CompactStyleConfigSectionName );
config.writeEntry( WithAlternating, withAlternating );
config.writeEntry( FirstColor, firstColor );
config.writeEntry( SecondColor, secondColor );
config.writeEntry( WithHomeAddress, withHomeAddress );
config.writeEntry( WithBusinessAddress, withBusinessAddress );
config.writeEntry( WithBirthday, withBirthday );
config.writeEntry( WithEMail, withEMail );
config.sync();
// print
QPrinter *printer = wizard()->printer();
printer->setPageMargins( 20, 20, 20, 20, QPrinter::DevicePixel );
progress->addMessage( i18n( "Setting up document" ) );
const QString html = contactsToHtml( contacts );
QTextDocument document;
document.setHtml( html );
progress->addMessage( i18n( "Printing" ) );
document.print( printer );
progress->addMessage( i18nc( "Finished printing", "Done" ) );
}
void CompactStyle::setAlternatingColors()
{
mPageSettings->cbFirst->setEnabled( mPageSettings->cbAlternating->isChecked() );
mPageSettings->lbCbFirst->setEnabled( mPageSettings->cbAlternating->isChecked() );
mPageSettings->cbSecond->setEnabled( mPageSettings->cbAlternating->isChecked() );
mPageSettings->lbCbSecond->setEnabled( mPageSettings->cbAlternating->isChecked() );
}
CompactStyleFactory::CompactStyleFactory( PrintingWizard *parent )
: PrintStyleFactory( parent )
{
}
PrintStyle *CompactStyleFactory::create() const
{
return new CompactStyle( mParent );
}
QString CompactStyleFactory::description() const
{
return i18n( "Compact Printing Style" );
}
#include "compactstyle.moc"
/*
This file is part of KAddressBook.
Copyright (c) 2011 Mario Scheel <zweistein12@gmx.de>
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 COMPACTSTYLE_H
#define COMPACTSTYLE_H
#include <QtGui/QFont>
#include "printstyle.h"
#include "contactfields.h"
namespace KABPrinting {
class CompactStyleForm;
class CompactStyle : public PrintStyle
{
Q_OBJECT
public:
CompactStyle( PrintingWizard *parent );
~CompactStyle();
/**
* prints the contacts
*/
void print( const KABC::Addressee::List&, PrintProgress* );
private:
QString contactsToHtml( const KABC::Addressee::List &contacts ) const;
CompactStyleForm *mPageSettings;
/**
* various settings
*/
bool withAlternating;
bool withBusinessAddress;
bool withHomeAddress;
bool withBirthday;
bool withEMail;
QColor firstColor;
QColor secondColor;
private Q_SLOTS:
/**
* Enable or disable the controls for color selection. The colors
* are needed for alternating background color of the rows.
*/
void setAlternatingColors();
};
class CompactStyleFactory : public PrintStyleFactory
{
public:
explicit CompactStyleFactory( PrintingWizard *parent );
PrintStyle *create() const;
QString description() const;
};
}
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CompactStyleForm_Base</class>
<widget class="QWidget" name="CompactStyleForm_Base">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>620</width>
<height>277</height>
</rect>
</property>
<property name="windowTitle">
<string>Appearance</string>
</property>
<layout class="QGridLayout">
<property name="margin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="1" column="0">
<widget class="QGroupBox" name="gbFields">
<property name="title">
<string>Fields</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="cbWithHomeAddress">
<property name="toolTip">
<string>print the home address, with home phone number and mobil phone number</string>
</property>
<property name="whatsThis">
<string>print the home address, with home phone number and mobil phone number</string>
</property>
<property name="text">
<string>with home address</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbWithBusinessAddress">
<property name="toolTip">
<string>print the business address, with business phone number</string>
</property>
<property name="whatsThis">
<string>print the business address, with business phone number</string>
</property>
<property name="text">
<string>with business address</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbWithBirthday">
<property name="toolTip">
<string>print the birthday</string>
</property>
<property name="whatsThis">
<string>print the birthday</string>
</property>
<property name="text">
<string>with birthday</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbWithEMail">
<property name="toolTip">
<string>prints the e-mail and e-mail2 field</string>
</property>
<property name="whatsThis">
<string>prints the e-mail and e-mail2 field</string>
</property>
<property name="text">
<string>with e-mail</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="gbColors">
<property name="title">
<string>GroupBox</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="1">
<widget class="KColorButton" name="cbSecond"/>
</item>
<item row="1" column="1">
<widget class="KColorButton" name="cbFirst"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbCbFirst">
<property name="toolTip">
<string>the first color, if alternating color is checked</string>
</property>
<property name="whatsThis">
<string>the first color, if alternating color is checked</string>
</property>
<property name="text">
<string>first color</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbCbSecond">
<property name="toolTip">
<string>the second color, if alternating color is checked</string>
</property>
<property name="whatsThis">
<string>the second color, if alternating color is checked</string>
</property>
<property name="text">
<string>second color</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="cbAlternating">
<property name="toolTip">
<string>Change the background color of every row</string>
</property>
<property name="whatsThis">
<string>Change the background color of every row</string>
</property>
<property name="text">
<string>Alternating the background color</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KColorButton</class>
<extends>QPushButton</extends>
<header>kcolorbutton.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
install(
FILES detailed-style.png mike-style.png ringbinder-style.png
FILES detailed-style.png mike-style.png ringbinder-style.png compact-style.png
DESTINATION ${DATA_INSTALL_DIR}/kaddressbook/printing
)
......@@ -36,6 +36,7 @@
#include "detailledstyle.h"
#include "mikesstyle.h"
#include "ringbinderstyle.h"
#include "compactstyle.h"
#include <KApplication>
#include <KDebug>
......@@ -99,6 +100,7 @@ void PrintingWizard::registerStyles()
mStyleFactories.append( new DetailledPrintStyleFactory( this ) );
mStyleFactories.append( new MikesStyleFactory( this ) );
mStyleFactories.append( new RingBinderPrintStyleFactory( this ) );
mStyleFactories.append( new CompactStyleFactory( this ) );
mStylePage->clearStyleNames();
for ( int i = 0; i < mStyleFactories.count(); ++i ) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment