summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kodaymatrix.cpp48
1 files changed, 35 insertions, 13 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index 15a1cb4..507f18e 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -579,292 +579,314 @@ void KODayMatrix::dropEvent(QDropEvent *e)
579 e->acceptAction(); 579 e->acceptAction();
580 580
581 Event *existingEvent = mCalendar->event(event->uid()); 581 Event *existingEvent = mCalendar->event(event->uid());
582 582
583 if(existingEvent) { 583 if(existingEvent) {
584 // uniquify event 584 // uniquify event
585 event->recreate(); 585 event->recreate();
586/* 586/*
587 KMessageBox::sorry(this, 587 KMessageBox::sorry(this,
588 i18n("Event already exists in this calendar."), 588 i18n("Event already exists in this calendar."),
589 i18n("Drop Event")); 589 i18n("Drop Event"));
590 delete event; 590 delete event;
591 return; 591 return;
592*/ 592*/
593 } 593 }
594// kdDebug() << "Drop new Event" << endl; 594// kdDebug() << "Drop new Event" << endl;
595 // Adjust date 595 // Adjust date
596 QDateTime start = event->dtStart(); 596 QDateTime start = event->dtStart();
597 QDateTime end = event->dtEnd(); 597 QDateTime end = event->dtEnd();
598 int duration = start.daysTo(end); 598 int duration = start.daysTo(end);
599 int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); 599 int idx = getDayIndexFrom(e->pos().x(), e->pos().y());
600 600
601 start.setDate(days[idx]); 601 start.setDate(days[idx]);
602 end.setDate(days[idx].addDays(duration)); 602 end.setDate(days[idx].addDays(duration));
603 603
604 event->setDtStart(start); 604 event->setDtStart(start);
605 event->setDtEnd(end); 605 event->setDtEnd(end);
606 mCalendar->addEvent(event); 606 mCalendar->addEvent(event);
607 607
608 emit eventDropped(event); 608 emit eventDropped(event);
609 } else { 609 } else {
610// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; 610// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl;
611 e->ignore(); 611 e->ignore();
612 } 612 }
613#endif 613#endif
614} 614}
615 615
616// ---------------------------------------------------------------------------- 616// ----------------------------------------------------------------------------
617// P A I N T E V E N T H A N D L I N G 617// P A I N T E V E N T H A N D L I N G
618// ---------------------------------------------------------------------------- 618// ----------------------------------------------------------------------------
619 619
620void KODayMatrix::paintEvent(QPaintEvent * pevent) 620void KODayMatrix::paintEvent(QPaintEvent * pevent)
621{ 621{
622 QRect sz = frameRect(); 622 QRect sz = frameRect();
623 if ( sz.width() <= 0 || sz.height() <= 0 ) 623 if ( sz.width() <= 0 || sz.height() <= 0 )
624 return; 624 return;
625 if ( mPendingUpdateBeforeRepaint ) { 625 if ( mPendingUpdateBeforeRepaint ) {
626 updateViewTimed(); 626 updateViewTimed();
627 mPendingUpdateBeforeRepaint = false; 627 mPendingUpdateBeforeRepaint = false;
628 } 628 }
629 if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) { 629 if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) {
630 myPix.resize(sz.size() ); 630 myPix.resize(sz.size() );
631 } 631 }
632 QPainter p(&myPix); 632 QPainter p(&myPix);
633 p.setFont(font()); 633 p.setFont(font());
634 634
635 635
636 int dheight = daysize.height(); 636 int dheight = daysize.height();
637 int dwidth = daysize.width(); 637 int dwidth = daysize.width();
638 int row,col; 638 int row,col;
639 int selw, selh; 639 int selw, selh;
640 int xyOff = frameWidth(); 640 int xyOff = frameWidth();
641 int colModulo = sz.width() % 7; 641 int colModulo = sz.width() % 7;
642 int rowModulo = sz.height() % 6; 642 int rowModulo = sz.height() % 6;
643 qDebug("off %d col %d row %d ",xyOff,colModulo,rowModulo ); 643 //qDebug("off %d col %d row %d ",xyOff,colModulo,rowModulo );
644 644
645 bool isRTL = KOGlobals::self()->reverseLayout(); 645 bool isRTL = KOGlobals::self()->reverseLayout();
646 646
647 // draw background and topleft frame 647 // draw background and topleft frame
648 p.fillRect(pevent->rect(), mDefaultBackColor); 648 p.fillRect(pevent->rect(), mDefaultBackColor);
649 p.setPen(mDefaultTextColor); 649 p.setPen(mDefaultTextColor);
650 p.drawRect(0, 0, sz.width()+1, sz.height()+1); 650 p.drawRect(0, 0, sz.width()+1, sz.height()+1);
651 int mSelStartT = mSelStart; 651 int mSelStartT = mSelStart;
652 int mSelEndT = mSelEnd; 652 int mSelEndT = mSelEnd;
653 if ( mSelEndT >= NUMDAYS ) 653 if ( mSelEndT >= NUMDAYS )
654 mSelEndT = NUMDAYS-1; 654 mSelEndT = NUMDAYS-1;
655 // draw selected days with highlighted background color 655 // draw selected days with highlighted background color
656 if (mSelStart != NOSELECTION) { 656 if (mSelStart != NOSELECTION) {
657 bool skip = false; 657 bool skip = false;
658 if ( ! mouseDown ) { 658 if ( ! mouseDown ) {
659 int mo = days[20].month(); 659 int mo = days[20].month();
660 //qDebug("-- %d %d ", mSelStartT, mSelEndT); 660 //qDebug("-- %d %d ", mSelStartT, mSelEndT);
661 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); 661 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() );
662 if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) { 662 if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) {
663 skip = true; 663 skip = true;
664 } else { 664 } else {
665 if ( days[mSelStartT].month() != mo ) { 665 if ( days[mSelStartT].month() != mo ) {
666 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); 666 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day();
667 mSelStartT += add +1; 667 mSelStartT += add +1;
668 } 668 }
669 if ( days[mSelEndT].month() != mo ) { 669 if ( days[mSelEndT].month() != mo ) {
670 int sub = days[mSelEndT].day(); 670 int sub = days[mSelEndT].day();
671 mSelEndT -= sub ; 671 mSelEndT -= sub ;
672 } 672 }
673 } 673 }
674 } 674 }
675 if ( ! skip ) { 675 if ( ! skip ) {
676 row = mSelStartT/7; 676 row = mSelStartT/7;
677 col = mSelStartT -row*7; 677 col = mSelStartT -row*7;
678 QColor selcol = KOPrefs::instance()->mHighlightColor; 678 QColor selcol = KOPrefs::instance()->mHighlightColor;
679 679
680 680
681 681
682 int addCol = 0; 682 int addCol = 0;
683 int addRow = 0; 683 int addRow = 0;
684 int addRow2 = 0;
685 int addCol2 = 0;
684#if 0 686#if 0
685 if ( colModulo ) { 687 if ( colModulo ) {
686 if ( col >= 7 - colModulo ) 688 if ( col >= 7 - colModulo )
687 addCol = col - 7 + colModulo; 689 addCol = col - 7 + colModulo;
688 } 690 }
689 if ( rowModulo ) { 691 if ( rowModulo ) {
690 if ( row >= 6 - rowModulo ) 692 if ( row >= 6 - rowModulo )
691 addRow = row - 5 + rowModulo; 693 addRow = row - 5 + rowModulo;
692 } 694 }
693#endif 695#endif
694 696
695 697
696 698
697 699
698 700
699 if (row == mSelEndT/7) { 701 if (row == mSelEndT/7) {
700 if ( rowModulo ) { 702 if ( rowModulo ) {
701 if ( row >= 6 - rowModulo ) 703 if ( row >= 6 - rowModulo )
702 addRow = row - 5 + rowModulo; 704 addRow = row - 5 + rowModulo;
703 } 705 }
704 if ( colModulo ) { 706 if ( colModulo ) {
705 if ( mSelEndT-mSelStartT+1 >= 7 - colModulo ) 707 int colt1 = mSelEndT%7;
706 addCol = mSelEndT-mSelStartT+1 - 7 + colModulo; 708 //qDebug("colt1 %d ", colt1 );
709 if ( colt1 >= 7 - colModulo )
710 addCol = colt1 - 7 + colModulo+1;
711 int colt = mSelStartT%7;
712 if ( colt >= 7 - colModulo )
713 addCol2 = colt - 7 + colModulo;
714 addCol -= addCol2;
715 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 );
707 } 716 }
708 // Single row selection 717 // Single row selection
709 if ( row == 0) 718 if ( row == 0)
710 addRow = 1; 719 addRow = 1;
711 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1, 720 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2,
712 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); 721 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol);
713 } else { 722 } else {
714 // draw first row to the right 723 // draw first row to the right
724 if ( colModulo ) {
725 if ( col >= 7 - colModulo )
726 addCol2 = col - 7 + colModulo;
727 }
728 if ( rowModulo ) {
729 if ( row >= 6 - rowModulo )
730 addRow = row - 5 + rowModulo;
731 }
715 if ( row == 0) 732 if ( row == 0)
716 addRow = 1; 733 addRow = 1;
717 p.fillRect(isRTL ? 0 : col*dwidth+1, row*dheight+addRow, (7-col)*dwidth+colModulo, 734 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo,
718 dheight, selcol); 735 dheight+1, selcol);
719 // draw full block till last line 736 // draw full block till last line
720 selh = mSelEndT/7-row; 737 selh = mSelEndT/7-row;
738 addRow = 0;
739 if ( rowModulo ) {
740 if ( mSelEndT/7 >= 6 - rowModulo )
741 addRow = mSelEndT/7 - 5 + rowModulo;
742 }
721 if (selh > 1) { 743 if (selh > 1) {
722 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight,selcol); 744 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol);
723 } 745 }
724 // draw last block from left to mSelEndT 746 // draw last block from left to mSelEndT
725 selw = mSelEndT-7*(mSelEndT/7)+1; 747 selw = mSelEndT-7*(mSelEndT/7)+1;
726 //qDebug("esl %d ",selw ); 748 //qDebug("esl %d ",selw );
727 int add = 0; 749 int add = 0;
728 if ( colModulo ) { 750 if ( colModulo ) {
729 add = 7 - colModulo; 751 add = 7 - colModulo;
730 if ( selw > add ) 752 if ( selw > add )
731 add = selw - add; 753 add = selw - add;
732 else 754 else
733 add = 0; 755 add = 0;
734 } 756 }
735 //qDebug("add %d ", add); 757 //qDebug("add %d ", add);
736 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight, 758 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow,
737 selw*dwidth+add, dheight, selcol); 759 selw*dwidth+add, dheight+1, selcol);
738 } 760 }
739 } 761 }
740 } 762 }
741 763
742 // iterate over all days in the matrix and draw the day label in appropriate colors 764 // iterate over all days in the matrix and draw the day label in appropriate colors
743 QColor actcol = mDefaultTextColorShaded; 765 QColor actcol = mDefaultTextColorShaded;
744 p.setPen(actcol); 766 p.setPen(actcol);
745 QPen tmppen; 767 QPen tmppen;
746 for(int i = 0; i < NUMDAYS; i++) { 768 for(int i = 0; i < NUMDAYS; i++) {
747 row = i/7; 769 row = i/7;
748 col = isRTL ? 6-(i-row*7) : i-row*7; 770 col = isRTL ? 6-(i-row*7) : i-row*7;
749 771
750 // if it is the first day of a month switch color from normal to shaded and vice versa 772 // if it is the first day of a month switch color from normal to shaded and vice versa
751 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { 773 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) {
752 if (actcol == mDefaultTextColorShaded) { 774 if (actcol == mDefaultTextColorShaded) {
753 actcol = mDefaultTextColor; 775 actcol = mDefaultTextColor;
754 } else { 776 } else {
755 actcol = mDefaultTextColorShaded; 777 actcol = mDefaultTextColorShaded;
756 } 778 }
757 p.setPen(actcol); 779 p.setPen(actcol);
758 } 780 }
759 if (actcol == mDefaultTextColorShaded) { 781 if (actcol == mDefaultTextColorShaded) {
760 if ( ! mouseDown ) { 782 if ( ! mouseDown ) {
761 continue; 783 continue;
762 } 784 }
763 } 785 }
764 //Reset pen color after selected days block 786 //Reset pen color after selected days block
765 if (i == mSelEndT+1) { 787 if (i == mSelEndT+1) {
766 p.setPen(actcol); 788 p.setPen(actcol);
767 } 789 }
768 790
769 // if today then draw rectangle around day 791 // if today then draw rectangle around day
770 if (today == i) { 792 if (today == i) {
771 tmppen = p.pen(); 793 tmppen = p.pen();
772 QPen mTodayPen(p.pen()); 794 QPen mTodayPen(p.pen());
773 795
774 mTodayPen.setWidth(mTodayMarginWidth); 796 mTodayPen.setWidth(mTodayMarginWidth);
775 //draw red rectangle for holidays 797 //draw red rectangle for holidays
776 if (!mHolidays[i].isNull()) { 798 if (!mHolidays[i].isNull()) {
777 if (actcol == mDefaultTextColor) { 799 if (actcol == mDefaultTextColor) {
778 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); 800 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor);
779 } else { 801 } else {
780 mTodayPen.setColor(mHolidayColorShaded); 802 mTodayPen.setColor(mHolidayColorShaded);
781 } 803 }
782 } 804 }
783 //draw gray rectangle for today if in selection 805 //draw gray rectangle for today if in selection
784 if (i >= mSelStartT && i <= mSelEndT) { 806 if (i >= mSelStartT && i <= mSelEndT) {
785 QColor grey("grey"); 807 QColor grey("grey");
786 mTodayPen.setColor(grey); 808 mTodayPen.setColor(grey);
787 } 809 }
788 p.setPen(mTodayPen); 810 p.setPen(mTodayPen);
789 p.drawRect(col*dwidth, row*dheight, dwidth, dheight); 811 p.drawRect(col*dwidth, row*dheight, dwidth, dheight);
790 p.setPen(tmppen); 812 p.setPen(tmppen);
791 } 813 }
792 814
793 // if any events are on that day then draw it using a bold font 815 // if any events are on that day then draw it using a bold font
794 if (events[i] > 0) { 816 if (events[i] > 0) {
795 QFont myFont = font(); 817 QFont myFont = font();
796 myFont.setBold(true); 818 myFont.setBold(true);
797 p.setFont(myFont); 819 p.setFont(myFont);
798 } 820 }
799 821
800 // if it is a holiday then use the default holiday color 822 // if it is a holiday then use the default holiday color
801 if (!mHolidays[i].isNull()) { 823 if (!mHolidays[i].isNull()) {
802 if ( bDays.testBit(i) ) { 824 if ( bDays.testBit(i) ) {
803 p.setPen(Qt::green); 825 p.setPen(Qt::green);
804 } else { 826 } else {
805 if (actcol == mDefaultTextColor) { 827 if (actcol == mDefaultTextColor) {
806 p.setPen(KOPrefs::instance()->mHolidayColor); 828 p.setPen(KOPrefs::instance()->mHolidayColor);
807 } else { 829 } else {
808 p.setPen(mHolidayColorShaded); 830 p.setPen(mHolidayColorShaded);
809 } 831 }
810 } 832 }
811 } 833 }
812 834
813 // draw selected days with special color 835 // draw selected days with special color
814 // DO NOT specially highlight holidays in selection ! 836 // DO NOT specially highlight holidays in selection !
815 if (i >= mSelStartT && i <= mSelEndT) { 837 if (i >= mSelStartT && i <= mSelEndT) {
816 ;//p.setPen(mSelectedDaysColor); 838 ;//p.setPen(mSelectedDaysColor);
817 } 839 }
818 840
819 int addCol = 0; 841 int addCol = 0;
820 int addRow = 0; 842 int addRow = 0;
821 if ( colModulo ) { 843 if ( colModulo ) {
822 if ( col >= 7 - colModulo ) 844 if ( col >= 7 - colModulo )
823 addCol = col - 7 + colModulo; 845 addCol = col - 7 + colModulo;
824 } 846 }
825 if ( rowModulo ) { 847 if ( rowModulo ) {
826 if ( row >= 6 - rowModulo ) 848 if ( row >= 6 - rowModulo )
827 addRow = row - 5 + rowModulo; 849 addRow = row - 5 + rowModulo;
828 } 850 }
829 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); 851 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow);
830 ++addCol;++addCol; 852 ++addCol;//++addCol;
831 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, 853 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight,
832 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); 854 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]);
833 855
834 // reset color to actual color 856 // reset color to actual color
835 if (!mHolidays[i].isNull()) { 857 if (!mHolidays[i].isNull()) {
836 p.setPen(actcol); 858 p.setPen(actcol);
837 } 859 }
838 // reset bold font to plain font 860 // reset bold font to plain font
839 if (events[i] > 0) { 861 if (events[i] > 0) {
840 QFont myFont = font(); 862 QFont myFont = font();
841 myFont.setBold(false); 863 myFont.setBold(false);
842 p.setFont(myFont); 864 p.setFont(myFont);
843 } 865 }
844 } 866 }
845 int off = xyOff; 867 int off = xyOff;
846 bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP); 868 bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP);
847 //qDebug("ffffffffff %d ", off); 869 //qDebug("ffffffffff %d ", off);
848} 870}
849 871
850// ---------------------------------------------------------------------------- 872// ----------------------------------------------------------------------------
851// R E SI Z E E V E N T H A N D L I N G 873// R E SI Z E E V E N T H A N D L I N G
852// ---------------------------------------------------------------------------- 874// ----------------------------------------------------------------------------
853 875
854void KODayMatrix::resizeEvent(QResizeEvent *) 876void KODayMatrix::resizeEvent(QResizeEvent *)
855{ 877{
856 QRect sz = frameRect(); 878 QRect sz = frameRect();
857 daysize.setHeight(sz.height()*7 / NUMDAYS); 879 daysize.setHeight(sz.height()*7 / NUMDAYS);
858 daysize.setWidth(sz.width() / 7); 880 daysize.setWidth(sz.width() / 7);
859} 881}
860 882
861QSize KODayMatrix::sizeHint() const 883QSize KODayMatrix::sizeHint() const
862{ 884{
863 885
864 QFontMetrics fm ( font() ); 886 QFontMetrics fm ( font() );
865 int wid = fm.width( "30") *7+3; 887 int wid = fm.width( "30") *7+3;
866 int hei = fm.height() * 6+3; 888 int hei = fm.height() * 6+3;
867 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); 889 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei);
868 return QSize ( wid, hei ); 890 return QSize ( wid, hei );
869 891
870} 892}