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 #include <qpainter.h>
00028 #include <qdatetimeedit.h>
00029 #include <qdatetime.h>
00030 #include <qcheckbox.h>
00031 #include <qlineedit.h>
00032 #include <qbuttongroup.h>
00033
00034 #include <kglobal.h>
00035 #include <klocale.h>
00036 #include <kdebug.h>
00037 #include <kprinter.h>
00038 #include <kconfig.h>
00039 #include <kcalendarsystem.h>
00040
00041 #include <libkcal/todo.h>
00042 #include <libkcal/calendar.h>
00043
00044 #include <libkdepim/kdateedit.h>
00045
00046 #include "koprefs.h"
00047 #include "koglobals.h"
00048 #include "calprintplugins.h"
00049 #ifndef KORG_NOPRINTER
00050
00051 #include "calprintplugins.moc"
00052
00053 #include "calprintdayconfig_base.h"
00054 #include "calprintweekconfig_base.h"
00055 #include "calprintmonthconfig_base.h"
00056 #include "calprinttodoconfig_base.h"
00057
00058
00059
00060
00061
00062
00063 CalPrintDay::CalPrintDay( KPrinter *printer, Calendar *cal, KConfig *cfg )
00064 : CalPrintBase( printer, cal, cfg )
00065 {
00066 }
00067
00068 CalPrintDay::~CalPrintDay()
00069 {
00070 }
00071
00072 QWidget *CalPrintDay::configWidget( QWidget *w )
00073 {
00074 mConfigWidget = new CalPrintDayConfig_Base( w );
00075 setSettingsWidget();
00076 return mConfigWidget;
00077 }
00078
00079 void CalPrintDay::readSettingsWidget()
00080 {
00081 CalPrintDayConfig_Base *cfg =
00082 dynamic_cast<CalPrintDayConfig_Base*>( mConfigWidget );
00083 if ( cfg ) {
00084 mFromDate = cfg->mFromDate->date();
00085 mToDate = cfg->mToDate->date();
00086
00087 mStartTime = cfg->mFromTime->time();
00088 mEndTime = cfg->mToTime->time();
00089 mIncludeAllEvents = cfg->mIncludeAllEvents->isChecked();
00090
00091 mIncludeTodos = cfg->mIncludeTodos->isChecked();
00092 mUseColors = cfg->mColors->isChecked();
00093 }
00094 }
00095
00096 void CalPrintDay::setSettingsWidget()
00097 {
00098 CalPrintDayConfig_Base *cfg =
00099 dynamic_cast<CalPrintDayConfig_Base*>( mConfigWidget );
00100 if ( cfg ) {
00101 cfg->mFromDate->setDate( mFromDate );
00102 cfg->mToDate->setDate( mToDate );
00103
00104 cfg->mFromTime->setTime( mStartTime );
00105 cfg->mToTime->setTime( mEndTime );
00106 cfg->mIncludeAllEvents->setChecked( mIncludeAllEvents );
00107
00108 cfg->mIncludeTodos->setChecked( mIncludeTodos );
00109 cfg->mColors->setChecked( mUseColors );
00110 }
00111 }
00112
00113 void CalPrintDay::loadConfig()
00114 {
00115 if ( mConfig ) {
00116 QDate dt;
00117 QTime tm1( KOPrefs::instance()->mDayBegins , 0 );
00118 QDateTime startTm( dt, tm1 );
00119 QDateTime endTm( dt, tm1.addSecs( 43200 ) );
00120 mStartTime = mConfig->readDateTimeEntry( "Start time", &startTm ).time();
00121 mEndTime = mConfig->readDateTimeEntry( "End time", &endTm ).time();
00122 mIncludeTodos = mConfig->readBoolEntry( "Include todos", false );
00123 mIncludeAllEvents = mConfig->readBoolEntry( "Include all events", false );
00124 }
00125 setSettingsWidget();
00126 }
00127
00128 void CalPrintDay::saveConfig()
00129 {
00130 kdDebug() << "CalPrintDay::saveConfig()" << endl;
00131
00132 readSettingsWidget();
00133 if ( mConfig ) {
00134 mConfig->writeEntry( "Start time", QDateTime( QDate(), mStartTime ) );
00135 mConfig->writeEntry( "End time", QDateTime( QDate(), mEndTime ) );
00136 mConfig->writeEntry( "Include todos", mIncludeTodos );
00137 mConfig->writeEntry( "Include all events", mIncludeAllEvents );
00138 }
00139 }
00140
00141 void CalPrintDay::setDateRange( const QDate& from, const QDate& to )
00142 {
00143 CalPrintBase::setDateRange( from, to );
00144 CalPrintDayConfig_Base *cfg =
00145 dynamic_cast<CalPrintDayConfig_Base*>( mConfigWidget );
00146 if ( cfg ) {
00147 cfg->mFromDate->setDate( from );
00148 cfg->mToDate->setDate( to );
00149 }
00150 }
00151
00152 void CalPrintDay::print( QPainter &p, int width, int height )
00153 {
00154 QDate curDay( mFromDate );
00155
00156 do {
00157 int x = 0;
00158 int y = 0;
00159 int currHeight=( height - y ) / 20;
00160 QTime curStartTime( mStartTime );
00161 QTime curEndTime( mEndTime );
00162 if ( curStartTime.secsTo( curEndTime ) <= 3600 ) {
00163 if ( curStartTime.hour() == 0 ) {
00164 curStartTime = QTime( 0, 0, 0 );
00165 curEndTime = curStartTime.addSecs( 3600 );
00166 } else if ( curEndTime.hour() == 23 ) {
00167 curEndTime=QTime( 23, 59, 59 );
00168 if ( curStartTime > QTime( 23, 0, 0 ) ) {
00169 curStartTime = QTime( 23, 0, 0 );
00170 }
00171 } else {
00172 curStartTime = curStartTime.addSecs( -1200 );
00173 }
00174 curEndTime = curEndTime.addSecs( 1200 );
00175 }
00176
00177 KLocale *local = KGlobal::locale();
00178 drawHeader( p, local->formatDate( curDay, false ),
00179 curDay, QDate(), 0, 0, width, mHeaderHeight );
00180
00181 y += mHeaderHeight + 5;
00182 x = 80;
00183 Event::List eventList = mCalendar->events( curDay, true );
00184
00185 p.setFont( QFont( "helvetica", 14 ) );
00186 drawAllDayBox( p, eventList, curDay, true, x, y, width - x, currHeight );
00187 y += currHeight;
00188 drawAgendaDayBox( p, eventList, curDay, mIncludeAllEvents,
00189 curStartTime, curEndTime, x, y, width - x, height - y );
00190 drawTimeLine( p, curStartTime, curEndTime, 0, y, x - 5, height - y );
00191 curDay = curDay.addDays( 1 );
00192 if ( curDay <= mToDate ) mPrinter->newPage();
00193 } while ( curDay <= mToDate );
00194 }
00195
00196
00197
00198
00199
00200
00201
00202 CalPrintWeek::CalPrintWeek(KPrinter *printer, Calendar *cal, KConfig *cfg)
00203 :CalPrintBase(printer,cal,cfg)
00204 {
00205 }
00206
00207 CalPrintWeek::~CalPrintWeek()
00208 {
00209 }
00210
00211 QWidget *CalPrintWeek::configWidget( QWidget *w )
00212 {
00213 mConfigWidget = new CalPrintWeekConfig_Base( w );
00214 setSettingsWidget();
00215 return mConfigWidget;
00216 }
00217
00218 void CalPrintWeek::readSettingsWidget()
00219 {
00220 CalPrintWeekConfig_Base *cfg =
00221 dynamic_cast<CalPrintWeekConfig_Base*>( mConfigWidget );
00222 if ( cfg ) {
00223 mFromDate = cfg->mFromDate->date();
00224 mToDate = cfg->mToDate->date();
00225
00226 mWeekPrintType = (eWeekPrintType)( cfg->mPrintType->id(
00227 cfg->mPrintType->selected() ) );
00228
00229 mStartTime = cfg->mFromTime->time();
00230 mEndTime = cfg->mToTime->time();
00231
00232 mIncludeTodos = cfg->mIncludeTodos->isChecked();
00233 mUseColors = cfg->mColors->isChecked();
00234 }
00235 }
00236
00237 void CalPrintWeek::setSettingsWidget()
00238 {
00239 CalPrintWeekConfig_Base *cfg =
00240 dynamic_cast<CalPrintWeekConfig_Base*>( mConfigWidget );
00241 if ( cfg ) {
00242 cfg->mFromDate->setDate( mFromDate );
00243 cfg->mToDate->setDate( mToDate );
00244
00245 cfg->mPrintType->setButton( mWeekPrintType );
00246
00247 cfg->mFromTime->setTime( mStartTime );
00248 cfg->mToTime->setTime( mEndTime );
00249
00250 cfg->mIncludeTodos->setChecked( mIncludeTodos );
00251 cfg->mColors->setChecked( mUseColors );
00252 }
00253 }
00254
00255 void CalPrintWeek::loadConfig()
00256 {
00257 if ( mConfig ) {
00258 QDate dt;
00259 QTime tm1( KOPrefs::instance()->mDayBegins , 0 );
00260 QDateTime startTm( dt, tm1 );
00261 QDateTime endTm( dt, tm1.addSecs( 43200 ) );
00262 mStartTime = mConfig->readDateTimeEntry( "Start time", &startTm ).time();
00263 mEndTime = mConfig->readDateTimeEntry( "End time", &endTm ).time();
00264 mIncludeTodos = mConfig->readBoolEntry( "Include todos", false );
00265 mWeekPrintType =(eWeekPrintType)( mConfig->readNumEntry( "Print type", (int)Filofax ) );
00266 }
00267 setSettingsWidget();
00268 }
00269
00270 void CalPrintWeek::saveConfig()
00271 {
00272 readSettingsWidget();
00273 if ( mConfig ) {
00274 mConfig->writeEntry( "Start time", QDateTime( QDate(), mStartTime ) );
00275 mConfig->writeEntry( "End time", QDateTime( QDate(), mEndTime ) );
00276 mConfig->writeEntry( "Include todos", mIncludeTodos );
00277 mConfig->writeEntry( "Print type", int( mWeekPrintType ) );
00278 }
00279 }
00280
00281 KPrinter::Orientation CalPrintWeek::orientation()
00282 {
00283 if ( mWeekPrintType == Filofax ) return KPrinter::Portrait;
00284 else return KPrinter::Landscape;
00285 }
00286
00287 void CalPrintWeek::setDateRange( const QDate &from, const QDate &to )
00288 {
00289 CalPrintBase::setDateRange( from, to );
00290 CalPrintWeekConfig_Base *cfg =
00291 dynamic_cast<CalPrintWeekConfig_Base*>( mConfigWidget );
00292 if ( cfg ) {
00293 cfg->mFromDate->setDate( from );
00294 cfg->mToDate->setDate( to );
00295 }
00296 }
00297
00298 void CalPrintWeek::print( QPainter &p, int width, int height )
00299 {
00300 QDate curWeek, fromWeek, toWeek;
00301
00302
00303 int weekdayCol = weekdayColumn( mFromDate.dayOfWeek() );
00304 fromWeek = mFromDate.addDays( -weekdayCol );
00305 weekdayCol = weekdayColumn( mFromDate.dayOfWeek() );
00306 toWeek = mToDate.addDays( 6 - weekdayCol );
00307
00308 curWeek = fromWeek.addDays( 6 );
00309 KLocale *local = KGlobal::locale();
00310
00311 switch ( mWeekPrintType ) {
00312 case Filofax:
00313 do {
00314 QString line1( local->formatDate( curWeek.addDays( -6 ) ) );
00315 QString line2( local->formatDate( curWeek ) );
00316 drawHeader( p, line1 + "\n" + line2, curWeek.addDays( -6 ), QDate(),
00317 0, 0, width, mHeaderHeight );
00318 int top = mHeaderHeight + 10;
00319 drawWeek( p, curWeek, 0, top, width, height - top );
00320 curWeek = curWeek.addDays( 7 );
00321 if ( curWeek <= toWeek )
00322 mPrinter->newPage();
00323 } while ( curWeek <= toWeek );
00324 break;
00325
00326 case Timetable:
00327 default:
00328 do {
00329 QString line1( local->formatDate( curWeek.addDays( -6 ) ) );
00330 QString line2( local->formatDate( curWeek ) );
00331 int hh = int(mHeaderHeight * 2./3.);
00332 drawHeader( p, i18n("date from - to", "%1 - %2").arg( line1 ).arg( line2 ),
00333 curWeek, QDate(), 0, 0, width, hh );
00334 drawTimeTable( p, fromWeek, curWeek,
00335 mStartTime, mEndTime, 0, hh + 5,
00336 width, height - hh - 5 );
00337 fromWeek = fromWeek.addDays( 7 );
00338 curWeek = fromWeek.addDays( 6 );
00339 if ( curWeek <= toWeek )
00340 mPrinter->newPage();
00341 } while ( curWeek <= toWeek );
00342 break;
00343 }
00344 }
00345
00346
00347
00348
00349
00350
00351
00352
00353 CalPrintMonth::CalPrintMonth( KPrinter *printer, Calendar *cal, KConfig *cfg )
00354 : CalPrintBase( printer, cal, cfg )
00355 {
00356 }
00357
00358 CalPrintMonth::~CalPrintMonth()
00359 {
00360 }
00361
00362 QWidget *CalPrintMonth::configWidget( QWidget *w )
00363 {
00364 mConfigWidget = new CalPrintMonthConfig_Base( w );
00365 return mConfigWidget;
00366 }
00367
00368 void CalPrintMonth::readSettingsWidget()
00369 {
00370 CalPrintMonthConfig_Base *cfg =
00371 dynamic_cast<CalPrintMonthConfig_Base *>( mConfigWidget );
00372 if ( cfg ) {
00373 mFromDate = cfg->mFromDate->date();
00374 mToDate = cfg->mToDate->date();
00375
00376 mWeekNumbers = cfg->mWeekNumbers->isChecked();
00377
00378 mIncludeTodos = cfg->mIncludeTodos->isChecked();
00379
00380 }
00381 }
00382
00383 void CalPrintMonth::setSettingsWidget()
00384 {
00385 CalPrintMonthConfig_Base *cfg =
00386 dynamic_cast<CalPrintMonthConfig_Base *>( mConfigWidget );
00387 if ( cfg ) {
00388 cfg->mFromDate->setDate( mFromDate );
00389 cfg->mToDate->setDate( mToDate );
00390
00391 cfg->mWeekNumbers->setChecked( mWeekNumbers );
00392
00393 cfg->mIncludeTodos->setChecked( mIncludeTodos );
00394
00395 }
00396 }
00397
00398 void CalPrintMonth::loadConfig()
00399 {
00400 if ( mConfig ) {
00401 mWeekNumbers = mConfig->readBoolEntry( "Print week numbers", true );
00402 mIncludeTodos = mConfig->readBoolEntry( "Include todos", false );
00403 }
00404 setSettingsWidget();
00405 }
00406
00407 void CalPrintMonth::saveConfig()
00408 {
00409 readSettingsWidget();
00410 if ( mConfig ) {
00411 mConfig->writeEntry( "Print week numbers", mWeekNumbers );
00412 mConfig->writeEntry( "Include todos", mIncludeTodos );
00413 }
00414 }
00415
00416 void CalPrintMonth::setDateRange( const QDate &from, const QDate &to )
00417 {
00418 CalPrintBase::setDateRange( from, to );
00419 CalPrintMonthConfig_Base *cfg =
00420 dynamic_cast<CalPrintMonthConfig_Base *>( mConfigWidget );
00421 if ( cfg ) {
00422 cfg->mFromDate->setDate( from );
00423 cfg->mToDate->setDate( to );
00424 }
00425 }
00426
00427 void CalPrintMonth::print( QPainter &p, int width, int height )
00428 {
00429 QDate curMonth, fromMonth, toMonth;
00430
00431 fromMonth = mFromDate.addDays( -( mFromDate.day() - 1 ) );
00432 toMonth = mToDate.addDays( mToDate.daysInMonth() - mToDate.day() );
00433
00434 curMonth = fromMonth;
00435 do {
00436 QString title( i18n("monthname year", "%1 %2") );
00437 title = title.arg( KOGlobals::self()->calendarSystem()->monthName( curMonth ) )
00438 .arg( curMonth.year() );
00439 QDate tmp( fromMonth );
00440 int weekdayCol = weekdayColumn( tmp.dayOfWeek() );
00441 tmp = tmp.addDays( -weekdayCol );
00442
00443 drawHeader( p, title,
00444 curMonth.addMonths( -1 ), curMonth.addMonths( 1 ),
00445 0, 0, width, mHeaderHeight );
00446 drawMonth( p, curMonth, mWeekNumbers, 0, mHeaderHeight + 5,
00447 width, height - mHeaderHeight - 5 );
00448 curMonth = curMonth.addDays( curMonth.daysInMonth() );
00449 if ( curMonth <= toMonth ) mPrinter->newPage();
00450 } while ( curMonth <= toMonth );
00451
00452 }
00453
00454
00455
00456
00457
00458
00459
00460
00461 CalPrintTodos::CalPrintTodos( KPrinter *printer, Calendar *cal, KConfig *cfg )
00462 : CalPrintBase( printer, cal, cfg )
00463 {
00464 }
00465
00466 CalPrintTodos::~CalPrintTodos()
00467 {
00468 }
00469
00470 QWidget *CalPrintTodos::configWidget( QWidget *w )
00471 {
00472 mConfigWidget = new CalPrintTodoConfig_Base( w );
00473 return mConfigWidget;
00474 }
00475
00476 void CalPrintTodos::readSettingsWidget()
00477 {
00478 CalPrintTodoConfig_Base *cfg =
00479 dynamic_cast<CalPrintTodoConfig_Base *>( mConfigWidget );
00480 if ( cfg ) {
00481 mPageTitle = cfg->mTitle->text();
00482
00483 mTodoPrintType = (eTodoPrintType)( cfg->mPrintType->id(
00484 cfg->mPrintType->selected() ) );
00485
00486 mFromDate = cfg->mFromDate->date();
00487 mToDate = cfg->mToDate->date();
00488
00489 mIncludeDescription = cfg->mDescription->isChecked();
00490 mIncludePriority = cfg->mPriority->isChecked();
00491 mIncludeDueDate = cfg->mDueDate->isChecked();
00492 mConnectSubTodos = cfg->mConnectSubTodos->isChecked();
00493 }
00494 }
00495
00496 void CalPrintTodos::setSettingsWidget()
00497 {
00498 CalPrintTodoConfig_Base *cfg =
00499 dynamic_cast<CalPrintTodoConfig_Base *>( mConfigWidget );
00500 if ( cfg ) {
00501 cfg->mTitle->setText( mPageTitle );
00502
00503 cfg->mPrintType->setButton( mTodoPrintType );
00504
00505 cfg->mFromDate->setDate( mFromDate );
00506 cfg->mToDate->setDate( mToDate );
00507
00508 cfg->mDescription->setChecked( mIncludeDescription );
00509 cfg->mPriority->setChecked( mIncludePriority );
00510 cfg->mDueDate->setChecked( mIncludeDueDate );
00511 cfg->mConnectSubTodos->setChecked( mConnectSubTodos );
00512 }
00513 }
00514
00515 void CalPrintTodos::loadConfig()
00516 {
00517 if ( mConfig ) {
00518 mPageTitle = mConfig->readEntry( "Page title", i18n("Todo list") );
00519 mTodoPrintType = (eTodoPrintType)mConfig->readNumEntry( "Print type", (int)TodosAll );
00520 mIncludeDescription = mConfig->readBoolEntry( "Include description", true );
00521 mIncludePriority = mConfig->readBoolEntry( "Include priority", true );
00522 mIncludeDueDate = mConfig->readBoolEntry( "Include due date", true );
00523 mConnectSubTodos = mConfig->readBoolEntry( "Connect subtodos", true );
00524 }
00525 setSettingsWidget();
00526 }
00527
00528 void CalPrintTodos::saveConfig()
00529 {
00530 readSettingsWidget();
00531 if ( mConfig ) {
00532 mConfig->writeEntry( "Page title", mPageTitle );
00533 mConfig->writeEntry( "Print type", int( mTodoPrintType ) );
00534 mConfig->writeEntry( "Include description", mIncludeDescription );
00535 mConfig->writeEntry( "Include priority", mIncludePriority );
00536 mConfig->writeEntry( "Include due date", mIncludeDueDate );
00537 mConfig->writeEntry( "Connect subtodos", mConnectSubTodos );
00538 }
00539 }
00540
00541 void CalPrintTodos::print( QPainter &p, int width, int height )
00542 {
00543 int pospriority = 10;
00544 int possummary = 60;
00545 int posdue = width - 85;
00546 int lineSpacing = 15;
00547 int fontHeight = 10;
00548
00549 drawHeader( p, mPageTitle, mFromDate, QDate(),
00550 0, 0, width, mHeaderHeight );
00551
00552 int mCurrentLinePos = mHeaderHeight + 5;
00553 QString outStr;
00554
00555 p.setFont( QFont( "helvetica", 10 ) );
00556 lineSpacing = p.fontMetrics().lineSpacing();
00557 mCurrentLinePos += lineSpacing;
00558
00559 p.setFont( QFont("helvetica", 10, QFont::Bold ) );
00560 if ( mIncludePriority ) {
00561 outStr += i18n("Priority");
00562 p.drawText( pospriority, mCurrentLinePos - 2, outStr);
00563 } else {
00564 possummary = 10;
00565 pospriority = -1;
00566 }
00567
00568 outStr.truncate( 0 );
00569 outStr += i18n("Summary");
00570 p.drawText( possummary, mCurrentLinePos - 2, outStr );
00571
00572 if ( mIncludeDueDate ) {
00573 outStr.truncate( 0 );
00574 outStr += i18n("Due");
00575 p.drawText( posdue, mCurrentLinePos - 2, outStr );
00576 } else {
00577 posdue = -1;
00578 }
00579
00580 p.setFont( QFont( "helvetica", 10 ) );
00581
00582 fontHeight = p.fontMetrics().height();
00583
00584 Todo::List todoList;
00585
00586
00587
00588 todoList = mCalendar->todos();
00589
00590
00591
00592 int count = 0;
00593 for( int cprior = 1; cprior <= 6; cprior++ ) {
00594 Todo::List::ConstIterator it;
00595 for( it = todoList.begin(); it != todoList.end(); ++it ) {
00596 Todo *currEvent = *it;
00597
00598
00599 if ( currEvent->relatedTo() ) {
00600 continue;
00601 }
00602
00603 QDate start = currEvent->dtStart().date();
00604
00605 if ( ( !start.isValid() ) && ( start >= mToDate ) ) {
00606 continue;
00607 }
00608
00609 int priority = currEvent->priority();
00610
00611 if ( ( priority != cprior ) ||
00612 ( ( cprior == 6 ) && ( priority == 0 ) ) ) {
00613 continue;
00614 }
00615 count++;
00616 int todoHeight = height - mCurrentLinePos;
00617 drawTodo( count, currEvent, p, mConnectSubTodos,
00618 mIncludeDescription, pospriority, possummary, posdue, 0,
00619 0, mCurrentLinePos, width, todoHeight, height );
00620 }
00621 }
00622 }
00623
00624
00625 #endif