summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kdatenavigator.cpp4
-rw-r--r--korganizer/koagendaitem.cpp13
-rw-r--r--korganizer/kodaymatrix.cpp148
-rw-r--r--korganizer/kodaymatrix.h5
4 files changed, 106 insertions, 64 deletions
diff --git a/korganizer/kdatenavigator.cpp b/korganizer/kdatenavigator.cpp
index b420351..f31e50a 100644
--- a/korganizer/kdatenavigator.cpp
+++ b/korganizer/kdatenavigator.cpp
@@ -164,166 +164,166 @@ void KDateNavigator::passedMidnight()
164 { 164 {
165 if (updateRollover==FollowMonth && 165 if (updateRollover==FollowMonth &&
166 daymatrix->isEndOfMonth()) { 166 daymatrix->isEndOfMonth()) {
167 goNextMonth(); 167 goNextMonth();
168 emitMonth=true; 168 emitMonth=true;
169 } 169 }
170 } 170 }
171 daymatrix->recalculateToday(); 171 daymatrix->recalculateToday();
172 daymatrix->repaint(); 172 daymatrix->repaint();
173 emit dayPassed(today); 173 emit dayPassed(today);
174 if (emitMonth) { emit monthPassed(today); } 174 if (emitMonth) { emit monthPassed(today); }
175} 175}
176 176
177/* slot */ void KDateNavigator::possiblyPastMidnight() 177/* slot */ void KDateNavigator::possiblyPastMidnight()
178{ 178{
179 if (lastDayChecked!=QDate::currentDate()) 179 if (lastDayChecked!=QDate::currentDate())
180 { 180 {
181 passedMidnight(); 181 passedMidnight();
182 lastDayChecked=QDate::currentDate(); 182 lastDayChecked=QDate::currentDate();
183 } 183 }
184 // Set the timer to go off 1 second after midnight 184 // Set the timer to go off 1 second after midnight
185 // or after 8 minutes, whichever comes first. 185 // or after 8 minutes, whichever comes first.
186 if (updateTimer) 186 if (updateTimer)
187 { 187 {
188 QTime now = QTime::currentTime(); 188 QTime now = QTime::currentTime();
189 QTime midnight = QTime(23,59,59); 189 QTime midnight = QTime(23,59,59);
190 int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000); 190 int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000);
191 191
192 // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait)) 192 // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait))
193 //.arg(now.toString()).arg(midnight.toString())); 193 //.arg(now.toString()).arg(midnight.toString()));
194 194
195 updateTimer->stop(); 195 updateTimer->stop();
196 updateTimer->start(msecsWait,true); 196 updateTimer->start(msecsWait,true);
197 } 197 }
198} 198}
199 199
200void KDateNavigator::updateDates() 200void KDateNavigator::updateDates()
201{ 201{
202 // Find the first day of the week of the current month. 202 // Find the first day of the week of the current month.
203 //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr ); 203 //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr );
204 QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() ); 204 QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() );
205 int d2 = KOGlobals::self()->calendarSystem()->day( dayone ); 205 int d2 = KOGlobals::self()->calendarSystem()->day( dayone );
206 //int di = d1 - d2 + 1; 206 //int di = d1 - d2 + 1;
207 dayone = dayone.addDays( -d2 + 1 ); 207 dayone = dayone.addDays( -d2 + 1 );
208 208
209 int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone ); 209 int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone );
210 210
211 // If month begins on Monday and Monday is first day of week, 211 // If month begins on Monday and Monday is first day of week,
212 // month should begin on second line. Sunday doesn't have this problem. 212 // month should begin on second line. Sunday doesn't have this problem.
213 int nextLine = ( ( m_fstDayOfWkCalsys == 1) && 213 int nextLine = ( ( m_fstDayOfWkCalsys == 1) &&
214 ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0; 214 ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0;
215 215
216 // update the matrix dates 216 // update the matrix dates
217 int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine; 217 int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine;
218 218
219 219
220 daymatrix->updateView(dayone.addDays(index)); 220 daymatrix->updateView(dayone.addDays(index));
221//each updateDates is followed by an updateView -> repaint is issued there ! 221//each updateDates is followed by an updateView -> repaint is issued there !
222// daymatrix->repaint(); 222// daymatrix->repaint();
223} 223}
224 224
225void KDateNavigator::updateDayMatrix() 225void KDateNavigator::updateDayMatrix()
226{ 226{
227 daymatrix->updateView(); 227 daymatrix->updateView();
228 daymatrix->repaint(); 228 //daymatrix->repaint();
229} 229}
230 230
231 231
232void KDateNavigator::updateView() 232void KDateNavigator::updateView()
233{ 233{
234 234
235 setUpdatesEnabled( false ); 235 setUpdatesEnabled( false );
236 236
237 int i; 237 int i;
238 238
239// kdDebug() << "updateView() -> daymatrix->updateView()" << endl; 239// kdDebug() << "updateView() -> daymatrix->updateView()" << endl;
240 daymatrix->updateView(); 240 daymatrix->updateView();
241 241
242 // set the week numbers. 242 // set the week numbers.
243 for(i = 0; i < 6; i++) { 243 for(i = 0; i < 6; i++) {
244 QString weeknum; 244 QString weeknum;
245 // remember, according to ISO 8601, the first week of the year is the 245 // remember, according to ISO 8601, the first week of the year is the
246 // first week that contains a thursday. Thus we must subtract off 4, 246 // first week that contains a thursday. Thus we must subtract off 4,
247 // not just 1. 247 // not just 1.
248 248
249 //ET int dayOfYear = buttons[(i + 1) * 7 - 4]->date().dayOfYear(); 249 //ET int dayOfYear = buttons[(i + 1) * 7 - 4]->date().dayOfYear();
250 int dayOfYear = KOGlobals::self()->calendarSystem()->dayOfYear((daymatrix->getDate((i+1)*7-4))); 250 int dayOfYear = KOGlobals::self()->calendarSystem()->dayOfYear((daymatrix->getDate((i+1)*7-4)));
251 251
252 int add = 0; 252 int add = 0;
253 if ( ! KGlobal::locale()->weekStartsMonday() ) 253 if ( ! KGlobal::locale()->weekStartsMonday() )
254 ++add; 254 ++add;
255 if (dayOfYear % 7 != 0) 255 if (dayOfYear % 7 != 0)
256 weeknum.setNum(dayOfYear / 7 + 1+add); 256 weeknum.setNum(dayOfYear / 7 + 1+add);
257 else 257 else
258 weeknum.setNum(dayOfYear / 7 +add); 258 weeknum.setNum(dayOfYear / 7 +add);
259 weeknos[i]->setText(weeknum); 259 weeknos[i]->setText(weeknum);
260 } 260 }
261 261
262 setUpdatesEnabled( true ); 262 setUpdatesEnabled( true );
263// kdDebug() << "updateView() -> repaint()" << endl; 263// kdDebug() << "updateView() -> repaint()" << endl;
264 repaint(); 264 repaint();
265 daymatrix->repaint(); 265 // daymatrix->repaint();
266} 266}
267 267
268void KDateNavigator::updateConfig() 268void KDateNavigator::updateConfig()
269{ 269{
270 int day; 270 int day;
271 for(int i=0; i<7; i++) { 271 for(int i=0; i<7; i++) {
272 // take the first letter of the day name to be the abbreviation 272 // take the first letter of the day name to be the abbreviation
273 if (KGlobal::locale()->weekStartsMonday()) { 273 if (KGlobal::locale()->weekStartsMonday()) {
274 day = i+1; 274 day = i+1;
275 } else { 275 } else {
276 if (i==0) day = 7; 276 if (i==0) day = 7;
277 else day = i; 277 else day = i;
278 } 278 }
279 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( day, 279 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( day,
280 true ); 280 true );
281 if ( KOPrefs::instance()->mCompactDialogs ) dayName = dayName.left( 1 ); 281 if ( KOPrefs::instance()->mCompactDialogs ) dayName = dayName.left( 1 );
282 headings[i]->setText( dayName ); 282 headings[i]->setText( dayName );
283 } 283 }
284 updateDates(); 284 updateDates();
285 updateView(); 285 updateView();
286} 286}
287 287
288void KDateNavigator::setShowWeekNums(bool enabled) 288void KDateNavigator::setShowWeekNums(bool enabled)
289{ 289{
290 m_bShowWeekNums = enabled; 290 m_bShowWeekNums = enabled;
291 for(int i=0; i<6; i++) { 291 for(int i=0; i<6; i++) {
292 if(enabled) 292 if(enabled)
293 weeknos[i]->show(); 293 weeknos[i]->show();
294 else 294 else
295 weeknos[i]->hide(); 295 weeknos[i]->hide();
296 } 296 }
297 resize(size()); 297 resize(size());
298} 298}
299 299
300void KDateNavigator::selectDates(const DateList& dateList) 300void KDateNavigator::selectDates(const DateList& dateList)
301{ 301{
302 302
303 if (dateList.count() > 0) { 303 if (dateList.count() > 0) {
304 mNavigatorBar->selectDates( dateList ); 304 mNavigatorBar->selectDates( dateList );
305 mSelectedDates = dateList; 305 mSelectedDates = dateList;
306 306
307 // set our record of the month and year that this datetbl is 307 // set our record of the month and year that this datetbl is
308 // displaying. 308 // displaying.
309 m_MthYr = mSelectedDates.first(); 309 m_MthYr = mSelectedDates.first();
310 310
311 311
312 // set our record of the first day of the week of the current 312 // set our record of the first day of the week of the current
313 // month. This needs to be done before calling dayToIndex, since it 313 // month. This needs to be done before calling dayToIndex, since it
314 // relies on this information being up to date. 314 // relies on this information being up to date.
315 QDate dayone(m_MthYr.year(), m_MthYr.month(), 1); 315 QDate dayone(m_MthYr.year(), m_MthYr.month(), 1);
316 m_fstDayOfWk = dayone.dayOfWeek(); 316 m_fstDayOfWk = dayone.dayOfWeek();
317 317
318 updateDates(); 318 updateDates();
319 319
320 daymatrix->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); 320 daymatrix->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
321 321
322 updateView(); 322 updateView();
323 } 323 }
324} 324}
325 325
326int KDateNavigator::dayNum(int row, int col) 326int KDateNavigator::dayNum(int row, int col)
327{ 327{
328 return 7 * (row - 1) + (col + 1) - m_fstDayOfWk; 328 return 7 * (row - 1) + (col + 1) - m_fstDayOfWk;
329} 329}
diff --git a/korganizer/koagendaitem.cpp b/korganizer/koagendaitem.cpp
index 39355b4..ee9f39a 100644
--- a/korganizer/koagendaitem.cpp
+++ b/korganizer/koagendaitem.cpp
@@ -408,135 +408,134 @@ QPixmap * KOAgendaItem::paintPix()
408 mPaintPix = new QPixmap(1,1); 408 mPaintPix = new QPixmap(1,1);
409 return mPaintPix ; 409 return mPaintPix ;
410} 410}
411QPixmap * KOAgendaItem::paintPixAllday() 411QPixmap * KOAgendaItem::paintPixAllday()
412{ 412{
413 static QPixmap* mPaintPixA = 0; 413 static QPixmap* mPaintPixA = 0;
414 if ( ! mPaintPixA ) 414 if ( ! mPaintPixA )
415 mPaintPixA = new QPixmap(1,1); 415 mPaintPixA = new QPixmap(1,1);
416 return mPaintPixA ; 416 return mPaintPixA ;
417} 417}
418QPixmap * KOAgendaItem::paintPixSel() 418QPixmap * KOAgendaItem::paintPixSel()
419{ 419{
420 static QPixmap* mPaintPixSel = 0; 420 static QPixmap* mPaintPixSel = 0;
421 if ( ! mPaintPixSel ) 421 if ( ! mPaintPixSel )
422 mPaintPixSel = new QPixmap(1,1); 422 mPaintPixSel = new QPixmap(1,1);
423 return mPaintPixSel ; 423 return mPaintPixSel ;
424} 424}
425void KOAgendaItem::paintEvent ( QPaintEvent *e ) 425void KOAgendaItem::paintEvent ( QPaintEvent *e )
426{ 426{
427 427
428 if ( globalFlagBlockAgendaItemPaint ) 428 if ( globalFlagBlockAgendaItemPaint )
429 return; 429 return;
430 if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 ) 430 if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 )
431 return; 431 return;
432 int yy; 432 int yy;
433 if ( mAllDay ) 433 if ( mAllDay )
434 yy = y(); 434 yy = y();
435 else 435 else
436 yy = mCellYTop * ( height() / cellHeight() ); 436 yy = mCellYTop * ( height() / cellHeight() );
437 int xx = x(); 437 int xx = x();
438 if ( xPaintCoord != xx || yPaintCoord != yy || 438 if ( xPaintCoord != xx || yPaintCoord != yy ||
439 wPaintCoord != width() || hPaintCoord != height()) { 439 wPaintCoord != width() || hPaintCoord != height()) {
440 xPaintCoord= xx; 440 xPaintCoord= xx;
441 yPaintCoord = yy; 441 yPaintCoord = yy;
442 wPaintCoord = width(); 442 wPaintCoord = width();
443 hPaintCoord = height(); 443 hPaintCoord = height();
444 globalFlagBlockAgendaItemUpdate = 0; 444 globalFlagBlockAgendaItemUpdate = 0;
445 paintMe( mSelected ); 445 paintMe( mSelected );
446 //qDebug("calling paintMe "); 446 //qDebug("calling paintMe ");
447 globalFlagBlockAgendaItemUpdate = 1; 447 globalFlagBlockAgendaItemUpdate = 1;
448 } 448 }
449 int rx, ry, rw, rh; 449 int rx, ry, rw, rh;
450 rx = e->rect().x(); 450 rx = e->rect().x();
451 ry = e->rect().y(); 451 ry = e->rect().y();
452 rw = e->rect().width(); 452 rw = e->rect().width();
453 rh = e->rect().height(); 453 rh = e->rect().height();
454 //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height()); 454 //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height());
455 455
456 QPixmap* paintFrom ; 456 QPixmap* paintFrom ;
457 if ( mSelected ) { 457 if ( mSelected ) {
458 paintFrom = paintPixSel(); 458 paintFrom = paintPixSel();
459 } else { 459 } else {
460 if ( mAllDay ) 460 if ( mAllDay )
461 paintFrom = paintPixAllday(); 461 paintFrom = paintPixAllday();
462 else 462 else
463 paintFrom = paintPix(); 463 paintFrom = paintPix();
464 } 464 }
465 bitBlt (this, rx, ry, paintFrom, x()+rx ,yPaintCoord+ry, rw, rh ,CopyROP); 465 bitBlt (this, rx, ry, paintFrom, x()+rx ,yPaintCoord+ry, rw, rh ,CopyROP);
466} 466}
467void KOAgendaItem::computeText() 467void KOAgendaItem::computeText()
468{ 468{
469 469
470 mDisplayedText = mIncidence->summary(); 470 mDisplayedText = mIncidence->summary();
471 if ( (mIncidence->type() == "Todo") ) { 471 if ( (mIncidence->type() == "Todo") ) {
472 if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() ) 472 if ( static_cast<Todo*>(mIncidence)->hasDueDate() ) {
473 mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")"; 473 if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() )
474 else if ( !(mIncidence->doesFloat())) 474 mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")";
475 mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")"; 475 else if ( !(mIncidence->doesFloat()))
476 476 mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")";
477 477 }
478
479 } else { 478 } else {
480 if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda) 479 if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda)
481 mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + "-" + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ; 480 mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + "-" + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ;
482 481
483 if ( mAllDay ) { 482 if ( mAllDay ) {
484 if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) { 483 if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) {
485 mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) ; 484 mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) ;
486 } 485 }
487 } 486 }
488 487
489 } 488 }
490 489
491 if ( !mIncidence->location().isEmpty() ) { 490 if ( !mIncidence->location().isEmpty() ) {
492 if ( mAllDay ) 491 if ( mAllDay )
493 mDisplayedText += " ("; 492 mDisplayedText += " (";
494 else 493 else
495 mDisplayedText += "\n("; 494 mDisplayedText += "\n(";
496 mDisplayedText += mIncidence->location() +")"; 495 mDisplayedText += mIncidence->location() +")";
497 } 496 }
498 497
499 QString tipText = mIncidence->summary(); 498 QString tipText = mIncidence->summary();
500 QWhatsThis::add(this,KIncidenceFormatter::instance()->getFormattedText( mIncidence )); 499 QWhatsThis::add(this,KIncidenceFormatter::instance()->getFormattedText( mIncidence ));
501 if ( !mIncidence->doesFloat() ) { 500 if ( !mIncidence->doesFloat() ) {
502 if ( mIncidence->type() == "Event" ) { 501 if ( mIncidence->type() == "Event" ) {
503 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) { 502 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) {
504 tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr(); 503 tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr();
505 tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr(); 504 tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr();
506 } 505 }
507 else { 506 else {
508 tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr(); 507 tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr();
509 tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr(); 508 tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr();
510 } 509 }
511 } 510 }
512 else if ( mIncidence->type() == "Todo" ) { 511 else if ( mIncidence->type() == "Todo" ) {
513 if (mIncidence->hasStartDate()) 512 if (mIncidence->hasStartDate())
514 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartStr(); 513 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartStr();
515 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueStr(); 514 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueStr();
516 } 515 }
517 } else if ( mIncidence->type() == "Todo" ) { 516 } else if ( mIncidence->type() == "Todo" ) {
518 if (mIncidence->hasStartDate()) 517 if (mIncidence->hasStartDate())
519 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartDateStr(); 518 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartDateStr();
520 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueDateStr(); 519 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueDateStr();
521 } 520 }
522 521
523 if (!mIncidence->location().isEmpty()) { 522 if (!mIncidence->location().isEmpty()) {
524 tipText += "\n"+i18n("Location: ")+mIncidence->location(); 523 tipText += "\n"+i18n("Location: ")+mIncidence->location();
525 } 524 }
526 QToolTip::add(this,tipText,toolTipGroup(),""); 525 QToolTip::add(this,tipText,toolTipGroup(),"");
527 526
528} 527}
529void KOAgendaItem::updateItem() 528void KOAgendaItem::updateItem()
530{ 529{
531 computeText(); 530 computeText();
532 531
533 //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y()); 532 //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y());
534 paintMe( mSelected ); 533 paintMe( mSelected );
535 repaint( false); 534 repaint( false);
536} 535}
537 536
538void KOAgendaItem::resizeEvent ( QResizeEvent *ev ) 537void KOAgendaItem::resizeEvent ( QResizeEvent *ev )
539{ 538{
540 //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1()); 539 //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1());
541 paintMe( mSelected ); 540 paintMe( mSelected );
542 repaint( false ); 541 repaint( false );
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index fc00828..060b4c4 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -47,304 +47,342 @@
47 47
48#include "kodaymatrix.h" 48#include "kodaymatrix.h"
49 49
50// ============================================================================ 50// ============================================================================
51// D Y N A M I C T I P 51// D Y N A M I C T I P
52// ============================================================================ 52// ============================================================================
53 53
54DynamicTip::DynamicTip( QWidget * parent ) 54DynamicTip::DynamicTip( QWidget * parent )
55 : QToolTip( parent ) 55 : QToolTip( parent )
56{ 56{
57 matrix = (KODayMatrix*)parent; 57 matrix = (KODayMatrix*)parent;
58} 58}
59 59
60 60
61void DynamicTip::maybeTip( const QPoint &pos ) 61void DynamicTip::maybeTip( const QPoint &pos )
62{ 62{
63 //calculate which cell of the matrix the mouse is in 63 //calculate which cell of the matrix the mouse is in
64 QRect sz = matrix->frameRect(); 64 QRect sz = matrix->frameRect();
65 int dheight = sz.height()*7 / 42; 65 int dheight = sz.height()*7 / 42;
66 int dwidth = sz.width() / 7; 66 int dwidth = sz.width() / 7;
67 int row = pos.y()/dheight; 67 int row = pos.y()/dheight;
68 int col = pos.x()/dwidth; 68 int col = pos.x()/dwidth;
69 69
70 QRect rct(col*dwidth, row*dheight, dwidth, dheight); 70 QRect rct(col*dwidth, row*dheight, dwidth, dheight);
71 71
72// kdDebug() << "DynamicTip::maybeTip matrix cell index [" << 72// kdDebug() << "DynamicTip::maybeTip matrix cell index [" <<
73// col << "][" << row << "] => " <<(col+row*7) << endl; 73// col << "][" << row << "] => " <<(col+row*7) << endl;
74 74
75 //show holiday names only 75 //show holiday names only
76 QString str = matrix->getHolidayLabel(col+row*7); 76 QString str = matrix->getHolidayLabel(col+row*7);
77 if (str.isEmpty()) return; 77 if (str.isEmpty()) return;
78 tip(rct, str); 78 tip(rct, str);
79} 79}
80 80
81 81
82// ============================================================================ 82// ============================================================================
83// K O D A Y M A T R I X 83// K O D A Y M A T R I X
84// ============================================================================ 84// ============================================================================
85 85
86const int KODayMatrix::NOSELECTION = -1000; 86const int KODayMatrix::NOSELECTION = -1000;
87const int KODayMatrix::NUMDAYS = 42; 87const int KODayMatrix::NUMDAYS = 42;
88 88
89KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : 89KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) :
90 QFrame(parent, name) 90 QFrame(parent, name)
91{ 91{
92 mCalendar = calendar; 92 mCalendar = calendar;
93 93
94 // initialize dynamic arrays 94 // initialize dynamic arrays
95 days = new QDate[NUMDAYS]; 95 days = new QDate[NUMDAYS];
96 daylbls = new QString[NUMDAYS]; 96 daylbls = new QString[NUMDAYS];
97 events = new int[NUMDAYS]; 97 events = new int[NUMDAYS];
98 mToolTip = new DynamicTip(this); 98 mToolTip = new DynamicTip(this);
99 99
100 // set default values used for drawing the matrix 100 // set default values used for drawing the matrix
101 mDefaultBackColor = palette().active().base(); 101 mDefaultBackColor = palette().active().base();
102 mDefaultTextColor = palette().active().foreground(); 102 mDefaultTextColor = palette().active().foreground();
103 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); 103 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor);
104 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); 104 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor);
105 mSelectedDaysColor = QColor("white"); 105 mSelectedDaysColor = QColor("white");
106 mTodayMarginWidth = 2; 106 mTodayMarginWidth = 2;
107 mSelEnd = mSelStart = NOSELECTION; 107 mSelEnd = mSelStart = NOSELECTION;
108 108
109 setAcceptDrops(true); 109 setAcceptDrops(true);
110 //setFont( QFont("Arial", 10) ); 110 //setFont( QFont("Arial", 10) );
111 updateView(date); 111
112 mUpdateTimer = new QTimer( this );
113 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() ));
114 mRepaintTimer = new QTimer( this );
115 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() ));
116 mDayChanged = false;
117 updateView();
112} 118}
113 119
114QColor KODayMatrix::getShadedColor(QColor color) 120QColor KODayMatrix::getShadedColor(QColor color)
115{ 121{
116 QColor shaded; 122 QColor shaded;
117 int h=0; 123 int h=0;
118 int s=0; 124 int s=0;
119 int v=0; 125 int v=0;
120 color.hsv(&h,&s,&v); 126 color.hsv(&h,&s,&v);
121 s = s/4; 127 s = s/4;
122 v = 192+v/4; 128 v = 192+v/4;
123 shaded.setHsv(h,s,v); 129 shaded.setHsv(h,s,v);
124 130
125 return shaded; 131 return shaded;
126} 132}
127 133
128KODayMatrix::~KODayMatrix() 134KODayMatrix::~KODayMatrix()
129{ 135{
130 delete [] days; 136 delete [] days;
131 delete [] daylbls; 137 delete [] daylbls;
132 delete [] events; 138 delete [] events;
133 delete mToolTip; 139 delete mToolTip;
134} 140}
135 141
136/* 142/*
137void KODayMatrix::setStartDate(QDate start) 143void KODayMatrix::setStartDate(QDate start)
138{ 144{
139 updateView(start); 145 updateView(start);
140} 146}
141*/ 147*/
142 148
143void KODayMatrix::addSelectedDaysTo(DateList& selDays) 149void KODayMatrix::addSelectedDaysTo(DateList& selDays)
144{ 150{
145 kdDebug() << "KODayMatrix::addSelectedDaysTo() - " << "mSelStart:" << mSelStart << endl; 151 kdDebug() << "KODayMatrix::addSelectedDaysTo() - " << "mSelStart:" << mSelStart << endl;
146 152
147 if (mSelStart == NOSELECTION) { 153 if (mSelStart == NOSELECTION) {
148 return; 154 return;
149 } 155 }
150 156
151 //cope with selection being out of matrix limits at top (< 0) 157 //cope with selection being out of matrix limits at top (< 0)
152 int i0 = mSelStart; 158 int i0 = mSelStart;
153 if (i0 < 0) { 159 if (i0 < 0) {
154 for (int i = i0; i < 0; i++) { 160 for (int i = i0; i < 0; i++) {
155 selDays.append(days[0].addDays(i)); 161 selDays.append(days[0].addDays(i));
156 } 162 }
157 i0 = 0; 163 i0 = 0;
158 } 164 }
159 165
160 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) 166 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1)
161 if (mSelEnd > NUMDAYS-1) { 167 if (mSelEnd > NUMDAYS-1) {
162 for (int i = i0; i <= NUMDAYS-1; i++) { 168 for (int i = i0; i <= NUMDAYS-1; i++) {
163 selDays.append(days[i]); 169 selDays.append(days[i]);
164 } 170 }
165 for (int i = NUMDAYS; i < mSelEnd; i++) { 171 for (int i = NUMDAYS; i < mSelEnd; i++) {
166 selDays.append(days[0].addDays(i)); 172 selDays.append(days[0].addDays(i));
167 } 173 }
168 174
169 // apply normal routine to selection being entirely within matrix limits 175 // apply normal routine to selection being entirely within matrix limits
170 } else { 176 } else {
171 for (int i = i0; i <= mSelEnd; i++) { 177 for (int i = i0; i <= mSelEnd; i++) {
172 selDays.append(days[i]); 178 selDays.append(days[i]);
173 } 179 }
174 } 180 }
175} 181}
176 182
177void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 183void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
178{ 184{
179 mSelStart = startdate.daysTo(start); 185 mSelStart = startdate.daysTo(start);
180 mSelEnd = startdate.daysTo(end); 186 mSelEnd = startdate.daysTo(end);
181} 187}
182 188
183 189
184void KODayMatrix::recalculateToday() 190void KODayMatrix::recalculateToday()
185{ 191{
186 today = -1; 192 today = -1;
187 for (int i=0; i<NUMDAYS; i++) { 193 for (int i=0; i<NUMDAYS; i++) {
188 days[i] = startdate.addDays(i); 194 days[i] = startdate.addDays(i);
189 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 195 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
190 196
191 // if today is in the currently displayed month, hilight today 197 // if today is in the currently displayed month, hilight today
192 if (days[i].year() == QDate::currentDate().year() && 198 if (days[i].year() == QDate::currentDate().year() &&
193 days[i].month() == QDate::currentDate().month() && 199 days[i].month() == QDate::currentDate().month() &&
194 days[i].day() == QDate::currentDate().day()) { 200 days[i].day() == QDate::currentDate().day()) {
195 today = i; 201 today = i;
196 } 202 }
197 } 203 }
198 // qDebug(QString("Today is visible at %1.").arg(today)); 204 // qDebug(QString("Today is visible at %1.").arg(today));
199} 205}
200 206
201void KODayMatrix::updateView() 207void KODayMatrix::updateView()
202{ 208{
203 updateView(startdate); 209 updateView(startdate);
204} 210}
205 211void KODayMatrix::repaintViewTimed()
206void KODayMatrix::updateView(QDate actdate) 212{
213 qDebug("KODayMatrix::repaintViewTimed ");
214 mRepaintTimer->stop();
215 repaint(false);
216}
217void KODayMatrix::updateViewTimed()
207{ 218{
208
209// kdDebug() << "KODayMatrix::updateView() " << actdate.toString() << endl;
210
211 //flag to indicate if the starting day of the matrix has changed by this call
212 bool daychanged = false;
213 // if a new startdate is to be set then apply Cornelius's calculation
214 // of the first day to be shown
215 if (actdate != startdate) {
216 // reset index of selection according to shift of starting date from startdate to actdate
217 if (mSelStart != NOSELECTION) {
218 int tmp = actdate.daysTo(startdate);
219 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl;
220 // shift selection if new one would be visible at least partly !
221
222 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) {
223 // nested if is required for next X display pushed from a different month - correction required
224 // otherwise, for month forward and backward, it must be avoided
225 if( mSelStart > NUMDAYS || mSelStart < 0 )
226 mSelStart = mSelStart + tmp;
227 if( mSelEnd > NUMDAYS || mSelEnd < 0 )
228 mSelEnd = mSelEnd + tmp;
229 }
230 }
231 219
232 startdate = actdate; 220 mUpdateTimer->stop();
233 daychanged = true; 221 //QDate actdate = mPendingNewDate;
234 }
235 222
236 if (daychanged) { 223 static int iii = 0;
237 recalculateToday(); 224 qDebug("KODayMatrix::updateView(QDate actdate) %d", ++iii );
238 } 225
226 if (mDayChanged) {
227 recalculateToday();
228 mDayChanged = false;
229 }
239 230
240 for(int i = 0; i < NUMDAYS; i++) { 231 for(int i = 0; i < NUMDAYS; i++) {
241 232
242 // if events are set for the day then remember to draw it bold 233 // if events are set for the day then remember to draw it bold
243 QPtrList<Event> eventlist = mCalendar->events(days[i]); 234 QPtrList<Event> eventlist = mCalendar->events(days[i]);
244 Event *event; 235 Event *event;
245 int numEvents = eventlist.count(); 236 int numEvents = eventlist.count();
246 237
247 for(event=eventlist.first();event != 0;event=eventlist.next()) { 238 for(event=eventlist.first();event != 0;event=eventlist.next()) {
248 ushort recurType = event->recurrence()->doesRecur(); 239 ushort recurType = event->recurrence()->doesRecur();
249 240
250 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 241 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
251 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 242 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
252 numEvents--; 243 numEvents--;
253 } 244 }
254 } 245 }
255 events[i] = numEvents; 246 events[i] = numEvents;
256 247
257 //if it is a holy day then draw it red. Sundays are consider holidays, too 248 //if it is a holy day then draw it red. Sundays are consider holidays, too
258#ifndef KORG_NOPLUGINS 249#ifndef KORG_NOPLUGINS
259 QString holiStr = KOCore::self()->holiday(days[i]); 250 QString holiStr = KOCore::self()->holiday(days[i]);
260#else 251#else
261 QString holiStr = QString::null; 252 QString holiStr = QString::null;
262#endif 253#endif
263 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || 254 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) ||
264 !holiStr.isEmpty()) { 255 !holiStr.isEmpty()) {
265 if (holiStr.isNull()) holiStr = ""; 256 if (holiStr.isNull()) holiStr = "";
266 mHolidays[i] = holiStr; 257 mHolidays[i] = holiStr;
267 258
259 } else {
260 mHolidays[i] = QString::null;
261 }
262 }
263 repaint(false);
264 }
265void KODayMatrix::updateView(QDate actdate)
266{
267
268 //flag to indicate if the starting day of the matrix has changed by this call
269 //mDayChanged = false;
270 // if a new startdate is to be set then apply Cornelius's calculation
271 // of the first day to be shown
272 if (actdate != startdate) {
273 // reset index of selection according to shift of starting date from startdate to actdate
274 if (mSelStart != NOSELECTION) {
275 int tmp = actdate.daysTo(startdate);
276 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl;
277 // shift selection if new one would be visible at least partly !
278
279 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) {
280 // nested if is required for next X display pushed from a different month - correction required
281 // otherwise, for month forward and backward, it must be avoided
282 if( mSelStart > NUMDAYS || mSelStart < 0 )
283 mSelStart = mSelStart + tmp;
284 if( mSelEnd > NUMDAYS || mSelEnd < 0 )
285 mSelEnd = mSelEnd + tmp;
286 }
287 }
288
289 startdate = actdate;
290 mDayChanged = true;
291 }
292 qDebug("restart Timer %d", mDayChanged );
293 static int iii = 0;
294 if ( iii < 5 ) {
295 ++iii;
296 updateViewTimed();
268 } else { 297 } else {
269 mHolidays[i] = QString::null; 298 if ( !isVisible() ) {
299 mUpdateTimer->start( 2000 );
300 } else {
301 if ( mDayChanged ) {
302 mUpdateTimer->start( 250 );
303 } else {
304 mRepaintTimer->start( 250 );
305 mUpdateTimer->start( 2000 );
306 }
307 }
270 } 308 }
271 } 309
272} 310}
273 311
274const QDate& KODayMatrix::getDate(int offset) 312const QDate& KODayMatrix::getDate(int offset)
275{ 313{
276 if (offset < 0 || offset > NUMDAYS-1) { 314 if (offset < 0 || offset > NUMDAYS-1) {
277 kdDebug() << "Wrong offset (" << offset << ") in KODayMatrix::getDate(int)" << endl; 315 qDebug("Wrong offset2 ");
278 return days[0]; 316 return days[0];
279 } 317 }
280 return days[offset]; 318 return days[offset];
281} 319}
282 320
283QString KODayMatrix::getHolidayLabel(int offset) 321QString KODayMatrix::getHolidayLabel(int offset)
284{ 322{
285 if (offset < 0 || offset > NUMDAYS-1) { 323 if (offset < 0 || offset > NUMDAYS-1) {
286 kdDebug() << "Wrong offset (" << offset << ") in KODayMatrix::getHolidayLabel(int)" << endl; 324 qDebug("Wrong offset1 ");
287 return 0; 325 return 0;
288 } 326 }
289 return mHolidays[offset]; 327 return mHolidays[offset];
290} 328}
291 329
292int KODayMatrix::getDayIndexFrom(int x, int y) 330int KODayMatrix::getDayIndexFrom(int x, int y)
293{ 331{
294 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 332 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
295 6 - x/daysize.width() : x/daysize.width()); 333 6 - x/daysize.width() : x/daysize.width());
296} 334}
297 335
298// ---------------------------------------------------------------------------- 336// ----------------------------------------------------------------------------
299// M O U S E E V E N T H A N D L I N G 337// M O U S E E V E N T H A N D L I N G
300// ---------------------------------------------------------------------------- 338// ----------------------------------------------------------------------------
301 339
302void KODayMatrix::mousePressEvent (QMouseEvent* e) 340void KODayMatrix::mousePressEvent (QMouseEvent* e)
303{ 341{
304 mSelStart = getDayIndexFrom(e->x(), e->y()); 342 mSelStart = getDayIndexFrom(e->x(), e->y());
305 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; 343 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
306 mSelInit = mSelStart; 344 mSelInit = mSelStart;
307} 345}
308 346
309void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) 347void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
310{ 348{
311 349
312 int tmp = getDayIndexFrom(e->x(), e->y()); 350 int tmp = getDayIndexFrom(e->x(), e->y());
313 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 351 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
314 352
315 if (mSelInit > tmp) { 353 if (mSelInit > tmp) {
316 mSelEnd = mSelInit; 354 mSelEnd = mSelInit;
317 if (tmp != mSelStart) { 355 if (tmp != mSelStart) {
318 mSelStart = tmp; 356 mSelStart = tmp;
319 repaint(); 357 repaint();
320 } 358 }
321 } else { 359 } else {
322 mSelStart = mSelInit; 360 mSelStart = mSelInit;
323 361
324 //repaint only if selection has changed 362 //repaint only if selection has changed
325 if (tmp != mSelEnd) { 363 if (tmp != mSelEnd) {
326 mSelEnd = tmp; 364 mSelEnd = tmp;
327 repaint(); 365 repaint();
328 } 366 }
329 } 367 }
330 368
331 DateList daylist; 369 DateList daylist;
332 if ( mSelStart < 0 ) 370 if ( mSelStart < 0 )
333 mSelStart = 0; 371 mSelStart = 0;
334 for (int i = mSelStart; i <= mSelEnd; i++) { 372 for (int i = mSelStart; i <= mSelEnd; i++) {
335 daylist.append(days[i]); 373 daylist.append(days[i]);
336 } 374 }
337 emit selected((const DateList)daylist); 375 emit selected((const DateList)daylist);
338 376
339} 377}
340 378
341void KODayMatrix::mouseMoveEvent (QMouseEvent* e) 379void KODayMatrix::mouseMoveEvent (QMouseEvent* e)
342{ 380{
343 int tmp = getDayIndexFrom(e->x(), e->y()); 381 int tmp = getDayIndexFrom(e->x(), e->y());
344 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 382 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
345 383
346 if (mSelInit > tmp) { 384 if (mSelInit > tmp) {
347 mSelEnd = mSelInit; 385 mSelEnd = mSelInit;
348 if (tmp != mSelStart) { 386 if (tmp != mSelStart) {
349 mSelStart = tmp; 387 mSelStart = tmp;
350 repaint(); 388 repaint();
diff --git a/korganizer/kodaymatrix.h b/korganizer/kodaymatrix.h
index b4eb2a8..0e9640a 100644
--- a/korganizer/kodaymatrix.h
+++ b/korganizer/kodaymatrix.h
@@ -111,175 +111,180 @@ public:
111 * 111 *
112 * @param parent widget that is the parent of the day matrix. Normally this should 112 * @param parent widget that is the parent of the day matrix. Normally this should
113 * be a KDateNavigator 113 * be a KDateNavigator
114 * @param calendar instance of a calendar on which all calculations are based 114 * @param calendar instance of a calendar on which all calculations are based
115 * @param date start date of the matrix (is expected to be already fixed). It is 115 * @param date start date of the matrix (is expected to be already fixed). It is
116 * assumed that this date is the first week day to be shown in the matrix. 116 * assumed that this date is the first week day to be shown in the matrix.
117 * @param name name of the widget 117 * @param name name of the widget
118 */ 118 */
119 KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name ); 119 KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name );
120 120
121 /** destructor that deallocates all dynamically allocated private members. 121 /** destructor that deallocates all dynamically allocated private members.
122 */ 122 */
123 ~KODayMatrix(); 123 ~KODayMatrix();
124 124
125 /** updates the day matrix to start with the given date. Does all the necessary 125 /** updates the day matrix to start with the given date. Does all the necessary
126 * checks for holidays or events on a day and stores them for display later on. 126 * checks for holidays or events on a day and stores them for display later on.
127 * Does NOT update the view visually. Call repaint() for this. 127 * Does NOT update the view visually. Call repaint() for this.
128 * 128 *
129 * @param actdate recalculates the day matrix to show NUMDAYS starting from this 129 * @param actdate recalculates the day matrix to show NUMDAYS starting from this
130 * date. 130 * date.
131 */ 131 */
132 void updateView(QDate actdate); 132 void updateView(QDate actdate);
133 133
134 /** returns the QDate object associated with day indexed by the 134 /** returns the QDate object associated with day indexed by the
135 * supplied offset. 135 * supplied offset.
136 */ 136 */
137 const QDate& getDate(int offset); 137 const QDate& getDate(int offset);
138 138
139 /** returns the official name of this holy day or 0 if there is no label 139 /** returns the official name of this holy day or 0 if there is no label
140 * for this day. 140 * for this day.
141 */ 141 */
142 QString getHolidayLabel(int offset); 142 QString getHolidayLabel(int offset);
143 143
144 /** adds all actual selected days from mSelStart to mSelEnd to the supplied 144 /** adds all actual selected days from mSelStart to mSelEnd to the supplied
145 * DateList. 145 * DateList.
146 */ 146 */
147 void addSelectedDaysTo(DateList&); 147 void addSelectedDaysTo(DateList&);
148 148
149 /** sets the actual to be displayed selection in the day matrix starting from 149 /** sets the actual to be displayed selection in the day matrix starting from
150 * start and ending with end. Theview must be manually updated by calling 150 * start and ending with end. Theview must be manually updated by calling
151 * repaint. (?) 151 * repaint. (?)
152 */ 152 */
153 void setSelectedDaysFrom(const QDate& start, const QDate& end); 153 void setSelectedDaysFrom(const QDate& start, const QDate& end);
154 154
155 155
156 /** Is today visible in the view? Keep this in sync with 156 /** Is today visible in the view? Keep this in sync with
157 * the values today (below) can take. 157 * the values today (below) can take.
158 */ 158 */
159 bool isTodayVisible() const { return today>=0; } ; 159 bool isTodayVisible() const { return today>=0; } ;
160 160
161 /** If today is visible, then we can find out if today is 161 /** If today is visible, then we can find out if today is
162 * near the beginning or the end of the month. 162 * near the beginning or the end of the month.
163 * This is dependent on today remaining the index 163 * This is dependent on today remaining the index
164 * in the array of visible dates and going from 164 * in the array of visible dates and going from
165 * top left (0) to bottom right (41). 165 * top left (0) to bottom right (41).
166 */ 166 */
167 bool isBeginningOfMonth() const { return today<=8; } ; 167 bool isBeginningOfMonth() const { return today<=8; } ;
168 bool isEndOfMonth() const { return today>=27; } ; 168 bool isEndOfMonth() const { return today>=27; } ;
169 169
170public slots: 170public slots:
171 /** Recalculates all the flags of the days in the matrix like holidays or events 171 /** Recalculates all the flags of the days in the matrix like holidays or events
172 * on a day (Actually calls above method with the actual startdate). 172 * on a day (Actually calls above method with the actual startdate).
173 */ 173 */
174 void updateView(); 174 void updateView();
175 void updateViewTimed();
176 void repaintViewTimed();
175 177
176 /** 178 /**
177 * Calculate which square in the matrix should be 179 * Calculate which square in the matrix should be
178 * hilighted to indicate it's today. 180 * hilighted to indicate it's today.
179 */ 181 */
180 void recalculateToday(); 182 void recalculateToday();
181 183
182/* 184/*
183 void setStartDate(QDate); 185 void setStartDate(QDate);
184*/ 186*/
185 187
186signals: 188signals:
187 189
188 /** emitted if the user selects a block of days with the mouse by dragging a rectangle 190 /** emitted if the user selects a block of days with the mouse by dragging a rectangle
189 * inside the matrix 191 * inside the matrix
190 * 192 *
191 * @param daylist list of days that have been selected by the user 193 * @param daylist list of days that have been selected by the user
192 */ 194 */
193 void selected( const KCal::DateList &daylist ); 195 void selected( const KCal::DateList &daylist );
194 196
195 /** emitted if the user has dropped an event inside the matrix 197 /** emitted if the user has dropped an event inside the matrix
196 * 198 *
197 * @param event the dropped calendar event 199 * @param event the dropped calendar event
198 */ 200 */
199 void eventDropped(Event *event); 201 void eventDropped(Event *event);
200 202
201protected: 203protected:
202 204
203 void paintEvent(QPaintEvent *ev); 205 void paintEvent(QPaintEvent *ev);
204 206
205 void mousePressEvent (QMouseEvent* e); 207 void mousePressEvent (QMouseEvent* e);
206 208
207 void mouseReleaseEvent (QMouseEvent* e); 209 void mouseReleaseEvent (QMouseEvent* e);
208 210
209 void mouseMoveEvent (QMouseEvent* e); 211 void mouseMoveEvent (QMouseEvent* e);
210 212
211 void dragEnterEvent(QDragEnterEvent *); 213 void dragEnterEvent(QDragEnterEvent *);
212 214
213 void dragMoveEvent(QDragMoveEvent *); 215 void dragMoveEvent(QDragMoveEvent *);
214 216
215 void dragLeaveEvent(QDragLeaveEvent *); 217 void dragLeaveEvent(QDragLeaveEvent *);
216 218
217 void dropEvent(QDropEvent *); 219 void dropEvent(QDropEvent *);
218 220
219 void resizeEvent(QResizeEvent *); 221 void resizeEvent(QResizeEvent *);
220 222
221private: 223private:
224 QTimer* mUpdateTimer;
225 QTimer* mRepaintTimer;
226 bool mDayChanged;
222 227
223 /** returns the index of the day located at the matrix's widget (x,y) position. 228 /** returns the index of the day located at the matrix's widget (x,y) position.
224 * 229 *
225 * @param x horizontal coordinate 230 * @param x horizontal coordinate
226 * @param y vertical coordinate 231 * @param y vertical coordinate
227 */ 232 */
228 int getDayIndexFrom(int x, int y); 233 int getDayIndexFrom(int x, int y);
229 234
230 /** calculates a "shaded" color from the supplied color object. 235 /** calculates a "shaded" color from the supplied color object.
231 * (Copied from Cornelius's kdpdatebutton.cpp) 236 * (Copied from Cornelius's kdpdatebutton.cpp)
232 * 237 *
233 * @param color source based on which a shaded color should be calculated. 238 * @param color source based on which a shaded color should be calculated.
234 */ 239 */
235 QColor getShadedColor(QColor color); 240 QColor getShadedColor(QColor color);
236 241
237 /** number of days to be displayed. For now there is no support for any other number then 42. 242 /** number of days to be displayed. For now there is no support for any other number then 42.
238 so change it at your own risk :o) */ 243 so change it at your own risk :o) */
239 static const int NUMDAYS; 244 static const int NUMDAYS;
240 245
241 /** calendar instance to be queried for holidays, events, ... */ 246 /** calendar instance to be queried for holidays, events, ... */
242 Calendar *mCalendar; 247 Calendar *mCalendar;
243 248
244 /** starting date of the matrix */ 249 /** starting date of the matrix */
245 QDate startdate; 250 QDate startdate;
246 251
247 /** array of day labels to optimeize drawing performance. */ 252 /** array of day labels to optimeize drawing performance. */
248 QString *daylbls; 253 QString *daylbls;
249 254
250 /** array of days displayed to reduce memory consumption by 255 /** array of days displayed to reduce memory consumption by
251 subsequently calling QDate::addDays(). */ 256 subsequently calling QDate::addDays(). */
252 QDate *days; 257 QDate *days;
253 258
254 /** array of storing the number of events on a given day. 259 /** array of storing the number of events on a given day.
255 * used for drawing a bold font if there is at least one event on that day. 260 * used for drawing a bold font if there is at least one event on that day.
256 */ 261 */
257 int *events; 262 int *events;
258 263
259 /** stores holiday names of the days shown in the matrix. */ 264 /** stores holiday names of the days shown in the matrix. */
260 QMap<int,QString> mHolidays; 265 QMap<int,QString> mHolidays;
261 266
262 /** indey of today or -1 if today is not visible in the matrix. */ 267 /** indey of today or -1 if today is not visible in the matrix. */
263 int today; 268 int today;
264 269
265 /** index of day where dragged selection was initiated. 270 /** index of day where dragged selection was initiated.
266 used to detect "negative" timely selections */ 271 used to detect "negative" timely selections */
267 int mSelInit; 272 int mSelInit;
268 273
269 /** if mSelStart has this value it indicates that there is no 274 /** if mSelStart has this value it indicates that there is no
270 actual selection in the matrix. */ 275 actual selection in the matrix. */
271 static const int NOSELECTION; 276 static const int NOSELECTION;
272 277
273 /** index of first selected day. */ 278 /** index of first selected day. */
274 int mSelStart; 279 int mSelStart;
275 280
276 /** index of last selected day. */ 281 /** index of last selected day. */
277 int mSelEnd; 282 int mSelEnd;
278 283
279 /** dynamic tooltip to handle mouse dependent tips for each day in the matrix. */ 284 /** dynamic tooltip to handle mouse dependent tips for each day in the matrix. */
280 DynamicTip* mToolTip; 285 DynamicTip* mToolTip;
281 286
282 287
283 /** default background colour of the matrix. */ 288 /** default background colour of the matrix. */
284 QColor mDefaultBackColor; 289 QColor mDefaultBackColor;
285 290