summaryrefslogtreecommitdiffabout
path: root/korganizer/kodaymatrix.cpp
Unidiff
Diffstat (limited to 'korganizer/kodaymatrix.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/kodaymatrix.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index 057df0d..7076e05 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -269,610 +269,616 @@ void KODayMatrix::setCalendar( Calendar *cal )
269} 269}
270 270
271QColor KODayMatrix::getShadedColor(QColor color) 271QColor KODayMatrix::getShadedColor(QColor color)
272{ 272{
273 QColor shaded; 273 QColor shaded;
274 int h=0; 274 int h=0;
275 int s=0; 275 int s=0;
276 int v=0; 276 int v=0;
277 color.hsv(&h,&s,&v); 277 color.hsv(&h,&s,&v);
278 s = s/4; 278 s = s/4;
279 v = 192+v/4; 279 v = 192+v/4;
280 shaded.setHsv(h,s,v); 280 shaded.setHsv(h,s,v);
281 281
282 return shaded; 282 return shaded;
283} 283}
284 284
285KODayMatrix::~KODayMatrix() 285KODayMatrix::~KODayMatrix()
286{ 286{
287#if QT_VERSION >= 0x030000 287#if QT_VERSION >= 0x030000
288 288
289#else 289#else
290 delete mKODaymatrixWhatsThis; 290 delete mKODaymatrixWhatsThis;
291#endif 291#endif
292 292
293 // delete mKODaymatrixWhatsThis; 293 // delete mKODaymatrixWhatsThis;
294 delete [] days; 294 delete [] days;
295 delete [] daylbls; 295 delete [] daylbls;
296 //delete [] events; 296 //delete [] events;
297 delete mToolTip; 297 delete mToolTip;
298} 298}
299 299
300/* 300/*
301void KODayMatrix::setStartDate(QDate start) 301void KODayMatrix::setStartDate(QDate start)
302{ 302{
303 updateView(start); 303 updateView(start);
304} 304}
305*/ 305*/
306 306
307void KODayMatrix::addSelectedDaysTo(DateList& selDays) 307void KODayMatrix::addSelectedDaysTo(DateList& selDays)
308{ 308{
309 309
310 if (mSelStart == NOSELECTION) { 310 if (mSelStart == NOSELECTION) {
311 return; 311 return;
312 } 312 }
313 313
314 //cope with selection being out of matrix limits at top (< 0) 314 //cope with selection being out of matrix limits at top (< 0)
315 int i0 = mSelStart; 315 int i0 = mSelStart;
316 if (i0 < 0) { 316 if (i0 < 0) {
317 for (int i = i0; i < 0; i++) { 317 for (int i = i0; i < 0; i++) {
318 selDays.append(days[0].addDays(i)); 318 selDays.append(days[0].addDays(i));
319 } 319 }
320 i0 = 0; 320 i0 = 0;
321 } 321 }
322 322
323 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) 323 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1)
324 if (mSelEnd > NUMDAYS-1) { 324 if (mSelEnd > NUMDAYS-1) {
325 for (int i = i0; i <= NUMDAYS-1; i++) { 325 for (int i = i0; i <= NUMDAYS-1; i++) {
326 selDays.append(days[i]); 326 selDays.append(days[i]);
327 } 327 }
328 for (int i = NUMDAYS; i < mSelEnd; i++) { 328 for (int i = NUMDAYS; i < mSelEnd; i++) {
329 selDays.append(days[0].addDays(i)); 329 selDays.append(days[0].addDays(i));
330 } 330 }
331 331
332 // apply normal routine to selection being entirely within matrix limits 332 // apply normal routine to selection being entirely within matrix limits
333 } else { 333 } else {
334 for (int i = i0; i <= mSelEnd; i++) { 334 for (int i = i0; i <= mSelEnd; i++) {
335 selDays.append(days[i]); 335 selDays.append(days[i]);
336 } 336 }
337 } 337 }
338} 338}
339 339
340bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 340bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
341{ 341{
342 mRedrawNeeded = true; 342 mRedrawNeeded = true;
343 bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION ); 343 bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION );
344 mSelStart = startdate.daysTo(start); 344 mSelStart = startdate.daysTo(start);
345 if ( mSelStart < 0 ) 345 if ( mSelStart < 0 )
346 mSelStart = 0; 346 mSelStart = 0;
347 mSelEnd = startdate.daysTo(end); 347 mSelEnd = startdate.daysTo(end);
348 if ( mSelEnd > NUMDAYS-1 ) 348 if ( mSelEnd > NUMDAYS-1 )
349 mSelEnd = NUMDAYS-1; 349 mSelEnd = NUMDAYS-1;
350 if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) { 350 if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) {
351 clearSelection(); 351 clearSelection();
352 if ( noSel ) 352 if ( noSel )
353 return false; 353 return false;
354 } 354 }
355 355
356 return true; 356 return true;
357} 357}
358void KODayMatrix::clearSelection() 358void KODayMatrix::clearSelection()
359{ 359{
360 mSelEnd = mSelStart = NOSELECTION; 360 mSelEnd = mSelStart = NOSELECTION;
361} 361}
362 362
363 363
364void KODayMatrix::recalculateToday() 364void KODayMatrix::recalculateToday()
365{ 365{
366 today = -1; 366 today = -1;
367 for (int i=0; i<NUMDAYS; i++) { 367 for (int i=0; i<NUMDAYS; i++) {
368 //events[i] = 0; 368 //events[i] = 0;
369 days[i] = startdate.addDays(i); 369 days[i] = startdate.addDays(i);
370 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 370 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
371 371
372 // if today is in the currently displayed month, hilight today 372 // if today is in the currently displayed month, hilight today
373 if (days[i].year() == QDate::currentDate().year() && 373 if (days[i].year() == QDate::currentDate().year() &&
374 days[i].month() == QDate::currentDate().month() && 374 days[i].month() == QDate::currentDate().month() &&
375 days[i].day() == QDate::currentDate().day()) { 375 days[i].day() == QDate::currentDate().day()) {
376 today = i; 376 today = i;
377 } 377 }
378 } 378 }
379 // qDebug(QString("Today is visible at %1.").arg(today)); 379 // qDebug(QString("Today is visible at %1.").arg(today));
380} 380}
381 381
382void KODayMatrix::updateView() 382void KODayMatrix::updateView()
383{ 383{
384 updateView(startdate); 384 updateView(startdate);
385} 385}
386void KODayMatrix::repaintViewTimed() 386void KODayMatrix::repaintViewTimed()
387{ 387{
388 mRedrawNeeded = true; 388 mRedrawNeeded = true;
389 // bDays.fill( false); 389 // bDays.fill( false);
390 //pDays.fill( false); 390 //pDays.fill( false);
391 //hDays.fill( false); 391 //hDays.fill( false);
392 //eDays.fill( false); 392 //eDays.fill( false);
393 mRepaintTimer->stop(); 393 mRepaintTimer->stop();
394 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday 394 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday
395 int i; 395 int i;
396 for(i = 0; i < NUMDAYS; i++) { 396 for(i = 0; i < NUMDAYS; i++) {
397 if ( ( (i+startDay) % 7 == 0 ) ) { 397 if ( ( (i+startDay) % 7 == 0 ) ) {
398 pDays.setBit(i); 398 pDays.setBit(i);
399 } 399 }
400 } 400 }
401 repaint(false); 401 repaint(false);
402} 402}
403void KODayMatrix::computeEvent(Event *event, int i ) 403void KODayMatrix::computeEvent(Event *event, int i )
404{ 404{
405 QString holiStr = mHolidays[i]; 405 QString holiStr = mHolidays[i];
406 if ( event->isHoliday()) { 406 if ( event->isHoliday()) {
407 pDays.setBit(i); 407 pDays.setBit(i);
408 hDays.setBit(i); 408 hDays.setBit(i);
409 if ( !holiStr.isEmpty() ) 409 if ( !holiStr.isEmpty() )
410 holiStr += "\n"; 410 holiStr += "\n";
411 holiStr += event->summary(); 411 holiStr += event->summary();
412 if ( !event->location().isEmpty() ) 412 if ( !event->location().isEmpty() )
413 holiStr += " (" + event->location() + ")"; 413 holiStr += " (" + event->location() + ")";
414 mHolidays[i] =holiStr ; 414 mHolidays[i] =holiStr ;
415 eDays.setBit(i); 415 eDays.setBit(i);
416 } 416 }
417 if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_T_VIEW && KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) { 417 if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_T_VIEW && KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) {
418 if ( event->isBirthday()) { 418 if ( event->isBirthday()) {
419 pDays.setBit(i); 419 pDays.setBit(i);
420 if ( !holiStr.isEmpty() ) 420 if ( !holiStr.isEmpty() )
421 holiStr += "\n"; 421 holiStr += "\n";
422 holiStr += i18n("Birthday") + ": "+event->summary(); 422 holiStr += i18n("Birthday") + ": "+event->summary();
423 if ( !event->location().isEmpty() ) 423 if ( !event->location().isEmpty() )
424 holiStr += " (" + event->location() + ")"; 424 holiStr += " (" + event->location() + ")";
425 bDays.setBit(i); 425 bDays.setBit(i);
426 mHolidays[i] =holiStr ; 426 mHolidays[i] =holiStr ;
427 } 427 }
428 } 428 }
429 if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) 429 if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW )
430 eDays.setBit(i); 430 eDays.setBit(i);
431} 431}
432void KODayMatrix::updateViewTimed() 432void KODayMatrix::updateViewTimed()
433{ 433{
434 mUpdateTimer->stop(); 434 mUpdateTimer->stop();
435 if ( !mCalendar ) { 435 if ( !mCalendar ) {
436 qDebug("NOT CAL "); 436 qDebug("NOT CAL ");
437 return; 437 return;
438 } 438 }
439#if 1 439#if 1
440 440
441 441
442 int i; 442 int i;
443 int timeSpan = NUMDAYS-1; 443 int timeSpan = NUMDAYS-1;
444 QPtrList<Event> events = mCalendar->events(); 444 QPtrList<Event> events = mCalendar->events();
445 Event *event; 445 Event *event;
446 QDateTime dt; 446 QDateTime dt;
447 bool ok; 447 bool ok;
448 bDays.fill( false); 448 bDays.fill( false);
449 pDays.fill( false); 449 pDays.fill( false);
450 hDays.fill( false); 450 hDays.fill( false);
451 eDays.fill( false); 451 eDays.fill( false);
452 mHolidays.clear(); 452 mHolidays.clear();
453 QDate mStartDate = days[0]; 453 QDate mStartDate = days[0];
454 QDate endDate = mStartDate.addDays( timeSpan ); 454 QDate endDate = mStartDate.addDays( timeSpan );
455 for( event = events.first(); event; event = events.next() ) { // for event 455 for( event = events.first(); event; event = events.next() ) { // for event
456 ushort recurType = event->doesRecur(); 456 ushort recurType = event->doesRecur();
457 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 457 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
458 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 458 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
459 continue; 459 continue;
460 } 460 }
461 if ( !KOPrefs::instance()->mLongAllday && event->doesFloat()&& event->isMultiDay() ) {
462 continue;
463 }
461 if ( event->doesRecur() ) { 464 if ( event->doesRecur() ) {
462 bool last; 465 bool last;
463 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); 466 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
464 QDateTime incidenceEnd; 467 QDateTime incidenceEnd;
465 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); 468 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() );
466 bool invalid = false; 469 bool invalid = false;
467 while( true ) { 470 while( true ) {
468 if ( incidenceStart.isValid() ) { 471 if ( incidenceStart.isValid() ) {
469 incidenceEnd = incidenceStart.addDays( eventlen ); 472 incidenceEnd = incidenceStart.addDays( eventlen );
470 int st = incidenceStart.date().daysTo( endDate ); 473 int st = incidenceStart.date().daysTo( endDate );
471 if ( st >= 0 ) { // start before timeend 474 if ( st >= 0 ) { // start before timeend
472 int end = mStartDate.daysTo( incidenceEnd.date() ); 475 int end = mStartDate.daysTo( incidenceEnd.date() );
473 if ( end >= 0 ) { // end after timestart --- got one! 476 if ( end >= 0 ) { // end after timestart --- got one!
474 //normalize 477 //normalize
475 st = timeSpan - st; 478 st = timeSpan - st;
476 if ( st < 0 ) st = 0; 479 if ( st < 0 ) st = 0;
477 if ( end > timeSpan ) end = timeSpan; 480 if ( end > timeSpan ) end = timeSpan;
478 int iii; 481 int iii;
479 //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); 482 //qDebug("found %s %d %d ",event->summary().latin1(), st, end );
480 for ( iii = st;iii<= end;++iii) { 483 for ( iii = st;iii<= end;++iii) {
481 computeEvent( event, iii ); 484 computeEvent( event, iii );
482 } 485 }
483 } 486 }
484 } 487 }
485 } else { 488 } else {
486 if ( invalid ) 489 if ( invalid )
487 break; 490 break;
488 invalid = true; 491 invalid = true;
489 //qDebug("invalid %s", event->summary().latin1()); 492 //qDebug("invalid %s", event->summary().latin1());
490 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; 493 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );;
491 } 494 }
492 if ( last ) 495 if ( last )
493 break; 496 break;
494 bool ok; 497 bool ok;
495 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); 498 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok );
496 if ( ! ok ) 499 if ( ! ok )
497 break; 500 break;
498 if ( incidenceStart.date() > endDate ) 501 if ( incidenceStart.date() > endDate )
499 break; 502 break;
500 } 503 }
501 } else { // no recur 504 } else { // no recur
502 int st = event->dtStart().date().daysTo( endDate ); 505 int st = event->dtStart().date().daysTo( endDate );
503 if ( st >= 0 ) { // start before timeend 506 if ( st >= 0 ) { // start before timeend
504 int end = mStartDate.daysTo( event->dtEnd().date() ); 507 int end = mStartDate.daysTo( event->dtEnd().date() );
505 if ( end >= 0 ) { // end after timestart --- got one! 508 if ( end >= 0 ) { // end after timestart --- got one!
506 //normalize 509 //normalize
507 st = timeSpan - st; 510 st = timeSpan - st;
508 if ( st < 0 ) st = 0; 511 if ( st < 0 ) st = 0;
509 if ( end > timeSpan ) end = timeSpan; 512 if ( end > timeSpan ) end = timeSpan;
510 int iii; 513 int iii;
511 for ( iii = st;iii<= end;++iii) 514 for ( iii = st;iii<= end;++iii)
512 computeEvent( event, iii ); 515 computeEvent( event, iii );
513 } 516 }
514 } 517 }
515 } 518 }
516 } 519 }
517 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday 520 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday
518 for(i = 0; i < NUMDAYS; i++) { 521 for(i = 0; i < NUMDAYS; i++) {
519 if ( ( (i+startDay) % 7 == 0 ) ) { 522 if ( ( (i+startDay) % 7 == 0 ) ) {
520 pDays.setBit(i); 523 pDays.setBit(i);
521 } 524 }
522 } 525 }
523 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { 526 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) {
524 bDays.fill( false); 527 bDays.fill( false);
525 // insert due todos 528 // insert due todos
526 QPtrList<Todo> todos = mCalendar->todos( ); 529 QPtrList<Todo> todos = mCalendar->todos( );
527 Todo *todo; 530 Todo *todo;
528 for(todo = todos.first(); todo; todo = todos.next()) { 531 for(todo = todos.first(); todo; todo = todos.next()) {
529 //insertTodo( todo ); 532 //insertTodo( todo );
530 if ( todo->hasDueDate() ) { 533 if ( todo->hasDueDate() ) {
531 int day = mStartDate.daysTo( todo->dtDue().date() ); 534 int day = mStartDate.daysTo( todo->dtDue().date() );
532 if ( day >= 0 && day < timeSpan + 1) { 535 if ( day >= 0 && day < timeSpan + 1) {
533 int i = day; 536 int i = day;
534 QString holiStr = mHolidays[i]; 537 QString holiStr = mHolidays[i];
535 pDays.setBit(i); 538 pDays.setBit(i);
536 if ( !holiStr.isEmpty() ) 539 if ( !holiStr.isEmpty() )
537 holiStr += "\n"; 540 holiStr += "\n";
538 holiStr += i18n("Todo") + ": "+todo->summary(); 541 holiStr += i18n("Todo") + ": "+todo->summary();
539 if ( !todo->location().isEmpty() ) 542 if ( !todo->location().isEmpty() )
540 holiStr += " (" + todo->location() + ")"; 543 holiStr += " (" + todo->location() + ")";
541 bDays.setBit(i); 544 bDays.setBit(i);
542 mHolidays[i] =holiStr ; 545 mHolidays[i] =holiStr ;
543 eDays.setBit(i); 546 eDays.setBit(i);
544 } 547 }
545 } 548 }
546 } 549 }
547 } 550 }
548 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { 551 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) {
549 bDays.fill( false); 552 bDays.fill( false);
550 // insert due todos 553 // insert due todos
551 QPtrList<Journal> todos = mCalendar->journals( ); 554 QPtrList<Journal> todos = mCalendar->journals( );
552 Journal *todo; 555 Journal *todo;
553 for(todo = todos.first(); todo; todo = todos.next()) { 556 for(todo = todos.first(); todo; todo = todos.next()) {
554 int day = mStartDate.daysTo( todo->dtStart().date() ); 557 int day = mStartDate.daysTo( todo->dtStart().date() );
555 if ( day >= 0 && day < timeSpan + 1) { 558 if ( day >= 0 && day < timeSpan + 1) {
556 int i = day; 559 int i = day;
557 QString holiStr = mHolidays[i]; 560 QString holiStr = mHolidays[i];
558 pDays.setBit(i); 561 pDays.setBit(i);
559 if ( !holiStr.isEmpty() ) 562 if ( !holiStr.isEmpty() )
560 holiStr += "\n"; 563 holiStr += "\n";
561 holiStr += i18n("Journal: ")+todo->summary().left(25); 564 holiStr += i18n("Journal: ")+todo->summary().left(25);
562 if ( todo->summary().length() > 25 ) 565 if ( todo->summary().length() > 25 )
563 holiStr +="..."; 566 holiStr +="...";
564 bDays.setBit(i); 567 bDays.setBit(i);
565 mHolidays[i] =holiStr ; 568 mHolidays[i] =holiStr ;
566 eDays.setBit(i); 569 eDays.setBit(i);
567 570
568 } 571 }
569 } 572 }
570 } 573 }
571#else 574#else
572 //qDebug("KODayMatrix::updateViewTimed "); 575 //qDebug("KODayMatrix::updateViewTimed ");
573 for(int i = 0; i < NUMDAYS; i++) { 576 for(int i = 0; i < NUMDAYS; i++) {
574 // if events are set for the day then remember to draw it bold 577 // if events are set for the day then remember to draw it bold
575 QPtrList<Event> eventlist = mCalendar->events(days[i]); 578 QPtrList<Event> eventlist = mCalendar->events(days[i]);
576 Event *event; 579 Event *event;
577 int numEvents = eventlist.count(); 580 int numEvents = eventlist.count();
578 QString holiStr = ""; 581 QString holiStr = "";
579 bDays.clearBit(i); 582 bDays.clearBit(i);
580 hDays.clearBit(i); 583 hDays.clearBit(i);
581 eDays.clearBit(i); 584 eDays.clearBit(i);
582 for(event=eventlist.first();event != 0;event=eventlist.next()) { 585 for(event=eventlist.first();event != 0;event=eventlist.next()) {
583 ushort recurType = event->recurrence()->doesRecur(); 586 ushort recurType = event->recurrence()->doesRecur();
584 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 587 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
585 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 588 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
586 numEvents--; 589 numEvents--;
587 } 590 }
588 if ( event->isHoliday()) { 591 if ( event->isHoliday()) {
589 hDays.setBit(i); 592 hDays.setBit(i);
590 if ( !holiStr.isEmpty() ) 593 if ( !holiStr.isEmpty() )
591 holiStr += "\n"; 594 holiStr += "\n";
592 holiStr += event->summary(); 595 holiStr += event->summary();
593 if ( !event->location().isEmpty() ) 596 if ( !event->location().isEmpty() )
594 holiStr += " (" + event->location() + ")"; 597 holiStr += " (" + event->location() + ")";
595 } 598 }
596 if ( event->isBirthday()) { 599 if ( event->isBirthday()) {
597 if ( !holiStr.isEmpty() ) 600 if ( !holiStr.isEmpty() )
598 holiStr += "\n"; 601 holiStr += "\n";
599 holiStr += i18n("Birthday") + ": "+event->summary(); 602 holiStr += i18n("Birthday") + ": "+event->summary();
600 if ( !event->location().isEmpty() ) 603 if ( !event->location().isEmpty() )
601 holiStr += " (" + event->location() + ")"; 604 holiStr += " (" + event->location() + ")";
602 bDays.setBit(i); 605 bDays.setBit(i);
603 } 606 }
604 } 607 }
605 if ( numEvents ) 608 if ( numEvents )
606 eDays.setBit(i); 609 eDays.setBit(i);
607 //if it is a holy day then draw it red. Sundays are consider holidays, too 610 //if it is a holy day then draw it red. Sundays are consider holidays, too
608 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || 611 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) ||
609 !holiStr.isEmpty()) { 612 !holiStr.isEmpty()) {
610 mHolidays[i] = holiStr; 613 mHolidays[i] = holiStr;
611 } else { 614 } else {
612 mHolidays[i] = QString::null; 615 mHolidays[i] = QString::null;
613 } 616 }
614 } 617 }
615#endif 618#endif
616 mRedrawNeeded = true; 619 mRedrawNeeded = true;
617 if ( ! mPendingUpdateBeforeRepaint ) 620 if ( ! mPendingUpdateBeforeRepaint )
618 repaint(false); 621 repaint(false);
619} 622}
620void KODayMatrix::updateView(QDate actdate) 623void KODayMatrix::updateView(QDate actdate)
621{ 624{
622 if ( mLastView != KOPrefs::instance()->mCurrentDisplayedView ) 625 if ( mLastView != KOPrefs::instance()->mCurrentDisplayedView )
623 mRedrawNeeded = true; 626 mRedrawNeeded = true;
624 mLastView = KOPrefs::instance()->mCurrentDisplayedView; 627 mLastView = KOPrefs::instance()->mCurrentDisplayedView;
625 if ( ! actdate.isValid() ) { 628 if ( ! actdate.isValid() ) {
626 //qDebug("date not valid "); 629 //qDebug("date not valid ");
627 return; 630 return;
628 } 631 }
629 mDayChanged = false; 632 mDayChanged = false;
630 //flag to indicate if the starting day of the matrix has changed by this call 633 //flag to indicate if the starting day of the matrix has changed by this call
631 //mDayChanged = false; 634 //mDayChanged = false;
632 // if a new startdate is to be set then apply Cornelius's calculation 635 // if a new startdate is to be set then apply Cornelius's calculation
633 // of the first day to be shown 636 // of the first day to be shown
634 if (actdate != startdate) { 637 if (actdate != startdate) {
635 // reset index of selection according to shift of starting date from startdate to actdate 638 // reset index of selection according to shift of starting date from startdate to actdate
636 if (mSelStart != NOSELECTION) { 639 if (mSelStart != NOSELECTION) {
637 int tmp = actdate.daysTo(startdate); 640 int tmp = actdate.daysTo(startdate);
638 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; 641 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl;
639 // shift selection if new one would be visible at least partly ! 642 // shift selection if new one would be visible at least partly !
640 643
641 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { 644 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) {
642 // nested if is required for next X display pushed from a different month - correction required 645 // nested if is required for next X display pushed from a different month - correction required
643 // otherwise, for month forward and backward, it must be avoided 646 // otherwise, for month forward and backward, it must be avoided
644 if( mSelStart > NUMDAYS || mSelStart < 0 ) 647 if( mSelStart > NUMDAYS || mSelStart < 0 )
645 mSelStart = mSelStart + tmp; 648 mSelStart = mSelStart + tmp;
646 if( mSelEnd > NUMDAYS || mSelEnd < 0 ) 649 if( mSelEnd > NUMDAYS || mSelEnd < 0 )
647 mSelEnd = mSelEnd + tmp; 650 mSelEnd = mSelEnd + tmp;
648 } 651 }
649 } 652 }
650 startdate = actdate; 653 startdate = actdate;
651 mDayChanged = true; 654 mDayChanged = true;
652 recalculateToday(); 655 recalculateToday();
653 mRedrawNeeded = true; 656 mRedrawNeeded = true;
654 } 657 }
655 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); 658 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() );
656 if ( !isVisible() ) { 659 if ( !isVisible() ) {
657 mPendingUpdateBeforeRepaint = true; 660 mPendingUpdateBeforeRepaint = true;
658 } else { 661 } else {
659#ifdef DESKTOP_VERSION 662#ifdef DESKTOP_VERSION
660 //mRepaintTimer->start( 100 ); 663 //mRepaintTimer->start( 100 );
661 //updateViewTimed(); 664 //updateViewTimed();
662 mUpdateTimer->start( 50 ); 665 mUpdateTimer->start( 50 );
663#else 666#else
664 mRepaintTimer->start( 350 ); 667 mRepaintTimer->start( 350 );
665 mUpdateTimer->start( 800 ); 668 mUpdateTimer->start( 800 );
666#endif 669#endif
667 } 670 }
668} 671}
669void KODayMatrix::updateEvents() 672void KODayMatrix::updateEvents()
670{ 673{
671 if ( !mCalendar ) return; 674 if ( !mCalendar ) return;
672 675
673 for( int i = 0; i < NUMDAYS; i++ ) { 676 for( int i = 0; i < NUMDAYS; i++ ) {
674 // if events are set for the day then remember to draw it bold 677 // if events are set for the day then remember to draw it bold
675 QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); 678 QPtrList<Event> eventlist = mCalendar->events( days[ i ] );
676 int numEvents = eventlist.count(); 679 int numEvents = eventlist.count();
677 Event *event; 680 Event *event;
678 for( event = eventlist.first(); event != 0;event=eventlist.next()) { 681 for( event = eventlist.first(); event != 0;event=eventlist.next()) {
679 ushort recurType = event->doesRecur(); 682 ushort recurType = event->doesRecur();
680 683
681 if ( ( recurType == Recurrence::rDaily && 684 if ( ( recurType == Recurrence::rDaily &&
682 !KOPrefs::instance()->mDailyRecur ) || 685 !KOPrefs::instance()->mDailyRecur ) ||
683 ( recurType == Recurrence::rWeekly && 686 ( recurType == Recurrence::rWeekly &&
684 !KOPrefs::instance()->mWeeklyRecur ) ) { 687 !KOPrefs::instance()->mWeeklyRecur ) ) {
685 numEvents--; 688 numEvents--;
686 } 689 }
690 if ( !KOPrefs::instance()->mLongAllday && event->doesFloat()&& event->isMultiDay() ) {
691 numEvents--;
692 }
687 } 693 }
688 if ( numEvents ) 694 if ( numEvents )
689 eDays.setBit(i); 695 eDays.setBit(i);
690 else 696 else
691 eDays.clearBit(i); 697 eDays.clearBit(i);
692 } 698 }
693} 699}
694 700
695const QDate& KODayMatrix::getDate(int offset) 701const QDate& KODayMatrix::getDate(int offset)
696{ 702{
697 if (offset < 0 || offset > NUMDAYS-1) { 703 if (offset < 0 || offset > NUMDAYS-1) {
698 qDebug("Wrong offset2 %d", offset); 704 qDebug("Wrong offset2 %d", offset);
699 return days[0]; 705 return days[0];
700 } 706 }
701 return days[offset]; 707 return days[offset];
702} 708}
703 709
704QString KODayMatrix::getHolidayLabel(int offset) 710QString KODayMatrix::getHolidayLabel(int offset)
705{ 711{
706 if (offset < 0 || offset > NUMDAYS-1) { 712 if (offset < 0 || offset > NUMDAYS-1) {
707 qDebug("Wrong offset1 %d", offset); 713 qDebug("Wrong offset1 %d", offset);
708 return QString(); 714 return QString();
709 } 715 }
710 return mHolidays[offset]; 716 return mHolidays[offset];
711} 717}
712 718
713int KODayMatrix::getDayIndexFrom(int x, int y) 719int KODayMatrix::getDayIndexFrom(int x, int y)
714{ 720{
715 int colModulo = (width()-2) % 7; 721 int colModulo = (width()-2) % 7;
716 int rowModulo = (height()-2) % 6; 722 int rowModulo = (height()-2) % 6;
717#if 0 723#if 0
718 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 724 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
719 6 - x/daysize.width() : x/daysize.width()); 725 6 - x/daysize.width() : x/daysize.width());
720#endif 726#endif
721 int xVal = (x-colModulo/2-2)/daysize.width(); 727 int xVal = (x-colModulo/2-2)/daysize.width();
722 int yVal = (y-rowModulo/2-2)/daysize.height(); 728 int yVal = (y-rowModulo/2-2)/daysize.height();
723 729
724 730
725 return 7*(yVal) + xVal; 731 return 7*(yVal) + xVal;
726 732
727} 733}
728 734
729// ---------------------------------------------------------------------------- 735// ----------------------------------------------------------------------------
730// M O U S E E V E N T H A N D L I N G 736// M O U S E E V E N T H A N D L I N G
731// ---------------------------------------------------------------------------- 737// ----------------------------------------------------------------------------
732 738
733void KODayMatrix::mousePressEvent (QMouseEvent* e) 739void KODayMatrix::mousePressEvent (QMouseEvent* e)
734{ 740{
735 741
736 if ( e->button() == LeftButton ) 742 if ( e->button() == LeftButton )
737 mouseDown = true; 743 mouseDown = true;
738 mSelStart = getDayIndexFrom(e->x(), e->y()); 744 mSelStart = getDayIndexFrom(e->x(), e->y());
739 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; 745 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
740 mSelInit = mSelStart; 746 mSelInit = mSelStart;
741 mSelEnd = mSelStart; 747 mSelEnd = mSelStart;
742 mRedrawNeeded = true; 748 mRedrawNeeded = true;
743 repaint(false); 749 repaint(false);
744} 750}
745 751
746void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) 752void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
747{ 753{
748 mRedrawNeeded = true; 754 mRedrawNeeded = true;
749 if ( e->button() == LeftButton ) 755 if ( e->button() == LeftButton )
750 if ( ! mouseDown ) { 756 if ( ! mouseDown ) {
751 return; 757 return;
752 } 758 }
753 else 759 else
754 mouseDown = false; 760 mouseDown = false;
755 int tmp = getDayIndexFrom(e->x(), e->y()); 761 int tmp = getDayIndexFrom(e->x(), e->y());
756 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 762 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
757 763
758 if (mSelInit > tmp) { 764 if (mSelInit > tmp) {
759 mSelEnd = mSelInit; 765 mSelEnd = mSelInit;
760 if (tmp != mSelStart) { 766 if (tmp != mSelStart) {
761 mSelStart = tmp; 767 mSelStart = tmp;
762 repaint(false); 768 repaint(false);
763 } 769 }
764 } else { 770 } else {
765 mSelStart = mSelInit; 771 mSelStart = mSelInit;
766 772
767 //repaint only if selection has changed 773 //repaint only if selection has changed
768 if (tmp != mSelEnd) { 774 if (tmp != mSelEnd) {
769 mSelEnd = tmp; 775 mSelEnd = tmp;
770 repaint(false); 776 repaint(false);
771 } 777 }
772 } 778 }
773 779
774 DateList daylist; 780 DateList daylist;
775 if ( mSelStart < 0 ) 781 if ( mSelStart < 0 )
776 mSelStart = 0; 782 mSelStart = 0;
777 for (int i = mSelStart; i <= mSelEnd; i++) { 783 for (int i = mSelStart; i <= mSelEnd; i++) {
778 daylist.append(days[i]); 784 daylist.append(days[i]);
779 } 785 }
780 emit selected((const DateList)daylist); 786 emit selected((const DateList)daylist);
781 787
782} 788}
783 789
784void KODayMatrix::mouseMoveEvent (QMouseEvent* e) 790void KODayMatrix::mouseMoveEvent (QMouseEvent* e)
785{ 791{
786 if ( ! mouseDown ) { 792 if ( ! mouseDown ) {
787 return; 793 return;
788 } 794 }
789 mRedrawNeeded = true; 795 mRedrawNeeded = true;
790 int tmp = getDayIndexFrom(e->x(), e->y()); 796 int tmp = getDayIndexFrom(e->x(), e->y());
791 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 797 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
792 798
793 if (mSelInit > tmp) { 799 if (mSelInit > tmp) {
794 mSelEnd = mSelInit; 800 mSelEnd = mSelInit;
795 if (tmp != mSelStart) { 801 if (tmp != mSelStart) {
796 mSelStart = tmp; 802 mSelStart = tmp;
797 repaint(false); 803 repaint(false);
798 } 804 }
799 } else { 805 } else {
800 mSelStart = mSelInit; 806 mSelStart = mSelInit;
801 807
802 //repaint only if selection has changed 808 //repaint only if selection has changed
803 if (tmp != mSelEnd) { 809 if (tmp != mSelEnd) {
804 mSelEnd = tmp; 810 mSelEnd = tmp;
805 repaint(false); 811 repaint(false);
806 } 812 }
807 } 813 }
808} 814}
809 815
810// ---------------------------------------------------------------------------- 816// ----------------------------------------------------------------------------
811// D R A G ' N D R O P H A N D L I N G 817// D R A G ' N D R O P H A N D L I N G
812// ---------------------------------------------------------------------------- 818// ----------------------------------------------------------------------------
813 819
814void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) 820void KODayMatrix::dragEnterEvent(QDragEnterEvent *e)
815{ 821{
816#ifndef KORG_NODND 822#ifndef KORG_NODND
817 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 823 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
818 e->ignore(); 824 e->ignore();
819 return; 825 return;
820 } 826 }
821 827
822 // some visual feedback 828 // some visual feedback
823// oldPalette = palette(); 829// oldPalette = palette();
824// setPalette(my_HilitePalette); 830// setPalette(my_HilitePalette);
825// update(); 831// update();
826#endif 832#endif
827} 833}
828 834
829void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) 835void KODayMatrix::dragMoveEvent(QDragMoveEvent *e)
830{ 836{
831#ifndef KORG_NODND 837#ifndef KORG_NODND
832 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 838 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
833 e->ignore(); 839 e->ignore();
834 return; 840 return;
835 } 841 }
836 842
837 e->accept(); 843 e->accept();
838#endif 844#endif
839} 845}
840 846
841void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) 847void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/)
842{ 848{
843#ifndef KORG_NODND 849#ifndef KORG_NODND
844// setPalette(oldPalette); 850// setPalette(oldPalette);
845// update(); 851// update();
846#endif 852#endif
847} 853}
848 854
849void KODayMatrix::dropEvent(QDropEvent *e) 855void KODayMatrix::dropEvent(QDropEvent *e)
850{ 856{
851#ifndef KORG_NODND 857#ifndef KORG_NODND
852// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; 858// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl;
853 859
854 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 860 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
855 e->ignore(); 861 e->ignore();
856 return; 862 return;
857 } 863 }
858 864
859 DndFactory factory( mCalendar ); 865 DndFactory factory( mCalendar );
860 Event *event = factory.createDrop(e); 866 Event *event = factory.createDrop(e);
861 867
862 if (event) { 868 if (event) {
863 e->acceptAction(); 869 e->acceptAction();
864 870
865 Event *existingEvent = mCalendar->event(event->uid()); 871 Event *existingEvent = mCalendar->event(event->uid());
866 872
867 if(existingEvent) { 873 if(existingEvent) {
868 // uniquify event 874 // uniquify event
869 event->recreate(); 875 event->recreate();
870/* 876/*
871 KMessageBox::sorry(this, 877 KMessageBox::sorry(this,
872 i18n("Event already exists in this calendar."), 878 i18n("Event already exists in this calendar."),
873 i18n("Drop Event")); 879 i18n("Drop Event"));
874 delete event; 880 delete event;
875 return; 881 return;
876*/ 882*/
877 } 883 }
878// kdDebug() << "Drop new Event" << endl; 884// kdDebug() << "Drop new Event" << endl;