summaryrefslogtreecommitdiffabout
path: root/korganizer/kodaymatrix.cpp
Unidiff
Diffstat (limited to 'korganizer/kodaymatrix.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kodaymatrix.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index 9812321..ca896b5 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -167,182 +167,182 @@ void KODayMatrix::addSelectedDaysTo(DateList& selDays)
167 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) 167 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1)
168 if (mSelEnd > NUMDAYS-1) { 168 if (mSelEnd > NUMDAYS-1) {
169 for (int i = i0; i <= NUMDAYS-1; i++) { 169 for (int i = i0; i <= NUMDAYS-1; i++) {
170 selDays.append(days[i]); 170 selDays.append(days[i]);
171 } 171 }
172 for (int i = NUMDAYS; i < mSelEnd; i++) { 172 for (int i = NUMDAYS; i < mSelEnd; i++) {
173 selDays.append(days[0].addDays(i)); 173 selDays.append(days[0].addDays(i));
174 } 174 }
175 175
176 // apply normal routine to selection being entirely within matrix limits 176 // apply normal routine to selection being entirely within matrix limits
177 } else { 177 } else {
178 for (int i = i0; i <= mSelEnd; i++) { 178 for (int i = i0; i <= mSelEnd; i++) {
179 selDays.append(days[i]); 179 selDays.append(days[i]);
180 } 180 }
181 } 181 }
182} 182}
183 183
184void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 184void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
185{ 185{
186 mSelStart = startdate.daysTo(start); 186 mSelStart = startdate.daysTo(start);
187 mSelEnd = startdate.daysTo(end); 187 mSelEnd = startdate.daysTo(end);
188} 188}
189 189
190 190
191void KODayMatrix::recalculateToday() 191void KODayMatrix::recalculateToday()
192{ 192{
193 today = -1; 193 today = -1;
194 for (int i=0; i<NUMDAYS; i++) { 194 for (int i=0; i<NUMDAYS; i++) {
195 events[i] = 0; 195 events[i] = 0;
196 days[i] = startdate.addDays(i); 196 days[i] = startdate.addDays(i);
197 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 197 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
198 198
199 // if today is in the currently displayed month, hilight today 199 // if today is in the currently displayed month, hilight today
200 if (days[i].year() == QDate::currentDate().year() && 200 if (days[i].year() == QDate::currentDate().year() &&
201 days[i].month() == QDate::currentDate().month() && 201 days[i].month() == QDate::currentDate().month() &&
202 days[i].day() == QDate::currentDate().day()) { 202 days[i].day() == QDate::currentDate().day()) {
203 today = i; 203 today = i;
204 } 204 }
205 } 205 }
206 // qDebug(QString("Today is visible at %1.").arg(today)); 206 // qDebug(QString("Today is visible at %1.").arg(today));
207} 207}
208 208
209void KODayMatrix::updateView() 209void KODayMatrix::updateView()
210{ 210{
211 updateView(startdate); 211 updateView(startdate);
212} 212}
213void KODayMatrix::repaintViewTimed() 213void KODayMatrix::repaintViewTimed()
214{ 214{
215 //qDebug("KODayMatrix::repaintViewTimed "); 215 qDebug("KODayMatrix::repaintViewTimed ");
216 mRepaintTimer->stop(); 216 mRepaintTimer->stop();
217 repaint(false); 217 repaint(false);
218} 218}
219void KODayMatrix::updateViewTimed() 219void KODayMatrix::updateViewTimed()
220{ 220{
221 221
222 mUpdateTimer->stop(); 222 mUpdateTimer->stop();
223 //qDebug("KODayMatrix::updateView(QDate actdate) %d", ++iii ); 223 qDebug("KODayMatrix::updateView(QDate actdate)");
224 for(int i = 0; i < NUMDAYS; i++) { 224 for(int i = 0; i < NUMDAYS; i++) {
225 225
226 // if events are set for the day then remember to draw it bold 226 // if events are set for the day then remember to draw it bold
227 QPtrList<Event> eventlist = mCalendar->events(days[i]); 227 QPtrList<Event> eventlist = mCalendar->events(days[i]);
228 Event *event; 228 Event *event;
229 int numEvents = eventlist.count(); 229 int numEvents = eventlist.count();
230 230
231 for(event=eventlist.first();event != 0;event=eventlist.next()) { 231 for(event=eventlist.first();event != 0;event=eventlist.next()) {
232 ushort recurType = event->recurrence()->doesRecur(); 232 ushort recurType = event->recurrence()->doesRecur();
233 233
234 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 234 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
235 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 235 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
236 numEvents--; 236 numEvents--;
237 } 237 }
238 } 238 }
239 events[i] = numEvents; 239 events[i] = numEvents;
240 240
241 //if it is a holy day then draw it red. Sundays are consider holidays, too 241 //if it is a holy day then draw it red. Sundays are consider holidays, too
242#ifndef KORG_NOPLUGINS 242#ifndef KORG_NOPLUGINS
243 QString holiStr = KOCore::self()->holiday(days[i]); 243 QString holiStr = KOCore::self()->holiday(days[i]);
244#else 244#else
245 QString holiStr = QString::null; 245 QString holiStr = QString::null;
246#endif 246#endif
247 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || 247 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) ||
248 !holiStr.isEmpty()) { 248 !holiStr.isEmpty()) {
249 if (holiStr.isNull()) holiStr = ""; 249 if (holiStr.isNull()) holiStr = "";
250 mHolidays[i] = holiStr; 250 mHolidays[i] = holiStr;
251 251
252 } else { 252 } else {
253 mHolidays[i] = QString::null; 253 mHolidays[i] = QString::null;
254 } 254 }
255 } 255 }
256 if ( ! mPendingUpdateBeforeRepaint ) 256 if ( ! mPendingUpdateBeforeRepaint )
257 repaint(false); 257 repaint(false);
258 } 258 }
259void KODayMatrix::updateView(QDate actdate) 259void KODayMatrix::updateView(QDate actdate)
260{ 260{
261 261
262 if ( ! actdate.isValid() ) { 262 if ( ! actdate.isValid() ) {
263 //qDebug("date not valid "); 263 //qDebug("date not valid ");
264 return; 264 return;
265 } 265 }
266 mDayChanged = false; 266 mDayChanged = false;
267 //flag to indicate if the starting day of the matrix has changed by this call 267 //flag to indicate if the starting day of the matrix has changed by this call
268 //mDayChanged = false; 268 //mDayChanged = false;
269 // if a new startdate is to be set then apply Cornelius's calculation 269 // if a new startdate is to be set then apply Cornelius's calculation
270 // of the first day to be shown 270 // of the first day to be shown
271 if (actdate != startdate) { 271 if (actdate != startdate) {
272 // reset index of selection according to shift of starting date from startdate to actdate 272 // reset index of selection according to shift of starting date from startdate to actdate
273 if (mSelStart != NOSELECTION) { 273 if (mSelStart != NOSELECTION) {
274 int tmp = actdate.daysTo(startdate); 274 int tmp = actdate.daysTo(startdate);
275 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; 275 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl;
276 // shift selection if new one would be visible at least partly ! 276 // shift selection if new one would be visible at least partly !
277 277
278 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { 278 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) {
279 // nested if is required for next X display pushed from a different month - correction required 279 // nested if is required for next X display pushed from a different month - correction required
280 // otherwise, for month forward and backward, it must be avoided 280 // otherwise, for month forward and backward, it must be avoided
281 if( mSelStart > NUMDAYS || mSelStart < 0 ) 281 if( mSelStart > NUMDAYS || mSelStart < 0 )
282 mSelStart = mSelStart + tmp; 282 mSelStart = mSelStart + tmp;
283 if( mSelEnd > NUMDAYS || mSelEnd < 0 ) 283 if( mSelEnd > NUMDAYS || mSelEnd < 0 )
284 mSelEnd = mSelEnd + tmp; 284 mSelEnd = mSelEnd + tmp;
285 } 285 }
286 } 286 }
287 startdate = actdate; 287 startdate = actdate;
288 mDayChanged = true; 288 mDayChanged = true;
289 recalculateToday(); 289 recalculateToday();
290 } 290 }
291 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); 291 qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() );
292 if ( !isVisible() ) { 292 if ( !isVisible() ) {
293 mPendingUpdateBeforeRepaint = true; 293 mPendingUpdateBeforeRepaint = true;
294 } else { 294 } else {
295#ifdef DESKTOP_VERSION 295#ifdef DESKTOP_VERSION
296 mRepaintTimer->start( 250 ); 296 //mRepaintTimer->start( 250 );
297 mUpdateTimer->start( 2000 ); 297 mUpdateTimer->start( 250 );
298#else 298#else
299 mRepaintTimer->start( 350 ); 299 mRepaintTimer->start( 350 );
300 mUpdateTimer->start( 4000 ); 300 mUpdateTimer->start( 2000 );
301#endif 301#endif
302 } 302 }
303} 303}
304 304
305const QDate& KODayMatrix::getDate(int offset) 305const QDate& KODayMatrix::getDate(int offset)
306{ 306{
307 if (offset < 0 || offset > NUMDAYS-1) { 307 if (offset < 0 || offset > NUMDAYS-1) {
308 qDebug("Wrong offset2 "); 308 qDebug("Wrong offset2 ");
309 return days[0]; 309 return days[0];
310 } 310 }
311 return days[offset]; 311 return days[offset];
312} 312}
313 313
314QString KODayMatrix::getHolidayLabel(int offset) 314QString KODayMatrix::getHolidayLabel(int offset)
315{ 315{
316 if (offset < 0 || offset > NUMDAYS-1) { 316 if (offset < 0 || offset > NUMDAYS-1) {
317 qDebug("Wrong offset1 "); 317 qDebug("Wrong offset1 ");
318 return 0; 318 return 0;
319 } 319 }
320 return mHolidays[offset]; 320 return mHolidays[offset];
321} 321}
322 322
323int KODayMatrix::getDayIndexFrom(int x, int y) 323int KODayMatrix::getDayIndexFrom(int x, int y)
324{ 324{
325 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 325 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
326 6 - x/daysize.width() : x/daysize.width()); 326 6 - x/daysize.width() : x/daysize.width());
327} 327}
328 328
329// ---------------------------------------------------------------------------- 329// ----------------------------------------------------------------------------
330// M O U S E E V E N T H A N D L I N G 330// M O U S E E V E N T H A N D L I N G
331// ---------------------------------------------------------------------------- 331// ----------------------------------------------------------------------------
332 332
333void KODayMatrix::mousePressEvent (QMouseEvent* e) 333void KODayMatrix::mousePressEvent (QMouseEvent* e)
334{ 334{
335 mSelStart = getDayIndexFrom(e->x(), e->y()); 335 mSelStart = getDayIndexFrom(e->x(), e->y());
336 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; 336 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
337 mSelInit = mSelStart; 337 mSelInit = mSelStart;
338} 338}
339 339
340void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) 340void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
341{ 341{
342 342
343 int tmp = getDayIndexFrom(e->x(), e->y()); 343 int tmp = getDayIndexFrom(e->x(), e->y());
344 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 344 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
345 345
346 if (mSelInit > tmp) { 346 if (mSelInit > tmp) {
347 mSelEnd = mSelInit; 347 mSelEnd = mSelInit;
348 if (tmp != mSelStart) { 348 if (tmp != mSelStart) {
@@ -444,98 +444,98 @@ void KODayMatrix::dropEvent(QDropEvent *e)
444 Event *event = factory.createDrop(e); 444 Event *event = factory.createDrop(e);
445 445
446 if (event) { 446 if (event) {
447 e->acceptAction(); 447 e->acceptAction();
448 448
449 Event *existingEvent = mCalendar->event(event->uid()); 449 Event *existingEvent = mCalendar->event(event->uid());
450 450
451 if(existingEvent) { 451 if(existingEvent) {
452 // uniquify event 452 // uniquify event
453 event->recreate(); 453 event->recreate();
454/* 454/*
455 KMessageBox::sorry(this, 455 KMessageBox::sorry(this,
456 i18n("Event already exists in this calendar."), 456 i18n("Event already exists in this calendar."),
457 i18n("Drop Event")); 457 i18n("Drop Event"));
458 delete event; 458 delete event;
459 return; 459 return;
460*/ 460*/
461 } 461 }
462// kdDebug() << "Drop new Event" << endl; 462// kdDebug() << "Drop new Event" << endl;
463 // Adjust date 463 // Adjust date
464 QDateTime start = event->dtStart(); 464 QDateTime start = event->dtStart();
465 QDateTime end = event->dtEnd(); 465 QDateTime end = event->dtEnd();
466 int duration = start.daysTo(end); 466 int duration = start.daysTo(end);
467 int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); 467 int idx = getDayIndexFrom(e->pos().x(), e->pos().y());
468 468
469 start.setDate(days[idx]); 469 start.setDate(days[idx]);
470 end.setDate(days[idx].addDays(duration)); 470 end.setDate(days[idx].addDays(duration));
471 471
472 event->setDtStart(start); 472 event->setDtStart(start);
473 event->setDtEnd(end); 473 event->setDtEnd(end);
474 mCalendar->addEvent(event); 474 mCalendar->addEvent(event);
475 475
476 emit eventDropped(event); 476 emit eventDropped(event);
477 } else { 477 } else {
478// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; 478// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl;
479 e->ignore(); 479 e->ignore();
480 } 480 }
481#endif 481#endif
482} 482}
483 483
484// ---------------------------------------------------------------------------- 484// ----------------------------------------------------------------------------
485// P A I N T E V E N T H A N D L I N G 485// P A I N T E V E N T H A N D L I N G
486// ---------------------------------------------------------------------------- 486// ----------------------------------------------------------------------------
487 487
488void KODayMatrix::paintEvent(QPaintEvent * pevent) 488void KODayMatrix::paintEvent(QPaintEvent * pevent)
489{ 489{
490//kdDebug() << "KODayMatrix::paintEvent() BEGIN" << endl; 490//kdDebug() << "KODayMatrix::paintEvent() BEGIN" << endl;
491 if ( mPendingUpdateBeforeRepaint ) { 491 if ( mPendingUpdateBeforeRepaint ) {
492 updateViewTimed(); 492 updateViewTimed();
493 mPendingUpdateBeforeRepaint = false; 493 mPendingUpdateBeforeRepaint = false;
494 } 494 }
495 QPainter p(this); 495 QPainter p(this);
496 496
497 QRect sz = frameRect(); 497 QRect sz = frameRect();
498 int dheight = daysize.height(); 498 int dheight = daysize.height();
499 int dwidth = daysize.width(); 499 int dwidth = daysize.width();
500 int row,col; 500 int row,col;
501 int selw, selh; 501 int selw, selh;
502 bool isRTL = KOGlobals::self()->reverseLayout(); 502 bool isRTL = KOGlobals::self()->reverseLayout();
503 503
504 // draw background and topleft frame 504 // draw background and topleft frame
505 p.fillRect(pevent->rect(), mDefaultBackColor); 505 p.fillRect(pevent->rect(), mDefaultBackColor);
506 p.setPen(mDefaultTextColor); 506 p.setPen(mDefaultTextColor);
507 p.drawRect(0, 0, sz.width()+1, sz.height()+1); 507 p.drawRect(0, 0, sz.width()+1, sz.height()+1);
508 508
509 // draw selected days with highlighted background color 509 // draw selected days with highlighted background color
510 if (mSelStart != NOSELECTION) { 510 if (mSelStart != NOSELECTION) {
511 511
512 row = mSelStart/7; 512 row = mSelStart/7;
513 col = mSelStart -row*7; 513 col = mSelStart -row*7;
514 QColor selcol = KOPrefs::instance()->mHighlightColor; 514 QColor selcol = KOPrefs::instance()->mHighlightColor;
515 515
516 if (row == mSelEnd/7) { 516 if (row == mSelEnd/7) {
517 // Single row selection 517 // Single row selection
518 p.fillRect(isRTL ? (7 - (mSelEnd-mSelStart+1) - col)*dwidth : col*dwidth, 518 p.fillRect(isRTL ? (7 - (mSelEnd-mSelStart+1) - col)*dwidth : col*dwidth,
519 row*dheight, (mSelEnd-mSelStart+1)*dwidth, dheight, selcol); 519 row*dheight, (mSelEnd-mSelStart+1)*dwidth, dheight, selcol);
520 } else { 520 } else {
521 // draw first row to the right 521 // draw first row to the right
522 p.fillRect(isRTL ? 0 : col*dwidth, row*dheight, (7-col)*dwidth, 522 p.fillRect(isRTL ? 0 : col*dwidth, row*dheight, (7-col)*dwidth,
523 dheight, selcol); 523 dheight, selcol);
524 // draw full block till last line 524 // draw full block till last line
525 selh = mSelEnd/7-row; 525 selh = mSelEnd/7-row;
526 if (selh > 1) { 526 if (selh > 1) {
527 p.fillRect(0, (row+1)*dheight, 7*dwidth, (selh-1)*dheight,selcol); 527 p.fillRect(0, (row+1)*dheight, 7*dwidth, (selh-1)*dheight,selcol);
528 } 528 }
529 // draw last block from left to mSelEnd 529 // draw last block from left to mSelEnd
530 selw = mSelEnd-7*(mSelEnd/7)+1; 530 selw = mSelEnd-7*(mSelEnd/7)+1;
531 p.fillRect(isRTL ? (7-selw)*dwidth : 0, (row+selh)*dheight, 531 p.fillRect(isRTL ? (7-selw)*dwidth : 0, (row+selh)*dheight,
532 selw*dwidth, dheight, selcol); 532 selw*dwidth, dheight, selcol);
533 } 533 }
534 } 534 }
535 535
536 // iterate over all days in the matrix and draw the day label in appropriate colors 536 // iterate over all days in the matrix and draw the day label in appropriate colors
537 QColor actcol = mDefaultTextColorShaded; 537 QColor actcol = mDefaultTextColorShaded;
538 p.setPen(actcol); 538 p.setPen(actcol);
539 QPen tmppen; 539 QPen tmppen;
540 for(int i = 0; i < NUMDAYS; i++) { 540 for(int i = 0; i < NUMDAYS; i++) {
541 row = i/7; 541 row = i/7;