summaryrefslogtreecommitdiffabout
path: root/korganizer/kodaymatrix.cpp
Unidiff
Diffstat (limited to 'korganizer/kodaymatrix.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kodaymatrix.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index 619ae39..9181936 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -607,192 +607,203 @@ void KODayMatrix::dropEvent(QDropEvent *e)
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 if ( width() <= 0 || height() <= 0 ) 622 if ( width() <= 0 || height() <= 0 )
623 return; 623 return;
624 if ( mPendingUpdateBeforeRepaint ) { 624 if ( mPendingUpdateBeforeRepaint ) {
625 updateViewTimed(); 625 updateViewTimed();
626 mPendingUpdateBeforeRepaint = false; 626 mPendingUpdateBeforeRepaint = false;
627 } 627 }
628 if ( myPix.width() != width() || myPix.height()!=height() ) { 628 if ( myPix.width() != width() || myPix.height()!=height() ) {
629 myPix.resize(size() ); 629 myPix.resize(size() );
630 } 630 }
631 QPainter p(&myPix); 631 QPainter p(&myPix);
632 p.setFont(font()); 632 p.setFont(font());
633 633
634 QRect sz = frameRect(); 634 QRect sz = frameRect();
635 int dheight = daysize.height(); 635 int dheight = daysize.height();
636 int dwidth = daysize.width(); 636 int dwidth = daysize.width();
637 int row,col; 637 int row,col;
638 int selw, selh; 638 int selw, selh;
639 bool isRTL = KOGlobals::self()->reverseLayout(); 639 bool isRTL = KOGlobals::self()->reverseLayout();
640 640
641 // draw background and topleft frame 641 // draw background and topleft frame
642 p.fillRect(pevent->rect(), mDefaultBackColor); 642 p.fillRect(pevent->rect(), mDefaultBackColor);
643 p.setPen(mDefaultTextColor); 643 p.setPen(mDefaultTextColor);
644 p.drawRect(0, 0, sz.width()+1, sz.height()+1); 644 p.drawRect(0, 0, sz.width()+1, sz.height()+1);
645 int mSelStartT = mSelStart; 645 int mSelStartT = mSelStart;
646 int mSelEndT = mSelEnd; 646 int mSelEndT = mSelEnd;
647 if ( mSelEndT >= NUMDAYS ) 647 if ( mSelEndT >= NUMDAYS )
648 mSelEndT = NUMDAYS-1; 648 mSelEndT = NUMDAYS-1;
649 // draw selected days with highlighted background color 649 // draw selected days with highlighted background color
650 if (mSelStart != NOSELECTION) { 650 if (mSelStart != NOSELECTION) {
651 bool skip = false; 651 bool skip = false;
652 if ( ! mouseDown ) { 652 if ( ! mouseDown ) {
653 int mo = days[20].month(); 653 int mo = days[20].month();
654 //qDebug("-- %d %d ", mSelStartT, mSelEndT); 654 //qDebug("-- %d %d ", mSelStartT, mSelEndT);
655 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); 655 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() );
656 if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) { 656 if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) {
657 skip = true; 657 skip = true;
658 } else { 658 } else {
659 if ( days[mSelStartT].month() != mo ) { 659 if ( days[mSelStartT].month() != mo ) {
660 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); 660 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day();
661 mSelStartT += add +1; 661 mSelStartT += add +1;
662 } 662 }
663 if ( days[mSelEndT].month() != mo ) { 663 if ( days[mSelEndT].month() != mo ) {
664 int sub = days[mSelEndT].day(); 664 int sub = days[mSelEndT].day();
665 mSelEndT -= sub ; 665 mSelEndT -= sub ;
666 } 666 }
667 } 667 }
668 } 668 }
669 if ( ! skip ) { 669 if ( ! skip ) {
670 row = mSelStartT/7; 670 row = mSelStartT/7;
671 col = mSelStartT -row*7; 671 col = mSelStartT -row*7;
672 QColor selcol = KOPrefs::instance()->mHighlightColor; 672 QColor selcol = KOPrefs::instance()->mHighlightColor;
673 673
674 if (row == mSelEndT/7) { 674 if (row == mSelEndT/7) {
675 // Single row selection 675 // Single row selection
676 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth, 676 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth,
677 row*dheight, (mSelEndT-mSelStartT+1)*dwidth, dheight, selcol); 677 row*dheight, (mSelEndT-mSelStartT+1)*dwidth, dheight, selcol);
678 } else { 678 } else {
679 // draw first row to the right 679 // draw first row to the right
680 p.fillRect(isRTL ? 0 : col*dwidth, row*dheight, (7-col)*dwidth, 680 p.fillRect(isRTL ? 0 : col*dwidth, row*dheight, (7-col)*dwidth,
681 dheight, selcol); 681 dheight, selcol);
682 // draw full block till last line 682 // draw full block till last line
683 selh = mSelEndT/7-row; 683 selh = mSelEndT/7-row;
684 if (selh > 1) { 684 if (selh > 1) {
685 p.fillRect(0, (row+1)*dheight, 7*dwidth, (selh-1)*dheight,selcol); 685 p.fillRect(0, (row+1)*dheight, 7*dwidth, (selh-1)*dheight,selcol);
686 } 686 }
687 // draw last block from left to mSelEndT 687 // draw last block from left to mSelEndT
688 selw = mSelEndT-7*(mSelEndT/7)+1; 688 selw = mSelEndT-7*(mSelEndT/7)+1;
689 p.fillRect(isRTL ? (7-selw)*dwidth : 0, (row+selh)*dheight, 689 p.fillRect(isRTL ? (7-selw)*dwidth : 0, (row+selh)*dheight,
690 selw*dwidth, dheight, selcol); 690 selw*dwidth, dheight, selcol);
691 } 691 }
692 } 692 }
693 } 693 }
694 694
695 // iterate over all days in the matrix and draw the day label in appropriate colors 695 // iterate over all days in the matrix and draw the day label in appropriate colors
696 QColor actcol = mDefaultTextColorShaded; 696 QColor actcol = mDefaultTextColorShaded;
697 p.setPen(actcol); 697 p.setPen(actcol);
698 QPen tmppen; 698 QPen tmppen;
699 for(int i = 0; i < NUMDAYS; i++) { 699 for(int i = 0; i < NUMDAYS; i++) {
700 row = i/7; 700 row = i/7;
701 col = isRTL ? 6-(i-row*7) : i-row*7; 701 col = isRTL ? 6-(i-row*7) : i-row*7;
702 702
703 // if it is the first day of a month switch color from normal to shaded and vice versa 703 // if it is the first day of a month switch color from normal to shaded and vice versa
704 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { 704 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) {
705 if (actcol == mDefaultTextColorShaded) { 705 if (actcol == mDefaultTextColorShaded) {
706 actcol = mDefaultTextColor; 706 actcol = mDefaultTextColor;
707 } else { 707 } else {
708 actcol = mDefaultTextColorShaded; 708 actcol = mDefaultTextColorShaded;
709 } 709 }
710 p.setPen(actcol); 710 p.setPen(actcol);
711 } 711 }
712 if (actcol == mDefaultTextColorShaded) { 712 if (actcol == mDefaultTextColorShaded) {
713 if ( ! mouseDown ) { 713 if ( ! mouseDown ) {
714 continue; 714 continue;
715 } 715 }
716 } 716 }
717 //Reset pen color after selected days block 717 //Reset pen color after selected days block
718 if (i == mSelEndT+1) { 718 if (i == mSelEndT+1) {
719 p.setPen(actcol); 719 p.setPen(actcol);
720 } 720 }
721 721
722 // if today then draw rectangle around day 722 // if today then draw rectangle around day
723 if (today == i) { 723 if (today == i) {
724 tmppen = p.pen(); 724 tmppen = p.pen();
725 QPen mTodayPen(p.pen()); 725 QPen mTodayPen(p.pen());
726 726
727 mTodayPen.setWidth(mTodayMarginWidth); 727 mTodayPen.setWidth(mTodayMarginWidth);
728 //draw red rectangle for holidays 728 //draw red rectangle for holidays
729 if (!mHolidays[i].isNull()) { 729 if (!mHolidays[i].isNull()) {
730 if (actcol == mDefaultTextColor) { 730 if (actcol == mDefaultTextColor) {
731 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); 731 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor);
732 } else { 732 } else {
733 mTodayPen.setColor(mHolidayColorShaded); 733 mTodayPen.setColor(mHolidayColorShaded);
734 } 734 }
735 } 735 }
736 //draw gray rectangle for today if in selection 736 //draw gray rectangle for today if in selection
737 if (i >= mSelStartT && i <= mSelEndT) { 737 if (i >= mSelStartT && i <= mSelEndT) {
738 QColor grey("grey"); 738 QColor grey("grey");
739 mTodayPen.setColor(grey); 739 mTodayPen.setColor(grey);
740 } 740 }
741 p.setPen(mTodayPen); 741 p.setPen(mTodayPen);
742 p.drawRect(col*dwidth, row*dheight, dwidth, dheight); 742 p.drawRect(col*dwidth, row*dheight, dwidth, dheight);
743 p.setPen(tmppen); 743 p.setPen(tmppen);
744 } 744 }
745 745
746 // if any events are on that day then draw it using a bold font 746 // if any events are on that day then draw it using a bold font
747 if (events[i] > 0) { 747 if (events[i] > 0) {
748 QFont myFont = font(); 748 QFont myFont = font();
749 myFont.setBold(true); 749 myFont.setBold(true);
750 p.setFont(myFont); 750 p.setFont(myFont);
751 } 751 }
752 752
753 // if it is a holiday then use the default holiday color 753 // if it is a holiday then use the default holiday color
754 if (!mHolidays[i].isNull()) { 754 if (!mHolidays[i].isNull()) {
755 if ( bDays.testBit(i) ) { 755 if ( bDays.testBit(i) ) {
756 p.setPen(Qt::green); 756 p.setPen(Qt::green);
757 } else { 757 } else {
758 if (actcol == mDefaultTextColor) { 758 if (actcol == mDefaultTextColor) {
759 p.setPen(KOPrefs::instance()->mHolidayColor); 759 p.setPen(KOPrefs::instance()->mHolidayColor);
760 } else { 760 } else {
761 p.setPen(mHolidayColorShaded); 761 p.setPen(mHolidayColorShaded);
762 } 762 }
763 } 763 }
764 } 764 }
765 765
766 // draw selected days with special color 766 // draw selected days with special color
767 // DO NOT specially highlight holidays in selection ! 767 // DO NOT specially highlight holidays in selection !
768 if (i >= mSelStartT && i <= mSelEndT) { 768 if (i >= mSelStartT && i <= mSelEndT) {
769 ;//p.setPen(mSelectedDaysColor); 769 ;//p.setPen(mSelectedDaysColor);
770 } 770 }
771 771
772 p.drawText(col*dwidth, row*dheight, dwidth, dheight, 772 p.drawText(col*dwidth, row*dheight, dwidth, dheight,
773 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); 773 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]);
774 774
775 // reset color to actual color 775 // reset color to actual color
776 if (!mHolidays[i].isNull()) { 776 if (!mHolidays[i].isNull()) {
777 p.setPen(actcol); 777 p.setPen(actcol);
778 } 778 }
779 // reset bold font to plain font 779 // reset bold font to plain font
780 if (events[i] > 0) { 780 if (events[i] > 0) {
781 QFont myFont = font(); 781 QFont myFont = font();
782 myFont.setBold(false); 782 myFont.setBold(false);
783 p.setFont(myFont); 783 p.setFont(myFont);
784 } 784 }
785 } 785 }
786 bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP); 786 bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP);
787} 787}
788 788
789// ---------------------------------------------------------------------------- 789// ----------------------------------------------------------------------------
790// R E SI Z E E V E N T H A N D L I N G 790// R E SI Z E E V E N T H A N D L I N G
791// ---------------------------------------------------------------------------- 791// ----------------------------------------------------------------------------
792 792
793void KODayMatrix::resizeEvent(QResizeEvent *) 793void KODayMatrix::resizeEvent(QResizeEvent *)
794{ 794{
795 QRect sz = frameRect(); 795 QRect sz = frameRect();
796 daysize.setHeight(sz.height()*7 / NUMDAYS); 796 daysize.setHeight(sz.height()*7 / NUMDAYS);
797 daysize.setWidth(sz.width() / 7); 797 daysize.setWidth(sz.width() / 7);
798} 798}
799
800QSize KODayMatrix::sizeHint() const
801{
802
803 QFontMetrics fm ( font() );
804 int wid = fm.width( "30") *7+7;
805 int hei = fm.height() * 6+4;
806 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei);
807 return QSize ( wid, hei );
808
809}