summaryrefslogtreecommitdiffabout
path: root/korganizer/kodaymatrix.cpp
authorzautrix <zautrix>2005-04-05 09:30:00 (UTC)
committer zautrix <zautrix>2005-04-05 09:30:00 (UTC)
commit53d7ec81939a9cf7ea2f63f133c1b61b2e2a9216 (patch) (side-by-side diff)
tree8dfcb059271cbfd4e28425d85dea747aa998594d /korganizer/kodaymatrix.cpp
parent768858848f466a726e2f50b777345976828cc2ff (diff)
downloadkdepimpi-53d7ec81939a9cf7ea2f63f133c1b61b2e2a9216.zip
kdepimpi-53d7ec81939a9cf7ea2f63f133c1b61b2e2a9216.tar.gz
kdepimpi-53d7ec81939a9cf7ea2f63f133c1b61b2e2a9216.tar.bz2
fix
Diffstat (limited to 'korganizer/kodaymatrix.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kodaymatrix.cpp144
1 files changed, 140 insertions, 4 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index c7e1b45..322131f 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -119,6 +119,7 @@ KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const
mouseDown = false;
// initialize dynamic arrays
bDays.resize ( NUMDAYS );
+ pDays.resize ( NUMDAYS );
hDays.resize ( NUMDAYS );
eDays.resize ( NUMDAYS );
days = new QDate[NUMDAYS];
@@ -340,11 +341,44 @@ 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 ;
+ }
+ 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 ;
+ }
+ eDays.setBit(i);
+}
void KODayMatrix::updateViewTimed()
{
mUpdateTimer->stop();
@@ -352,6 +386,106 @@ void KODayMatrix::updateViewTimed()
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();
+ 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 0
+ // insert due todos
+ QPtrList<Todo> todos = calendar()->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) {
+ (*cells)[day]->insertTodo( todo );
+ }
+ }
+ }
+#endif
+
+#else
//qDebug("KODayMatrix::updateViewTimed ");
for(int i = 0; i < NUMDAYS; i++) {
// if events are set for the day then remember to draw it bold
@@ -363,6 +497,7 @@ void KODayMatrix::updateViewTimed()
hDays.clearBit(i);
eDays.clearBit(i);
for(event=eventlist.first();event != 0;event=eventlist.next()) {
+ qDebug("FFFFFFFFFFFFFFFFFFFFFFFFF ");
ushort recurType = event->recurrence()->doesRecur();
if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
(recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
@@ -395,6 +530,7 @@ void KODayMatrix::updateViewTimed()
mHolidays[i] = QString::null;
}
}
+#endif
mRedrawNeeded = true;
if ( ! mPendingUpdateBeforeRepaint )
repaint(false);
@@ -442,7 +578,7 @@ void KODayMatrix::updateView(QDate actdate)
mUpdateTimer->start( 50 );
#else
mRepaintTimer->start( 350 );
- mUpdateTimer->start( 1200 );
+ mUpdateTimer->start( 800 );
#endif
}
}
@@ -873,7 +1009,7 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent)
else
mTodayPen.setWidth(mTodayMarginWidth);
//draw red rectangle for holidays
- if (!mHolidays[i].isNull()) {
+ if (pDays.testBit(i)) {
if (actcol == mDefaultTextColor) {
mTodayPen.setColor(KOPrefs::instance()->mHolidayColor);
} else {
@@ -914,7 +1050,7 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent)
}
// if it is a holiday then use the default holiday color
- if ( !mHolidays[i].isNull()) {
+ if ( pDays.testBit(i)) {
if ( bDays.testBit(i) ) {
if ( hDays.testBit(i) )
p.setPen(QColor(Qt::green));
@@ -953,7 +1089,7 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent)
Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]);
// reset color to actual color
- if (!mHolidays[i].isNull()) {
+ if (pDays.testBit(i)) {
p.setPen(actcol);
}
// reset bold font to plain font