• 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
  • plugins
  • printing
  • year
yearprint.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (C) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc.,
18  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of Qt, and distribute the resulting executable,
22  without including the source code for Qt in the source distribution.
23 */
24 
25 #include "yearprint.h"
26 
27 #include <KCalendarSystem>
28 
29 class YearPrintFactory : public KOrg::PrintPluginFactory
30 {
31  public:
32  KOrg::PrintPlugin *createPluginFactory() { return new CalPrintYear; }
33 };
34 
35 K_EXPORT_PLUGIN( YearPrintFactory )
36 
37 /**************************************************************
38  * Print Year
39  **************************************************************/
40 
41 QWidget *CalPrintYear::createConfigWidget( QWidget *w )
42 {
43  return new CalPrintYearConfig( w );
44 }
45 
46 void CalPrintYear::readSettingsWidget()
47 {
48  CalPrintYearConfig *cfg = dynamic_cast<CalPrintYearConfig*>( ( QWidget* )mConfigWidget );
49  if ( cfg ) {
50  mYear = cfg->mYear->value();
51  mPages = cfg->mPages->currentText().toInt();
52  mSubDaysEvents = ( cfg->mSubDays->currentIndex() == 0 ) ? Text : TimeBoxes;
53  mHolidaysEvents = ( cfg->mHolidays->currentIndex() == 0 ) ? Text : TimeBoxes;
54  }
55 }
56 
57 void CalPrintYear::setSettingsWidget()
58 {
59  CalPrintYearConfig *cfg =
60  dynamic_cast<CalPrintYearConfig*>( (QWidget *)mConfigWidget );
61  if ( cfg ) {
62  const KCalendarSystem *calsys = calendarSystem();
63  QDate start;
64  calsys->setDate( start, mYear, 1, 1 );
65  int months = calsys->monthsInYear( start );
66  int prevPages = 0;
67  for ( int i=1; i<= months; ++i ) {
68  const int pages = ( months - 1 ) / i + 1;
69  if ( pages != prevPages ) {
70  prevPages = pages;
71  cfg->mPages->addItem( QString::number( pages ), 0 );
72  }
73  }
74 
75  cfg->mYear->setValue( mYear );
76  cfg->mPages->setItemText( cfg->mPages->currentIndex(), QString::number( mPages ) );
77 
78  cfg->mSubDays->setCurrentIndex( ( mSubDaysEvents == Text ) ? 0 : 1 );
79  cfg->mHolidays->setCurrentIndex( ( mHolidaysEvents == Text ) ? 0 : 1 );
80  }
81 }
82 
83 void CalPrintYear::loadConfig()
84 {
85  if ( mConfig ) {
86  KConfigGroup config( mConfig, "Yearprint" );
87  mYear = config.readEntry( "Year", QDate::currentDate().year() );
88  mPages = config.readEntry( "Pages", 1 );
89  mSubDaysEvents = config.readEntry( "ShowSubDayEventsAs", (int)TimeBoxes );
90  mHolidaysEvents = config.readEntry( "ShowHolidaysAs", (int)Text );
91  }
92  setSettingsWidget();
93 }
94 
95 void CalPrintYear::saveConfig()
96 {
97  kDebug();
98 
99  readSettingsWidget();
100  if ( mConfig ) {
101  KConfigGroup config( mConfig, "Yearprint" );
102  config.writeEntry( "Year", mYear );
103  config.writeEntry( "Pages", mPages );
104  config.writeEntry( "Pages", mPages );
105  config.writeEntry( "ShowSubDayEventsAs", mSubDaysEvents );
106  config.writeEntry( "ShowHolidaysAs", mHolidaysEvents );
107  }
108 }
109 
110 QPrinter::Orientation CalPrintYear::defaultOrientation()
111 {
112  return ( mPages == 1 ) ? QPrinter::Landscape : QPrinter::Portrait;
113 }
114 
115 void CalPrintYear::setDateRange( const QDate &from, const QDate &to )
116 {
117  CalPrintPluginBase::setDateRange( from, to );
118  CalPrintYearConfig *cfg = dynamic_cast<CalPrintYearConfig*>( ( QWidget* )mConfigWidget );
119  if ( cfg ) {
120  cfg->mYear->setValue( from.year() );
121  }
122 }
123 
124 void CalPrintYear::print( QPainter &p, int width, int height )
125 {
126  const KCalendarSystem *calsys = calendarSystem();
127  KLocale *locale = KGlobal::locale();
128  if ( !calsys || !locale ) {
129  return;
130  }
131 
132  QRect headerBox( 0, 0, width, headerHeight() );
133  QRect footerBox( 0, height - footerHeight(), width, footerHeight() );
134  height -= footerHeight();
135 
136  QDate start;
137  calsys->setDate( start, mYear, 1, 1 );
138 
139  // Determine the nr of months and the max nr of days per month (dependent on
140  // calendar system!!!!)
141  QDate temp( start );
142  int months = calsys->monthsInYear( start );
143  int maxdays = 1;
144  for ( int i = 1; i< months; ++i ) {
145  maxdays = qMax( maxdays, temp.daysInMonth() );
146  temp = calsys->addMonths( temp, 1 );
147  }
148 
149  // Now determine the months per page so that the printout fits on
150  // exactly mPages pages
151  int monthsPerPage = ( months - 1 ) / mPages + 1;
152  int pages = ( months - 1 ) / monthsPerPage + 1;
153  int thismonth = 0;
154  temp = start;
155  for ( int page = 0; page < pages; ++page ) {
156  if ( page > 0 ) {
157  mPrinter->newPage();
158  }
159  QDate end( calsys->addMonths( start, monthsPerPage ) );
160  end = calsys->addDays( end, -1 );
161  QString stdate = locale->formatDate( start );
162  QString endate = locale->formatDate( end );
163  QString title;
164  if ( orientation() == QPrinter::Landscape ) {
165  title = i18nc( "date from - to", "%1 - %2", stdate, endate );
166  } else {
167  title = i18nc( "date from -\nto", "%1 -\n%2", stdate, endate );
168  }
169  drawHeader( p, title, calsys->addMonths( start, -1 ),
170  calsys->addMonths( start, monthsPerPage ), headerBox );
171 
172  QRect monthesBox( headerBox );
173  monthesBox.setTop( monthesBox.bottom() + padding() );
174  monthesBox.setBottom( height );
175 
176  drawBox( p, BOX_BORDER_WIDTH, monthesBox );
177  float monthwidth = float( monthesBox.width() ) / float( monthsPerPage );
178 
179  for ( int j=0; j<monthsPerPage; ++j ) {
180  if ( ++thismonth > months ) {
181  break;
182  }
183  int xstart = int( j * monthwidth + 0.5 );
184  int xend = int( ( j + 1 ) * monthwidth + 0.5 );
185  QRect monthBox( xstart, monthesBox.top(), xend - xstart, monthesBox.height() );
186  drawMonth( p, temp, monthBox, maxdays, mSubDaysEvents, mHolidaysEvents );
187 
188  temp = calsys->addMonths( temp, 1 );
189  }
190 
191  drawFooter( p, footerBox );
192  start = calsys->addMonths( start, monthsPerPage );
193  }
194 }
CalPrintYear::readSettingsWidget
virtual void readSettingsWidget()
Read settings from configuration widget and apply them to current object.
Definition: yearprint.cpp:46
CalPrintPluginBase::drawHeader
int drawHeader(QPainter &p, const QString &title, const QDate &month1, const QDate &month2, const QRect &box, bool expand=false, QColor backColor=QColor())
Draw the gray header bar of the printout to the QPainter.
Definition: calprintpluginbase.cpp:553
CalPrintPluginBase::orientation
QPrinter::Orientation orientation() const
Definition: calprintpluginbase.cpp:241
CalPrintPluginBase::TimeBoxes
Definition: calprintpluginbase.h:69
CalPrintPluginBase::padding
int padding() const
Definition: calprintpluginbase.cpp:371
yearprint.h
KOrg::PrintPlugin::mPrinter
QPrinter * mPrinter
The printer object.
Definition: printplugin.h:180
QWidget
CalPrintYear::setSettingsWidget
virtual void setSettingsWidget()
Set configuration widget to reflect settings of current object.
Definition: yearprint.cpp:57
KOrg::PrintPluginFactory::createPluginFactory
virtual PrintPlugin * createPluginFactory()=0
CalPrintPluginBase::Text
Definition: calprintpluginbase.h:68
KOrg::PrintPlugin::setDateRange
virtual void setDateRange(const QDate &from, const QDate &to)
Set date range which should be printed.
Definition: printplugin.h:165
KOrg::PrintPlugin
Base class for KOrganizer printing classes.
Definition: printplugin.h:62
CalPrintYearConfig
Definition: yearprint.h:60
CalPrintPluginBase::headerHeight
int headerHeight() const
Returns the height of the page header.
Definition: calprintpluginbase.cpp:315
CalPrintYear::print
virtual void print(QPainter &p, int width, int height)
Actually do the printing.
Definition: yearprint.cpp:124
CalPrintPluginBase::drawBox
static void drawBox(QPainter &p, int linewidth, const QRect &rect)
Draw a box with given width at the given coordinates.
Definition: calprintpluginbase.cpp:391
CalPrintYear::setDateRange
virtual void setDateRange(const QDate &from, const QDate &to)
Set date range which should be printed.
Definition: yearprint.cpp:115
CalPrintYear::mSubDaysEvents
int mSubDaysEvents
Definition: yearprint.h:57
CalPrintYear::loadConfig
virtual void loadConfig()
Load print format configuration from config file.
Definition: yearprint.cpp:83
CalPrintPluginBase::calendarSystem
const KCalendarSystem * calendarSystem() const
Definition: calprintpluginbase.cpp:305
CalPrintYear::defaultOrientation
virtual QPrinter::Orientation defaultOrientation()
Orientation of printout.
Definition: yearprint.cpp:110
KOrg::PrintPluginFactory
Definition: printplugin.h:186
CalPrintYear::mHolidaysEvents
int mHolidaysEvents
Definition: yearprint.h:57
CalPrintYear::mYear
int mYear
Definition: yearprint.h:55
BOX_BORDER_WIDTH
#define BOX_BORDER_WIDTH
Definition: calprintpluginbase.h:55
CalPrintPluginBase::drawFooter
int drawFooter(QPainter &p, const QRect &box)
Draw a page footer containing the printing date and possibly other things, like a page number...
Definition: calprintpluginbase.cpp:628
CalPrintPluginBase::footerHeight
int footerHeight() const
Returns the height of the page footer.
Definition: calprintpluginbase.cpp:341
KOrg::PrintPlugin::mConfig
KConfig * mConfig
Definition: printplugin.h:183
CalPrintYear::mPages
int mPages
Definition: yearprint.h:56
K_EXPORT_PLUGIN
K_EXPORT_PLUGIN(KOrganizerFactory(createAboutData())) KOrganizerPart
Definition: korganizer_part.cpp:49
CalPrintPluginBase::drawMonth
void drawMonth(QPainter &p, const QDate &dt, const QRect &box, int maxdays=-1, int subDailyFlags=TimeBoxes, int holidaysFlags=Text)
Draw a vertical representation of the month containing the date dt.
Definition: calprintpluginbase.cpp:1524
KOrg::PrintPlugin::mConfigWidget
QPointer< QWidget > mConfigWidget
Definition: printplugin.h:176
CalPrintYear
Definition: yearprint.h:33
CalPrintYear::saveConfig
virtual void saveConfig()
Write print format configuration to config file.
Definition: yearprint.cpp:95
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