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

korganizer

  • sources
  • kde-4.12
  • kdepim
  • korganizer
  • printing
calprinter.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 1998 Preston Brown <pbrown@kde.org>
5  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License along
18  with this program; if not, write to the Free Software Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  As a special exception, permission is given to link this program
22  with any edition of Qt, and distribute the resulting executable,
23  without including the source code for Qt in the source distribution.
24 */
25 
26 #include "calprinter.h"
27 #include "calprinter.moc"
28 #include "calprintdefaultplugins.h"
29 #include "korganizer/corehelper.h"
30 
31 #include <KMessageBox>
32 #include <KPrintPreview>
33 #include <KStandardGuiItem>
34 #include <KVBox>
35 #include <kdeprintdialog.h> //krazy:exclude=camelcase TODO wait for kdelibs4.10
36 
37 #include <QButtonGroup>
38 #include <QGridLayout>
39 #include <QGroupBox>
40 #include <QPrintDialog>
41 #include <QSplitter>
42 #include <QStackedWidget>
43 #include <QVBoxLayout>
44 
45 CalPrinter::CalPrinter( QWidget *parent, const Akonadi::ETMCalendar::Ptr &calendar,
46  KOrg::CoreHelper *helper, bool uniqItem )
47  : QObject( parent ), mUniqItem( uniqItem )
48 {
49  mParent = parent;
50  mConfig = new KConfig( QLatin1String("korganizer_printing.rc"), KConfig::SimpleConfig );
51  mCoreHelper = helper;
52 
53  init( calendar );
54 }
55 
56 CalPrinter::~CalPrinter()
57 {
58  mPrintPlugins.clear();
59  delete mConfig;
60 }
61 
62 void CalPrinter::init( const Akonadi::ETMCalendar::Ptr &calendar )
63 {
64  mCalendar = calendar;
65 
66  mPrintPlugins.clear();
67 
68  mPrintPlugins = mCoreHelper->loadPrintPlugins();
69  if( !mUniqItem ) {
70  mPrintPlugins.prepend( new CalPrintTodos() );
71  mPrintPlugins.prepend( new CalPrintMonth() );
72  mPrintPlugins.prepend( new CalPrintWeek() );
73  mPrintPlugins.prepend( new CalPrintDay() );
74  }
75  mPrintPlugins.prepend( new CalPrintIncidence() );
76 
77  KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
78  for ( ; it != mPrintPlugins.end(); ++it ) {
79  if ( *it ) {
80  (*it)->setConfig( mConfig );
81  (*it)->setCalendar( mCalendar );
82  (*it)->setKOrgCoreHelper( mCoreHelper );
83  (*it)->doLoadConfig();
84  }
85  }
86 }
87 
88 void CalPrinter::setDateRange( const QDate &fd, const QDate &td )
89 {
90  KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
91  for ( ; it != mPrintPlugins.end(); ++it ) {
92  (*it)->setDateRange( fd, td );
93  }
94 }
95 
96 void CalPrinter::print( int type, const QDate &fd, const QDate &td,
97  Incidence::List selectedIncidences, bool preview )
98 {
99  KOrg::PrintPlugin::List::Iterator it;
100  for ( it = mPrintPlugins.begin(); it != mPrintPlugins.end(); ++it ) {
101  (*it)->setSelectedIncidences( selectedIncidences );
102  }
103  QPointer<CalPrintDialog> printDialog =
104  new CalPrintDialog( type, mPrintPlugins, mParent, mUniqItem );
105 
106  KConfigGroup grp( mConfig, "" ); //orientation setting isn't in a group
107  printDialog->setOrientation( CalPrinter::ePrintOrientation( grp.readEntry( "Orientation", 1 ) ) );
108  printDialog->setPreview( preview );
109  setDateRange( fd, td );
110 
111  if ( printDialog->exec() == QDialog::Accepted ) {
112  grp.writeEntry( "Orientation", (int)printDialog->orientation() );
113 
114  // Save all changes in the dialog
115  for ( it = mPrintPlugins.begin(); it != mPrintPlugins.end(); ++it ) {
116  (*it)->doSaveConfig();
117  }
118  doPrint( printDialog->selectedPlugin(), printDialog->orientation(), preview );
119  }
120  delete printDialog;
121 
122  for ( it = mPrintPlugins.begin(); it != mPrintPlugins.end(); ++it ) {
123  (*it)->setSelectedIncidences( Incidence::List() );
124  }
125 }
126 
127 void CalPrinter::doPrint( KOrg::PrintPlugin *selectedStyle,
128  CalPrinter::ePrintOrientation dlgorientation, bool preview )
129 {
130  if ( !selectedStyle ) {
131  KMessageBox::error(
132  mParent,
133  i18nc( "@info", "Unable to print, an invalid print style was specified." ),
134  i18nc( "@title:window", "Printing error" ) );
135  return;
136  }
137 
138  QPrinter printer;
139  switch ( dlgorientation ) {
140  case eOrientPlugin:
141  printer.setOrientation( selectedStyle->defaultOrientation() );
142  break;
143  case eOrientPortrait:
144  printer.setOrientation( QPrinter::Portrait );
145  break;
146  case eOrientLandscape:
147  printer.setOrientation( QPrinter::Landscape );
148  break;
149  case eOrientPrinter:
150  default:
151  break;
152  }
153 
154  if ( preview ) {
155  QPointer<KPrintPreview> printPreview = new KPrintPreview( &printer );
156  selectedStyle->doPrint( &printer );
157  printPreview->exec();
158  delete printPreview;
159  } else {
160  QPointer<QPrintDialog> printDialog = KdePrint::createPrintDialog( &printer, mParent );
161  if ( printDialog->exec() == QDialog::Accepted ) {
162  selectedStyle->doPrint( &printer );
163  }
164  delete printDialog;
165  }
166 }
167 
168 void CalPrinter::updateConfig()
169 {
170 }
171 
172 CalPrintDialog::CalPrintDialog( int initialPrintType, KOrg::PrintPlugin::List plugins,
173  QWidget *parent, bool uniqItem )
174  : KDialog( parent )
175 {
176  setCaption( i18nc( "@title:window", "Print" ) );
177  setButtons( Ok | Cancel );
178  setModal( true );
179  KVBox *page = new KVBox( this );
180  setMainWidget( page );
181 
182  QSplitter *splitter = new QSplitter( page );
183  splitter->setOrientation( Qt::Horizontal );
184  splitter->setChildrenCollapsible( false );
185  QGroupBox *typeBox = new QGroupBox( i18nc( "@title:group", "Print Style" ), splitter );
186  QBoxLayout *typeLayout = new QVBoxLayout( typeBox );
187  mTypeGroup = new QButtonGroup( typeBox );
188 
189  QWidget *splitterRight = new QWidget( splitter );
190  QGridLayout *splitterRightLayout = new QGridLayout( splitterRight );
191  splitterRightLayout->setMargin( marginHint() );
192  splitterRightLayout->setSpacing( spacingHint() );
193 
194  mConfigArea = new QStackedWidget( splitterRight );
195  splitterRightLayout->addWidget( mConfigArea, 0, 0, 1, 2 );
196  QLabel *orientationLabel = new QLabel( i18nc( "@label", "Page &orientation:" ), splitterRight );
197  orientationLabel->setAlignment( Qt::AlignRight );
198  splitterRightLayout->addWidget( orientationLabel, 1, 0 );
199 
200  mOrientationSelection = new KComboBox( splitterRight );
201  mOrientationSelection->setToolTip(
202  i18nc( "@info:tooltip", "Set the print orientation" ) );
203  mOrientationSelection->setWhatsThis(
204  i18nc( "@info:whatsthis",
205  "Choose if you want your output to be printed in \"portrait\" or "
206  "\"landscape\". You can also default to the orientation best suited to "
207  "the selected style or to your printer's default setting." ) );
208  mOrientationSelection->addItem( i18nc( "@item:inlistbox",
209  "Use Default Orientation of Selected Style" ) );
210  mOrientationSelection->addItem( i18nc( "@item:inlistbox",
211  "Use Printer Default" ) );
212  mOrientationSelection->addItem( i18nc( "@item:inlistbox",
213  "Portrait" ) );
214  mOrientationSelection->addItem( i18nc( "@item:inlistbox",
215  "Landscape" ) );
216  splitterRightLayout->addWidget( mOrientationSelection, 1, 1 );
217 
218  // signals and slots connections
219  connect( mTypeGroup, SIGNAL(buttonClicked(int)), SLOT(setPrintType(int)) );
220  orientationLabel->setBuddy( mOrientationSelection );
221 
222  // First insert the config widgets into the widget stack. This possibly assigns
223  // proper ids (when two plugins have the same sortID), so store them in a map
224  // and use these new IDs to later sort the plugins for the type selection.
225  for ( KOrg::PrintPlugin::List::ConstIterator it=plugins.constBegin();
226  it != plugins.constEnd(); ++it ) {
227  int newid = mConfigArea->insertWidget( (*it)->sortID(), (*it)->configWidget( mConfigArea ) );
228  mPluginIDs[newid] = (*it);
229  }
230  // Insert all plugins in sorted order; plugins with clashing IDs will be first
231  QMap<int, KOrg::PrintPlugin*>::ConstIterator mapit;
232  int firstButton = true;
233  int id = 0;
234  for ( mapit = mPluginIDs.constBegin(); mapit != mPluginIDs.constEnd(); ++mapit ) {
235  KOrg::PrintPlugin *p = mapit.value();
236  QRadioButton *radioButton = new QRadioButton( p->description() );
237  radioButton->setEnabled( p->enabled() );
238  radioButton->setToolTip(
239  i18nc( "@info:tooltip", "Select the type of print" ) );
240  radioButton->setWhatsThis(
241  i18nc( "@info:whatsthis",
242  "Select one of the following types of prints you want to make. "
243  "You may want to print an individual item, or all the items for a "
244  "specific time range (like a day, week or month), or you may want "
245  "to print your to-do list." ) );
246  // Check the first available button (to ensure one is selected initially) and then
247  // the button matching the desired print type -- if such is available!
248  if ( ( firstButton || p->sortID() == initialPrintType ) && p->enabled() ) {
249  firstButton = false;
250  radioButton->setChecked( true );
251  setPrintType( id );
252  }
253  mTypeGroup->addButton( radioButton, mapit.key() );
254  typeLayout->addWidget( radioButton );
255  id++;
256  }
257  if ( uniqItem ) {
258  typeBox->hide();
259  }
260  typeLayout->insertStretch( -1, 100 );
261  connect( this, SIGNAL(okClicked()), SLOT(slotOk()) );
262  setMinimumSize( minimumSizeHint() );
263  resize( minimumSizeHint() );
264 }
265 
266 CalPrintDialog::~CalPrintDialog()
267 {
268 }
269 
270 void CalPrintDialog::setPreview( bool preview )
271 {
272  if ( preview ) {
273  setButtonText( Ok, i18nc( "@action:button", "&Preview" ) );
274  } else {
275  setButtonText( Ok, KStandardGuiItem::print().text() );
276  }
277 }
278 
279 void CalPrintDialog::setPrintType( int i )
280 {
281  mConfigArea->setCurrentIndex( i );
282  mConfigArea->currentWidget()->raise();
283  QAbstractButton *btn = mTypeGroup->button( i );
284  if (btn) {
285  btn->setChecked( true );
286  }
287 }
288 
289 void CalPrintDialog::setOrientation( CalPrinter::ePrintOrientation orientation )
290 {
291  mOrientation = orientation;
292  mOrientationSelection->setCurrentIndex( mOrientation );
293 }
294 
295 KOrg::PrintPlugin *CalPrintDialog::selectedPlugin()
296 {
297  int id = mConfigArea->currentIndex();
298  if ( mPluginIDs.contains( id ) ) {
299  return mPluginIDs[id];
300  } else {
301  return 0;
302  }
303 }
304 
305 void CalPrintDialog::slotOk()
306 {
307  mOrientation =
308  ( CalPrinter::ePrintOrientation )mOrientationSelection->currentIndex();
309 
310  QMap<int, KOrg::PrintPlugin*>::ConstIterator it = mPluginIDs.constBegin();
311  for ( ; it != mPluginIDs.constEnd(); ++it ) {
312  if ( it.value() ) {
313  it.value()->readSettingsWidget();
314  }
315  }
316 }
CalPrintDay
Definition: calprintdefaultplugins.h:98
CalPrinter::~CalPrinter
virtual ~CalPrinter()
Definition: calprinter.cpp:56
CalPrintDialog::orientation
CalPrinter::ePrintOrientation orientation()
Definition: calprinter.h:118
calprintdefaultplugins.h
KOrg::PrintPlugin::description
virtual QString description()=0
Returns short description of print format.
CalPrinter::eOrientPrinter
Definition: calprinter.h:52
QWidget
CalPrintDialog::CalPrintDialog
CalPrintDialog(int initialPrintType, KOrg::PrintPlugin::List plugins, QWidget *parent=0, bool mUniqItem=false)
Definition: calprinter.cpp:172
KOrg::PrintPlugin::doPrint
virtual void doPrint(QPrinter *printer)=0
Actually do the printing.
CalPrinter::eOrientLandscape
Definition: calprinter.h:54
KOrg::PrintPlugin::List
QList< PrintPlugin * > List
Definition: printplugin.h:69
KDialog
CalPrinter::CalPrinter
CalPrinter(QWidget *par, const Akonadi::ETMCalendar::Ptr &calendar, KOrg::CoreHelper *helper, bool uniqItem=false)
Definition: calprinter.cpp:45
CalPrinter::ePrintOrientation
ePrintOrientation
Definition: calprinter.h:50
QObject
CalPrintDialog::setOrientation
void setOrientation(CalPrinter::ePrintOrientation orientation)
Definition: calprinter.cpp:289
CalPrintDialog::slotOk
void slotOk()
Definition: calprinter.cpp:305
CalPrintDialog::setPrintType
void setPrintType(int)
Definition: calprinter.cpp:279
CalPrintDialog::setPreview
void setPreview(bool)
Definition: calprinter.cpp:270
CalPrintDialog::selectedPlugin
KOrg::PrintPlugin * selectedPlugin()
Definition: calprinter.cpp:295
corehelper.h
CalPrinter::init
void init(const Akonadi::ETMCalendar::Ptr &calendar)
Definition: calprinter.cpp:62
KOrg::PrintPlugin
Base class for KOrganizer printing classes.
Definition: printplugin.h:62
CalPrinter::setDateRange
void setDateRange(const QDate &start, const QDate &end)
Set date range to be printed.
Definition: calprinter.cpp:88
CalPrintIncidence
Definition: calprintdefaultplugins.h:43
KOrg::CoreHelper::loadPrintPlugins
virtual KOrg::PrintPlugin::List loadPrintPlugins()=0
CalPrinter::mPrintPlugins
KOrg::PrintPlugin::List mPrintPlugins
Definition: calprinter.h:97
KOrg::PrintPlugin::sortID
virtual int sortID()
Returns the sort ID of the plugin.
Definition: printplugin.h:109
KOrg::CoreHelper
Definition: corehelper.h:30
KOrg::PrintPlugin::defaultOrientation
virtual QPrinter::Orientation defaultOrientation()
Orientation of printout.
Definition: printplugin.h:139
CalPrintTodos
Definition: calprintdefaultplugins.h:249
CalPrintMonth
Definition: calprintdefaultplugins.h:201
CalPrinter::print
void print(int type, const QDate &fd, const QDate &td, Incidence::List selectedIncidences=Incidence::List(), bool preview=false)
Definition: calprinter.cpp:96
CalPrinter::eOrientPlugin
Definition: calprinter.h:51
CalPrintDialog::~CalPrintDialog
virtual ~CalPrintDialog()
Definition: calprinter.cpp:266
KOrg::PrintPlugin::enabled
virtual bool enabled()
Returns true if the plugin should be enabled; false otherwise.
Definition: printplugin.h:114
calprinter.h
CalPrinter::updateConfig
void updateConfig()
Definition: calprinter.cpp:168
CalPrintDialog
Definition: calprinter.h:107
CalPrinter::calendar
Akonadi::ETMCalendar::Ptr calendar() const
CalPrintWeek
Definition: calprintdefaultplugins.h:147
CalPrinter::eOrientPortrait
Definition: calprinter.h:53
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

korganizer

Skip menu "korganizer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

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

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