author | zautrix <zautrix> | 2005-03-20 20:24:06 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-20 20:24:06 (UTC) |
commit | b32c8de5dcd6c4f8dce9415fb686970e2c991ebb (patch) (unidiff) | |
tree | ee5ba00bcc830d011a816981fd20dcf781b9cbf5 | |
parent | 64068741e3b82a34c1b8a67da412ac88841b640c (diff) | |
download | kdepimpi-b32c8de5dcd6c4f8dce9415fb686970e2c991ebb.zip kdepimpi-b32c8de5dcd6c4f8dce9415fb686970e2c991ebb.tar.gz kdepimpi-b32c8de5dcd6c4f8dce9415fb686970e2c991ebb.tar.bz2 |
nf
-rw-r--r-- | korganizer/kodaymatrix.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index f864022..ae0a051 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp | |||
@@ -397,99 +397,109 @@ void KODayMatrix::updateView(QDate actdate) | |||
397 | #else | 397 | #else |
398 | mRepaintTimer->start( 350 ); | 398 | mRepaintTimer->start( 350 ); |
399 | mUpdateTimer->start( 1200 ); | 399 | mUpdateTimer->start( 1200 ); |
400 | #endif | 400 | #endif |
401 | } | 401 | } |
402 | } | 402 | } |
403 | void KODayMatrix::updateEvents() | 403 | void KODayMatrix::updateEvents() |
404 | { | 404 | { |
405 | if ( !mCalendar ) return; | 405 | if ( !mCalendar ) return; |
406 | 406 | ||
407 | for( int i = 0; i < NUMDAYS; i++ ) { | 407 | for( int i = 0; i < NUMDAYS; i++ ) { |
408 | // if events are set for the day then remember to draw it bold | 408 | // if events are set for the day then remember to draw it bold |
409 | QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); | 409 | QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); |
410 | int numEvents = eventlist.count(); | 410 | int numEvents = eventlist.count(); |
411 | Event *event; | 411 | Event *event; |
412 | for( event = eventlist.first(); event != 0;event=eventlist.next()) { | 412 | for( event = eventlist.first(); event != 0;event=eventlist.next()) { |
413 | ushort recurType = event->doesRecur(); | 413 | ushort recurType = event->doesRecur(); |
414 | 414 | ||
415 | if ( ( recurType == Recurrence::rDaily && | 415 | if ( ( recurType == Recurrence::rDaily && |
416 | !KOPrefs::instance()->mDailyRecur ) || | 416 | !KOPrefs::instance()->mDailyRecur ) || |
417 | ( recurType == Recurrence::rWeekly && | 417 | ( recurType == Recurrence::rWeekly && |
418 | !KOPrefs::instance()->mWeeklyRecur ) ) { | 418 | !KOPrefs::instance()->mWeeklyRecur ) ) { |
419 | numEvents--; | 419 | numEvents--; |
420 | } | 420 | } |
421 | } | 421 | } |
422 | events[ i ] = numEvents; | 422 | events[ i ] = numEvents; |
423 | } | 423 | } |
424 | } | 424 | } |
425 | 425 | ||
426 | const QDate& KODayMatrix::getDate(int offset) | 426 | const QDate& KODayMatrix::getDate(int offset) |
427 | { | 427 | { |
428 | if (offset < 0 || offset > NUMDAYS-1) { | 428 | if (offset < 0 || offset > NUMDAYS-1) { |
429 | qDebug("Wrong offset2 "); | 429 | qDebug("Wrong offset2 "); |
430 | return days[0]; | 430 | return days[0]; |
431 | } | 431 | } |
432 | return days[offset]; | 432 | return days[offset]; |
433 | } | 433 | } |
434 | 434 | ||
435 | QString KODayMatrix::getHolidayLabel(int offset) | 435 | QString KODayMatrix::getHolidayLabel(int offset) |
436 | { | 436 | { |
437 | if (offset < 0 || offset > NUMDAYS-1) { | 437 | if (offset < 0 || offset > NUMDAYS-1) { |
438 | qDebug("Wrong offset1 "); | 438 | qDebug("Wrong offset1 "); |
439 | return 0; | 439 | return 0; |
440 | } | 440 | } |
441 | return mHolidays[offset]; | 441 | return mHolidays[offset]; |
442 | } | 442 | } |
443 | 443 | ||
444 | int KODayMatrix::getDayIndexFrom(int x, int y) | 444 | int KODayMatrix::getDayIndexFrom(int x, int y) |
445 | { | 445 | { |
446 | int colModulo = (width()-2) % 7; | ||
447 | int rowModulo = (height()-2) % 6; | ||
448 | #if 0 | ||
446 | return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? | 449 | return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? |
447 | 6 - x/daysize.width() : x/daysize.width()); | 450 | 6 - x/daysize.width() : x/daysize.width()); |
451 | #endif | ||
452 | int xVal = (x-colModulo/2-2)/daysize.width(); | ||
453 | int yVal = (y-rowModulo/2-2)/daysize.height(); | ||
454 | |||
455 | |||
456 | return 7*(yVal) + xVal; | ||
457 | |||
448 | } | 458 | } |
449 | 459 | ||
450 | // ---------------------------------------------------------------------------- | 460 | // ---------------------------------------------------------------------------- |
451 | // M O U S E E V E N T H A N D L I N G | 461 | // M O U S E E V E N T H A N D L I N G |
452 | // ---------------------------------------------------------------------------- | 462 | // ---------------------------------------------------------------------------- |
453 | 463 | ||
454 | void KODayMatrix::mousePressEvent (QMouseEvent* e) | 464 | void KODayMatrix::mousePressEvent (QMouseEvent* e) |
455 | { | 465 | { |
456 | 466 | ||
457 | if ( e->button() == LeftButton ) | 467 | if ( e->button() == LeftButton ) |
458 | mouseDown = true; | 468 | mouseDown = true; |
459 | mSelStart = getDayIndexFrom(e->x(), e->y()); | 469 | mSelStart = getDayIndexFrom(e->x(), e->y()); |
460 | if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; | 470 | if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; |
461 | mSelInit = mSelStart; | 471 | mSelInit = mSelStart; |
462 | mSelEnd = mSelStart; | 472 | mSelEnd = mSelStart; |
463 | repaint(false); | 473 | repaint(false); |
464 | } | 474 | } |
465 | 475 | ||
466 | void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) | 476 | void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) |
467 | { | 477 | { |
468 | if ( e->button() == LeftButton ) | 478 | if ( e->button() == LeftButton ) |
469 | if ( ! mouseDown ) { | 479 | if ( ! mouseDown ) { |
470 | return; | 480 | return; |
471 | } | 481 | } |
472 | else | 482 | else |
473 | mouseDown = false; | 483 | mouseDown = false; |
474 | int tmp = getDayIndexFrom(e->x(), e->y()); | 484 | int tmp = getDayIndexFrom(e->x(), e->y()); |
475 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; | 485 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; |
476 | 486 | ||
477 | if (mSelInit > tmp) { | 487 | if (mSelInit > tmp) { |
478 | mSelEnd = mSelInit; | 488 | mSelEnd = mSelInit; |
479 | if (tmp != mSelStart) { | 489 | if (tmp != mSelStart) { |
480 | mSelStart = tmp; | 490 | mSelStart = tmp; |
481 | repaint(false); | 491 | repaint(false); |
482 | } | 492 | } |
483 | } else { | 493 | } else { |
484 | mSelStart = mSelInit; | 494 | mSelStart = mSelInit; |
485 | 495 | ||
486 | //repaint only if selection has changed | 496 | //repaint only if selection has changed |
487 | if (tmp != mSelEnd) { | 497 | if (tmp != mSelEnd) { |
488 | mSelEnd = tmp; | 498 | mSelEnd = tmp; |
489 | repaint(false); | 499 | repaint(false); |
490 | } | 500 | } |
491 | } | 501 | } |
492 | 502 | ||
493 | DateList daylist; | 503 | DateList daylist; |
494 | if ( mSelStart < 0 ) | 504 | if ( mSelStart < 0 ) |
495 | mSelStart = 0; | 505 | mSelStart = 0; |
@@ -597,97 +607,97 @@ void KODayMatrix::dropEvent(QDropEvent *e) | |||
597 | // Adjust date | 607 | // Adjust date |
598 | QDateTime start = event->dtStart(); | 608 | QDateTime start = event->dtStart(); |
599 | QDateTime end = event->dtEnd(); | 609 | QDateTime end = event->dtEnd(); |
600 | int duration = start.daysTo(end); | 610 | int duration = start.daysTo(end); |
601 | int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); | 611 | int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); |
602 | 612 | ||
603 | start.setDate(days[idx]); | 613 | start.setDate(days[idx]); |
604 | end.setDate(days[idx].addDays(duration)); | 614 | end.setDate(days[idx].addDays(duration)); |
605 | 615 | ||
606 | event->setDtStart(start); | 616 | event->setDtStart(start); |
607 | event->setDtEnd(end); | 617 | event->setDtEnd(end); |
608 | mCalendar->addEvent(event); | 618 | mCalendar->addEvent(event); |
609 | 619 | ||
610 | emit eventDropped(event); | 620 | emit eventDropped(event); |
611 | } else { | 621 | } else { |
612 | // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; | 622 | // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; |
613 | e->ignore(); | 623 | e->ignore(); |
614 | } | 624 | } |
615 | #endif | 625 | #endif |
616 | } | 626 | } |
617 | 627 | ||
618 | // ---------------------------------------------------------------------------- | 628 | // ---------------------------------------------------------------------------- |
619 | // P A I N T E V E N T H A N D L I N G | 629 | // P A I N T E V E N T H A N D L I N G |
620 | // ---------------------------------------------------------------------------- | 630 | // ---------------------------------------------------------------------------- |
621 | 631 | ||
622 | void KODayMatrix::paintEvent(QPaintEvent * pevent) | 632 | void KODayMatrix::paintEvent(QPaintEvent * pevent) |
623 | { | 633 | { |
624 | QRect sz = frameRect(); | 634 | QRect sz = frameRect(); |
625 | if ( sz.width() <= 0 || sz.height() <= 0 ) | 635 | if ( sz.width() <= 0 || sz.height() <= 0 ) |
626 | return; | 636 | return; |
627 | if ( mPendingUpdateBeforeRepaint ) { | 637 | if ( mPendingUpdateBeforeRepaint ) { |
628 | updateViewTimed(); | 638 | updateViewTimed(); |
629 | mPendingUpdateBeforeRepaint = false; | 639 | mPendingUpdateBeforeRepaint = false; |
630 | } | 640 | } |
631 | if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) { | 641 | if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) { |
632 | myPix.resize(sz.size() ); | 642 | myPix.resize(sz.size() ); |
633 | } | 643 | } |
634 | QPainter p(&myPix); | 644 | QPainter p(&myPix); |
635 | p.setFont(font()); | 645 | p.setFont(font()); |
636 | 646 | ||
637 | 647 | ||
638 | int dheight = daysize.height(); | 648 | int dheight = daysize.height(); |
639 | int dwidth = daysize.width(); | 649 | int dwidth = daysize.width(); |
640 | int row,col; | 650 | int row,col; |
641 | int selw, selh; | 651 | int selw, selh; |
642 | int xyOff = frameWidth(); | 652 | int xyOff = frameWidth(); |
643 | int colModulo = sz.width() % 7; | 653 | int colModulo = sz.width() % 7; |
644 | int rowModulo = sz.height() % 6; | 654 | int rowModulo = sz.height() % 6; |
645 | qDebug("col %d row %d ",colModulo,rowModulo ); | 655 | //qDebug("col %d row %d ",colModulo,rowModulo ); |
646 | 656 | ||
647 | bool isRTL = KOGlobals::self()->reverseLayout(); | 657 | bool isRTL = KOGlobals::self()->reverseLayout(); |
648 | 658 | ||
649 | // draw background and topleft frame | 659 | // draw background and topleft frame |
650 | p.fillRect(pevent->rect(), mDefaultBackColor); | 660 | p.fillRect(pevent->rect(), mDefaultBackColor); |
651 | p.setPen(mDefaultTextColor); | 661 | p.setPen(mDefaultTextColor); |
652 | p.drawRect(0, 0, sz.width()+1, sz.height()+1); | 662 | p.drawRect(0, 0, sz.width()+1, sz.height()+1); |
653 | int mSelStartT = mSelStart; | 663 | int mSelStartT = mSelStart; |
654 | int mSelEndT = mSelEnd; | 664 | int mSelEndT = mSelEnd; |
655 | if ( mSelEndT >= NUMDAYS ) | 665 | if ( mSelEndT >= NUMDAYS ) |
656 | mSelEndT = NUMDAYS-1; | 666 | mSelEndT = NUMDAYS-1; |
657 | // draw selected days with highlighted background color | 667 | // draw selected days with highlighted background color |
658 | if (mSelStart != NOSELECTION) { | 668 | if (mSelStart != NOSELECTION) { |
659 | bool skip = false; | 669 | bool skip = false; |
660 | if ( ! mouseDown ) { | 670 | if ( ! mouseDown ) { |
661 | int mo = days[20].month(); | 671 | int mo = days[20].month(); |
662 | //qDebug("-- %d %d ", mSelStartT, mSelEndT); | 672 | //qDebug("-- %d %d ", mSelStartT, mSelEndT); |
663 | //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); | 673 | //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); |
664 | if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) { | 674 | if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) { |
665 | skip = true; | 675 | skip = true; |
666 | } else { | 676 | } else { |
667 | if ( days[mSelStartT].month() != mo ) { | 677 | if ( days[mSelStartT].month() != mo ) { |
668 | int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); | 678 | int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); |
669 | mSelStartT += add +1; | 679 | mSelStartT += add +1; |
670 | } | 680 | } |
671 | if ( days[mSelEndT].month() != mo ) { | 681 | if ( days[mSelEndT].month() != mo ) { |
672 | int sub = days[mSelEndT].day(); | 682 | int sub = days[mSelEndT].day(); |
673 | mSelEndT -= sub ; | 683 | mSelEndT -= sub ; |
674 | } | 684 | } |
675 | } | 685 | } |
676 | } | 686 | } |
677 | if ( ! skip ) { | 687 | if ( ! skip ) { |
678 | row = mSelStartT/7; | 688 | row = mSelStartT/7; |
679 | col = mSelStartT -row*7; | 689 | col = mSelStartT -row*7; |
680 | QColor selcol = KOPrefs::instance()->mHighlightColor; | 690 | QColor selcol = KOPrefs::instance()->mHighlightColor; |
681 | int addCol = 0; | 691 | int addCol = 0; |
682 | int addRow = 0; | 692 | int addRow = 0; |
683 | int addRow2 = 0; | 693 | int addRow2 = 0; |
684 | int addCol2 = 0; | 694 | int addCol2 = 0; |
685 | if (row == mSelEndT/7) { | 695 | if (row == mSelEndT/7) { |
686 | if ( rowModulo ) { | 696 | if ( rowModulo ) { |
687 | if ( row >= 6 - rowModulo ) | 697 | if ( row >= 6 - rowModulo ) |
688 | addRow = row - 5 + rowModulo; | 698 | addRow = row - 5 + rowModulo; |
689 | } | 699 | } |
690 | if ( colModulo ) { | 700 | if ( colModulo ) { |
691 | int colt1 = mSelEndT%7; | 701 | int colt1 = mSelEndT%7; |
692 | //qDebug("colt1 %d ", colt1 ); | 702 | //qDebug("colt1 %d ", colt1 ); |
693 | if ( colt1 >= 7 - colModulo ) | 703 | if ( colt1 >= 7 - colModulo ) |