author | zautrix <zautrix> | 2005-03-20 16:15:56 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-20 16:15:56 (UTC) |
commit | a9e08041c8978d52cfcabc84f579784af45eb8d9 (patch) (unidiff) | |
tree | 6448348326db4325938679350c58d87176d90771 | |
parent | 69d75020eea5f95b9f5d77d97ed85ec8869d32db (diff) | |
download | kdepimpi-a9e08041c8978d52cfcabc84f579784af45eb8d9.zip kdepimpi-a9e08041c8978d52cfcabc84f579784af45eb8d9.tar.gz kdepimpi-a9e08041c8978d52cfcabc84f579784af45eb8d9.tar.bz2 |
layout fix
-rw-r--r-- | korganizer/kodaymatrix.cpp | 89 | ||||
-rw-r--r-- | korganizer/kodaymatrix.h | 2 |
2 files changed, 76 insertions, 15 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index 9181936..15a1cb4 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp | |||
@@ -598,117 +598,164 @@ void KODayMatrix::dropEvent(QDropEvent *e) | |||
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 | ||
620 | void KODayMatrix::paintEvent(QPaintEvent * pevent) | 620 | void KODayMatrix::paintEvent(QPaintEvent * pevent) |
621 | { | 621 | { |
622 | if ( width() <= 0 || height() <= 0 ) | 622 | QRect sz = frameRect(); |
623 | if ( sz.width() <= 0 || sz.height() <= 0 ) | ||
623 | return; | 624 | return; |
624 | if ( mPendingUpdateBeforeRepaint ) { | 625 | if ( mPendingUpdateBeforeRepaint ) { |
625 | updateViewTimed(); | 626 | updateViewTimed(); |
626 | mPendingUpdateBeforeRepaint = false; | 627 | mPendingUpdateBeforeRepaint = false; |
627 | } | 628 | } |
628 | if ( myPix.width() != width() || myPix.height()!=height() ) { | 629 | if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) { |
629 | myPix.resize(size() ); | 630 | myPix.resize(sz.size() ); |
630 | } | 631 | } |
631 | QPainter p(&myPix); | 632 | QPainter p(&myPix); |
632 | p.setFont(font()); | 633 | p.setFont(font()); |
633 | 634 | ||
634 | QRect sz = frameRect(); | 635 | |
635 | int dheight = daysize.height(); | 636 | int dheight = daysize.height(); |
636 | int dwidth = daysize.width(); | 637 | int dwidth = daysize.width(); |
637 | int row,col; | 638 | int row,col; |
638 | int selw, selh; | 639 | int selw, selh; |
640 | int xyOff = frameWidth(); | ||
641 | int colModulo = sz.width() % 7; | ||
642 | int rowModulo = sz.height() % 6; | ||
643 | qDebug("off %d col %d row %d ",xyOff,colModulo,rowModulo ); | ||
644 | |||
639 | bool isRTL = KOGlobals::self()->reverseLayout(); | 645 | bool isRTL = KOGlobals::self()->reverseLayout(); |
640 | 646 | ||
641 | // draw background and topleft frame | 647 | // draw background and topleft frame |
642 | p.fillRect(pevent->rect(), mDefaultBackColor); | 648 | p.fillRect(pevent->rect(), mDefaultBackColor); |
643 | p.setPen(mDefaultTextColor); | 649 | p.setPen(mDefaultTextColor); |
644 | p.drawRect(0, 0, sz.width()+1, sz.height()+1); | 650 | p.drawRect(0, 0, sz.width()+1, sz.height()+1); |
645 | int mSelStartT = mSelStart; | 651 | int mSelStartT = mSelStart; |
646 | int mSelEndT = mSelEnd; | 652 | int mSelEndT = mSelEnd; |
647 | if ( mSelEndT >= NUMDAYS ) | 653 | if ( mSelEndT >= NUMDAYS ) |
648 | mSelEndT = NUMDAYS-1; | 654 | mSelEndT = NUMDAYS-1; |
649 | // draw selected days with highlighted background color | 655 | // draw selected days with highlighted background color |
650 | if (mSelStart != NOSELECTION) { | 656 | if (mSelStart != NOSELECTION) { |
651 | bool skip = false; | 657 | bool skip = false; |
652 | if ( ! mouseDown ) { | 658 | if ( ! mouseDown ) { |
653 | int mo = days[20].month(); | 659 | int mo = days[20].month(); |
654 | //qDebug("-- %d %d ", mSelStartT, mSelEndT); | 660 | //qDebug("-- %d %d ", mSelStartT, mSelEndT); |
655 | //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() ); |
656 | if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) { | 662 | if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) { |
657 | skip = true; | 663 | skip = true; |
658 | } else { | 664 | } else { |
659 | if ( days[mSelStartT].month() != mo ) { | 665 | if ( days[mSelStartT].month() != mo ) { |
660 | int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); | 666 | int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); |
661 | mSelStartT += add +1; | 667 | mSelStartT += add +1; |
662 | } | 668 | } |
663 | if ( days[mSelEndT].month() != mo ) { | 669 | if ( days[mSelEndT].month() != mo ) { |
664 | int sub = days[mSelEndT].day(); | 670 | int sub = days[mSelEndT].day(); |
665 | mSelEndT -= sub ; | 671 | mSelEndT -= sub ; |
666 | } | 672 | } |
667 | } | 673 | } |
668 | } | 674 | } |
669 | if ( ! skip ) { | 675 | if ( ! skip ) { |
670 | row = mSelStartT/7; | 676 | row = mSelStartT/7; |
671 | col = mSelStartT -row*7; | 677 | col = mSelStartT -row*7; |
672 | QColor selcol = KOPrefs::instance()->mHighlightColor; | 678 | QColor selcol = KOPrefs::instance()->mHighlightColor; |
673 | 679 | ||
680 | |||
681 | |||
682 | int addCol = 0; | ||
683 | int addRow = 0; | ||
684 | #if 0 | ||
685 | if ( colModulo ) { | ||
686 | if ( col >= 7 - colModulo ) | ||
687 | addCol = col - 7 + colModulo; | ||
688 | } | ||
689 | if ( rowModulo ) { | ||
690 | if ( row >= 6 - rowModulo ) | ||
691 | addRow = row - 5 + rowModulo; | ||
692 | } | ||
693 | #endif | ||
694 | |||
695 | |||
696 | |||
697 | |||
698 | |||
674 | if (row == mSelEndT/7) { | 699 | if (row == mSelEndT/7) { |
700 | if ( rowModulo ) { | ||
701 | if ( row >= 6 - rowModulo ) | ||
702 | addRow = row - 5 + rowModulo; | ||
703 | } | ||
704 | if ( colModulo ) { | ||
705 | if ( mSelEndT-mSelStartT+1 >= 7 - colModulo ) | ||
706 | addCol = mSelEndT-mSelStartT+1 - 7 + colModulo; | ||
707 | } | ||
675 | // Single row selection | 708 | // Single row selection |
676 | p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth, | 709 | if ( row == 0) |
677 | row*dheight, (mSelEndT-mSelStartT+1)*dwidth, dheight, selcol); | 710 | addRow = 1; |
711 | p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1, | ||
712 | row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); | ||
678 | } else { | 713 | } else { |
679 | // draw first row to the right | 714 | // draw first row to the right |
680 | p.fillRect(isRTL ? 0 : col*dwidth, row*dheight, (7-col)*dwidth, | 715 | if ( row == 0) |
716 | addRow = 1; | ||
717 | p.fillRect(isRTL ? 0 : col*dwidth+1, row*dheight+addRow, (7-col)*dwidth+colModulo, | ||
681 | dheight, selcol); | 718 | dheight, selcol); |
682 | // draw full block till last line | 719 | // draw full block till last line |
683 | selh = mSelEndT/7-row; | 720 | selh = mSelEndT/7-row; |
684 | if (selh > 1) { | 721 | if (selh > 1) { |
685 | p.fillRect(0, (row+1)*dheight, 7*dwidth, (selh-1)*dheight,selcol); | 722 | p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight,selcol); |
686 | } | 723 | } |
687 | // draw last block from left to mSelEndT | 724 | // draw last block from left to mSelEndT |
688 | selw = mSelEndT-7*(mSelEndT/7)+1; | 725 | selw = mSelEndT-7*(mSelEndT/7)+1; |
689 | p.fillRect(isRTL ? (7-selw)*dwidth : 0, (row+selh)*dheight, | 726 | //qDebug("esl %d ",selw ); |
690 | selw*dwidth, dheight, selcol); | 727 | int add = 0; |
728 | if ( colModulo ) { | ||
729 | add = 7 - colModulo; | ||
730 | if ( selw > add ) | ||
731 | add = selw - add; | ||
732 | else | ||
733 | add = 0; | ||
734 | } | ||
735 | //qDebug("add %d ", add); | ||
736 | p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight, | ||
737 | selw*dwidth+add, dheight, selcol); | ||
691 | } | 738 | } |
692 | } | 739 | } |
693 | } | 740 | } |
694 | 741 | ||
695 | // iterate over all days in the matrix and draw the day label in appropriate colors | 742 | // iterate over all days in the matrix and draw the day label in appropriate colors |
696 | QColor actcol = mDefaultTextColorShaded; | 743 | QColor actcol = mDefaultTextColorShaded; |
697 | p.setPen(actcol); | 744 | p.setPen(actcol); |
698 | QPen tmppen; | 745 | QPen tmppen; |
699 | for(int i = 0; i < NUMDAYS; i++) { | 746 | for(int i = 0; i < NUMDAYS; i++) { |
700 | row = i/7; | 747 | row = i/7; |
701 | col = isRTL ? 6-(i-row*7) : i-row*7; | 748 | col = isRTL ? 6-(i-row*7) : i-row*7; |
702 | 749 | ||
703 | // if it is the first day of a month switch color from normal to shaded and vice versa | 750 | // 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) { | 751 | if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { |
705 | if (actcol == mDefaultTextColorShaded) { | 752 | if (actcol == mDefaultTextColorShaded) { |
706 | actcol = mDefaultTextColor; | 753 | actcol = mDefaultTextColor; |
707 | } else { | 754 | } else { |
708 | actcol = mDefaultTextColorShaded; | 755 | actcol = mDefaultTextColorShaded; |
709 | } | 756 | } |
710 | p.setPen(actcol); | 757 | p.setPen(actcol); |
711 | } | 758 | } |
712 | if (actcol == mDefaultTextColorShaded) { | 759 | if (actcol == mDefaultTextColorShaded) { |
713 | if ( ! mouseDown ) { | 760 | if ( ! mouseDown ) { |
714 | continue; | 761 | continue; |
@@ -748,62 +795,76 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent) | |||
748 | QFont myFont = font(); | 795 | QFont myFont = font(); |
749 | myFont.setBold(true); | 796 | myFont.setBold(true); |
750 | p.setFont(myFont); | 797 | p.setFont(myFont); |
751 | } | 798 | } |
752 | 799 | ||
753 | // if it is a holiday then use the default holiday color | 800 | // if it is a holiday then use the default holiday color |
754 | if (!mHolidays[i].isNull()) { | 801 | if (!mHolidays[i].isNull()) { |
755 | if ( bDays.testBit(i) ) { | 802 | if ( bDays.testBit(i) ) { |
756 | p.setPen(Qt::green); | 803 | p.setPen(Qt::green); |
757 | } else { | 804 | } else { |
758 | if (actcol == mDefaultTextColor) { | 805 | if (actcol == mDefaultTextColor) { |
759 | p.setPen(KOPrefs::instance()->mHolidayColor); | 806 | p.setPen(KOPrefs::instance()->mHolidayColor); |
760 | } else { | 807 | } else { |
761 | p.setPen(mHolidayColorShaded); | 808 | p.setPen(mHolidayColorShaded); |
762 | } | 809 | } |
763 | } | 810 | } |
764 | } | 811 | } |
765 | 812 | ||
766 | // draw selected days with special color | 813 | // draw selected days with special color |
767 | // DO NOT specially highlight holidays in selection ! | 814 | // DO NOT specially highlight holidays in selection ! |
768 | if (i >= mSelStartT && i <= mSelEndT) { | 815 | if (i >= mSelStartT && i <= mSelEndT) { |
769 | ;//p.setPen(mSelectedDaysColor); | 816 | ;//p.setPen(mSelectedDaysColor); |
770 | } | 817 | } |
771 | 818 | ||
772 | p.drawText(col*dwidth, row*dheight, dwidth, dheight, | 819 | int addCol = 0; |
820 | int addRow = 0; | ||
821 | if ( colModulo ) { | ||
822 | if ( col >= 7 - colModulo ) | ||
823 | addCol = col - 7 + colModulo; | ||
824 | } | ||
825 | if ( rowModulo ) { | ||
826 | if ( row >= 6 - rowModulo ) | ||
827 | addRow = row - 5 + rowModulo; | ||
828 | } | ||
829 | //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); | ||
830 | ++addCol;++addCol; | ||
831 | p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, | ||
773 | Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); | 832 | Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); |
774 | 833 | ||
775 | // reset color to actual color | 834 | // reset color to actual color |
776 | if (!mHolidays[i].isNull()) { | 835 | if (!mHolidays[i].isNull()) { |
777 | p.setPen(actcol); | 836 | p.setPen(actcol); |
778 | } | 837 | } |
779 | // reset bold font to plain font | 838 | // reset bold font to plain font |
780 | if (events[i] > 0) { | 839 | if (events[i] > 0) { |
781 | QFont myFont = font(); | 840 | QFont myFont = font(); |
782 | myFont.setBold(false); | 841 | myFont.setBold(false); |
783 | p.setFont(myFont); | 842 | p.setFont(myFont); |
784 | } | 843 | } |
785 | } | 844 | } |
786 | bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP); | 845 | int off = xyOff; |
846 | bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP); | ||
847 | //qDebug("ffffffffff %d ", off); | ||
787 | } | 848 | } |
788 | 849 | ||
789 | // ---------------------------------------------------------------------------- | 850 | // ---------------------------------------------------------------------------- |
790 | // R E SI Z E E V E N T H A N D L I N G | 851 | // R E SI Z E E V E N T H A N D L I N G |
791 | // ---------------------------------------------------------------------------- | 852 | // ---------------------------------------------------------------------------- |
792 | 853 | ||
793 | void KODayMatrix::resizeEvent(QResizeEvent *) | 854 | void KODayMatrix::resizeEvent(QResizeEvent *) |
794 | { | 855 | { |
795 | QRect sz = frameRect(); | 856 | QRect sz = frameRect(); |
796 | daysize.setHeight(sz.height()*7 / NUMDAYS); | 857 | daysize.setHeight(sz.height()*7 / NUMDAYS); |
797 | daysize.setWidth(sz.width() / 7); | 858 | daysize.setWidth(sz.width() / 7); |
798 | } | 859 | } |
799 | 860 | ||
800 | QSize KODayMatrix::sizeHint() const | 861 | QSize KODayMatrix::sizeHint() const |
801 | { | 862 | { |
802 | 863 | ||
803 | QFontMetrics fm ( font() ); | 864 | QFontMetrics fm ( font() ); |
804 | int wid = fm.width( "30") *7+7; | 865 | int wid = fm.width( "30") *7+3; |
805 | int hei = fm.height() * 6+4; | 866 | int hei = fm.height() * 6+3; |
806 | //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); | 867 | //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); |
807 | return QSize ( wid, hei ); | 868 | return QSize ( wid, hei ); |
808 | 869 | ||
809 | } | 870 | } |
diff --git a/korganizer/kodaymatrix.h b/korganizer/kodaymatrix.h index 39946de..f4016b6 100644 --- a/korganizer/kodaymatrix.h +++ b/korganizer/kodaymatrix.h | |||
@@ -150,49 +150,49 @@ public: | |||
150 | void addSelectedDaysTo(DateList&); | 150 | void addSelectedDaysTo(DateList&); |
151 | 151 | ||
152 | /** sets the actual to be displayed selection in the day matrix starting from | 152 | /** sets the actual to be displayed selection in the day matrix starting from |
153 | * start and ending with end. Theview must be manually updated by calling | 153 | * start and ending with end. Theview must be manually updated by calling |
154 | * repaint. (?) | 154 | * repaint. (?) |
155 | */ | 155 | */ |
156 | void setSelectedDaysFrom(const QDate& start, const QDate& end); | 156 | void setSelectedDaysFrom(const QDate& start, const QDate& end); |
157 | void clearSelection(); | 157 | void clearSelection(); |
158 | 158 | ||
159 | /** Is today visible in the view? Keep this in sync with | 159 | /** Is today visible in the view? Keep this in sync with |
160 | * the values today (below) can take. | 160 | * the values today (below) can take. |
161 | */ | 161 | */ |
162 | bool isTodayVisible() const { return today>=0; } ; | 162 | bool isTodayVisible() const { return today>=0; } ; |
163 | 163 | ||
164 | /** If today is visible, then we can find out if today is | 164 | /** If today is visible, then we can find out if today is |
165 | * near the beginning or the end of the month. | 165 | * near the beginning or the end of the month. |
166 | * This is dependent on today remaining the index | 166 | * This is dependent on today remaining the index |
167 | * in the array of visible dates and going from | 167 | * in the array of visible dates and going from |
168 | * top left (0) to bottom right (41). | 168 | * top left (0) to bottom right (41). |
169 | */ | 169 | */ |
170 | bool isBeginningOfMonth() const { return today<=8; } ; | 170 | bool isBeginningOfMonth() const { return today<=8; } ; |
171 | bool isEndOfMonth() const { return today>=27; } ; | 171 | bool isEndOfMonth() const { return today>=27; } ; |
172 | QString getWhatsThisText( QPoint ) ; | 172 | QString getWhatsThisText( QPoint ) ; |
173 | QSize sizeHint() const; | 173 | QSize sizeHint() const; |
174 | 174 | QRect frameRect () const { int wid = frameWidth(); return QRect(0+wid,0+wid,width()-wid-wid,height()-wid-wid);} | |
175 | public slots: | 175 | public slots: |
176 | /** Recalculates all the flags of the days in the matrix like holidays or events | 176 | /** Recalculates all the flags of the days in the matrix like holidays or events |
177 | * on a day (Actually calls above method with the actual startdate). | 177 | * on a day (Actually calls above method with the actual startdate). |
178 | */ | 178 | */ |
179 | void updateView(); | 179 | void updateView(); |
180 | void updateViewTimed(); | 180 | void updateViewTimed(); |
181 | void repaintViewTimed(); | 181 | void repaintViewTimed(); |
182 | 182 | ||
183 | /** | 183 | /** |
184 | * Calculate which square in the matrix should be | 184 | * Calculate which square in the matrix should be |
185 | * hilighted to indicate it's today. | 185 | * hilighted to indicate it's today. |
186 | */ | 186 | */ |
187 | void recalculateToday(); | 187 | void recalculateToday(); |
188 | 188 | ||
189 | /* | 189 | /* |
190 | void setStartDate(QDate); | 190 | void setStartDate(QDate); |
191 | */ | 191 | */ |
192 | 192 | ||
193 | signals: | 193 | signals: |
194 | 194 | ||
195 | /** emitted if the user selects a block of days with the mouse by dragging a rectangle | 195 | /** emitted if the user selects a block of days with the mouse by dragging a rectangle |
196 | * inside the matrix | 196 | * inside the matrix |
197 | * | 197 | * |
198 | * @param daylist list of days that have been selected by the user | 198 | * @param daylist list of days that have been selected by the user |