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 <qdatetime.h>
00032 #include <qcheckbox.h>
00033 #include <qlineedit.h>
00034 #include <qbuttongroup.h>
00035 
00036 #include <kglobal.h>
00037 #include <klocale.h>
00038 #include <kdebug.h>
00039 #include <kprinter.h>
00040 #include <kconfig.h>
00041 #include <kcalendarsystem.h>
00042 
00043 #include <libkcal/todo.h>
00044 #include <libkcal/calendar.h>
00045 
00046 #include <libkdepim/kdateedit.h>
00047 
00048 #include "calprinthelper.h"
00049 #include "calprintpluginbase.h"
00050 #include "calprintdefaultplugins.h"
00051 
00052 #include "calprintdayconfig_base.h"
00053 #include "calprintweekconfig_base.h"
00054 #include "calprintmonthconfig_base.h"
00055 #include "calprinttodoconfig_base.h"
00056 
00057 
00058 /**************************************************************
00059  *           Print Day
00060  **************************************************************/
00061 
00062 CalPrintDay::CalPrintDay() : CalPrintPluginBase()
00063 {
00064 }
00065 
00066 CalPrintDay::~CalPrintDay()
00067 {
00068 }
00069 
00070 QWidget *CalPrintDay::createConfigWidget( QWidget *w )
00071 {
00072   return new CalPrintDayConfig_Base( w );
00073 }
00074 
00075 void CalPrintDay::readSettingsWidget()
00076 {
00077   CalPrintDayConfig_Base *cfg =
00078       dynamic_cast<CalPrintDayConfig_Base*>( mConfigWidget );
00079   if ( cfg ) {
00080     mFromDate = cfg->mFromDate->date();
00081     mToDate = cfg->mToDate->date();
00082 
00083     mStartTime = cfg->mFromTime->time();
00084     mEndTime = cfg->mToTime->time();
00085     mIncludeAllEvents = cfg->mIncludeAllEvents->isChecked();
00086 
00087     mIncludeTodos = cfg->mIncludeTodos->isChecked();
00088     mUseColors = cfg->mColors->isChecked();
00089   }
00090 }
00091 
00092 void CalPrintDay::setSettingsWidget()
00093 {
00094   CalPrintDayConfig_Base *cfg =
00095       dynamic_cast<CalPrintDayConfig_Base*>( mConfigWidget );
00096   if ( cfg ) {
00097     cfg->mFromDate->setDate( mFromDate );
00098     cfg->mToDate->setDate( mToDate );
00099 
00100     cfg->mFromTime->setTime( mStartTime );
00101     cfg->mToTime->setTime( mEndTime );
00102     cfg->mIncludeAllEvents->setChecked( mIncludeAllEvents );
00103 
00104     cfg->mIncludeTodos->setChecked( mIncludeTodos );
00105     cfg->mColors->setChecked( mUseColors );
00106   }
00107 }
00108 
00109 void CalPrintDay::loadConfig()
00110 {
00111   if ( mConfig ) {
00112     QDate dt;
00113     QTime tm1( mCoreHelper->dayStart() );
00114     QDateTime startTm( dt, tm1 );
00115     QDateTime endTm( dt, tm1.addSecs( 12 * 60 * 60 ) );
00116     mStartTime = mConfig->readDateTimeEntry( "Start time", &startTm ).time();
00117     mEndTime = mConfig->readDateTimeEntry( "End time", &endTm ).time();
00118     mIncludeTodos = mConfig->readBoolEntry( "Include todos", false );
00119     mIncludeAllEvents = mConfig->readBoolEntry( "Include all events", false );
00120   }
00121   setSettingsWidget();
00122 }
00123 
00124 void CalPrintDay::saveConfig()
00125 {
00126   readSettingsWidget();
00127   if ( mConfig ) {
00128     mConfig->writeEntry( "Start time", QDateTime( QDate(), mStartTime ) );
00129     mConfig->writeEntry( "End time", QDateTime( QDate(), mEndTime ) );
00130     mConfig->writeEntry( "Include todos", mIncludeTodos );
00131     mConfig->writeEntry( "Include all events", mIncludeAllEvents );
00132   }
00133 }
00134 
00135 void CalPrintDay::setDateRange( const QDate& from, const QDate& to )
00136 {
00137   CalPrintPluginBase::setDateRange( from, to );
00138   CalPrintDayConfig_Base *cfg =
00139       dynamic_cast<CalPrintDayConfig_Base*>( mConfigWidget );
00140   if ( cfg ) {
00141     cfg->mFromDate->setDate( from );
00142     cfg->mToDate->setDate( to );
00143   }
00144 }
00145 
00146 void CalPrintDay::print( QPainter &p, int width, int height )
00147 {
00148   QDate curDay( mFromDate );
00149 
00150   do {
00151     int x = 0;
00152     int y = 0;
00153     int currHeight=( height - y ) / 20;
00154     QTime curStartTime( mStartTime );
00155     QTime curEndTime( mEndTime );
00156     if ( curStartTime.secsTo( curEndTime ) <= 3600 ) {
00157       if ( curStartTime.hour() == 0 ) {
00158         curStartTime = QTime( 0, 0, 0 );
00159         curEndTime = curStartTime.addSecs( 3600 );
00160       } else if ( curEndTime.hour() == 23 ) {
00161         curEndTime=QTime( 23, 59, 59 );
00162         if ( curStartTime > QTime( 23, 0, 0 ) ) {
00163           curStartTime = QTime( 23, 0, 0 );
00164         }
00165       } else {
00166         curStartTime = curStartTime.addSecs( -1200 );
00167       }
00168       curEndTime = curEndTime.addSecs( 1200 );
00169     }
00170 
00171     KLocale *local = KGlobal::locale();
00172     mHelper->drawHeader( p, local->formatDate( curDay, false ),
00173                 curDay, QDate(), 0, 0, width, mHelper->mHeaderHeight );
00174 
00175     y += mHelper->mHeaderHeight + 5;
00176     x = 80;
00177     Event::List eventList = mCalendar->events( curDay,
00178                                                EventSortStartDate,
00179                                                SortDirectionAscending );
00180 
00181     p.setFont( QFont( "helvetica", 12 ) );
00182     mHelper->drawAllDayBox( p, eventList, curDay, true, x, y, width - x, currHeight );
00183     y += currHeight;
00184     mHelper->drawAgendaDayBox( p, eventList, curDay, mIncludeAllEvents,
00185                       curStartTime, curEndTime, x, y, width - x, height - y );
00186     mHelper->drawTimeLine( p, curStartTime, curEndTime, 0, y, x - 5, height - y );
00187     curDay = curDay.addDays( 1 );
00188     if ( curDay <= mToDate ) mPrinter->newPage();
00189   } while ( curDay <= mToDate );
00190 }
00191 
00192 
00193 
00194 /**************************************************************
00195  *           Print Week
00196  **************************************************************/
00197 
00198 CalPrintWeek::CalPrintWeek() : CalPrintPluginBase()
00199 {
00200 }
00201 
00202 CalPrintWeek::~CalPrintWeek()
00203 {
00204 }
00205 
00206 QWidget *CalPrintWeek::createConfigWidget( QWidget *w )
00207 {
00208   return new CalPrintWeekConfig_Base( w );
00209 }
00210 
00211 void CalPrintWeek::readSettingsWidget()
00212 {
00213   CalPrintWeekConfig_Base *cfg =
00214       dynamic_cast<CalPrintWeekConfig_Base*>( mConfigWidget );
00215   if ( cfg ) {
00216     mFromDate = cfg->mFromDate->date();
00217     mToDate = cfg->mToDate->date();
00218 
00219     mWeekPrintType = (eWeekPrintType)( cfg->mPrintType->id(
00220       cfg->mPrintType->selected() ) );
00221 
00222     mStartTime = cfg->mFromTime->time();
00223     mEndTime = cfg->mToTime->time();
00224 
00225     mIncludeTodos = cfg->mIncludeTodos->isChecked();
00226     mUseColors = cfg->mColors->isChecked();
00227   }
00228 }
00229 
00230 void CalPrintWeek::setSettingsWidget()
00231 {
00232   CalPrintWeekConfig_Base *cfg =
00233       dynamic_cast<CalPrintWeekConfig_Base*>( mConfigWidget );
00234   if ( cfg ) {
00235     cfg->mFromDate->setDate( mFromDate );
00236     cfg->mToDate->setDate( mToDate );
00237 
00238     cfg->mPrintType->setButton( mWeekPrintType );
00239 
00240     cfg->mFromTime->setTime( mStartTime );
00241     cfg->mToTime->setTime( mEndTime );
00242 
00243     cfg->mIncludeTodos->setChecked( mIncludeTodos );
00244     cfg->mColors->setChecked( mUseColors );
00245   }
00246 }
00247 
00248 void CalPrintWeek::loadConfig()
00249 {
00250   if ( mConfig ) {
00251     QDate dt;
00252     QTime tm1( mCoreHelper->dayStart() );
00253     QDateTime startTm( dt, tm1  );
00254     QDateTime endTm( dt, tm1.addSecs( 43200 ) );
00255     mStartTime = mConfig->readDateTimeEntry( "Start time", &startTm ).time();
00256     mEndTime = mConfig->readDateTimeEntry( "End time", &endTm ).time();
00257     mIncludeTodos = mConfig->readBoolEntry( "Include todos", false );
00258     mWeekPrintType =(eWeekPrintType)( mConfig->readNumEntry( "Print type", (int)Filofax ) );
00259   }
00260   setSettingsWidget();
00261 }
00262 
00263 void CalPrintWeek::saveConfig()
00264 {
00265   readSettingsWidget();
00266   if ( mConfig ) {
00267     mConfig->writeEntry( "Start time", QDateTime( QDate(), mStartTime ) );
00268     mConfig->writeEntry( "End time", QDateTime( QDate(), mEndTime ) );
00269     mConfig->writeEntry( "Include todos", mIncludeTodos );
00270     mConfig->writeEntry( "Print type", int( mWeekPrintType ) );
00271   }
00272 }
00273 
00274 KPrinter::Orientation CalPrintWeek::orientation()
00275 {
00276   if ( mWeekPrintType == Filofax ) return KPrinter::Portrait;
00277   else if ( mWeekPrintType == SplitWeek ) return KPrinter::Portrait;
00278   else return KPrinter::Landscape;
00279 }
00280 
00281 void CalPrintWeek::setDateRange( const QDate &from, const QDate &to )
00282 {
00283   CalPrintPluginBase::setDateRange( from, to );
00284   CalPrintWeekConfig_Base *cfg =
00285       dynamic_cast<CalPrintWeekConfig_Base*>( mConfigWidget );
00286   if ( cfg ) {
00287     cfg->mFromDate->setDate( from );
00288     cfg->mToDate->setDate( to );
00289   }
00290 }
00291 
00292 void CalPrintWeek::print( QPainter &p, int width, int height )
00293 {
00294   QDate curWeek, fromWeek, toWeek;
00295 
00296   // correct begin and end to first and last day of week
00297   int weekdayCol = mHelper->weekdayColumn( mFromDate.dayOfWeek() );
00298   fromWeek = mFromDate.addDays( -weekdayCol );
00299   weekdayCol = mHelper->weekdayColumn( mFromDate.dayOfWeek() );
00300   toWeek = mToDate.addDays( 6 - weekdayCol );
00301 
00302   curWeek = fromWeek.addDays( 6 );
00303   KLocale *local = KGlobal::locale();
00304 
00305   switch ( mWeekPrintType ) {
00306     case Filofax:
00307       do {
00308         QString line1( local->formatDate( curWeek.addDays( -6 ) ) );
00309         QString line2( local->formatDate( curWeek ) );
00310         mHelper->drawHeader( p, line1 + "\n" + line2, curWeek.addDays( -6 ), QDate(),
00311                     0, 0, width, mHelper->mHeaderHeight );
00312         int top = mHelper->mHeaderHeight + 10;
00313         mHelper->drawWeek( p, curWeek, 0, top, width, height - top );
00314         curWeek = curWeek.addDays( 7 );
00315         if ( curWeek <= toWeek )
00316           mPrinter->newPage();
00317       } while ( curWeek <= toWeek );
00318       break;
00319 
00320     case Timetable:
00321     default:
00322       do {
00323         QString line1( local->formatDate( curWeek.addDays( -6 ) ) );
00324         QString line2( local->formatDate( curWeek ) );
00325         int hh = int(mHelper->mHeaderHeight * 2./3.);
00326         mHelper->drawHeader( p, i18n("date from - to", "%1 - %2\nWeek %3")
00327                              .arg( line1 )
00328                              .arg( line2 )
00329                              .arg( curWeek.weekNumber() ),
00330                              curWeek, QDate(), 0, 0, width, hh );
00331         mHelper->drawTimeTable( p, fromWeek, curWeek,
00332                        mStartTime, mEndTime, 0, hh + 5,
00333                        width, height - hh - 5 );
00334         fromWeek = fromWeek.addDays( 7 );
00335         curWeek = fromWeek.addDays( 6 );
00336         if ( curWeek <= toWeek )
00337           mPrinter->newPage();
00338       } while ( curWeek <= toWeek );
00339       break;
00340 
00341     case SplitWeek:
00342       do {
00343         QString line1( local->formatDate( curWeek.addDays( -6 ) ) );
00344         QString line2( local->formatDate( curWeek ) );
00345         QDate endLeft( fromWeek.addDays( 3 ) );
00346         int hh = mHelper->mHeaderHeight;
00347 
00348         mHelper->drawTimeTable( p, fromWeek, endLeft,
00349                        mStartTime, mEndTime, 0, hh + 5,
00350                        width, height - hh - 5 );
00351         mPrinter->newPage();
00352         mHelper->drawSplitHeaderRight( p, fromWeek, curWeek, QDate(), width, hh );
00353         mHelper->drawTimeTable( p, endLeft.addDays( 1 ), curWeek,
00354                        mStartTime, mEndTime, 0, hh + 5,
00355                        int( ( width - 50 ) * 3. / 4. + 50 ), height - hh - 5 );
00356 
00357         fromWeek = fromWeek.addDays( 7 );
00358         curWeek = fromWeek.addDays( 6 );
00359         if ( curWeek <= toWeek )
00360           mPrinter->newPage();
00361       } while ( curWeek <= toWeek );
00362       break;
00363   }
00364 }
00365 
00366 
00367 
00368 
00369 /**************************************************************
00370  *           Print Month
00371  **************************************************************/
00372 
00373 CalPrintMonth::CalPrintMonth() : CalPrintPluginBase()
00374 {
00375 }
00376 
00377 CalPrintMonth::~CalPrintMonth()
00378 {
00379 }
00380 
00381 QWidget *CalPrintMonth::createConfigWidget( QWidget *w )
00382 {
00383   return new CalPrintMonthConfig_Base( w );
00384 }
00385 
00386 void CalPrintMonth::readSettingsWidget()
00387 {
00388   CalPrintMonthConfig_Base *cfg =
00389       dynamic_cast<CalPrintMonthConfig_Base *>( mConfigWidget );
00390   if ( cfg ) {
00391     mFromDate = cfg->mFromDate->date();
00392     mToDate = cfg->mToDate->date();
00393 
00394     mWeekNumbers =  cfg->mWeekNumbers->isChecked();
00395     mRecurDaily = cfg->mRecurDaily->isChecked();
00396     mRecurWeekly = cfg->mRecurWeekly->isChecked();
00397     mIncludeTodos = cfg->mIncludeTodos->isChecked();
00398 //    mUseColors = cfg->mColors->isChecked();
00399   }
00400 }
00401 
00402 void CalPrintMonth::setSettingsWidget()
00403 {
00404   CalPrintMonthConfig_Base *cfg =
00405       dynamic_cast<CalPrintMonthConfig_Base *>( mConfigWidget );
00406   if ( cfg ) {
00407     cfg->mFromDate->setDate( mFromDate );
00408     cfg->mToDate->setDate( mToDate );
00409 
00410     cfg->mWeekNumbers->setChecked( mWeekNumbers );
00411     cfg->mRecurDaily->setChecked( mRecurDaily );
00412     cfg->mRecurWeekly->setChecked( mRecurWeekly );
00413     cfg->mIncludeTodos->setChecked( mIncludeTodos );
00414 //    cfg->mColors->setChecked( mUseColors );
00415   }
00416 }
00417 
00418 void CalPrintMonth::loadConfig()
00419 {
00420   if ( mConfig ) {
00421     mWeekNumbers = mConfig->readBoolEntry( "Print week numbers", true );
00422     mRecurDaily = mConfig->readBoolEntry( "Print daily incidences", true );
00423     mRecurWeekly = mConfig->readBoolEntry( "Print weekly incidences", true );
00424     mIncludeTodos = mConfig->readBoolEntry( "Include todos", false );
00425   }
00426   setSettingsWidget();
00427 }
00428 
00429 void CalPrintMonth::saveConfig()
00430 {
00431   readSettingsWidget();
00432   if ( mConfig ) {
00433     mConfig->writeEntry( "Print week numbers", mWeekNumbers );
00434     mConfig->writeEntry( "Print daily incidences", mRecurDaily );
00435     mConfig->writeEntry( "Print weekly incidences", mRecurWeekly );
00436     mConfig->writeEntry( "Include todos", mIncludeTodos );
00437   }
00438 }
00439 
00440 void CalPrintMonth::setDateRange( const QDate &from, const QDate &to )
00441 {
00442   CalPrintPluginBase::setDateRange( from, to );
00443   CalPrintMonthConfig_Base *cfg =
00444       dynamic_cast<CalPrintMonthConfig_Base *>( mConfigWidget );
00445   if ( cfg ) {
00446     cfg->mFromDate->setDate( from );
00447     cfg->mToDate->setDate( to );
00448   }
00449 }
00450 
00451 void CalPrintMonth::print( QPainter &p, int width, int height )
00452 {
00453   QDate curMonth, fromMonth, toMonth;
00454 
00455   fromMonth = mFromDate.addDays( -( mFromDate.day() - 1 ) );
00456   toMonth = mToDate.addDays( mToDate.daysInMonth() - mToDate.day() );
00457 
00458   curMonth = fromMonth;
00459   const KCalendarSystem *calSys = mHelper->calendarSystem();
00460   do {
00461     QString title( i18n("monthname year", "%1 %2") );
00462     title = title.arg( calSys->monthName( curMonth ) )
00463                  .arg( curMonth.year() );
00464     QDate tmp( fromMonth );
00465     int weekdayCol = mHelper->weekdayColumn( tmp.dayOfWeek() );
00466     tmp = tmp.addDays( -weekdayCol );
00467 
00468     mHelper->drawHeader( p, title,
00469                 curMonth.addMonths( -1 ), curMonth.addMonths( 1 ),
00470                 0, 0, width, mHelper->mHeaderHeight );
00471     mHelper->drawMonth( p, curMonth, mWeekNumbers, mRecurDaily, mRecurWeekly, 0, mHelper->mHeaderHeight + 5,
00472                width, height - mHelper->mHeaderHeight - 5 );
00473     curMonth = curMonth.addDays( curMonth.daysInMonth() );
00474     if ( curMonth <= toMonth ) mPrinter->newPage();
00475   } while ( curMonth <= toMonth );
00476 
00477 }
00478 
00479 
00480 
00481 
00482 /**************************************************************
00483  *           Print Todos
00484  **************************************************************/
00485 
00486 CalPrintTodos::CalPrintTodos() : CalPrintPluginBase()
00487 {
00488   mTodoSortField = TodoFieldUnset;
00489   mTodoSortDirection = TodoDirectionUnset;
00490 }
00491 
00492 CalPrintTodos::~CalPrintTodos()
00493 {
00494 }
00495 
00496 QWidget *CalPrintTodos::createConfigWidget( QWidget *w )
00497 {
00498   return new CalPrintTodoConfig_Base( w );
00499 }
00500 
00501 void CalPrintTodos::readSettingsWidget()
00502 {
00503   CalPrintTodoConfig_Base *cfg =
00504       dynamic_cast<CalPrintTodoConfig_Base *>( mConfigWidget );
00505   if ( cfg ) {
00506     mPageTitle = cfg->mTitle->text();
00507 
00508     mTodoPrintType = (eTodoPrintType)( cfg->mPrintType->id(
00509       cfg->mPrintType->selected() ) );
00510 
00511     mFromDate = cfg->mFromDate->date();
00512     mToDate = cfg->mToDate->date();
00513 
00514     mIncludeDescription = cfg->mDescription->isChecked();
00515     mIncludePriority = cfg->mPriority->isChecked();
00516     mIncludeDueDate = cfg->mDueDate->isChecked();
00517     mIncludePercentComplete = cfg->mPercentComplete->isChecked();
00518     mConnectSubTodos = cfg->mConnectSubTodos->isChecked();
00519     mStrikeOutCompleted = cfg->mStrikeOutCompleted->isChecked();
00520 
00521     mTodoSortField = (eTodoSortField)cfg->mSortField->currentItem();
00522     mTodoSortDirection = (eTodoSortDirection)cfg->mSortDirection->currentItem();
00523   }
00524 }
00525 
00526 void CalPrintTodos::setSettingsWidget()
00527 {
00528   kdDebug() << "CalPrintTodos::setSettingsWidget" << endl;
00529 
00530   CalPrintTodoConfig_Base *cfg =
00531       dynamic_cast<CalPrintTodoConfig_Base *>( mConfigWidget );
00532   if ( cfg ) {
00533     cfg->mTitle->setText( mPageTitle );
00534 
00535     cfg->mPrintType->setButton( mTodoPrintType );
00536 
00537     cfg->mFromDate->setDate( mFromDate );
00538     cfg->mToDate->setDate( mToDate );
00539 
00540     cfg->mDescription->setChecked( mIncludeDescription );
00541     cfg->mPriority->setChecked( mIncludePriority );
00542     cfg->mDueDate->setChecked( mIncludeDueDate );
00543     cfg->mPercentComplete->setChecked( mIncludePercentComplete );
00544     cfg->mConnectSubTodos->setChecked( mConnectSubTodos );
00545     cfg->mStrikeOutCompleted->setChecked( mStrikeOutCompleted );
00546 
00547     if ( mTodoSortField != TodoFieldUnset ) {
00548       // do not insert if already done so.
00549       cfg->mSortField->insertItem( i18n("Summary") );
00550       cfg->mSortField->insertItem( i18n("Start Date") );
00551       cfg->mSortField->insertItem( i18n("Due Date") );
00552       cfg->mSortField->insertItem( i18n("Priority") );
00553       cfg->mSortField->insertItem( i18n("Percent Complete") );
00554       cfg->mSortField->setCurrentItem( (int)mTodoSortField );
00555     }
00556 
00557     if ( mTodoSortDirection != TodoDirectionUnset ) {
00558       // do not insert if already done so.
00559       cfg->mSortDirection->insertItem( i18n("Ascending") );
00560       cfg->mSortDirection->insertItem( i18n("Descending") );
00561       cfg->mSortDirection->setCurrentItem( (int)mTodoSortDirection );
00562     }
00563   }
00564 }
00565 
00566 void CalPrintTodos::loadConfig()
00567 {
00568   if ( mConfig ) {
00569     mPageTitle = mConfig->readEntry( "Page title", i18n("To-do list") );
00570     mTodoPrintType = (eTodoPrintType)mConfig->readNumEntry( "Print type", (int)TodosAll );
00571     mIncludeDescription = mConfig->readBoolEntry( "Include description", true );
00572     mIncludePriority = mConfig->readBoolEntry( "Include priority", true );
00573     mIncludeDueDate = mConfig->readBoolEntry( "Include due date", true );
00574     mIncludePercentComplete = mConfig->readBoolEntry( "Include percentage completed", true );
00575     mConnectSubTodos = mConfig->readBoolEntry( "Connect subtodos", true );
00576     mStrikeOutCompleted = mConfig->readBoolEntry( "Strike out completed summaries",  true );
00577     mTodoSortField = (eTodoSortField)mConfig->readNumEntry( "Sort field", (int)TodoFieldSummary );
00578     mTodoSortDirection = (eTodoSortDirection)mConfig->readNumEntry( "Sort direction", (int)TodoDirectionAscending );
00579   }
00580   setSettingsWidget();
00581 }
00582 
00583 void CalPrintTodos::saveConfig()
00584 {
00585   readSettingsWidget();
00586   if ( mConfig ) {
00587     mConfig->writeEntry( "Page title", mPageTitle );
00588     mConfig->writeEntry( "Print type", int( mTodoPrintType ) );
00589     mConfig->writeEntry( "Include description", mIncludeDescription );
00590     mConfig->writeEntry( "Include priority", mIncludePriority );
00591     mConfig->writeEntry( "Include due date", mIncludeDueDate );
00592     mConfig->writeEntry( "Include percentage completed", mIncludePercentComplete );
00593     mConfig->writeEntry( "Connect subtodos", mConnectSubTodos );
00594     mConfig->writeEntry( "Strike out completed summaries", mStrikeOutCompleted );
00595     mConfig->writeEntry( "Sort field", mTodoSortField );
00596     mConfig->writeEntry( "Sort direction", mTodoSortDirection );
00597   }
00598 }
00599 
00600 void CalPrintTodos::print( QPainter &p, int width, int height )
00601 {
00602   int pospriority = 10;
00603   int possummary = 60;
00604   int posdue = width - 65;
00605   int poscomplete = posdue - 70; //Complete column is to right of the Due column
00606   int lineSpacing = 15;
00607   int fontHeight = 10;
00608 
00609   // Draw the First Page Header
00610   mHelper->drawHeader( p, mPageTitle, mFromDate, QDate(),
00611                        0, 0, width, mHelper->mHeaderHeight );
00612 
00613   // Draw the Column Headers
00614   int mCurrentLinePos = mHelper->mHeaderHeight + 5;
00615   QString outStr;
00616   QFont oldFont( p.font() );
00617 
00618   p.setFont( QFont( "helvetica", 10, QFont::Bold ) );
00619   lineSpacing = p.fontMetrics().lineSpacing();
00620   mCurrentLinePos += lineSpacing;
00621   if ( mIncludePriority ) {
00622     outStr += i18n( "Priority" );
00623     p.drawText( pospriority, mCurrentLinePos - 2, outStr );
00624   } else {
00625     possummary = 10;
00626     pospriority = -1;
00627   }
00628 
00629   outStr.truncate( 0 );
00630   outStr += i18n( "Summary" );
00631   p.drawText( possummary, mCurrentLinePos - 2, outStr );
00632 
00633   if ( mIncludePercentComplete ) {
00634     if ( !mIncludeDueDate ) //move Complete column to the right
00635       poscomplete = posdue; //if not print the Due Date column
00636     outStr.truncate( 0 );
00637     outStr += i18n( "Complete" );
00638     p.drawText( poscomplete, mCurrentLinePos - 2, outStr );
00639   } else {
00640     poscomplete = -1;
00641   }
00642 
00643   if ( mIncludeDueDate ) {
00644     outStr.truncate( 0 );
00645     outStr += i18n( "Due" );
00646     p.drawText( posdue, mCurrentLinePos - 2, outStr );
00647   } else {
00648     posdue = -1;
00649   }
00650 
00651   p.setFont( QFont( "helvetica", 10 ) );
00652   fontHeight = p.fontMetrics().height();
00653 
00654   Todo::List todoList;
00655   Todo::List tempList;
00656   Todo::List::ConstIterator it;
00657 
00658   // Convert sort options to the corresponding enums
00659   TodoSortField sortField;
00660   switch( mTodoSortField ) {
00661   case TodoFieldSummary:
00662     sortField = TodoSortSummary; break;
00663   case TodoFieldStartDate:
00664     sortField = TodoSortStartDate; break;
00665   case TodoFieldDueDate:
00666     sortField = TodoSortDueDate; break;
00667   case TodoFieldPriority:
00668     sortField = TodoSortPriority; break;
00669   case TodoFieldPercentComplete:
00670     sortField = TodoSortPercentComplete; break;
00671   case TodoFieldUnset:
00672     break;
00673   }
00674 
00675   SortDirection sortDirection;
00676   switch( mTodoSortDirection ) {
00677   case TodoDirectionAscending:
00678     sortDirection = SortDirectionAscending; break;
00679   case TodoDirectionDescending:
00680     sortDirection = SortDirectionDescending; break;
00681   case TodoDirectionUnset:
00682     break;
00683   }
00684 
00685   // Create list of to-dos which will be printed
00686   todoList = mCalendar->todos( sortField,  sortDirection );
00687   switch( mTodoPrintType ) {
00688   case TodosAll:
00689     break;
00690   case TodosUnfinished:
00691     for( it = todoList.begin(); it!= todoList.end(); ++it ) {
00692       if ( !(*it)->isCompleted() )
00693         tempList.append( *it );
00694     }
00695     todoList = tempList;
00696     break;
00697   case TodosDueRange:
00698     for( it = todoList.begin(); it!= todoList.end(); ++it ) {
00699       if ( (*it)->hasDueDate() ) {
00700         if ( (*it)->dtDue().date() >= mFromDate &&
00701              (*it)->dtDue().date() <= mToDate )
00702           tempList.append( *it );
00703       } else {
00704         tempList.append( *it );
00705       }
00706     }
00707     todoList = tempList;
00708     break;
00709   }
00710 
00711   // Print to-dos
00712   int count = 0;
00713   for ( it=todoList.begin(); it!=todoList.end(); ++it ) {
00714     Todo *currEvent = *it;
00715 
00716     // Skip sub-to-dos. They will be printed recursively in drawTodo()
00717     if ( !currEvent->relatedTo() ) {
00718       count++;
00719       mHelper->drawTodo( count, currEvent, p,
00720                          sortField, sortDirection,
00721                          mConnectSubTodos,
00722                          mStrikeOutCompleted, mIncludeDescription,
00723                          pospriority, possummary, posdue, poscomplete,
00724                          0, 0, mCurrentLinePos, width, height, todoList );
00725     }
00726   }
00727   p.setFont( oldFont );
00728 }
00729 
00730 
00731 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys