summaryrefslogtreecommitdiffabout
path: root/korganizer/kodaymatrix.cpp
Unidiff
Diffstat (limited to 'korganizer/kodaymatrix.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kodaymatrix.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index 366e8b8..59618bf 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -615,200 +615,201 @@ void KODayMatrix::dropEvent(QDropEvent *e)
615 615
616 DndFactory factory( mCalendar ); 616 DndFactory factory( mCalendar );
617 Event *event = factory.createDrop(e); 617 Event *event = factory.createDrop(e);
618 618
619 if (event) { 619 if (event) {
620 e->acceptAction(); 620 e->acceptAction();
621 621
622 Event *existingEvent = mCalendar->event(event->uid()); 622 Event *existingEvent = mCalendar->event(event->uid());
623 623
624 if(existingEvent) { 624 if(existingEvent) {
625 // uniquify event 625 // uniquify event
626 event->recreate(); 626 event->recreate();
627/* 627/*
628 KMessageBox::sorry(this, 628 KMessageBox::sorry(this,
629 i18n("Event already exists in this calendar."), 629 i18n("Event already exists in this calendar."),
630 i18n("Drop Event")); 630 i18n("Drop Event"));
631 delete event; 631 delete event;
632 return; 632 return;
633*/ 633*/
634 } 634 }
635// kdDebug() << "Drop new Event" << endl; 635// kdDebug() << "Drop new Event" << endl;
636 // Adjust date 636 // Adjust date
637 QDateTime start = event->dtStart(); 637 QDateTime start = event->dtStart();
638 QDateTime end = event->dtEnd(); 638 QDateTime end = event->dtEnd();
639 int duration = start.daysTo(end); 639 int duration = start.daysTo(end);
640 int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); 640 int idx = getDayIndexFrom(e->pos().x(), e->pos().y());
641 641
642 start.setDate(days[idx]); 642 start.setDate(days[idx]);
643 end.setDate(days[idx].addDays(duration)); 643 end.setDate(days[idx].addDays(duration));
644 644
645 event->setDtStart(start); 645 event->setDtStart(start);
646 event->setDtEnd(end); 646 event->setDtEnd(end);
647 mCalendar->addEvent(event); 647 mCalendar->addEvent(event);
648 648
649 emit eventDropped(event); 649 emit eventDropped(event);
650 } else { 650 } else {
651// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; 651// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl;
652 e->ignore(); 652 e->ignore();
653 } 653 }
654#endif 654#endif
655} 655}
656 656
657// ---------------------------------------------------------------------------- 657// ----------------------------------------------------------------------------
658// P A I N T E V E N T H A N D L I N G 658// P A I N T E V E N T H A N D L I N G
659// ---------------------------------------------------------------------------- 659// ----------------------------------------------------------------------------
660 660
661void KODayMatrix::paintEvent(QPaintEvent * pevent) 661void KODayMatrix::paintEvent(QPaintEvent * pevent)
662{ 662{
663 QRect sz = frameRect(); 663
664 if ( sz.width() <= 0 || sz.height() <= 0 ) 664 if ( width() <= 0 || height() <= 0 )
665 return; 665 return;
666 if ( mPendingUpdateBeforeRepaint ) { 666 if ( mPendingUpdateBeforeRepaint ) {
667 updateViewTimed(); 667 updateViewTimed();
668 mPendingUpdateBeforeRepaint = false; 668 mPendingUpdateBeforeRepaint = false;
669 } 669 }
670 if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) { 670 if ( myPix.width() != width() || myPix.height()!=height() ) {
671 myPix.resize(sz.size() ); 671 myPix.resize(size() );
672 } 672 }
673 QPainter p(&myPix); 673 QPainter p(&myPix);
674 p.setFont(font()); 674 p.setFont(font());
675 675
676 676
677 int dheight = daysize.height(); 677 int dheight = daysize.height();
678 int dwidth = daysize.width(); 678 int dwidth = daysize.width();
679 int row,col; 679 int row,col;
680 int selw, selh; 680 int selw, selh;
681 int xyOff = frameWidth(); 681 int xyOff = frameWidth();
682 int colModulo = sz.width() % 7; 682 int colModulo = (width()-2) % 7;
683 int rowModulo = sz.height() % 6; 683 int rowModulo = (height()-2) % 6;
684 //qDebug("col %d row %d ",colModulo,rowModulo ); 684 //qDebug("col %d row %d ",colModulo,rowModulo );
685 685
686 bool isRTL = KOGlobals::self()->reverseLayout(); 686 bool isRTL = KOGlobals::self()->reverseLayout();
687 687
688 // draw background and topleft frame 688 // draw background and topleft frame
689 p.fillRect(pevent->rect(), mDefaultBackColor); 689 p.fillRect(0,0,width(),height(), mDefaultBackColor);
690 p.setPen(mDefaultTextColor); 690 p.setPen(mDefaultTextColor);
691 p.drawRect(0, 0, sz.width()+1, sz.height()+1); 691 p.drawRect(0, 0, width(), height());
692 int mSelStartT = mSelStart; 692 int mSelStartT = mSelStart;
693 int mSelEndT = mSelEnd; 693 int mSelEndT = mSelEnd;
694 if ( mSelEndT >= NUMDAYS ) 694 if ( mSelEndT >= NUMDAYS )
695 mSelEndT = NUMDAYS-1; 695 mSelEndT = NUMDAYS-1;
696 // draw selected days with highlighted background color 696 // draw selected days with highlighted background color
697 if (mSelStart != NOSELECTION) { 697 if (mSelStart != NOSELECTION) {
698 bool skip = false; 698 bool skip = false;
699 if ( ! mouseDown ) { 699 if ( ! mouseDown ) {
700 int mo = days[20].month(); 700 int mo = days[20].month();
701 //qDebug("-- %d %d ", mSelStartT, mSelEndT); 701 //qDebug("-- %d %d ", mSelStartT, mSelEndT);
702 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); 702 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() );
703 int startMo = days[mSelStartT].month(); 703 int startMo = days[mSelStartT].month();
704 int endMo = days[mSelEndT].month(); 704 int endMo = days[mSelEndT].month();
705 if ( startMo == 12 && mo == 1 && endMo <= 2 ) 705 if ( startMo == 12 && mo == 1 && endMo <= 2 )
706 startMo = 1; 706 startMo = 1;
707 if ( endMo == 1 && mo == 12 ) 707 if ( endMo == 1 && mo == 12 )
708 endMo = 12; 708 endMo = 12;
709 if ( mo == 12 && startMo == 1 ) 709 if ( mo == 12 && startMo == 1 )
710 startMo = 13; 710 startMo = 13;
711 if ( (startMo > mo || endMo < mo) ) { 711 if ( (startMo > mo || endMo < mo) ) {
712 skip = true; 712 skip = true;
713 } else { 713 } else {
714 if ( days[mSelStartT].month() != mo ) { 714 if ( days[mSelStartT].month() != mo ) {
715 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); 715 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day();
716 mSelStartT += add +1; 716 mSelStartT += add +1;
717 } 717 }
718 if ( days[mSelEndT].month() != mo ) { 718 if ( days[mSelEndT].month() != mo ) {
719 int sub = days[mSelEndT].day(); 719 int sub = days[mSelEndT].day();
720 mSelEndT -= sub ; 720 mSelEndT -= sub ;
721 } 721 }
722 } 722 }
723 } 723 }
724 //qDebug("SKIP %d ", skip); 724 //qDebug("SKIP %d ", skip);
725 if ( ! skip ) { 725 if ( ! skip ) {
726 row = mSelStartT/7; 726 row = mSelStartT/7;
727 col = mSelStartT -row*7; 727 col = mSelStartT -row*7;
728 QColor selcol = KOPrefs::instance()->mHighlightColor; 728 QColor selcol = KOPrefs::instance()->mHighlightColor;
729 int addCol = 0; 729 int addCol = 0;
730 int addRow = 0; 730 int addRow = 0;
731 int addRow2 = 0; 731 int addRow2 = 0;
732 int addCol2 = 0; 732 int addCol2 = 0;
733 if (row == mSelEndT/7) { 733 if (row == mSelEndT/7) {
734 if ( rowModulo ) { 734 if ( rowModulo ) {
735 if ( row >= 6 - rowModulo ) 735 if ( row >= 6 - rowModulo )
736 addRow = row - 5 + rowModulo; 736 addRow = row - 5 + rowModulo;
737 } 737 }
738 if ( colModulo ) { 738 if ( colModulo ) {
739 int colt1 = mSelEndT%7; 739 int colt1 = mSelEndT%7;
740 //qDebug("colt1 %d ", colt1 ); 740 //qDebug("colt1 %d ", colt1 );
741 if ( colt1 >= 7 - colModulo ) 741 if ( colt1 >= 7 - colModulo )
742 addCol = colt1 - 7 + colModulo+1; 742 addCol = colt1 - 7 + colModulo+1;
743 int colt = mSelStartT%7; 743 int colt = mSelStartT%7;
744 if ( colt >= 7 - colModulo ) 744 if ( colt >= 7 - colModulo )
745 addCol2 = colt - 7 + colModulo; 745 addCol2 = colt - 7 + colModulo;
746 addCol -= addCol2; 746 addCol -= addCol2;
747 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); 747 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 );
748 } 748 }
749 // Single row selection 749 // Single row selection
750 if ( row == 0) 750 if ( row == 0)
751 addRow = 1; 751 addRow = 1;
752 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, 752 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2,
753 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); 753 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol);
754 } else { 754 } else {
755 // draw first row to the right 755 // draw first row to the right
756 if ( colModulo ) { 756 if ( colModulo ) {
757 if ( col >= 7 - colModulo ) 757 if ( col >= 7 - colModulo )
758 addCol2 = col - 7 + colModulo; 758 addCol2 = col - 7 + colModulo;
759 } 759 }
760 if ( rowModulo ) { 760 if ( rowModulo ) {
761 if ( row >= 6 - rowModulo ) 761 if ( row >= 6 - rowModulo )
762 addRow = row - 5 + rowModulo; 762 addRow = row - 5 + rowModulo;
763 } 763 }
764 if ( row == 0) 764 if ( row == 0)
765 addRow = 1; 765 addRow = 1;
766 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo, 766 int drawWid = width()-(col*dwidth+1+addCol2)-1;
767 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, drawWid,
767 dheight+1, selcol); 768 dheight+1, selcol);
768 // draw full block till last line 769 // draw full block till last line
769 selh = mSelEndT/7-row; 770 selh = mSelEndT/7-row;
770 addRow = 0; 771 addRow = 0;
771 if ( rowModulo ) { 772 if ( rowModulo ) {
772 if ( mSelEndT/7 >= 6 - rowModulo ) 773 if ( mSelEndT/7 >= 6 - rowModulo )
773 addRow = mSelEndT/7 - 5 + rowModulo; 774 addRow = mSelEndT/7 - 5 + rowModulo;
774 } 775 }
775 if (selh > 1) { 776 if (selh > 1) {
776 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); 777 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol);
777 } 778 }
778 // draw last block from left to mSelEndT 779 // draw last block from left to mSelEndT
779 selw = mSelEndT-7*(mSelEndT/7)+1; 780 selw = mSelEndT-7*(mSelEndT/7)+1;
780 //qDebug("esl %d ",selw ); 781 //qDebug("esl %d ",selw );
781 int add = 0; 782 int add = 0;
782 if ( colModulo ) { 783 if ( colModulo ) {
783 add = 7 - colModulo; 784 add = 7 - colModulo;
784 if ( selw > add ) 785 if ( selw > add )
785 add = selw - add; 786 add = selw - add;
786 else 787 else
787 add = 0; 788 add = 0;
788 } 789 }
789 //qDebug("add %d ", add); 790 //qDebug("add %d ", add);
790 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, 791 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow,
791 selw*dwidth+add, dheight+1, selcol); 792 selw*dwidth+add, dheight+1, selcol);
792 } 793 }
793 } 794 }
794 } 795 }
795 796
796 // iterate over all days in the matrix and draw the day label in appropriate colors 797 // iterate over all days in the matrix and draw the day label in appropriate colors
797 QColor actcol = mDefaultTextColorShaded; 798 QColor actcol = mDefaultTextColorShaded;
798 p.setPen(actcol); 799 p.setPen(actcol);
799 QPen tmppen; 800 QPen tmppen;
800 for(int i = 0; i < NUMDAYS; i++) { 801 for(int i = 0; i < NUMDAYS; i++) {
801 row = i/7; 802 row = i/7;
802 col = isRTL ? 6-(i-row*7) : i-row*7; 803 col = isRTL ? 6-(i-row*7) : i-row*7;
803 804
804 // if it is the first day of a month switch color from normal to shaded and vice versa 805 // if it is the first day of a month switch color from normal to shaded and vice versa
805 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { 806 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) {
806 if (actcol == mDefaultTextColorShaded) { 807 if (actcol == mDefaultTextColorShaded) {
807 actcol = mDefaultTextColor; 808 actcol = mDefaultTextColor;
808 } else { 809 } else {
809 actcol = mDefaultTextColorShaded; 810 actcol = mDefaultTextColorShaded;
810 } 811 }
811 p.setPen(actcol); 812 p.setPen(actcol);
812 } 813 }
813 if (actcol == mDefaultTextColorShaded) { 814 if (actcol == mDefaultTextColorShaded) {
814 if ( ! mouseDown ) { 815 if ( ! mouseDown ) {
@@ -869,74 +870,74 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent)
869 870
870 // if it is a holiday then use the default holiday color 871 // if it is a holiday then use the default holiday color
871 if (!mHolidays[i].isNull()) { 872 if (!mHolidays[i].isNull()) {
872 if ( bDays.testBit(i) ) { 873 if ( bDays.testBit(i) ) {
873 p.setPen(Qt::green); 874 p.setPen(Qt::green);
874 } else { 875 } else {
875 if (actcol == mDefaultTextColor) { 876 if (actcol == mDefaultTextColor) {
876 p.setPen(KOPrefs::instance()->mHolidayColor); 877 p.setPen(KOPrefs::instance()->mHolidayColor);
877 } else { 878 } else {
878 p.setPen(mHolidayColorShaded); 879 p.setPen(mHolidayColorShaded);
879 } 880 }
880 } 881 }
881 } 882 }
882 883
883 // draw selected days with special color 884 // draw selected days with special color
884 // DO NOT specially highlight holidays in selection ! 885 // DO NOT specially highlight holidays in selection !
885 if (i >= mSelStartT && i <= mSelEndT) { 886 if (i >= mSelStartT && i <= mSelEndT) {
886 ;//p.setPen(mSelectedDaysColor); 887 ;//p.setPen(mSelectedDaysColor);
887 } 888 }
888 889
889 int addCol = 0; 890 int addCol = 0;
890 int addRow = 0; 891 int addRow = 0;
891 if ( colModulo ) { 892 if ( colModulo ) {
892 if ( col >= 7 - colModulo ) 893 if ( col >= 7 - colModulo )
893 addCol = col - 7 + colModulo; 894 addCol = col - 7 + colModulo;
894 } 895 }
895 if ( rowModulo ) { 896 if ( rowModulo ) {
896 if ( row >= 6 - rowModulo ) 897 if ( row >= 6 - rowModulo )
897 addRow = row - 5 + rowModulo; 898 addRow = row - 5 + rowModulo;
898 } 899 }
899 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); 900 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow);
900 ++addCol;//++addCol; 901 ++addCol;//++addCol;
901 if ( row == 0) 902 if ( row == 0)
902 addRow = 1; 903 addRow = 1;
903 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, 904 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight,
904 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); 905 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]);
905 906
906 // reset color to actual color 907 // reset color to actual color
907 if (!mHolidays[i].isNull()) { 908 if (!mHolidays[i].isNull()) {
908 p.setPen(actcol); 909 p.setPen(actcol);
909 } 910 }
910 // reset bold font to plain font 911 // reset bold font to plain font
911 if (events[i] > 0) { 912 if (events[i] > 0) {
912 QFont myFont = font(); 913 QFont myFont = font();
913 myFont.setBold(false); 914 myFont.setBold(false);
914 p.setFont(myFont); 915 p.setFont(myFont);
915 } 916 }
916 } 917 }
917 int off = xyOff; 918 int off = 0;//xyOff;
918 bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP); 919 bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP);
919 //qDebug("ffffffffff %d ", off); 920 //qDebug("ffffffffff %d ", off);
920} 921}
921 922
922// ---------------------------------------------------------------------------- 923// ----------------------------------------------------------------------------
923// R E SI Z E E V E N T H A N D L I N G 924// R E SI Z E E V E N T H A N D L I N G
924// ---------------------------------------------------------------------------- 925// ----------------------------------------------------------------------------
925 926
926void KODayMatrix::resizeEvent(QResizeEvent *) 927void KODayMatrix::resizeEvent(QResizeEvent *)
927{ 928{
928 QRect sz = frameRect(); 929 QRect sz = frameRect();
929 daysize.setHeight(sz.height()*7 / NUMDAYS); 930 daysize.setHeight(sz.height()*7 / NUMDAYS);
930 daysize.setWidth(sz.width() / 7); 931 daysize.setWidth(sz.width() / 7);
931} 932}
932 933
933QSize KODayMatrix::sizeHint() const 934QSize KODayMatrix::sizeHint() const
934{ 935{
935 936
936 QFontMetrics fm ( font() ); 937 QFontMetrics fm ( font() );
937 int wid = fm.width( "30") *7+3; 938 int wid = fm.width( "30") *7+3;
938 int hei = fm.height() * 6+3; 939 int hei = fm.height() * 6+3;
939 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); 940 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei);
940 return QSize ( wid, hei ); 941 return QSize ( wid, hei );
941 942
942} 943}