Diffstat (limited to 'korganizer/calprintplugins.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | korganizer/calprintplugins.cpp | 669 |
1 files changed, 669 insertions, 0 deletions
diff --git a/korganizer/calprintplugins.cpp b/korganizer/calprintplugins.cpp new file mode 100644 index 0000000..bc35ca4 --- a/dev/null +++ b/korganizer/calprintplugins.cpp | |||
@@ -0,0 +1,669 @@ | |||
1 | /* | ||
2 | This file is part of KOrganizer. | ||
3 | |||
4 | Copyright (c) 1998 Preston Brown | ||
5 | Copyright (c) 2003 Reinhold Kainhofer <reinhold@kainhofer.com> | ||
6 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | ||
7 | |||
8 | This program is free software; you can redistribute it and/or modify | ||
9 | it under the terms of the GNU General Public License as published by | ||
10 | the Free Software Foundation; either version 2 of the License, or | ||
11 | (at your option) any later version. | ||
12 | |||
13 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | GNU General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU General Public License | ||
19 | along with this program; if not, write to the Free Software | ||
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
21 | |||
22 | As a special exception, permission is given to link this program | ||
23 | with any edition of Qt, and distribute the resulting executable, | ||
24 | without including the source code for Qt in the source distribution. | ||
25 | */ | ||
26 | |||
27 | #include <qpainter.h> | ||
28 | #include <qdatetimeedit.h> | ||
29 | #include <qdatetime.h> | ||
30 | #include <qcheckbox.h> | ||
31 | #include <qlineedit.h> | ||
32 | #include <qbuttongroup.h> | ||
33 | |||
34 | #include <kglobal.h> | ||
35 | #include <klocale.h> | ||
36 | #include <kdebug.h> | ||
37 | #include <kprinter.h> | ||
38 | #include <kconfig.h> | ||
39 | #include <kcalendarsystem.h> | ||
40 | |||
41 | #include <libkcal/todo.h> | ||
42 | #include <libkcal/calendar.h> | ||
43 | |||
44 | #include <libkdepim/kdateedit.h> | ||
45 | |||
46 | #include "koprefs.h" | ||
47 | #include "koglobals.h" | ||
48 | #include "calprintplugins.h" | ||
49 | #ifndef KORG_NOPRINTER | ||
50 | |||
51 | //#include "calprintplugins.moc" | ||
52 | |||
53 | #define LEFT_DISTANCE 45 | ||
54 | |||
55 | /************************************************************** | ||
56 | * Print Day | ||
57 | **************************************************************/ | ||
58 | |||
59 | CalPrintDay::CalPrintDay( KPrinter *printer, Calendar *cal, KConfig *cfg ) | ||
60 | : CalPrintBase( printer, cal, cfg ) | ||
61 | { | ||
62 | } | ||
63 | |||
64 | CalPrintDay::~CalPrintDay() | ||
65 | { | ||
66 | } | ||
67 | |||
68 | QWidget *CalPrintDay::configWidget( QWidget *w ) | ||
69 | { | ||
70 | mConfigWidget = new CalPrintDayConfig_Base( w ); | ||
71 | setSettingsWidget(); | ||
72 | return mConfigWidget; | ||
73 | } | ||
74 | |||
75 | void CalPrintDay::readSettingsWidget() | ||
76 | { | ||
77 | CalPrintDayConfig_Base *cfg = mConfigWidget; | ||
78 | if ( cfg ) { | ||
79 | mFromDate = cfg->mFromDate->date(); | ||
80 | mToDate = cfg->mToDate->date(); | ||
81 | |||
82 | mStartTime = cfg->mFromTime->time(); | ||
83 | mEndTime = cfg->mToTime->time(); | ||
84 | mIncludeAllEvents = cfg->mIncludeAllEvents->isChecked(); | ||
85 | |||
86 | mIncludeTodos = cfg->mIncludeTodos->isChecked(); | ||
87 | mUseColors = cfg->mColors->isChecked(); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | void CalPrintDay::setSettingsWidget() | ||
92 | { | ||
93 | CalPrintDayConfig_Base *cfg =( mConfigWidget ); | ||
94 | if ( cfg ) { | ||
95 | cfg->mFromDate->setDate( mFromDate ); | ||
96 | cfg->mToDate->setDate( mToDate ); | ||
97 | |||
98 | cfg->mFromTime->setTime( mStartTime ); | ||
99 | cfg->mToTime->setTime( mEndTime ); | ||
100 | cfg->mIncludeAllEvents->setChecked( mIncludeAllEvents ); | ||
101 | |||
102 | cfg->mIncludeTodos->setChecked( mIncludeTodos ); | ||
103 | cfg->mColors->setChecked( mUseColors ); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | void CalPrintDay::loadConfig() | ||
108 | { | ||
109 | if ( mConfig ) { | ||
110 | QDate dt; | ||
111 | QTime tm1 = QTime( KOPrefs::instance()->mDayBegins, 0,0 ); | ||
112 | QDateTime startTm( dt, tm1 ); | ||
113 | QDateTime endTm( dt, tm1.addSecs( 12 * 60 * 60 ) ); | ||
114 | mStartTime = mConfig->readDateTimeEntry( "Start time", &startTm ).time(); | ||
115 | mEndTime = mConfig->readDateTimeEntry( "End time", &endTm ).time(); | ||
116 | mIncludeTodos = mConfig->readBoolEntry( "Include todos", false ); | ||
117 | mIncludeAllEvents = mConfig->readBoolEntry( "Include all events", false ); | ||
118 | } | ||
119 | setSettingsWidget(); | ||
120 | } | ||
121 | |||
122 | void CalPrintDay::saveConfig() | ||
123 | { | ||
124 | readSettingsWidget(); | ||
125 | if ( mConfig ) { | ||
126 | mConfig->writeEntry( "Start time", QDateTime( QDate(), mStartTime ) ); | ||
127 | mConfig->writeEntry( "End time", QDateTime( QDate(), mEndTime ) ); | ||
128 | mConfig->writeEntry( "Include todos", mIncludeTodos ); | ||
129 | mConfig->writeEntry( "Include all events", mIncludeAllEvents ); | ||
130 | } | ||
131 | } | ||
132 | |||
133 | void CalPrintDay::setDateRange( const QDate& from, const QDate& to ) | ||
134 | { | ||
135 | CalPrintBase::setDateRange( from, to ); | ||
136 | CalPrintDayConfig_Base *cfg = mConfigWidget ; | ||
137 | if ( cfg ) { | ||
138 | cfg->mFromDate->setDate( from ); | ||
139 | cfg->mToDate->setDate( to ); | ||
140 | } | ||
141 | } | ||
142 | |||
143 | void CalPrintDay::print( QPainter &p, int width, int height ) | ||
144 | { | ||
145 | QDate curDay( mFromDate ); | ||
146 | int yoffset = 0, xoffset = 0; | ||
147 | if ( width > height ) { | ||
148 | yoffset += LEFT_DISTANCE; | ||
149 | } else { | ||
150 | xoffset += LEFT_DISTANCE; | ||
151 | } | ||
152 | width -= xoffset; | ||
153 | height -= yoffset; | ||
154 | do { | ||
155 | int x = 0; | ||
156 | int y = 0; | ||
157 | |||
158 | |||
159 | int currHeight=( height - y ) / 20; | ||
160 | QTime curStartTime( mStartTime ); | ||
161 | QTime curEndTime( mEndTime ); | ||
162 | if ( curStartTime.secsTo( curEndTime ) <= 3600 ) { | ||
163 | if ( curStartTime.hour() == 0 ) { | ||
164 | curStartTime = QTime( 0, 0, 0 ); | ||
165 | curEndTime = curStartTime.addSecs( 3600 ); | ||
166 | } else if ( curEndTime.hour() == 23 ) { | ||
167 | curEndTime=QTime( 23, 59, 59 ); | ||
168 | if ( curStartTime > QTime( 23, 0, 0 ) ) { | ||
169 | curStartTime = QTime( 23, 0, 0 ); | ||
170 | } | ||
171 | } else { | ||
172 | curStartTime = curStartTime.addSecs( -1200 ); | ||
173 | } | ||
174 | curEndTime = curEndTime.addSecs( 1200 ); | ||
175 | } | ||
176 | |||
177 | KLocale *local = KGlobal::locale(); | ||
178 | drawHeader( p, local->formatDate( curDay, false ), | ||
179 | curDay, QDate(), xoffset, yoffset, width, mHeaderHeight ); | ||
180 | |||
181 | y += mHeaderHeight + 5; | ||
182 | x = 80; | ||
183 | Event::List eventList; eventList.fill( mCalendar->events( curDay, true )); | ||
184 | |||
185 | p.setFont( QFont( "helvetica", 10 ) ); | ||
186 | currHeight = p.fontMetrics().lineSpacing()*3/2; | ||
187 | drawAllDayBox( p, eventList, curDay, true, x+xoffset, y+yoffset, width - x, currHeight ); | ||
188 | y += currHeight; | ||
189 | drawAgendaDayBox( p, eventList, curDay, mIncludeAllEvents, | ||
190 | curStartTime, curEndTime, x+xoffset, y+yoffset, width - x, height - y ); | ||
191 | drawTimeLine( p, curStartTime, curEndTime, xoffset, y+yoffset, x - 5, height - y ); | ||
192 | curDay = curDay.addDays( 1 ); | ||
193 | if ( curDay <= mToDate ) mPrinter->newPage(); | ||
194 | } while ( curDay <= mToDate ); | ||
195 | } | ||
196 | |||
197 | |||
198 | |||
199 | /************************************************************** | ||
200 | * Print Week | ||
201 | **************************************************************/ | ||
202 | |||
203 | CalPrintWeek::CalPrintWeek(KPrinter *printer, Calendar *cal, KConfig *cfg) | ||
204 | :CalPrintBase(printer,cal,cfg) | ||
205 | { | ||
206 | } | ||
207 | |||
208 | CalPrintWeek::~CalPrintWeek() | ||
209 | { | ||
210 | } | ||
211 | |||
212 | QWidget *CalPrintWeek::configWidget( QWidget *w ) | ||
213 | { | ||
214 | mConfigWidget = new CalPrintWeekConfig_Base( w ); | ||
215 | setSettingsWidget(); | ||
216 | return mConfigWidget; | ||
217 | } | ||
218 | |||
219 | void CalPrintWeek::readSettingsWidget() | ||
220 | { | ||
221 | CalPrintWeekConfig_Base *cfg =( mConfigWidget ); | ||
222 | if ( cfg ) { | ||
223 | mFromDate = cfg->mFromDate->date(); | ||
224 | mToDate = cfg->mToDate->date(); | ||
225 | |||
226 | mWeekPrintType = (eWeekPrintType)( cfg->mPrintType->id( | ||
227 | cfg->mPrintType->selected() ) ); | ||
228 | |||
229 | mStartTime = cfg->mFromTime->time(); | ||
230 | mEndTime = cfg->mToTime->time(); | ||
231 | |||
232 | mIncludeTodos = cfg->mIncludeTodos->isChecked(); | ||
233 | mUseColors = cfg->mColors->isChecked(); | ||
234 | } | ||
235 | } | ||
236 | |||
237 | void CalPrintWeek::setSettingsWidget() | ||
238 | { | ||
239 | CalPrintWeekConfig_Base *cfg =( mConfigWidget ); | ||
240 | if ( cfg ) { | ||
241 | cfg->mFromDate->setDate( mFromDate ); | ||
242 | cfg->mToDate->setDate( mToDate ); | ||
243 | |||
244 | cfg->mPrintType->setButton( mWeekPrintType ); | ||
245 | |||
246 | cfg->mFromTime->setTime( mStartTime ); | ||
247 | cfg->mToTime->setTime( mEndTime ); | ||
248 | |||
249 | cfg->mIncludeTodos->setChecked( mIncludeTodos ); | ||
250 | cfg->mColors->setChecked( mUseColors ); | ||
251 | } | ||
252 | } | ||
253 | |||
254 | void CalPrintWeek::loadConfig() | ||
255 | { | ||
256 | if ( mConfig ) { | ||
257 | QDate dt; | ||
258 | QTime tm1 = QTime( KOPrefs::instance()->mDayBegins, 0,0); | ||
259 | QDateTime startTm( dt, tm1 ); | ||
260 | QDateTime endTm( dt, tm1.addSecs( 43200 ) ); | ||
261 | mStartTime = mConfig->readDateTimeEntry( "Start time", &startTm ).time(); | ||
262 | mEndTime = mConfig->readDateTimeEntry( "End time", &endTm ).time(); | ||
263 | mIncludeTodos = mConfig->readBoolEntry( "Include todos", false ); | ||
264 | mWeekPrintType =(eWeekPrintType)( mConfig->readNumEntry( "Print type", (int)Filofax ) ); | ||
265 | } | ||
266 | setSettingsWidget(); | ||
267 | } | ||
268 | |||
269 | void CalPrintWeek::saveConfig() | ||
270 | { | ||
271 | readSettingsWidget(); | ||
272 | if ( mConfig ) { | ||
273 | mConfig->writeEntry( "Start time", QDateTime( QDate(), mStartTime ) ); | ||
274 | mConfig->writeEntry( "End time", QDateTime( QDate(), mEndTime ) ); | ||
275 | mConfig->writeEntry( "Include todos", mIncludeTodos ); | ||
276 | mConfig->writeEntry( "Print type", int( mWeekPrintType ) ); | ||
277 | } | ||
278 | } | ||
279 | |||
280 | KPrinter::Orientation CalPrintWeek::orientation() | ||
281 | { | ||
282 | if ( mWeekPrintType == Filofax || mWeekPrintType == SplitWeek ) return KPrinter::Portrait; | ||
283 | else return KPrinter::Landscape; | ||
284 | } | ||
285 | |||
286 | void CalPrintWeek::setDateRange( const QDate &from, const QDate &to ) | ||
287 | { | ||
288 | CalPrintBase::setDateRange( from, to ); | ||
289 | CalPrintWeekConfig_Base *cfg =( mConfigWidget ); | ||
290 | if ( cfg ) { | ||
291 | cfg->mFromDate->setDate( from ); | ||
292 | cfg->mToDate->setDate( to ); | ||
293 | } | ||
294 | } | ||
295 | |||
296 | void CalPrintWeek::print( QPainter &p, int width, int height ) | ||
297 | { | ||
298 | QDate curWeek, fromWeek, toWeek; | ||
299 | int yoffset = 0, xoffset = 0; | ||
300 | //width = height -1;//test only | ||
301 | if ( width > height ) { | ||
302 | yoffset += LEFT_DISTANCE; | ||
303 | } else { | ||
304 | xoffset += LEFT_DISTANCE; | ||
305 | } | ||
306 | width -= xoffset; | ||
307 | height -= yoffset; | ||
308 | // correct begin and end to first and last day of week | ||
309 | int weekdayCol = weekdayColumn( mFromDate.dayOfWeek() ); | ||
310 | fromWeek = mFromDate.addDays( -weekdayCol ); | ||
311 | weekdayCol = weekdayColumn( mFromDate.dayOfWeek() ); | ||
312 | toWeek = mToDate.addDays( 6 - weekdayCol ); | ||
313 | |||
314 | curWeek = fromWeek.addDays( 6 ); | ||
315 | KLocale *local = KGlobal::locale(); | ||
316 | |||
317 | switch ( mWeekPrintType ) { | ||
318 | case Filofax: | ||
319 | do { | ||
320 | QString line1( local->formatDate( curWeek.addDays( -6 ) ) ); | ||
321 | QString line2( local->formatDate( curWeek ) ); | ||
322 | drawHeader( p, line1 + "\n" + line2, curWeek.addDays( -6 ), QDate(), | ||
323 | 0+xoffset, 0+yoffset, width, mHeaderHeight ); | ||
324 | int top = mHeaderHeight + 10; | ||
325 | drawWeek( p, curWeek, 0+xoffset, top+yoffset, width, height - top ); | ||
326 | curWeek = curWeek.addDays( 7 ); | ||
327 | if ( curWeek <= toWeek ) | ||
328 | mPrinter->newPage(); | ||
329 | } while ( curWeek <= toWeek ); | ||
330 | break; | ||
331 | |||
332 | case Timetable: | ||
333 | default: | ||
334 | do { | ||
335 | QString line1( local->formatDate( curWeek.addDays( -6 ) ) ); | ||
336 | QString line2( local->formatDate( curWeek ) ); | ||
337 | //int hh = int(mHeaderHeight * 2./3.); | ||
338 | int hh = mHeaderHeight; | ||
339 | if ( yoffset ) | ||
340 | drawHeader( p, i18n("date from - to", "%1 - %2").arg( line1 ).arg( line2 ), | ||
341 | curWeek, QDate(), 0+xoffset, 0+yoffset, width, hh ); | ||
342 | else | ||
343 | drawHeader( p, i18n("date from - to", "%1 -\n%2").arg( line1 ).arg( line2 ), | ||
344 | curWeek, QDate(), 0+xoffset, 0+yoffset, width, hh ); | ||
345 | drawTimeTable( p, fromWeek, curWeek, | ||
346 | mStartTime, mEndTime, 0+xoffset, hh + 5+yoffset, | ||
347 | width, height - hh - 5 ); | ||
348 | fromWeek = fromWeek.addDays( 7 ); | ||
349 | curWeek = fromWeek.addDays( 6 ); | ||
350 | if ( curWeek <= toWeek ) | ||
351 | mPrinter->newPage(); | ||
352 | } while ( curWeek <= toWeek ); | ||
353 | break; | ||
354 | |||
355 | case SplitWeek: | ||
356 | drawSplitWeek( p, fromWeek, toWeek ); | ||
357 | break; | ||
358 | } | ||
359 | } | ||
360 | |||
361 | |||
362 | |||
363 | |||
364 | /************************************************************** | ||
365 | * Print Month | ||
366 | **************************************************************/ | ||
367 | |||
368 | CalPrintMonth::CalPrintMonth( KPrinter *printer, Calendar *cal, KConfig *cfg ) | ||
369 | : CalPrintBase( printer, cal, cfg ) | ||
370 | { | ||
371 | } | ||
372 | |||
373 | CalPrintMonth::~CalPrintMonth() | ||
374 | { | ||
375 | } | ||
376 | |||
377 | QWidget *CalPrintMonth::configWidget( QWidget *w ) | ||
378 | { | ||
379 | mConfigWidget = new CalPrintMonthConfig_Base( w ); | ||
380 | return mConfigWidget; | ||
381 | } | ||
382 | |||
383 | void CalPrintMonth::readSettingsWidget() | ||
384 | { | ||
385 | CalPrintMonthConfig_Base *cfg =( mConfigWidget ); | ||
386 | if ( cfg ) { | ||
387 | mFromDate = cfg->mFromDate->date(); | ||
388 | mToDate = cfg->mToDate->date(); | ||
389 | |||
390 | mWeekNumbers = cfg->mWeekNumbers->isChecked(); | ||
391 | |||
392 | mIncludeTodos = cfg->mIncludeTodos->isChecked(); | ||
393 | // mUseColors = cfg->mColors->isChecked(); | ||
394 | } | ||
395 | } | ||
396 | |||
397 | void CalPrintMonth::setSettingsWidget() | ||
398 | { | ||
399 | CalPrintMonthConfig_Base *cfg =( mConfigWidget ); | ||
400 | if ( cfg ) { | ||
401 | cfg->mFromDate->setDate( mFromDate ); | ||
402 | cfg->mToDate->setDate( mToDate ); | ||
403 | |||
404 | cfg->mWeekNumbers->setChecked( mWeekNumbers ); | ||
405 | |||
406 | cfg->mIncludeTodos->setChecked( mIncludeTodos ); | ||
407 | // cfg->mColors->setChecked( mUseColors ); | ||
408 | } | ||
409 | } | ||
410 | |||
411 | void CalPrintMonth::loadConfig() | ||
412 | { | ||
413 | if ( mConfig ) { | ||
414 | mWeekNumbers = mConfig->readBoolEntry( "Print week numbers", true ); | ||
415 | mIncludeTodos = mConfig->readBoolEntry( "Include todos", false ); | ||
416 | } | ||
417 | setSettingsWidget(); | ||
418 | } | ||
419 | |||
420 | void CalPrintMonth::saveConfig() | ||
421 | { | ||
422 | readSettingsWidget(); | ||
423 | if ( mConfig ) { | ||
424 | mConfig->writeEntry( "Print week numbers", mWeekNumbers ); | ||
425 | mConfig->writeEntry( "Include todos", mIncludeTodos ); | ||
426 | } | ||
427 | } | ||
428 | |||
429 | void CalPrintMonth::setDateRange( const QDate &from, const QDate &to ) | ||
430 | { | ||
431 | CalPrintBase::setDateRange( from, to ); | ||
432 | CalPrintMonthConfig_Base *cfg =( mConfigWidget ); | ||
433 | if ( cfg ) { | ||
434 | cfg->mFromDate->setDate( from ); | ||
435 | cfg->mToDate->setDate( to ); | ||
436 | } | ||
437 | } | ||
438 | |||
439 | void CalPrintMonth::print( QPainter &p, int width, int height ) | ||
440 | { | ||
441 | QDate curMonth, fromMonth, toMonth; | ||
442 | /* | ||
443 | if ( width > height ) { | ||
444 | // for debug only | ||
445 | int te = height; | ||
446 | height = width; | ||
447 | width = te; | ||
448 | } | ||
449 | */ | ||
450 | int yoffset = 0, xoffset = 0; | ||
451 | if ( width > height ) { | ||
452 | yoffset += LEFT_DISTANCE; | ||
453 | } else { | ||
454 | xoffset += LEFT_DISTANCE; | ||
455 | } | ||
456 | width -= xoffset; | ||
457 | height -= yoffset; | ||
458 | fromMonth = mFromDate.addDays( -( mFromDate.day() - 1 ) ); | ||
459 | toMonth = mToDate.addDays( mToDate.daysInMonth() - mToDate.day() ); | ||
460 | |||
461 | curMonth = fromMonth; | ||
462 | do { | ||
463 | QString title( i18n("monthname year", "%1 %2") ); | ||
464 | title = title.arg( KOGlobals::self()->calendarSystem()->monthName( curMonth ) ) | ||
465 | .arg( curMonth.year() ); | ||
466 | QDate tmp( fromMonth ); | ||
467 | int weekdayCol = weekdayColumn( tmp.dayOfWeek() ); | ||
468 | tmp = tmp.addDays( -weekdayCol ); | ||
469 | |||
470 | drawHeader( p, title, | ||
471 | curMonth.addMonths( -1 ), curMonth.addMonths( 1 ), | ||
472 | xoffset, yoffset, width, mHeaderHeight ); | ||
473 | drawMonth( p, curMonth, mWeekNumbers, xoffset, mHeaderHeight + 5+yoffset, | ||
474 | width, height - mHeaderHeight - 5 ); | ||
475 | curMonth = curMonth.addDays( curMonth.daysInMonth() ); | ||
476 | if ( curMonth <= toMonth ) mPrinter->newPage(); | ||
477 | } while ( curMonth <= toMonth ); | ||
478 | |||
479 | } | ||
480 | |||
481 | |||
482 | |||
483 | |||
484 | /************************************************************** | ||
485 | * Print Todos | ||
486 | **************************************************************/ | ||
487 | |||
488 | CalPrintTodos::CalPrintTodos( KPrinter *printer, Calendar *cal, KConfig *cfg ) | ||
489 | : CalPrintBase( printer, cal, cfg ) | ||
490 | { | ||
491 | } | ||
492 | |||
493 | CalPrintTodos::~CalPrintTodos() | ||
494 | { | ||
495 | } | ||
496 | |||
497 | QWidget *CalPrintTodos::configWidget( QWidget *w ) | ||
498 | { | ||
499 | mConfigWidget = new CalPrintTodoConfig_Base( w ); | ||
500 | return mConfigWidget; | ||
501 | } | ||
502 | |||
503 | void CalPrintTodos::readSettingsWidget() | ||
504 | { | ||
505 | CalPrintTodoConfig_Base *cfg =( mConfigWidget ); | ||
506 | if ( cfg ) { | ||
507 | mPageTitle = cfg->mTitle->text(); | ||
508 | |||
509 | mTodoPrintType = (eTodoPrintType)( cfg->mPrintType->id( | ||
510 | cfg->mPrintType->selected() ) ); | ||
511 | |||
512 | mFromDate = cfg->mFromDate->date(); | ||
513 | mToDate = cfg->mToDate->date(); | ||
514 | |||
515 | mIncludeDescription = cfg->mDescription->isChecked(); | ||
516 | mIncludePriority = cfg->mPriority->isChecked(); | ||
517 | mIncludeDueDate = cfg->mDueDate->isChecked(); | ||
518 | mConnectSubTodos = cfg->mConnectSubTodos->isChecked(); | ||
519 | } | ||
520 | } | ||
521 | |||
522 | void CalPrintTodos::setSettingsWidget() | ||
523 | { | ||
524 | CalPrintTodoConfig_Base *cfg =( mConfigWidget ); | ||
525 | if ( cfg ) { | ||
526 | cfg->mTitle->setText( mPageTitle ); | ||
527 | |||
528 | cfg->mPrintType->setButton( mTodoPrintType ); | ||
529 | |||
530 | cfg->mFromDate->setDate( mFromDate ); | ||
531 | cfg->mToDate->setDate( mToDate ); | ||
532 | |||
533 | cfg->mDescription->setChecked( mIncludeDescription ); | ||
534 | cfg->mPriority->setChecked( mIncludePriority ); | ||
535 | cfg->mDueDate->setChecked( mIncludeDueDate ); | ||
536 | cfg->mConnectSubTodos->setChecked( mConnectSubTodos ); | ||
537 | } | ||
538 | } | ||
539 | |||
540 | void CalPrintTodos::loadConfig() | ||
541 | { | ||
542 | if ( mConfig ) { | ||
543 | mPageTitle = mConfig->readEntry( "Page title", i18n("Todo list") ); | ||
544 | mTodoPrintType = (eTodoPrintType)mConfig->readNumEntry( "Print type", (int)TodosAll ); | ||
545 | mIncludeDescription = mConfig->readBoolEntry( "Include description", true ); | ||
546 | mIncludePriority = mConfig->readBoolEntry( "Include priority", true ); | ||
547 | mIncludeDueDate = mConfig->readBoolEntry( "Include due date", true ); | ||
548 | mConnectSubTodos = mConfig->readBoolEntry( "Connect subtodos", true ); | ||
549 | mTodoPrintType = (eTodoPrintType) mConfig->readNumEntry( "Printing type", 0 ); | ||
550 | } | ||
551 | setSettingsWidget(); | ||
552 | } | ||
553 | |||
554 | void CalPrintTodos::saveConfig() | ||
555 | { | ||
556 | readSettingsWidget(); | ||
557 | if ( mConfig ) { | ||
558 | mConfig->writeEntry( "Page title", mPageTitle ); | ||
559 | mConfig->writeEntry( "Print type", int( mTodoPrintType ) ); | ||
560 | mConfig->writeEntry( "Include description", mIncludeDescription ); | ||
561 | mConfig->writeEntry( "Include priority", mIncludePriority ); | ||
562 | mConfig->writeEntry( "Include due date", mIncludeDueDate ); | ||
563 | mConfig->writeEntry( "Connect subtodos", mConnectSubTodos ); | ||
564 | mConfig->writeEntry( "Printing type", mTodoPrintType ); | ||
565 | } | ||
566 | } | ||
567 | |||
568 | void CalPrintTodos::print( QPainter &p, int width, int height ) | ||
569 | { | ||
570 | bool printCompleted = true; | ||
571 | if ( mTodoPrintType == 1 ) | ||
572 | printCompleted = false; | ||
573 | int yoffset = 0, xoffset = 0; | ||
574 | //width = height -1;//test only | ||
575 | if ( width > height ) { | ||
576 | yoffset += LEFT_DISTANCE; | ||
577 | } else { | ||
578 | xoffset += LEFT_DISTANCE; | ||
579 | } | ||
580 | width -= xoffset; | ||
581 | height -= yoffset; | ||
582 | |||
583 | int pospriority = 5+xoffset; | ||
584 | int possummary = 70+xoffset; | ||
585 | int posdue = width - 145; | ||
586 | int lineSpacing = 15; | ||
587 | int fontHeight = 10; | ||
588 | |||
589 | |||
590 | drawHeader( p, mPageTitle, mFromDate, QDate(), | ||
591 | 0+xoffset, 0+yoffset, width, mHeaderHeight ); | ||
592 | |||
593 | int mCurrentLinePos = mHeaderHeight + 5+yoffset; | ||
594 | QString outStr; | ||
595 | |||
596 | p.setFont( QFont( "helvetica", 10 ) ); | ||
597 | lineSpacing = p.fontMetrics().lineSpacing(); | ||
598 | mCurrentLinePos += lineSpacing; | ||
599 | // draw the headers | ||
600 | p.setFont( QFont("helvetica", 10, QFont::Bold ) ); | ||
601 | if ( mIncludePriority ) { | ||
602 | outStr += i18n("Priority"); | ||
603 | p.drawText( pospriority, mCurrentLinePos - 2, outStr); | ||
604 | } else { | ||
605 | possummary = 10; | ||
606 | pospriority = -1; | ||
607 | } | ||
608 | |||
609 | outStr.truncate( 0 ); | ||
610 | outStr += i18n("Summary"); | ||
611 | if ( mIncludeDueDate ) | ||
612 | outStr += i18n(" (Due)"); | ||
613 | |||
614 | p.drawText( possummary, mCurrentLinePos - 2, outStr ); | ||
615 | |||
616 | if ( mIncludeDueDate ) { | ||
617 | // outStr.truncate( 0 ); | ||
618 | // outStr += i18n("Due"); | ||
619 | // p.drawText( posdue, mCurrentLinePos - 2, outStr ); | ||
620 | } else { | ||
621 | posdue = -1; | ||
622 | } | ||
623 | |||
624 | p.setFont( QFont( "helvetica", 10 ) ); | ||
625 | |||
626 | fontHeight = p.fontMetrics().height(); | ||
627 | |||
628 | Todo::List todoList; | ||
629 | // if (mTodoPrintType==TodosSelected) { | ||
630 | // todoList.append(selectedTodoo); | ||
631 | // } else { | ||
632 | todoList.fill(mCalendar->todos()); | ||
633 | // } | ||
634 | // TODO_RK: filter out todos | ||
635 | |||
636 | int count = 0; | ||
637 | for( int cprior = 1; cprior <= 6; cprior++ ) { | ||
638 | Todo::List::ConstIterator it; | ||
639 | for( it = todoList.begin(); it != todoList.end(); ++it ) { | ||
640 | Todo *currEvent = *it; | ||
641 | |||
642 | // Filter out the subitems. | ||
643 | if ( currEvent->relatedTo() ) { | ||
644 | continue; | ||
645 | } | ||
646 | |||
647 | QDate start = currEvent->dtStart().date(); | ||
648 | // if it is not to start yet, skip. | ||
649 | // if ( ( !start.isValid() ) && ( start >= mToDate ) ) { | ||
650 | // continue; | ||
651 | //} | ||
652 | // priority | ||
653 | int priority = currEvent->priority(); | ||
654 | // 6 is the lowest priority (the unspecified one) | ||
655 | if ( ( priority != cprior ) || | ||
656 | ( ( cprior == 6 ) && ( priority == 0 ) ) ) { | ||
657 | continue; | ||
658 | } | ||
659 | count++; | ||
660 | int todoHeight = height - mCurrentLinePos; | ||
661 | drawTodo( printCompleted, count, currEvent, p, mConnectSubTodos, | ||
662 | mIncludeDescription, pospriority, possummary, posdue, 0, | ||
663 | 0, mCurrentLinePos, width, todoHeight, height ); | ||
664 | } | ||
665 | } | ||
666 | } | ||
667 | |||
668 | |||
669 | #endif | ||