korganizer

calprintdefaultplugins.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 1998 Preston Brown <pbrown@kde.org>
00005     Copyright (c) 2003 Reinhold Kainhofer <reinhold@kainhofer.com>
00006     Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00021 
00022     As a special exception, permission is given to link this program
00023     with any edition of Qt, and distribute the resulting executable,
00024     without including the source code for Qt in the source distribution.
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  *           Print Incidence
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         // Show date/time or only date, depending on whether it's an all-day event
00136 // TODO: Add shortfmt param to dtStartStr, dtEndStr and dtDueStr!!!
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         // Show date/time or only date, depending on whether it's an all-day event
00165 // TODO: Add shortfmt param to dtStartStr, dtEndStr and dtDueStr!!!
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 // TODO: Add shortfmt param to dtStartStr, dtEndStr and dtDueStr!!!
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     // don't do anything on a 0-pointer!
00226     if ( !(*it) ) continue;
00227     if ( it != mSelectedIncidences.begin() ) mPrinter->newPage();
00228 
00229 
00230     // PAGE Layout (same for landscape and portrait! astonishingly, it looks good with both!):
00231     //  +-----------------------------------+
00232     //  | Header:  Summary                  |
00233     //  +===================================+
00234     //  | start: ______   end: _________    |
00235     //  | repeats: ___________________      |
00236     //  | reminder: __________________      |
00237     //  +-----------------------------------+
00238     //  | Location: ______________________  |
00239     //  +------------------------+----------+
00240     //  | Description:           | Notes or |
00241     //  |                        | Subitems |
00242     //  |                        |          |
00243     //  |                        |          |
00244     //  |                        |          |
00245     //  |                        |          |
00246     //  |                        |          |
00247     //  |                        |          |
00248     //  |                        |          |
00249     //  |                        |          |
00250     //  +------------------------+----------+
00251     //  | Attachments:           | Settings |
00252     //  |                        |          |
00253     //  +------------------------+----------+
00254     //  | Attendees:                        |
00255     //  |                                   |
00256     //  +-----------------------------------+
00257     //  | Categories: _____________________ |
00258     //  +-----------------------------------+
00259 
00260     QRect box( 0, 0, width, height );
00261     QRect titleBox( box );
00262     titleBox.setHeight( headerHeight() );
00263     // Draw summary as header, no small calendars in title bar, expand height if needed
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       // TODO: Convert the recurrence to a string and print it out!
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         // Alarm offset, copied from koeditoralarms.cpp:
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; // make minutes
00326         int useoffset = offset;
00327 
00328         if ( offset % (24*60) == 0 && offset>0 ) { // divides evenly into days?
00329           useoffset = offset / (24*60);
00330           offsetstr = offsetstr.arg( i18n("1 day", "%n days", useoffset ) );
00331         } else if (offset % 60 == 0 && offset>0 ) { // divides evenly into hours?
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     // Finally, draw the frame around the time information...
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(), /*sameLine=*/true, /*expand=*/true, captionFont, textFont );
00359     locationBox.setBottom( locationBottom );
00360 
00361 
00362     // Now start constructing the boxes from the bottom:
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     // TODO: Adjust boxes depending on the show options...
00380 //     if ( !mShowOptions ) {
00381 //       optionsBox.left()
00382 //     bool mShowOptions;
00383 // //     bool mShowSubitemsNotes;
00384 //     bool mShowAttendees;
00385 //     bool mShowAttachments;
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(), /*sameLine=*/false, 
00394                         /*expand=*/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, /*sameLine=*/false, /*expand=*/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(), /*sameLine=*/false, 
00410                             /*expand=*/false, captionFont, textFont );
00411         // TODO: Draw subitems
00412       }
00413     }
00414 
00415     if ( mShowAttachments ) {
00416       int attachStart = drawBoxWithCaption( p, attachmentsBox, 
00417                         i18n("Attachments:"), QString::null, /*sameLine=*/false, 
00418                         /*expand=*/false, captionFont, textFont );
00419       // TODO: Print out the attachments somehow
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                /*sameLine=*/false, /*expand=*/false, captionFont, textFont );
00441     }
00442 
00443     if ( mShowOptions ) {
00444       QString optionsString = i18n("Status: %1").arg( (*it)->statusStr() );
00445       optionsString += "\n";
00446       optionsString += i18n("Secrecy: %1").arg( (*it)->secrecyStr() );
00447       optionsString += "\n";
00448       if ( (*it)->type() == "Event" ) {
00449         Event *e = static_cast<Event*>(*it);
00450         if ( e->transparency() == Event::Opaque ) {
00451           optionsString += i18n("Show as: Busy");
00452         } else {
00453           optionsString += i18n("Show as: Free");
00454         }
00455         optionsString += "\n";
00456       } else if ( (*it)->type() == "Todo" ) {
00457         Todo *t = static_cast<Todo*>(*it);
00458         if ( t->isOverdue() ) {
00459           optionsString += i18n("This task is overdue!");
00460           optionsString += "\n";
00461         }
00462       } else if ( (*it)->type() == "Journal" ) {
00463         //TODO: Anything Journal-specific?
00464       }
00465       drawBoxWithCaption( p, optionsBox, i18n("Settings: "),
00466              optionsString, /*sameLine=*/false, /*expand=*/false, captionFont, textFont );
00467     }
00468     
00469     drawBoxWithCaption( p, categoriesBox, i18n("Categories: "),
00470            (*it)->categories().join( i18n("Spacer for the joined list of categories", ", ") ),
00471            /*sameLine=*/true, /*expand=*/false, captionFont, textFont );
00472   }
00473   p.setFont( oldFont );
00474 }
00475 
00476 /**************************************************************
00477  *           Print Day
00478  **************************************************************/
00479 
00480 CalPrintDay::CalPrintDay() : CalPrintPluginBase()
00481 {
00482 }
00483 
00484 CalPrintDay::~CalPrintDay()
00485 {
00486 }
00487 
00488 QWidget *CalPrintDay::createConfigWidget( QWidget *w )
00489 {
00490   return new CalPrintDayConfig_Base( w );
00491 }
00492 
00493 void CalPrintDay::readSettingsWidget()
00494 {
00495   CalPrintDayConfig_Base *cfg =
00496       dynamic_cast<CalPrintDayConfig_Base*>( mConfigWidget );
00497   if ( cfg ) {
00498     mFromDate = cfg->mFromDate->date();
00499     mToDate = cfg->mToDate->date();
00500 
00501     mStartTime = cfg->mFromTime->time();
00502     mEndTime = cfg->mToTime->time();
00503     mIncludeAllEvents = cfg->mIncludeAllEvents->isChecked();
00504 
00505     mIncludeTodos = cfg->mIncludeTodos->isChecked();
00506     mUseColors = cfg->mColors->isChecked();
00507   }
00508 }
00509 
00510 void CalPrintDay::setSettingsWidget()
00511 {
00512   CalPrintDayConfig_Base *cfg =
00513       dynamic_cast<CalPrintDayConfig_Base*>( mConfigWidget );
00514   if ( cfg ) {
00515     cfg->mFromDate->setDate( mFromDate );
00516     cfg->mToDate->setDate( mToDate );
00517 
00518     cfg->mFromTime->setTime( mStartTime );
00519     cfg->mToTime->setTime( mEndTime );
00520     cfg->mIncludeAllEvents->setChecked( mIncludeAllEvents );
00521 
00522     cfg->mIncludeTodos->setChecked( mIncludeTodos );
00523     cfg->mColors->setChecked( mUseColors );
00524   }
00525 }
00526 
00527 void CalPrintDay::loadConfig()
00528 {
00529   if ( mConfig ) {
00530     QDate dt;
00531     QTime tm1( dayStart() );
00532     QDateTime startTm( dt, tm1 );
00533     QDateTime endTm( dt, tm1.addSecs( 12 * 60 * 60 ) );
00534     mStartTime = mConfig->readDateTimeEntry( "Start time", &startTm ).time();
00535     mEndTime = mConfig->readDateTimeEntry( "End time", &endTm ).time();
00536     mIncludeTodos = mConfig->readBoolEntry( "Include todos", false );
00537     mIncludeAllEvents = mConfig->readBoolEntry( "Include all events", false );
00538   }
00539   setSettingsWidget();
00540 }
00541 
00542 void CalPrintDay::saveConfig()
00543 {
00544   readSettingsWidget();
00545   if ( mConfig ) {
00546     mConfig->writeEntry( "Start time", QDateTime( QDate(), mStartTime ) );
00547     mConfig->writeEntry( "End time", QDateTime( QDate(), mEndTime ) );
00548     mConfig->writeEntry( "Include todos", mIncludeTodos );
00549     mConfig->writeEntry( "Include all events", mIncludeAllEvents );
00550   }
00551 }
00552 
00553 void CalPrintDay::setDateRange( const QDate& from, const QDate& to )
00554 {
00555   CalPrintPluginBase::setDateRange( from, to );
00556   CalPrintDayConfig_Base *cfg =
00557       dynamic_cast<CalPrintDayConfig_Base*>( mConfigWidget );
00558   if ( cfg ) {
00559     cfg->mFromDate->setDate( from );
00560     cfg->mToDate->setDate( to );
00561   }
00562 }
00563 
00564 void CalPrintDay::print( QPainter &p, int width, int height )
00565 {
00566   QDate curDay( mFromDate );
00567 
00568   do {
00569     QTime curStartTime( mStartTime );
00570     QTime curEndTime( mEndTime );
00571 
00572     // For an invalid time range, simply show one hour, starting at the hour
00573     // before the given start time
00574     if ( curEndTime <= curStartTime ) {
00575       curStartTime = QTime( curStartTime.hour(), 0, 0 );
00576       curEndTime = curStartTime.addSecs( 3600 );
00577     }
00578 
00579     KLocale *local = KGlobal::locale();
00580     QRect headerBox( 0, 0, width, headerHeight() );
00581     drawHeader( p, local->formatDate( curDay ), curDay, QDate(), headerBox );
00582 
00583 
00584     Event::List eventList = mCalendar->events( curDay,
00585                                                EventSortStartDate,
00586                                                SortDirectionAscending );
00587 
00588     p.setFont( QFont( "sans-serif", 12 ) );
00589 
00590     // TODO: Find a good way to determine the height of the all-day box
00591     QRect allDayBox( TIMELINE_WIDTH + padding(), headerBox.bottom() + padding(),
00592                      0, height / 20 );
00593     allDayBox.setRight( width );
00594     int allDayHeight = drawAllDayBox( p, eventList, curDay, true, allDayBox );
00595 
00596     QRect dayBox( allDayBox );
00597     dayBox.setTop( allDayHeight /*allDayBox.bottom()*/ );
00598     dayBox.setBottom( height );
00599     drawAgendaDayBox( p, eventList, curDay, mIncludeAllEvents,
00600                       curStartTime, curEndTime, dayBox );
00601 
00602     QRect tlBox( dayBox );
00603     tlBox.setLeft( 0 );
00604     tlBox.setWidth( TIMELINE_WIDTH );
00605     drawTimeLine( p, curStartTime, curEndTime, tlBox );
00606     curDay = curDay.addDays( 1 );
00607     if ( curDay <= mToDate ) mPrinter->newPage();
00608   } while ( curDay <= mToDate );
00609 }
00610 
00611 
00612 
00613 /**************************************************************
00614  *           Print Week
00615  **************************************************************/
00616 
00617 CalPrintWeek::CalPrintWeek() : CalPrintPluginBase()
00618 {
00619 }
00620 
00621 CalPrintWeek::~CalPrintWeek()
00622 {
00623 }
00624 
00625 QWidget *CalPrintWeek::createConfigWidget( QWidget *w )
00626 {
00627   return new CalPrintWeekConfig_Base( w );
00628 }
00629 
00630 void CalPrintWeek::readSettingsWidget()
00631 {
00632   CalPrintWeekConfig_Base *cfg =
00633       dynamic_cast<CalPrintWeekConfig_Base*>( mConfigWidget );
00634   if ( cfg ) {
00635     mFromDate = cfg->mFromDate->date();
00636     mToDate = cfg->mToDate->date();
00637 
00638     mWeekPrintType = (eWeekPrintType)( cfg->mPrintType->id(
00639       cfg->mPrintType->selected() ) );
00640 
00641     mStartTime = cfg->mFromTime->time();
00642     mEndTime = cfg->mToTime->time();
00643 
00644     mIncludeTodos = cfg->mIncludeTodos->isChecked();
00645     mUseColors = cfg->mColors->isChecked();
00646   }
00647 }
00648 
00649 void CalPrintWeek::setSettingsWidget()
00650 {
00651   CalPrintWeekConfig_Base *cfg =
00652       dynamic_cast<CalPrintWeekConfig_Base*>( mConfigWidget );
00653   if ( cfg ) {
00654     cfg->mFromDate->setDate( mFromDate );
00655     cfg->mToDate->setDate( mToDate );
00656 
00657     cfg->mPrintType->setButton( mWeekPrintType );
00658 
00659     cfg->mFromTime->setTime( mStartTime );
00660     cfg->mToTime->setTime( mEndTime );
00661 
00662     cfg->mIncludeTodos->setChecked( mIncludeTodos );
00663     cfg->mColors->setChecked( mUseColors );
00664   }
00665 }
00666 
00667 void CalPrintWeek::loadConfig()
00668 {
00669   if ( mConfig ) {
00670     QDate dt;
00671     QTime tm1( dayStart() );
00672     QDateTime startTm( dt, tm1  );
00673     QDateTime endTm( dt, tm1.addSecs( 43200 ) );
00674     mStartTime = mConfig->readDateTimeEntry( "Start time", &startTm ).time();
00675     mEndTime = mConfig->readDateTimeEntry( "End time", &endTm ).time();
00676     mIncludeTodos = mConfig->readBoolEntry( "Include todos", false );
00677     mWeekPrintType =(eWeekPrintType)( mConfig->readNumEntry( "Print type", (int)Filofax ) );
00678   }
00679   setSettingsWidget();
00680 }
00681 
00682 void CalPrintWeek::saveConfig()
00683 {
00684   readSettingsWidget();
00685   if ( mConfig ) {
00686     mConfig->writeEntry( "Start time", QDateTime( QDate(), mStartTime ) );
00687     mConfig->writeEntry( "End time", QDateTime( QDate(), mEndTime ) );
00688     mConfig->writeEntry( "Include todos", mIncludeTodos );
00689     mConfig->writeEntry( "Print type", int( mWeekPrintType ) );
00690   }
00691 }
00692 
00693 KPrinter::Orientation CalPrintWeek::defaultOrientation()
00694 {
00695   if ( mWeekPrintType == Filofax ) return KPrinter::Portrait;
00696   else if ( mWeekPrintType == SplitWeek ) return KPrinter::Portrait;
00697   else return KPrinter::Landscape;
00698 }
00699 
00700 void CalPrintWeek::setDateRange( const QDate &from, const QDate &to )
00701 {
00702   CalPrintPluginBase::setDateRange( from, to );
00703   CalPrintWeekConfig_Base *cfg =
00704       dynamic_cast<CalPrintWeekConfig_Base*>( mConfigWidget );
00705   if ( cfg ) {
00706     cfg->mFromDate->setDate( from );
00707     cfg->mToDate->setDate( to );
00708   }
00709 }
00710 
00711 void CalPrintWeek::print( QPainter &p, int width, int height )
00712 {
00713   QDate curWeek, fromWeek, toWeek;
00714 
00715   // correct begin and end to first and last day of week
00716   int weekdayCol = weekdayColumn( mFromDate.dayOfWeek() );
00717   fromWeek = mFromDate.addDays( -weekdayCol );
00718   weekdayCol = weekdayColumn( mFromDate.dayOfWeek() );
00719   toWeek = mToDate.addDays( 6 - weekdayCol );
00720 
00721   curWeek = fromWeek.addDays( 6 );
00722   KLocale *local = KGlobal::locale();
00723 
00724   QString line1, line2, title;
00725   QRect headerBox( 0, 0, width, headerHeight() );
00726   QRect weekBox( headerBox );
00727   weekBox.setTop( headerBox.bottom() + padding() );
00728   weekBox.setBottom( height );
00729 
00730   switch ( mWeekPrintType ) {
00731     case Filofax:
00732       do {
00733         line1 = local->formatDate( curWeek.addDays( -6 ) );
00734         line2 = local->formatDate( curWeek );
00735         if ( orientation() == KPrinter::Landscape ) {
00736           title = i18n("date from-to", "%1 - %2");
00737         } else {
00738           title = i18n("date from-\nto", "%1 -\n%2");;
00739         }
00740         title = title.arg( line1 ).arg( line2 );
00741         drawHeader( p, title, curWeek.addDays( -6 ), QDate(), headerBox );
00742         drawWeek( p, curWeek, weekBox );
00743         curWeek = curWeek.addDays( 7 );
00744         if ( curWeek <= toWeek )
00745           mPrinter->newPage();
00746       } while ( curWeek <= toWeek );
00747       break;
00748 
00749     case Timetable:
00750     default:
00751       do {
00752         line1 = local->formatDate( curWeek.addDays( -6 ) );
00753         line2 = local->formatDate( curWeek );
00754         if ( orientation() == KPrinter::Landscape ) {
00755           title = i18n("date from - to (week number)", "%1 - %2 (Week %3)");
00756         } else {
00757           title = i18n("date from -\nto (week number)", "%1 -\n%2 (Week %3)");
00758         }
00759         title = title.arg( line1 ).arg( line2 ).arg( curWeek.weekNumber() );
00760         drawHeader( p, title, curWeek, QDate(), headerBox );
00761         QRect weekBox( headerBox );
00762         weekBox.setTop( headerBox.bottom() + padding() );
00763         weekBox.setBottom( height );
00764 
00765         drawTimeTable( p, fromWeek, curWeek, mStartTime, mEndTime, weekBox );
00766         fromWeek = fromWeek.addDays( 7 );
00767         curWeek = fromWeek.addDays( 6 );
00768         if ( curWeek <= toWeek )
00769           mPrinter->newPage();
00770       } while ( curWeek <= toWeek );
00771       break;
00772 
00773     case SplitWeek: {
00774       QRect weekBox1( weekBox );
00775       // On the left side there are four days (mo-th) plus the timeline,
00776       // on the right there are only three days (fr-su) plus the timeline. Don't
00777       // use the whole width, but rather give them the same width as on the left.
00778       weekBox1.setRight( int( ( width - TIMELINE_WIDTH ) * 3. / 4. + TIMELINE_WIDTH ) );
00779       do {
00780         QDate endLeft( fromWeek.addDays( 3 ) );
00781         int hh = headerHeight();
00782 
00783         drawTimeTable( p, fromWeek, endLeft,
00784                        mStartTime, mEndTime, weekBox );
00785         mPrinter->newPage();
00786         drawSplitHeaderRight( p, fromWeek, curWeek, QDate(), width, hh );
00787         drawTimeTable( p, endLeft.addDays( 1 ), curWeek,
00788                        mStartTime, mEndTime, weekBox1 );
00789 
00790         fromWeek = fromWeek.addDays( 7 );
00791         curWeek = fromWeek.addDays( 6 );
00792         if ( curWeek <= toWeek )
00793           mPrinter->newPage();
00794       } while ( curWeek <= toWeek );
00795       }
00796       break;
00797   }
00798 }
00799 
00800 
00801 
00802 
00803 /**************************************************************
00804  *           Print Month
00805  **************************************************************/
00806 
00807 CalPrintMonth::CalPrintMonth() : CalPrintPluginBase()
00808 {
00809 }
00810 
00811 CalPrintMonth::~CalPrintMonth()
00812 {
00813 }
00814 
00815 QWidget *CalPrintMonth::createConfigWidget( QWidget *w )
00816 {
00817   return new CalPrintMonthConfig_Base( w );
00818 }
00819 
00820 void CalPrintMonth::readSettingsWidget()
00821 {
00822   CalPrintMonthConfig_Base *cfg =
00823       dynamic_cast<CalPrintMonthConfig_Base *>( mConfigWidget );
00824   if ( cfg ) {
00825     mFromDate = QDate( cfg->mFromYear->value(), cfg->mFromMonth->currentItem()+1, 1 );
00826     mToDate = QDate( cfg->mToYear->value(), cfg->mToMonth->currentItem()+1, 1 );
00827 
00828     mWeekNumbers =  cfg->mWeekNumbers->isChecked();
00829     mRecurDaily = cfg->mRecurDaily->isChecked();
00830     mRecurWeekly = cfg->mRecurWeekly->isChecked();
00831     mIncludeTodos = cfg->mIncludeTodos->isChecked();
00832 //    mUseColors = cfg->mColors->isChecked();
00833   }
00834 }
00835 
00836 void CalPrintMonth::setSettingsWidget()
00837 {
00838   CalPrintMonthConfig_Base *cfg =
00839       dynamic_cast<CalPrintMonthConfig_Base *>( mConfigWidget );
00840   setDateRange( mFromDate, mToDate );
00841   if ( cfg ) {
00842     cfg->mWeekNumbers->setChecked( mWeekNumbers );
00843     cfg->mRecurDaily->setChecked( mRecurDaily );
00844     cfg->mRecurWeekly->setChecked( mRecurWeekly );
00845     cfg->mIncludeTodos->setChecked( mIncludeTodos );
00846 //    cfg->mColors->setChecked( mUseColors );
00847   }
00848 }
00849 
00850 void CalPrintMonth::loadConfig()
00851 {
00852   if ( mConfig ) {
00853     mWeekNumbers = mConfig->readBoolEntry( "Print week numbers", true );
00854     mRecurDaily = mConfig->readBoolEntry( "Print daily incidences", true );
00855     mRecurWeekly = mConfig->readBoolEntry( "Print weekly incidences", true );
00856     mIncludeTodos = mConfig->readBoolEntry( "Include todos", false );
00857   }
00858   setSettingsWidget();
00859 }
00860 
00861 void CalPrintMonth::saveConfig()
00862 {
00863   readSettingsWidget();
00864   if ( mConfig ) {
00865     mConfig->writeEntry( "Print week numbers", mWeekNumbers );
00866     mConfig->writeEntry( "Print daily incidences", mRecurDaily );
00867     mConfig->writeEntry( "Print weekly incidences", mRecurWeekly );
00868     mConfig->writeEntry( "Include todos", mIncludeTodos );
00869   }
00870 }
00871 
00872 void CalPrintMonth::setDateRange( const QDate &from, const QDate &to )
00873 {
00874   CalPrintPluginBase::setDateRange( from, to );
00875   CalPrintMonthConfig_Base *cfg =
00876       dynamic_cast<CalPrintMonthConfig_Base *>( mConfigWidget );
00877   const KCalendarSystem *calSys = calendarSystem();
00878   if ( cfg && calSys ) {
00879     cfg->mFromMonth->clear();
00880     for ( int i=0; i<calSys->monthsInYear( mFromDate ); ++i ) {
00881       cfg->mFromMonth->insertItem( calSys->monthName( i+1, mFromDate.year() ) );
00882     }
00883     cfg->mToMonth->clear();
00884     for ( int i=0; i<calSys->monthsInYear( mToDate ); ++i ) {
00885       cfg->mToMonth->insertItem( calSys->monthName( i+1, mToDate.year() ) );
00886     }
00887   }
00888   if ( cfg ) {
00889     cfg->mFromMonth->setCurrentItem( from.month()-1 );
00890     cfg->mFromYear->setValue( to.year() );
00891     cfg->mToMonth->setCurrentItem( mToDate.month()-1 );
00892     cfg->mToYear->setValue( mToDate.year() );
00893   }
00894 }
00895 
00896 void CalPrintMonth::print( QPainter &p, int width, int height )
00897 {
00898   QDate curMonth, fromMonth, toMonth;
00899 
00900   fromMonth = mFromDate.addDays( -( mFromDate.day() - 1 ) );
00901   toMonth = mToDate.addDays( mToDate.daysInMonth() - mToDate.day() );
00902 
00903   curMonth = fromMonth;
00904   const KCalendarSystem *calSys = calendarSystem();
00905   if ( !calSys ) return;
00906 
00907   QRect headerBox( 0, 0, width, headerHeight() );
00908   QRect monthBox( 0, 0, width, height );
00909   monthBox.setTop( headerBox.bottom() + padding() );
00910 
00911   do {
00912     QString title( i18n("monthname year", "%1 %2") );
00913     title = title.arg( calSys->monthName( curMonth ) )
00914                  .arg( curMonth.year() );
00915     QDate tmp( fromMonth );
00916     int weekdayCol = weekdayColumn( tmp.dayOfWeek() );
00917     tmp = tmp.addDays( -weekdayCol );
00918 
00919     drawHeader( p, title, curMonth.addMonths( -1 ), curMonth.addMonths( 1 ),
00920                 headerBox );
00921     drawMonthTable( p, curMonth, mWeekNumbers, mRecurDaily, mRecurWeekly, monthBox );
00922     curMonth = curMonth.addDays( curMonth.daysInMonth() );
00923     if ( curMonth <= toMonth ) mPrinter->newPage();
00924   } while ( curMonth <= toMonth );
00925 
00926 }
00927 
00928 
00929 
00930 
00931 /**************************************************************
00932  *           Print Todos
00933  **************************************************************/
00934 
00935 CalPrintTodos::CalPrintTodos() : CalPrintPluginBase()
00936 {
00937   mTodoSortField = TodoFieldUnset;
00938   mTodoSortDirection = TodoDirectionUnset;
00939 }
00940 
00941 CalPrintTodos::~CalPrintTodos()
00942 {
00943 }
00944 
00945 QWidget *CalPrintTodos::createConfigWidget( QWidget *w )
00946 {
00947   return new CalPrintTodoConfig_Base( w );
00948 }
00949 
00950 void CalPrintTodos::readSettingsWidget()
00951 {
00952   CalPrintTodoConfig_Base *cfg =
00953       dynamic_cast<CalPrintTodoConfig_Base *>( mConfigWidget );
00954   if ( cfg ) {
00955     mPageTitle = cfg->mTitle->text();
00956 
00957     mTodoPrintType = (eTodoPrintType)( cfg->mPrintType->id(
00958       cfg->mPrintType->selected() ) );
00959 
00960     mFromDate = cfg->mFromDate->date();
00961     mToDate = cfg->mToDate->date();
00962 
00963     mIncludeDescription = cfg->mDescription->isChecked();
00964     mIncludePriority = cfg->mPriority->isChecked();
00965     mIncludeDueDate = cfg->mDueDate->isChecked();
00966     mIncludePercentComplete = cfg->mPercentComplete->isChecked();
00967     mConnectSubTodos = cfg->mConnectSubTodos->isChecked();
00968     mStrikeOutCompleted = cfg->mStrikeOutCompleted->isChecked();
00969 
00970     mTodoSortField = (eTodoSortField)cfg->mSortField->currentItem();
00971     mTodoSortDirection = (eTodoSortDirection)cfg->mSortDirection->currentItem();
00972   }
00973 }
00974 
00975 void CalPrintTodos::setSettingsWidget()
00976 {
00977 //   kdDebug(5850) << "CalPrintTodos::setSettingsWidget" << endl;
00978 
00979   CalPrintTodoConfig_Base *cfg =
00980       dynamic_cast<CalPrintTodoConfig_Base *>( mConfigWidget );
00981   if ( cfg ) {
00982     cfg->mTitle->setText( mPageTitle );
00983 
00984     cfg->mPrintType->setButton( mTodoPrintType );
00985 
00986     cfg->mFromDate->setDate( mFromDate );
00987     cfg->mToDate->setDate( mToDate );
00988 
00989     cfg->mDescription->setChecked( mIncludeDescription );
00990     cfg->mPriority->setChecked( mIncludePriority );
00991     cfg->mDueDate->setChecked( mIncludeDueDate );
00992     cfg->mPercentComplete->setChecked( mIncludePercentComplete );
00993     cfg->mConnectSubTodos->setChecked( mConnectSubTodos );
00994     cfg->mStrikeOutCompleted->setChecked( mStrikeOutCompleted );
00995 
00996     if ( mTodoSortField != TodoFieldUnset ) {
00997       // do not insert if already done so.
00998       cfg->mSortField->insertItem( i18n("Summary") );
00999       cfg->mSortField->insertItem( i18n("Start Date") );
01000       cfg->mSortField->insertItem( i18n("Due Date") );
01001       cfg->mSortField->insertItem( i18n("Priority") );
01002       cfg->mSortField->insertItem( i18n("Percent Complete") );
01003       cfg->mSortField->setCurrentItem( (int)mTodoSortField );
01004     }
01005 
01006     if ( mTodoSortDirection != TodoDirectionUnset ) {
01007       // do not insert if already done so.
01008       cfg->mSortDirection->insertItem( i18n("Ascending") );
01009       cfg->mSortDirection->insertItem( i18n("Descending") );
01010       cfg->mSortDirection->setCurrentItem( (int)mTodoSortDirection );
01011     }
01012   }
01013 }
01014 
01015 void CalPrintTodos::loadConfig()
01016 {
01017   if ( mConfig ) {
01018     mPageTitle = mConfig->readEntry( "Page title", i18n("To-do list") );
01019     mTodoPrintType = (eTodoPrintType)mConfig->readNumEntry( "Print type", (int)TodosAll );
01020     mIncludeDescription = mConfig->readBoolEntry( "Include description", true );
01021     mIncludePriority = mConfig->readBoolEntry( "Include priority", true );
01022     mIncludeDueDate = mConfig->readBoolEntry( "Include due date", true );
01023     mIncludePercentComplete = mConfig->readBoolEntry( "Include percentage completed", true );
01024     mConnectSubTodos = mConfig->readBoolEntry( "Connect subtodos", true );
01025     mStrikeOutCompleted = mConfig->readBoolEntry( "Strike out completed summaries",  true );
01026     mTodoSortField = (eTodoSortField)mConfig->readNumEntry( "Sort field", (int)TodoFieldSummary );
01027     mTodoSortDirection = (eTodoSortDirection)mConfig->readNumEntry( "Sort direction", (int)TodoDirectionAscending );
01028   }
01029   setSettingsWidget();
01030 }
01031 
01032 void CalPrintTodos::saveConfig()
01033 {
01034   readSettingsWidget();
01035   if ( mConfig ) {
01036     mConfig->writeEntry( "Page title", mPageTitle );
01037     mConfig->writeEntry( "Print type", int( mTodoPrintType ) );
01038     mConfig->writeEntry( "Include description", mIncludeDescription );
01039     mConfig->writeEntry( "Include priority", mIncludePriority );
01040     mConfig->writeEntry( "Include due date", mIncludeDueDate );
01041     mConfig->writeEntry( "Include percentage completed", mIncludePercentComplete );
01042     mConfig->writeEntry( "Connect subtodos", mConnectSubTodos );
01043     mConfig->writeEntry( "Strike out completed summaries", mStrikeOutCompleted );
01044     mConfig->writeEntry( "Sort field", mTodoSortField );
01045     mConfig->writeEntry( "Sort direction", mTodoSortDirection );
01046   }
01047 }
01048 
01049 void CalPrintTodos::print( QPainter &p, int width, int height )
01050 {
01051   // TODO: Find a good way to guarantee a nicely designed output
01052   int pospriority = 10;
01053   int possummary = 60;
01054   int posdue = width - 65;
01055   int poscomplete = posdue - 70; //Complete column is to right of the Due column
01056   int lineSpacing = 15;
01057   int fontHeight = 10;
01058 
01059   // Draw the First Page Header
01060   drawHeader( p, mPageTitle, mFromDate, QDate(),
01061                        QRect( 0, 0, width, headerHeight() ) );
01062 
01063   // Draw the Column Headers
01064   int mCurrentLinePos = headerHeight() + 5;
01065   QString outStr;
01066   QFont oldFont( p.font() );
01067 
01068   p.setFont( QFont( "sans-serif", 10, QFont::Bold ) );
01069   lineSpacing = p.fontMetrics().lineSpacing();
01070   mCurrentLinePos += lineSpacing;
01071   if ( mIncludePriority ) {
01072     outStr += i18n( "Priority" );
01073     p.drawText( pospriority, mCurrentLinePos - 2, outStr );
01074   } else {
01075     possummary = 10;
01076     pospriority = -1;
01077   }
01078 
01079   outStr.truncate( 0 );
01080   outStr += i18n( "Summary" );
01081   p.drawText( possummary, mCurrentLinePos - 2, outStr );
01082 
01083   if ( mIncludePercentComplete ) {
01084     if ( !mIncludeDueDate ) //move Complete column to the right
01085       poscomplete = posdue; //if not print the Due Date column
01086     outStr.truncate( 0 );
01087     outStr += i18n( "Complete" );
01088     p.drawText( poscomplete, mCurrentLinePos - 2, outStr );
01089   } else {
01090     poscomplete = -1;
01091   }
01092 
01093   if ( mIncludeDueDate ) {
01094     outStr.truncate( 0 );
01095     outStr += i18n( "Due" );
01096     p.drawText( posdue, mCurrentLinePos - 2, outStr );
01097   } else {
01098     posdue = -1;
01099   }
01100 
01101   p.setFont( QFont( "sans-serif", 10 ) );
01102   fontHeight = p.fontMetrics().height();
01103 
01104   Todo::List todoList;
01105   Todo::List tempList;
01106   Todo::List::ConstIterator it;
01107 
01108   // Convert sort options to the corresponding enums
01109   TodoSortField sortField = TodoSortSummary;
01110   switch( mTodoSortField ) {
01111   case TodoFieldSummary:
01112     sortField = TodoSortSummary; break;
01113   case TodoFieldStartDate:
01114     sortField = TodoSortStartDate; break;
01115   case TodoFieldDueDate:
01116     sortField = TodoSortDueDate; break;
01117   case TodoFieldPriority:
01118     sortField = TodoSortPriority; break;
01119   case TodoFieldPercentComplete:
01120     sortField = TodoSortPercentComplete; break;
01121   case TodoFieldUnset:
01122     break;
01123   }
01124 
01125   SortDirection sortDirection;
01126   switch( mTodoSortDirection ) {
01127   case TodoDirectionAscending:
01128     sortDirection = SortDirectionAscending; break;
01129   case TodoDirectionDescending:
01130     sortDirection = SortDirectionDescending; break;
01131   case TodoDirectionUnset:
01132     break;
01133   }
01134 
01135   // Create list of to-dos which will be printed
01136   todoList = mCalendar->todos( sortField,  sortDirection );
01137   switch( mTodoPrintType ) {
01138   case TodosAll:
01139     break;
01140   case TodosUnfinished:
01141     for( it = todoList.begin(); it!= todoList.end(); ++it ) {
01142       if ( !(*it)->isCompleted() )
01143         tempList.append( *it );
01144     }
01145     todoList = tempList;
01146     break;
01147   case TodosDueRange:
01148     for( it = todoList.begin(); it!= todoList.end(); ++it ) {
01149       if ( (*it)->hasDueDate() ) {
01150         if ( (*it)->dtDue().date() >= mFromDate &&
01151              (*it)->dtDue().date() <= mToDate )
01152           tempList.append( *it );
01153       } else {
01154         tempList.append( *it );
01155       }
01156     }
01157     todoList = tempList;
01158     break;
01159   }
01160 
01161   // Print to-dos
01162   int count = 0;
01163   for ( it=todoList.begin(); it!=todoList.end(); ++it ) {
01164     Todo *currEvent = *it;
01165 
01166     // Skip sub-to-dos. They will be printed recursively in drawTodo()
01167     if ( !currEvent->relatedTo() ) {
01168       count++;
01169       drawTodo( count, currEvent, p,
01170                          sortField, sortDirection,
01171                          mConnectSubTodos,
01172                          mStrikeOutCompleted, mIncludeDescription,
01173                          pospriority, possummary, posdue, poscomplete,
01174                          0, 0, mCurrentLinePos, width, height, todoList );
01175     }
01176   }
01177   p.setFont( oldFont );
01178 }
01179 
01180 
01181 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys