summaryrefslogtreecommitdiffabout
path: root/korganizer/kodaymatrix.cpp
Unidiff
Diffstat (limited to 'korganizer/kodaymatrix.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kodaymatrix.cpp1
1 files changed, 0 insertions, 1 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index ecca374..17a1d13 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -308,385 +308,384 @@ bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
308 } 308 }
309 309
310 return true; 310 return true;
311} 311}
312void KODayMatrix::clearSelection() 312void KODayMatrix::clearSelection()
313{ 313{
314 mSelEnd = mSelStart = NOSELECTION; 314 mSelEnd = mSelStart = NOSELECTION;
315} 315}
316 316
317 317
318void KODayMatrix::recalculateToday() 318void KODayMatrix::recalculateToday()
319{ 319{
320 today = -1; 320 today = -1;
321 for (int i=0; i<NUMDAYS; i++) { 321 for (int i=0; i<NUMDAYS; i++) {
322 //events[i] = 0; 322 //events[i] = 0;
323 days[i] = startdate.addDays(i); 323 days[i] = startdate.addDays(i);
324 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 324 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
325 325
326 // if today is in the currently displayed month, hilight today 326 // if today is in the currently displayed month, hilight today
327 if (days[i].year() == QDate::currentDate().year() && 327 if (days[i].year() == QDate::currentDate().year() &&
328 days[i].month() == QDate::currentDate().month() && 328 days[i].month() == QDate::currentDate().month() &&
329 days[i].day() == QDate::currentDate().day()) { 329 days[i].day() == QDate::currentDate().day()) {
330 today = i; 330 today = i;
331 } 331 }
332 } 332 }
333 // qDebug(QString("Today is visible at %1.").arg(today)); 333 // qDebug(QString("Today is visible at %1.").arg(today));
334} 334}
335 335
336void KODayMatrix::updateView() 336void KODayMatrix::updateView()
337{ 337{
338 updateView(startdate); 338 updateView(startdate);
339} 339}
340void KODayMatrix::repaintViewTimed() 340void KODayMatrix::repaintViewTimed()
341{ 341{
342 mRedrawNeeded = true; 342 mRedrawNeeded = true;
343 // bDays.fill( false); 343 // bDays.fill( false);
344 //pDays.fill( false); 344 //pDays.fill( false);
345 //hDays.fill( false); 345 //hDays.fill( false);
346 //eDays.fill( false); 346 //eDays.fill( false);
347 mRepaintTimer->stop(); 347 mRepaintTimer->stop();
348 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday 348 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday
349 int i; 349 int i;
350 for(i = 0; i < NUMDAYS; i++) { 350 for(i = 0; i < NUMDAYS; i++) {
351 if ( ( (i+startDay) % 7 == 0 ) ) { 351 if ( ( (i+startDay) % 7 == 0 ) ) {
352 pDays.setBit(i); 352 pDays.setBit(i);
353 } 353 }
354 } 354 }
355 repaint(false); 355 repaint(false);
356} 356}
357void KODayMatrix::computeEvent(Event *event, int i ) 357void KODayMatrix::computeEvent(Event *event, int i )
358{ 358{
359 QString holiStr = mHolidays[i]; 359 QString holiStr = mHolidays[i];
360 if ( event->isHoliday()) { 360 if ( event->isHoliday()) {
361 pDays.setBit(i); 361 pDays.setBit(i);
362 hDays.setBit(i); 362 hDays.setBit(i);
363 if ( !holiStr.isEmpty() ) 363 if ( !holiStr.isEmpty() )
364 holiStr += "\n"; 364 holiStr += "\n";
365 holiStr += event->summary(); 365 holiStr += event->summary();
366 if ( !event->location().isEmpty() ) 366 if ( !event->location().isEmpty() )
367 holiStr += " (" + event->location() + ")"; 367 holiStr += " (" + event->location() + ")";
368 mHolidays[i] =holiStr ; 368 mHolidays[i] =holiStr ;
369 } 369 }
370 if ( event->isBirthday()) { 370 if ( event->isBirthday()) {
371 pDays.setBit(i); 371 pDays.setBit(i);
372 if ( !holiStr.isEmpty() ) 372 if ( !holiStr.isEmpty() )
373 holiStr += "\n"; 373 holiStr += "\n";
374 holiStr += i18n("Birthday") + ": "+event->summary(); 374 holiStr += i18n("Birthday") + ": "+event->summary();
375 if ( !event->location().isEmpty() ) 375 if ( !event->location().isEmpty() )
376 holiStr += " (" + event->location() + ")"; 376 holiStr += " (" + event->location() + ")";
377 bDays.setBit(i); 377 bDays.setBit(i);
378 mHolidays[i] =holiStr ; 378 mHolidays[i] =holiStr ;
379 } 379 }
380 eDays.setBit(i); 380 eDays.setBit(i);
381} 381}
382void KODayMatrix::updateViewTimed() 382void KODayMatrix::updateViewTimed()
383{ 383{
384 mUpdateTimer->stop(); 384 mUpdateTimer->stop();
385 if ( !mCalendar ) { 385 if ( !mCalendar ) {
386 qDebug("NOT CAL "); 386 qDebug("NOT CAL ");
387 return; 387 return;
388 } 388 }
389#if 1 389#if 1
390 390
391 int i; 391 int i;
392 int timeSpan = NUMDAYS-1; 392 int timeSpan = NUMDAYS-1;
393 QPtrList<Event> events = mCalendar->events(); 393 QPtrList<Event> events = mCalendar->events();
394 Event *event; 394 Event *event;
395 QDateTime dt; 395 QDateTime dt;
396 bool ok; 396 bool ok;
397 bDays.fill( false); 397 bDays.fill( false);
398 pDays.fill( false); 398 pDays.fill( false);
399 hDays.fill( false); 399 hDays.fill( false);
400 eDays.fill( false); 400 eDays.fill( false);
401 mHolidays.clear(); 401 mHolidays.clear();
402 QDate mStartDate = days[0]; 402 QDate mStartDate = days[0];
403 QDate endDate = mStartDate.addDays( timeSpan ); 403 QDate endDate = mStartDate.addDays( timeSpan );
404 for( event = events.first(); event; event = events.next() ) { // for event 404 for( event = events.first(); event; event = events.next() ) { // for event
405 ushort recurType = event->recurrence()->doesRecur(); 405 ushort recurType = event->recurrence()->doesRecur();
406 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 406 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
407 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 407 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
408 continue; 408 continue;
409 } 409 }
410 if ( event->doesRecur() ) { 410 if ( event->doesRecur() ) {
411 bool last; 411 bool last;
412 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); 412 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
413 QDateTime incidenceEnd; 413 QDateTime incidenceEnd;
414 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); 414 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() );
415 bool invalid = false; 415 bool invalid = false;
416 while( true ) { 416 while( true ) {
417 if ( incidenceStart.isValid() ) { 417 if ( incidenceStart.isValid() ) {
418 incidenceEnd = incidenceStart.addDays( eventlen ); 418 incidenceEnd = incidenceStart.addDays( eventlen );
419 int st = incidenceStart.date().daysTo( endDate ); 419 int st = incidenceStart.date().daysTo( endDate );
420 if ( st >= 0 ) { // start before timeend 420 if ( st >= 0 ) { // start before timeend
421 int end = mStartDate.daysTo( incidenceEnd.date() ); 421 int end = mStartDate.daysTo( incidenceEnd.date() );
422 if ( end >= 0 ) { // end after timestart --- got one! 422 if ( end >= 0 ) { // end after timestart --- got one!
423 //normalize 423 //normalize
424 st = timeSpan - st; 424 st = timeSpan - st;
425 if ( st < 0 ) st = 0; 425 if ( st < 0 ) st = 0;
426 if ( end > timeSpan ) end = timeSpan; 426 if ( end > timeSpan ) end = timeSpan;
427 int iii; 427 int iii;
428 //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); 428 //qDebug("found %s %d %d ",event->summary().latin1(), st, end );
429 for ( iii = st;iii<= end;++iii) { 429 for ( iii = st;iii<= end;++iii) {
430 computeEvent( event, iii ); 430 computeEvent( event, iii );
431 } 431 }
432 } 432 }
433 } 433 }
434 } else { 434 } else {
435 if ( invalid ) 435 if ( invalid )
436 break; 436 break;
437 invalid = true; 437 invalid = true;
438 //qDebug("invalid %s", event->summary().latin1()); 438 //qDebug("invalid %s", event->summary().latin1());
439 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; 439 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );;
440 } 440 }
441 if ( last ) 441 if ( last )
442 break; 442 break;
443 bool ok; 443 bool ok;
444 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); 444 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok );
445 if ( ! ok ) 445 if ( ! ok )
446 break; 446 break;
447 if ( incidenceStart.date() > endDate ) 447 if ( incidenceStart.date() > endDate )
448 break; 448 break;
449 } 449 }
450 } else { // no recur 450 } else { // no recur
451 int st = event->dtStart().date().daysTo( endDate ); 451 int st = event->dtStart().date().daysTo( endDate );
452 if ( st >= 0 ) { // start before timeend 452 if ( st >= 0 ) { // start before timeend
453 int end = mStartDate.daysTo( event->dtEnd().date() ); 453 int end = mStartDate.daysTo( event->dtEnd().date() );
454 if ( end >= 0 ) { // end after timestart --- got one! 454 if ( end >= 0 ) { // end after timestart --- got one!
455 //normalize 455 //normalize
456 st = timeSpan - st; 456 st = timeSpan - st;
457 if ( st < 0 ) st = 0; 457 if ( st < 0 ) st = 0;
458 if ( end > timeSpan ) end = timeSpan; 458 if ( end > timeSpan ) end = timeSpan;
459 int iii; 459 int iii;
460 for ( iii = st;iii<= end;++iii) 460 for ( iii = st;iii<= end;++iii)
461 computeEvent( event, iii ); 461 computeEvent( event, iii );
462 } 462 }
463 } 463 }
464 } 464 }
465 } 465 }
466 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday 466 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday
467 for(i = 0; i < NUMDAYS; i++) { 467 for(i = 0; i < NUMDAYS; i++) {
468 if ( ( (i+startDay) % 7 == 0 ) ) { 468 if ( ( (i+startDay) % 7 == 0 ) ) {
469 pDays.setBit(i); 469 pDays.setBit(i);
470 } 470 }
471 } 471 }
472 472
473#if 0 473#if 0
474 // insert due todos 474 // insert due todos
475 QPtrList<Todo> todos = calendar()->todos( ); 475 QPtrList<Todo> todos = calendar()->todos( );
476 Todo *todo; 476 Todo *todo;
477 for(todo = todos.first(); todo; todo = todos.next()) { 477 for(todo = todos.first(); todo; todo = todos.next()) {
478 //insertTodo( todo ); 478 //insertTodo( todo );
479 if ( todo->hasDueDate() ) { 479 if ( todo->hasDueDate() ) {
480 int day = mStartDate.daysTo( todo->dtDue().date() ); 480 int day = mStartDate.daysTo( todo->dtDue().date() );
481 if ( day >= 0 && day < timeSpan + 1) { 481 if ( day >= 0 && day < timeSpan + 1) {
482 (*cells)[day]->insertTodo( todo ); 482 (*cells)[day]->insertTodo( todo );
483 } 483 }
484 } 484 }
485 } 485 }
486#endif 486#endif
487 487
488#else 488#else
489 //qDebug("KODayMatrix::updateViewTimed "); 489 //qDebug("KODayMatrix::updateViewTimed ");
490 for(int i = 0; i < NUMDAYS; i++) { 490 for(int i = 0; i < NUMDAYS; i++) {
491 // if events are set for the day then remember to draw it bold 491 // if events are set for the day then remember to draw it bold
492 QPtrList<Event> eventlist = mCalendar->events(days[i]); 492 QPtrList<Event> eventlist = mCalendar->events(days[i]);
493 Event *event; 493 Event *event;
494 int numEvents = eventlist.count(); 494 int numEvents = eventlist.count();
495 QString holiStr = ""; 495 QString holiStr = "";
496 bDays.clearBit(i); 496 bDays.clearBit(i);
497 hDays.clearBit(i); 497 hDays.clearBit(i);
498 eDays.clearBit(i); 498 eDays.clearBit(i);
499 for(event=eventlist.first();event != 0;event=eventlist.next()) { 499 for(event=eventlist.first();event != 0;event=eventlist.next()) {
500 qDebug("FFFFFFFFFFFFFFFFFFFFFFFFF ");
501 ushort recurType = event->recurrence()->doesRecur(); 500 ushort recurType = event->recurrence()->doesRecur();
502 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 501 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
503 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 502 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
504 numEvents--; 503 numEvents--;
505 } 504 }
506 if ( event->isHoliday()) { 505 if ( event->isHoliday()) {
507 hDays.setBit(i); 506 hDays.setBit(i);
508 if ( !holiStr.isEmpty() ) 507 if ( !holiStr.isEmpty() )
509 holiStr += "\n"; 508 holiStr += "\n";
510 holiStr += event->summary(); 509 holiStr += event->summary();
511 if ( !event->location().isEmpty() ) 510 if ( !event->location().isEmpty() )
512 holiStr += " (" + event->location() + ")"; 511 holiStr += " (" + event->location() + ")";
513 } 512 }
514 if ( event->isBirthday()) { 513 if ( event->isBirthday()) {
515 if ( !holiStr.isEmpty() ) 514 if ( !holiStr.isEmpty() )
516 holiStr += "\n"; 515 holiStr += "\n";
517 holiStr += i18n("Birthday") + ": "+event->summary(); 516 holiStr += i18n("Birthday") + ": "+event->summary();
518 if ( !event->location().isEmpty() ) 517 if ( !event->location().isEmpty() )
519 holiStr += " (" + event->location() + ")"; 518 holiStr += " (" + event->location() + ")";
520 bDays.setBit(i); 519 bDays.setBit(i);
521 } 520 }
522 } 521 }
523 if ( numEvents ) 522 if ( numEvents )
524 eDays.setBit(i); 523 eDays.setBit(i);
525 //if it is a holy day then draw it red. Sundays are consider holidays, too 524 //if it is a holy day then draw it red. Sundays are consider holidays, too
526 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || 525 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) ||
527 !holiStr.isEmpty()) { 526 !holiStr.isEmpty()) {
528 mHolidays[i] = holiStr; 527 mHolidays[i] = holiStr;
529 } else { 528 } else {
530 mHolidays[i] = QString::null; 529 mHolidays[i] = QString::null;
531 } 530 }
532 } 531 }
533#endif 532#endif
534 mRedrawNeeded = true; 533 mRedrawNeeded = true;
535 if ( ! mPendingUpdateBeforeRepaint ) 534 if ( ! mPendingUpdateBeforeRepaint )
536 repaint(false); 535 repaint(false);
537} 536}
538void KODayMatrix::updateView(QDate actdate) 537void KODayMatrix::updateView(QDate actdate)
539{ 538{
540 539
541 if ( ! actdate.isValid() ) { 540 if ( ! actdate.isValid() ) {
542 //qDebug("date not valid "); 541 //qDebug("date not valid ");
543 return; 542 return;
544 } 543 }
545 mDayChanged = false; 544 mDayChanged = false;
546 //flag to indicate if the starting day of the matrix has changed by this call 545 //flag to indicate if the starting day of the matrix has changed by this call
547 //mDayChanged = false; 546 //mDayChanged = false;
548 // if a new startdate is to be set then apply Cornelius's calculation 547 // if a new startdate is to be set then apply Cornelius's calculation
549 // of the first day to be shown 548 // of the first day to be shown
550 if (actdate != startdate) { 549 if (actdate != startdate) {
551 // reset index of selection according to shift of starting date from startdate to actdate 550 // reset index of selection according to shift of starting date from startdate to actdate
552 if (mSelStart != NOSELECTION) { 551 if (mSelStart != NOSELECTION) {
553 int tmp = actdate.daysTo(startdate); 552 int tmp = actdate.daysTo(startdate);
554 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; 553 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl;
555 // shift selection if new one would be visible at least partly ! 554 // shift selection if new one would be visible at least partly !
556 555
557 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { 556 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) {
558 // nested if is required for next X display pushed from a different month - correction required 557 // nested if is required for next X display pushed from a different month - correction required
559 // otherwise, for month forward and backward, it must be avoided 558 // otherwise, for month forward and backward, it must be avoided
560 if( mSelStart > NUMDAYS || mSelStart < 0 ) 559 if( mSelStart > NUMDAYS || mSelStart < 0 )
561 mSelStart = mSelStart + tmp; 560 mSelStart = mSelStart + tmp;
562 if( mSelEnd > NUMDAYS || mSelEnd < 0 ) 561 if( mSelEnd > NUMDAYS || mSelEnd < 0 )
563 mSelEnd = mSelEnd + tmp; 562 mSelEnd = mSelEnd + tmp;
564 } 563 }
565 } 564 }
566 startdate = actdate; 565 startdate = actdate;
567 mDayChanged = true; 566 mDayChanged = true;
568 recalculateToday(); 567 recalculateToday();
569 mRedrawNeeded = true; 568 mRedrawNeeded = true;
570 } 569 }
571 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); 570 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() );
572 if ( !isVisible() ) { 571 if ( !isVisible() ) {
573 mPendingUpdateBeforeRepaint = true; 572 mPendingUpdateBeforeRepaint = true;
574 } else { 573 } else {
575#ifdef DESKTOP_VERSION 574#ifdef DESKTOP_VERSION
576 //mRepaintTimer->start( 100 ); 575 //mRepaintTimer->start( 100 );
577 //updateViewTimed(); 576 //updateViewTimed();
578 mUpdateTimer->start( 50 ); 577 mUpdateTimer->start( 50 );
579#else 578#else
580 mRepaintTimer->start( 350 ); 579 mRepaintTimer->start( 350 );
581 mUpdateTimer->start( 800 ); 580 mUpdateTimer->start( 800 );
582#endif 581#endif
583 } 582 }
584} 583}
585void KODayMatrix::updateEvents() 584void KODayMatrix::updateEvents()
586{ 585{
587 if ( !mCalendar ) return; 586 if ( !mCalendar ) return;
588 587
589 for( int i = 0; i < NUMDAYS; i++ ) { 588 for( int i = 0; i < NUMDAYS; i++ ) {
590 // if events are set for the day then remember to draw it bold 589 // if events are set for the day then remember to draw it bold
591 QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); 590 QPtrList<Event> eventlist = mCalendar->events( days[ i ] );
592 int numEvents = eventlist.count(); 591 int numEvents = eventlist.count();
593 Event *event; 592 Event *event;
594 for( event = eventlist.first(); event != 0;event=eventlist.next()) { 593 for( event = eventlist.first(); event != 0;event=eventlist.next()) {
595 ushort recurType = event->doesRecur(); 594 ushort recurType = event->doesRecur();
596 595
597 if ( ( recurType == Recurrence::rDaily && 596 if ( ( recurType == Recurrence::rDaily &&
598 !KOPrefs::instance()->mDailyRecur ) || 597 !KOPrefs::instance()->mDailyRecur ) ||
599 ( recurType == Recurrence::rWeekly && 598 ( recurType == Recurrence::rWeekly &&
600 !KOPrefs::instance()->mWeeklyRecur ) ) { 599 !KOPrefs::instance()->mWeeklyRecur ) ) {
601 numEvents--; 600 numEvents--;
602 } 601 }
603 } 602 }
604 if ( numEvents ) 603 if ( numEvents )
605 eDays.setBit(i); 604 eDays.setBit(i);
606 else 605 else
607 eDays.clearBit(i); 606 eDays.clearBit(i);
608 } 607 }
609} 608}
610 609
611const QDate& KODayMatrix::getDate(int offset) 610const QDate& KODayMatrix::getDate(int offset)
612{ 611{
613 if (offset < 0 || offset > NUMDAYS-1) { 612 if (offset < 0 || offset > NUMDAYS-1) {
614 qDebug("Wrong offset2 %d", offset); 613 qDebug("Wrong offset2 %d", offset);
615 return days[0]; 614 return days[0];
616 } 615 }
617 return days[offset]; 616 return days[offset];
618} 617}
619 618
620QString KODayMatrix::getHolidayLabel(int offset) 619QString KODayMatrix::getHolidayLabel(int offset)
621{ 620{
622 if (offset < 0 || offset > NUMDAYS-1) { 621 if (offset < 0 || offset > NUMDAYS-1) {
623 qDebug("Wrong offset1 %d", offset); 622 qDebug("Wrong offset1 %d", offset);
624 return QString(); 623 return QString();
625 } 624 }
626 return mHolidays[offset]; 625 return mHolidays[offset];
627} 626}
628 627
629int KODayMatrix::getDayIndexFrom(int x, int y) 628int KODayMatrix::getDayIndexFrom(int x, int y)
630{ 629{
631 int colModulo = (width()-2) % 7; 630 int colModulo = (width()-2) % 7;
632 int rowModulo = (height()-2) % 6; 631 int rowModulo = (height()-2) % 6;
633#if 0 632#if 0
634 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 633 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
635 6 - x/daysize.width() : x/daysize.width()); 634 6 - x/daysize.width() : x/daysize.width());
636#endif 635#endif
637 int xVal = (x-colModulo/2-2)/daysize.width(); 636 int xVal = (x-colModulo/2-2)/daysize.width();
638 int yVal = (y-rowModulo/2-2)/daysize.height(); 637 int yVal = (y-rowModulo/2-2)/daysize.height();
639 638
640 639
641 return 7*(yVal) + xVal; 640 return 7*(yVal) + xVal;
642 641
643} 642}
644 643
645// ---------------------------------------------------------------------------- 644// ----------------------------------------------------------------------------
646// M O U S E E V E N T H A N D L I N G 645// M O U S E E V E N T H A N D L I N G
647// ---------------------------------------------------------------------------- 646// ----------------------------------------------------------------------------
648 647
649void KODayMatrix::mousePressEvent (QMouseEvent* e) 648void KODayMatrix::mousePressEvent (QMouseEvent* e)
650{ 649{
651 650
652 if ( e->button() == LeftButton ) 651 if ( e->button() == LeftButton )
653 mouseDown = true; 652 mouseDown = true;
654 mSelStart = getDayIndexFrom(e->x(), e->y()); 653 mSelStart = getDayIndexFrom(e->x(), e->y());
655 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; 654 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
656 mSelInit = mSelStart; 655 mSelInit = mSelStart;
657 mSelEnd = mSelStart; 656 mSelEnd = mSelStart;
658 mRedrawNeeded = true; 657 mRedrawNeeded = true;
659 repaint(false); 658 repaint(false);
660} 659}
661 660
662void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) 661void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
663{ 662{
664 mRedrawNeeded = true; 663 mRedrawNeeded = true;
665 if ( e->button() == LeftButton ) 664 if ( e->button() == LeftButton )
666 if ( ! mouseDown ) { 665 if ( ! mouseDown ) {
667 return; 666 return;
668 } 667 }
669 else 668 else
670 mouseDown = false; 669 mouseDown = false;
671 int tmp = getDayIndexFrom(e->x(), e->y()); 670 int tmp = getDayIndexFrom(e->x(), e->y());
672 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 671 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
673 672
674 if (mSelInit > tmp) { 673 if (mSelInit > tmp) {
675 mSelEnd = mSelInit; 674 mSelEnd = mSelInit;
676 if (tmp != mSelStart) { 675 if (tmp != mSelStart) {
677 mSelStart = tmp; 676 mSelStart = tmp;
678 repaint(false); 677 repaint(false);
679 } 678 }
680 } else { 679 } else {
681 mSelStart = mSelInit; 680 mSelStart = mSelInit;
682 681
683 //repaint only if selection has changed 682 //repaint only if selection has changed
684 if (tmp != mSelEnd) { 683 if (tmp != mSelEnd) {
685 mSelEnd = tmp; 684 mSelEnd = tmp;
686 repaint(false); 685 repaint(false);
687 } 686 }
688 } 687 }
689 688
690 DateList daylist; 689 DateList daylist;
691 if ( mSelStart < 0 ) 690 if ( mSelStart < 0 )
692 mSelStart = 0; 691 mSelStart = 0;