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

calendarsupport

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

KDE's Doxygen guidelines are available online.

calendarsupport

Skip menu "calendarsupport"
  • 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