summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagendaview.cpp3
-rw-r--r--korganizer/kotodoview.cpp29
-rw-r--r--korganizer/kotodoviewitem.cpp30
-rw-r--r--libkcal/todo.cpp6
4 files changed, 44 insertions, 24 deletions
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp
index bbc43e4..42a6f7c 100644
--- a/korganizer/koagendaview.cpp
+++ b/korganizer/koagendaview.cpp
@@ -396,1155 +396,1154 @@ KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) :
396 396
397 agendaFrame->setFocusPolicy(NoFocus); 397 agendaFrame->setFocusPolicy(NoFocus);
398#endif 398#endif
399 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this); 399 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this);
400 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 400 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
401 topLayout->addWidget( mSplitterAgenda ); 401 topLayout->addWidget( mSplitterAgenda );
402 mAllDayFrame = new QHBox(mSplitterAgenda); 402 mAllDayFrame = new QHBox(mSplitterAgenda);
403 mAllDayFrame->setFocusPolicy(NoFocus); 403 mAllDayFrame->setFocusPolicy(NoFocus);
404 QWidget *agendaFrame = new QWidget(mSplitterAgenda); 404 QWidget *agendaFrame = new QWidget(mSplitterAgenda);
405 agendaFrame->setFocusPolicy(NoFocus); 405 agendaFrame->setFocusPolicy(NoFocus);
406 406
407#endif 407#endif
408 408
409 // Create all-day agenda widget 409 // Create all-day agenda widget
410 mDummyAllDayLeft = new QVBox( mAllDayFrame ); 410 mDummyAllDayLeft = new QVBox( mAllDayFrame );
411 411
412 mExpandButton = new QPushButton(mDummyAllDayLeft); 412 mExpandButton = new QPushButton(mDummyAllDayLeft);
413 mExpandButton->setPixmap( mNotExpandedPixmap ); 413 mExpandButton->setPixmap( mNotExpandedPixmap );
414 int widebut = mExpandButton->sizeHint().width(); 414 int widebut = mExpandButton->sizeHint().width();
415 if ( QApplication::desktop()->width() < 480 ) 415 if ( QApplication::desktop()->width() < 480 )
416 widebut = widebut*2; 416 widebut = widebut*2;
417 else 417 else
418 widebut = (widebut*3) / 2; 418 widebut = (widebut*3) / 2;
419 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, 419 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed,
420 // QSizePolicy::Fixed ) ); 420 // QSizePolicy::Fixed ) );
421 mExpandButton->setFixedSize( widebut, widebut); 421 mExpandButton->setFixedSize( widebut, widebut);
422 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) ); 422 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) );
423 mExpandButton->setFocusPolicy(NoFocus); 423 mExpandButton->setFocusPolicy(NoFocus);
424 mAllDayAgenda = new KOAgenda(1,mAllDayFrame); 424 mAllDayAgenda = new KOAgenda(1,mAllDayFrame);
425 mAllDayAgenda->setFocusPolicy(NoFocus); 425 mAllDayAgenda->setFocusPolicy(NoFocus);
426 QWidget *dummyAllDayRight = new QWidget(mAllDayFrame); 426 QWidget *dummyAllDayRight = new QWidget(mAllDayFrame);
427 427
428 // Create event context menu for all day agenda 428 // Create event context menu for all day agenda
429 mAllDayAgendaPopup = eventPopup(); 429 mAllDayAgendaPopup = eventPopup();
430 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 430 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
431 mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 431 mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
432 432
433 // Create agenda frame 433 // Create agenda frame
434 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,3,3); 434 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,3,3);
435 // QHBox *agendaFrame = new QHBox(splitterAgenda); 435 // QHBox *agendaFrame = new QHBox(splitterAgenda);
436 436
437 // create event indicator bars 437 // create event indicator bars
438 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame); 438 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame);
439 agendaLayout->addWidget(mEventIndicatorTop,0,1); 439 agendaLayout->addWidget(mEventIndicatorTop,0,1);
440 mEventIndicatorTop->setPaintWidget( mSplitterAgenda ); 440 mEventIndicatorTop->setPaintWidget( mSplitterAgenda );
441 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom, 441 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom,
442 agendaFrame); 442 agendaFrame);
443 agendaLayout->addWidget(mEventIndicatorBottom,2,1); 443 agendaLayout->addWidget(mEventIndicatorBottom,2,1);
444 QWidget *dummyAgendaRight = new QWidget(agendaFrame); 444 QWidget *dummyAgendaRight = new QWidget(agendaFrame);
445 agendaLayout->addWidget(dummyAgendaRight,0,2); 445 agendaLayout->addWidget(dummyAgendaRight,0,2);
446 446
447 // Create time labels 447 // Create time labels
448 mTimeLabels = new TimeLabels(24,agendaFrame); 448 mTimeLabels = new TimeLabels(24,agendaFrame);
449 agendaLayout->addWidget(mTimeLabels,1,0); 449 agendaLayout->addWidget(mTimeLabels,1,0);
450 connect(mTimeLabels,SIGNAL( scaleChanged()), 450 connect(mTimeLabels,SIGNAL( scaleChanged()),
451 this,SLOT(updateConfig())); 451 this,SLOT(updateConfig()));
452 452
453 // Create agenda 453 // Create agenda
454 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame); 454 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame);
455 agendaLayout->addMultiCellWidget(mAgenda,1,1,1,2); 455 agendaLayout->addMultiCellWidget(mAgenda,1,1,1,2);
456 agendaLayout->setColStretch(1,1); 456 agendaLayout->setColStretch(1,1);
457 mAgenda->setFocusPolicy(NoFocus); 457 mAgenda->setFocusPolicy(NoFocus);
458 // Create event context menu for agenda 458 // Create event context menu for agenda
459 mAgendaPopup = eventPopup(); 459 mAgendaPopup = eventPopup();
460 460
461 mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")), 461 mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")),
462 i18n("Toggle Alarm"),mAgenda, 462 i18n("Toggle Alarm"),mAgenda,
463 SLOT(popupAlarm()),true); 463 SLOT(popupAlarm()),true);
464 464
465 465
466 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 466 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
467 mAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 467 mAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
468 468
469 // make connections between dependent widgets 469 // make connections between dependent widgets
470 mTimeLabels->setAgenda(mAgenda); 470 mTimeLabels->setAgenda(mAgenda);
471 471
472 // Update widgets to reflect user preferences 472 // Update widgets to reflect user preferences
473 // updateConfig(); 473 // updateConfig();
474 474
475 // createDayLabels(); 475 // createDayLabels();
476 476
477 // these blank widgets make the All Day Event box line up with the agenda 477 // these blank widgets make the All Day Event box line up with the agenda
478 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 478 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
479 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 479 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
480 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 480 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
481 481
482 // Scrolling 482 // Scrolling
483 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)), 483 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)),
484 mTimeLabels, SLOT(positionChanged())); 484 mTimeLabels, SLOT(positionChanged()));
485 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)), 485 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)),
486 SLOT(setContentsPos(int))); 486 SLOT(setContentsPos(int)));
487 487
488 connect(mAgenda,SIGNAL(showDateView( int, QDate )),SIGNAL(showDateView( int, QDate ))); 488 connect(mAgenda,SIGNAL(showDateView( int, QDate )),SIGNAL(showDateView( int, QDate )));
489 connect(mAllDayAgenda,SIGNAL(showDateView( int, QDate )),SIGNAL(showDateView( int, QDate ))); 489 connect(mAllDayAgenda,SIGNAL(showDateView( int, QDate )),SIGNAL(showDateView( int, QDate )));
490 490
491 // Create/Show/Edit/Delete Event 491 // Create/Show/Edit/Delete Event
492 connect(mAgenda,SIGNAL(newEventSignal(int,int)), 492 connect(mAgenda,SIGNAL(newEventSignal(int,int)),
493 SLOT(newEvent(int,int))); 493 SLOT(newEvent(int,int)));
494 connect(mAgenda,SIGNAL(newTodoSignal(int,int)), 494 connect(mAgenda,SIGNAL(newTodoSignal(int,int)),
495 SLOT(newTodo(int,int))); 495 SLOT(newTodo(int,int)));
496 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)), 496 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)),
497 SLOT(newEvent(int,int,int,int))); 497 SLOT(newEvent(int,int,int,int)));
498 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)), 498 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)),
499 SLOT(newEventAllDay(int,int))); 499 SLOT(newEventAllDay(int,int)));
500 connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)), 500 connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)),
501 SLOT(newTodoAllDay(int,int))); 501 SLOT(newTodoAllDay(int,int)));
502 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)), 502 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)),
503 SLOT(newEventAllDay(int,int))); 503 SLOT(newEventAllDay(int,int)));
504 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 504 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
505 SLOT(newTimeSpanSelected(int,int,int,int))); 505 SLOT(newTimeSpanSelected(int,int,int,int)));
506 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 506 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
507 SLOT(newTimeSpanSelectedAllDay(int,int,int,int))); 507 SLOT(newTimeSpanSelectedAllDay(int,int,int,int)));
508 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 508 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
509 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 509 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
510 510
511 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 511 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
512 SIGNAL(editIncidenceSignal(Incidence *))); 512 SIGNAL(editIncidenceSignal(Incidence *)));
513 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 513 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
514 SIGNAL(editIncidenceSignal(Incidence *))); 514 SIGNAL(editIncidenceSignal(Incidence *)));
515 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 515 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
516 SIGNAL(showIncidenceSignal(Incidence *))); 516 SIGNAL(showIncidenceSignal(Incidence *)));
517 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 517 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
518 SIGNAL(showIncidenceSignal(Incidence *))); 518 SIGNAL(showIncidenceSignal(Incidence *)));
519 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 519 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
520 SIGNAL(deleteIncidenceSignal(Incidence *))); 520 SIGNAL(deleteIncidenceSignal(Incidence *)));
521 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 521 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
522 SIGNAL(deleteIncidenceSignal(Incidence *))); 522 SIGNAL(deleteIncidenceSignal(Incidence *)));
523 523
524 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 524 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
525 SLOT(updateEventDates(KOAgendaItem *, int ))); 525 SLOT(updateEventDates(KOAgendaItem *, int )));
526 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 526 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
527 SLOT(updateEventDates(KOAgendaItem *, int))); 527 SLOT(updateEventDates(KOAgendaItem *, int)));
528 528
529 // event indicator update 529 // event indicator update
530 connect(mAgenda,SIGNAL(lowerYChanged(int)), 530 connect(mAgenda,SIGNAL(lowerYChanged(int)),
531 SLOT(updateEventIndicatorTop(int))); 531 SLOT(updateEventIndicatorTop(int)));
532 connect(mAgenda,SIGNAL(upperYChanged(int)), 532 connect(mAgenda,SIGNAL(upperYChanged(int)),
533 SLOT(updateEventIndicatorBottom(int))); 533 SLOT(updateEventIndicatorBottom(int)));
534 // drag signals 534 // drag signals
535 /* 535 /*
536 connect(mAgenda,SIGNAL(startDragSignal(Event *)), 536 connect(mAgenda,SIGNAL(startDragSignal(Event *)),
537 SLOT(startDrag(Event *))); 537 SLOT(startDrag(Event *)));
538 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)), 538 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)),
539 SLOT(startDrag(Event *))); 539 SLOT(startDrag(Event *)));
540 */ 540 */
541 // synchronize selections 541 // synchronize selections
542 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 542 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
543 mAllDayAgenda, SLOT( deselectItem() ) ); 543 mAllDayAgenda, SLOT( deselectItem() ) );
544 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 544 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
545 mAgenda, SLOT( deselectItem() ) ); 545 mAgenda, SLOT( deselectItem() ) );
546 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 546 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
547 SIGNAL( incidenceSelected( Incidence * ) ) ); 547 SIGNAL( incidenceSelected( Incidence * ) ) );
548 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 548 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
549 SIGNAL( incidenceSelected( Incidence * ) ) ); 549 SIGNAL( incidenceSelected( Incidence * ) ) );
550 connect( mAgenda, SIGNAL( resizedSignal() ), 550 connect( mAgenda, SIGNAL( resizedSignal() ),
551 SLOT( updateConfig( ) ) ); 551 SLOT( updateConfig( ) ) );
552 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ), 552 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ),
553 SLOT( addToCalSlot(Incidence *, Incidence * ) ) ); 553 SLOT( addToCalSlot(Incidence *, Incidence * ) ) );
554 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ), 554 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ),
555 SLOT( addToCalSlot(Incidence * , Incidence *) ) ); 555 SLOT( addToCalSlot(Incidence * , Incidence *) ) );
556 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 556 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
557 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 557 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
558 558
559 559
560} 560}
561 561
562void KOAgendaView::toggleAllDay() 562void KOAgendaView::toggleAllDay()
563{ 563{
564 if ( mSplitterAgenda->firstHandle() ) 564 if ( mSplitterAgenda->firstHandle() )
565 mSplitterAgenda->firstHandle()->toggle(); 565 mSplitterAgenda->firstHandle()->toggle();
566} 566}
567void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld ) 567void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld )
568{ 568{
569 calendar()->addIncidence( inc ); 569 calendar()->addIncidence( inc );
570 570
571 if ( incOld ) { 571 if ( incOld ) {
572 if ( incOld->type() == "Todo" ) 572 if ( incOld->type() == "Todo" )
573 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED ); 573 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED );
574 else 574 else
575 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED); 575 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED);
576 } 576 }
577 577
578} 578}
579 579
580KOAgendaView::~KOAgendaView() 580KOAgendaView::~KOAgendaView()
581{ 581{
582 delete mAgendaPopup; 582 delete mAgendaPopup;
583 delete mAllDayAgendaPopup; 583 delete mAllDayAgendaPopup;
584 delete KOAgendaItem::paintPix(); 584 delete KOAgendaItem::paintPix();
585 delete KOAgendaItem::paintPixSel(); 585 delete KOAgendaItem::paintPixSel();
586} 586}
587void KOAgendaView::resizeEvent( QResizeEvent* e ) 587void KOAgendaView::resizeEvent( QResizeEvent* e )
588{ 588{
589 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); 589 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width());
590 bool uc = false; 590 bool uc = false;
591 int ow = e->oldSize().width(); 591 int ow = e->oldSize().width();
592 int oh = e->oldSize().height(); 592 int oh = e->oldSize().height();
593 int w = e->size().width(); 593 int w = e->size().width();
594 int h = e->size().height(); 594 int h = e->size().height();
595 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { 595 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) {
596 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) 596 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda )
597 uc = true; 597 uc = true;
598 //qDebug("view changed %d %d %d %d ", ow, oh , w , h); 598 //qDebug("view changed %d %d %d %d ", ow, oh , w , h);
599 } 599 }
600 mUpcomingWidth = e->size().width() ; 600 mUpcomingWidth = e->size().width() ;
601 if ( mBlockUpdating || uc ) { 601 if ( mBlockUpdating || uc ) {
602 mBlockUpdating = false; 602 mBlockUpdating = false;
603 //mAgenda->setMinimumSize(800 , 600 ); 603 //mAgenda->setMinimumSize(800 , 600 );
604 //qDebug("mAgenda->resize+++++++++++++++ "); 604 //qDebug("mAgenda->resize+++++++++++++++ ");
605 updateConfig(); 605 updateConfig();
606 //qDebug("KOAgendaView::Updating now possible "); 606 //qDebug("KOAgendaView::Updating now possible ");
607 } else 607 } else
608 createDayLabels(); 608 createDayLabels();
609 //qDebug("resizeEvent end "); 609 //qDebug("resizeEvent end ");
610 610
611} 611}
612void KOAgendaView::createDayLabels() 612void KOAgendaView::createDayLabels()
613{ 613{
614 614
615 if ( mBlockUpdating || globalFlagBlockLabel == 1) { 615 if ( mBlockUpdating || globalFlagBlockLabel == 1) {
616 // qDebug(" KOAgendaView::createDayLabels() blocked "); 616 // qDebug(" KOAgendaView::createDayLabels() blocked ");
617 return; 617 return;
618 618
619 } 619 }
620 int newHight; 620 int newHight;
621 621
622 // ### Before deleting and recreating we could check if mSelectedDates changed... 622 // ### Before deleting and recreating we could check if mSelectedDates changed...
623 // It would remove some flickering and gain speed (since this is called by 623 // It would remove some flickering and gain speed (since this is called by
624 // each updateView() call) 624 // each updateView() call)
625 625
626 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - 2; 626 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - 2;
627 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); 627 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth );
628 if ( maxWid < 0 ) 628 if ( maxWid < 0 )
629 maxWid = 20; 629 maxWid = 20;
630 630
631 QFont dlf = KOPrefs::instance()->mTimeLabelsFont; 631 QFont dlf = KOPrefs::instance()->mTimeLabelsFont;
632 QFontMetrics fm ( dlf ); 632 QFontMetrics fm ( dlf );
633 int selCount = mSelectedDates.count(); 633 int selCount = mSelectedDates.count();
634 QString dayTest = "Mon 20"; 634 QString dayTest = "Mon 20";
635 int wid = fm.width( dayTest ); 635 int wid = fm.width( dayTest );
636 maxWid -= ( selCount * 3 ); 636 maxWid -= ( selCount * 3 );
637 if ( maxWid < 0 ) 637 if ( maxWid < 0 )
638 maxWid = 20; 638 maxWid = 20;
639 int needWid = wid * selCount; 639 int needWid = wid * selCount;
640 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); 640 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid );
641 //if ( needWid > maxWid ) 641 //if ( needWid > maxWid )
642 // qDebug("DAYLABELS TOOOOOOO BIG "); 642 // qDebug("DAYLABELS TOOOOOOO BIG ");
643 while ( needWid > maxWid ) { 643 while ( needWid > maxWid ) {
644 dayTest = dayTest.left( dayTest.length() - 1 ); 644 dayTest = dayTest.left( dayTest.length() - 1 );
645 wid = fm.width( dayTest ); 645 wid = fm.width( dayTest );
646 needWid = wid * selCount; 646 needWid = wid * selCount;
647 } 647 }
648 int maxLen = dayTest.length(); 648 int maxLen = dayTest.length();
649 int fontPoint = dlf.pointSize(); 649 int fontPoint = dlf.pointSize();
650 if ( maxLen < 2 ) { 650 if ( maxLen < 2 ) {
651 int fontPoint = dlf.pointSize(); 651 int fontPoint = dlf.pointSize();
652 while ( fontPoint > 4 ) { 652 while ( fontPoint > 4 ) {
653 --fontPoint; 653 --fontPoint;
654 dlf.setPointSize( fontPoint ); 654 dlf.setPointSize( fontPoint );
655 QFontMetrics f( dlf ); 655 QFontMetrics f( dlf );
656 wid = f.width( "20" ); 656 wid = f.width( "20" );
657 needWid = wid * selCount; 657 needWid = wid * selCount;
658 if ( needWid < maxWid ) 658 if ( needWid < maxWid )
659 break; 659 break;
660 } 660 }
661 maxLen = 2; 661 maxLen = 2;
662 } 662 }
663 //qDebug("Max len %d ", dayTest.length() ); 663 //qDebug("Max len %d ", dayTest.length() );
664 664
665 QFontMetrics tempF( dlf ); 665 QFontMetrics tempF( dlf );
666 newHight = tempF.height(); 666 newHight = tempF.height();
667 mDayLabels->setFont( dlf ); 667 mDayLabels->setFont( dlf );
668 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; 668 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);;
669 // mLayoutDayLabels->addSpacing(mTimeLabels->width()); 669 // mLayoutDayLabels->addSpacing(mTimeLabels->width());
670 //mLayoutDayLabels->addSpacing( 2 ); 670 //mLayoutDayLabels->addSpacing( 2 );
671 // QFont lFont = dlf; 671 // QFont lFont = dlf;
672 bool appendLabels = false; 672 bool appendLabels = false;
673 QLabel *dayLabel; 673 QLabel *dayLabel;
674 dayLabel = mDayLabelsList.first(); 674 dayLabel = mDayLabelsList.first();
675 if ( !dayLabel ) { 675 if ( !dayLabel ) {
676 appendLabels = true; 676 appendLabels = true;
677 dayLabel = new QLabel(mDayLabels); 677 dayLabel = new QLabel(mDayLabels);
678 mDayLabelsList.append( dayLabel ); 678 mDayLabelsList.append( dayLabel );
679 mLayoutDayLabels->addWidget(dayLabel); 679 mLayoutDayLabels->addWidget(dayLabel);
680 } 680 }
681 dayLabel->setFixedWidth( mTimeLabels->width()+2 ); 681 dayLabel->setFixedWidth( mTimeLabels->width()+2 );
682 dayLabel->setFont( dlf ); 682 dayLabel->setFont( dlf );
683 dayLabel->setAlignment(QLabel::AlignHCenter); 683 dayLabel->setAlignment(QLabel::AlignHCenter);
684 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); 684 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) );
685 dayLabel->show(); 685 dayLabel->show();
686 DateList::ConstIterator dit; 686 DateList::ConstIterator dit;
687 bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); 687 bool oneday = (mSelectedDates.first() == mSelectedDates.last() );
688 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 688 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
689 QDate date = *dit; 689 QDate date = *dit;
690 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); 690 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels);
691 if ( ! appendLabels ) { 691 if ( ! appendLabels ) {
692 dayLabel = mDayLabelsList.next(); 692 dayLabel = mDayLabelsList.next();
693 if ( !dayLabel ) 693 if ( !dayLabel )
694 appendLabels = true; 694 appendLabels = true;
695 } 695 }
696 if ( appendLabels ) { 696 if ( appendLabels ) {
697 dayLabel = new QLabel(mDayLabels); 697 dayLabel = new QLabel(mDayLabels);
698 mDayLabelsList.append( dayLabel ); 698 mDayLabelsList.append( dayLabel );
699 mLayoutDayLabels->addWidget(dayLabel); 699 mLayoutDayLabels->addWidget(dayLabel);
700 } 700 }
701 dayLabel->setMinimumWidth( 1 ); 701 dayLabel->setMinimumWidth( 1 );
702 dayLabel->setMaximumWidth( 2048 ); 702 dayLabel->setMaximumWidth( 2048 );
703 dayLabel->setFont( dlf ); 703 dayLabel->setFont( dlf );
704 dayLabel->show(); 704 dayLabel->show();
705 QString str; 705 QString str;
706 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date); 706 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date);
707 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true ); 707 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true );
708 switch ( maxLen ) { 708 switch ( maxLen ) {
709 case 2: 709 case 2:
710 str = QString::number( date.day() ); 710 str = QString::number( date.day() );
711 break; 711 break;
712 712
713 case 3: 713 case 3:
714 str = dayName.left( 1 ) +QString::number( date.day()); 714 str = dayName.left( 1 ) +QString::number( date.day());
715 715
716 break; 716 break;
717 case 4: 717 case 4:
718 str = dayName.left( 1 ) + " " +QString::number( date.day()); 718 str = dayName.left( 1 ) + " " +QString::number( date.day());
719 719
720 break; 720 break;
721 case 5: 721 case 5:
722 str = dayName.left( 2 ) + " " +QString::number( date.day()); 722 str = dayName.left( 2 ) + " " +QString::number( date.day());
723 723
724 break; 724 break;
725 case 6: 725 case 6:
726 str = dayName.left( 3 ) + " " +QString::number( date.day()); 726 str = dayName.left( 3 ) + " " +QString::number( date.day());
727 break; 727 break;
728 728
729 default: 729 default:
730 break; 730 break;
731 } 731 }
732 if ( oneday ) { 732 if ( oneday ) {
733 QString addString; 733 QString addString;
734 if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) 734 if ( mSelectedDates.first() == QDateTime::currentDateTime().date() )
735 addString = i18n("Today"); 735 addString = i18n("Today");
736 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) 736 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) )
737 addString = i18n("Tomorrow"); 737 addString = i18n("Tomorrow");
738 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) 738 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) )
739 addString = i18n("Yesterday"); 739 addString = i18n("Yesterday");
740 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) 740 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) )
741 addString = i18n("Day before yesterday"); 741 addString = i18n("Day before yesterday");
742 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) 742 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) )
743 addString = i18n("Day after tomorrow"); 743 addString = i18n("Day after tomorrow");
744 if ( !addString.isEmpty() ) { 744 if ( !addString.isEmpty() ) {
745 str = addString+", " + str; 745 str = addString+", " + str;
746 } 746 }
747 } 747 }
748 dayLabel->setText(str); 748 dayLabel->setText(str);
749 dayLabel->setAlignment(QLabel::AlignHCenter); 749 dayLabel->setAlignment(QLabel::AlignHCenter);
750 if (date == QDate::currentDate()) { 750 if (date == QDate::currentDate()) {
751 QFont bFont = dlf; 751 QFont bFont = dlf;
752 bFont.setBold( true ); 752 bFont.setBold( true );
753 dayLabel->setFont(bFont); 753 dayLabel->setFont(bFont);
754 } 754 }
755 //dayLayout->addWidget(dayLabel); 755 //dayLayout->addWidget(dayLabel);
756 756
757#ifndef KORG_NOPLUGINS 757#ifndef KORG_NOPLUGINS
758 CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); 758 CalendarDecoration::List cds = KOCore::self()->calendarDecorations();
759 CalendarDecoration *it; 759 CalendarDecoration *it;
760 for(it = cds.first(); it; it = cds.next()) { 760 for(it = cds.first(); it; it = cds.next()) {
761 QString text = it->shortText( date ); 761 QString text = it->shortText( date );
762 if ( !text.isEmpty() ) { 762 if ( !text.isEmpty() ) {
763 QLabel *label = new QLabel(text,mDayLabels); 763 QLabel *label = new QLabel(text,mDayLabels);
764 label->setAlignment(AlignCenter); 764 label->setAlignment(AlignCenter);
765 dayLayout->addWidget(label); 765 dayLayout->addWidget(label);
766 } 766 }
767 } 767 }
768 768
769 for(it = cds.first(); it; it = cds.next()) { 769 for(it = cds.first(); it; it = cds.next()) {
770 QWidget *wid = it->smallWidget(mDayLabels,date); 770 QWidget *wid = it->smallWidget(mDayLabels,date);
771 if ( wid ) { 771 if ( wid ) {
772 // wid->setHeight(20); 772 // wid->setHeight(20);
773 dayLayout->addWidget(wid); 773 dayLayout->addWidget(wid);
774 } 774 }
775 } 775 }
776#endif 776#endif
777 } 777 }
778 if ( ! appendLabels ) { 778 if ( ! appendLabels ) {
779 dayLabel = mDayLabelsList.next(); 779 dayLabel = mDayLabelsList.next();
780 if ( !dayLabel ) 780 if ( !dayLabel )
781 appendLabels = true; 781 appendLabels = true;
782 } 782 }
783 if ( appendLabels ) { 783 if ( appendLabels ) {
784 dayLabel = new QLabel(mDayLabels); 784 dayLabel = new QLabel(mDayLabels);
785 mDayLabelsList.append( dayLabel ); 785 mDayLabelsList.append( dayLabel );
786 mLayoutDayLabels->addWidget(dayLabel); 786 mLayoutDayLabels->addWidget(dayLabel);
787 } 787 }
788 //dayLabel->hide();//test only 788 //dayLabel->hide();//test only
789 789
790 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()-3 ) % mSelectedDates.count() ; 790 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()-3 ) % mSelectedDates.count() ;
791 if ( offset < 0 ) offset = 0; 791 if ( offset < 0 ) offset = 0;
792 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 ); 792 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 );
793 dayLabel->setText("");//QString::number ( mSelectedDates.first().month() ) ); 793 dayLabel->setText("");//QString::number ( mSelectedDates.first().month() ) );
794 dayLabel->show(); 794 dayLabel->show();
795 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset ); 795 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset );
796 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2); 796 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2);
797 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); 797 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2);
798 if ( !appendLabels ) { 798 if ( !appendLabels ) {
799 dayLabel = mDayLabelsList.next(); 799 dayLabel = mDayLabelsList.next();
800 while ( dayLabel ) { 800 while ( dayLabel ) {
801 //qDebug("!dayLabel %d",dayLabel ); 801 //qDebug("!dayLabel %d",dayLabel );
802 dayLabel->hide(); 802 dayLabel->hide();
803 dayLabel = mDayLabelsList.next(); 803 dayLabel = mDayLabelsList.next();
804 } 804 }
805 } 805 }
806 //mDayLabelsFrame->show(); 806 //mDayLabelsFrame->show();
807 //mDayLabels->show(); 807 //mDayLabels->show();
808 //qDebug("heigt %d %d %d ",mDayLabelsFrame->height(), mDayLabelsFrame->sizeHint().height(), newHight); 808 //qDebug("heigt %d %d %d ",mDayLabelsFrame->height(), mDayLabelsFrame->sizeHint().height(), newHight);
809 //mDayLabelsFrame->resize( mAgenda->visibleWidth(), newHight ); 809 //mDayLabelsFrame->resize( mAgenda->visibleWidth(), newHight );
810 mDayLabelsFrame->setFixedHeight( newHight ); 810 mDayLabelsFrame->setFixedHeight( newHight );
811} 811}
812 812
813int KOAgendaView::maxDatesHint() 813int KOAgendaView::maxDatesHint()
814{ 814{
815 // Not sure about the max number of events, so return 0 for now. 815 // Not sure about the max number of events, so return 0 for now.
816 return 0; 816 return 0;
817} 817}
818 818
819int KOAgendaView::currentDateCount() 819int KOAgendaView::currentDateCount()
820{ 820{
821 return mSelectedDates.count(); 821 return mSelectedDates.count();
822} 822}
823 823
824QPtrList<Incidence> KOAgendaView::selectedIncidences() 824QPtrList<Incidence> KOAgendaView::selectedIncidences()
825{ 825{
826 QPtrList<Incidence> selected; 826 QPtrList<Incidence> selected;
827 Incidence *incidence; 827 Incidence *incidence;
828 828
829 incidence = mAgenda->selectedIncidence(); 829 incidence = mAgenda->selectedIncidence();
830 if (incidence) selected.append(incidence); 830 if (incidence) selected.append(incidence);
831 831
832 incidence = mAllDayAgenda->selectedIncidence(); 832 incidence = mAllDayAgenda->selectedIncidence();
833 if (incidence) selected.append(incidence); 833 if (incidence) selected.append(incidence);
834 834
835 return selected; 835 return selected;
836} 836}
837 837
838DateList KOAgendaView::selectedDates() 838DateList KOAgendaView::selectedDates()
839{ 839{
840 DateList selected; 840 DateList selected;
841 QDate qd; 841 QDate qd;
842 842
843 qd = mAgenda->selectedIncidenceDate(); 843 qd = mAgenda->selectedIncidenceDate();
844 if (qd.isValid()) selected.append(qd); 844 if (qd.isValid()) selected.append(qd);
845 845
846 qd = mAllDayAgenda->selectedIncidenceDate(); 846 qd = mAllDayAgenda->selectedIncidenceDate();
847 if (qd.isValid()) selected.append(qd); 847 if (qd.isValid()) selected.append(qd);
848 848
849 return selected; 849 return selected;
850} 850}
851 851
852 852
853void KOAgendaView::updateView() 853void KOAgendaView::updateView()
854{ 854{
855 if ( mBlockUpdating ) 855 if ( mBlockUpdating )
856 return; 856 return;
857 // kdDebug() << "KOAgendaView::updateView()" << endl; 857 // kdDebug() << "KOAgendaView::updateView()" << endl;
858 fillAgenda(); 858 fillAgenda();
859 859
860} 860}
861 861
862 862
863/* 863/*
864 Update configuration settings for the agenda view. This method is not 864 Update configuration settings for the agenda view. This method is not
865 complete. 865 complete.
866*/ 866*/
867void KOAgendaView::updateConfig() 867void KOAgendaView::updateConfig()
868{ 868{
869 if ( mBlockUpdating ) 869 if ( mBlockUpdating )
870 return; 870 return;
871 // kdDebug() << "KOAgendaView::updateConfig()" << endl; 871 // kdDebug() << "KOAgendaView::updateConfig()" << endl;
872 872
873 // update config for children 873 // update config for children
874 mTimeLabels->updateConfig(); 874 mTimeLabels->updateConfig();
875 mAgenda->storePosition(); 875 mAgenda->storePosition();
876 mAgenda->updateConfig(); 876 mAgenda->updateConfig();
877 mAllDayAgenda->updateConfig(); 877 mAllDayAgenda->updateConfig();
878 // widget synchronization 878 // widget synchronization
879 //TODO: find a better way, maybe signal/slot 879 //TODO: find a better way, maybe signal/slot
880 mTimeLabels->positionChanged(); 880 mTimeLabels->positionChanged();
881 881
882 // for some reason, this needs to be called explicitly 882 // for some reason, this needs to be called explicitly
883 mTimeLabels->repaint(); 883 mTimeLabels->repaint();
884 884
885 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 885 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
886 886
887 // ToolTips displaying summary of events 887 // ToolTips displaying summary of events
888 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance() 888 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance()
889 ->mEnableToolTips); 889 ->mEnableToolTips);
890 890
891 //setHolidayMasks(); 891 //setHolidayMasks();
892 892
893 //createDayLabels(); called by via updateView(); 893 //createDayLabels(); called by via updateView();
894 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth()); 894 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth());
895 updateView(); 895 updateView();
896 mAgenda->restorePosition(); 896 mAgenda->restorePosition();
897} 897}
898 898
899 899
900void KOAgendaView::updateEventDates(KOAgendaItem *item, int type) 900void KOAgendaView::updateEventDates(KOAgendaItem *item, int type)
901{ 901{
902 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl; 902 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl;
903 //qDebug("KOAgendaView::updateEventDates "); 903 //qDebug("KOAgendaView::updateEventDates ");
904 QDateTime startDt,endDt; 904 QDateTime startDt,endDt;
905 QDate startDate; 905 QDate startDate;
906 int lenInSecs; 906 int lenInSecs;
907 // if ( type == KOAgenda::RESIZETOP ) 907 // if ( type == KOAgenda::RESIZETOP )
908 // qDebug("RESIZETOP "); 908 // qDebug("RESIZETOP ");
909 // if ( type == KOAgenda::RESIZEBOTTOM ) 909 // if ( type == KOAgenda::RESIZEBOTTOM )
910 // qDebug("RESIZEBOTTOM "); 910 // qDebug("RESIZEBOTTOM ");
911 // if ( type == KOAgenda::MOVE ) 911 // if ( type == KOAgenda::MOVE )
912 // qDebug("MOVE "); 912 // qDebug("MOVE ");
913 if ( item->incidence()->type() == "Event" ) { 913 if ( item->incidence()->type() == "Event" ) {
914 startDt =item->incidence()->dtStart(); 914 startDt =item->incidence()->dtStart();
915 endDt = item->incidence()->dtEnd(); 915 endDt = item->incidence()->dtEnd();
916 lenInSecs = startDt.secsTo( endDt ); 916 lenInSecs = startDt.secsTo( endDt );
917 } 917 }
918 918
919 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED ); 919 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED );
920 920
921 if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) { 921 if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) {
922 startDate = mSelectedDates[item->mLastMoveXPos]; 922 startDate = mSelectedDates[item->mLastMoveXPos];
923 } else { 923 } else {
924 if (item->cellX() < 0) { 924 if (item->cellX() < 0) {
925 startDate = (mSelectedDates.first()).addDays(item->cellX()); 925 startDate = (mSelectedDates.first()).addDays(item->cellX());
926 } else { 926 } else {
927 startDate = mSelectedDates[item->cellX()]; 927 startDate = mSelectedDates[item->cellX()];
928 } 928 }
929 } 929 }
930 startDt.setDate(startDate); 930 startDt.setDate(startDate);
931 931
932 if (item->incidence()->doesFloat()) { 932 if (item->incidence()->doesFloat()) {
933 endDt.setDate(startDate.addDays(item->cellWidth() - 1)); 933 endDt.setDate(startDate.addDays(item->cellWidth() - 1));
934 } else { 934 } else {
935 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE ) 935 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE )
936 startDt.setTime(mAgenda->gyToTime(item->cellYTop())); 936 startDt.setTime(mAgenda->gyToTime(item->cellYTop()));
937 if ( item->incidence()->type() == "Event" ) { 937 if ( item->incidence()->type() == "Event" ) {
938 if ( type == KOAgenda::MOVE ) { 938 if ( type == KOAgenda::MOVE ) {
939 endDt = startDt.addSecs(lenInSecs); 939 endDt = startDt.addSecs(lenInSecs);
940 940
941 } else if ( type == KOAgenda::RESIZEBOTTOM ) { 941 } else if ( type == KOAgenda::RESIZEBOTTOM ) {
942 if (item->lastMultiItem()) { 942 if (item->lastMultiItem()) {
943 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 943 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
944 endDt.setDate(startDate. 944 endDt.setDate(startDate.
945 addDays(item->lastMultiItem()->cellX() - item->cellX())); 945 addDays(item->lastMultiItem()->cellX() - item->cellX()));
946 } else { 946 } else {
947 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 947 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
948 endDt.setDate(startDate); 948 endDt.setDate(startDate);
949 } 949 }
950 } 950 }
951 } else { 951 } else {
952 // todo 952 // todo
953 qDebug("tooooodoooooo "); 953 qDebug("tooooodoooooo ");
954 if (item->lastMultiItem()) { 954 if (item->lastMultiItem()) {
955 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 955 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
956 endDt.setDate(startDate. 956 endDt.setDate(startDate.
957 addDays(item->lastMultiItem()->cellX() - item->cellX())); 957 addDays(item->lastMultiItem()->cellX() - item->cellX()));
958 } else { 958 } else {
959 //qDebug("tem->cellYBottom() %d",item->cellYBottom() ); 959 //qDebug("tem->cellYBottom() %d",item->cellYBottom() );
960 if ( item->cellYBottom() > 0 ) 960 if ( item->cellYBottom() > 0 )
961 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 961 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
962 else 962 else
963 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time()); 963 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time());
964 endDt.setDate(startDate); 964 endDt.setDate(startDate);
965 } 965 }
966 } 966 }
967 } 967 }
968 968
969 qDebug("to888"); 969 qDebug("to888");
970 if ( item->incidence()->type() == "Event" ) { 970 if ( item->incidence()->type() == "Event" ) {
971 item->incidence()->setDtStart(startDt); 971 item->incidence()->setDtStart(startDt);
972 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt); 972 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt);
973 } else if ( item->incidence()->type() == "Todo" ) { 973 } else if ( item->incidence()->type() == "Todo" ) {
974 (static_cast<Todo*>(item->incidence()))->setDtDue(endDt); 974 (static_cast<Todo*>(item->incidence()))->setDtDue(endDt);
975 } 975 }
976 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() ); 976 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() );
977 item->incidence()->setRevision(item->incidence()->revision()+1); 977 item->incidence()->setRevision(item->incidence()->revision()+1);
978 item->setItemDate(startDt.date()); 978 item->setItemDate(startDt.date());
979 //item->updateItem(); 979 //item->updateItem();
980 if ( item->incidence()->type() == "Todo" ) { 980 if ( item->incidence()->type() == "Todo" ) {
981 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED ); 981 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED );
982 982
983 } 983 }
984 else 984 else
985 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED); 985 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED);
986 item->updateItem(); 986 item->updateItem();
987} 987}
988 988
989void KOAgendaView::showDates( const QDate &start, const QDate &end ) 989void KOAgendaView::showDates( const QDate &start, const QDate &end )
990{ 990{
991 // kdDebug() << "KOAgendaView::selectDates" << endl; 991 // kdDebug() << "KOAgendaView::selectDates" << endl;
992 992
993 mSelectedDates.clear(); 993 mSelectedDates.clear();
994 // qDebug("KOAgendaView::showDates "); 994 // qDebug("KOAgendaView::showDates ");
995 QDate d = start; 995 QDate d = start;
996 while (d <= end) { 996 while (d <= end) {
997 mSelectedDates.append(d); 997 mSelectedDates.append(d);
998 d = d.addDays( 1 ); 998 d = d.addDays( 1 );
999 } 999 }
1000 1000
1001 // and update the view 1001 // and update the view
1002 fillAgenda(); 1002 fillAgenda();
1003} 1003}
1004 1004
1005 1005
1006void KOAgendaView::showEvents(QPtrList<Event>) 1006void KOAgendaView::showEvents(QPtrList<Event>)
1007{ 1007{
1008 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl; 1008 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl;
1009} 1009}
1010 1010
1011void KOAgendaView::changeEventDisplay(Event *, int) 1011void KOAgendaView::changeEventDisplay(Event *, int)
1012{ 1012{
1013 // qDebug("KOAgendaView::changeEventDisplay "); 1013 // qDebug("KOAgendaView::changeEventDisplay ");
1014 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl; 1014 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl;
1015 // this should be re-written to be MUCH smarter. Right now we 1015 // this should be re-written to be MUCH smarter. Right now we
1016 // are just playing dumb. 1016 // are just playing dumb.
1017 fillAgenda(); 1017 fillAgenda();
1018} 1018}
1019 1019
1020void KOAgendaView::fillAgenda(const QDate &) 1020void KOAgendaView::fillAgenda(const QDate &)
1021{ 1021{
1022 // qDebug("KOAgendaView::fillAgenda "); 1022 // qDebug("KOAgendaView::fillAgenda ");
1023 fillAgenda(); 1023 fillAgenda();
1024} 1024}
1025 1025
1026void KOAgendaView::fillAgenda() 1026void KOAgendaView::fillAgenda()
1027{ 1027{
1028 if ( globalFlagBlockStartup ) 1028 if ( globalFlagBlockStartup )
1029 return; 1029 return;
1030 if ( globalFlagBlockAgenda == 1 ) 1030 if ( globalFlagBlockAgenda == 1 )
1031 return; 1031 return;
1032 //if ( globalFlagBlockAgenda == 2 ) 1032 //if ( globalFlagBlockAgenda == 2 )
1033 //globalFlagBlockAgenda = 0; 1033 //globalFlagBlockAgenda = 0;
1034 // globalFlagBlockPainting = false; 1034 // globalFlagBlockPainting = false;
1035 if ( globalFlagBlockAgenda == 0 ) 1035 if ( globalFlagBlockAgenda == 0 )
1036 globalFlagBlockAgenda = 1; 1036 globalFlagBlockAgenda = 1;
1037 // clearView(); 1037 // clearView();
1038 //qDebug("fillAgenda()++++ "); 1038 //qDebug("fillAgenda()++++ ");
1039 globalFlagBlockAgendaItemPaint = 1; 1039 globalFlagBlockAgendaItemPaint = 1;
1040 mAllDayAgenda->changeColumns(mSelectedDates.count()); 1040 mAllDayAgenda->changeColumns(mSelectedDates.count());
1041 mAgenda->changeColumns(mSelectedDates.count()); 1041 mAgenda->changeColumns(mSelectedDates.count());
1042 qApp->processEvents(); 1042 qApp->processEvents();
1043 mEventIndicatorTop->changeColumns(mSelectedDates.count()); 1043 mEventIndicatorTop->changeColumns(mSelectedDates.count());
1044 mEventIndicatorBottom->changeColumns(mSelectedDates.count()); 1044 mEventIndicatorBottom->changeColumns(mSelectedDates.count());
1045 setHolidayMasks(); 1045 setHolidayMasks();
1046 1046
1047 //mAgenda->hideUnused(); 1047 //mAgenda->hideUnused();
1048 //mAllDayAgenda->hideUnused(); 1048 //mAllDayAgenda->hideUnused();
1049 1049
1050 // mAgenda->blockNextRepaint( false ); 1050 // mAgenda->blockNextRepaint( false );
1051 // mAgenda->viewport()->repaint(); 1051 // mAgenda->viewport()->repaint();
1052 // mAgenda->blockNextRepaint( true ); 1052 // mAgenda->blockNextRepaint( true );
1053 mMinY.resize(mSelectedDates.count()); 1053 mMinY.resize(mSelectedDates.count());
1054 mMaxY.resize(mSelectedDates.count()); 1054 mMaxY.resize(mSelectedDates.count());
1055 1055
1056 QPtrList<Event> dayEvents; 1056 QPtrList<Event> dayEvents;
1057 1057
1058 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1058 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1059 // Therefore, gtodoset all of them. 1059 // Therefore, gtodoset all of them.
1060 QPtrList<Todo> todos = calendar()->todos(); 1060 QPtrList<Todo> todos = calendar()->todos();
1061 1061
1062 mAgenda->setDateList(mSelectedDates); 1062 mAgenda->setDateList(mSelectedDates);
1063 1063
1064 QDate today = QDate::currentDate(); 1064 QDate today = QDate::currentDate();
1065 1065
1066 DateList::ConstIterator dit; 1066 DateList::ConstIterator dit;
1067 int curCol = 0; 1067 int curCol = 0;
1068 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 1068 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
1069 QDate currentDate = *dit; 1069 QDate currentDate = *dit;
1070 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString() 1070 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString()
1071 // << endl; 1071 // << endl;
1072 1072
1073 dayEvents = calendar()->events(currentDate,true); 1073 dayEvents = calendar()->events(currentDate,true);
1074 1074
1075 // Default values, which can never be reached 1075 // Default values, which can never be reached
1076 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1; 1076 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1;
1077 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1; 1077 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1;
1078 1078
1079 unsigned int numEvent; 1079 unsigned int numEvent;
1080 for(numEvent=0;numEvent<dayEvents.count();++numEvent) { 1080 for(numEvent=0;numEvent<dayEvents.count();++numEvent) {
1081 Event *event = dayEvents.at(numEvent); 1081 Event *event = dayEvents.at(numEvent);
1082 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) 1082 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") )
1083 if ( event->uid().left(15) == QString("last-syncEvent-") ) 1083 if ( event->uid().left(15) == QString("last-syncEvent-") )
1084 continue; 1084 continue;
1085 // kdDebug() << " Event: " << event->summary() << endl; 1085 // kdDebug() << " Event: " << event->summary() << endl;
1086 1086
1087 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol; 1087 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol;
1088 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol; 1088 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol;
1089 1089
1090 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl; 1090 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl;
1091 1091
1092 if (event->doesFloat()) { 1092 if (event->doesFloat()) {
1093 if (event->recurrence()->doesRecur()) { 1093 if (event->recurrence()->doesRecur()) {
1094 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol); 1094 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol);
1095 } else { 1095 } else {
1096 if (beginX <= 0 && curCol == 0) { 1096 if (beginX <= 0 && curCol == 0) {
1097 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1097 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1098 } else if (beginX == curCol) { 1098 } else if (beginX == curCol) {
1099 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1099 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1100 } 1100 }
1101 } 1101 }
1102 } else if (event->isMultiDay()) { 1102 } else if (event->isMultiDay()) {
1103 if ( event->doesRecur () ) { 1103 if ( event->doesRecur () ) {
1104 QDate dateit = currentDate; 1104 QDate dateit = currentDate;
1105 int count = 0; 1105 int count = 0;
1106 int max = event->dtStart().daysTo( event->dtEnd() ) +2; 1106 int max = event->dtStart().daysTo( event->dtEnd() ) +2;
1107 while (! event->recursOn( dateit ) && count <= max ) { 1107 while (! event->recursOn( dateit ) && count <= max ) {
1108 ++count; 1108 ++count;
1109 dateit = dateit.addDays( -1 ); 1109 dateit = dateit.addDays( -1 );
1110 } 1110 }
1111 bool ok; 1111 bool ok;
1112 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok ); 1112 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok );
1113 if ( ok ) 1113 if ( ok )
1114 { 1114 {
1115 int secs = event->dtStart().secsTo( event->dtEnd() ); 1115 int secs = event->dtStart().secsTo( event->dtEnd() );
1116 QDateTime nextOcend =nextOcstart.addSecs( secs ); ; 1116 QDateTime nextOcend =nextOcstart.addSecs( secs ); ;
1117 beginX = currentDate.daysTo(nextOcstart.date()) + curCol; 1117 beginX = currentDate.daysTo(nextOcstart.date()) + curCol;
1118 endX = currentDate.daysTo(nextOcend.date()) + curCol; 1118 endX = currentDate.daysTo(nextOcend.date()) + curCol;
1119 1119
1120 } 1120 }
1121 } 1121 }
1122 int startY = mAgenda->timeToY(event->dtStart().time()); 1122 int startY = mAgenda->timeToY(event->dtStart().time());
1123 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1123 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1124 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol ); 1124 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol );
1125 if ((beginX <= 0 && curCol == 0) || beginX == curCol) { 1125 if ((beginX <= 0 && curCol == 0) || beginX == curCol) {
1126 //qDebug("insert!!! "); 1126 //qDebug("insert!!! ");
1127 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY); 1127 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY);
1128 } 1128 }
1129 if (beginX == curCol) { 1129 if (beginX == curCol) {
1130 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1130 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1131 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1131 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1132 } else if (endX == curCol) { 1132 } else if (endX == curCol) {
1133 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1133 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1134 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1134 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1135 } else { 1135 } else {
1136 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1136 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1137 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1137 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1138 } 1138 }
1139 } else { 1139 } else {
1140 int startY = mAgenda->timeToY(event->dtStart().time()); 1140 int startY = mAgenda->timeToY(event->dtStart().time());
1141 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1141 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1142 if (endY < startY) endY = startY; 1142 if (endY < startY) endY = startY;
1143 mAgenda->insertItem(event,currentDate,curCol,startY,endY); 1143 mAgenda->insertItem(event,currentDate,curCol,startY,endY);
1144 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1144 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1145 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1145 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1146 } 1146 }
1147 } 1147 }
1148 // ---------- [display Todos -------------- 1148 // ---------- [display Todos --------------
1149 unsigned int numTodo; 1149 unsigned int numTodo;
1150 for (numTodo = 0; numTodo < todos.count(); ++numTodo) { 1150 for (numTodo = 0; numTodo < todos.count(); ++numTodo) {
1151 Todo *todo = todos.at(numTodo); 1151 Todo *todo = todos.at(numTodo);
1152 1152
1153 if ( ! todo->hasDueDate() && !todo->hasCompletedDate()) continue; // todo shall not be displayed if it has no date 1153 if ( ! todo->hasDueDate() && !todo->hasCompletedDate()) continue; // todo shall not be displayed if it has no date
1154 1154
1155 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1155 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1156 // Already completed items can be displayed on their original due date 1156 // Already completed items can be displayed on their original due date
1157 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda 1157 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda
1158 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda; 1158 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda;
1159 bool fillIn = false; 1159 bool fillIn = false;
1160 if ( todo->hasCompletedDate() && todo->completed().date() == currentDate ) 1160 if ( todo->hasCompletedDate() && todo->completed().date() == currentDate )
1161 fillIn = true; 1161 fillIn = true;
1162 if ( ! fillIn && !todo->hasCompletedDate() ) 1162 if ( ! fillIn && !todo->hasCompletedDate() )
1163 fillIn = ((todo->dtDue().date() == currentDate) && !overdue) || ((currentDate == today) && overdue); 1163 fillIn = ((todo->dtDue().date() == currentDate) && !overdue) || ((currentDate == today) && overdue);
1164 qDebug("refill todo ");
1165 if ( fillIn ) { 1164 if ( fillIn ) {
1166 if ( (todo->doesFloat() || overdue ) && !todo->hasCompletedDate() ) { // Todo has no due-time set or is already overdue 1165 if ( (todo->doesFloat() || overdue ) && !todo->hasCompletedDate() ) { // Todo has no due-time set or is already overdue
1167 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1166 if ( KOPrefs::instance()->mShowTodoInAgenda )
1168 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol); 1167 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol);
1169 } 1168 }
1170 else { 1169 else {
1171 QDateTime dt; 1170 QDateTime dt;
1172 if ( todo->hasCompletedDate() ) 1171 if ( todo->hasCompletedDate() )
1173 dt = todo->completed(); 1172 dt = todo->completed();
1174 else 1173 else
1175 dt = todo->dtDue();; 1174 dt = todo->dtDue();;
1176 1175
1177 1176
1178 int endY = mAgenda->timeToY(dt.time()) - 1; 1177 int endY = mAgenda->timeToY(dt.time()) - 1;
1179 int hi = (18/KOPrefs::instance()->mHourSize); 1178 int hi = (18/KOPrefs::instance()->mHourSize);
1180 //qDebug("hei %d ",KOPrefs::instance()->mHourSize); 1179 //qDebug("hei %d ",KOPrefs::instance()->mHourSize);
1181 int startY = endY -hi; 1180 int startY = endY -hi;
1182 1181
1183 mAgenda->insertItem(todo,currentDate,curCol,startY,endY); 1182 mAgenda->insertItem(todo,currentDate,curCol,startY,endY);
1184 1183
1185 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1184 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1186 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1185 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1187 } 1186 }
1188 } 1187 }
1189 } 1188 }
1190 // ---------- display Todos] -------------- 1189 // ---------- display Todos] --------------
1191 1190
1192 ++curCol; 1191 ++curCol;
1193 } 1192 }
1194 mAgenda->hideUnused(); 1193 mAgenda->hideUnused();
1195 mAllDayAgenda->hideUnused(); 1194 mAllDayAgenda->hideUnused();
1196 mAgenda->checkScrollBoundaries(); 1195 mAgenda->checkScrollBoundaries();
1197 1196
1198 deleteSelectedDateTime(); 1197 deleteSelectedDateTime();
1199 1198
1200 createDayLabels(); 1199 createDayLabels();
1201 emit incidenceSelected( 0 ); 1200 emit incidenceSelected( 0 );
1202 1201
1203 if ( globalFlagBlockAgenda == 2 ) { 1202 if ( globalFlagBlockAgenda == 2 ) {
1204 if ( KOPrefs::instance()->mSetTimeToDayStartAt ) 1203 if ( KOPrefs::instance()->mSetTimeToDayStartAt )
1205 setStartHour( KOPrefs::instance()->mDayBegins ); 1204 setStartHour( KOPrefs::instance()->mDayBegins );
1206 else if ( KOPrefs::instance()->mCenterOnCurrentTime ) 1205 else if ( KOPrefs::instance()->mCenterOnCurrentTime )
1207 setStartHour( QTime::currentTime ().hour() ); 1206 setStartHour( QTime::currentTime ().hour() );
1208 // qApp->processEvents(); 1207 // qApp->processEvents();
1209 } 1208 }
1210 qApp->processEvents(); 1209 qApp->processEvents();
1211 //qDebug("qApp->processEvents(); END "); 1210 //qDebug("qApp->processEvents(); END ");
1212 globalFlagBlockAgenda = 0; 1211 globalFlagBlockAgenda = 0;
1213 1212
1214 // mAgenda->hideUnused(); 1213 // mAgenda->hideUnused();
1215 //mAllDayAgenda->hideUnused(); 1214 //mAllDayAgenda->hideUnused();
1216 mAllDayAgenda->drawContentsToPainter(); 1215 mAllDayAgenda->drawContentsToPainter();
1217 mAgenda->drawContentsToPainter(); 1216 mAgenda->drawContentsToPainter();
1218 repaintAgenda(); 1217 repaintAgenda();
1219 // mAgenda->finishUpdate(); 1218 // mAgenda->finishUpdate();
1220 //mAllDayAgenda->finishUpdate(); 1219 //mAllDayAgenda->finishUpdate();
1221 1220
1222 // repaintAgenda(); 1221 // repaintAgenda();
1223 //qApp->processEvents(); 1222 //qApp->processEvents();
1224 // globalFlagBlockAgenda = 0; 1223 // globalFlagBlockAgenda = 0;
1225} 1224}
1226void KOAgendaView::repaintAgenda() 1225void KOAgendaView::repaintAgenda()
1227{ 1226{
1228 // mAllDayAgenda->drawContentsToPainter(); 1227 // mAllDayAgenda->drawContentsToPainter();
1229// mAllDayAgenda->viewport()->repaint( false ); 1228// mAllDayAgenda->viewport()->repaint( false );
1230// mAgenda->drawContentsToPainter(); 1229// mAgenda->drawContentsToPainter();
1231// mAgenda->viewport()->repaint( false ); 1230// mAgenda->viewport()->repaint( false );
1232// qApp->processEvents(); 1231// qApp->processEvents();
1233 1232
1234 //qDebug("KOAgendaView::repaintAgenda() "); 1233 //qDebug("KOAgendaView::repaintAgenda() ");
1235 //qApp->processEvents(); 1234 //qApp->processEvents();
1236 mAgenda->viewport()->repaint( false ); 1235 mAgenda->viewport()->repaint( false );
1237 mAllDayAgenda->viewport()->repaint( false ); 1236 mAllDayAgenda->viewport()->repaint( false );
1238 mAgenda->finishUpdate(); 1237 mAgenda->finishUpdate();
1239 mAllDayAgenda->finishUpdate(); 1238 mAllDayAgenda->finishUpdate();
1240} 1239}
1241 1240
1242 1241
1243void KOAgendaView::clearView() 1242void KOAgendaView::clearView()
1244{ 1243{
1245 // kdDebug() << "ClearView" << endl; 1244 // kdDebug() << "ClearView" << endl;
1246 mAllDayAgenda->clear(); 1245 mAllDayAgenda->clear();
1247 mAgenda->clear(); 1246 mAgenda->clear();
1248} 1247}
1249 1248
1250void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1249void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1251 const QDate &td) 1250 const QDate &td)
1252{ 1251{
1253#ifndef KORG_NOPRINTER 1252#ifndef KORG_NOPRINTER
1254 if (fd == td) 1253 if (fd == td)
1255 calPrinter->preview(CalPrinter::Day, fd, td); 1254 calPrinter->preview(CalPrinter::Day, fd, td);
1256 else 1255 else
1257 calPrinter->preview(CalPrinter::Week, fd, td); 1256 calPrinter->preview(CalPrinter::Week, fd, td);
1258#endif 1257#endif
1259} 1258}
1260 1259
1261// void KOAgendaView::updateMovedTodo() 1260// void KOAgendaView::updateMovedTodo()
1262// { 1261// {
1263// // updateConfig(); 1262// // updateConfig();
1264// // emit updateTodoViews(); 1263// // emit updateTodoViews();
1265// } 1264// }
1266 1265
1267void KOAgendaView::newEvent(int gx, int gy) 1266void KOAgendaView::newEvent(int gx, int gy)
1268{ 1267{
1269 if (!mSelectedDates.count()) return; 1268 if (!mSelectedDates.count()) return;
1270 1269
1271 QDate day = mSelectedDates[gx]; 1270 QDate day = mSelectedDates[gx];
1272 1271
1273 QTime time = mAgenda->gyToTime(gy); 1272 QTime time = mAgenda->gyToTime(gy);
1274 QDateTime dt(day,time); 1273 QDateTime dt(day,time);
1275 // if ( dt < QDateTime::currentDateTime () ) 1274 // if ( dt < QDateTime::currentDateTime () )
1276 // dt = QDateTime::currentDateTime ().addSecs( 3600 ); 1275 // dt = QDateTime::currentDateTime ().addSecs( 3600 );
1277 emit newEventSignal(dt); 1276 emit newEventSignal(dt);
1278} 1277}
1279 1278
1280void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd) 1279void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd)
1281{ 1280{
1282 if (!mSelectedDates.count()) return; 1281 if (!mSelectedDates.count()) return;
1283 1282
1284 QDate dayStart = mSelectedDates[gxStart]; 1283 QDate dayStart = mSelectedDates[gxStart];
1285 QDate dayEnd = mSelectedDates[gxEnd]; 1284 QDate dayEnd = mSelectedDates[gxEnd];
1286 1285
1287 QTime timeStart = mAgenda->gyToTime(gyStart); 1286 QTime timeStart = mAgenda->gyToTime(gyStart);
1288 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1287 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1289 1288
1290 QDateTime dtStart(dayStart,timeStart); 1289 QDateTime dtStart(dayStart,timeStart);
1291 QDateTime dtEnd(dayEnd,timeEnd); 1290 QDateTime dtEnd(dayEnd,timeEnd);
1292 1291
1293 emit newEventSignal(dtStart,dtEnd); 1292 emit newEventSignal(dtStart,dtEnd);
1294} 1293}
1295 1294
1296void KOAgendaView::newEventAllDay(int gx, int ) 1295void KOAgendaView::newEventAllDay(int gx, int )
1297{ 1296{
1298 if (!mSelectedDates.count()) return; 1297 if (!mSelectedDates.count()) return;
1299 1298
1300 QDate day = mSelectedDates[gx]; 1299 QDate day = mSelectedDates[gx];
1301 1300
1302 emit newEventSignal(day); 1301 emit newEventSignal(day);
1303} 1302}
1304void KOAgendaView::newTodoAllDay(int gx, int ) 1303void KOAgendaView::newTodoAllDay(int gx, int )
1305{ 1304{
1306 if (!mSelectedDates.count()) return; 1305 if (!mSelectedDates.count()) return;
1307 1306
1308 QDateTime day (mSelectedDates[gx] ); 1307 QDateTime day (mSelectedDates[gx] );
1309 emit newTodoSignal(day, true); 1308 emit newTodoSignal(day, true);
1310} 1309}
1311void KOAgendaView::newTodo(int gx, int gy ) 1310void KOAgendaView::newTodo(int gx, int gy )
1312{ 1311{
1313 if (!mSelectedDates.count()) return; 1312 if (!mSelectedDates.count()) return;
1314 QDate dayStart = mSelectedDates[gx]; 1313 QDate dayStart = mSelectedDates[gx];
1315 QTime timeStart = mAgenda->gyToTime(gy); 1314 QTime timeStart = mAgenda->gyToTime(gy);
1316 QDateTime dt (dayStart,timeStart); 1315 QDateTime dt (dayStart,timeStart);
1317 emit newTodoSignal( dt, false ); 1316 emit newTodoSignal( dt, false );
1318} 1317}
1319 1318
1320void KOAgendaView::updateEventIndicatorTop(int newY) 1319void KOAgendaView::updateEventIndicatorTop(int newY)
1321{ 1320{
1322 uint i; 1321 uint i;
1323 for(i=0;i<mMinY.size();++i) { 1322 for(i=0;i<mMinY.size();++i) {
1324 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true); 1323 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true);
1325 else mEventIndicatorTop->enableColumn(i,false); 1324 else mEventIndicatorTop->enableColumn(i,false);
1326 } 1325 }
1327 1326
1328 mEventIndicatorTop->update(); 1327 mEventIndicatorTop->update();
1329} 1328}
1330 1329
1331void KOAgendaView::updateEventIndicatorBottom(int newY) 1330void KOAgendaView::updateEventIndicatorBottom(int newY)
1332{ 1331{
1333 uint i; 1332 uint i;
1334 for(i=0;i<mMaxY.size();++i) { 1333 for(i=0;i<mMaxY.size();++i) {
1335 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true); 1334 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true);
1336 else mEventIndicatorBottom->enableColumn(i,false); 1335 else mEventIndicatorBottom->enableColumn(i,false);
1337 } 1336 }
1338 1337
1339 mEventIndicatorBottom->update(); 1338 mEventIndicatorBottom->update();
1340} 1339}
1341 1340
1342void KOAgendaView::startDrag(Event *event) 1341void KOAgendaView::startDrag(Event *event)
1343{ 1342{
1344#ifndef KORG_NODND 1343#ifndef KORG_NODND
1345 DndFactory factory( calendar() ); 1344 DndFactory factory( calendar() );
1346 ICalDrag *vd = factory.createDrag(event,this); 1345 ICalDrag *vd = factory.createDrag(event,this);
1347 if (vd->drag()) { 1346 if (vd->drag()) {
1348 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl; 1347 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl;
1349 } 1348 }
1350#endif 1349#endif
1351} 1350}
1352 1351
1353void KOAgendaView::readSettings() 1352void KOAgendaView::readSettings()
1354{ 1353{
1355 readSettings(KOGlobals::config()); 1354 readSettings(KOGlobals::config());
1356} 1355}
1357 1356
1358void KOAgendaView::readSettings(KConfig *config) 1357void KOAgendaView::readSettings(KConfig *config)
1359{ 1358{
1360 // kdDebug() << "KOAgendaView::readSettings()" << endl; 1359 // kdDebug() << "KOAgendaView::readSettings()" << endl;
1361 1360
1362 config->setGroup("Views"); 1361 config->setGroup("Views");
1363 1362
1364 //#ifndef KORG_NOSPLITTER 1363 //#ifndef KORG_NOSPLITTER
1365 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView"); 1364 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView");
1366 if (sizes.count() == 2) { 1365 if (sizes.count() == 2) {
1367 if ( sizes[0] < 20 ) { 1366 if ( sizes[0] < 20 ) {
1368 sizes[1] = sizes[1] +20 - sizes[0]; 1367 sizes[1] = sizes[1] +20 - sizes[0];
1369 sizes[0] = 20; 1368 sizes[0] = 20;
1370 } 1369 }
1371 mSplitterAgenda->setSizes(sizes); 1370 mSplitterAgenda->setSizes(sizes);
1372 // qDebug("read %d %d ",sizes[0],sizes[1] ); 1371 // qDebug("read %d %d ",sizes[0],sizes[1] );
1373 } 1372 }
1374 //#endif 1373 //#endif
1375 1374
1376 // updateConfig(); 1375 // updateConfig();
1377} 1376}
1378 1377
1379void KOAgendaView::writeSettings(KConfig *config) 1378void KOAgendaView::writeSettings(KConfig *config)
1380{ 1379{
1381 // kdDebug() << "KOAgendaView::writeSettings()" << endl; 1380 // kdDebug() << "KOAgendaView::writeSettings()" << endl;
1382 1381
1383 config->setGroup("Views"); 1382 config->setGroup("Views");
1384 1383
1385 //#ifndef KORG_NOSPLITTER 1384 //#ifndef KORG_NOSPLITTER
1386 QValueList<int> list = mSplitterAgenda->sizes(); 1385 QValueList<int> list = mSplitterAgenda->sizes();
1387 config->writeEntry("Separator AgendaView",list); 1386 config->writeEntry("Separator AgendaView",list);
1388 //qDebug("write %d %d ", list[0],list[1] ); 1387 //qDebug("write %d %d ", list[0],list[1] );
1389 //#endif 1388 //#endif
1390} 1389}
1391 1390
1392void KOAgendaView::setHolidayMasks() 1391void KOAgendaView::setHolidayMasks()
1393{ 1392{
1394 mHolidayMask.resize(mSelectedDates.count()); 1393 mHolidayMask.resize(mSelectedDates.count());
1395 1394
1396 uint i; 1395 uint i;
1397 for(i=0;i<mSelectedDates.count();++i) { 1396 for(i=0;i<mSelectedDates.count();++i) {
1398 QDate date = mSelectedDates[i]; 1397 QDate date = mSelectedDates[i];
1399 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6); 1398 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6);
1400 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7); 1399 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7);
1401 bool showHoliday = false; 1400 bool showHoliday = false;
1402 if ( KOPrefs::instance()->mExcludeHolidays ) { 1401 if ( KOPrefs::instance()->mExcludeHolidays ) {
1403 QPtrList<Event> events = calendar()->events( date, true ); 1402 QPtrList<Event> events = calendar()->events( date, true );
1404 Event *event; 1403 Event *event;
1405 for( event = events.first(); event; event = events.next() ) { 1404 for( event = events.first(); event; event = events.next() ) {
1406 if ( event->categories().contains("Holiday") || 1405 if ( event->categories().contains("Holiday") ||
1407 event->categories().contains(i18n("Holiday"))) { 1406 event->categories().contains(i18n("Holiday"))) {
1408 showHoliday = true; 1407 showHoliday = true;
1409 break; 1408 break;
1410 } 1409 }
1411 } 1410 }
1412 1411
1413 } 1412 }
1414 1413
1415#ifndef KORG_NOPLUGINS 1414#ifndef KORG_NOPLUGINS
1416 bool showHoliday = KOPrefs::instance()->mExcludeHolidays && 1415 bool showHoliday = KOPrefs::instance()->mExcludeHolidays &&
1417 !KOCore::self()->holiday(date).isEmpty(); 1416 !KOCore::self()->holiday(date).isEmpty();
1418#endif 1417#endif
1419 bool showDay = showSaturday || showSunday || showHoliday; 1418 bool showDay = showSaturday || showSunday || showHoliday;
1420 1419
1421 if (showDay) { 1420 if (showDay) {
1422 mHolidayMask.at(i) = true; 1421 mHolidayMask.at(i) = true;
1423 } else { 1422 } else {
1424 mHolidayMask.at(i) = false; 1423 mHolidayMask.at(i) = false;
1425 } 1424 }
1426 } 1425 }
1427 1426
1428 mAgenda->setHolidayMask(&mHolidayMask); 1427 mAgenda->setHolidayMask(&mHolidayMask);
1429 mAllDayAgenda->setHolidayMask(&mHolidayMask); 1428 mAllDayAgenda->setHolidayMask(&mHolidayMask);
1430} 1429}
1431 1430
1432void KOAgendaView::setContentsPos(int y) 1431void KOAgendaView::setContentsPos(int y)
1433{ 1432{
1434 mAgenda->setContentsPos(0,y); 1433 mAgenda->setContentsPos(0,y);
1435} 1434}
1436 1435
1437void KOAgendaView::setExpandedButton( bool expanded ) 1436void KOAgendaView::setExpandedButton( bool expanded )
1438{ 1437{
1439 if ( expanded ) { 1438 if ( expanded ) {
1440 mExpandButton->setPixmap( mExpandedPixmap ); 1439 mExpandButton->setPixmap( mExpandedPixmap );
1441 } else { 1440 } else {
1442 mExpandButton->setPixmap( mNotExpandedPixmap ); 1441 mExpandButton->setPixmap( mNotExpandedPixmap );
1443 } 1442 }
1444} 1443}
1445 1444
1446void KOAgendaView::clearSelection() 1445void KOAgendaView::clearSelection()
1447{ 1446{
1448 mAgenda->deselectItem(); 1447 mAgenda->deselectItem();
1449 mAllDayAgenda->deselectItem(); 1448 mAllDayAgenda->deselectItem();
1450} 1449}
1451 1450
1452void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart, 1451void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart,
1453 int gxEnd, int gyEnd) 1452 int gxEnd, int gyEnd)
1454{ 1453{
1455 mTimeSpanInAllDay = true; 1454 mTimeSpanInAllDay = true;
1456 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd); 1455 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd);
1457} 1456}
1458 1457
1459 1458
1460 1459
1461 1460
1462void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart, 1461void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart,
1463 int gxEnd, int gyEnd) 1462 int gxEnd, int gyEnd)
1464{ 1463{
1465 if (!mSelectedDates.count()) return; 1464 if (!mSelectedDates.count()) return;
1466 1465
1467 QDate dayStart = mSelectedDates[gxStart]; 1466 QDate dayStart = mSelectedDates[gxStart];
1468 QDate dayEnd = mSelectedDates[gxEnd]; 1467 QDate dayEnd = mSelectedDates[gxEnd];
1469 1468
1470 QTime timeStart = mAgenda->gyToTime(gyStart); 1469 QTime timeStart = mAgenda->gyToTime(gyStart);
1471 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1470 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1472 1471
1473 QDateTime dtStart(dayStart,timeStart); 1472 QDateTime dtStart(dayStart,timeStart);
1474 QDateTime dtEnd(dayEnd,timeEnd); 1473 QDateTime dtEnd(dayEnd,timeEnd);
1475 1474
1476 mTimeSpanBegin = dtStart; 1475 mTimeSpanBegin = dtStart;
1477 mTimeSpanEnd = dtEnd; 1476 mTimeSpanEnd = dtEnd;
1478 1477
1479} 1478}
1480 1479
1481void KOAgendaView::deleteSelectedDateTime() 1480void KOAgendaView::deleteSelectedDateTime()
1482{ 1481{
1483 mTimeSpanBegin.setDate(QDate()); 1482 mTimeSpanBegin.setDate(QDate());
1484 mTimeSpanEnd.setDate(QDate()); 1483 mTimeSpanEnd.setDate(QDate());
1485 mTimeSpanInAllDay = false; 1484 mTimeSpanInAllDay = false;
1486} 1485}
1487 1486
1488void KOAgendaView::keyPressEvent ( QKeyEvent * e ) 1487void KOAgendaView::keyPressEvent ( QKeyEvent * e )
1489{ 1488{
1490 e->ignore(); 1489 e->ignore();
1491} 1490}
1492 1491
1493void KOAgendaView::scrollOneHourUp() 1492void KOAgendaView::scrollOneHourUp()
1494{ 1493{
1495 1494
1496 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 ); 1495 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 );
1497} 1496}
1498void KOAgendaView::scrollOneHourDown() 1497void KOAgendaView::scrollOneHourDown()
1499{ 1498{
1500 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 ); 1499 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 );
1501} 1500}
1502 1501
1503void KOAgendaView::setStartHour( int h ) 1502void KOAgendaView::setStartHour( int h )
1504{ 1503{
1505 mAgenda->setStartHour( h ); 1504 mAgenda->setStartHour( h );
1506 1505
1507} 1506}
1508 1507
1509void KOAgendaView::updateTodo( Todo * t, int ) 1508void KOAgendaView::updateTodo( Todo * t, int )
1510{ 1509{
1511 1510
1512 bool remove = false; 1511 bool remove = false;
1513 bool removeAD = false; 1512 bool removeAD = false;
1514 QDate da; 1513 QDate da;
1515 if ( t->hasCompletedDate() ) 1514 if ( t->hasCompletedDate() )
1516 da = t->completed().date(); 1515 da = t->completed().date();
1517 else 1516 else
1518 da = t->dtDue().date(); 1517 da = t->dtDue().date();
1519 if ( ! t->hasDueDate() && !t->hasCompletedDate() ) { 1518 if ( ! t->hasDueDate() && !t->hasCompletedDate() ) {
1520 remove = true; 1519 remove = true;
1521 removeAD = true; 1520 removeAD = true;
1522 } 1521 }
1523 else { 1522 else {
1524 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ; 1523 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ;
1525 if ( overdue && 1524 if ( overdue &&
1526 QDate::currentDate() >= mSelectedDates.first() && 1525 QDate::currentDate() >= mSelectedDates.first() &&
1527 QDate::currentDate() <= mSelectedDates.last()) { 1526 QDate::currentDate() <= mSelectedDates.last()) {
1528 removeAD = false; 1527 removeAD = false;
1529 remove = true; 1528 remove = true;
1530 } 1529 }
1531 else { 1530 else {
1532 1531
1533 if ( da < mSelectedDates.first() || 1532 if ( da < mSelectedDates.first() ||
1534 da > mSelectedDates.last() ) { 1533 da > mSelectedDates.last() ) {
1535 remove = true; 1534 remove = true;
1536 removeAD = true; 1535 removeAD = true;
1537 } else { 1536 } else {
1538 remove = t->doesFloat() && !t->hasCompletedDate(); 1537 remove = t->doesFloat() && !t->hasCompletedDate();
1539 removeAD = !remove; 1538 removeAD = !remove;
1540 } 1539 }
1541 } 1540 }
1542 } 1541 }
1543 int days = mSelectedDates.first().daysTo( da ); 1542 int days = mSelectedDates.first().daysTo( da );
1544 // qDebug("daysto %d ", days ); 1543 // qDebug("daysto %d ", days );
1545 mAgenda->updateTodo( t , days, remove); 1544 mAgenda->updateTodo( t , days, remove);
1546 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1545 if ( KOPrefs::instance()->mShowTodoInAgenda )
1547 mAllDayAgenda->updateTodo( t , days, removeAD); 1546 mAllDayAgenda->updateTodo( t , days, removeAD);
1548 //qDebug("KOAgendaView::updateTodo( Todo *, int ) "); 1547 //qDebug("KOAgendaView::updateTodo( Todo *, int ) ");
1549 1548
1550} 1549}
diff --git a/korganizer/kotodoview.cpp b/korganizer/kotodoview.cpp
index 14e8b5c..902f3f4 100644
--- a/korganizer/kotodoview.cpp
+++ b/korganizer/kotodoview.cpp
@@ -92,1145 +92,1154 @@ void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e)
92void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e) 92void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e)
93{ 93{
94#ifndef KORG_NODND 94#ifndef KORG_NODND
95// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl; 95// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl;
96 96
97 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 97 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
98 !QTextDrag::canDecode( e ) ) { 98 !QTextDrag::canDecode( e ) ) {
99 e->ignore(); 99 e->ignore();
100 return; 100 return;
101 } 101 }
102 102
103 e->accept(); 103 e->accept();
104#endif 104#endif
105} 105}
106 106
107void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *) 107void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *)
108{ 108{
109#ifndef KORG_NODND 109#ifndef KORG_NODND
110// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl; 110// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl;
111 111
112 setCurrentItem(mOldCurrent); 112 setCurrentItem(mOldCurrent);
113 setSelected(mOldCurrent,true); 113 setSelected(mOldCurrent,true);
114#endif 114#endif
115} 115}
116 116
117void KOTodoListView::contentsDropEvent(QDropEvent *e) 117void KOTodoListView::contentsDropEvent(QDropEvent *e)
118{ 118{
119#ifndef KORG_NODND 119#ifndef KORG_NODND
120// kdDebug() << "KOTodoListView::contentsDropEvent" << endl; 120// kdDebug() << "KOTodoListView::contentsDropEvent" << endl;
121 121
122 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 122 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
123 !QTextDrag::canDecode( e ) ) { 123 !QTextDrag::canDecode( e ) ) {
124 e->ignore(); 124 e->ignore();
125 return; 125 return;
126 } 126 }
127 127
128 DndFactory factory( mCalendar ); 128 DndFactory factory( mCalendar );
129 Todo *todo = factory.createDropTodo(e); 129 Todo *todo = factory.createDropTodo(e);
130 130
131 if (todo) { 131 if (todo) {
132 e->acceptAction(); 132 e->acceptAction();
133 133
134 KOTodoViewItem *destination = 134 KOTodoViewItem *destination =
135 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos())); 135 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos()));
136 Todo *destinationEvent = 0; 136 Todo *destinationEvent = 0;
137 if (destination) destinationEvent = destination->todo(); 137 if (destination) destinationEvent = destination->todo();
138 138
139 Todo *existingTodo = mCalendar->todo(todo->uid()); 139 Todo *existingTodo = mCalendar->todo(todo->uid());
140 140
141 if(existingTodo) { 141 if(existingTodo) {
142 Incidence *to = destinationEvent; 142 Incidence *to = destinationEvent;
143 while(to) { 143 while(to) {
144 if (to->uid() == todo->uid()) { 144 if (to->uid() == todo->uid()) {
145 KMessageBox::sorry(this, 145 KMessageBox::sorry(this,
146 i18n("Cannot move To-Do to itself\nor a child of itself"), 146 i18n("Cannot move To-Do to itself\nor a child of itself"),
147 i18n("Drop To-Do")); 147 i18n("Drop To-Do"));
148 delete todo; 148 delete todo;
149 return; 149 return;
150 } 150 }
151 to = to->relatedTo(); 151 to = to->relatedTo();
152 } 152 }
153 internalDrop = true; 153 internalDrop = true;
154 if ( destinationEvent ) 154 if ( destinationEvent )
155 reparentTodoSignal( destinationEvent, existingTodo ); 155 reparentTodoSignal( destinationEvent, existingTodo );
156 else 156 else
157 unparentTodoSignal(existingTodo); 157 unparentTodoSignal(existingTodo);
158 delete todo; 158 delete todo;
159 } else { 159 } else {
160 mCalendar->addTodo(todo); 160 mCalendar->addTodo(todo);
161 emit todoDropped(todo, KOGlobals::EVENTADDED); 161 emit todoDropped(todo, KOGlobals::EVENTADDED);
162 if ( destinationEvent ) 162 if ( destinationEvent )
163 reparentTodoSignal( destinationEvent, todo ); 163 reparentTodoSignal( destinationEvent, todo );
164 } 164 }
165 } 165 }
166 else { 166 else {
167 QString text; 167 QString text;
168 if (QTextDrag::decode(e,text)) { 168 if (QTextDrag::decode(e,text)) {
169 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) ); 169 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) );
170 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) )); 170 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) ));
171 qDebug("Dropped : " + text); 171 qDebug("Dropped : " + text);
172 QStringList emails = QStringList::split(",",text); 172 QStringList emails = QStringList::split(",",text);
173 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 173 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
174 int pos = (*it).find("<"); 174 int pos = (*it).find("<");
175 QString name = (*it).left(pos); 175 QString name = (*it).left(pos);
176 QString email = (*it).mid(pos); 176 QString email = (*it).mid(pos);
177 if (!email.isEmpty() && todoi) { 177 if (!email.isEmpty() && todoi) {
178 todoi->todo()->addAttendee(new Attendee(name,email)); 178 todoi->todo()->addAttendee(new Attendee(name,email));
179 } 179 }
180 } 180 }
181 } 181 }
182 else { 182 else {
183 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable "); 183 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable ");
184 e->ignore(); 184 e->ignore();
185 } 185 }
186 } 186 }
187#endif 187#endif
188} 188}
189 189
190void KOTodoListView::contentsMousePressEvent(QMouseEvent* e) 190void KOTodoListView::contentsMousePressEvent(QMouseEvent* e)
191{ 191{
192#ifndef KORG_NODND 192#ifndef KORG_NODND
193 QPoint p(contentsToViewport(e->pos())); 193 QPoint p(contentsToViewport(e->pos()));
194 QListViewItem *i = itemAt(p); 194 QListViewItem *i = itemAt(p);
195 mMousePressed = false; 195 mMousePressed = false;
196 if (i) { 196 if (i) {
197 // if the user clicked into the root decoration of the item, don't 197 // if the user clicked into the root decoration of the item, don't
198 // try to start a drag! 198 // try to start a drag!
199 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) + 199 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) +
200 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) + 200 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) +
201 itemMargin() || 201 itemMargin() ||
202 p.x() < header()->sectionPos(header()->mapToIndex(0))) { 202 p.x() < header()->sectionPos(header()->mapToIndex(0))) {
203 if (e->button()==Qt::LeftButton) { 203 if (e->button()==Qt::LeftButton) {
204 mPressPos = e->pos(); 204 mPressPos = e->pos();
205 mMousePressed = true; 205 mMousePressed = true;
206 } 206 }
207 } 207 }
208 } 208 }
209#endif 209#endif
210 QListView::contentsMousePressEvent(e); 210 QListView::contentsMousePressEvent(e);
211} 211}
212 212
213void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e) 213void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e)
214{ 214{
215 215
216#ifndef KORG_NODND 216#ifndef KORG_NODND
217 QListView::contentsMouseMoveEvent(e); 217 QListView::contentsMouseMoveEvent(e);
218 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() > 218 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() >
219 QApplication::startDragDistance()) { 219 QApplication::startDragDistance()) {
220 mMousePressed = false; 220 mMousePressed = false;
221 QListViewItem *item = itemAt(contentsToViewport(mPressPos)); 221 QListViewItem *item = itemAt(contentsToViewport(mPressPos));
222 if (item) { 222 if (item) {
223 DndFactory factory( mCalendar ); 223 DndFactory factory( mCalendar );
224 ICalDrag *vd = factory.createDrag( 224 ICalDrag *vd = factory.createDrag(
225 ((KOTodoViewItem *)item)->todo(),viewport()); 225 ((KOTodoViewItem *)item)->todo(),viewport());
226 internalDrop = false; 226 internalDrop = false;
227 // we cannot do any senseful here, because the DnD is still broken in Qt 227 // we cannot do any senseful here, because the DnD is still broken in Qt
228 if (vd->drag()) { 228 if (vd->drag()) {
229 if ( !internalDrop ) { 229 if ( !internalDrop ) {
230 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() ); 230 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() );
231 qDebug("Dnd: External move: Delete drag source "); 231 qDebug("Dnd: External move: Delete drag source ");
232 } else 232 } else
233 qDebug("Dnd: Internal move "); 233 qDebug("Dnd: Internal move ");
234 234
235 } else { 235 } else {
236 if ( !internalDrop ) { 236 if ( !internalDrop ) {
237 qDebug("Dnd: External Copy"); 237 qDebug("Dnd: External Copy");
238 } else 238 } else
239 qDebug("DnD: Internal copy: Copy pending"); 239 qDebug("DnD: Internal copy: Copy pending");
240 } 240 }
241 } 241 }
242 } 242 }
243#endif 243#endif
244} 244}
245void KOTodoListView::keyPressEvent ( QKeyEvent * e ) 245void KOTodoListView::keyPressEvent ( QKeyEvent * e )
246{ 246{
247 247
248 QListViewItem* cn; 248 QListViewItem* cn;
249 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) { 249 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) {
250 cn = currentItem(); 250 cn = currentItem();
251 if ( cn ) { 251 if ( cn ) {
252 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 252 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
253 if ( ci ){ 253 if ( ci ){
254 if ( e->state() == ShiftButton ) 254 if ( e->state() == ShiftButton )
255 ci->setOn( false ); 255 ci->setOn( false );
256 else 256 else
257 ci->setOn( true ); 257 ci->setOn( true );
258 cn = cn->nextSibling(); 258 cn = cn->nextSibling();
259 if ( cn ) { 259 if ( cn ) {
260 setCurrentItem ( cn ); 260 setCurrentItem ( cn );
261 ensureItemVisible ( cn ); 261 ensureItemVisible ( cn );
262 } 262 }
263 263
264 } 264 }
265 } 265 }
266 266
267 return; 267 return;
268 } 268 }
269 269
270 // qDebug("KOTodoListView::keyPressEvent "); 270 // qDebug("KOTodoListView::keyPressEvent ");
271 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) { 271 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) {
272 switch ( e->key() ) { 272 switch ( e->key() ) {
273 case Qt::Key_Down: 273 case Qt::Key_Down:
274 case Qt::Key_Up: 274 case Qt::Key_Up:
275 QListView::keyPressEvent ( e ); 275 QListView::keyPressEvent ( e );
276 break; 276 break;
277 case Qt::Key_Left: 277 case Qt::Key_Left:
278 case Qt::Key_Right: 278 case Qt::Key_Right:
279 QListView::keyPressEvent ( e ); 279 QListView::keyPressEvent ( e );
280 e->accept(); 280 e->accept();
281 return; 281 return;
282 break; 282 break;
283 default: 283 default:
284 e->ignore(); 284 e->ignore();
285 break; 285 break;
286 } 286 }
287 return; 287 return;
288 } 288 }
289 e->ignore(); 289 e->ignore();
290} 290}
291void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e) 291void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e)
292{ 292{
293 QListView::contentsMouseReleaseEvent(e); 293 QListView::contentsMouseReleaseEvent(e);
294 mMousePressed = false; 294 mMousePressed = false;
295} 295}
296 296
297void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e) 297void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
298{ 298{
299 if (!e) return; 299 if (!e) return;
300 300
301 QPoint vp = contentsToViewport(e->pos()); 301 QPoint vp = contentsToViewport(e->pos());
302 302
303 QListViewItem *item = itemAt(vp); 303 QListViewItem *item = itemAt(vp);
304 304
305 emit double_Clicked(item); 305 emit double_Clicked(item);
306 if (!item) return; 306 if (!item) return;
307 307
308 emit doubleClicked(item,vp,0); 308 emit doubleClicked(item,vp,0);
309} 309}
310 310
311///////////////////////////////////////////////////////////////////////////// 311/////////////////////////////////////////////////////////////////////////////
312 312
313KOQuickTodo::KOQuickTodo(QWidget *parent) : 313KOQuickTodo::KOQuickTodo(QWidget *parent) :
314 QLineEdit(parent) 314 QLineEdit(parent)
315{ 315{
316 setText(i18n("Click to add a new Todo")); 316 setText(i18n("Click to add a new Todo"));
317} 317}
318 318
319void KOQuickTodo::focusInEvent(QFocusEvent *ev) 319void KOQuickTodo::focusInEvent(QFocusEvent *ev)
320{ 320{
321 if ( text()==i18n("Click to add a new Todo") ) 321 if ( text()==i18n("Click to add a new Todo") )
322 setText(""); 322 setText("");
323 QLineEdit::focusInEvent(ev); 323 QLineEdit::focusInEvent(ev);
324} 324}
325 325
326void KOQuickTodo::focusOutEvent(QFocusEvent *ev) 326void KOQuickTodo::focusOutEvent(QFocusEvent *ev)
327{ 327{
328 setText(i18n("Click to add a new Todo")); 328 setText(i18n("Click to add a new Todo"));
329 QLineEdit::focusOutEvent(ev); 329 QLineEdit::focusOutEvent(ev);
330} 330}
331 331
332///////////////////////////////////////////////////////////////////////////// 332/////////////////////////////////////////////////////////////////////////////
333 333
334KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) : 334KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) :
335 KOrg::BaseView(calendar,parent,name) 335 KOrg::BaseView(calendar,parent,name)
336{ 336{
337 isFlatDisplay = false; 337 isFlatDisplay = false;
338 mNavigator = 0; 338 mNavigator = 0;
339 QBoxLayout *topLayout = new QVBoxLayout(this); 339 QBoxLayout *topLayout = new QVBoxLayout(this);
340 mName = QString ( name ); 340 mName = QString ( name );
341 mBlockUpdate = false; 341 mBlockUpdate = false;
342 mQuickAdd = new KOQuickTodo(this); 342 mQuickAdd = new KOQuickTodo(this);
343 topLayout->addWidget(mQuickAdd); 343 topLayout->addWidget(mQuickAdd);
344 344
345 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide(); 345 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide();
346 346
347 mTodoListView = new KOTodoListView(calendar,this, name ); 347 mTodoListView = new KOTodoListView(calendar,this, name );
348 topLayout->addWidget(mTodoListView); 348 topLayout->addWidget(mTodoListView);
349 //mTodoListView->header()->setMaximumHeight(30); 349 //mTodoListView->header()->setMaximumHeight(30);
350 mTodoListView->setRootIsDecorated(true); 350 mTodoListView->setRootIsDecorated(true);
351 mTodoListView->setAllColumnsShowFocus(true); 351 mTodoListView->setAllColumnsShowFocus(true);
352 352
353 mTodoListView->setShowSortIndicator(true); 353 mTodoListView->setShowSortIndicator(true);
354 354
355 mTodoListView->addColumn(i18n("Todo")); 355 mTodoListView->addColumn(i18n("Todo"));
356 mTodoListView->addColumn(i18n("Prio")); 356 mTodoListView->addColumn(i18n("Prio"));
357 mTodoListView->setColumnAlignment(1,AlignHCenter); 357 mTodoListView->setColumnAlignment(1,AlignHCenter);
358 mTodoListView->addColumn(i18n("Complete")); 358 mTodoListView->addColumn(i18n("Complete"));
359 mTodoListView->setColumnAlignment(2,AlignCenter); 359 mTodoListView->setColumnAlignment(2,AlignCenter);
360 360
361 mTodoListView->addColumn(i18n("Due Date")); 361 mTodoListView->addColumn(i18n("Due Date"));
362 mTodoListView->setColumnAlignment(3,AlignLeft); 362 mTodoListView->setColumnAlignment(3,AlignLeft);
363 mTodoListView->addColumn(i18n("Due Time")); 363 mTodoListView->addColumn(i18n("Due Time"));
364 mTodoListView->setColumnAlignment(4,AlignHCenter); 364 mTodoListView->setColumnAlignment(4,AlignHCenter);
365 365
366 mTodoListView->addColumn(i18n("Start Date")); 366 mTodoListView->addColumn(i18n("Start Date"));
367 mTodoListView->setColumnAlignment(5,AlignLeft); 367 mTodoListView->setColumnAlignment(5,AlignLeft);
368 mTodoListView->addColumn(i18n("Start Time")); 368 mTodoListView->addColumn(i18n("Start Time"));
369 mTodoListView->setColumnAlignment(6,AlignHCenter); 369 mTodoListView->setColumnAlignment(6,AlignHCenter);
370 370
371 mTodoListView->addColumn(i18n("Cancelled")); 371 mTodoListView->addColumn(i18n("Cancelled"));
372 mTodoListView->addColumn(i18n("Categories")); 372 mTodoListView->addColumn(i18n("Categories"));
373#if 0 373#if 0
374 mTodoListView->addColumn(i18n("Sort Id")); 374 mTodoListView->addColumn(i18n("Sort Id"));
375 mTodoListView->setColumnAlignment(4,AlignHCenter); 375 mTodoListView->setColumnAlignment(4,AlignHCenter);
376#endif 376#endif
377 377
378 mTodoListView->setMinimumHeight( 60 ); 378 mTodoListView->setMinimumHeight( 60 );
379 mTodoListView->setItemsRenameable( true ); 379 mTodoListView->setItemsRenameable( true );
380 mTodoListView->setRenameable( 0 ); 380 mTodoListView->setRenameable( 0 );
381 mTodoListView->setColumnWidth( 0, 120 ); 381 mTodoListView->setColumnWidth( 0, 120 );
382 mTodoListView->setColumnWidthMode(0, QListView::Manual); 382 mTodoListView->setColumnWidthMode(0, QListView::Manual);
383 mTodoListView->setColumnWidthMode(1, QListView::Manual); 383 mTodoListView->setColumnWidthMode(1, QListView::Manual);
384 mTodoListView->setColumnWidthMode(2, QListView::Manual); 384 mTodoListView->setColumnWidthMode(2, QListView::Manual);
385 mTodoListView->setColumnWidthMode(3, QListView::Manual); 385 mTodoListView->setColumnWidthMode(3, QListView::Manual);
386 mTodoListView->setColumnWidthMode(4, QListView::Manual); 386 mTodoListView->setColumnWidthMode(4, QListView::Manual);
387 mTodoListView->setColumnWidthMode(5, QListView::Manual); 387 mTodoListView->setColumnWidthMode(5, QListView::Manual);
388 mTodoListView->setColumnWidthMode(6, QListView::Manual); 388 mTodoListView->setColumnWidthMode(6, QListView::Manual);
389 mTodoListView->setColumnWidthMode(7, QListView::Manual); 389 mTodoListView->setColumnWidthMode(7, QListView::Manual);
390 mTodoListView->setColumnWidthMode(8, QListView::Manual); 390 mTodoListView->setColumnWidthMode(8, QListView::Manual);
391 391
392 392
393 mPriorityPopupMenu = new QPopupMenu(this); 393 mPriorityPopupMenu = new QPopupMenu(this);
394 for (int i = 1; i <= 5; i++) { 394 for (int i = 1; i <= 5; i++) {
395 QString label = QString ("%1").arg (i); 395 QString label = QString ("%1").arg (i);
396 mPriority[mPriorityPopupMenu->insertItem (label)] = i; 396 mPriority[mPriorityPopupMenu->insertItem (label)] = i;
397 } 397 }
398 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int))); 398 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int)));
399 399
400 mPercentageCompletedPopupMenu = new QPopupMenu(this); 400 mPercentageCompletedPopupMenu = new QPopupMenu(this);
401 for (int i = 0; i <= 100; i+=20) { 401 for (int i = 0; i <= 100; i+=20) {
402 QString label = QString ("%1 %").arg (i); 402 QString label = QString ("%1 %").arg (i);
403 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i; 403 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i;
404 } 404 }
405 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int))); 405 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int)));
406 406
407 407
408 408
409 mItemPopupMenu = new QPopupMenu(this); 409 mItemPopupMenu = new QPopupMenu(this);
410 mItemPopupMenu->insertItem(i18n("Show..."), this, 410 mItemPopupMenu->insertItem(i18n("Show..."), this,
411 SLOT (showTodo())); 411 SLOT (showTodo()));
412 mItemPopupMenu->insertItem(i18n("Edit..."), this, 412 mItemPopupMenu->insertItem(i18n("Edit..."), this,
413 SLOT (editTodo())); 413 SLOT (editTodo()));
414 mItemPopupMenu->insertItem( i18n("Delete"), this, 414 mItemPopupMenu->insertItem( i18n("Delete"), this,
415 SLOT (deleteTodo())); 415 SLOT (deleteTodo()));
416 mItemPopupMenu->insertItem( i18n("Clone..."), this, 416 mItemPopupMenu->insertItem( i18n("Clone..."), this,
417 SLOT (cloneTodo())); 417 SLOT (cloneTodo()));
418 mItemPopupMenu->insertItem( i18n("Move..."), this, 418 mItemPopupMenu->insertItem( i18n("Move..."), this,
419 SLOT (moveTodo())); 419 SLOT (moveTodo()));
420 mItemPopupMenu->insertItem( i18n("Beam..."), this, 420 mItemPopupMenu->insertItem( i18n("Beam..."), this,
421 SLOT (beamTodo())); 421 SLOT (beamTodo()));
422 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this, 422 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this,
423 SLOT (cancelTodo())); 423 SLOT (cancelTodo()));
424 mItemPopupMenu->insertSeparator(); 424 mItemPopupMenu->insertSeparator();
425 425
426 mItemPopupMenu->insertItem( i18n("New Todo..."), this, 426 mItemPopupMenu->insertItem( i18n("New Todo..."), this,
427 SLOT (newTodo())); 427 SLOT (newTodo()));
428 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this, 428 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this,
429 SLOT (newSubTodo())); 429 SLOT (newSubTodo()));
430 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this, 430 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this,
431 SLOT (unparentTodo()),0,21); 431 SLOT (unparentTodo()),0,21);
432 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this, 432 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this,
433 SLOT (reparentTodo()),0,22); 433 SLOT (reparentTodo()),0,22);
434 mItemPopupMenu->insertSeparator(); 434 mItemPopupMenu->insertSeparator();
435#if 0 435#if 0
436 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"), 436 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"),
437 this, SLOT( purgeCompleted() ) ); 437 this, SLOT( purgeCompleted() ) );
438 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"), 438 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"),
439 this, SLOT( toggleCompleted() ),0, 33 ); 439 this, SLOT( toggleCompleted() ),0, 33 );
440 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 440 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
441 this, SLOT( toggleQuickTodo() ),0, 34 ); 441 this, SLOT( toggleQuickTodo() ),0, 34 );
442 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 442 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
443 this, SLOT( toggleRunning() ),0, 35 ); 443 this, SLOT( toggleRunning() ),0, 35 );
444 444
445#endif 445#endif
446 mPopupMenu = new QPopupMenu(this); 446 mPopupMenu = new QPopupMenu(this);
447 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this, 447 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this,
448 SLOT (newTodo()),0,1); 448 SLOT (newTodo()),0,1);
449 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"), 449 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"),
450 this, SLOT(purgeCompleted()),0,2); 450 this, SLOT(purgeCompleted()),0,2);
451 mPopupMenu->insertItem(i18n("Show Completed"), 451 mPopupMenu->insertItem(i18n("Show Completed"),
452 this, SLOT( toggleCompleted() ),0,3 ); 452 this, SLOT( toggleCompleted() ),0,3 );
453 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 453 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
454 this, SLOT( toggleQuickTodo() ),0,4 ); 454 this, SLOT( toggleQuickTodo() ),0,4 );
455 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 455 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
456 this, SLOT( toggleRunning() ),0,5 ); 456 this, SLOT( toggleRunning() ),0,5 );
457 mPopupMenu->insertItem(i18n(" set all open","Display all opened"), 457 mPopupMenu->insertItem(i18n(" set all open","Display all opened"),
458 this, SLOT( setAllOpen() ),0,6 ); 458 this, SLOT( setAllOpen() ),0,6 );
459 mPopupMenu->insertItem(i18n(" set all close","Display all closed"), 459 mPopupMenu->insertItem(i18n(" set all close","Display all closed"),
460 this, SLOT( setAllClose() ),0,7 ); 460 this, SLOT( setAllClose() ),0,7 );
461 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"), 461 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"),
462 this, SLOT( setAllFlat() ),0,8 ); 462 this, SLOT( setAllFlat() ),0,8 );
463 mDocPrefs = new DocPrefs( name ); 463 mDocPrefs = new DocPrefs( name );
464 464
465 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu ); 465 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu );
466 mPopupMenu->setCheckable( true ); 466 mPopupMenu->setCheckable( true );
467 mItemPopupMenu->setCheckable( true ); 467 mItemPopupMenu->setCheckable( true );
468 468
469 469
470 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 470 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
471 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 471 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
472 472
473 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 473 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
474 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 474 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
475 475
476 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 476 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
477 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 477 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
478 478
479 479
480 // Double clicking conflicts with opening/closing the subtree 480 // Double clicking conflicts with opening/closing the subtree
481 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ), 481 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ),
482 SLOT( editItem( QListViewItem *) ) ); 482 SLOT( editItem( QListViewItem *) ) );
483 /* 483 /*
484 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *, 484 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *,
485 const QPoint &,int ) ), 485 const QPoint &,int ) ),
486 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 486 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
487 */ 487 */
488 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *, 488 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *,
489 const QPoint &,int ) ), 489 const QPoint &,int ) ),
490 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 490 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
491 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ), 491 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ),
492 SLOT( itemClicked( QListViewItem * ) ) ); 492 SLOT( itemClicked( QListViewItem * ) ) );
493 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ), 493 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ),
494 SLOT( itemDoubleClicked( QListViewItem * ) ) ); 494 SLOT( itemDoubleClicked( QListViewItem * ) ) );
495 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 495 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
496 SLOT( updateView() ) ); 496 SLOT( updateView() ) );
497 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 497 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
498 SLOT( todoModified(Todo *, int) ) ); 498 SLOT( todoModified(Todo *, int) ) );
499 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ), 499 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ),
500 SLOT( itemStateChanged( QListViewItem * ) ) ); 500 SLOT( itemStateChanged( QListViewItem * ) ) );
501 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ), 501 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ),
502 SLOT( itemStateChanged( QListViewItem * ) ) ); 502 SLOT( itemStateChanged( QListViewItem * ) ) );
503 503
504#if 0 504#if 0
505 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)), 505 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)),
506 SLOT(selectionChanged(QListViewItem *))); 506 SLOT(selectionChanged(QListViewItem *)));
507 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)), 507 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)),
508 SLOT(selectionChanged(QListViewItem *))); 508 SLOT(selectionChanged(QListViewItem *)));
509 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)), 509 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)),
510 SLOT(selectionChanged(QListViewItem *))); 510 SLOT(selectionChanged(QListViewItem *)));
511#endif 511#endif
512 512
513 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) )); 513 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) ));
514 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) )); 514 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) ));
515 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) )); 515 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) ));
516 516
517 connect( mTodoListView, SIGNAL(selectionChanged() ), 517 connect( mTodoListView, SIGNAL(selectionChanged() ),
518 SLOT( processSelectionChange() ) ); 518 SLOT( processSelectionChange() ) );
519 connect( mQuickAdd, SIGNAL( returnPressed () ), 519 connect( mQuickAdd, SIGNAL( returnPressed () ),
520 SLOT( addQuickTodo() ) ); 520 SLOT( addQuickTodo() ) );
521 521
522} 522}
523 523
524KOTodoView::~KOTodoView() 524KOTodoView::~KOTodoView()
525{ 525{
526 delete mDocPrefs; 526 delete mDocPrefs;
527} 527}
528 528
529void KOTodoView::jumpToDate () 529void KOTodoView::jumpToDate ()
530{ 530{
531 // if (mActiveItem) { 531 // if (mActiveItem) {
532// mActiveItem->todo()); 532// mActiveItem->todo());
533// if ( mActiveItem->todo()->hasDueDate() ) 533// if ( mActiveItem->todo()->hasDueDate() )
534// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() ); 534// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() );
535} 535}
536 536
537void KOTodoView::updateView() 537void KOTodoView::updateView()
538{ 538{
539 pendingSubtodo = 0; 539 pendingSubtodo = 0;
540 if ( mBlockUpdate ) { 540 if ( mBlockUpdate ) {
541 //qDebug("blocked "); 541 //qDebug("blocked ");
542 return; 542 return;
543 } 543 }
544 if ( isFlatDisplay ) { 544 if ( isFlatDisplay ) {
545 setAllFlat(); 545 setAllFlat();
546 return; 546 return;
547 } 547 }
548 //qDebug("update "); 548 //qDebug("update ");
549// kdDebug() << "KOTodoView::updateView()" << endl; 549// kdDebug() << "KOTodoView::updateView()" << endl;
550 QFont fo = KOPrefs::instance()->mTodoViewFont; 550 QFont fo = KOPrefs::instance()->mTodoViewFont;
551 mTodoListView->clear(); 551 mTodoListView->clear();
552 if ( mName == "todolistsmall" ) { 552 if ( mName == "todolistsmall" ) {
553 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) { 553 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) {
554 int ps = fo.pointSize() -2; 554 int ps = fo.pointSize() -2;
555 if ( ps > 12 ) 555 if ( ps > 12 )
556 ps -= 2; 556 ps -= 2;
557 fo.setPointSize( ps ); 557 fo.setPointSize( ps );
558 } 558 }
559 } 559 }
560 560
561 mTodoListView->setFont( fo ); 561 mTodoListView->setFont( fo );
562 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont ); 562 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont );
563 //mTodoListView->header()->setMaximumHeight(fm.height()); 563 //mTodoListView->header()->setMaximumHeight(fm.height());
564 QPtrList<Todo> todoList = calendar()->todos(); 564 QPtrList<Todo> todoList = calendar()->todos();
565 565
566/* 566/*
567 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl; 567 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl;
568 Event *t; 568 Event *t;
569 for(t = todoList.first(); t; t = todoList.next()) { 569 for(t = todoList.first(); t; t = todoList.next()) {
570 kdDebug() << " " << t->getSummary() << endl; 570 kdDebug() << " " << t->getSummary() << endl;
571 571
572 if (t->getRelatedTo()) { 572 if (t->getRelatedTo()) {
573 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl; 573 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl;
574 } 574 }
575 575
576 QPtrList<Event> l = t->getRelations(); 576 QPtrList<Event> l = t->getRelations();
577 Event *c; 577 Event *c;
578 for(c=l.first();c;c=l.next()) { 578 for(c=l.first();c;c=l.next()) {
579 kdDebug() << " - relation: " << c->getSummary() << endl; 579 kdDebug() << " - relation: " << c->getSummary() << endl;
580 } 580 }
581 } 581 }
582*/ 582*/
583 583
584 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a 584 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a
585 // specific order of events. That means that we have to generate parent items 585 // specific order of events. That means that we have to generate parent items
586 // recursively for proper hierarchical display of Todos. 586 // recursively for proper hierarchical display of Todos.
587 mTodoMap.clear(); 587 mTodoMap.clear();
588 Todo *todo; 588 Todo *todo;
589 todo = todoList.first();// todo; todo = todoList.next()) { 589 todo = todoList.first();// todo; todo = todoList.next()) {
590 while ( todo ) { 590 while ( todo ) {
591 bool next = true; 591 bool next = true;
592 // qDebug("todo %s ", todo->summary().latin1()); 592 // qDebug("todo %s ", todo->summary().latin1());
593 Incidence *incidence = todo->relatedTo(); 593 Incidence *incidence = todo->relatedTo();
594 while ( incidence ) { 594 while ( incidence ) {
595 if ( incidence->type() == "Todo") { 595 if ( incidence->type() == "Todo") {
596 //qDebug("related %s ",incidence->summary().latin1() ); 596 //qDebug("related %s ",incidence->summary().latin1() );
597 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) { 597 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) {
598 //qDebug("related not found "); 598 //qDebug("related not found ");
599 todoList.remove( ); 599 todoList.remove( );
600 todo = todoList.current(); 600 todo = todoList.current();
601 next = false; 601 next = false;
602 incidence = 0; 602 incidence = 0;
603 603
604 } else { 604 } else {
605 //qDebug("related found "); 605 //qDebug("related found ");
606 incidence = incidence->relatedTo(); 606 incidence = incidence->relatedTo();
607 } 607 }
608 } else 608 } else
609 incidence = 0; 609 incidence = 0;
610 } 610 }
611 if ( next ) 611 if ( next )
612 todo = todoList.next(); 612 todo = todoList.next();
613 } 613 }
614// qDebug("again .... "); 614// qDebug("again .... ");
615// for(todo = todoList.first(); todo; todo = todoList.next()) { 615// for(todo = todoList.first(); todo; todo = todoList.next()) {
616 616
617// qDebug("yytodo %s ", todo->summary().latin1()); 617// qDebug("yytodo %s ", todo->summary().latin1());
618// } 618// }
619 //qDebug("for "); 619 //qDebug("for ");
620 for(todo = todoList.first(); todo; todo = todoList.next()) { 620 for(todo = todoList.first(); todo; todo = todoList.next()) {
621 if (!mTodoMap.contains(todo) && checkTodo( todo ) ) 621 if (!mTodoMap.contains(todo) && checkTodo( todo ) )
622 { 622 {
623 insertTodoItem(todo); 623 insertTodoItem(todo);
624 } 624 }
625 } 625 }
626 //qDebug("for end "); 626 //qDebug("for end ");
627 // Restore opened/closed state 627 // Restore opened/closed state
628 mTodoListView->blockSignals( true ); 628 mTodoListView->blockSignals( true );
629 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() ); 629 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() );
630 mTodoListView->blockSignals( false ); 630 mTodoListView->blockSignals( false );
631 mTodoListView->setFocus(); 631 mTodoListView->setFocus();
632 processSelectionChange(); 632 processSelectionChange();
633} 633}
634 634
635bool KOTodoView::checkTodo( Todo * todo ) 635bool KOTodoView::checkTodo( Todo * todo )
636{ 636{
637 637
638 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() ) 638 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() )
639 return false; 639 return false;
640 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) { 640 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) {
641 if ( todo->hasStartDate() ) 641 if ( todo->hasStartDate() )
642 if ( mNavigator->selectedDates().last() < todo->dtStart().date() ) 642 if ( mNavigator->selectedDates().last() < todo->dtStart().date() )
643 return false; 643 return false;
644 if ( todo->hasDueDate() ) 644 if ( todo->hasDueDate() )
645 if ( mNavigator->selectedDates().first() > todo->dtDue().date() ) 645 if ( mNavigator->selectedDates().first() > todo->dtDue().date() )
646 return false; 646 return false;
647 } 647 }
648 return true; 648 return true;
649} 649}
650 650
651void KOTodoView::restoreItemState( QListViewItem *item ) 651void KOTodoView::restoreItemState( QListViewItem *item )
652{ 652{
653 pendingSubtodo = 0; 653 pendingSubtodo = 0;
654 while( item ) { 654 while( item ) {
655 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 655 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
656 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) ); 656 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) );
657 if( item->childCount() > 0 ) restoreItemState( item->firstChild() ); 657 if( item->childCount() > 0 ) restoreItemState( item->firstChild() );
658 item = item->nextSibling(); 658 item = item->nextSibling();
659 } 659 }
660} 660}
661 661
662 662
663QMap<Todo *,KOTodoViewItem *>::ConstIterator 663QMap<Todo *,KOTodoViewItem *>::ConstIterator
664 KOTodoView::insertTodoItem(Todo *todo) 664 KOTodoView::insertTodoItem(Todo *todo)
665{ 665{
666 666
667// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl; 667// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl;
668 // TODO: Check, if dynmaic cast is necessary 668 // TODO: Check, if dynmaic cast is necessary
669 669
670 pendingSubtodo = 0; 670 pendingSubtodo = 0;
671 Incidence *incidence = todo->relatedTo(); 671 Incidence *incidence = todo->relatedTo();
672 if (incidence && incidence->type() == "Todo") { 672 if (incidence && incidence->type() == "Todo") {
673 Todo *relatedTodo = static_cast<Todo *>(incidence); 673 Todo *relatedTodo = static_cast<Todo *>(incidence);
674 674
675// kdDebug() << " has Related" << endl; 675// kdDebug() << " has Related" << endl;
676 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 676 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
677 itemIterator = mTodoMap.find(relatedTodo); 677 itemIterator = mTodoMap.find(relatedTodo);
678 if (itemIterator == mTodoMap.end()) { 678 if (itemIterator == mTodoMap.end()) {
679// kdDebug() << " related not yet in list" << endl; 679// kdDebug() << " related not yet in list" << endl;
680 itemIterator = insertTodoItem (relatedTodo); 680 itemIterator = insertTodoItem (relatedTodo);
681 } 681 }
682 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem 682 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem
683 // and one into the map. Sure finding is more easy but why? -zecke 683 // and one into the map. Sure finding is more easy but why? -zecke
684 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this); 684 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this);
685 return mTodoMap.insert(todo,todoItem); 685 return mTodoMap.insert(todo,todoItem);
686 } else { 686 } else {
687// kdDebug() << " no Related" << endl; 687// kdDebug() << " no Related" << endl;
688 // see above -zecke 688 // see above -zecke
689 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 689 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
690 return mTodoMap.insert(todo,todoItem); 690 return mTodoMap.insert(todo,todoItem);
691 } 691 }
692} 692}
693 693
694 694
695void KOTodoView::updateConfig() 695void KOTodoView::updateConfig()
696{ 696{
697 updateView(); 697 updateView();
698 mTodoListView->repaintContents(); 698 mTodoListView->repaintContents();
699} 699}
700 700
701QPtrList<Incidence> KOTodoView::selectedIncidences() 701QPtrList<Incidence> KOTodoView::selectedIncidences()
702{ 702{
703 QPtrList<Incidence> selected; 703 QPtrList<Incidence> selected;
704 704
705 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 705 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
706// if (!item) item = mActiveItem; 706// if (!item) item = mActiveItem;
707 if (item) selected.append(item->todo()); 707 if (item) selected.append(item->todo());
708 708
709 return selected; 709 return selected;
710} 710}
711 711
712QPtrList<Todo> KOTodoView::selectedTodos() 712QPtrList<Todo> KOTodoView::selectedTodos()
713{ 713{
714 QPtrList<Todo> selected; 714 QPtrList<Todo> selected;
715 715
716 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 716 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
717// if (!item) item = mActiveItem; 717// if (!item) item = mActiveItem;
718 if (item) selected.append(item->todo()); 718 if (item) selected.append(item->todo());
719 719
720 return selected; 720 return selected;
721} 721}
722 722
723void KOTodoView::changeEventDisplay(Event *, int) 723void KOTodoView::changeEventDisplay(Event *, int)
724{ 724{
725 updateView(); 725 updateView();
726} 726}
727 727
728void KOTodoView::showDates(const QDate &, const QDate &) 728void KOTodoView::showDates(const QDate &, const QDate &)
729{ 729{
730} 730}
731 731
732void KOTodoView::showEvents(QPtrList<Event>) 732void KOTodoView::showEvents(QPtrList<Event>)
733{ 733{
734 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl; 734 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl;
735} 735}
736 736
737void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd, 737void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd,
738 const QDate &td) 738 const QDate &td)
739{ 739{
740#ifndef KORG_NOPRINTER 740#ifndef KORG_NOPRINTER
741 calPrinter->preview(CalPrinter::Todolist, fd, td); 741 calPrinter->preview(CalPrinter::Todolist, fd, td);
742#endif 742#endif
743} 743}
744 744
745void KOTodoView::editItem(QListViewItem *item ) 745void KOTodoView::editItem(QListViewItem *item )
746{ 746{
747 // qDebug("editItem(QListViewItem *item ) "); 747 // qDebug("editItem(QListViewItem *item ) ");
748 emit editTodoSignal(((KOTodoViewItem *)item)->todo()); 748 emit editTodoSignal(((KOTodoViewItem *)item)->todo());
749} 749}
750 750
751void KOTodoView::showItem(QListViewItem *item,const QPoint &,int) 751void KOTodoView::showItem(QListViewItem *item,const QPoint &,int)
752{ 752{
753 emit showTodoSignal(((KOTodoViewItem *)item)->todo()); 753 emit showTodoSignal(((KOTodoViewItem *)item)->todo());
754} 754}
755 755
756void KOTodoView::popupMenu(QListViewItem *item,const QPoint &,int column) 756void KOTodoView::popupMenu(QListViewItem *item,const QPoint &,int column)
757{ 757{
758 pendingSubtodo = 0; 758 pendingSubtodo = 0;
759 mActiveItem = (KOTodoViewItem *)item; 759 mActiveItem = (KOTodoViewItem *)item;
760 if (item) { 760 if (item) {
761 switch (column){ 761 switch (column){
762 case 1: 762 case 1:
763 mPriorityPopupMenu->popup(QCursor::pos ()); break; 763 mPriorityPopupMenu->popup(QCursor::pos ()); break;
764 case 2: 764 case 2:
765 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break; 765 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break;
766 case 3: 766 case 3:
767 moveTodo(); 767 moveTodo();
768 break; 768 break;
769 case 8: 769 case 8:
770 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break; 770 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break;
771 default: 771 default:
772 mItemPopupMenu->popup(QCursor::pos()); 772 mItemPopupMenu->popup(QCursor::pos());
773 } 773 }
774 } else mPopupMenu->popup(QCursor::pos()); 774 } else mPopupMenu->popup(QCursor::pos());
775} 775}
776void KOTodoView::newTodo() 776void KOTodoView::newTodo()
777{ 777{
778 emit newTodoSignal(); 778 emit newTodoSignal();
779} 779}
780 780
781void KOTodoView::newSubTodo() 781void KOTodoView::newSubTodo()
782{ 782{
783 if (mActiveItem) { 783 if (mActiveItem) {
784 emit newSubTodoSignal(mActiveItem->todo()); 784 emit newSubTodoSignal(mActiveItem->todo());
785 } 785 }
786} 786}
787void KOTodoView::unparentTodo() 787void KOTodoView::unparentTodo()
788{ 788{
789 if (mActiveItem) { 789 if (mActiveItem) {
790 emit unparentTodoSignal(mActiveItem->todo()); 790 emit unparentTodoSignal(mActiveItem->todo());
791 } 791 }
792} 792}
793 793
794void KOTodoView::reparentTodo() 794void KOTodoView::reparentTodo()
795{ 795{
796 if (mActiveItem) { 796 if (mActiveItem) {
797 qDebug("KOTodoView::reparentTodo() "); 797 qDebug("KOTodoView::reparentTodo() ");
798 topLevelWidget()->setCaption(i18n("Click on new parent item")); 798 topLevelWidget()->setCaption(i18n("Click on new parent item"));
799 pendingSubtodo = mActiveItem; 799 pendingSubtodo = mActiveItem;
800 } 800 }
801} 801}
802void KOTodoView::editTodo() 802void KOTodoView::editTodo()
803{ 803{
804 if (mActiveItem) { 804 if (mActiveItem) {
805 emit editTodoSignal(mActiveItem->todo()); 805 emit editTodoSignal(mActiveItem->todo());
806 } 806 }
807} 807}
808void KOTodoView::cloneTodo() 808void KOTodoView::cloneTodo()
809{ 809{
810 if (mActiveItem) { 810 if (mActiveItem) {
811 emit cloneTodoSignal((Incidence*)mActiveItem->todo()); 811 emit cloneTodoSignal((Incidence*)mActiveItem->todo());
812 } 812 }
813} 813}
814void KOTodoView::cancelTodo() 814void KOTodoView::cancelTodo()
815{ 815{
816 if (mActiveItem) { 816 if (mActiveItem) {
817 emit cancelTodoSignal((Incidence*)mActiveItem->todo()); 817 emit cancelTodoSignal((Incidence*)mActiveItem->todo());
818 } 818 }
819} 819}
820void KOTodoView::moveTodo() 820void KOTodoView::moveTodo()
821{ 821{
822 if (mActiveItem) { 822 if (mActiveItem) {
823 emit moveTodoSignal((Incidence*)mActiveItem->todo()); 823 emit moveTodoSignal((Incidence*)mActiveItem->todo());
824 } 824 }
825} 825}
826void KOTodoView::beamTodo() 826void KOTodoView::beamTodo()
827{ 827{
828 if (mActiveItem) { 828 if (mActiveItem) {
829 emit beamTodoSignal((Incidence*)mActiveItem->todo()); 829 emit beamTodoSignal((Incidence*)mActiveItem->todo());
830 } 830 }
831} 831}
832 832
833 833
834void KOTodoView::showTodo() 834void KOTodoView::showTodo()
835{ 835{
836 if (mActiveItem) { 836 if (mActiveItem) {
837 emit showTodoSignal(mActiveItem->todo()); 837 emit showTodoSignal(mActiveItem->todo());
838 } 838 }
839} 839}
840 840
841void KOTodoView::deleteTodo() 841void KOTodoView::deleteTodo()
842{ 842{
843 if (mActiveItem) { 843 if (mActiveItem) {
844 emit deleteTodoSignal(mActiveItem->todo()); 844 emit deleteTodoSignal(mActiveItem->todo());
845 } 845 }
846} 846}
847 847
848void KOTodoView::setNewPriority(int index) 848void KOTodoView::setNewPriority(int index)
849{ 849{
850 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 850 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
851 mActiveItem->todo()->setPriority(mPriority[index]); 851 mActiveItem->todo()->setPriority(mPriority[index]);
852 mActiveItem->construct(); 852 mActiveItem->construct();
853 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED); 853 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED);
854 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 854 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
855 } 855 }
856} 856}
857 857
858void KOTodoView::setNewPercentage(int index) 858void KOTodoView::setNewPercentage(int index)
859{ 859{
860 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 860 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
861 if (mPercentage[index] == 100) { 861
862 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime()); 862 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) {
863 } else { 863 mActiveItem->setOn( true );
864 mActiveItem->todo()->setCompleted(false); 864 return;
865 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) {
866 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent()));
867 if ( par && par->isOn() )
868 par->setOn( false );
869 }
870 if (mPercentage[index] == 100) {
871 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime());
872 } else {
873 mActiveItem->todo()->setCompleted(false);
874 }
875 mActiveItem->todo()->setPercentComplete(mPercentage[index]);
876 mActiveItem->construct();
877 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED);
878 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
865 } 879 }
866 mActiveItem->todo()->setPercentComplete(mPercentage[index]);
867 mActiveItem->construct();
868 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED);
869 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
870 }
871} 880}
872 881
873 882
874QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem) 883QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem)
875{ 884{
876 QPopupMenu* tempMenu = new QPopupMenu (this); 885 QPopupMenu* tempMenu = new QPopupMenu (this);
877 QStringList checkedCategories = todoItem->todo()->categories (); 886 QStringList checkedCategories = todoItem->todo()->categories ();
878 887
879 tempMenu->setCheckable (true); 888 tempMenu->setCheckable (true);
880 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); 889 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin ();
881 it != KOPrefs::instance()->mCustomCategories.end (); 890 it != KOPrefs::instance()->mCustomCategories.end ();
882 ++it) { 891 ++it) {
883 int index = tempMenu->insertItem (*it); 892 int index = tempMenu->insertItem (*it);
884 mCategory[index] = *it; 893 mCategory[index] = *it;
885 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true); 894 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true);
886 } 895 }
887 896
888 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int))); 897 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int)));
889 return tempMenu; 898 return tempMenu;
890 899
891 900
892} 901}
893void KOTodoView::changedCategories(int index) 902void KOTodoView::changedCategories(int index)
894{ 903{
895 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 904 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
896 QStringList categories = mActiveItem->todo()->categories (); 905 QStringList categories = mActiveItem->todo()->categories ();
897 if (categories.find (mCategory[index]) != categories.end ()) 906 if (categories.find (mCategory[index]) != categories.end ())
898 categories.remove (mCategory[index]); 907 categories.remove (mCategory[index]);
899 else 908 else
900 categories.insert (categories.end(), mCategory[index]); 909 categories.insert (categories.end(), mCategory[index]);
901 categories.sort (); 910 categories.sort ();
902 mActiveItem->todo()->setCategories (categories); 911 mActiveItem->todo()->setCategories (categories);
903 mActiveItem->construct(); 912 mActiveItem->construct();
904 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 913 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
905 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED); 914 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED);
906 } 915 }
907} 916}
908void KOTodoView::itemDoubleClicked(QListViewItem *item) 917void KOTodoView::itemDoubleClicked(QListViewItem *item)
909{ 918{
910 if ( pendingSubtodo != 0 ) { 919 if ( pendingSubtodo != 0 ) {
911 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 920 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
912 } 921 }
913 pendingSubtodo = 0; 922 pendingSubtodo = 0;
914 if (!item) { 923 if (!item) {
915 newTodo(); 924 newTodo();
916 return; 925 return;
917 } 926 }
918 if ( KOPrefs::instance()->mEditOnDoubleClick ) 927 if ( KOPrefs::instance()->mEditOnDoubleClick )
919 editItem( item ); 928 editItem( item );
920 else 929 else
921 showItem( item , QPoint(), 0 ); 930 showItem( item , QPoint(), 0 );
922} 931}
923void KOTodoView::itemClicked(QListViewItem *item) 932void KOTodoView::itemClicked(QListViewItem *item)
924{ 933{
925 934
926 if (!item) { 935 if (!item) {
927 if ( pendingSubtodo != 0 ) { 936 if ( pendingSubtodo != 0 ) {
928 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 937 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
929 } 938 }
930 pendingSubtodo = 0; 939 pendingSubtodo = 0;
931 return; 940 return;
932 } 941 }
933 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 942 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
934 if ( pendingSubtodo != 0 ) { 943 if ( pendingSubtodo != 0 ) {
935 bool allowReparent = true; 944 bool allowReparent = true;
936 QListViewItem *par = item; 945 QListViewItem *par = item;
937 while ( par ) { 946 while ( par ) {
938 if ( par == pendingSubtodo ) { 947 if ( par == pendingSubtodo ) {
939 allowReparent = false; 948 allowReparent = false;
940 break; 949 break;
941 } 950 }
942 par = par->parent(); 951 par = par->parent();
943 } 952 }
944 if ( !allowReparent ) { 953 if ( !allowReparent ) {
945 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!")); 954 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!"));
946 qDebug("Recursive reparenting not possible "); 955 qDebug("Recursive reparenting not possible ");
947 pendingSubtodo = 0; 956 pendingSubtodo = 0;
948 } else { 957 } else {
949 Todo* newParent = todoItem->todo(); 958 Todo* newParent = todoItem->todo();
950 Todo* newSub = pendingSubtodo->todo(); 959 Todo* newSub = pendingSubtodo->todo();
951 pendingSubtodo = 0; 960 pendingSubtodo = 0;
952 emit reparentTodoSignal( newParent,newSub ); 961 emit reparentTodoSignal( newParent,newSub );
953 return; 962 return;
954 } 963 }
955 } 964 }
956#if 0 965#if 0
957 // handled by the item itself 966 // handled by the item itself
958 bool completed = todoItem->todo()->isCompleted(); // Completed or not? 967 bool completed = todoItem->todo()->isCompleted(); // Completed or not?
959 qDebug("com %d ",completed ); 968 qDebug("com %d ",completed );
960 qDebug("itemclicked "); 969 qDebug("itemclicked ");
961 if (todoItem->isOn()) { 970 if (todoItem->isOn()) {
962 qDebug("on "); 971 qDebug("on ");
963 if (!completed) { 972 if (!completed) {
964 qDebug("set true "); 973 qDebug("set true ");
965 todoItem->todo()->setCompleted(QDateTime::currentDateTime()); 974 todoItem->todo()->setCompleted(QDateTime::currentDateTime());
966 } 975 }
967 } else { 976 } else {
968 qDebug("not on "); 977 qDebug("not on ");
969 if (completed) { 978 if (completed) {
970 qDebug("set false "); 979 qDebug("set false ");
971 todoItem->todo()->setCompleted(false); 980 todoItem->todo()->setCompleted(false);
972 } 981 }
973 } 982 }
974#endif 983#endif
975} 984}
976 985
977void KOTodoView::setDocumentId( const QString &id ) 986void KOTodoView::setDocumentId( const QString &id )
978{ 987{
979 kdDebug() << "KOTodoView::setDocumentId()" << endl; 988 kdDebug() << "KOTodoView::setDocumentId()" << endl;
980 989
981 mDocPrefs->setDoc( id ); 990 mDocPrefs->setDoc( id );
982} 991}
983 992
984void KOTodoView::itemStateChanged( QListViewItem *item ) 993void KOTodoView::itemStateChanged( QListViewItem *item )
985{ 994{
986 if (!item) return; 995 if (!item) return;
987 996
988 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 997 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
989 998
990// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl; 999// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl;
991 1000
992 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() ); 1001 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() );
993} 1002}
994 1003
995void KOTodoView::saveLayout(KConfig *config, const QString &group) const 1004void KOTodoView::saveLayout(KConfig *config, const QString &group) const
996{ 1005{
997 mTodoListView->saveLayout(config,group); 1006 mTodoListView->saveLayout(config,group);
998} 1007}
999 1008
1000void KOTodoView::restoreLayout(KConfig *config, const QString &group) 1009void KOTodoView::restoreLayout(KConfig *config, const QString &group)
1001{ 1010{
1002 mTodoListView->restoreLayout(config,group); 1011 mTodoListView->restoreLayout(config,group);
1003} 1012}
1004 1013
1005void KOTodoView::processSelectionChange() 1014void KOTodoView::processSelectionChange()
1006{ 1015{
1007// kdDebug() << "KOTodoView::processSelectionChange()" << endl; 1016// kdDebug() << "KOTodoView::processSelectionChange()" << endl;
1008 1017
1009 KOTodoViewItem *item = 1018 KOTodoViewItem *item =
1010 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() ); 1019 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() );
1011 1020
1012 if ( !item ) { 1021 if ( !item ) {
1013 emit incidenceSelected( 0 ); 1022 emit incidenceSelected( 0 );
1014 } else { 1023 } else {
1015 emit incidenceSelected( item->todo() ); 1024 emit incidenceSelected( item->todo() );
1016 } 1025 }
1017} 1026}
1018 1027
1019void KOTodoView::modified(bool b) 1028void KOTodoView::modified(bool b)
1020{ 1029{
1021 emit isModified(b); 1030 emit isModified(b);
1022} 1031}
1023void KOTodoView::setTodoModified( Todo* todo ) 1032void KOTodoView::setTodoModified( Todo* todo )
1024{ 1033{
1025 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED ); 1034 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED );
1026} 1035}
1027void KOTodoView::clearSelection() 1036void KOTodoView::clearSelection()
1028{ 1037{
1029 mTodoListView->selectAll( false ); 1038 mTodoListView->selectAll( false );
1030} 1039}
1031void KOTodoView::setAllOpen() 1040void KOTodoView::setAllOpen()
1032{ 1041{
1033 if ( isFlatDisplay ) { 1042 if ( isFlatDisplay ) {
1034 isFlatDisplay = false; 1043 isFlatDisplay = false;
1035 mPopupMenu->setItemChecked( 8,false ); 1044 mPopupMenu->setItemChecked( 8,false );
1036 updateView(); 1045 updateView();
1037 } 1046 }
1038 setOpen(mTodoListView->firstChild(), true); 1047 setOpen(mTodoListView->firstChild(), true);
1039} 1048}
1040void KOTodoView::setAllClose() 1049void KOTodoView::setAllClose()
1041{ 1050{
1042 if ( isFlatDisplay ) { 1051 if ( isFlatDisplay ) {
1043 isFlatDisplay = false; 1052 isFlatDisplay = false;
1044 mPopupMenu->setItemChecked( 8,false ); 1053 mPopupMenu->setItemChecked( 8,false );
1045 updateView(); 1054 updateView();
1046 } 1055 }
1047 setOpen(mTodoListView->firstChild(), false); 1056 setOpen(mTodoListView->firstChild(), false);
1048} 1057}
1049void KOTodoView::setOpen( QListViewItem* item, bool setOpenI) 1058void KOTodoView::setOpen( QListViewItem* item, bool setOpenI)
1050{ 1059{
1051 1060
1052 while ( item ) { 1061 while ( item ) {
1053 setOpen( item->firstChild(), setOpenI ); 1062 setOpen( item->firstChild(), setOpenI );
1054 item->setOpen( setOpenI ); 1063 item->setOpen( setOpenI );
1055 item = item->nextSibling(); 1064 item = item->nextSibling();
1056 } 1065 }
1057} 1066}
1058 1067
1059void KOTodoView::setAllFlat() 1068void KOTodoView::setAllFlat()
1060{ 1069{
1061 if ( isFlatDisplay ) { 1070 if ( isFlatDisplay ) {
1062 isFlatDisplay = false; 1071 isFlatDisplay = false;
1063 mPopupMenu->setItemChecked( 8,false ); 1072 mPopupMenu->setItemChecked( 8,false );
1064 updateView(); 1073 updateView();
1065 return; 1074 return;
1066 } 1075 }
1067 pendingSubtodo = 0; 1076 pendingSubtodo = 0;
1068 if ( mBlockUpdate ) { 1077 if ( mBlockUpdate ) {
1069 return; 1078 return;
1070 } 1079 }
1071 mPopupMenu->setItemChecked( 8,true ); 1080 mPopupMenu->setItemChecked( 8,true );
1072 isFlatDisplay = true; 1081 isFlatDisplay = true;
1073 QPtrList<Todo> todoList = calendar()->todos(); 1082 QPtrList<Todo> todoList = calendar()->todos();
1074 mTodoMap.clear(); 1083 mTodoMap.clear();
1075 mTodoListView->clear(); 1084 mTodoListView->clear();
1076 Todo *todo; 1085 Todo *todo;
1077 for(todo = todoList.first(); todo; todo = todoList.next()) { 1086 for(todo = todoList.first(); todo; todo = todoList.next()) {
1078 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 1087 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
1079 mTodoMap.insert(todo,todoItem); 1088 mTodoMap.insert(todo,todoItem);
1080 } 1089 }
1081 mTodoListView->setFocus(); 1090 mTodoListView->setFocus();
1082 processSelectionChange(); 1091 processSelectionChange();
1083} 1092}
1084 1093
1085void KOTodoView::purgeCompleted() 1094void KOTodoView::purgeCompleted()
1086{ 1095{
1087 emit purgeCompletedSignal(); 1096 emit purgeCompletedSignal();
1088} 1097}
1089void KOTodoView::toggleQuickTodo() 1098void KOTodoView::toggleQuickTodo()
1090{ 1099{
1091 if ( mQuickAdd->isVisible() ) { 1100 if ( mQuickAdd->isVisible() ) {
1092 mQuickAdd->hide(); 1101 mQuickAdd->hide();
1093 KOPrefs::instance()->mEnableQuickTodo = false; 1102 KOPrefs::instance()->mEnableQuickTodo = false;
1094 } 1103 }
1095 else { 1104 else {
1096 mQuickAdd->show(); 1105 mQuickAdd->show();
1097 KOPrefs::instance()->mEnableQuickTodo = true; 1106 KOPrefs::instance()->mEnableQuickTodo = true;
1098 } 1107 }
1099 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 1108 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
1100 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 1109 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
1101} 1110}
1102 1111
1103void KOTodoView::toggleRunning() 1112void KOTodoView::toggleRunning()
1104{ 1113{
1105 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos; 1114 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos;
1106 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 1115 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
1107 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 1116 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
1108 updateView(); 1117 updateView();
1109} 1118}
1110 1119
1111void KOTodoView::toggleCompleted() 1120void KOTodoView::toggleCompleted()
1112{ 1121{
1113 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo; 1122 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo;
1114 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 1123 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
1115 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 1124 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
1116 updateView(); 1125 updateView();
1117} 1126}
1118 1127
1119void KOTodoView::addQuickTodo() 1128void KOTodoView::addQuickTodo()
1120{ 1129{
1121 Todo *todo = new Todo(); 1130 Todo *todo = new Todo();
1122 todo->setSummary(mQuickAdd->text()); 1131 todo->setSummary(mQuickAdd->text());
1123 todo->setOrganizer(KOPrefs::instance()->email()); 1132 todo->setOrganizer(KOPrefs::instance()->email());
1124 CalFilter * cf = mCalendar->filter(); 1133 CalFilter * cf = mCalendar->filter();
1125 if ( cf ) { 1134 if ( cf ) {
1126 if ( cf->isEnabled()&& cf->showCategories()) { 1135 if ( cf->isEnabled()&& cf->showCategories()) {
1127 todo->setCategories(cf->categoryList()); 1136 todo->setCategories(cf->categoryList());
1128 } 1137 }
1129 if ( cf->isEnabled() ) 1138 if ( cf->isEnabled() )
1130 todo->setSecrecy( cf->getSecrecy()); 1139 todo->setSecrecy( cf->getSecrecy());
1131 } 1140 }
1132 mCalendar->addTodo(todo); 1141 mCalendar->addTodo(todo);
1133 mQuickAdd->setText(""); 1142 mQuickAdd->setText("");
1134 todoModified (todo, KOGlobals::EVENTADDED ); 1143 todoModified (todo, KOGlobals::EVENTADDED );
1135 updateView(); 1144 updateView();
1136} 1145}
1137void KOTodoView::keyPressEvent ( QKeyEvent * e ) 1146void KOTodoView::keyPressEvent ( QKeyEvent * e )
1138{ 1147{
1139 // e->ignore(); 1148 // e->ignore();
1140 //return; 1149 //return;
1141 //qDebug("KOTodoView::keyPressEvent "); 1150 //qDebug("KOTodoView::keyPressEvent ");
1142 switch ( e->key() ) { 1151 switch ( e->key() ) {
1143 case Qt::Key_Down: 1152 case Qt::Key_Down:
1144 case Qt::Key_Up: 1153 case Qt::Key_Up:
1145 QWidget::keyPressEvent ( e ); 1154 QWidget::keyPressEvent ( e );
1146 break; 1155 break;
1147 1156
1148 case Qt::Key_Q: 1157 case Qt::Key_Q:
1149 toggleQuickTodo(); 1158 toggleQuickTodo();
1150 break; 1159 break;
1151 case Qt::Key_U: 1160 case Qt::Key_U:
1152 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1161 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1153 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1162 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1154 unparentTodo(); 1163 unparentTodo();
1155 e->accept(); 1164 e->accept();
1156 } else 1165 } else
1157 e->ignore(); 1166 e->ignore();
1158 break; 1167 break;
1159 case Qt::Key_S: 1168 case Qt::Key_S:
1160 if ( e->state() == Qt::ControlButton ) { 1169 if ( e->state() == Qt::ControlButton ) {
1161 e->ignore(); 1170 e->ignore();
1162 break; 1171 break;
1163 } 1172 }
1164 if ( e->state() == Qt::ShiftButton ) { 1173 if ( e->state() == Qt::ShiftButton ) {
1165 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1174 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1166 reparentTodo(); 1175 reparentTodo();
1167 e->accept(); 1176 e->accept();
1168 } else 1177 } else
1169 e->ignore(); 1178 e->ignore();
1170 break; 1179 break;
1171 case Qt::Key_P: 1180 case Qt::Key_P:
1172 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1181 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1173 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1182 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1174 if ( pendingSubtodo ) 1183 if ( pendingSubtodo )
1175 itemClicked(mActiveItem); 1184 itemClicked(mActiveItem);
1176 e->accept(); 1185 e->accept();
1177 } else 1186 } else
1178 e->ignore(); 1187 e->ignore();
1179 break; 1188 break;
1180 case Qt::Key_Escape: 1189 case Qt::Key_Escape:
1181 if ( pendingSubtodo ) { 1190 if ( pendingSubtodo ) {
1182 itemClicked(0); 1191 itemClicked(0);
1183 e->accept(); 1192 e->accept();
1184 } else 1193 } else
1185 e->ignore(); 1194 e->ignore();
1186 break; 1195 break;
1187 default: 1196 default:
1188 e->ignore(); 1197 e->ignore();
1189 } 1198 }
1190 1199
1191 if ( true ) { 1200 if ( true ) {
1192 if ( e->key() == Qt::Key_I ) { 1201 if ( e->key() == Qt::Key_I ) {
1193 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem(); 1202 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem();
1194 if ( cn ) { 1203 if ( cn ) {
1195 mActiveItem = cn; 1204 mActiveItem = cn;
1196 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 1205 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
1197 if ( ci ){ 1206 if ( ci ){
1198 showTodo(); 1207 showTodo();
1199 cn = (KOTodoViewItem*)cn->itemBelow(); 1208 cn = (KOTodoViewItem*)cn->itemBelow();
1200 if ( cn ) { 1209 if ( cn ) {
1201 mTodoListView->setCurrentItem ( cn ); 1210 mTodoListView->setCurrentItem ( cn );
1202 mTodoListView->ensureItemVisible ( cn ); 1211 mTodoListView->ensureItemVisible ( cn );
1203 } 1212 }
1204 1213
1205 } 1214 }
1206 } 1215 }
1207 e->accept(); 1216 e->accept();
1208 1217
1209 } 1218 }
1210 1219
1211 } 1220 }
1212 1221
1213} 1222}
1214void KOTodoView::updateTodo( Todo * t, int type ) 1223void KOTodoView::updateTodo( Todo * t, int type )
1215{ 1224{
1216 if ( mBlockUpdate) 1225 if ( mBlockUpdate)
1217 return; 1226 return;
1218 1227
1219 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 1228 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
1220 itemIterator = mTodoMap.find(t); 1229 itemIterator = mTodoMap.find(t);
1221 if (itemIterator != mTodoMap.end()) { 1230 if (itemIterator != mTodoMap.end()) {
1222 (*itemIterator)->construct(); 1231 (*itemIterator)->construct();
1223 } else { 1232 } else {
1224 if ( type == KOGlobals::EVENTADDED ) { 1233 if ( type == KOGlobals::EVENTADDED ) {
1225 insertTodoItem( t ); 1234 insertTodoItem( t );
1226 } 1235 }
1227 } 1236 }
1228 1237
1229} 1238}
1230 1239
1231void KOTodoView::todoModified(Todo * t , int p ) 1240void KOTodoView::todoModified(Todo * t , int p )
1232{ 1241{
1233 mBlockUpdate = true; 1242 mBlockUpdate = true;
1234 emit todoModifiedSignal ( t, p ); 1243 emit todoModifiedSignal ( t, p );
1235 mBlockUpdate = false; 1244 mBlockUpdate = false;
1236} 1245}
diff --git a/korganizer/kotodoviewitem.cpp b/korganizer/kotodoviewitem.cpp
index 2822237..1edddac 100644
--- a/korganizer/kotodoviewitem.cpp
+++ b/korganizer/kotodoviewitem.cpp
@@ -1,456 +1,464 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <klocale.h> 20#include <klocale.h>
21#include <kdebug.h> 21#include <kdebug.h>
22#include <qapp.h> 22#include <qapp.h>
23 23
24#include <kiconloader.h> 24#include <kiconloader.h>
25#include "kotodoviewitem.h" 25#include "kotodoviewitem.h"
26#include "kotodoview.h" 26#include "kotodoview.h"
27#include "koprefs.h" 27#include "koprefs.h"
28 28
29KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo) 29KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo)
30 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) 30 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
31{ 31{
32 construct(); 32 construct();
33} 33}
34 34
35KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo ) 35KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo )
36 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) 36 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
37{ 37{
38 construct(); 38 construct();
39} 39}
40 40
41QString KOTodoViewItem::key(int column,bool) const 41QString KOTodoViewItem::key(int column,bool) const
42{ 42{
43 QMap<int,QString>::ConstIterator it = mKeyMap.find(column); 43 QMap<int,QString>::ConstIterator it = mKeyMap.find(column);
44 if (it == mKeyMap.end()) { 44 if (it == mKeyMap.end()) {
45 return text(column).lower(); 45 return text(column).lower();
46 } else { 46 } else {
47 return *it; 47 return *it;
48 } 48 }
49} 49}
50 50
51void KOTodoViewItem:: setup() 51void KOTodoViewItem:: setup()
52{ 52{
53 53
54 int h = 20; 54 int h = 20;
55 if ( listView () ) { 55 if ( listView () ) {
56 QFontMetrics fm ( listView ()->font () ); 56 QFontMetrics fm ( listView ()->font () );
57 h = fm.height(); 57 h = fm.height();
58 } 58 }
59 setHeight( h ); 59 setHeight( h );
60 60
61} 61}
62void KOTodoViewItem::setSortKey(int column,const QString &key) 62void KOTodoViewItem::setSortKey(int column,const QString &key)
63{ 63{
64 mKeyMap.insert(column,key); 64 mKeyMap.insert(column,key);
65} 65}
66 66
67#if QT_VERSION >= 0x030000 67#if QT_VERSION >= 0x030000
68void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w, 68void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w,
69 int y,int h) 69 int y,int h)
70{ 70{
71 QListViewItem::paintBranches(p,cg,w,y,h); 71 QListViewItem::paintBranches(p,cg,w,y,h);
72} 72}
73#else 73#else
74#endif 74#endif
75 75
76void KOTodoViewItem::construct() 76void KOTodoViewItem::construct()
77{ 77{
78 // qDebug("KOTodoViewItem::construct() "); 78 // qDebug("KOTodoViewItem::construct() ");
79 m_init = true; 79 m_init = true;
80 QString keyd = "=="; 80 QString keyd = "==";
81 QString keyt = "=="; 81 QString keyt = "==";
82 QString skeyd = "=="; 82 QString skeyd = "==";
83 QString skeyt = "=="; 83 QString skeyt = "==";
84 84
85 setOn(mTodo->isCompleted()); 85 setOn(mTodo->isCompleted());
86 setText(0,mTodo->summary()); 86 setText(0,mTodo->summary());
87 setText(1,QString::number(mTodo->priority())); 87 setText(1,QString::number(mTodo->priority()));
88 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); 88 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
89 if (mTodo->percentComplete()<100) { 89 if (mTodo->percentComplete()<100) {
90 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 90 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
91 else setSortKey(2,QString::number(mTodo->percentComplete())); 91 else setSortKey(2,QString::number(mTodo->percentComplete()));
92 } 92 }
93 else { 93 else {
94 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 94 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
95 else setSortKey(2,QString::number(99)); 95 else setSortKey(2,QString::number(99));
96 } 96 }
97 if (mTodo->hasDueDate()) { 97 if (mTodo->hasDueDate()) {
98 setText(3, mTodo->dtDueDateStr()); 98 setText(3, mTodo->dtDueDateStr());
99 QDate d = mTodo->dtDue().date(); 99 QDate d = mTodo->dtDue().date();
100 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 100 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
101 // setSortKey(3,keyd); 101 // setSortKey(3,keyd);
102 if (mTodo->doesFloat()) { 102 if (mTodo->doesFloat()) {
103 setText(4,""); 103 setText(4,"");
104 } 104 }
105 else { 105 else {
106 setText(4,mTodo->dtDueTimeStr()); 106 setText(4,mTodo->dtDueTimeStr());
107 QTime t = mTodo->dtDue().time(); 107 QTime t = mTodo->dtDue().time();
108 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 108 keyt.sprintf("%02d%02d",t.hour(),t.minute());
109 //setSortKey(4,keyt); 109 //setSortKey(4,keyt);
110 } 110 }
111 } else { 111 } else {
112 setText(3,""); 112 setText(3,"");
113 setText(4,""); 113 setText(4,"");
114 } 114 }
115 setSortKey(3,keyd); 115 setSortKey(3,keyd);
116 setSortKey(4,keyt); 116 setSortKey(4,keyt);
117 117
118 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt); 118 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt);
119 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 119 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
120 120
121 121
122 122
123 if (mTodo->hasStartDate()) { 123 if (mTodo->hasStartDate()) {
124 setText(5, mTodo->dtStartDateStr()); 124 setText(5, mTodo->dtStartDateStr());
125 QDate d = mTodo->dtStart().date(); 125 QDate d = mTodo->dtStart().date();
126 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 126 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
127 127
128 if (mTodo->doesFloat()) { 128 if (mTodo->doesFloat()) {
129 setText(6,""); 129 setText(6,"");
130 } 130 }
131 else { 131 else {
132 setText(6,mTodo->dtStartTimeStr()); 132 setText(6,mTodo->dtStartTimeStr());
133 QTime t = mTodo->dtStart().time(); 133 QTime t = mTodo->dtStart().time();
134 skeyt.sprintf("%02d%02d",t.hour(),t.minute()); 134 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
135 135
136 } 136 }
137 } else { 137 } else {
138 setText(5,""); 138 setText(5,"");
139 setText(6,""); 139 setText(6,"");
140 } 140 }
141 setSortKey(5,skeyd); 141 setSortKey(5,skeyd);
142 setSortKey(6,skeyt); 142 setSortKey(6,skeyt);
143 143
144 setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No")); 144 setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No"));
145 setText(8,mTodo->categoriesStr()); 145 setText(8,mTodo->categoriesStr());
146 146
147#if 0 147#if 0
148 // Find sort id in description. It's the text behind the last '#' character 148 // Find sort id in description. It's the text behind the last '#' character
149 // found in the description. White spaces are removed from beginning and end 149 // found in the description. White spaces are removed from beginning and end
150 // of sort id. 150 // of sort id.
151 int pos = mTodo->description().findRev('#'); 151 int pos = mTodo->description().findRev('#');
152 if (pos < 0) { 152 if (pos < 0) {
153 setText(6,""); 153 setText(6,"");
154 } else { 154 } else {
155 QString str = mTodo->description().mid(pos+1); 155 QString str = mTodo->description().mid(pos+1);
156 str.stripWhiteSpace(); 156 str.stripWhiteSpace();
157 setText(6,str); 157 setText(6,str);
158 } 158 }
159#endif 159#endif
160 160
161 m_known = false; 161 m_known = false;
162 m_init = false; 162 m_init = false;
163 163
164 setMyPixmap(); 164 setMyPixmap();
165 165
166} 166}
167void KOTodoViewItem::setMyPixmap() 167void KOTodoViewItem::setMyPixmap()
168{ 168{
169 int size = 5; 169 int size = 5;
170 QPixmap pixi = QPixmap( 1, 1 ); 170 QPixmap pixi = QPixmap( 1, 1 );
171 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) { 171 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) {
172// pixi = SmallIcon("redcross16"); 172// pixi = SmallIcon("redcross16");
173// } else { 173// } else {
174 QPainter p; 174 QPainter p;
175 175
176 int pixSize = 0; 176 int pixSize = 0;
177 QPixmap pPix = QPixmap( size, size ); 177 QPixmap pPix = QPixmap( size, size );
178 if ( mTodo->description().length() > 0 ) { 178 if ( mTodo->description().length() > 0 ) {
179 pixi.resize(size, pixSize+size); 179 pixi.resize(size, pixSize+size);
180 pPix.fill( Qt::darkGreen ); 180 pPix.fill( Qt::darkGreen );
181 p.begin( &pixi ); 181 p.begin( &pixi );
182 p. drawPixmap ( 0, pixSize, pPix); 182 p. drawPixmap ( 0, pixSize, pPix);
183 p.end(); 183 p.end();
184 pixSize += size; 184 pixSize += size;
185 } 185 }
186 if ( mTodo->isAlarmEnabled() ) { 186 if ( mTodo->isAlarmEnabled() ) {
187 pixi.resize(size, pixSize+size); 187 pixi.resize(size, pixSize+size);
188 pPix.fill( Qt::red ); 188 pPix.fill( Qt::red );
189 p.begin( &pixi ); 189 p.begin( &pixi );
190 p. drawPixmap ( 0, pixSize, pPix); 190 p. drawPixmap ( 0, pixSize, pPix);
191 p.end(); 191 p.end();
192 pixSize += size; 192 pixSize += size;
193 } 193 }
194 // } 194 // }
195 if ( pixi.width() > 1 ) { 195 if ( pixi.width() > 1 ) {
196 setPixmap ( 0,pixi ) ; 196 setPixmap ( 0,pixi ) ;
197 } else { 197 } else {
198 setPixmap ( 0,QPixmap() ) ; 198 setPixmap ( 0,QPixmap() ) ;
199 } 199 }
200} 200}
201void KOTodoViewItem::stateChange(bool state) 201void KOTodoViewItem::stateChange(bool state)
202{ 202{
203 // qDebug("KOTodoViewItem::stateChange "); 203 // qDebug("KOTodoViewItem::stateChange ");
204 // do not change setting on startup 204 // do not change setting on startup
205 if ( m_init ) return; 205 if ( m_init ) return;
206 qDebug("KOTodoViewItem::stateChange "); 206 if (isOn()!=state) {
207 setOn(state);
208 //qDebug("SETON ");
209 return;
210 }
207 QString keyd = "=="; 211 QString keyd = "==";
208 QString keyt = "=="; 212 QString keyt = "==";
209 213 //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1());
210 mTodo->setCompleted(state); 214 mTodo->setCompleted(state);
211 if (state) mTodo->setCompleted(QDateTime::currentDateTime()); 215 if (state) mTodo->setCompleted(QDateTime::currentDateTime());
212 if (isOn()!=state) {
213 setOn(state);
214 }
215 216
216 if (mTodo->hasDueDate()) { 217 if (mTodo->hasDueDate()) {
217 setText(3, mTodo->dtDueDateStr()); 218 setText(3, mTodo->dtDueDateStr());
218 QDate d = mTodo->dtDue().date(); 219 QDate d = mTodo->dtDue().date();
219 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 220 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
220 setSortKey(3,keyd); 221 setSortKey(3,keyd);
221 if (mTodo->doesFloat()) { 222 if (mTodo->doesFloat()) {
222 setText(4,""); 223 setText(4,"");
223 } 224 }
224 else { 225 else {
225 setText(4,mTodo->dtDueTimeStr()); 226 setText(4,mTodo->dtDueTimeStr());
226 QTime t = mTodo->dtDue().time(); 227 QTime t = mTodo->dtDue().time();
227 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 228 keyt.sprintf("%02d%02d",t.hour(),t.minute());
228 setSortKey(4,keyt); 229 setSortKey(4,keyt);
229 } 230 }
230 } 231 }
231 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt); 232 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt);
232 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 233 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
233 234
234 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); 235 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
235 if (mTodo->percentComplete()<100) { 236 if (mTodo->percentComplete()<100) {
236 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 237 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
237 else setSortKey(2,QString::number(mTodo->percentComplete())); 238 else setSortKey(2,QString::number(mTodo->percentComplete()));
238 } 239 }
239 else { 240 else {
240 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 241 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
241 else setSortKey(2,QString::number(99)); 242 else setSortKey(2,QString::number(99));
242 } 243 }
243 QListViewItem * myChild = firstChild(); 244 if ( state ) {
244 KOTodoViewItem *item; 245 QListViewItem * myChild = firstChild();
245 while( myChild ) { 246 KOTodoViewItem *item;
246 item = static_cast<KOTodoViewItem*>(myChild); 247 while( myChild ) {
247 item->stateChange(state); 248 //qDebug("stateCH ");
248 myChild = myChild->nextSibling(); 249 item = static_cast<KOTodoViewItem*>(myChild);
250 item->stateChange(state);
251 myChild = myChild->nextSibling();
252 }
253 } else {
254 QListViewItem * myChild = parent();
255 if ( myChild )
256 (static_cast<KOTodoViewItem*>(myChild))->stateChange(state);
249 } 257 }
250 mTodoView->modified(true); 258 mTodoView->modified(true);
251 setMyPixmap(); 259 setMyPixmap();
252 mTodoView->setTodoModified( mTodo ); 260 mTodoView->setTodoModified( mTodo );
253} 261}
254 262
255bool KOTodoViewItem::isAlternate() 263bool KOTodoViewItem::isAlternate()
256{ 264{
257#ifndef KORG_NOLVALTERNATION 265#ifndef KORG_NOLVALTERNATION
258 KOTodoListView *lv = static_cast<KOTodoListView *>(listView()); 266 KOTodoListView *lv = static_cast<KOTodoListView *>(listView());
259 if (lv && lv->alternateBackground().isValid()) 267 if (lv && lv->alternateBackground().isValid())
260 { 268 {
261 KOTodoViewItem *above = 0; 269 KOTodoViewItem *above = 0;
262 above = dynamic_cast<KOTodoViewItem *>(itemAbove()); 270 above = dynamic_cast<KOTodoViewItem *>(itemAbove());
263 m_known = above ? above->m_known : true; 271 m_known = above ? above->m_known : true;
264 if (m_known) 272 if (m_known)
265 { 273 {
266 m_odd = above ? !above->m_odd : false; 274 m_odd = above ? !above->m_odd : false;
267 } 275 }
268 else 276 else
269 { 277 {
270 KOTodoViewItem *item; 278 KOTodoViewItem *item;
271 bool previous = true; 279 bool previous = true;
272 if (QListViewItem::parent()) 280 if (QListViewItem::parent())
273 { 281 {
274 item = dynamic_cast<KOTodoViewItem *>(QListViewItem::parent()); 282 item = dynamic_cast<KOTodoViewItem *>(QListViewItem::parent());
275 if (item) 283 if (item)
276 previous = item->m_odd; 284 previous = item->m_odd;
277 item = dynamic_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild()); 285 item = dynamic_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild());
278 } 286 }
279 else 287 else
280 { 288 {
281 item = dynamic_cast<KOTodoViewItem *>(lv->firstChild()); 289 item = dynamic_cast<KOTodoViewItem *>(lv->firstChild());
282 } 290 }
283 291
284 while(item) 292 while(item)
285 { 293 {
286 item->m_odd = previous = !previous; 294 item->m_odd = previous = !previous;
287 item->m_known = true; 295 item->m_known = true;
288 item = dynamic_cast<KOTodoViewItem *>(item->nextSibling()); 296 item = dynamic_cast<KOTodoViewItem *>(item->nextSibling());
289 } 297 }
290 } 298 }
291 return m_odd; 299 return m_odd;
292 } 300 }
293 return false; 301 return false;
294#else 302#else
295 return false; 303 return false;
296#endif 304#endif
297} 305}
298 306
299void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 307void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
300{ 308{
301 QColorGroup _cg = cg; 309 QColorGroup _cg = cg;
302 QColorGroup::ColorRole role; 310 QColorGroup::ColorRole role;
303 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor ) 311 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor )
304 role = QColorGroup::Text; 312 role = QColorGroup::Text;
305 else 313 else
306 role = QColorGroup::Base; 314 role = QColorGroup::Base;
307 //#ifndef KORG_NOLVALTERNATION 315 //#ifndef KORG_NOLVALTERNATION
308 // if (isAlternate()) 316 // if (isAlternate())
309 // _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground()); 317 // _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground());
310 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors; 318 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors;
311 QColor colorToSet; 319 QColor colorToSet;
312 if ( setColor ) { 320 if ( setColor ) {
313 QStringList categories = mTodo->categories(); 321 QStringList categories = mTodo->categories();
314 QString cat = categories.first(); 322 QString cat = categories.first();
315 if ( !cat.isEmpty()) { 323 if ( !cat.isEmpty()) {
316 colorToSet = *(KOPrefs::instance()->categoryColor(cat) ); 324 colorToSet = *(KOPrefs::instance()->categoryColor(cat) );
317 } else 325 } else
318 setColor = false; 326 setColor = false;
319 } 327 }
320 if (mTodo->hasDueDate()) { 328 if (mTodo->hasDueDate()) {
321 if (mTodo->dtDue().date()==QDate::currentDate() && 329 if (mTodo->dtDue().date()==QDate::currentDate() &&
322 !mTodo->isCompleted()) { 330 !mTodo->isCompleted()) {
323 //_cg.setColor( role , KOPrefs::instance()->mTodoDueTodayColor); 331 //_cg.setColor( role , KOPrefs::instance()->mTodoDueTodayColor);
324 colorToSet = KOPrefs::instance()->mTodoDueTodayColor; 332 colorToSet = KOPrefs::instance()->mTodoDueTodayColor;
325 setColor = true; 333 setColor = true;
326 } 334 }
327 if (mTodo->dtDue().date() < QDate::currentDate() && 335 if (mTodo->dtDue().date() < QDate::currentDate() &&
328 !mTodo->isCompleted()) { 336 !mTodo->isCompleted()) {
329 //_cg.setColor( role, KOPrefs::instance()->mTodoOverdueColor); 337 //_cg.setColor( role, KOPrefs::instance()->mTodoOverdueColor);
330 colorToSet = KOPrefs::instance()->mTodoOverdueColor; 338 colorToSet = KOPrefs::instance()->mTodoOverdueColor;
331 setColor = true; 339 setColor = true;
332 } 340 }
333 } 341 }
334 342
335 if ( setColor ) { 343 if ( setColor ) {
336 _cg.setColor(role,colorToSet ); 344 _cg.setColor(role,colorToSet );
337 if ( role == QColorGroup::Base) { 345 if ( role == QColorGroup::Base) {
338 int rgb = colorToSet.red(); 346 int rgb = colorToSet.red();
339 rgb += colorToSet.blue()/2; 347 rgb += colorToSet.blue()/2;
340 rgb += colorToSet.green(); 348 rgb += colorToSet.green();
341 if ( rgb < 200 ) 349 if ( rgb < 200 )
342 _cg.setColor(QColorGroup::Text,Qt::white ); 350 _cg.setColor(QColorGroup::Text,Qt::white );
343 } 351 }
344 } 352 }
345 //#endif 353 //#endif
346 if ( column > 0 ){ 354 if ( column > 0 ){
347 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) { 355 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) {
348 p->save(); 356 p->save();
349 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5); 357 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5);
350 358
351 p->fillRect( 0, 0, width, height(), _cg.base() ); // background 359 p->fillRect( 0, 0, width, height(), _cg.base() ); // background
352 // p->setPen(Qt::black ); //border 360 // p->setPen(Qt::black ); //border
353 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling 361 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling
354 QColor fc = KOPrefs::instance()->mHighlightColor; 362 QColor fc = KOPrefs::instance()->mHighlightColor;
355 if ( mTodo->percentComplete() == 100 ) 363 if ( mTodo->percentComplete() == 100 )
356 fc = darkGreen; 364 fc = darkGreen;
357 p->drawRect( 2, 2, width-4, height()-4); 365 p->drawRect( 2, 2, width-4, height()-4);
358 p->fillRect( 3, 3, progress, height()-6, 366 p->fillRect( 3, 3, progress, height()-6,
359 fc ); 367 fc );
360 p->restore(); 368 p->restore();
361 } else { 369 } else {
362 QCheckListItem::paintCell(p, _cg, column, width, alignment); 370 QCheckListItem::paintCell(p, _cg, column, width, alignment);
363 } 371 }
364 return; 372 return;
365 } 373 }
366 374
367 int align = alignment; 375 int align = alignment;
368 376
369 if ( !p ) 377 if ( !p )
370 return; 378 return;
371 379
372 p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) ); 380 p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) );
373 381
374 QListView *lv = listView(); 382 QListView *lv = listView();
375 if ( !lv ) 383 if ( !lv )
376 return; 384 return;
377 int marg = 2;//lv->itemMargin(); 385 int marg = 2;//lv->itemMargin();
378 int r = 0; 386 int r = 0;
379 QCheckListItem::Type myType = QCheckListItem::CheckBox; 387 QCheckListItem::Type myType = QCheckListItem::CheckBox;
380 int BoxSize = 20; 388 int BoxSize = 20;
381 int boxOffset = 2; 389 int boxOffset = 2;
382 int xOffset = 2; 390 int xOffset = 2;
383 if (qApp->desktop()->width() < 300 ) { 391 if (qApp->desktop()->width() < 300 ) {
384 BoxSize = 14; 392 BoxSize = 14;
385 boxOffset = -1; 393 boxOffset = -1;
386 xOffset = 1; 394 xOffset = 1;
387 // marg = 0; 395 // marg = 0;
388 } 396 }
389 if ( height() < BoxSize ) { 397 if ( height() < BoxSize ) {
390 boxOffset = boxOffset - ((BoxSize - height())/2) ; 398 boxOffset = boxOffset - ((BoxSize - height())/2) ;
391 // qDebug("boxOffset %d height %d", boxOffset, height() ); 399 // qDebug("boxOffset %d height %d", boxOffset, height() );
392 BoxSize = height(); 400 BoxSize = height();
393 401
394 } 402 }
395 //bool winStyle = lv->style() == WindowsStyle; 403 //bool winStyle = lv->style() == WindowsStyle;
396 404
397 int lineStart = 5; 405 int lineStart = 5;
398 if ( myType == Controller ) { 406 if ( myType == Controller ) {
399 if ( !pixmap( 0 ) ) 407 if ( !pixmap( 0 ) )
400 r += BoxSize + 4; 408 r += BoxSize + 4;
401 } else { 409 } else {
402 ASSERT( lv ); //### 410 ASSERT( lv ); //###
403 //QFontMetrics fm( lv->font() ); 411 //QFontMetrics fm( lv->font() );
404 //int d = fm.height(); 412 //int d = fm.height();
405 int x = 0; 413 int x = 0;
406 int y = (height() - BoxSize) / 2; 414 int y = (height() - BoxSize) / 2;
407 //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) ); 415 //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) );
408 if ( myType == CheckBox ) { 416 if ( myType == CheckBox ) {
409 if ( isEnabled() ) 417 if ( isEnabled() )
410 p->setPen( QPen( _cg.text(), 1 ) ); 418 p->setPen( QPen( _cg.text(), 1 ) );
411 else 419 else
412 p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) ); 420 p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) );
413 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 ); 421 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 );
414 lineStart = x+marg; 422 lineStart = x+marg;
415 ///////////////////// 423 /////////////////////
416 x++; 424 x++;
417 y++; 425 y++;
418 if ( isOn() ) { 426 if ( isOn() ) {
419 QPointArray a( 7*2 ); 427 QPointArray a( 7*2 );
420 int i, xx, yy; 428 int i, xx, yy;
421 xx = x+xOffset+marg+(boxOffset/2); 429 xx = x+xOffset+marg+(boxOffset/2);
422 yy = y+5+boxOffset; 430 yy = y+5+boxOffset;
423 for ( i=0; i<3; i++ ) { 431 for ( i=0; i<3; i++ ) {
424 a.setPoint( 2*i, xx, yy ); 432 a.setPoint( 2*i, xx, yy );
425 a.setPoint( 2*i+1, xx, yy+2 ); 433 a.setPoint( 2*i+1, xx, yy+2 );
426 // qDebug(" "); 434 // qDebug(" ");
427 xx++; yy++; 435 xx++; yy++;
428 } 436 }
429 yy -= 2; 437 yy -= 2;
430 for ( i=3; i<7; i++ ) { 438 for ( i=3; i<7; i++ ) {
431 a.setPoint( 2*i, xx, yy ); 439 a.setPoint( 2*i, xx, yy );
432 a.setPoint( 2*i+1, xx, yy+2 ); 440 a.setPoint( 2*i+1, xx, yy+2 );
433 xx++; yy--; 441 xx++; yy--;
434 } 442 }
435 p->setPen( darkGreen ); 443 p->setPen( darkGreen );
436 p->drawLineSegments( a ); 444 p->drawLineSegments( a );
437 } 445 }
438 //////////////////////// 446 ////////////////////////
439 } 447 }
440 r += BoxSize + 4; 448 r += BoxSize + 4;
441 } 449 }
442 450
443 p->translate( r, 0 ); 451 p->translate( r, 0 );
444 p->setPen( QPen( _cg.text() ) ); 452 p->setPen( QPen( _cg.text() ) );
445 QListViewItem::paintCell( p, _cg, column, width - r, align ); 453 QListViewItem::paintCell( p, _cg, column, width - r, align );
446 if ( mTodo->cancelled () ) { 454 if ( mTodo->cancelled () ) {
447 p->setPen( black ); 455 p->setPen( black );
448 QRect br = p->boundingRect( 1,1,1,1,0,mTodo->summary() ); 456 QRect br = p->boundingRect( 1,1,1,1,0,mTodo->summary() );
449 int wid = br.width() +lineStart; 457 int wid = br.width() +lineStart;
450 if ( wid > width-3 ) 458 if ( wid > width-3 )
451 wid = width-3; 459 wid = width-3;
452 p->drawLine( lineStart, height()/2+1, wid, height()/2+1 ); 460 p->drawLine( lineStart, height()/2+1, wid, height()/2+1 );
453 461
454 } 462 }
455 463
456} 464}
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 7d04793..7f1de78 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,380 +1,384 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24 24
25#include "todo.h" 25#include "todo.h"
26 26
27using namespace KCal; 27using namespace KCal;
28 28
29Todo::Todo(): Incidence() 29Todo::Todo(): Incidence()
30{ 30{
31// mStatus = TENTATIVE; 31// mStatus = TENTATIVE;
32 32
33 mHasDueDate = false; 33 mHasDueDate = false;
34 setHasStartDate( false ); 34 setHasStartDate( false );
35 mCompleted = getEvenTime(QDateTime::currentDateTime()); 35 mCompleted = getEvenTime(QDateTime::currentDateTime());
36 mHasCompletedDate = false; 36 mHasCompletedDate = false;
37 mPercentComplete = 0; 37 mPercentComplete = 0;
38} 38}
39 39
40Todo::Todo(const Todo &t) : Incidence(t) 40Todo::Todo(const Todo &t) : Incidence(t)
41{ 41{
42 mDtDue = t.mDtDue; 42 mDtDue = t.mDtDue;
43 mHasDueDate = t.mHasDueDate; 43 mHasDueDate = t.mHasDueDate;
44 mCompleted = t.mCompleted; 44 mCompleted = t.mCompleted;
45 mHasCompletedDate = t.mHasCompletedDate; 45 mHasCompletedDate = t.mHasCompletedDate;
46 mPercentComplete = t.mPercentComplete; 46 mPercentComplete = t.mPercentComplete;
47} 47}
48 48
49Todo::~Todo() 49Todo::~Todo()
50{ 50{
51 51
52} 52}
53 53
54Incidence *Todo::clone() 54Incidence *Todo::clone()
55{ 55{
56 return new Todo(*this); 56 return new Todo(*this);
57} 57}
58 58
59bool Todo::contains ( Todo* from ) 59bool Todo::contains ( Todo* from )
60{ 60{
61 61
62 if ( !from->summary().isEmpty() ) 62 if ( !from->summary().isEmpty() )
63 if ( !summary().startsWith( from->summary() )) 63 if ( !summary().startsWith( from->summary() ))
64 return false; 64 return false;
65 if ( from->hasStartDate() ) { 65 if ( from->hasStartDate() ) {
66 if ( !hasStartDate() ) 66 if ( !hasStartDate() )
67 return false; 67 return false;
68 if ( from->dtStart() != dtStart()) 68 if ( from->dtStart() != dtStart())
69 return false; 69 return false;
70 } 70 }
71 if ( from->hasDueDate() ){ 71 if ( from->hasDueDate() ){
72 if ( !hasDueDate() ) 72 if ( !hasDueDate() )
73 return false; 73 return false;
74 if ( from->dtDue() != dtDue()) 74 if ( from->dtDue() != dtDue())
75 return false; 75 return false;
76 } 76 }
77 if ( !from->location().isEmpty() ) 77 if ( !from->location().isEmpty() )
78 if ( !location().startsWith( from->location() ) ) 78 if ( !location().startsWith( from->location() ) )
79 return false; 79 return false;
80 if ( !from->description().isEmpty() ) 80 if ( !from->description().isEmpty() )
81 if ( !description().startsWith( from->description() )) 81 if ( !description().startsWith( from->description() ))
82 return false; 82 return false;
83 if ( from->alarms().count() ) { 83 if ( from->alarms().count() ) {
84 Alarm *a = from->alarms().first(); 84 Alarm *a = from->alarms().first();
85 if ( a->enabled() ){ 85 if ( a->enabled() ){
86 if ( !alarms().count() ) 86 if ( !alarms().count() )
87 return false; 87 return false;
88 Alarm *b = alarms().first(); 88 Alarm *b = alarms().first();
89 if( ! b->enabled() ) 89 if( ! b->enabled() )
90 return false; 90 return false;
91 if ( ! (a->offset() == b->offset() )) 91 if ( ! (a->offset() == b->offset() ))
92 return false; 92 return false;
93 } 93 }
94 } 94 }
95 95
96 QStringList cat = categories(); 96 QStringList cat = categories();
97 QStringList catFrom = from->categories(); 97 QStringList catFrom = from->categories();
98 QString nCat; 98 QString nCat;
99 int iii; 99 int iii;
100 for ( iii = 0; iii < catFrom.count();++iii ) { 100 for ( iii = 0; iii < catFrom.count();++iii ) {
101 nCat = catFrom[iii]; 101 nCat = catFrom[iii];
102 if ( !nCat.isEmpty() ) 102 if ( !nCat.isEmpty() )
103 if ( !cat.contains( nCat )) { 103 if ( !cat.contains( nCat )) {
104 return false; 104 return false;
105 } 105 }
106 } 106 }
107 if ( from->isCompleted() ) { 107 if ( from->isCompleted() ) {
108 if ( !isCompleted() ) 108 if ( !isCompleted() )
109 return false; 109 return false;
110 } 110 }
111 if( priority() != from->priority() ) 111 if( priority() != from->priority() )
112 return false; 112 return false;
113 113
114 114
115 return true; 115 return true;
116 116
117} 117}
118bool KCal::operator==( const Todo& t1, const Todo& t2 ) 118bool KCal::operator==( const Todo& t1, const Todo& t2 )
119{ 119{
120 120
121 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); 121 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
122 if ( ! ret ) 122 if ( ! ret )
123 return false; 123 return false;
124 if ( t1.hasDueDate() == t2.hasDueDate() ) { 124 if ( t1.hasDueDate() == t2.hasDueDate() ) {
125 if ( t1.hasDueDate() ) { 125 if ( t1.hasDueDate() ) {
126 if ( t1.doesFloat() == t2.doesFloat() ) { 126 if ( t1.doesFloat() == t2.doesFloat() ) {
127 if ( t1.doesFloat() ) { 127 if ( t1.doesFloat() ) {
128 if ( t1.dtDue().date() != t2.dtDue().date() ) 128 if ( t1.dtDue().date() != t2.dtDue().date() )
129 return false; 129 return false;
130 } else 130 } else
131 if ( t1.dtDue() != t2.dtDue() ) 131 if ( t1.dtDue() != t2.dtDue() )
132 return false; 132 return false;
133 } else 133 } else
134 return false;// float != 134 return false;// float !=
135 } 135 }
136 136
137 } else 137 } else
138 return false; 138 return false;
139 if ( t1.percentComplete() != t2.percentComplete() ) 139 if ( t1.percentComplete() != t2.percentComplete() )
140 return false; 140 return false;
141 if ( t1.isCompleted() ) { 141 if ( t1.isCompleted() ) {
142 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { 142 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) {
143 if ( t1.hasCompletedDate() ) { 143 if ( t1.hasCompletedDate() ) {
144 if ( t1.completed() != t2.completed() ) 144 if ( t1.completed() != t2.completed() )
145 return false; 145 return false;
146 } 146 }
147 147
148 } else 148 } else
149 return false; 149 return false;
150 } 150 }
151 return true; 151 return true;
152 152
153} 153}
154 154
155void Todo::setDtDue(const QDateTime &dtDue) 155void Todo::setDtDue(const QDateTime &dtDue)
156{ 156{
157 //int diffsecs = mDtDue.secsTo(dtDue); 157 //int diffsecs = mDtDue.secsTo(dtDue);
158 158
159 /*if (mReadOnly) return; 159 /*if (mReadOnly) return;
160 const QPtrList<Alarm>& alarms = alarms(); 160 const QPtrList<Alarm>& alarms = alarms();
161 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { 161 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
162 if (alarm->enabled()) { 162 if (alarm->enabled()) {
163 alarm->setTime(alarm->time().addSecs(diffsecs)); 163 alarm->setTime(alarm->time().addSecs(diffsecs));
164 } 164 }
165 }*/ 165 }*/
166 mDtDue = getEvenTime(dtDue); 166 mDtDue = getEvenTime(dtDue);
167 167
168 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 168 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
169 169
170 /*const QPtrList<Alarm>& alarms = alarms(); 170 /*const QPtrList<Alarm>& alarms = alarms();
171 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 171 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
172 alarm->setAlarmStart(mDtDue);*/ 172 alarm->setAlarmStart(mDtDue);*/
173 173
174 updated(); 174 updated();
175} 175}
176 176
177QDateTime Todo::dtDue() const 177QDateTime Todo::dtDue() const
178{ 178{
179 return mDtDue; 179 return mDtDue;
180} 180}
181 181
182QString Todo::dtDueTimeStr() const 182QString Todo::dtDueTimeStr() const
183{ 183{
184 return KGlobal::locale()->formatTime(mDtDue.time()); 184 return KGlobal::locale()->formatTime(mDtDue.time());
185} 185}
186 186
187QString Todo::dtDueDateStr(bool shortfmt) const 187QString Todo::dtDueDateStr(bool shortfmt) const
188{ 188{
189 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 189 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
190} 190}
191 191
192QString Todo::dtDueStr(bool shortfmt) const 192QString Todo::dtDueStr(bool shortfmt) const
193{ 193{
194 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 194 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
195} 195}
196 196
197bool Todo::hasDueDate() const 197bool Todo::hasDueDate() const
198{ 198{
199 return mHasDueDate; 199 return mHasDueDate;
200} 200}
201 201
202void Todo::setHasDueDate(bool f) 202void Todo::setHasDueDate(bool f)
203{ 203{
204 if (mReadOnly) return; 204 if (mReadOnly) return;
205 mHasDueDate = f; 205 mHasDueDate = f;
206 updated(); 206 updated();
207} 207}
208 208
209 209
210#if 0 210#if 0
211void Todo::setStatus(const QString &statStr) 211void Todo::setStatus(const QString &statStr)
212{ 212{
213 if (mReadOnly) return; 213 if (mReadOnly) return;
214 QString ss(statStr.upper()); 214 QString ss(statStr.upper());
215 215
216 if (ss == "X-ACTION") 216 if (ss == "X-ACTION")
217 mStatus = NEEDS_ACTION; 217 mStatus = NEEDS_ACTION;
218 else if (ss == "NEEDS ACTION") 218 else if (ss == "NEEDS ACTION")
219 mStatus = NEEDS_ACTION; 219 mStatus = NEEDS_ACTION;
220 else if (ss == "ACCEPTED") 220 else if (ss == "ACCEPTED")
221 mStatus = ACCEPTED; 221 mStatus = ACCEPTED;
222 else if (ss == "SENT") 222 else if (ss == "SENT")
223 mStatus = SENT; 223 mStatus = SENT;
224 else if (ss == "TENTATIVE") 224 else if (ss == "TENTATIVE")
225 mStatus = TENTATIVE; 225 mStatus = TENTATIVE;
226 else if (ss == "CONFIRMED") 226 else if (ss == "CONFIRMED")
227 mStatus = CONFIRMED; 227 mStatus = CONFIRMED;
228 else if (ss == "DECLINED") 228 else if (ss == "DECLINED")
229 mStatus = DECLINED; 229 mStatus = DECLINED;
230 else if (ss == "COMPLETED") 230 else if (ss == "COMPLETED")
231 mStatus = COMPLETED; 231 mStatus = COMPLETED;
232 else if (ss == "DELEGATED") 232 else if (ss == "DELEGATED")
233 mStatus = DELEGATED; 233 mStatus = DELEGATED;
234 234
235 updated(); 235 updated();
236} 236}
237 237
238void Todo::setStatus(int status) 238void Todo::setStatus(int status)
239{ 239{
240 if (mReadOnly) return; 240 if (mReadOnly) return;
241 mStatus = status; 241 mStatus = status;
242 updated(); 242 updated();
243} 243}
244 244
245int Todo::status() const 245int Todo::status() const
246{ 246{
247 return mStatus; 247 return mStatus;
248} 248}
249 249
250QString Todo::statusStr() const 250QString Todo::statusStr() const
251{ 251{
252 switch(mStatus) { 252 switch(mStatus) {
253 case NEEDS_ACTION: 253 case NEEDS_ACTION:
254 return QString("NEEDS ACTION"); 254 return QString("NEEDS ACTION");
255 break; 255 break;
256 case ACCEPTED: 256 case ACCEPTED:
257 return QString("ACCEPTED"); 257 return QString("ACCEPTED");
258 break; 258 break;
259 case SENT: 259 case SENT:
260 return QString("SENT"); 260 return QString("SENT");
261 break; 261 break;
262 case TENTATIVE: 262 case TENTATIVE:
263 return QString("TENTATIVE"); 263 return QString("TENTATIVE");
264 break; 264 break;
265 case CONFIRMED: 265 case CONFIRMED:
266 return QString("CONFIRMED"); 266 return QString("CONFIRMED");
267 break; 267 break;
268 case DECLINED: 268 case DECLINED:
269 return QString("DECLINED"); 269 return QString("DECLINED");
270 break; 270 break;
271 case COMPLETED: 271 case COMPLETED:
272 return QString("COMPLETED"); 272 return QString("COMPLETED");
273 break; 273 break;
274 case DELEGATED: 274 case DELEGATED:
275 return QString("DELEGATED"); 275 return QString("DELEGATED");
276 break; 276 break;
277 } 277 }
278 return QString(""); 278 return QString("");
279} 279}
280#endif 280#endif
281 281
282bool Todo::isCompleted() const 282bool Todo::isCompleted() const
283{ 283{
284 if (mPercentComplete == 100) return true; 284 if (mPercentComplete == 100) return true;
285 else return false; 285 else return false;
286} 286}
287 287
288void Todo::setCompleted(bool completed) 288void Todo::setCompleted(bool completed)
289{ 289{
290 if (completed) mPercentComplete = 100; 290 if (completed) mPercentComplete = 100;
291 else { 291 else {
292 mPercentComplete = 0; 292 mPercentComplete = 0;
293 mHasCompletedDate = false; 293 mHasCompletedDate = false;
294 } 294 }
295 updated(); 295 updated();
296} 296}
297 297
298QDateTime Todo::completed() const 298QDateTime Todo::completed() const
299{ 299{
300 return mCompleted; 300 return mCompleted;
301} 301}
302 302
303QString Todo::completedStr( bool shortF ) const 303QString Todo::completedStr( bool shortF ) const
304{ 304{
305 return KGlobal::locale()->formatDateTime(mCompleted, shortF); 305 return KGlobal::locale()->formatDateTime(mCompleted, shortF);
306} 306}
307 307
308void Todo::setCompleted(const QDateTime &completed) 308void Todo::setCompleted(const QDateTime &completed)
309{ 309{
310 qDebug("Todo::setCompleted "); 310 //qDebug("Todo::setCompleted ");
311 if ( mHasCompletedDate ) {
312 // qDebug("has completed data - return ");
313 return;
314 }
311 mHasCompletedDate = true; 315 mHasCompletedDate = true;
312 mPercentComplete = 100; 316 mPercentComplete = 100;
313 mCompleted = getEvenTime(completed); 317 mCompleted = getEvenTime(completed);
314 updated(); 318 updated();
315} 319}
316 320
317bool Todo::hasCompletedDate() const 321bool Todo::hasCompletedDate() const
318{ 322{
319 return mHasCompletedDate; 323 return mHasCompletedDate;
320} 324}
321 325
322int Todo::percentComplete() const 326int Todo::percentComplete() const
323{ 327{
324 return mPercentComplete; 328 return mPercentComplete;
325} 329}
326 330
327void Todo::setPercentComplete(int v) 331void Todo::setPercentComplete(int v)
328{ 332{
329 mPercentComplete = v; 333 mPercentComplete = v;
330 if ( v != 100 ) 334 if ( v != 100 )
331 mHasCompletedDate = false; 335 mHasCompletedDate = false;
332 updated(); 336 updated();
333} 337}
334QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const 338QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const
335{ 339{
336 if ( isCompleted() || ! hasDueDate() || cancelled() ) { 340 if ( isCompleted() || ! hasDueDate() || cancelled() ) {
337 *ok = false; 341 *ok = false;
338 return QDateTime (); 342 return QDateTime ();
339 } 343 }
340 QDateTime incidenceStart; 344 QDateTime incidenceStart;
341 incidenceStart = dtDue(); 345 incidenceStart = dtDue();
342 bool enabled = false; 346 bool enabled = false;
343 Alarm* alarm; 347 Alarm* alarm;
344 int off; 348 int off;
345 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 349 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
346 // if ( QDateTime::currentDateTime() > incidenceStart ){ 350 // if ( QDateTime::currentDateTime() > incidenceStart ){
347// *ok = false; 351// *ok = false;
348// return incidenceStart; 352// return incidenceStart;
349// } 353// }
350 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 354 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
351 if (alarm->enabled()) { 355 if (alarm->enabled()) {
352 if ( alarm->hasTime () ) { 356 if ( alarm->hasTime () ) {
353 if ( alarm->time() < alarmStart ) { 357 if ( alarm->time() < alarmStart ) {
354 alarmStart = alarm->time(); 358 alarmStart = alarm->time();
355 enabled = true; 359 enabled = true;
356 off = alarmStart.secsTo( incidenceStart ); 360 off = alarmStart.secsTo( incidenceStart );
357 } 361 }
358 362
359 } else { 363 } else {
360 int secs = alarm->startOffset().asSeconds(); 364 int secs = alarm->startOffset().asSeconds();
361 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 365 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
362 alarmStart = incidenceStart.addSecs( secs ); 366 alarmStart = incidenceStart.addSecs( secs );
363 enabled = true; 367 enabled = true;
364 off = -secs; 368 off = -secs;
365 } 369 }
366 } 370 }
367 } 371 }
368 } 372 }
369 if ( enabled ) { 373 if ( enabled ) {
370 if ( alarmStart > QDateTime::currentDateTime() ) { 374 if ( alarmStart > QDateTime::currentDateTime() ) {
371 *ok = true; 375 *ok = true;
372 * offset = off; 376 * offset = off;
373 return alarmStart; 377 return alarmStart;
374 } 378 }
375 } 379 }
376 *ok = false; 380 *ok = false;
377 return QDateTime (); 381 return QDateTime ();
378 382
379} 383}
380 384