28 #ifndef KORG_NOPRINTER
30 #include <tqpainter.h>
31 #include <tqdatetimeedit.h>
32 #include <tqcheckbox.h>
33 #include <tqlineedit.h>
34 #include <tqbuttongroup.h>
37 #include <tdeconfig.h>
38 #include <kcalendarsystem.h>
39 #include <knuminput.h>
40 #include <kcombobox.h>
42 #include <libkcal/incidenceformatter.h>
44 #include "calprintdefaultplugins.h"
46 #include "calprintincidenceconfig_base.h"
47 #include "calprintdayconfig_base.h"
48 #include "calprintweetdeconfig_base.h"
49 #include "calprintmonthconfig_base.h"
50 #include "calprinttodoconfig_base.h"
52 static TQString cleanString(
const TQString &instr )
55 return ret.replace(
'\n',
' ' );
66 CalPrintIncidence::~CalPrintIncidence()
70 TQWidget *CalPrintIncidence::createConfigWidget( TQWidget *w )
72 return new CalPrintIncidenceConfig_Base( w );
75 void CalPrintIncidence::readSettingsWidget()
77 CalPrintIncidenceConfig_Base *cfg =
78 dynamic_cast<CalPrintIncidenceConfig_Base*
>( mConfigWidget );
80 mUseColors = cfg->mColors->isChecked();
81 mShowOptions = cfg->mShowDetails->isChecked();
82 mShowSubitemsNotes = cfg->mShowSubitemsNotes->isChecked();
83 mShowAttendees = cfg->mShowAttendees->isChecked();
84 mShowAttachments = cfg->mShowAttachments->isChecked();
88 void CalPrintIncidence::setSettingsWidget()
90 CalPrintIncidenceConfig_Base *cfg =
91 dynamic_cast<CalPrintIncidenceConfig_Base*
>( mConfigWidget );
93 cfg->mColors->setChecked( mUseColors );
94 cfg->mShowDetails->setChecked(mShowOptions);
95 cfg->mShowSubitemsNotes->setChecked(mShowSubitemsNotes);
96 cfg->mShowAttendees->setChecked(mShowAttendees);
97 cfg->mShowAttachments->setChecked(mShowAttachments);
101 void CalPrintIncidence::loadConfig()
104 mUseColors = mConfig->readBoolEntry(
"Use Colors",
false );
105 mShowOptions = mConfig->readBoolEntry(
"Show Options",
false );
106 mShowSubitemsNotes = mConfig->readBoolEntry(
"Show Subitems and Notes",
false );
107 mShowAttendees = mConfig->readBoolEntry(
"Use Attendees",
false );
108 mShowAttachments = mConfig->readBoolEntry(
"Use Attachments",
false );
113 void CalPrintIncidence::saveConfig()
115 readSettingsWidget();
117 mConfig->writeEntry(
"Use Colors", mUseColors );
118 mConfig->writeEntry(
"Show Options", mShowOptions );
119 mConfig->writeEntry(
"Show Subitems and Notes", mShowSubitemsNotes );
120 mConfig->writeEntry(
"Use Attendees", mShowAttendees );
121 mConfig->writeEntry(
"Use Attachments", mShowAttachments );
129 TimePrintStringsVisitor() {}
133 return incidence->
accept( *
this );
135 TQString mStartCaption, mStartString;
136 TQString mEndCaption, mEndString;
137 TQString mDurationCaption, mDurationString;
141 if ( event->
dtStart().isValid() ) {
142 mStartCaption = i18n(
"Start date: " );
143 mStartString = IncidenceFormatter::dateTimeToString(
146 mStartCaption = i18n(
"No start date" );
147 mStartString = TQString();
151 mEndCaption = i18n(
"End date: " );
152 mEndString = IncidenceFormatter::dateTimeToString(
154 }
else if ( event->hasDuration() ) {
155 mEndCaption = i18n(
"Duration: ");
156 int mins =
event->duration() / 60;
158 mEndString += i18n(
"1 hour ",
"%n hours ", mins/60 );
161 mEndString += i18n(
"1 minute ",
"%n minutes ", mins%60 );
164 mEndCaption = i18n(
"No end date");
165 mEndString = TQString();
171 mStartCaption = i18n(
"Start date: " );
172 mStartString = IncidenceFormatter::dateTimeToString(
175 mStartCaption = i18n(
"No start date" );
176 mStartString = TQString();
180 mEndCaption = i18n(
"Due date: " );
181 mEndString = IncidenceFormatter::dateTimeToString(
184 mEndCaption = i18n(
"No due date");
185 mEndString = TQString();
190 mStartCaption = i18n(
"Start date: " );
191 mStartString = IncidenceFormatter::dateTimeToString(
193 mEndCaption = TQString();
194 mEndString = TQString();
199 int CalPrintIncidence::printCaptionAndText( TQPainter &p,
const TQRect &box,
const TQString &caption,
const TQString &text, TQFont captionFont, TQFont textFont )
201 TQFontMetrics captionFM( captionFont );
202 int textWd = captionFM.width( caption );
203 TQRect textRect( box );
205 TQFont oldFont( p.font() );
206 p.setFont( captionFont );
207 p.drawText( box, TQt::AlignLeft|TQt::AlignTop|TQt::SingleLine, caption );
209 if ( !text.isEmpty() ) {
210 textRect.setLeft( textRect.left() + textWd );
211 p.setFont( textFont );
212 p.drawText( textRect, TQt::AlignLeft|TQt::AlignTop|TQt::SingleLine, text );
214 p.setFont( oldFont );
215 return textRect.bottom();
218 #include <tqfontdatabase.h>
219 void CalPrintIncidence::print( TQPainter &p,
int width,
int height )
221 TQFont oldFont(p.font());
222 TQFont textFont(
"sans-serif", 11, TQFont::Normal );
223 TQFont captionFont(
"sans-serif", 11, TQFont::Bold );
224 p.setFont( textFont );
225 int lineHeight = p.fontMetrics().lineSpacing();
229 Incidence::List::ConstIterator it;
230 for ( it=mSelectedIncidences.begin(); it!=mSelectedIncidences.end(); ++it ) {
232 if ( !(*it) )
continue;
233 if ( it != mSelectedIncidences.begin() ) mPrinter->newPage();
266 TQRect box( 0, 0, width, height );
267 TQRect titleBox( box );
268 titleBox.setHeight( headerHeight() );
270 int titleBottom = drawHeader( p, (*it)->summary(), TQDate(), TQDate(), titleBox,
true );
271 titleBox.setBottom( titleBottom );
273 TQRect timesBox( titleBox );
274 timesBox.setTop( titleBox.bottom() + padding() );
275 timesBox.setHeight( height / 8 );
277 TimePrintStringsVisitor stringVis;
278 int h = timesBox.top();
279 if ( stringVis.act(*it) ) {
280 TQRect textRect( timesBox.left()+padding(), timesBox.top()+padding(), 0, lineHeight );
281 textRect.setRight( timesBox.center().x() );
282 h = printCaptionAndText( p, textRect, stringVis.mStartCaption, stringVis.mStartString, captionFont, textFont );
284 textRect.setLeft( textRect.right() );
285 textRect.setRight( timesBox.right() - padding() );
286 h = TQMAX( printCaptionAndText( p, textRect, stringVis.mEndCaption, stringVis.mEndString, captionFont, textFont ), h );
290 if ( (*it)->doesRecur() ) {
291 TQRect recurBox( timesBox.left()+padding(), h+padding(), timesBox.right()-padding(), lineHeight );
294 TQString displayString = IncidenceFormatter::recurrenceString((*it));
296 TQString exceptString;
297 if ( !recurs->exDates().isEmpty() ) {
298 exceptString = i18n(
"except for listed dates",
" except");
299 for ( uint i = 0; i < recurs->exDates().size(); i++ ) {
300 exceptString.append(
" ");
301 exceptString.append( TDEGlobal::locale()->formatDate(recurs->exDates()[i],
305 displayString.append(exceptString);
306 h = TQMAX( printCaptionAndText( p, recurBox, i18n(
"Repeats: "), displayString, captionFont, textFont ), h );
310 TQRect alarmBox( timesBox.left()+padding(), h+padding(), timesBox.right()-padding(), lineHeight );
311 Alarm::List alarms = (*it)->alarms();
312 if ( alarms.count() == 0 ) {
313 cap = i18n(
"No reminders");
316 cap = i18n(
"Reminder: ",
"%n reminders: ", alarms.count() );
318 TQStringList alarmStrings;
319 KCal::Alarm::List::ConstIterator it;
320 for ( it = alarms.begin(); it != alarms.end(); ++it ) {
329 offsetstr = i18n(
"N days/hours/minutes before/after the start/end",
"%1 before the start");
332 offsetstr = i18n(
"N days/hours/minutes before/after the start/end",
"%1 after the start");
337 offsetstr = i18n(
"N days/hours/minutes before/after the start/end",
"%1 before the end");
340 offsetstr = i18n(
"N days/hours/minutes before/after the start/end",
"%1 after the end");
344 offset = offset / 60;
345 int useoffset = offset;
347 if ( offset % (24*60) == 0 && offset>0 ) {
348 useoffset = offset / (24*60);
349 offsetstr = offsetstr.arg( i18n(
"1 day",
"%n days", useoffset ) );
350 }
else if (offset % 60 == 0 && offset>0 ) {
351 useoffset = offset / 60;
352 offsetstr = offsetstr.arg( i18n(
"1 hour",
"%n hours", useoffset ) );
355 offsetstr = offsetstr.arg( i18n(
"1 minute",
"%n minutes", useoffset ) );
357 alarmStrings << offsetstr;
359 txt = alarmStrings.join( i18n(
"Spacer for the joined list of categories",
", ") );
362 h = TQMAX( printCaptionAndText( p, alarmBox, cap, txt, captionFont, textFont ), h );
365 TQRect organizerBox( timesBox.left()+padding(), h+padding(), timesBox.right()-padding(), lineHeight );
366 h = TQMAX( printCaptionAndText( p, organizerBox, i18n(
"Organizer: "), (*it)->organizer().fullName(), captionFont, textFont ), h );
369 timesBox.setBottom( TQMAX( timesBox.bottom(), h+padding() ) );
370 drawBox( p, BOX_BORDER_WIDTH, timesBox );
373 TQRect locationBox( timesBox );
374 locationBox.setTop( timesBox.bottom() + padding() );
375 locationBox.setHeight( 0 );
376 int locationBottom = drawBoxWithCaption( p, locationBox, i18n(
"Location: "),
377 (*it)->location(),
true,
true, captionFont, textFont );
378 locationBox.setBottom( locationBottom );
382 TQRect footerBox( locationBox );
383 footerBox.setBottom( box.bottom() );
384 footerBox.setTop( footerBox.bottom() - lineHeight - 2*padding() );
386 TQRect categoriesBox( footerBox );
387 categoriesBox.setBottom( footerBox.top() );
388 categoriesBox.setTop( categoriesBox.bottom() - lineHeight - 2*padding() );
390 TQRect attendeesBox( box.left(), categoriesBox.top()-padding()-box.height()/9, box.width(), box.height()/9 );
392 TQRect attachmentsBox( box.left(), attendeesBox.top()-padding()-box.height()/9, box.width()*3/4 - padding(), box.height()/9 );
393 TQRect optionsBox( attachmentsBox.right() + padding(), attachmentsBox.top(), 0, 0 );
394 optionsBox.setRight( box.right() );
395 optionsBox.setBottom( attachmentsBox.bottom() );
396 TQRect notesBox( optionsBox.left(), locationBox.bottom() + padding(), optionsBox.width(), 0 );
397 notesBox.setBottom( optionsBox.top() - padding() );
399 TQRect descriptionBox( notesBox );
400 descriptionBox.setLeft( box.left() );
401 descriptionBox.setRight( attachmentsBox.right() );
403 if (!mShowSubitemsNotes) {
404 descriptionBox.setRight( box.right() );
406 if (!mShowAttachments || !mShowAttendees) {
407 descriptionBox.setBottom( attachmentsBox.bottom() );
408 optionsBox.setTop( attendeesBox.top() );
409 optionsBox.setBottom( attendeesBox.bottom() );
410 notesBox.setBottom( attachmentsBox.bottom() );
412 attendeesBox.setRight( attachmentsBox.right() );
414 if (!mShowAttachments && !mShowAttendees) {
415 if (mShowSubitemsNotes) {
416 descriptionBox.setBottom( attendeesBox.bottom() );
419 descriptionBox.setBottom( attendeesBox.bottom() );
420 notesBox.setBottom( attendeesBox.bottom() );
424 if (mShowAttachments) {
426 attachmentsBox.setRight( box.right() );
427 attachmentsBox.setRight( box.right() );
429 if (!mShowAttendees) {
430 attachmentsBox.setTop( attendeesBox.top() );
431 attachmentsBox.setBottom( attendeesBox.bottom() );
435 drawBoxWithCaption( p, descriptionBox, i18n(
"Description:"),
436 (*it)->description(),
false,
437 false, captionFont, textFont );
439 if ( mShowSubitemsNotes ) {
440 if ( (*it)->relations().isEmpty() || (*it)->type() !=
"Todo" ) {
441 int notesPosition = drawBoxWithCaption( p, notesBox, i18n(
"Notes:"),
442 TQString(),
false,
false,
443 captionFont, textFont );
444 TQPen oldPen( p.pen() );
445 p.setPen( TQt::DotLine );
446 while ( (notesPosition +=
int(1.5*lineHeight)) < notesBox.bottom() ) {
447 p.drawLine( notesBox.left()+padding(), notesPosition, notesBox.right()-padding(), notesPosition );
451 Incidence::List relations = (*it)->relations();
452 TQString subitemCaption;
453 if ( relations.count() == 0 ) {
454 subitemCaption = i18n(
"No Subitems" );
457 subitemCaption = i18n(
"1 Subitem:",
461 Incidence::List::ConstIterator rit;
462 TQString subitemString;
463 TQString statusString;
464 TQString datesString;
466 for ( rit = relations.begin(); rit != relations.end(); ++rit ) {
472 statusString = (*rit)->statusStr();
473 if ( statusString.isEmpty() ) {
474 if ( (*rit)->status() == Incidence::StatusNone ) {
475 statusString = i18n(
"no status",
"none" );
477 statusString = i18n(
"unknown status",
"unknown" );
482 if ( (*rit)->dtStart().isValid() ) {
484 "Start Date: %1\n").arg(
485 TDEGlobal::locale()->formatDate( (*rit)->dtStart().date(),
487 if ( !(*rit)->doesFloat() ) {
489 "Start Time: %1\n").arg(
490 TDEGlobal::locale()->formatTime((*rit)->dtStart().time(),
494 if ( (*rit)->dtEnd().isValid() ) {
495 subitemString += i18n(
496 "Due Date: %1\n").arg(
497 TDEGlobal::locale()->formatDate( (*rit)->dtEnd().date(),
499 if ( !(*rit)->doesFloat() ) {
500 subitemString += i18n(
501 "subitem due time",
"Due Time: %1\n").arg(
502 TDEGlobal::locale()->formatTime((*rit)->dtEnd().time(),
506 subitemString += i18n(
"subitem counter",
"%1: ", count);
507 subitemString += (*rit)->summary();
508 subitemString +=
"\n";
509 if ( !datesString.isEmpty() ) {
510 subitemString += datesString;
511 subitemString +=
"\n";
513 subitemString += i18n(
"subitem Status: statusString",
514 "Status: %1\n").arg( statusString );
515 subitemString += IncidenceFormatter::recurrenceString((*rit)) +
"\n";
516 subitemString += i18n(
"subitem Priority: N",
517 "Priority: %1\n").arg( (*rit)->priority() );
518 subitemString += i18n(
"subitem Secrecy: secrecyString",
519 "Secrecy: %1\n").arg( (*rit)->secrecyStr() );
520 subitemString +=
"\n";
522 drawBoxWithCaption( p, notesBox, i18n(
"Subitems:"),
523 (*it)->description(),
false,
524 false, captionFont, textFont );
528 if ( mShowAttachments ) {
529 Attachment::List attachments = (*it)->attachments();
530 TQString attachmentCaption;
531 if ( attachments.count() == 0 ) {
532 attachmentCaption = i18n(
"No Attachments" );
535 attachmentCaption = i18n(
"1 Attachment:",
"%1 Attachments:", attachments.count() );
537 TQString attachmentString;
538 Attachment::List::ConstIterator ait = attachments.begin();
539 for ( ; ait != attachments.end(); ++ait ) {
540 if (!attachmentString.isEmpty()) {
541 attachmentString += i18n(
"Spacer for list of attachments",
" " );
543 attachmentString.append((*ait)->label());
545 drawBoxWithCaption( p, attachmentsBox,
546 attachmentCaption, attachmentString,
548 captionFont, textFont );
551 if ( mShowAttendees ) {
552 Attendee::List attendees = (*it)->attendees();
553 TQString attendeeCaption;
554 if ( attendees.count() == 0 )
555 attendeeCaption = i18n(
"No Attendees");
557 attendeeCaption = i18n(
"1 Attendee:",
"%n Attendees:", attendees.count() );
558 TQString attendeeString;
559 for ( Attendee::List::ConstIterator ait = attendees.begin(); ait != attendees.end(); ++ait ) {
560 if ( !attendeeString.isEmpty() ) attendeeString +=
"\n";
561 attendeeString += i18n(
"Formatting of an attendee: "
562 "'Name (Role): Status', e.g. 'Reinhold Kainhofer "
563 "<reinhold@kainhofer.com> (Participant): Awaiting Response'",
565 .arg( (*ait)->fullName() )
566 .arg( (*ait)->roleStr() ).arg( (*ait)->statusStr() );
568 drawBoxWithCaption( p, attendeesBox, i18n(
"Attendees:"), attendeeString,
569 false,
false, captionFont, textFont );
572 if ( mShowOptions ) {
573 TQString optionsString;
574 if ( !(*it)->statusStr().isEmpty() ) {
575 optionsString += i18n(
"Status: %1").arg( (*it)->statusStr() );
576 optionsString +=
"\n";
578 if ( !(*it)->secrecyStr().isEmpty() ) {
579 optionsString += i18n(
"Secrecy: %1").arg( (*it)->secrecyStr() );
580 optionsString +=
"\n";
582 if ( (*it)->type() ==
"Event" ) {
585 optionsString += i18n(
"Show as: Busy");
587 optionsString += i18n(
"Show as: Free");
589 optionsString +=
"\n";
590 }
else if ( (*it)->type() ==
"Todo" ) {
593 optionsString += i18n(
"This task is overdue!");
594 optionsString +=
"\n";
596 }
else if ( (*it)->type() ==
"Journal" ) {
599 drawBoxWithCaption( p, optionsBox, i18n(
"Settings: "),
600 optionsString,
false,
false, captionFont, textFont );
603 drawBoxWithCaption( p, categoriesBox, i18n(
"Categories: "),
604 (*it)->categories().join( i18n(
"Spacer for the joined list of categories",
", ") ),
605 true,
false, captionFont, textFont );
607 drawFooter( p, footerBox );
609 p.setFont( oldFont );
620 CalPrintDay::~CalPrintDay()
624 TQWidget *CalPrintDay::createConfigWidget( TQWidget *w )
626 return new CalPrintDayConfig_Base( w );
629 void CalPrintDay::readSettingsWidget()
631 CalPrintDayConfig_Base *cfg =
632 dynamic_cast<CalPrintDayConfig_Base*
>( mConfigWidget );
634 mFromDate = cfg->mFromDate->date();
635 mToDate = cfg->mToDate->date();
637 mStartTime = cfg->mFromTime->time();
638 mEndTime = cfg->mToTime->time();
639 mIncludeAllEvents = cfg->mIncludeAllEvents->isChecked();
641 mIncludeTodos = cfg->mIncludeTodos->isChecked();
642 mUseColors = cfg->mColors->isChecked();
646 void CalPrintDay::setSettingsWidget()
648 CalPrintDayConfig_Base *cfg =
649 dynamic_cast<CalPrintDayConfig_Base*
>( mConfigWidget );
651 cfg->mFromDate->setDate( mFromDate );
652 cfg->mToDate->setDate( mToDate );
654 cfg->mFromTime->setTime( mStartTime );
655 cfg->mToTime->setTime( mEndTime );
656 cfg->mIncludeAllEvents->setChecked( mIncludeAllEvents );
658 cfg->mIncludeTodos->setChecked( mIncludeTodos );
659 cfg->mColors->setChecked( mUseColors );
663 void CalPrintDay::loadConfig()
667 TQTime tm1( dayStart() );
668 TQDateTime startTm( dt, tm1 );
669 TQDateTime endTm( dt, tm1.addSecs( 12 * 60 * 60 ) );
670 mStartTime = mConfig->readDateTimeEntry(
"Start time", &startTm ).time();
671 mEndTime = mConfig->readDateTimeEntry(
"End time", &endTm ).time();
672 mIncludeTodos = mConfig->readBoolEntry(
"Include todos",
false );
673 mIncludeAllEvents = mConfig->readBoolEntry(
"Include all events",
false );
678 void CalPrintDay::saveConfig()
680 readSettingsWidget();
682 mConfig->writeEntry(
"Start time", TQDateTime( TQDate(), mStartTime ) );
683 mConfig->writeEntry(
"End time", TQDateTime( TQDate(), mEndTime ) );
684 mConfig->writeEntry(
"Include todos", mIncludeTodos );
685 mConfig->writeEntry(
"Include all events", mIncludeAllEvents );
689 void CalPrintDay::setDateRange(
const TQDate& from,
const TQDate& to )
692 CalPrintDayConfig_Base *cfg =
693 dynamic_cast<CalPrintDayConfig_Base*
>( mConfigWidget );
695 cfg->mFromDate->setDate( from );
696 cfg->mToDate->setDate( to );
700 void CalPrintDay::print( TQPainter &p,
int width,
int height )
702 TQDate curDay( mFromDate );
704 TQRect headerBox( 0, 0, width, headerHeight() );
705 TQRect footerBox( 0, height - footerHeight(), width, footerHeight() );
706 height -= footerHeight();
708 TDELocale *local = TDEGlobal::locale();
711 TQTime curStartTime( mStartTime );
712 TQTime curEndTime( mEndTime );
716 if ( curEndTime <= curStartTime ) {
717 curStartTime = TQTime( curStartTime.hour(), 0, 0 );
718 curEndTime = curStartTime.addSecs( 3600 );
721 drawHeader( p, local->formatDate( curDay ), curDay, TQDate(), headerBox );
722 Event::List eventList = mCalendar->events( curDay,
724 SortDirectionAscending );
727 Event::List alldayEvents, timedEvents;
728 Event::List::ConstIterator it;
729 for ( it = eventList.begin(); it != eventList.end(); ++it ) {
730 if ( (*it)->doesFloat() ) {
731 alldayEvents.append( *it );
733 timedEvents.append( *it );
738 TQFont textFont(
"sans-serif", fontSize, TQFont::Normal );
739 p.setFont( textFont );
740 uint lineSpacing = p.fontMetrics().lineSpacing();
742 uint maxAllDayEvents = 8;
743 uint allDayHeight = TQMIN( alldayEvents.count(), maxAllDayEvents ) * lineSpacing;
744 allDayHeight = TQMAX( allDayHeight, ( 5 * lineSpacing ) ) + ( 2 * padding() );
745 TQRect allDayBox( TIMELINE_WIDTH + padding(), headerBox.bottom() + padding(),
746 width - TIMELINE_WIDTH - padding(), allDayHeight );
747 if ( alldayEvents.count() > 0 ) {
749 TQFont oldFont( p.font() );
750 p.setFont( TQFont(
"sans-serif", 9, TQFont::Normal ) );
753 TQRect( 0, headerBox.bottom() + padding(), TIMELINE_WIDTH, allDayHeight ),
754 i18n(
"Today's Events" ),
755 TQt::AlignHCenter | TQt::AlignVCenter | TQt::WordBreak );
756 p.setFont( oldFont );
759 drawBox( p, BOX_BORDER_WIDTH, allDayBox );
761 Event::List::ConstIterator it;
762 TQRect eventBox( allDayBox );
763 eventBox.setLeft( TIMELINE_WIDTH + ( 2 * padding() ) );
764 eventBox.setTop( eventBox.top() + padding() );
765 eventBox.setBottom( eventBox.top() + lineSpacing );
767 for ( it = alldayEvents.begin(); it != alldayEvents.end(); ++it ) {
768 if ( count == maxAllDayEvents ) {
773 if ( (*it)->location().isEmpty() ) {
774 str = cleanString( (*it)->summary() );
776 str = i18n(
"summary, location",
"%1, %2" ).
777 arg( cleanString( (*it)->summary() ), cleanString( (*it)->location() ) );
779 printEventString( p, eventBox, str );
780 eventBox.setTop( eventBox.bottom() );
781 eventBox.setBottom( eventBox.top() + lineSpacing );
784 allDayBox.setBottom( headerBox.bottom() );
787 TQRect dayBox( allDayBox );
788 dayBox.setTop( allDayBox.bottom() + padding() );
789 dayBox.setBottom( height );
790 drawAgendaDayBox( p, timedEvents, curDay, mIncludeAllEvents,
791 curStartTime, curEndTime, dayBox );
793 TQRect tlBox( dayBox );
795 tlBox.setWidth( TIMELINE_WIDTH );
796 drawTimeLine( p, curStartTime, curEndTime, tlBox );
798 drawFooter( p, footerBox );
800 curDay = curDay.addDays( 1 );
801 if ( curDay <= mToDate ) {
804 }
while ( curDay <= mToDate );
817 CalPrintWeek::~CalPrintWeek()
821 TQWidget *CalPrintWeek::createConfigWidget( TQWidget *w )
823 return new CalPrintWeekConfig_Base( w );
826 void CalPrintWeek::readSettingsWidget()
828 CalPrintWeekConfig_Base *cfg =
829 dynamic_cast<CalPrintWeekConfig_Base*
>( mConfigWidget );
831 mFromDate = cfg->mFromDate->date();
832 mToDate = cfg->mToDate->date();
834 mWeekPrintType = (eWeekPrintType)( cfg->mPrintType->id(
835 cfg->mPrintType->selected() ) );
837 mStartTime = cfg->mFromTime->time();
838 mEndTime = cfg->mToTime->time();
840 mIncludeTodos = cfg->mIncludeTodos->isChecked();
841 mUseColors = cfg->mColors->isChecked();
845 void CalPrintWeek::setSettingsWidget()
847 CalPrintWeekConfig_Base *cfg =
848 dynamic_cast<CalPrintWeekConfig_Base*
>( mConfigWidget );
850 cfg->mFromDate->setDate( mFromDate );
851 cfg->mToDate->setDate( mToDate );
853 cfg->mPrintType->setButton( mWeekPrintType );
855 cfg->mFromTime->setTime( mStartTime );
856 cfg->mToTime->setTime( mEndTime );
858 cfg->mIncludeTodos->setChecked( mIncludeTodos );
859 cfg->mColors->setChecked( mUseColors );
863 void CalPrintWeek::loadConfig()
867 TQTime tm1( dayStart() );
868 TQDateTime startTm( dt, tm1 );
869 TQDateTime endTm( dt, tm1.addSecs( 43200 ) );
870 mStartTime = mConfig->readDateTimeEntry(
"Start time", &startTm ).time();
871 mEndTime = mConfig->readDateTimeEntry(
"End time", &endTm ).time();
872 mIncludeTodos = mConfig->readBoolEntry(
"Include todos",
false );
873 mWeekPrintType =(eWeekPrintType)( mConfig->readNumEntry(
"Print type", (
int)Filofax ) );
878 void CalPrintWeek::saveConfig()
880 readSettingsWidget();
882 mConfig->writeEntry(
"Start time", TQDateTime( TQDate(), mStartTime ) );
883 mConfig->writeEntry(
"End time", TQDateTime( TQDate(), mEndTime ) );
884 mConfig->writeEntry(
"Include todos", mIncludeTodos );
885 mConfig->writeEntry(
"Print type",
int( mWeekPrintType ) );
889 KPrinter::Orientation CalPrintWeek::defaultOrientation()
891 if ( mWeekPrintType == Filofax )
return KPrinter::Portrait;
892 else if ( mWeekPrintType == SplitWeek )
return KPrinter::Portrait;
893 else return KPrinter::Landscape;
896 void CalPrintWeek::setDateRange(
const TQDate &from,
const TQDate &to )
899 CalPrintWeekConfig_Base *cfg =
900 dynamic_cast<CalPrintWeekConfig_Base*
>( mConfigWidget );
902 cfg->mFromDate->setDate( from );
903 cfg->mToDate->setDate( to );
907 void CalPrintWeek::print( TQPainter &p,
int width,
int height )
909 TQDate curWeek, fromWeek, toWeek;
912 int weekdayCol = weekdayColumn( mFromDate.dayOfWeek() );
913 fromWeek = mFromDate.addDays( -weekdayCol );
914 weekdayCol = weekdayColumn( mFromDate.dayOfWeek() );
915 toWeek = mToDate.addDays( 6 - weekdayCol );
917 curWeek = fromWeek.addDays( 6 );
918 TDELocale *local = TDEGlobal::locale();
920 TQString line1, line2, title;
921 TQRect headerBox( 0, 0, width, headerHeight() );
922 TQRect footerBox( 0, height - footerHeight(), width, footerHeight() );
923 height -= footerHeight();
925 TQRect weekBox( headerBox );
926 weekBox.setTop( headerBox.bottom() + padding() );
927 weekBox.setBottom( height );
929 switch ( mWeekPrintType ) {
932 line1 = local->formatDate( curWeek.addDays( -6 ) );
933 line2 = local->formatDate( curWeek );
934 if ( orientation() == KPrinter::Landscape ) {
935 title = i18n(
"date from-to",
"%1 - %2");
937 title = i18n(
"date from-\nto",
"%1 -\n%2");;
939 title = title.arg( line1 ).arg( line2 );
940 drawHeader( p, title, curWeek.addDays( -6 ), TQDate(), headerBox );
942 drawWeek( p, curWeek, weekBox );
944 drawFooter( p, footerBox );
946 curWeek = curWeek.addDays( 7 );
947 if ( curWeek <= toWeek )
949 }
while ( curWeek <= toWeek );
955 line1 = local->formatDate( curWeek.addDays( -6 ) );
956 line2 = local->formatDate( curWeek );
957 if ( orientation() == KPrinter::Landscape ) {
958 title = i18n(
"date from - to (week number)",
"%1 - %2 (Week %3)");
960 title = i18n(
"date from -\nto (week number)",
"%1 -\n%2 (Week %3)");
962 title = title.arg( line1 ).arg( line2 ).arg( curWeek.weekNumber() );
963 drawHeader( p, title, curWeek, TQDate(), headerBox );
965 TQRect weekBox( headerBox );
966 weekBox.setTop( headerBox.bottom() + padding() );
967 weekBox.setBottom( height );
968 drawTimeTable( p, fromWeek, curWeek, mStartTime, mEndTime, weekBox );
970 drawFooter( p, footerBox );
972 fromWeek = fromWeek.addDays( 7 );
973 curWeek = fromWeek.addDays( 6 );
974 if ( curWeek <= toWeek )
976 }
while ( curWeek <= toWeek );
980 TQRect weekBox1( weekBox );
984 weekBox1.setRight(
int( ( width - TIMELINE_WIDTH ) * 3. / 4. + TIMELINE_WIDTH ) );
986 TQDate endLeft( fromWeek.addDays( 3 ) );
987 int hh = headerHeight();
989 drawTimeTable( p, fromWeek, endLeft,
990 mStartTime, mEndTime, weekBox );
992 drawSplitHeaderRight( p, fromWeek, curWeek, TQDate(), width, hh );
993 drawTimeTable( p, endLeft.addDays( 1 ), curWeek,
994 mStartTime, mEndTime, weekBox1 );
996 drawFooter( p, footerBox );
998 fromWeek = fromWeek.addDays( 7 );
999 curWeek = fromWeek.addDays( 6 );
1000 if ( curWeek <= toWeek )
1001 mPrinter->newPage();
1002 }
while ( curWeek <= toWeek );
1019 CalPrintMonth::~CalPrintMonth()
1023 TQWidget *CalPrintMonth::createConfigWidget( TQWidget *w )
1025 return new CalPrintMonthConfig_Base( w );
1028 void CalPrintMonth::readSettingsWidget()
1030 CalPrintMonthConfig_Base *cfg =
1031 dynamic_cast<CalPrintMonthConfig_Base *
>( mConfigWidget );
1033 mFromDate = TQDate( cfg->mFromYear->value(), cfg->mFromMonth->currentItem()+1, 1 );
1034 mToDate = TQDate( cfg->mToYear->value(), cfg->mToMonth->currentItem()+1, 1 );
1036 mWeekNumbers = cfg->mWeekNumbers->isChecked();
1037 mRecurDaily = cfg->mRecurDaily->isChecked();
1038 mRecurWeekly = cfg->mRecurWeekly->isChecked();
1039 mIncludeTodos = cfg->mIncludeTodos->isChecked();
1044 void CalPrintMonth::setSettingsWidget()
1046 CalPrintMonthConfig_Base *cfg =
1047 dynamic_cast<CalPrintMonthConfig_Base *
>( mConfigWidget );
1048 setDateRange( mFromDate, mToDate );
1050 cfg->mWeekNumbers->setChecked( mWeekNumbers );
1051 cfg->mRecurDaily->setChecked( mRecurDaily );
1052 cfg->mRecurWeekly->setChecked( mRecurWeekly );
1053 cfg->mIncludeTodos->setChecked( mIncludeTodos );
1058 void CalPrintMonth::loadConfig()
1061 mWeekNumbers = mConfig->readBoolEntry(
"Print week numbers",
true );
1062 mRecurDaily = mConfig->readBoolEntry(
"Print daily incidences",
true );
1063 mRecurWeekly = mConfig->readBoolEntry(
"Print weekly incidences",
true );
1064 mIncludeTodos = mConfig->readBoolEntry(
"Include todos",
false );
1066 setSettingsWidget();
1069 void CalPrintMonth::saveConfig()
1071 readSettingsWidget();
1073 mConfig->writeEntry(
"Print week numbers", mWeekNumbers );
1074 mConfig->writeEntry(
"Print daily incidences", mRecurDaily );
1075 mConfig->writeEntry(
"Print weekly incidences", mRecurWeekly );
1076 mConfig->writeEntry(
"Include todos", mIncludeTodos );
1080 void CalPrintMonth::setDateRange(
const TQDate &from,
const TQDate &to )
1083 CalPrintMonthConfig_Base *cfg =
1084 dynamic_cast<CalPrintMonthConfig_Base *
>( mConfigWidget );
1085 const KCalendarSystem *calSys = calendarSystem();
1086 if ( cfg && calSys ) {
1087 cfg->mFromMonth->clear();
1088 for (
int i=0; i<calSys->monthsInYear( mFromDate ); ++i ) {
1089 cfg->mFromMonth->insertItem( calSys->monthName( i+1, mFromDate.year() ) );
1091 cfg->mToMonth->clear();
1092 for (
int i=0; i<calSys->monthsInYear( mToDate ); ++i ) {
1093 cfg->mToMonth->insertItem( calSys->monthName( i+1, mToDate.year() ) );
1097 cfg->mFromMonth->setCurrentItem( from.month()-1 );
1098 cfg->mFromYear->setValue( to.year() );
1099 cfg->mToMonth->setCurrentItem( mToDate.month()-1 );
1100 cfg->mToYear->setValue( mToDate.year() );
1104 void CalPrintMonth::print( TQPainter &p,
int width,
int height )
1106 TQDate curMonth, fromMonth, toMonth;
1108 fromMonth = mFromDate.addDays( -( mFromDate.day() - 1 ) );
1109 toMonth = mToDate.addDays( mToDate.daysInMonth() - mToDate.day() );
1111 curMonth = fromMonth;
1112 const KCalendarSystem *calSys = calendarSystem();
1113 if ( !calSys )
return;
1115 TQRect headerBox( 0, 0, width, headerHeight() );
1116 TQRect footerBox( 0, height - footerHeight(), width, footerHeight() );
1117 height -= footerHeight();
1119 TQRect monthBox( 0, 0, width, height );
1120 monthBox.setTop( headerBox.bottom() + padding() );
1123 TQString title( i18n(
"monthname year",
"%1 %2") );
1124 title = title.arg( calSys->monthName( curMonth ) )
1125 .arg( curMonth.year() );
1126 TQDate tmp( fromMonth );
1127 int weekdayCol = weekdayColumn( tmp.dayOfWeek() );
1128 tmp = tmp.addDays( -weekdayCol );
1130 drawHeader( p, title, curMonth.addMonths( -1 ), curMonth.addMonths( 1 ),
1132 drawMonthTable( p, curMonth, mWeekNumbers, mRecurDaily, mRecurWeekly, monthBox );
1134 drawFooter( p, footerBox );
1136 curMonth = curMonth.addDays( curMonth.daysInMonth() );
1137 if ( curMonth <= toMonth ) mPrinter->newPage();
1138 }
while ( curMonth <= toMonth );
1151 mTodoSortField = TodoFieldUnset;
1152 mTodoSortDirection = TodoDirectionUnset;
1155 CalPrintTodos::~CalPrintTodos()
1159 TQWidget *CalPrintTodos::createConfigWidget( TQWidget *w )
1161 return new CalPrintTodoConfig_Base( w );
1164 void CalPrintTodos::readSettingsWidget()
1166 CalPrintTodoConfig_Base *cfg =
1167 dynamic_cast<CalPrintTodoConfig_Base *
>( mConfigWidget );
1169 mPageTitle = cfg->mTitle->text();
1171 mTodoPrintType = (eTodoPrintType)( cfg->mPrintType->id(
1172 cfg->mPrintType->selected() ) );
1174 mFromDate = cfg->mFromDate->date();
1175 mToDate = cfg->mToDate->date();
1177 mIncludeDescription = cfg->mDescription->isChecked();
1178 mIncludePriority = cfg->mPriority->isChecked();
1179 mIncludeDueDate = cfg->mDueDate->isChecked();
1180 mIncludePercentComplete = cfg->mPercentComplete->isChecked();
1181 mConnectSubTodos = cfg->mConnectSubTodos->isChecked();
1182 mStrikeOutCompleted = cfg->mStrikeOutCompleted->isChecked();
1184 mTodoSortField = (eTodoSortField)cfg->mSortField->currentItem();
1185 mTodoSortDirection = (eTodoSortDirection)cfg->mSortDirection->currentItem();
1189 void CalPrintTodos::setSettingsWidget()
1193 CalPrintTodoConfig_Base *cfg =
1194 dynamic_cast<CalPrintTodoConfig_Base *
>( mConfigWidget );
1196 cfg->mTitle->setText( mPageTitle );
1198 cfg->mPrintType->setButton( mTodoPrintType );
1200 cfg->mFromDate->setDate( mFromDate );
1201 cfg->mToDate->setDate( mToDate );
1203 cfg->mDescription->setChecked( mIncludeDescription );
1204 cfg->mPriority->setChecked( mIncludePriority );
1205 cfg->mDueDate->setChecked( mIncludeDueDate );
1206 cfg->mPercentComplete->setChecked( mIncludePercentComplete );
1207 cfg->mConnectSubTodos->setChecked( mConnectSubTodos );
1208 cfg->mStrikeOutCompleted->setChecked( mStrikeOutCompleted );
1210 if ( mTodoSortField != TodoFieldUnset ) {
1212 cfg->mSortField->insertItem( i18n(
"Summary") );
1213 cfg->mSortField->insertItem( i18n(
"Start Date") );
1214 cfg->mSortField->insertItem( i18n(
"Due Date") );
1215 cfg->mSortField->insertItem( i18n(
"Priority") );
1216 cfg->mSortField->insertItem( i18n(
"Percent Complete") );
1217 cfg->mSortField->setCurrentItem( (
int)mTodoSortField );
1220 if ( mTodoSortDirection != TodoDirectionUnset ) {
1222 cfg->mSortDirection->insertItem( i18n(
"Ascending") );
1223 cfg->mSortDirection->insertItem( i18n(
"Descending") );
1224 cfg->mSortDirection->setCurrentItem( (
int)mTodoSortDirection );
1229 void CalPrintTodos::loadConfig()
1232 mPageTitle = mConfig->readEntry(
"Page title", i18n(
"To-do list") );
1233 mTodoPrintType = (eTodoPrintType)mConfig->readNumEntry(
"Print type", (
int)TodosAll );
1234 mIncludeDescription = mConfig->readBoolEntry(
"Include description",
true );
1235 mIncludePriority = mConfig->readBoolEntry(
"Include priority",
true );
1236 mIncludeDueDate = mConfig->readBoolEntry(
"Include due date",
true );
1237 mIncludePercentComplete = mConfig->readBoolEntry(
"Include percentage completed",
true );
1238 mConnectSubTodos = mConfig->readBoolEntry(
"Connect subtodos",
true );
1239 mStrikeOutCompleted = mConfig->readBoolEntry(
"Strike out completed summaries",
true );
1240 mTodoSortField = (eTodoSortField)mConfig->readNumEntry(
"Sort field", (
int)TodoFieldSummary );
1241 mTodoSortDirection = (eTodoSortDirection)mConfig->readNumEntry(
"Sort direction", (
int)TodoDirectionAscending );
1243 setSettingsWidget();
1246 void CalPrintTodos::saveConfig()
1248 readSettingsWidget();
1250 mConfig->writeEntry(
"Page title", mPageTitle );
1251 mConfig->writeEntry(
"Print type",
int( mTodoPrintType ) );
1252 mConfig->writeEntry(
"Include description", mIncludeDescription );
1253 mConfig->writeEntry(
"Include priority", mIncludePriority );
1254 mConfig->writeEntry(
"Include due date", mIncludeDueDate );
1255 mConfig->writeEntry(
"Include percentage completed", mIncludePercentComplete );
1256 mConfig->writeEntry(
"Connect subtodos", mConnectSubTodos );
1257 mConfig->writeEntry(
"Strike out completed summaries", mStrikeOutCompleted );
1258 mConfig->writeEntry(
"Sort field", mTodoSortField );
1259 mConfig->writeEntry(
"Sort direction", mTodoSortDirection );
1263 void CalPrintTodos::print( TQPainter &p,
int width,
int height )
1266 int pospriority = 0;
1267 int possummary = 100;
1268 int posdue = width - 65;
1269 int poscomplete = posdue - 70;
1270 int lineSpacing = 15;
1271 int fontHeight = 10;
1273 TQRect headerBox( 0, 0, width, headerHeight() );
1274 TQRect footerBox( 0, height - footerHeight(), width, footerHeight() );
1275 height -= footerHeight();
1278 drawHeader( p, mPageTitle, mFromDate, TQDate(), headerBox );
1281 int mCurrentLinePos = headerHeight() + 5;
1283 TQFont oldFont( p.font() );
1285 p.setFont( TQFont(
"sans-serif", 9, TQFont::Bold ) );
1286 lineSpacing = p.fontMetrics().lineSpacing();
1287 mCurrentLinePos += lineSpacing;
1288 if ( mIncludePriority ) {
1289 outStr += i18n(
"Priority" );
1290 p.drawText( pospriority, mCurrentLinePos - 2, outStr );
1295 outStr.truncate( 0 );
1296 outStr += i18n(
"Summary" );
1297 p.drawText( possummary, mCurrentLinePos - 2, outStr );
1299 if ( mIncludePercentComplete ) {
1300 if ( !mIncludeDueDate )
1301 poscomplete = posdue;
1302 outStr.truncate( 0 );
1303 outStr += i18n(
"Complete" );
1304 p.drawText( poscomplete, mCurrentLinePos - 2, outStr );
1309 if ( mIncludeDueDate ) {
1310 outStr.truncate( 0 );
1311 outStr += i18n(
"Due" );
1312 p.drawText( posdue, mCurrentLinePos - 2, outStr );
1317 p.setFont( TQFont(
"sans-serif", 10 ) );
1318 fontHeight = p.fontMetrics().height();
1320 Todo::List todoList;
1321 Todo::List tempList;
1322 Todo::List::ConstIterator it;
1326 switch( mTodoSortField ) {
1327 case TodoFieldSummary:
1329 case TodoFieldStartDate:
1331 case TodoFieldDueDate:
1333 case TodoFieldPriority:
1335 case TodoFieldPercentComplete:
1337 case TodoFieldUnset:
1342 switch( mTodoSortDirection ) {
1343 case TodoDirectionAscending:
1345 case TodoDirectionDescending:
1347 case TodoDirectionUnset:
1352 todoList = mCalendar->todos( sortField, sortDirection );
1353 switch( mTodoPrintType ) {
1356 case TodosUnfinished:
1357 for( it = todoList.begin(); it!= todoList.end(); ++it ) {
1358 if ( !(*it)->isCompleted() )
1359 tempList.append( *it );
1361 todoList = tempList;
1364 for( it = todoList.begin(); it!= todoList.end(); ++it ) {
1365 if ( (*it)->hasDueDate() ) {
1366 if ( (*it)->dtDue().date() >= mFromDate &&
1367 (*it)->dtDue().date() <= mToDate )
1368 tempList.append( *it );
1370 tempList.append( *it );
1373 todoList = tempList;
1379 for ( it=todoList.begin(); it!=todoList.end(); ++it ) {
1380 Todo *currEvent = *it;
1385 drawTodo( count, currEvent, p,
1386 sortField, sortDirection,
1388 mStrikeOutCompleted, mIncludeDescription,
1389 pospriority, possummary, posdue, poscomplete,
1390 0, 0, mCurrentLinePos, width, height, todoList );
1394 drawFooter( p, footerBox );
1395 p.setFont( oldFont );
Base class for KOrganizer printing classes.
bool hasStartOffset() const
Duration endOffset() const
bool hasEndOffset() const
Duration startOffset() const
virtual TQDateTime dtEnd() const
Transparency transparency() const
virtual bool visit(Event *)
virtual TQDateTime dtStart() const
virtual bool accept(Visitor &)
Incidence * relatedTo() const
bool hasStartDate() const
TQDateTime dtStart(bool first=false) const
TQDateTime dtDue(bool first=false) const
virtual void setDateRange(const TQDate &from, const TQDate &to)
Set date range which should be printed.