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

PIMPrint Library

  • sources
  • kde-4.14
  • kdepim
  • pimprint
  • calendar
calprintweek.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the PimPrint library.
3 
4  Copyright (C) 2012 Allen Winter <winter@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library 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 Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "calprintweek.h"
23 
24 #include <KLocale>
25 #include <KGlobal>
26 
27 using namespace PimPrint::Calendar;
28 
29 //@cond PRIVATE
30 class PimPrint::Calendar::CalPrintWeek::Private
31 {
32 public:
33  Private()
34  {
35  }
36 
37  QDate mStartDate; // starting date of print
38  QDate mEndDate; // ending date of print
39  QTime mStartTime; // starting time of each day's print
40  QTime mEndTime; // ending time of each day's print
41 };
42 //@endcond
43 
44 CalPrintWeek::CalPrintWeek(QPrinter *printer)
45  : CalPrintBase(printer),
46  d(new PimPrint::Calendar::CalPrintWeek::Private)
47 {
48  //TODO:
49  // set the calendar and calendar system
50 
51  // Set default print style
52  setPrintStyle(CalPrintBase::WeekTimeTable);
53 
54  // TODO: Set default Info options
55  //setInfoOptions(CalPrintBase::InfoTimeRange);
56 
57  // TODO: Set default Type options
58  //setTypeOptions(0);
59 
60  // TODO: Set default Range options
61  //setRangeOptions(0);
62 
63  // TODO: Set default Extra options
64  //setExtraOptions(0);
65 }
66 
67 CalPrintWeek::~CalPrintWeek()
68 {
69  delete d;
70 }
71 
72 void CalPrintWeek::print(QPainter &p)
73 {
74  switch (printStyle()) {
75  case CalPrintBase::WeekFiloFax:
76  drawFiloFaxWeek(p);
77  break;
78  case CalPrintBase::WeekTimeTable:
79  drawTimeTableWeek(p);
80  break;
81  case CalPrintBase::WeekSplitWeek:
82  default:
83  drawSplitWeek(p);
84  break;
85  }
86 }
87 
88 void CalPrintWeek::setStartDate(const QDate &date)
89 {
90  d->mStartDate = date;
91 }
92 
93 QDate CalPrintWeek::startDate() const
94 {
95  return d->mStartDate;
96 }
97 
98 void CalPrintWeek::setEndDate(const QDate &date)
99 {
100  d->mEndDate = date;
101 }
102 
103 QDate CalPrintWeek::endDate() const
104 {
105  return d->mEndDate;
106 }
107 
108 void CalPrintWeek::setStartTime(const QTime &time)
109 {
110  d->mStartTime = time;
111 }
112 
113 QTime CalPrintWeek::startTime() const
114 {
115  return d->mStartTime;
116 }
117 
118 void CalPrintWeek::setEndTime(const QTime &time)
119 {
120  d->mEndTime = time;
121 }
122 
123 QTime CalPrintWeek::endTime() const
124 {
125  return d->mEndTime;
126 }
127 
128 QRect CalPrintWeek::drawHeader(QPainter &p, const QDate &date, bool printWeekNumber) const
129 {
130  if (!date.isValid()) {
131  return QRect();
132  }
133 
134  KLocale *local = KGlobal::locale();
135 
136  const QDate startDate = date.addDays(-6);
137  const QString line1 = local->formatDate(startDate);
138  const QString line2 = local->formatDate(date);
139 
140  QString title;
141  if (useLandscape()) {
142  if (printWeekNumber) {
143  title = i18nc("date from - to (week number)", "%1 - %2 (Week %3)",
144  line1, line2, date.weekNumber());
145  } else {
146  title = i18nc("date from - to", "%1 - %2", line1, line2);
147  }
148  } else {
149  if (printWeekNumber) {
150  title = i18nc("date from -\nto (week number)", "%1 -\n%2 (Week %3)",
151  line1, line2, date.weekNumber());
152  } else {
153  title = i18nc("date from -\nto", "%1 -\n%2", line1, line2);
154  }
155  }
156 
157  const QRect headerBox(0, 0, pageWidth(), headerHeight());
158  CalPrintBase::drawHeader(p, headerBox, title, startDate);
159  return headerBox;
160 }
161 
162 QRect CalPrintWeek::drawFooter(QPainter &p) const
163 {
164  QRect footerBox(0, pageHeight() - footerHeight(), pageWidth(), footerHeight());
165 
166  CalPrintBase::drawFooter(p, footerBox);
167 
168  return footerBox;
169 }
170 
171 void CalPrintWeek::drawWeek(QPainter &p, const QDate &qd,
172  const QTime &fromTime, const QTime &toTime,
173  const QRect &box) const
174 {
175  QDate weekDate = qd;
176  const bool portrait = (box.height() > box.width());
177  int cellWidth;
178  int vcells;
179  if (portrait) {
180  cellWidth = box.width() / 2;
181  vcells = 3;
182  } else {
183  cellWidth = box.width() / 6;
184  vcells = 1;
185  }
186  const int cellHeight = box.height() / vcells;
187 
188  // correct begin of week
189  int weekdayCol = weekdayColumn(qd.dayOfWeek());
190  weekDate = qd.addDays(-weekdayCol);
191 
192  for (int i = 0; i < 7; i++, weekDate = weekDate.addDays(1)) {
193  // Saturday and sunday share a cell, so we have to special-case sunday
194  int hpos = ((i < 6) ? i : (i - 1)) / vcells;
195  int vpos = ((i < 6) ? i : (i - 1)) % vcells;
196  QRect dayBox(
197  box.left() + cellWidth * hpos,
198  box.top() + cellHeight * vpos + ((i == 6) ? (cellHeight / 2) : 0),
199  cellWidth, (i < 5) ? (cellHeight) : (cellHeight / 2));
200  drawDayBox(p, dayBox, weekDate, fromTime, toTime, true/*fulldate*/);
201  } // for i through all weekdays
202 }
203 
204 void CalPrintWeek::drawFiloFaxWeek(QPainter &p) const
205 {
206  QDate dateCurWeek, dateStartWeek, dateEndWeek;
207 
208  // correct begin and end to first and last day of week
209  int weekdayCol = weekdayColumn(d->mStartDate.dayOfWeek());
210  dateStartWeek = d->mStartDate.addDays(-weekdayCol);
211  weekdayCol = weekdayColumn(d->mEndDate.dayOfWeek());
212  dateEndWeek = d->mEndDate.addDays(6 - weekdayCol);
213 
214  dateCurWeek = dateStartWeek.addDays(6);
215 
216  bool firstTime = true;
217  QRect weekBox;
218 
219  do {
220  const QRect headerBox = drawHeader(p, dateCurWeek, false);
221 
222  if (firstTime) {
223  weekBox = headerBox;
224  weekBox.setTop(headerBox.bottom() + padding());
225  weekBox.setBottom(pageHeight() - footerHeight());
226  firstTime = false;
227  }
228 
229  drawWeek(p, dateCurWeek, d->mStartTime, d->mEndTime, weekBox);
230 
231  if (extraOptions().testFlag(CalPrintBase::ExtraFooter)) {
232  drawFooter(p);
233  }
234 
235  dateCurWeek = dateCurWeek.addDays(7);
236  if (dateCurWeek <= dateEndWeek) {
237  thePrinter()->newPage();
238  }
239  } while (dateCurWeek <= dateEndWeek);
240 }
241 
242 void CalPrintWeek::drawTimeTableWeek(QPainter &p) const
243 {
244  QDate dateCurWeek, dateStartWeek, dateEndWeek;
245 
246  // correct begin and end to first and last day of week
247  int weekdayCol = weekdayColumn(d->mStartDate.dayOfWeek());
248  dateStartWeek = d->mStartDate.addDays(-weekdayCol);
249  weekdayCol = weekdayColumn(d->mEndDate.dayOfWeek());
250  dateEndWeek = d->mEndDate.addDays(6 - weekdayCol);
251 
252  dateCurWeek = dateStartWeek.addDays(6);
253 
254  bool firstTime = true;
255  QRect weekBox;
256 
257  do {
258  const QRect headerBox = drawHeader(p, dateCurWeek, true);
259 
260  if (firstTime) {
261  weekBox = headerBox;
262  weekBox.setTop(headerBox.bottom() + padding());
263  weekBox.setBottom(pageHeight() - footerHeight());
264  firstTime = false;
265  }
266 
267  drawTimeTable(p, weekBox,
268  dateStartWeek, dateCurWeek,
269  d->mStartTime, d->mEndTime);
270 
271  if (extraOptions().testFlag(CalPrintBase::ExtraFooter)) {
272  drawFooter(p);
273  }
274 
275  dateStartWeek = dateStartWeek.addDays(7);
276  dateCurWeek = dateStartWeek.addDays(6);
277  if (dateCurWeek <= dateEndWeek) {
278  thePrinter()->newPage();
279  }
280  } while (dateCurWeek <= dateEndWeek);
281 }
282 
283 void CalPrintWeek::drawSplitWeek(QPainter &p) const
284 {
285  // TODO:
286 }
QRect::setBottom
void setBottom(int y)
PimPrint::Calendar::CalPrintBase::setPrintStyle
void setPrintStyle(const Style style)
Sets the printing Style.
Definition: calprintbase.cpp:193
PimPrint::Calendar::CalPrintBase::printStyle
Style printStyle() const
Returns the current printing Style.
Definition: calprintbase.cpp:198
PimPrint::Calendar::CalPrintBase::thePrinter
QPrinter * thePrinter() const
Returns a pointer to the currently set QPrinter.
Definition: calprintbase.cpp:168
PimPrint::Calendar::CalPrintWeek::setEndTime
void setEndTime(const QTime &time)
Sets the printout ending time.
Definition: calprintweek.cpp:118
PimPrint::Calendar::CalPrintWeek::startDate
QDate startDate() const
Returns the current print starting date.
QPrinter
PimPrint::Calendar::CalPrintBase::extraOptions
ExtraOptions extraOptions() const
Returns the current extra option flags.
Definition: calprintbase.cpp:366
PimPrint::Calendar::CalPrintBase::pageWidth
int pageWidth() const
Returns the current printed page width.
QRect::height
int height() const
PimPrint::Calendar::CalPrintBase::drawTimeTable
void drawTimeTable(QPainter &p, const QRect &box, const QDate &startDate, const QDate &endDate, const QTime &startTime, const QTime &endTime, bool expandAll=false) const
Draws the timetable view of the given time range from startDate to endDate.
Definition: calprintbase.cpp:655
PimPrint::Calendar::CalPrintBase::WeekSplitWeek
Definition: calprintbase.h:129
PimPrint::Calendar::CalPrintWeek::setEndDate
void setEndDate(const QDate &date)
Sets the printout ending date.
Definition: calprintweek.cpp:98
PimPrint::Calendar::CalPrintWeek::setStartDate
void setStartDate(const QDate &date)
Sets the printout starting date.
Definition: calprintweek.cpp:88
QTime
QDate::weekNumber
int weekNumber(int *yearNumber) const
PimPrint::Calendar::CalPrintBase::weekdayColumn
int weekdayColumn(int weekday) const
Determines the column of the given weekday (1=Monday, 7=Sunday), taking the start of the week setting...
Definition: calprintbase.cpp:1330
QDate::dayOfWeek
int dayOfWeek() const
QRect
PimPrint::Calendar::CalPrintWeek::CalPrintWeek
CalPrintWeek(QPrinter *printer)
Definition: calprintweek.cpp:44
PimPrint::Calendar::CalPrintWeek::~CalPrintWeek
virtual ~CalPrintWeek()
Definition: calprintweek.cpp:67
QRect::top
int top() const
QRect::setTop
void setTop(int y)
QRect::left
int left() const
QPainter
PimPrint::Calendar::CalPrintWeek
Definition: calprintweek.h:33
PimPrint::Calendar::CalPrintWeek::endTime
QTime endTime() const
Returns the current print ending time.
PimPrint::Calendar::CalPrintBase::ExtraFooter
Definition: calprintbase.h:309
PimPrint::Calendar::CalPrintWeek::print
void print(QPainter &p)
Definition: calprintweek.cpp:72
QDate::isValid
bool isValid() const
PimPrint::Calendar::CalPrintBase::drawFooter
int drawFooter(QPainter &p, const QRect &box) const
Draws a page footer containing the printing date and possibly other things, like a page number...
Definition: calprintbase.cpp:568
PimPrint::Calendar::CalPrintBase
Definition: calprintbase.h:67
PimPrint::Calendar::CalPrintBase::padding
int padding() const
Returns the current padding margin.
QDate
QString
PimPrint::Calendar::CalPrintWeek::setStartTime
void setStartTime(const QTime &time)
Sets the printout starting time.
Definition: calprintweek.cpp:108
PimPrint::Calendar::CalPrintBase::headerHeight
int headerHeight() const
Returns the current height of the page header.
QPrinter::newPage
bool newPage()
PimPrint::Calendar::CalPrintBase::drawHeader
int drawHeader(QPainter &p, const QRect &box, const QString &title, const QDate &leftMonth=QDate(), const QDate &rightMonth=QDate(), const bool expand=false, const QColor &backColor=QColor()) const
Draws the gray header bar of the printout to the QPainter.
Definition: calprintbase.cpp:497
PimPrint::Calendar::CalPrintBase::footerHeight
int footerHeight() const
Returns the current height of the page footer.
PimPrint::Calendar::CalPrintBase::drawDayBox
void drawDayBox(QPainter &p, const QRect &box, const QDate &date, const QTime &startTime, const QTime &endTime, bool fullDate=false) const
Draws the box containing a list of all events and to-dos of the given day.
Definition: calprintbase.cpp:1141
QRect::width
int width() const
PimPrint::Calendar::CalPrintBase::useLandscape
bool useLandscape() const
Returns if the current printed page orientation is landscape.
calprintweek.h
PimPrint::Calendar::CalPrintBase::WeekTimeTable
Definition: calprintbase.h:128
QRect::bottom
int bottom() const
PimPrint::Calendar::CalPrintBase::pageHeight
int pageHeight() const
Returns the current printed page height.
PimPrint::Calendar::CalPrintBase::WeekFiloFax
Definition: calprintbase.h:127
QDate::addDays
QDate addDays(int ndays) const
PimPrint::Calendar::CalPrintWeek::startTime
QTime startTime() const
Returns the current print starting time.
PimPrint::Calendar::CalPrintWeek::endDate
QDate endDate() const
Returns the current print ending date.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

PIMPrint Library

Skip menu "PIMPrint Library"
  • Main Page
  • Namespace List
  • 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
  • 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