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