00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef KORG_NOPRINTER
00028
00029 #include <qpainter.h>
00030 #include <qdatetimeedit.h>
00031 #include <qcheckbox.h>
00032 #include <qlineedit.h>
00033 #include <qbuttongroup.h>
00034
00035 #include <kdebug.h>
00036 #include <kconfig.h>
00037 #include <kcalendarsystem.h>
00038 #include <knuminput.h>
00039 #include <kcombobox.h>
00040
00041 #include "calprintdefaultplugins.h"
00042
00043 #include "calprintincidenceconfig_base.h"
00044 #include "calprintdayconfig_base.h"
00045 #include "calprintweekconfig_base.h"
00046 #include "calprintmonthconfig_base.h"
00047 #include "calprinttodoconfig_base.h"
00048
00049
00050
00051
00052
00053
00054 CalPrintIncidence::CalPrintIncidence() : CalPrintPluginBase()
00055 {
00056 }
00057
00058 CalPrintIncidence::~CalPrintIncidence()
00059 {
00060 }
00061
00062 QWidget *CalPrintIncidence::createConfigWidget( QWidget *w )
00063 {
00064 return new CalPrintIncidenceConfig_Base( w );
00065 }
00066
00067 void CalPrintIncidence::readSettingsWidget()
00068 {
00069 CalPrintIncidenceConfig_Base *cfg =
00070 dynamic_cast<CalPrintIncidenceConfig_Base*>( mConfigWidget );
00071 if ( cfg ) {
00072 mUseColors = cfg->mColors->isChecked();
00073 mShowOptions = cfg->mShowDetails->isChecked();
00074 mShowSubitemsNotes = cfg->mShowSubitemsNotes->isChecked();
00075 mShowAttendees = cfg->mShowAttendees->isChecked();
00076 mShowAttachments = cfg->mShowAttachments->isChecked();
00077 }
00078 }
00079
00080 void CalPrintIncidence::setSettingsWidget()
00081 {
00082 CalPrintIncidenceConfig_Base *cfg =
00083 dynamic_cast<CalPrintIncidenceConfig_Base*>( mConfigWidget );
00084 if ( cfg ) {
00085 cfg->mColors->setChecked( mUseColors );
00086 cfg->mShowDetails->setChecked(mShowOptions);
00087 cfg->mShowSubitemsNotes->setChecked(mShowSubitemsNotes);
00088 cfg->mShowAttendees->setChecked(mShowAttendees);
00089 cfg->mShowAttachments->setChecked(mShowAttachments);
00090 }
00091 }
00092
00093 void CalPrintIncidence::loadConfig()
00094 {
00095 if ( mConfig ) {
00096 mUseColors = mConfig->readBoolEntry( "Use Colors", false );
00097 mShowOptions = mConfig->readBoolEntry( "Show Options", false );
00098 mShowSubitemsNotes = mConfig->readBoolEntry( "Show Subitems and Notes", false );
00099 mShowAttendees = mConfig->readBoolEntry( "Use Attendees", false );
00100 mShowAttachments = mConfig->readBoolEntry( "Use Attachments", false );
00101 }
00102 setSettingsWidget();
00103 }
00104
00105 void CalPrintIncidence::saveConfig()
00106 {
00107 readSettingsWidget();
00108 if ( mConfig ) {
00109 mConfig->writeEntry( "Use Colors", mUseColors );
00110 mConfig->writeEntry( "Show Options", mShowOptions );
00111 mConfig->writeEntry( "Show Subitems and Notes", mShowSubitemsNotes );
00112 mConfig->writeEntry( "Use Attendees", mShowAttendees );
00113 mConfig->writeEntry( "Use Attachments", mShowAttachments );
00114 }
00115 }
00116
00117
00118 class TimePrintStringsVisitor : public IncidenceBase::Visitor
00119 {
00120 public:
00121 TimePrintStringsVisitor() {}
00122
00123 bool act( IncidenceBase *incidence )
00124 {
00125 return incidence->accept( *this );
00126 }
00127 QString mStartCaption, mStartString;
00128 QString mEndCaption, mEndString;
00129 QString mDurationCaption, mDurationString;
00130
00131 protected:
00132 bool visit( Event *event ) {
00133 if ( event->dtStart().isValid() ) {
00134 mStartCaption = i18n("Start date: ");
00135
00136
00137 mStartString = (event->doesFloat()) ? (event->dtStartDateStr(false)) : (event->dtStartStr());
00138 } else {
00139 mStartCaption = i18n("No start date");
00140 mStartString = QString::null;
00141 }
00142
00143 if ( event->hasEndDate() ) {
00144 mEndCaption = i18n("End date: ");
00145 mEndString = (event->doesFloat()) ? (event->dtEndDateStr(false)) : (event->dtEndStr());
00146 } else if ( event->hasDuration() ) {
00147 mEndCaption = i18n("Duration: ");
00148 int mins = event->duration() / 60;
00149 if ( mins >= 60 ) {
00150 mEndString += i18n( "1 hour ", "%n hours ", mins/60 );
00151 }
00152 if ( mins%60 > 0 ) {
00153 mEndString += i18n( "1 minute ", "%n minutes ", mins%60 );
00154 }
00155 } else {
00156 mEndCaption = i18n("No end date");
00157 mEndString = QString::null;
00158 }
00159 return true;
00160 }
00161 bool visit( Todo *todo ) {
00162 if ( todo->hasStartDate() ) {
00163 mStartCaption = i18n("Start date: ");
00164
00165
00166 mStartString = (todo->doesFloat()) ? (todo->dtStartDateStr(false)) : (todo->dtStartStr());
00167 } else {
00168 mStartCaption = i18n("No start date");
00169 mStartString = QString::null;
00170 }
00171
00172 if ( todo->hasDueDate() ) {
00173 mEndCaption = i18n("Due date: ");
00174 mEndString = (todo->doesFloat()) ? (todo->dtDueDateStr(false)) : (todo->dtDueStr());
00175 } else {
00176 mEndCaption = i18n("No due date");
00177 mEndString = QString::null;
00178 }
00179 return true;
00180 }
00181 bool visit( Journal *journal ) {
00182 mStartCaption = i18n("Start date: ");
00183
00184 mStartString = (journal->doesFloat()) ? (journal->dtStartDateStr(false)) : (journal->dtStartStr());
00185 mEndCaption = QString::null;
00186 mEndString = QString::null;
00187 return true;
00188 }
00189 };
00190
00191 int CalPrintIncidence::printCaptionAndText( QPainter &p, const QRect &box, const QString &caption, const QString &text, QFont captionFont, QFont textFont )
00192 {
00193 QFontMetrics captionFM( captionFont );
00194 int textWd = captionFM.width( caption );
00195 QRect textRect( box );
00196
00197 QFont oldFont( p.font() );
00198 p.setFont( captionFont );
00199 p.drawText( box, Qt::AlignLeft|Qt::AlignTop|Qt::SingleLine, caption );
00200
00201 if ( !text.isEmpty() ) {
00202 textRect.setLeft( textRect.left() + textWd );
00203 p.setFont( textFont );
00204 p.drawText( textRect, Qt::AlignLeft|Qt::AlignTop|Qt::SingleLine, text );
00205 }
00206 p.setFont( oldFont );
00207 return textRect.bottom();
00208 }
00209
00210 #include <qfontdatabase.h>
00211 void CalPrintIncidence::print( QPainter &p, int width, int height )
00212 {
00213 KLocale *local = KGlobal::locale();
00214
00215 QFont oldFont(p.font());
00216 QFont textFont( "sans-serif", 11, QFont::Normal );
00217 QFont captionFont( "sans-serif", 11, QFont::Bold );
00218 p.setFont( textFont );
00219 int lineHeight = p.fontMetrics().lineSpacing();
00220 QString cap, txt;
00221
00222
00223 Incidence::List::ConstIterator it;
00224 for ( it=mSelectedIncidences.begin(); it!=mSelectedIncidences.end(); ++it ) {
00225
00226 if ( !(*it) ) continue;
00227 if ( it != mSelectedIncidences.begin() ) mPrinter->newPage();
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 QRect box( 0, 0, width, height );
00261 QRect titleBox( box );
00262 titleBox.setHeight( headerHeight() );
00263
00264 int titleBottom = drawHeader( p, (*it)->summary(), QDate(), QDate(), titleBox, true );
00265 titleBox.setBottom( titleBottom );
00266
00267 QRect timesBox( titleBox );
00268 timesBox.setTop( titleBox.bottom() + padding() );
00269 timesBox.setHeight( height / 8 );
00270
00271 TimePrintStringsVisitor stringVis;
00272 int h = timesBox.top();
00273 if ( stringVis.act(*it) ) {
00274 QRect textRect( timesBox.left()+padding(), timesBox.top()+padding(), 0, lineHeight );
00275 textRect.setRight( timesBox.center().x() );
00276 h = printCaptionAndText( p, textRect, stringVis.mStartCaption, stringVis.mStartString, captionFont, textFont );
00277
00278 textRect.setLeft( textRect.right() );
00279 textRect.setRight( timesBox.right() - padding() );
00280 h = QMAX( printCaptionAndText( p, textRect, stringVis.mEndCaption, stringVis.mEndString, captionFont, textFont ), h );
00281 }
00282
00283
00284 if ( (*it)->doesRecur() ) {
00285 QRect recurBox( timesBox.left()+padding(), h+padding(), timesBox.right()-padding(), lineHeight );
00286
00287 QString recurString( "TODO: Convert Repeat to String!" );
00288 h = QMAX( printCaptionAndText( p, recurBox, i18n("Repeats: "), recurString, captionFont, textFont ), h );
00289 }
00290
00291 QRect alarmBox( timesBox.left()+padding(), h+padding(), timesBox.right()-padding(), lineHeight );
00292 Alarm::List alarms = (*it)->alarms();
00293 if ( alarms.count() == 0 ) {
00294 cap = i18n("No reminders");
00295 txt = QString::null;
00296 } else {
00297 cap = i18n("Reminder: ", "%n reminders: ", alarms.count() );
00298
00299 QStringList alarmStrings;
00300 KCal::Alarm::List::ConstIterator it;
00301 for ( it = alarms.begin(); it != alarms.end(); ++it ) {
00302 Alarm *alarm = *it;
00303
00304
00305 QString offsetstr;
00306 int offset = 0;
00307 if ( alarm->hasStartOffset() ) {
00308 offset = alarm->startOffset().asSeconds();
00309 if ( offset < 0 ) {
00310 offsetstr = i18n("N days/hours/minutes before/after the start/end", "%1 before the start");
00311 offset = -offset;
00312 } else {
00313 offsetstr = i18n("N days/hours/minutes before/after the start/end", "%1 after the start");
00314 }
00315 } else if ( alarm->hasEndOffset() ) {
00316 offset = alarm->endOffset().asSeconds();
00317 if ( offset < 0 ) {
00318 offsetstr = i18n("N days/hours/minutes before/after the start/end", "%1 before the end");
00319 offset = -offset;
00320 } else {
00321 offsetstr = i18n("N days/hours/minutes before/after the start/end", "%1 after the end");
00322 }
00323 }
00324
00325 offset = offset / 60;
00326 int useoffset = offset;
00327
00328 if ( offset % (24*60) == 0 && offset>0 ) {
00329 useoffset = offset / (24*60);
00330 offsetstr = offsetstr.arg( i18n("1 day", "%n days", useoffset ) );
00331 } else if (offset % 60 == 0 && offset>0 ) {
00332 useoffset = offset / 60;
00333 offsetstr = offsetstr.arg( i18n("1 hour", "%n hours", useoffset ) );
00334 } else {
00335 useoffset = offset;
00336 offsetstr = offsetstr.arg( i18n("1 minute", "%n minutes", useoffset ) );
00337 }
00338 alarmStrings << offsetstr;
00339 }
00340 txt = alarmStrings.join( i18n("Spacer for the joined list of categories", ", ") );
00341
00342 }
00343 h = QMAX( printCaptionAndText( p, alarmBox, cap, txt, captionFont, textFont ), h );
00344
00345
00346 QRect organizerBox( timesBox.left()+padding(), h+padding(), timesBox.right()-padding(), lineHeight );
00347 h = QMAX( printCaptionAndText( p, organizerBox, i18n("Organizer: "), (*it)->organizer().fullName(), captionFont, textFont ), h );
00348
00349
00350 timesBox.setBottom( QMAX( timesBox.bottom(), h+padding() ) );
00351 drawBox( p, BOX_BORDER_WIDTH, timesBox );
00352
00353
00354 QRect locationBox( timesBox );
00355 locationBox.setTop( timesBox.bottom() + padding() );
00356 locationBox.setHeight( 0 );
00357 int locationBottom = drawBoxWithCaption( p, locationBox, i18n("Location: "),
00358 (*it)->location(), true, true, captionFont, textFont );
00359 locationBox.setBottom( locationBottom );
00360
00361
00362
00363 QRect categoriesBox( locationBox );
00364 categoriesBox.setBottom( box.bottom() );
00365 categoriesBox.setTop( categoriesBox.bottom() - lineHeight - 2*padding() );
00366
00367
00368 QRect attendeesBox( box.left(), categoriesBox.top()-padding()-box.height()/9, box.width(), box.height()/9 );
00369 if ( !mShowAttendees ) {
00370 attendeesBox.setTop( categoriesBox.top() );
00371 }
00372 QRect attachmentsBox( box.left(), attendeesBox.top()-padding()-box.height()/9, box.width()*3/4 - padding(), box.height()/9 );
00373 QRect optionsBox( attachmentsBox.right() + padding(), attachmentsBox.top(), 0, 0 );
00374 optionsBox.setRight( box.right() );
00375 optionsBox.setBottom( attachmentsBox.bottom() );
00376 QRect notesBox( optionsBox.left(), locationBox.bottom() + padding(), optionsBox.width(), 0 );
00377 notesBox.setBottom( optionsBox.top() - padding() );
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388 QRect descriptionBox( notesBox );
00389 descriptionBox.setLeft( box.left() );
00390 descriptionBox.setRight( mShowOptions?(attachmentsBox.right()):(box.right()) );
00391
00392 drawBoxWithCaption( p, descriptionBox, i18n("Description:"),
00393 (*it)->description(), false,
00394 false, captionFont, textFont );
00395
00396 if ( mShowSubitemsNotes ) {
00397 if ( (*it)->relations().isEmpty() || (*it)->type() != "Todo" ) {
00398 int notesPosition = drawBoxWithCaption( p, notesBox, i18n("Notes:"),
00399 QString::null, false, false,
00400 captionFont, textFont );
00401 QPen oldPen( p.pen() );
00402 p.setPen( Qt::DotLine );
00403 while ( (notesPosition += int(1.5*lineHeight)) < notesBox.bottom() ) {
00404 p.drawLine( notesBox.left()+padding(), notesPosition, notesBox.right()-padding(), notesPosition );
00405 }
00406 p.setPen( oldPen );
00407 } else {
00408 int subitemsStart = drawBoxWithCaption( p, notesBox, i18n("Subitems:"),
00409 (*it)->description(), false,
00410 false, captionFont, textFont );
00411
00412 }
00413 }
00414
00415 if ( mShowAttachments ) {
00416 int attachStart = drawBoxWithCaption( p, attachmentsBox,
00417 i18n("Attachments:"), QString::null, false,
00418 false, captionFont, textFont );
00419
00420 }
00421
00422 if ( mShowAttendees ) {
00423 Attendee::List attendees = (*it)->attendees();
00424 QString attendeeCaption;
00425 if ( attendees.count() == 0 )
00426 attendeeCaption = i18n("No Attendees");
00427 else
00428 attendeeCaption = i18n("1 Attendee:", "%n Attendees:", attendees.count() );
00429 QString attendeeString;
00430 for ( Attendee::List::ConstIterator ait = attendees.begin(); ait != attendees.end(); ++ait ) {
00431 if ( !attendeeString.isEmpty() ) attendeeString += "\n";
00432 attendeeString += i18n("Formatting of an attendee: "
00433 "'Name (Role): Status', e.g. 'Reinhold Kainhofer "
00434 "<reinhold@kainhofer.com> (Participant): Awaiting Response'",
00435 "%1 (%2): %3")
00436 .arg( (*ait)->fullName() )
00437 .arg( (*ait)->roleStr() ).arg( (*ait)->statusStr() );
00438 }
00439 drawBoxWithCaption( p, attendeesBox, i18n("Attendees:"), attendeeString,
00440 false, false, captionFont, textFont );
00441 }
00442
00443 if ( mShowOptions ) {
00444 QString optionsString;
00445 if ( !(*it)->statusStr().isEmpty() ) {
00446 optionsString += i18n("Status: %1").arg( (*it)->statusStr() );
00447 optionsString += "\n";
00448 }
00449 if ( !(*it)->secrecyStr().isEmpty() ) {
00450 optionsString += i18n("Secrecy: %1").arg( (*it)->secrecyStr() );
00451 optionsString += "\n";
00452 }
00453 if ( (*it)->type() == "Event" ) {
00454 Event *e = static_cast<Event*>(*it);
00455 if ( e->transparency() == Event::Opaque ) {
00456 optionsString += i18n("Show as: Busy");
00457 } else {
00458 optionsString += i18n("Show as: Free");
00459 }
00460 optionsString += "\n";
00461 } else if ( (*it)->type() == "Todo" ) {
00462 Todo *t = static_cast<Todo*>(*it);
00463 if ( t->isOverdue() ) {
00464 optionsString += i18n("This task is overdue!");
00465 optionsString += "\n";
00466 }
00467 } else if ( (*it)->type() == "Journal" ) {
00468
00469 }
00470 drawBoxWithCaption( p, optionsBox, i18n("Settings: "),
00471 optionsString, false, false, captionFont, textFont );
00472 }
00473
00474 drawBoxWithCaption( p, categoriesBox, i18n("Categories: "),
00475 (*it)->categories().join( i18n("Spacer for the joined list of categories", ", ") ),
00476 true, false, captionFont, textFont );
00477 }
00478 p.setFont( oldFont );
00479 }
00480
00481
00482
00483
00484
00485 CalPrintDay::CalPrintDay() : CalPrintPluginBase()
00486 {
00487 }
00488
00489 CalPrintDay::~CalPrintDay()
00490 {
00491 }
00492
00493 QWidget *CalPrintDay::createConfigWidget( QWidget *w )
00494 {
00495 return new CalPrintDayConfig_Base( w );
00496 }
00497
00498 void CalPrintDay::readSettingsWidget()
00499 {
00500 CalPrintDayConfig_Base *cfg =
00501 dynamic_cast<CalPrintDayConfig_Base*>( mConfigWidget );
00502 if ( cfg ) {
00503 mFromDate = cfg->mFromDate->date();
00504 mToDate = cfg->mToDate->date();
00505
00506 mStartTime = cfg->mFromTime->time();
00507 mEndTime = cfg->mToTime->time();
00508 mIncludeAllEvents = cfg->mIncludeAllEvents->isChecked();
00509
00510 mIncludeTodos = cfg->mIncludeTodos->isChecked();
00511 mUseColors = cfg->mColors->isChecked();
00512 }
00513 }
00514
00515 void CalPrintDay::setSettingsWidget()
00516 {
00517 CalPrintDayConfig_Base *cfg =
00518 dynamic_cast<CalPrintDayConfig_Base*>( mConfigWidget );
00519 if ( cfg ) {
00520 cfg->mFromDate->setDate( mFromDate );
00521 cfg->mToDate->setDate( mToDate );
00522
00523 cfg->mFromTime->setTime( mStartTime );
00524 cfg->mToTime->setTime( mEndTime );
00525 cfg->mIncludeAllEvents->setChecked( mIncludeAllEvents );
00526
00527 cfg->mIncludeTodos->setChecked( mIncludeTodos );
00528 cfg->mColors->setChecked( mUseColors );
00529 }
00530 }
00531
00532 void CalPrintDay::loadConfig()
00533 {
00534 if ( mConfig ) {
00535 QDate dt;
00536 QTime tm1( dayStart() );
00537 QDateTime startTm( dt, tm1 );
00538 QDateTime endTm( dt, tm1.addSecs( 12 * 60 * 60 ) );
00539 mStartTime = mConfig->readDateTimeEntry( "Start time", &startTm ).time();
00540 mEndTime = mConfig->readDateTimeEntry( "End time", &endTm ).time();
00541 mIncludeTodos = mConfig->readBoolEntry( "Include todos", false );
00542 mIncludeAllEvents = mConfig->readBoolEntry( "Include all events", false );
00543 }
00544 setSettingsWidget();
00545 }
00546
00547 void CalPrintDay::saveConfig()
00548 {
00549 readSettingsWidget();
00550 if ( mConfig ) {
00551 mConfig->writeEntry( "Start time", QDateTime( QDate(), mStartTime ) );
00552 mConfig->writeEntry( "End time", QDateTime( QDate(), mEndTime ) );
00553 mConfig->writeEntry( "Include todos", mIncludeTodos );
00554 mConfig->writeEntry( "Include all events", mIncludeAllEvents );
00555 }
00556 }
00557
00558 void CalPrintDay::setDateRange( const QDate& from, const QDate& to )
00559 {
00560 CalPrintPluginBase::setDateRange( from, to );
00561 CalPrintDayConfig_Base *cfg =
00562 dynamic_cast<CalPrintDayConfig_Base*>( mConfigWidget );
00563 if ( cfg ) {
00564 cfg->mFromDate->setDate( from );
00565 cfg->mToDate->setDate( to );
00566 }
00567 }
00568
00569 void CalPrintDay::print( QPainter &p, int width, int height )
00570 {
00571 QDate curDay( mFromDate );
00572
00573 do {
00574 QTime curStartTime( mStartTime );
00575 QTime curEndTime( mEndTime );
00576
00577
00578
00579 if ( curEndTime <= curStartTime ) {
00580 curStartTime = QTime( curStartTime.hour(), 0, 0 );
00581 curEndTime = curStartTime.addSecs( 3600 );
00582 }
00583
00584 KLocale *local = KGlobal::locale();
00585 QRect headerBox( 0, 0, width, headerHeight() );
00586 drawHeader( p, local->formatDate( curDay ), curDay, QDate(), headerBox );
00587
00588
00589 Event::List eventList = mCalendar->events( curDay,
00590 EventSortStartDate,
00591 SortDirectionAscending );
00592
00593 p.setFont( QFont( "sans-serif", 12 ) );
00594
00595
00596 QRect allDayBox( TIMELINE_WIDTH + padding(), headerBox.bottom() + padding(),
00597 0, height / 20 );
00598 allDayBox.setRight( width );
00599 int allDayHeight = drawAllDayBox( p, eventList, curDay, true, allDayBox );
00600
00601 QRect dayBox( allDayBox );
00602 dayBox.setTop( allDayHeight );
00603 dayBox.setBottom( height );
00604 drawAgendaDayBox( p, eventList, curDay, mIncludeAllEvents,
00605 curStartTime, curEndTime, dayBox );
00606
00607 QRect tlBox( dayBox );
00608 tlBox.setLeft( 0 );
00609 tlBox.setWidth( TIMELINE_WIDTH );
00610 drawTimeLine( p, curStartTime, curEndTime, tlBox );
00611 curDay = curDay.addDays( 1 );
00612 if ( curDay <= mToDate ) mPrinter->newPage();
00613 } while ( curDay <= mToDate );
00614 }
00615
00616
00617
00618
00619
00620
00621
00622 CalPrintWeek::CalPrintWeek() : CalPrintPluginBase()
00623 {
00624 }
00625
00626 CalPrintWeek::~CalPrintWeek()
00627 {
00628 }
00629
00630 QWidget *CalPrintWeek::createConfigWidget( QWidget *w )
00631 {
00632 return new CalPrintWeekConfig_Base( w );
00633 }
00634
00635 void CalPrintWeek::readSettingsWidget()
00636 {
00637 CalPrintWeekConfig_Base *cfg =
00638 dynamic_cast<CalPrintWeekConfig_Base*>( mConfigWidget );
00639 if ( cfg ) {
00640 mFromDate = cfg->mFromDate->date();
00641 mToDate = cfg->mToDate->date();
00642
00643 mWeekPrintType = (eWeekPrintType)( cfg->mPrintType->id(
00644 cfg->mPrintType->selected() ) );
00645
00646 mStartTime = cfg->mFromTime->time();
00647 mEndTime = cfg->mToTime->time();
00648
00649 mIncludeTodos = cfg->mIncludeTodos->isChecked();
00650 mUseColors = cfg->mColors->isChecked();
00651 }
00652 }
00653
00654 void CalPrintWeek::setSettingsWidget()
00655 {
00656 CalPrintWeekConfig_Base *cfg =
00657 dynamic_cast<CalPrintWeekConfig_Base*>( mConfigWidget );
00658 if ( cfg ) {
00659 cfg->mFromDate->setDate( mFromDate );
00660 cfg->mToDate->setDate( mToDate );
00661
00662 cfg->mPrintType->setButton( mWeekPrintType );
00663
00664 cfg->mFromTime->setTime( mStartTime );
00665 cfg->mToTime->setTime( mEndTime );
00666
00667 cfg->mIncludeTodos->setChecked( mIncludeTodos );
00668 cfg->mColors->setChecked( mUseColors );
00669 }
00670 }
00671
00672 void CalPrintWeek::loadConfig()
00673 {
00674 if ( mConfig ) {
00675 QDate dt;
00676 QTime tm1( dayStart() );
00677 QDateTime startTm( dt, tm1 );
00678 QDateTime endTm( dt, tm1.addSecs( 43200 ) );
00679 mStartTime = mConfig->readDateTimeEntry( "Start time", &startTm ).time();
00680 mEndTime = mConfig->readDateTimeEntry( "End time", &endTm ).time();
00681 mIncludeTodos = mConfig->readBoolEntry( "Include todos", false );
00682 mWeekPrintType =(eWeekPrintType)( mConfig->readNumEntry( "Print type", (int)Filofax ) );
00683 }
00684 setSettingsWidget();
00685 }
00686
00687 void CalPrintWeek::saveConfig()
00688 {
00689 readSettingsWidget();
00690 if ( mConfig ) {
00691 mConfig->writeEntry( "Start time", QDateTime( QDate(), mStartTime ) );
00692 mConfig->writeEntry( "End time", QDateTime( QDate(), mEndTime ) );
00693 mConfig->writeEntry( "Include todos", mIncludeTodos );
00694 mConfig->writeEntry( "Print type", int( mWeekPrintType ) );
00695 }
00696 }
00697
00698 KPrinter::Orientation CalPrintWeek::defaultOrientation()
00699 {
00700 if ( mWeekPrintType == Filofax ) return KPrinter::Portrait;
00701 else if ( mWeekPrintType == SplitWeek ) return KPrinter::Portrait;
00702 else return KPrinter::Landscape;
00703 }
00704
00705 void CalPrintWeek::setDateRange( const QDate &from, const QDate &to )
00706 {
00707 CalPrintPluginBase::setDateRange( from, to );
00708 CalPrintWeekConfig_Base *cfg =
00709 dynamic_cast<CalPrintWeekConfig_Base*>( mConfigWidget );
00710 if ( cfg ) {
00711 cfg->mFromDate->setDate( from );
00712 cfg->mToDate->setDate( to );
00713 }
00714 }
00715
00716 void CalPrintWeek::print( QPainter &p, int width, int height )
00717 {
00718 QDate curWeek, fromWeek, toWeek;
00719
00720
00721 int weekdayCol = weekdayColumn( mFromDate.dayOfWeek() );
00722 fromWeek = mFromDate.addDays( -weekdayCol );
00723 weekdayCol = weekdayColumn( mFromDate.dayOfWeek() );
00724 toWeek = mToDate.addDays( 6 - weekdayCol );
00725
00726 curWeek = fromWeek.addDays( 6 );
00727 KLocale *local = KGlobal::locale();
00728
00729 QString line1, line2, title;
00730 QRect headerBox( 0, 0, width, headerHeight() );
00731 QRect weekBox( headerBox );
00732 weekBox.setTop( headerBox.bottom() + padding() );
00733 weekBox.setBottom( height );
00734
00735 switch ( mWeekPrintType ) {
00736 case Filofax:
00737 do {
00738 line1 = local->formatDate( curWeek.addDays( -6 ) );
00739 line2 = local->formatDate( curWeek );
00740 if ( orientation() == KPrinter::Landscape ) {
00741 title = i18n("date from-to", "%1 - %2");
00742 } else {
00743 title = i18n("date from-\nto", "%1 -\n%2");;
00744 }
00745 title = title.arg( line1 ).arg( line2 );
00746 drawHeader( p, title, curWeek.addDays( -6 ), QDate(), headerBox );
00747 drawWeek( p, curWeek, weekBox );
00748 curWeek = curWeek.addDays( 7 );
00749 if ( curWeek <= toWeek )
00750 mPrinter->newPage();
00751 } while ( curWeek <= toWeek );
00752 break;
00753
00754 case Timetable:
00755 default:
00756 do {
00757 line1 = local->formatDate( curWeek.addDays( -6 ) );
00758 line2 = local->formatDate( curWeek );
00759 if ( orientation() == KPrinter::Landscape ) {
00760 title = i18n("date from - to (week number)", "%1 - %2 (Week %3)");
00761 } else {
00762 title = i18n("date from -\nto (week number)", "%1 -\n%2 (Week %3)");
00763 }
00764 title = title.arg( line1 ).arg( line2 ).arg( curWeek.weekNumber() );
00765 drawHeader( p, title, curWeek, QDate(), headerBox );
00766 QRect weekBox( headerBox );
00767 weekBox.setTop( headerBox.bottom() + padding() );
00768 weekBox.setBottom( height );
00769
00770 drawTimeTable( p, fromWeek, curWeek, mStartTime, mEndTime, weekBox );
00771 fromWeek = fromWeek.addDays( 7 );
00772 curWeek = fromWeek.addDays( 6 );
00773 if ( curWeek <= toWeek )
00774 mPrinter->newPage();
00775 } while ( curWeek <= toWeek );
00776 break;
00777
00778 case SplitWeek: {
00779 QRect weekBox1( weekBox );
00780
00781
00782
00783 weekBox1.setRight( int( ( width - TIMELINE_WIDTH ) * 3. / 4. + TIMELINE_WIDTH ) );
00784 do {
00785 QDate endLeft( fromWeek.addDays( 3 ) );
00786 int hh = headerHeight();
00787
00788 drawTimeTable( p, fromWeek, endLeft,
00789 mStartTime, mEndTime, weekBox );
00790 mPrinter->newPage();
00791 drawSplitHeaderRight( p, fromWeek, curWeek, QDate(), width, hh );
00792 drawTimeTable( p, endLeft.addDays( 1 ), curWeek,
00793 mStartTime, mEndTime, weekBox1 );
00794
00795 fromWeek = fromWeek.addDays( 7 );
00796 curWeek = fromWeek.addDays( 6 );
00797 if ( curWeek <= toWeek )
00798 mPrinter->newPage();
00799 } while ( curWeek <= toWeek );
00800 }
00801 break;
00802 }
00803 }
00804
00805
00806
00807
00808
00809
00810
00811
00812 CalPrintMonth::CalPrintMonth() : CalPrintPluginBase()
00813 {
00814 }
00815
00816 CalPrintMonth::~CalPrintMonth()
00817 {
00818 }
00819
00820 QWidget *CalPrintMonth::createConfigWidget( QWidget *w )
00821 {
00822 return new CalPrintMonthConfig_Base( w );
00823 }
00824
00825 void CalPrintMonth::readSettingsWidget()
00826 {
00827 CalPrintMonthConfig_Base *cfg =
00828 dynamic_cast<CalPrintMonthConfig_Base *>( mConfigWidget );
00829 if ( cfg ) {
00830 mFromDate = QDate( cfg->mFromYear->value(), cfg->mFromMonth->currentItem()+1, 1 );
00831 mToDate = QDate( cfg->mToYear->value(), cfg->mToMonth->currentItem()+1, 1 );
00832
00833 mWeekNumbers = cfg->mWeekNumbers->isChecked();
00834 mRecurDaily = cfg->mRecurDaily->isChecked();
00835 mRecurWeekly = cfg->mRecurWeekly->isChecked();
00836 mIncludeTodos = cfg->mIncludeTodos->isChecked();
00837
00838 }
00839 }
00840
00841 void CalPrintMonth::setSettingsWidget()
00842 {
00843 CalPrintMonthConfig_Base *cfg =
00844 dynamic_cast<CalPrintMonthConfig_Base *>( mConfigWidget );
00845 setDateRange( mFromDate, mToDate );
00846 if ( cfg ) {
00847 cfg->mWeekNumbers->setChecked( mWeekNumbers );
00848 cfg->mRecurDaily->setChecked( mRecurDaily );
00849 cfg->mRecurWeekly->setChecked( mRecurWeekly );
00850 cfg->mIncludeTodos->setChecked( mIncludeTodos );
00851
00852 }
00853 }
00854
00855 void CalPrintMonth::loadConfig()
00856 {
00857 if ( mConfig ) {
00858 mWeekNumbers = mConfig->readBoolEntry( "Print week numbers", true );
00859 mRecurDaily = mConfig->readBoolEntry( "Print daily incidences", true );
00860 mRecurWeekly = mConfig->readBoolEntry( "Print weekly incidences", true );
00861 mIncludeTodos = mConfig->readBoolEntry( "Include todos", false );
00862 }
00863 setSettingsWidget();
00864 }
00865
00866 void CalPrintMonth::saveConfig()
00867 {
00868 readSettingsWidget();
00869 if ( mConfig ) {
00870 mConfig->writeEntry( "Print week numbers", mWeekNumbers );
00871 mConfig->writeEntry( "Print daily incidences", mRecurDaily );
00872 mConfig->writeEntry( "Print weekly incidences", mRecurWeekly );
00873 mConfig->writeEntry( "Include todos", mIncludeTodos );
00874 }
00875 }
00876
00877 void CalPrintMonth::setDateRange( const QDate &from, const QDate &to )
00878 {
00879 CalPrintPluginBase::setDateRange( from, to );
00880 CalPrintMonthConfig_Base *cfg =
00881 dynamic_cast<CalPrintMonthConfig_Base *>( mConfigWidget );
00882 const KCalendarSystem *calSys = calendarSystem();
00883 if ( cfg && calSys ) {
00884 cfg->mFromMonth->clear();
00885 for ( int i=0; i<calSys->monthsInYear( mFromDate ); ++i ) {
00886 cfg->mFromMonth->insertItem( calSys->monthName( i+1, mFromDate.year() ) );
00887 }
00888 cfg->mToMonth->clear();
00889 for ( int i=0; i<calSys->monthsInYear( mToDate ); ++i ) {
00890 cfg->mToMonth->insertItem( calSys->monthName( i+1, mToDate.year() ) );
00891 }
00892 }
00893 if ( cfg ) {
00894 cfg->mFromMonth->setCurrentItem( from.month()-1 );
00895 cfg->mFromYear->setValue( to.year() );
00896 cfg->mToMonth->setCurrentItem( mToDate.month()-1 );
00897 cfg->mToYear->setValue( mToDate.year() );
00898 }
00899 }
00900
00901 void CalPrintMonth::print( QPainter &p, int width, int height )
00902 {
00903 QDate curMonth, fromMonth, toMonth;
00904
00905 fromMonth = mFromDate.addDays( -( mFromDate.day() - 1 ) );
00906 toMonth = mToDate.addDays( mToDate.daysInMonth() - mToDate.day() );
00907
00908 curMonth = fromMonth;
00909 const KCalendarSystem *calSys = calendarSystem();
00910 if ( !calSys ) return;
00911
00912 QRect headerBox( 0, 0, width, headerHeight() );
00913 QRect monthBox( 0, 0, width, height );
00914 monthBox.setTop( headerBox.bottom() + padding() );
00915
00916 do {
00917 QString title( i18n("monthname year", "%1 %2") );
00918 title = title.arg( calSys->monthName( curMonth ) )
00919 .arg( curMonth.year() );
00920 QDate tmp( fromMonth );
00921 int weekdayCol = weekdayColumn( tmp.dayOfWeek() );
00922 tmp = tmp.addDays( -weekdayCol );
00923
00924 drawHeader( p, title, curMonth.addMonths( -1 ), curMonth.addMonths( 1 ),
00925 headerBox );
00926 drawMonthTable( p, curMonth, mWeekNumbers, mRecurDaily, mRecurWeekly, monthBox );
00927 curMonth = curMonth.addDays( curMonth.daysInMonth() );
00928 if ( curMonth <= toMonth ) mPrinter->newPage();
00929 } while ( curMonth <= toMonth );
00930
00931 }
00932
00933
00934
00935
00936
00937
00938
00939
00940 CalPrintTodos::CalPrintTodos() : CalPrintPluginBase()
00941 {
00942 mTodoSortField = TodoFieldUnset;
00943 mTodoSortDirection = TodoDirectionUnset;
00944 }
00945
00946 CalPrintTodos::~CalPrintTodos()
00947 {
00948 }
00949
00950 QWidget *CalPrintTodos::createConfigWidget( QWidget *w )
00951 {
00952 return new CalPrintTodoConfig_Base( w );
00953 }
00954
00955 void CalPrintTodos::readSettingsWidget()
00956 {
00957 CalPrintTodoConfig_Base *cfg =
00958 dynamic_cast<CalPrintTodoConfig_Base *>( mConfigWidget );
00959 if ( cfg ) {
00960 mPageTitle = cfg->mTitle->text();
00961
00962 mTodoPrintType = (eTodoPrintType)( cfg->mPrintType->id(
00963 cfg->mPrintType->selected() ) );
00964
00965 mFromDate = cfg->mFromDate->date();
00966 mToDate = cfg->mToDate->date();
00967
00968 mIncludeDescription = cfg->mDescription->isChecked();
00969 mIncludePriority = cfg->mPriority->isChecked();
00970 mIncludeDueDate = cfg->mDueDate->isChecked();
00971 mIncludePercentComplete = cfg->mPercentComplete->isChecked();
00972 mConnectSubTodos = cfg->mConnectSubTodos->isChecked();
00973 mStrikeOutCompleted = cfg->mStrikeOutCompleted->isChecked();
00974
00975 mTodoSortField = (eTodoSortField)cfg->mSortField->currentItem();
00976 mTodoSortDirection = (eTodoSortDirection)cfg->mSortDirection->currentItem();
00977 }
00978 }
00979
00980 void CalPrintTodos::setSettingsWidget()
00981 {
00982
00983
00984 CalPrintTodoConfig_Base *cfg =
00985 dynamic_cast<CalPrintTodoConfig_Base *>( mConfigWidget );
00986 if ( cfg ) {
00987 cfg->mTitle->setText( mPageTitle );
00988
00989 cfg->mPrintType->setButton( mTodoPrintType );
00990
00991 cfg->mFromDate->setDate( mFromDate );
00992 cfg->mToDate->setDate( mToDate );
00993
00994 cfg->mDescription->setChecked( mIncludeDescription );
00995 cfg->mPriority->setChecked( mIncludePriority );
00996 cfg->mDueDate->setChecked( mIncludeDueDate );
00997 cfg->mPercentComplete->setChecked( mIncludePercentComplete );
00998 cfg->mConnectSubTodos->setChecked( mConnectSubTodos );
00999 cfg->mStrikeOutCompleted->setChecked( mStrikeOutCompleted );
01000
01001 if ( mTodoSortField != TodoFieldUnset ) {
01002
01003 cfg->mSortField->insertItem( i18n("Summary") );
01004 cfg->mSortField->insertItem( i18n("Start Date") );
01005 cfg->mSortField->insertItem( i18n("Due Date") );
01006 cfg->mSortField->insertItem( i18n("Priority") );
01007 cfg->mSortField->insertItem( i18n("Percent Complete") );
01008 cfg->mSortField->setCurrentItem( (int)mTodoSortField );
01009 }
01010
01011 if ( mTodoSortDirection != TodoDirectionUnset ) {
01012
01013 cfg->mSortDirection->insertItem( i18n("Ascending") );
01014 cfg->mSortDirection->insertItem( i18n("Descending") );
01015 cfg->mSortDirection->setCurrentItem( (int)mTodoSortDirection );
01016 }
01017 }
01018 }
01019
01020 void CalPrintTodos::loadConfig()
01021 {
01022 if ( mConfig ) {
01023 mPageTitle = mConfig->readEntry( "Page title", i18n("To-do list") );
01024 mTodoPrintType = (eTodoPrintType)mConfig->readNumEntry( "Print type", (int)TodosAll );
01025 mIncludeDescription = mConfig->readBoolEntry( "Include description", true );
01026 mIncludePriority = mConfig->readBoolEntry( "Include priority", true );
01027 mIncludeDueDate = mConfig->readBoolEntry( "Include due date", true );
01028 mIncludePercentComplete = mConfig->readBoolEntry( "Include percentage completed", true );
01029 mConnectSubTodos = mConfig->readBoolEntry( "Connect subtodos", true );
01030 mStrikeOutCompleted = mConfig->readBoolEntry( "Strike out completed summaries", true );
01031 mTodoSortField = (eTodoSortField)mConfig->readNumEntry( "Sort field", (int)TodoFieldSummary );
01032 mTodoSortDirection = (eTodoSortDirection)mConfig->readNumEntry( "Sort direction", (int)TodoDirectionAscending );
01033 }
01034 setSettingsWidget();
01035 }
01036
01037 void CalPrintTodos::saveConfig()
01038 {
01039 readSettingsWidget();
01040 if ( mConfig ) {
01041 mConfig->writeEntry( "Page title", mPageTitle );
01042 mConfig->writeEntry( "Print type", int( mTodoPrintType ) );
01043 mConfig->writeEntry( "Include description", mIncludeDescription );
01044 mConfig->writeEntry( "Include priority", mIncludePriority );
01045 mConfig->writeEntry( "Include due date", mIncludeDueDate );
01046 mConfig->writeEntry( "Include percentage completed", mIncludePercentComplete );
01047 mConfig->writeEntry( "Connect subtodos", mConnectSubTodos );
01048 mConfig->writeEntry( "Strike out completed summaries", mStrikeOutCompleted );
01049 mConfig->writeEntry( "Sort field", mTodoSortField );
01050 mConfig->writeEntry( "Sort direction", mTodoSortDirection );
01051 }
01052 }
01053
01054 void CalPrintTodos::print( QPainter &p, int width, int height )
01055 {
01056
01057 int pospriority = 10;
01058 int possummary = 60;
01059 int posdue = width - 65;
01060 int poscomplete = posdue - 70;
01061 int lineSpacing = 15;
01062 int fontHeight = 10;
01063
01064
01065 drawHeader( p, mPageTitle, mFromDate, QDate(),
01066 QRect( 0, 0, width, headerHeight() ) );
01067
01068
01069 int mCurrentLinePos = headerHeight() + 5;
01070 QString outStr;
01071 QFont oldFont( p.font() );
01072
01073 p.setFont( QFont( "sans-serif", 10, QFont::Bold ) );
01074 lineSpacing = p.fontMetrics().lineSpacing();
01075 mCurrentLinePos += lineSpacing;
01076 if ( mIncludePriority ) {
01077 outStr += i18n( "Priority" );
01078 p.drawText( pospriority, mCurrentLinePos - 2, outStr );
01079 } else {
01080 possummary = 10;
01081 pospriority = -1;
01082 }
01083
01084 outStr.truncate( 0 );
01085 outStr += i18n( "Summary" );
01086 p.drawText( possummary, mCurrentLinePos - 2, outStr );
01087
01088 if ( mIncludePercentComplete ) {
01089 if ( !mIncludeDueDate )
01090 poscomplete = posdue;
01091 outStr.truncate( 0 );
01092 outStr += i18n( "Complete" );
01093 p.drawText( poscomplete, mCurrentLinePos - 2, outStr );
01094 } else {
01095 poscomplete = -1;
01096 }
01097
01098 if ( mIncludeDueDate ) {
01099 outStr.truncate( 0 );
01100 outStr += i18n( "Due" );
01101 p.drawText( posdue, mCurrentLinePos - 2, outStr );
01102 } else {
01103 posdue = -1;
01104 }
01105
01106 p.setFont( QFont( "sans-serif", 10 ) );
01107 fontHeight = p.fontMetrics().height();
01108
01109 Todo::List todoList;
01110 Todo::List tempList;
01111 Todo::List::ConstIterator it;
01112
01113
01114 TodoSortField sortField = TodoSortSummary;
01115 switch( mTodoSortField ) {
01116 case TodoFieldSummary:
01117 sortField = TodoSortSummary; break;
01118 case TodoFieldStartDate:
01119 sortField = TodoSortStartDate; break;
01120 case TodoFieldDueDate:
01121 sortField = TodoSortDueDate; break;
01122 case TodoFieldPriority:
01123 sortField = TodoSortPriority; break;
01124 case TodoFieldPercentComplete:
01125 sortField = TodoSortPercentComplete; break;
01126 case TodoFieldUnset:
01127 break;
01128 }
01129
01130 SortDirection sortDirection;
01131 switch( mTodoSortDirection ) {
01132 case TodoDirectionAscending:
01133 sortDirection = SortDirectionAscending; break;
01134 case TodoDirectionDescending:
01135 sortDirection = SortDirectionDescending; break;
01136 case TodoDirectionUnset:
01137 break;
01138 }
01139
01140
01141 todoList = mCalendar->todos( sortField, sortDirection );
01142 switch( mTodoPrintType ) {
01143 case TodosAll:
01144 break;
01145 case TodosUnfinished:
01146 for( it = todoList.begin(); it!= todoList.end(); ++it ) {
01147 if ( !(*it)->isCompleted() )
01148 tempList.append( *it );
01149 }
01150 todoList = tempList;
01151 break;
01152 case TodosDueRange:
01153 for( it = todoList.begin(); it!= todoList.end(); ++it ) {
01154 if ( (*it)->hasDueDate() ) {
01155 if ( (*it)->dtDue().date() >= mFromDate &&
01156 (*it)->dtDue().date() <= mToDate )
01157 tempList.append( *it );
01158 } else {
01159 tempList.append( *it );
01160 }
01161 }
01162 todoList = tempList;
01163 break;
01164 }
01165
01166
01167 int count = 0;
01168 for ( it=todoList.begin(); it!=todoList.end(); ++it ) {
01169 Todo *currEvent = *it;
01170
01171
01172 if ( !currEvent->relatedTo() ) {
01173 count++;
01174 drawTodo( count, currEvent, p,
01175 sortField, sortDirection,
01176 mConnectSubTodos,
01177 mStrikeOutCompleted, mIncludeDescription,
01178 pospriority, possummary, posdue, poscomplete,
01179 0, 0, mCurrentLinePos, width, height, todoList );
01180 }
01181 }
01182 p.setFont( oldFont );
01183 }
01184
01185
01186 #endif