author | zautrix <zautrix> | 2005-07-27 22:26:08 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-07-27 22:26:08 (UTC) |
commit | 0e38cffd7ba745f237c659e1c48080fcb25b126c (patch) (side-by-side diff) | |
tree | 6069600e18bae5300c6ce427735457dbfed93141 /korganizer/kodaymatrix.cpp | |
parent | 136f9082862e7a56abb3a201e96f5e7386c4f1b9 (diff) | |
download | kdepimpi-0e38cffd7ba745f237c659e1c48080fcb25b126c.zip kdepimpi-0e38cffd7ba745f237c659e1c48080fcb25b126c.tar.gz kdepimpi-0e38cffd7ba745f237c659e1c48080fcb25b126c.tar.bz2 |
rec changes
-rw-r--r-- | korganizer/kodaymatrix.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index ec1154a..057df0d 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp @@ -72,769 +72,769 @@ protected: } private: KODayMatrix * _view; }; void DynamicTip::maybeTip( const QPoint &pos ) { //calculate which cell of the matrix the mouse is in QRect sz = matrix->frameRect(); int dheight = sz.height()*7 / 42; int dwidth = sz.width() / 7; int row = pos.y()/dheight; int col = pos.x()/dwidth; QRect rct(col*dwidth, row*dheight, dwidth, dheight); // kdDebug() << "DynamicTip::maybeTip matrix cell index [" << // col << "][" << row << "] => " <<(col+row*7) << endl; //show holiday names only QString str = matrix->getHolidayLabel(col+row*7); if (str.isEmpty()) return; tip(rct, str); } // ============================================================================ // K O D A Y M A T R I X // ============================================================================ const int KODayMatrix::NOSELECTION = -1000; const int KODayMatrix::NUMDAYS = 42; KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 ) { mLastView = -1; oldW = 0; oldH = 0; myPix.resize( 150, 120 ); mRedrawNeeded = true; mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); mPendingUpdateBeforeRepaint = false; mouseDown = false; // initialize dynamic arrays bDays.resize ( NUMDAYS ); pDays.resize ( NUMDAYS ); hDays.resize ( NUMDAYS ); eDays.resize ( NUMDAYS ); days = new QDate[NUMDAYS]; daylbls = new QString[NUMDAYS]; //events = new int[NUMDAYS]; mToolTip = new DynamicTip(this); // set default values used for drawing the matrix mDefaultBackColor = palette().active().base(); mDefaultTextColor = palette().active().foreground(); mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); mSelectedDaysColor = QColor("white"); mTodayMarginWidth = 2; mSelEnd = mSelStart = NOSELECTION; setAcceptDrops(true); //setFont( QFont("Arial", 10) ); mUpdateTimer = new QTimer( this ); connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); mRepaintTimer = new QTimer( this ); connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); mDayChanged = false; updateView(); } QString KODayMatrix::getWhatsThisText( QPoint p ) { int tmp = getDayIndexFrom(p.x(), p.y()); if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) return QString(); QDate mDate = days[tmp]; QPtrList<Event> eventlist = mCalendar->events(mDate); Event *event; QStringList mToolTip; for(event=eventlist.first();event != 0;event=eventlist.next()) { QString mToolTipText; QString text; int multiday = 0;// 1 = start, 2 = midddle, 3 = end day if (event->isMultiDay()) { QString prefix = "<->";multiday = 2; QString time; if ( event->doesRecur() ) { if ( event->recursOn( mDate) ) { prefix ="->" ;multiday = 1; } else { int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); if ( event->recursOn( mDate.addDays( -days)) ) { prefix ="<-" ;multiday = 3; } } } else { if (mDate == event->dtStart().date()) { prefix ="->" ;multiday = 1; } else if (mDate == event->dtEnd().date()) { prefix ="<-" ;multiday = 3; } } if ( !event->doesFloat() ) { if ( mDate == event->dtStart().date () ) time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; else if ( mDate == event->dtEnd().date () ) time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; } text = time + event->summary(); mToolTipText += prefix + text; } else { if (event->doesFloat()) { text = event->summary(); mToolTipText += text; } else { text = KGlobal::locale()->formatTime(event->dtStart().time()); text += " " + event->summary(); mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); } } if ( !event->location().isEmpty() ) mToolTipText += " (" + event->location() + ")"; //qDebug("TTT: %s ", mToolTipText.latin1()); mToolTip.append( deTag( mToolTipText ) ); } mToolTip.sort(); if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { QPtrList<Todo> todolist = mCalendar->todos(mDate); Todo *todo; for(todo=todolist.first();todo != 0;todo=todolist.next()) { QString mToolTipText; if ( !todo->doesFloat() ) mToolTipText += KGlobal::locale()->formatTime(todo->dtDue().time())+" "; mToolTipText += todo->summary(); if ( !todo->location().isEmpty() ) mToolTipText += " (" + todo->location() + ")"; mToolTipText = deTag( mToolTipText); mToolTipText = "<b>" + i18n("Todo: ") + "</b>"+ mToolTipText; mToolTip.append( mToolTipText ); } } if (KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { QPtrList<Journal> j_list = mCalendar->journals4Date( mDate ); Journal *j = j_list.first(); while ( j ) { QString mToolTipText; if ( !j->summary().isEmpty() ) { mToolTipText = j->summary().left(30); if ( j->summary().length() > 30 ) mToolTipText += " ..."; } else { mToolTipText = j->description().left(25); if ( j->description().length() > 25 ) mToolTipText += " ..."; mToolTipText = deTag( mToolTipText); } mToolTipText = "<b>" + i18n("Journal: ") + "</b>"+ mToolTipText; mToolTip.append( mToolTipText ); j = j_list.next(); } } return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); } QString KODayMatrix::deTag( QString mToolTipText ) { #if QT_VERSION >= 0x030000 mToolTipText.replace( '<' , "<" ); mToolTipText.replace( '>' , ">" ); #else if ( mToolTipText.find ('<') >= 0 ) { mToolTipText.replace( QRegExp("<") , "<" ); } if ( mToolTipText.find ('>') >= 0 ) { mToolTipText.replace( QRegExp(">") , ">" ); } #endif return mToolTipText; } void KODayMatrix::setCalendar( Calendar *cal ) { mCalendar = cal; setAcceptDrops( mCalendar ); updateEvents(); } QColor KODayMatrix::getShadedColor(QColor color) { QColor shaded; int h=0; int s=0; int v=0; color.hsv(&h,&s,&v); s = s/4; v = 192+v/4; shaded.setHsv(h,s,v); return shaded; } KODayMatrix::~KODayMatrix() { #if QT_VERSION >= 0x030000 #else delete mKODaymatrixWhatsThis; #endif // delete mKODaymatrixWhatsThis; delete [] days; delete [] daylbls; //delete [] events; delete mToolTip; } /* void KODayMatrix::setStartDate(QDate start) { updateView(start); } */ void KODayMatrix::addSelectedDaysTo(DateList& selDays) { if (mSelStart == NOSELECTION) { return; } //cope with selection being out of matrix limits at top (< 0) int i0 = mSelStart; if (i0 < 0) { for (int i = i0; i < 0; i++) { selDays.append(days[0].addDays(i)); } i0 = 0; } //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) if (mSelEnd > NUMDAYS-1) { for (int i = i0; i <= NUMDAYS-1; i++) { selDays.append(days[i]); } for (int i = NUMDAYS; i < mSelEnd; i++) { selDays.append(days[0].addDays(i)); } // apply normal routine to selection being entirely within matrix limits } else { for (int i = i0; i <= mSelEnd; i++) { selDays.append(days[i]); } } } bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) { mRedrawNeeded = true; bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION ); mSelStart = startdate.daysTo(start); if ( mSelStart < 0 ) mSelStart = 0; mSelEnd = startdate.daysTo(end); if ( mSelEnd > NUMDAYS-1 ) mSelEnd = NUMDAYS-1; if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) { clearSelection(); if ( noSel ) return false; } return true; } void KODayMatrix::clearSelection() { mSelEnd = mSelStart = NOSELECTION; } void KODayMatrix::recalculateToday() { today = -1; for (int i=0; i<NUMDAYS; i++) { //events[i] = 0; days[i] = startdate.addDays(i); daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); // if today is in the currently displayed month, hilight today if (days[i].year() == QDate::currentDate().year() && days[i].month() == QDate::currentDate().month() && days[i].day() == QDate::currentDate().day()) { today = i; } } // qDebug(QString("Today is visible at %1.").arg(today)); } void KODayMatrix::updateView() { updateView(startdate); } void KODayMatrix::repaintViewTimed() { mRedrawNeeded = true; // bDays.fill( false); //pDays.fill( false); //hDays.fill( false); //eDays.fill( false); mRepaintTimer->stop(); int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday int i; for(i = 0; i < NUMDAYS; i++) { if ( ( (i+startDay) % 7 == 0 ) ) { pDays.setBit(i); } } repaint(false); } void KODayMatrix::computeEvent(Event *event, int i ) { QString holiStr = mHolidays[i]; if ( event->isHoliday()) { pDays.setBit(i); hDays.setBit(i); if ( !holiStr.isEmpty() ) holiStr += "\n"; holiStr += event->summary(); if ( !event->location().isEmpty() ) holiStr += " (" + event->location() + ")"; mHolidays[i] =holiStr ; eDays.setBit(i); } if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_T_VIEW && KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) { if ( event->isBirthday()) { pDays.setBit(i); if ( !holiStr.isEmpty() ) holiStr += "\n"; holiStr += i18n("Birthday") + ": "+event->summary(); if ( !event->location().isEmpty() ) holiStr += " (" + event->location() + ")"; bDays.setBit(i); mHolidays[i] =holiStr ; } } if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) eDays.setBit(i); } void KODayMatrix::updateViewTimed() { mUpdateTimer->stop(); if ( !mCalendar ) { qDebug("NOT CAL "); return; } #if 1 int i; int timeSpan = NUMDAYS-1; QPtrList<Event> events = mCalendar->events(); Event *event; QDateTime dt; bool ok; bDays.fill( false); pDays.fill( false); hDays.fill( false); eDays.fill( false); mHolidays.clear(); QDate mStartDate = days[0]; QDate endDate = mStartDate.addDays( timeSpan ); for( event = events.first(); event; event = events.next() ) { // for event - ushort recurType = event->recurrence()->doesRecur(); + ushort recurType = event->doesRecur(); if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { continue; } if ( event->doesRecur() ) { bool last; QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); QDateTime incidenceEnd; int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); bool invalid = false; while( true ) { if ( incidenceStart.isValid() ) { incidenceEnd = incidenceStart.addDays( eventlen ); int st = incidenceStart.date().daysTo( endDate ); if ( st >= 0 ) { // start before timeend int end = mStartDate.daysTo( incidenceEnd.date() ); if ( end >= 0 ) { // end after timestart --- got one! //normalize st = timeSpan - st; if ( st < 0 ) st = 0; if ( end > timeSpan ) end = timeSpan; int iii; //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); for ( iii = st;iii<= end;++iii) { computeEvent( event, iii ); } } } } else { if ( invalid ) break; invalid = true; //qDebug("invalid %s", event->summary().latin1()); incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; } if ( last ) break; bool ok; incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); if ( ! ok ) break; if ( incidenceStart.date() > endDate ) break; } } else { // no recur int st = event->dtStart().date().daysTo( endDate ); if ( st >= 0 ) { // start before timeend int end = mStartDate.daysTo( event->dtEnd().date() ); if ( end >= 0 ) { // end after timestart --- got one! //normalize st = timeSpan - st; if ( st < 0 ) st = 0; if ( end > timeSpan ) end = timeSpan; int iii; for ( iii = st;iii<= end;++iii) computeEvent( event, iii ); } } } } int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday for(i = 0; i < NUMDAYS; i++) { if ( ( (i+startDay) % 7 == 0 ) ) { pDays.setBit(i); } } if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { bDays.fill( false); // insert due todos QPtrList<Todo> todos = mCalendar->todos( ); Todo *todo; for(todo = todos.first(); todo; todo = todos.next()) { //insertTodo( todo ); if ( todo->hasDueDate() ) { int day = mStartDate.daysTo( todo->dtDue().date() ); if ( day >= 0 && day < timeSpan + 1) { int i = day; QString holiStr = mHolidays[i]; pDays.setBit(i); if ( !holiStr.isEmpty() ) holiStr += "\n"; holiStr += i18n("Todo") + ": "+todo->summary(); if ( !todo->location().isEmpty() ) holiStr += " (" + todo->location() + ")"; bDays.setBit(i); mHolidays[i] =holiStr ; eDays.setBit(i); } } } } if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { bDays.fill( false); // insert due todos QPtrList<Journal> todos = mCalendar->journals( ); Journal *todo; for(todo = todos.first(); todo; todo = todos.next()) { int day = mStartDate.daysTo( todo->dtStart().date() ); if ( day >= 0 && day < timeSpan + 1) { int i = day; QString holiStr = mHolidays[i]; pDays.setBit(i); if ( !holiStr.isEmpty() ) holiStr += "\n"; holiStr += i18n("Journal: ")+todo->summary().left(25); if ( todo->summary().length() > 25 ) holiStr +="..."; bDays.setBit(i); mHolidays[i] =holiStr ; eDays.setBit(i); } } } #else //qDebug("KODayMatrix::updateViewTimed "); for(int i = 0; i < NUMDAYS; i++) { // if events are set for the day then remember to draw it bold QPtrList<Event> eventlist = mCalendar->events(days[i]); Event *event; int numEvents = eventlist.count(); QString holiStr = ""; bDays.clearBit(i); hDays.clearBit(i); eDays.clearBit(i); for(event=eventlist.first();event != 0;event=eventlist.next()) { ushort recurType = event->recurrence()->doesRecur(); if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { numEvents--; } if ( event->isHoliday()) { hDays.setBit(i); if ( !holiStr.isEmpty() ) holiStr += "\n"; holiStr += event->summary(); if ( !event->location().isEmpty() ) holiStr += " (" + event->location() + ")"; } if ( event->isBirthday()) { if ( !holiStr.isEmpty() ) holiStr += "\n"; holiStr += i18n("Birthday") + ": "+event->summary(); if ( !event->location().isEmpty() ) holiStr += " (" + event->location() + ")"; bDays.setBit(i); } } if ( numEvents ) eDays.setBit(i); //if it is a holy day then draw it red. Sundays are consider holidays, too if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || !holiStr.isEmpty()) { mHolidays[i] = holiStr; } else { mHolidays[i] = QString::null; } } #endif mRedrawNeeded = true; if ( ! mPendingUpdateBeforeRepaint ) repaint(false); } void KODayMatrix::updateView(QDate actdate) { if ( mLastView != KOPrefs::instance()->mCurrentDisplayedView ) mRedrawNeeded = true; mLastView = KOPrefs::instance()->mCurrentDisplayedView; if ( ! actdate.isValid() ) { //qDebug("date not valid "); return; } mDayChanged = false; //flag to indicate if the starting day of the matrix has changed by this call //mDayChanged = false; // if a new startdate is to be set then apply Cornelius's calculation // of the first day to be shown if (actdate != startdate) { // reset index of selection according to shift of starting date from startdate to actdate if (mSelStart != NOSELECTION) { int tmp = actdate.daysTo(startdate); //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; // shift selection if new one would be visible at least partly ! if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { // nested if is required for next X display pushed from a different month - correction required // otherwise, for month forward and backward, it must be avoided if( mSelStart > NUMDAYS || mSelStart < 0 ) mSelStart = mSelStart + tmp; if( mSelEnd > NUMDAYS || mSelEnd < 0 ) mSelEnd = mSelEnd + tmp; } } startdate = actdate; mDayChanged = true; recalculateToday(); mRedrawNeeded = true; } //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); if ( !isVisible() ) { mPendingUpdateBeforeRepaint = true; } else { #ifdef DESKTOP_VERSION //mRepaintTimer->start( 100 ); //updateViewTimed(); mUpdateTimer->start( 50 ); #else mRepaintTimer->start( 350 ); mUpdateTimer->start( 800 ); #endif } } void KODayMatrix::updateEvents() { if ( !mCalendar ) return; for( int i = 0; i < NUMDAYS; i++ ) { // if events are set for the day then remember to draw it bold QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); int numEvents = eventlist.count(); Event *event; for( event = eventlist.first(); event != 0;event=eventlist.next()) { ushort recurType = event->doesRecur(); if ( ( recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur ) || ( recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur ) ) { numEvents--; } } if ( numEvents ) eDays.setBit(i); else eDays.clearBit(i); } } const QDate& KODayMatrix::getDate(int offset) { if (offset < 0 || offset > NUMDAYS-1) { qDebug("Wrong offset2 %d", offset); return days[0]; } return days[offset]; } QString KODayMatrix::getHolidayLabel(int offset) { if (offset < 0 || offset > NUMDAYS-1) { qDebug("Wrong offset1 %d", offset); return QString(); } return mHolidays[offset]; } int KODayMatrix::getDayIndexFrom(int x, int y) { int colModulo = (width()-2) % 7; int rowModulo = (height()-2) % 6; #if 0 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 6 - x/daysize.width() : x/daysize.width()); #endif int xVal = (x-colModulo/2-2)/daysize.width(); int yVal = (y-rowModulo/2-2)/daysize.height(); return 7*(yVal) + xVal; } // ---------------------------------------------------------------------------- // M O U S E E V E N T H A N D L I N G // ---------------------------------------------------------------------------- void KODayMatrix::mousePressEvent (QMouseEvent* e) { if ( e->button() == LeftButton ) mouseDown = true; mSelStart = getDayIndexFrom(e->x(), e->y()); if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; mSelInit = mSelStart; mSelEnd = mSelStart; mRedrawNeeded = true; repaint(false); } void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) { mRedrawNeeded = true; if ( e->button() == LeftButton ) if ( ! mouseDown ) { return; } else mouseDown = false; int tmp = getDayIndexFrom(e->x(), e->y()); if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; if (mSelInit > tmp) { mSelEnd = mSelInit; if (tmp != mSelStart) { mSelStart = tmp; repaint(false); } } else { mSelStart = mSelInit; //repaint only if selection has changed if (tmp != mSelEnd) { mSelEnd = tmp; repaint(false); } } DateList daylist; if ( mSelStart < 0 ) mSelStart = 0; for (int i = mSelStart; i <= mSelEnd; i++) { daylist.append(days[i]); } emit selected((const DateList)daylist); } void KODayMatrix::mouseMoveEvent (QMouseEvent* e) { if ( ! mouseDown ) { return; } mRedrawNeeded = true; int tmp = getDayIndexFrom(e->x(), e->y()); if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; if (mSelInit > tmp) { mSelEnd = mSelInit; if (tmp != mSelStart) { mSelStart = tmp; repaint(false); } } else { mSelStart = mSelInit; //repaint only if selection has changed if (tmp != mSelEnd) { mSelEnd = tmp; repaint(false); } } } // ---------------------------------------------------------------------------- // D R A G ' N D R O P H A N D L I N G // ---------------------------------------------------------------------------- void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) { #ifndef KORG_NODND if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { e->ignore(); return; } // some visual feedback // oldPalette = palette(); // setPalette(my_HilitePalette); // update(); #endif } void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) { #ifndef KORG_NODND if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { e->ignore(); return; } e->accept(); #endif } |