-rw-r--r-- | korganizer/koagenda.cpp | 66 |
1 files changed, 59 insertions, 7 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp index 7e0b216..73ee5cb 100644 --- a/korganizer/koagenda.cpp +++ b/korganizer/koagenda.cpp | |||
@@ -123,116 +123,136 @@ void MarcusBains::updateLocation(bool recalculate) | |||
123 | int x = agenda->gridSpacingX()*today; | 123 | int x = agenda->gridSpacingX()*today; |
124 | bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled); | 124 | bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled); |
125 | 125 | ||
126 | oldTime = tim; | 126 | oldTime = tim; |
127 | oldToday = today; | 127 | oldToday = today; |
128 | 128 | ||
129 | if(disabled || (today<0)) { | 129 | if(disabled || (today<0)) { |
130 | hide(); mTimeBox->hide(); | 130 | hide(); mTimeBox->hide(); |
131 | return; | 131 | return; |
132 | } else { | 132 | } else { |
133 | show(); mTimeBox->show(); | 133 | show(); mTimeBox->show(); |
134 | } | 134 | } |
135 | 135 | ||
136 | if(recalculate) | 136 | if(recalculate) |
137 | setFixedSize(agenda->gridSpacingX(),1); | 137 | setFixedSize(agenda->gridSpacingX(),1); |
138 | agenda->moveChild(this, x, y); | 138 | agenda->moveChild(this, x, y); |
139 | raise(); | 139 | raise(); |
140 | 140 | ||
141 | if(recalculate) | 141 | if(recalculate) |
142 | //mTimeBox->setFont(QFont("helvetica",10)); | 142 | //mTimeBox->setFont(QFont("helvetica",10)); |
143 | mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont); | 143 | mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont); |
144 | 144 | ||
145 | mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds)); | 145 | mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds)); |
146 | mTimeBox->adjustSize(); | 146 | mTimeBox->adjustSize(); |
147 | // the -2 below is there because there is a bug in this program | 147 | // the -2 below is there because there is a bug in this program |
148 | // somewhere, where the last column of this widget is a few pixels | 148 | // somewhere, where the last column of this widget is a few pixels |
149 | // narrower than the other columns. | 149 | // narrower than the other columns. |
150 | int offs = (today==agenda->columns()-1) ? -4 : 0; | 150 | int offs = (today==agenda->columns()-1) ? -4 : 0; |
151 | agenda->moveChild(mTimeBox, | 151 | agenda->moveChild(mTimeBox, |
152 | x+agenda->gridSpacingX()-mTimeBox->width()+offs-1, | 152 | x+agenda->gridSpacingX()-mTimeBox->width()+offs-1, |
153 | y-mTimeBox->height()); | 153 | y-mTimeBox->height()); |
154 | 154 | ||
155 | mTimeBox->raise(); | 155 | mTimeBox->raise(); |
156 | //mTimeBox->setAutoMask(true); | 156 | //mTimeBox->setAutoMask(true); |
157 | minutes->start(5000,true); | 157 | minutes->start(5000,true); |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
161 | //////////////////////////////////////////////////////////////////////////// | 161 | //////////////////////////////////////////////////////////////////////////// |
162 | 162 | ||
163 | 163 | ||
164 | /* | 164 | /* |
165 | Create an agenda widget with rows rows and columns columns. | 165 | Create an agenda widget with rows rows and columns columns. |
166 | */ | 166 | */ |
167 | KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, | 167 | KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, |
168 | const char *name,WFlags f) : | 168 | const char *name,WFlags f) : |
169 | QScrollView(parent,name,f) | 169 | QScrollView(parent,name,f) |
170 | { | 170 | { |
171 | 171 | mNewItemPopup = new QPopupMenu( this ); | |
172 | connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) ); | ||
173 | QString pathString = ""; | ||
174 | if ( !KOPrefs::instance()->mToolBarMiniIcons ) { | ||
175 | if ( QApplication::desktop()->width() < 480 ) | ||
176 | pathString += "icons16/"; | ||
177 | } else | ||
178 | pathString += "iconsmini/"; | ||
179 | |||
180 | mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 ); | ||
181 | mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 ); | ||
182 | |||
172 | mColumns = columns; | 183 | mColumns = columns; |
173 | mRows = rows; | 184 | mRows = rows; |
174 | mGridSpacingY = rowSize; | 185 | mGridSpacingY = rowSize; |
175 | mAllDayMode = false; | 186 | mAllDayMode = false; |
176 | #ifndef DESKTOP_VERSION | 187 | #ifndef DESKTOP_VERSION |
177 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); | 188 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); |
178 | #endif | 189 | #endif |
179 | mHolidayMask = 0; | 190 | mHolidayMask = 0; |
180 | init(); | 191 | init(); |
181 | } | 192 | } |
182 | 193 | ||
183 | /* | 194 | /* |
184 | Create an agenda widget with columns columns and one row. This is used for | 195 | Create an agenda widget with columns columns and one row. This is used for |
185 | all-day events. | 196 | all-day events. |
186 | */ | 197 | */ |
187 | KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : | 198 | KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : |
188 | QScrollView(parent,name,f) | 199 | QScrollView(parent,name,f) |
189 | { | 200 | { |
190 | 201 | mNewItemPopup = new QPopupMenu( this ); | |
202 | connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) ); | ||
203 | QString pathString = ""; | ||
204 | if ( !KOPrefs::instance()->mToolBarMiniIcons ) { | ||
205 | if ( QApplication::desktop()->width() < 480 ) | ||
206 | pathString += "icons16/"; | ||
207 | } else | ||
208 | pathString += "iconsmini/"; | ||
209 | mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."),1 ); | ||
210 | mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 ); | ||
191 | blockResize = false; | 211 | blockResize = false; |
192 | mColumns = columns; | 212 | mColumns = columns; |
193 | mRows = 1; | 213 | mRows = 1; |
194 | //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize); | 214 | //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize); |
195 | mGridSpacingY = KOPrefs::instance()->mAllDaySize; | 215 | mGridSpacingY = KOPrefs::instance()->mAllDaySize; |
196 | mAllDayMode = true; | 216 | mAllDayMode = true; |
197 | #ifndef DESKTOP_VERSION | 217 | #ifndef DESKTOP_VERSION |
198 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); | 218 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); |
199 | #endif | 219 | #endif |
200 | mHolidayMask = 0; | 220 | mHolidayMask = 0; |
201 | init(); | 221 | init(); |
202 | } | 222 | } |
203 | 223 | ||
204 | 224 | ||
205 | KOAgenda::~KOAgenda() | 225 | KOAgenda::~KOAgenda() |
206 | { | 226 | { |
207 | if(mMarcusBains) delete mMarcusBains; | 227 | if(mMarcusBains) delete mMarcusBains; |
208 | 228 | ||
209 | } | 229 | } |
210 | 230 | ||
211 | Incidence *KOAgenda::selectedIncidence() const | 231 | Incidence *KOAgenda::selectedIncidence() const |
212 | { | 232 | { |
213 | return (mSelectedItem ? mSelectedItem->incidence() : 0); | 233 | return (mSelectedItem ? mSelectedItem->incidence() : 0); |
214 | } | 234 | } |
215 | 235 | ||
216 | 236 | ||
217 | QDate KOAgenda::selectedIncidenceDate() const | 237 | QDate KOAgenda::selectedIncidenceDate() const |
218 | { | 238 | { |
219 | return (mSelectedItem ? mSelectedItem->itemDate() : QDate()); | 239 | return (mSelectedItem ? mSelectedItem->itemDate() : QDate()); |
220 | } | 240 | } |
221 | 241 | ||
222 | 242 | ||
223 | void KOAgenda::init() | 243 | void KOAgenda::init() |
224 | { | 244 | { |
225 | #ifndef _WIN32_ | 245 | #ifndef _WIN32_ |
226 | int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase | 246 | int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase |
227 | viewport()->setWFlags ( wflags); | 247 | viewport()->setWFlags ( wflags); |
228 | #endif | 248 | #endif |
229 | mGridSpacingX = 80; | 249 | mGridSpacingX = 80; |
230 | mResizeBorderWidth = 8; | 250 | mResizeBorderWidth = 8; |
231 | mScrollBorderWidth = 8; | 251 | mScrollBorderWidth = 8; |
232 | mScrollDelay = 30; | 252 | mScrollDelay = 30; |
233 | mScrollOffset = 10; | 253 | mScrollOffset = 10; |
234 | mPaintPixmap.resize( 20,20); | 254 | mPaintPixmap.resize( 20,20); |
235 | //enableClipper(true); | 255 | //enableClipper(true); |
236 | 256 | ||
237 | // Grab key strokes for keyboard navigation of agenda. Seems to have no | 257 | // Grab key strokes for keyboard navigation of agenda. Seems to have no |
238 | // effect. Has to be fixed. | 258 | // effect. Has to be fixed. |
@@ -373,294 +393,326 @@ bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) | |||
373 | if (object != viewport()) { | 393 | if (object != viewport()) { |
374 | viewportPos = ((QWidget *)object)->mapToParent(me->pos()); | 394 | viewportPos = ((QWidget *)object)->mapToParent(me->pos()); |
375 | } else { | 395 | } else { |
376 | viewportPos = me->pos(); | 396 | viewportPos = me->pos(); |
377 | } | 397 | } |
378 | static int startX = 0; | 398 | static int startX = 0; |
379 | static int startY = 0; | 399 | static int startY = 0; |
380 | static bool block = true; | 400 | static bool block = true; |
381 | switch (me->type()) { | 401 | switch (me->type()) { |
382 | case QEvent::MouseButtonPress: | 402 | case QEvent::MouseButtonPress: |
383 | //qDebug("QEvent::MouseButtonPress: "); | 403 | //qDebug("QEvent::MouseButtonPress: "); |
384 | // kdDebug() << "koagenda: filtered button press" << endl; | 404 | // kdDebug() << "koagenda: filtered button press" << endl; |
385 | if (object != viewport()) { | 405 | if (object != viewport()) { |
386 | if (me->button() == RightButton) { | 406 | if (me->button() == RightButton) { |
387 | 407 | ||
388 | mClickedItem = (KOAgendaItem *)object; | 408 | mClickedItem = (KOAgendaItem *)object; |
389 | if (mClickedItem) { | 409 | if (mClickedItem) { |
390 | selectItem(mClickedItem); | 410 | selectItem(mClickedItem); |
391 | // emit showIncidencePopupSignal(mClickedItem->incidence()); | 411 | // emit showIncidencePopupSignal(mClickedItem->incidence()); |
392 | } | 412 | } |
393 | //mItemPopup->popup(QCursor::pos()); | 413 | //mItemPopup->popup(QCursor::pos()); |
394 | } else { | 414 | } else { |
395 | mActionItem = (KOAgendaItem *)object; | 415 | mActionItem = (KOAgendaItem *)object; |
396 | if (mActionItem) { | 416 | if (mActionItem) { |
397 | if ( mSelectionHeight > 0 ) { | 417 | if ( mSelectionHeight > 0 ) { |
398 | int selectionCellX = mSelectionCellX * mGridSpacingX; | 418 | int selectionCellX = mSelectionCellX * mGridSpacingX; |
399 | int selectionYTop = mSelectionYTop; | 419 | int selectionYTop = mSelectionYTop; |
400 | int gridSpacingX = mGridSpacingX; | 420 | int gridSpacingX = mGridSpacingX; |
401 | int selectionHeight = mSelectionHeight; | 421 | int selectionHeight = mSelectionHeight; |
402 | clearSelection(); | 422 | clearSelection(); |
403 | repaintContents( selectionCellX, selectionYTop, | 423 | repaintContents( selectionCellX, selectionYTop, |
404 | gridSpacingX, selectionHeight,false ); | 424 | gridSpacingX, selectionHeight,false ); |
405 | } | 425 | } |
406 | selectItem(mActionItem); | 426 | selectItem(mActionItem); |
407 | Incidence *incidence = mActionItem->incidence(); | 427 | Incidence *incidence = mActionItem->incidence(); |
408 | if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { | 428 | if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { |
409 | mActionItem = 0; | 429 | mActionItem = 0; |
410 | } else { | 430 | } else { |
411 | startItemAction(viewportPos); | 431 | startItemAction(viewportPos); |
412 | startX = viewportPos.x(); | 432 | startX = viewportPos.x(); |
413 | startY = viewportPos.y(); | 433 | startY = viewportPos.y(); |
414 | block = true; | 434 | block = true; |
415 | } | 435 | } |
416 | } | 436 | } |
417 | } | 437 | } |
418 | } else { | 438 | } else { |
419 | selectItem(0); | 439 | selectItem(0); |
420 | mActionItem = 0; | 440 | mActionItem = 0; |
421 | setCursor(arrowCursor); | 441 | if (me->button() == RightButton ) { |
422 | startSelectAction(viewportPos); | 442 | blockNewEvent = true; |
443 | qDebug("right "); | ||
444 | int x,y; | ||
445 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | ||
446 | int gx,gy; | ||
447 | contentsToGrid(x,y,gx,gy); | ||
448 | mStartCellX = gx; | ||
449 | mStartCellY = gy; | ||
450 | mCurrentCellX = gx; | ||
451 | mCurrentCellY = gy; | ||
452 | mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) ); | ||
453 | |||
454 | } else { | ||
455 | blockNewEvent = false; | ||
456 | setCursor(arrowCursor); | ||
457 | startSelectAction(viewportPos); | ||
458 | } | ||
423 | } | 459 | } |
424 | break; | 460 | break; |
425 | 461 | ||
426 | case QEvent::MouseButtonRelease: | 462 | case QEvent::MouseButtonRelease: |
427 | //qDebug("QEvent::MouseButtonRelease: "); | 463 | //qDebug("QEvent::MouseButtonRelease: "); |
428 | if (me->button() == RightButton && block ) { | 464 | if (me->button() == RightButton && block ) { |
429 | if (object != viewport()) { | 465 | if (object != viewport()) { |
430 | mClickedItem = (KOAgendaItem *)object; | 466 | mClickedItem = (KOAgendaItem *)object; |
431 | if (mActionItem ) { | 467 | if (mActionItem ) { |
432 | endItemAction(); | 468 | endItemAction(); |
433 | } | 469 | } |
434 | if (mClickedItem) { | 470 | if (mClickedItem) { |
435 | selectItem(mClickedItem); | 471 | selectItem(mClickedItem); |
436 | emit showIncidencePopupSignal(mClickedItem->incidence()); | 472 | emit showIncidencePopupSignal(mClickedItem->incidence()); |
437 | } | 473 | } |
438 | } | 474 | } |
439 | break; | 475 | break; |
440 | } | 476 | } |
441 | block = true; | 477 | block = true; |
442 | if (mActionItem) { | 478 | if (mActionItem) { |
443 | QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); | 479 | QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); |
444 | //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); | 480 | //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); |
445 | if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { | 481 | if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { |
446 | mScrollUpTimer.stop(); | 482 | mScrollUpTimer.stop(); |
447 | mScrollDownTimer.stop(); | 483 | mScrollDownTimer.stop(); |
448 | mActionItem->resetMove(); | 484 | mActionItem->resetMove(); |
449 | placeSubCells( mActionItem ); | 485 | placeSubCells( mActionItem ); |
450 | // emit startDragSignal( mActionItem->incidence() ); | 486 | // emit startDragSignal( mActionItem->incidence() ); |
451 | setCursor( arrowCursor ); | 487 | setCursor( arrowCursor ); |
452 | mActionItem = 0; | 488 | mActionItem = 0; |
453 | mActionType = NOP; | 489 | mActionType = NOP; |
454 | mItemMoved = 0; | 490 | mItemMoved = 0; |
455 | return true; | 491 | return true; |
456 | } | 492 | } |
457 | endItemAction(); | 493 | endItemAction(); |
458 | } else if ( mActionType == SELECT ) { | 494 | } else if ( mActionType == SELECT ) { |
459 | endSelectAction(); | 495 | if (me->button() == RightButton ) { |
496 | |||
497 | } else { | ||
498 | endSelectAction( !blockNewEvent ); | ||
499 | } | ||
460 | } | 500 | } |
461 | break; | 501 | break; |
462 | 502 | ||
463 | case QEvent::MouseMove: | 503 | case QEvent::MouseMove: |
464 | if (object != viewport()) { | 504 | if (object != viewport()) { |
465 | KOAgendaItem *moveItem = (KOAgendaItem *)object; | 505 | KOAgendaItem *moveItem = (KOAgendaItem *)object; |
466 | //qDebug("moveItem %d ",moveItem ); | 506 | //qDebug("moveItem %d ",moveItem ); |
467 | if (!moveItem->incidence()->isReadOnly() /*&& | 507 | if (!moveItem->incidence()->isReadOnly() /*&& |
468 | !moveItem->incidence()->recurrence()->doesRecur()*/ ) | 508 | !moveItem->incidence()->recurrence()->doesRecur()*/ ) |
469 | if (!mActionItem) | 509 | if (!mActionItem) |
470 | setNoActionCursor(moveItem,viewportPos); | 510 | setNoActionCursor(moveItem,viewportPos); |
471 | else { | 511 | else { |
472 | if ( block ) { | 512 | if ( block ) { |
473 | int dX, dY; | 513 | int dX, dY; |
474 | dX = startX - viewportPos.x(); | 514 | dX = startX - viewportPos.x(); |
475 | if ( dX < 0 ) | 515 | if ( dX < 0 ) |
476 | dX = -dX; | 516 | dX = -dX; |
477 | dY = viewportPos.y() - startY; | 517 | dY = viewportPos.y() - startY; |
478 | if ( dY < 0 ) | 518 | if ( dY < 0 ) |
479 | dY = -dY; | 519 | dY = -dY; |
480 | int diff = 30; | 520 | int diff = 30; |
481 | if ( QApplication::desktop()->width() < 480 ) | 521 | if ( QApplication::desktop()->width() < 480 ) |
482 | diff = 15; | 522 | diff = 15; |
483 | // qDebug(" %d %d ",dX, dY ); | 523 | // qDebug(" %d %d ",dX, dY ); |
484 | if ( dX > diff || dY > diff ) { | 524 | if ( dX > diff || dY > diff ) { |
485 | block = false; | 525 | block = false; |
486 | } | 526 | } |
487 | } | 527 | } |
488 | if ( !block ) | 528 | if ( !block ) |
489 | performItemAction(viewportPos); | 529 | performItemAction(viewportPos); |
490 | } | 530 | } |
491 | } else { | 531 | } else { |
492 | if ( mActionType == SELECT ) { | 532 | if ( mActionType == SELECT ) { |
493 | performSelectAction( viewportPos ); | 533 | performSelectAction( viewportPos ); |
494 | } | 534 | } |
495 | } | 535 | } |
496 | break; | 536 | break; |
497 | 537 | ||
498 | case QEvent::MouseButtonDblClick: | 538 | case QEvent::MouseButtonDblClick: |
499 | if (object == viewport()) { | 539 | if (object == viewport()) { |
500 | selectItem(0); | 540 | selectItem(0); |
501 | int x,y; | 541 | int x,y; |
502 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 542 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
503 | int gx,gy; | 543 | int gx,gy; |
504 | contentsToGrid(x,y,gx,gy); | 544 | contentsToGrid(x,y,gx,gy); |
505 | emit newEventSignal(gx,gy); | 545 | emit newEventSignal(gx,gy); |
506 | } else { | 546 | } else { |
507 | KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; | 547 | KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; |
508 | selectItem(doubleClickedItem); | 548 | selectItem(doubleClickedItem); |
509 | if ( KOPrefs::instance()->mEditOnDoubleClick ) | 549 | if ( KOPrefs::instance()->mEditOnDoubleClick ) |
510 | emit editIncidenceSignal(doubleClickedItem->incidence()); | 550 | emit editIncidenceSignal(doubleClickedItem->incidence()); |
511 | else | 551 | else |
512 | emit showIncidenceSignal(doubleClickedItem->incidence()); | 552 | emit showIncidenceSignal(doubleClickedItem->incidence()); |
513 | } | 553 | } |
514 | break; | 554 | break; |
515 | 555 | ||
516 | default: | 556 | default: |
517 | break; | 557 | break; |
518 | } | 558 | } |
519 | 559 | ||
520 | return true; | 560 | return true; |
521 | } | 561 | } |
522 | 562 | ||
563 | void KOAgenda::newItem( int item ) | ||
564 | { | ||
565 | qDebug("new %d ", item); | ||
566 | if ( item == 1 ) { //new event | ||
567 | newEventSignal(mStartCellX ,mStartCellY ); | ||
568 | } | ||
569 | if ( item == 2 ) { //new event | ||
570 | newTodoSignal(mStartCellX ,mStartCellY ); | ||
571 | } | ||
572 | } | ||
523 | void KOAgenda::startSelectAction(QPoint viewportPos) | 573 | void KOAgenda::startSelectAction(QPoint viewportPos) |
524 | { | 574 | { |
525 | //emit newStartSelectSignal(); | 575 | //emit newStartSelectSignal(); |
526 | 576 | ||
527 | mActionType = SELECT; | 577 | mActionType = SELECT; |
528 | 578 | ||
529 | int x,y; | 579 | int x,y; |
530 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 580 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
531 | int gx,gy; | 581 | int gx,gy; |
532 | contentsToGrid(x,y,gx,gy); | 582 | contentsToGrid(x,y,gx,gy); |
533 | 583 | ||
534 | mStartCellX = gx; | 584 | mStartCellX = gx; |
535 | mStartCellY = gy; | 585 | mStartCellY = gy; |
536 | mCurrentCellX = gx; | 586 | mCurrentCellX = gx; |
537 | mCurrentCellY = gy; | 587 | mCurrentCellY = gy; |
538 | 588 | ||
539 | // Store coordinates of old selection | 589 | // Store coordinates of old selection |
540 | int selectionX = mSelectionCellX * mGridSpacingX; | 590 | int selectionX = mSelectionCellX * mGridSpacingX; |
541 | int selectionYTop = mSelectionYTop; | 591 | int selectionYTop = mSelectionYTop; |
542 | int selectionHeight = mSelectionHeight; | 592 | int selectionHeight = mSelectionHeight; |
543 | 593 | ||
544 | // Store new selection | 594 | // Store new selection |
545 | mSelectionCellX = gx; | 595 | mSelectionCellX = gx; |
546 | mSelectionYTop = gy * mGridSpacingY; | 596 | mSelectionYTop = gy * mGridSpacingY; |
547 | mSelectionHeight = mGridSpacingY; | 597 | mSelectionHeight = mGridSpacingY; |
548 | 598 | ||
549 | // Clear old selection | 599 | // Clear old selection |
550 | repaintContents( selectionX, selectionYTop, | 600 | repaintContents( selectionX, selectionYTop, |
551 | mGridSpacingX, selectionHeight,false ); | 601 | mGridSpacingX, selectionHeight,false ); |
552 | 602 | ||
553 | // Paint new selection | 603 | // Paint new selection |
554 | // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop, | 604 | // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop, |
555 | // mGridSpacingX, mSelectionHeight ); | 605 | // mGridSpacingX, mSelectionHeight ); |
556 | } | 606 | } |
557 | 607 | ||
558 | void KOAgenda::performSelectAction(QPoint viewportPos) | 608 | void KOAgenda::performSelectAction(QPoint viewportPos) |
559 | { | 609 | { |
560 | int x,y; | 610 | int x,y; |
561 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 611 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
562 | int gx,gy; | 612 | int gx,gy; |
563 | contentsToGrid(x,y,gx,gy); | 613 | contentsToGrid(x,y,gx,gy); |
564 | 614 | ||
565 | QPoint clipperPos = clipper()-> | 615 | QPoint clipperPos = clipper()-> |
566 | mapFromGlobal(viewport()->mapToGlobal(viewportPos)); | 616 | mapFromGlobal(viewport()->mapToGlobal(viewportPos)); |
567 | 617 | ||
568 | // Scroll if cursor was moved to upper or lower end of agenda. | 618 | // Scroll if cursor was moved to upper or lower end of agenda. |
569 | if (clipperPos.y() < mScrollBorderWidth) { | 619 | if (clipperPos.y() < mScrollBorderWidth) { |
570 | mScrollUpTimer.start(mScrollDelay); | 620 | mScrollUpTimer.start(mScrollDelay); |
571 | } else if (visibleHeight() - clipperPos.y() < | 621 | } else if (visibleHeight() - clipperPos.y() < |
572 | mScrollBorderWidth) { | 622 | mScrollBorderWidth) { |
573 | mScrollDownTimer.start(mScrollDelay); | 623 | mScrollDownTimer.start(mScrollDelay); |
574 | } else { | 624 | } else { |
575 | mScrollUpTimer.stop(); | 625 | mScrollUpTimer.stop(); |
576 | mScrollDownTimer.stop(); | 626 | mScrollDownTimer.stop(); |
577 | } | 627 | } |
578 | 628 | ||
579 | if ( gy > mCurrentCellY ) { | 629 | if ( gy > mCurrentCellY ) { |
580 | mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; | 630 | mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; |
581 | 631 | ||
582 | #if 0 | 632 | #if 0 |
583 | // FIXME: Repaint only the newly selected region | 633 | // FIXME: Repaint only the newly selected region |
584 | repaintContents( mSelectionCellX * mGridSpacingX, | 634 | repaintContents( mSelectionCellX * mGridSpacingX, |
585 | mCurrentCellY + mGridSpacingY, | 635 | mCurrentCellY + mGridSpacingY, |
586 | mGridSpacingX, | 636 | mGridSpacingX, |
587 | mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY ); | 637 | mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY ); |
588 | #else | 638 | #else |
589 | repaintContents( (KOGlobals::self()->reverseLayout() ? | 639 | repaintContents( (KOGlobals::self()->reverseLayout() ? |
590 | mColumns - 1 - mSelectionCellX : mSelectionCellX) * | 640 | mColumns - 1 - mSelectionCellX : mSelectionCellX) * |
591 | mGridSpacingX, mSelectionYTop, | 641 | mGridSpacingX, mSelectionYTop, |
592 | mGridSpacingX, mSelectionHeight , false); | 642 | mGridSpacingX, mSelectionHeight , false); |
593 | #endif | 643 | #endif |
594 | 644 | ||
595 | mCurrentCellY = gy; | 645 | mCurrentCellY = gy; |
596 | } else if ( gy < mCurrentCellY ) { | 646 | } else if ( gy < mCurrentCellY ) { |
597 | if ( gy >= mStartCellY ) { | 647 | if ( gy >= mStartCellY ) { |
598 | int selectionHeight = mSelectionHeight; | 648 | int selectionHeight = mSelectionHeight; |
599 | mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; | 649 | mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; |
600 | 650 | ||
601 | repaintContents( (KOGlobals::self()->reverseLayout() ? | 651 | repaintContents( (KOGlobals::self()->reverseLayout() ? |
602 | mColumns - 1 - mSelectionCellX : mSelectionCellX) * | 652 | mColumns - 1 - mSelectionCellX : mSelectionCellX) * |
603 | mGridSpacingX, mSelectionYTop, | 653 | mGridSpacingX, mSelectionYTop, |
604 | mGridSpacingX, selectionHeight,false ); | 654 | mGridSpacingX, selectionHeight,false ); |
605 | 655 | ||
606 | mCurrentCellY = gy; | 656 | mCurrentCellY = gy; |
607 | } else { | 657 | } else { |
608 | } | 658 | } |
609 | } | 659 | } |
610 | } | 660 | } |
611 | 661 | ||
612 | void KOAgenda::endSelectAction() | 662 | void KOAgenda::endSelectAction( bool emitNewEvent ) |
613 | { | 663 | { |
614 | mActionType = NOP; | 664 | mActionType = NOP; |
615 | mScrollUpTimer.stop(); | 665 | mScrollUpTimer.stop(); |
616 | mScrollDownTimer.stop(); | 666 | mScrollDownTimer.stop(); |
617 | 667 | ||
618 | emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); | 668 | emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); |
669 | if ( emitNewEvent && mStartCellY < mCurrentCellY ) | ||
670 | emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); | ||
619 | } | 671 | } |
620 | 672 | ||
621 | void KOAgenda::startItemAction(QPoint viewportPos) | 673 | void KOAgenda::startItemAction(QPoint viewportPos) |
622 | { | 674 | { |
623 | int x,y; | 675 | int x,y; |
624 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 676 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
625 | int gx,gy; | 677 | int gx,gy; |
626 | contentsToGrid(x,y,gx,gy); | 678 | contentsToGrid(x,y,gx,gy); |
627 | 679 | ||
628 | mStartCellX = gx; | 680 | mStartCellX = gx; |
629 | mStartCellY = gy; | 681 | mStartCellY = gy; |
630 | mCurrentCellX = gx; | 682 | mCurrentCellX = gx; |
631 | mCurrentCellY = gy; | 683 | mCurrentCellY = gy; |
632 | 684 | ||
633 | if (mAllDayMode) { | 685 | if (mAllDayMode) { |
634 | int gridDistanceX = (x - gx * mGridSpacingX); | 686 | int gridDistanceX = (x - gx * mGridSpacingX); |
635 | if (gridDistanceX < mResizeBorderWidth && | 687 | if (gridDistanceX < mResizeBorderWidth && |
636 | mActionItem->cellX() == mCurrentCellX) { | 688 | mActionItem->cellX() == mCurrentCellX) { |
637 | mActionType = RESIZELEFT; | 689 | mActionType = RESIZELEFT; |
638 | setCursor(sizeHorCursor); | 690 | setCursor(sizeHorCursor); |
639 | } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && | 691 | } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && |
640 | mActionItem->cellXWidth() == mCurrentCellX) { | 692 | mActionItem->cellXWidth() == mCurrentCellX) { |
641 | mActionType = RESIZERIGHT; | 693 | mActionType = RESIZERIGHT; |
642 | setCursor(sizeHorCursor); | 694 | setCursor(sizeHorCursor); |
643 | } else { | 695 | } else { |
644 | mActionType = MOVE; | 696 | mActionType = MOVE; |
645 | mActionItem->startMove(); | 697 | mActionItem->startMove(); |
646 | setCursor(sizeAllCursor); | 698 | setCursor(sizeAllCursor); |
647 | } | 699 | } |
648 | } else { | 700 | } else { |
649 | int gridDistanceY = (y - gy * mGridSpacingY); | 701 | int gridDistanceY = (y - gy * mGridSpacingY); |
650 | bool allowResize = ( mActionItem->incidence()->type() != "Todo" ); | 702 | bool allowResize = ( mActionItem->incidence()->type() != "Todo" ); |
651 | if (allowResize && gridDistanceY < mResizeBorderWidth && | 703 | if (allowResize && gridDistanceY < mResizeBorderWidth && |
652 | mActionItem->cellYTop() == mCurrentCellY && | 704 | mActionItem->cellYTop() == mCurrentCellY && |
653 | !mActionItem->firstMultiItem()) { | 705 | !mActionItem->firstMultiItem()) { |
654 | mActionType = RESIZETOP; | 706 | mActionType = RESIZETOP; |
655 | setCursor(sizeVerCursor); | 707 | setCursor(sizeVerCursor); |
656 | } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && | 708 | } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && |
657 | mActionItem->cellYBottom() == mCurrentCellY && | 709 | mActionItem->cellYBottom() == mCurrentCellY && |
658 | !mActionItem->lastMultiItem()) { | 710 | !mActionItem->lastMultiItem()) { |
659 | mActionType = RESIZEBOTTOM; | 711 | mActionType = RESIZEBOTTOM; |
660 | setCursor(sizeVerCursor); | 712 | setCursor(sizeVerCursor); |
661 | } else { | 713 | } else { |
662 | mActionType = MOVE; | 714 | mActionType = MOVE; |
663 | mActionItem->startMove(); | 715 | mActionItem->startMove(); |
664 | setCursor(sizeAllCursor); | 716 | setCursor(sizeAllCursor); |
665 | } | 717 | } |
666 | } | 718 | } |
@@ -1615,97 +1667,97 @@ void KOAgenda::computeSizes() | |||
1615 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); | 1667 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); |
1616 | emit resizedSignal(); | 1668 | emit resizedSignal(); |
1617 | } else | 1669 | } else |
1618 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); | 1670 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); |
1619 | KOAgendaItem *item; | 1671 | KOAgendaItem *item; |
1620 | int subCellWidth; | 1672 | int subCellWidth; |
1621 | 1673 | ||
1622 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 1674 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
1623 | subCellWidth = mGridSpacingX / item->subCells(); | 1675 | subCellWidth = mGridSpacingX / item->subCells(); |
1624 | item->resize(subCellWidth,item->height()); | 1676 | item->resize(subCellWidth,item->height()); |
1625 | moveChild(item,(KOGlobals::self()->reverseLayout() ? | 1677 | moveChild(item,(KOGlobals::self()->reverseLayout() ? |
1626 | (mColumns - 1 - item->cellX()) * mGridSpacingX : | 1678 | (mColumns - 1 - item->cellX()) * mGridSpacingX : |
1627 | item->cellX() * mGridSpacingX) + | 1679 | item->cellX() * mGridSpacingX) + |
1628 | item->subCell() * subCellWidth,childY(item)); | 1680 | item->subCell() * subCellWidth,childY(item)); |
1629 | } | 1681 | } |
1630 | } | 1682 | } |
1631 | int cw = contentsWidth(); | 1683 | int cw = contentsWidth(); |
1632 | int ch = contentsHeight(); | 1684 | int ch = contentsHeight(); |
1633 | if ( mAllDayMode ) { | 1685 | if ( mAllDayMode ) { |
1634 | QPixmap* paintPixAll = KOAgendaItem::paintPixAllday(); | 1686 | QPixmap* paintPixAll = KOAgendaItem::paintPixAllday(); |
1635 | if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 ) | 1687 | if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 ) |
1636 | paintPixAll->resize( cw, ch ); | 1688 | paintPixAll->resize( cw, ch ); |
1637 | } else { | 1689 | } else { |
1638 | QPixmap* paintPix = KOAgendaItem::paintPix(); | 1690 | QPixmap* paintPix = KOAgendaItem::paintPix(); |
1639 | if ( paintPix->width() < cw || paintPix->height() < ch ) | 1691 | if ( paintPix->width() < cw || paintPix->height() < ch ) |
1640 | KOAgendaItem::resizePixmap( cw , ch ); | 1692 | KOAgendaItem::resizePixmap( cw , ch ); |
1641 | } | 1693 | } |
1642 | 1694 | ||
1643 | checkScrollBoundaries(); | 1695 | checkScrollBoundaries(); |
1644 | marcus_bains(); | 1696 | marcus_bains(); |
1645 | drawContentsToPainter(); | 1697 | drawContentsToPainter(); |
1646 | viewport()->repaint(false); | 1698 | viewport()->repaint(false); |
1647 | } | 1699 | } |
1648 | 1700 | ||
1649 | void KOAgenda::scrollUp() | 1701 | void KOAgenda::scrollUp() |
1650 | { | 1702 | { |
1651 | scrollBy(0,-mScrollOffset); | 1703 | scrollBy(0,-mScrollOffset); |
1652 | } | 1704 | } |
1653 | 1705 | ||
1654 | 1706 | ||
1655 | void KOAgenda::scrollDown() | 1707 | void KOAgenda::scrollDown() |
1656 | { | 1708 | { |
1657 | scrollBy(0,mScrollOffset); | 1709 | scrollBy(0,mScrollOffset); |
1658 | } | 1710 | } |
1659 | 1711 | ||
1660 | void KOAgenda::popupAlarm() | 1712 | void KOAgenda::popupAlarm() |
1661 | { | 1713 | { |
1662 | if (!mClickedItem) { | 1714 | if (!mClickedItem) { |
1663 | kdDebug() << "KOAgenda::popupAlarm() called without having a clicked item" << endl; | 1715 | qDebug("KOAgenda::popupAlarm() called without having a clicked item "); |
1664 | return; | 1716 | return; |
1665 | } | 1717 | } |
1666 | // TODO: deal correctly with multiple alarms | 1718 | // TODO: deal correctly with multiple alarms |
1667 | Alarm* alarm; | 1719 | Alarm* alarm; |
1668 | QPtrList<Alarm> list(mClickedItem->incidence()->alarms()); | 1720 | QPtrList<Alarm> list(mClickedItem->incidence()->alarms()); |
1669 | for(alarm=list.first();alarm;alarm=list.next()) { | 1721 | for(alarm=list.first();alarm;alarm=list.next()) { |
1670 | alarm->toggleAlarm(); | 1722 | alarm->toggleAlarm(); |
1671 | } | 1723 | } |
1672 | emit itemModified( mClickedItem , KOGlobals::EVENTEDITED ); | 1724 | emit itemModified( mClickedItem , KOGlobals::EVENTEDITED ); |
1673 | mClickedItem->paintMe( true ); | 1725 | mClickedItem->paintMe( true ); |
1674 | mClickedItem->repaint( false ); | 1726 | mClickedItem->repaint( false ); |
1675 | } | 1727 | } |
1676 | 1728 | ||
1677 | /* | 1729 | /* |
1678 | Calculates the minimum width | 1730 | Calculates the minimum width |
1679 | */ | 1731 | */ |
1680 | int KOAgenda::minimumWidth() const | 1732 | int KOAgenda::minimumWidth() const |
1681 | { | 1733 | { |
1682 | // TODO:: develop a way to dynamically determine the minimum width | 1734 | // TODO:: develop a way to dynamically determine the minimum width |
1683 | int min = 100; | 1735 | int min = 100; |
1684 | 1736 | ||
1685 | return min; | 1737 | return min; |
1686 | } | 1738 | } |
1687 | 1739 | ||
1688 | void KOAgenda::updateConfig() | 1740 | void KOAgenda::updateConfig() |
1689 | { | 1741 | { |
1690 | if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor) | 1742 | if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor) |
1691 | viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor); | 1743 | viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor); |
1692 | if ( mAllDayMode ) { | 1744 | if ( mAllDayMode ) { |
1693 | mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize; | 1745 | mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize; |
1694 | //mGridSpacingY = KOPrefs::instance()->mAllDaySize; | 1746 | //mGridSpacingY = KOPrefs::instance()->mAllDaySize; |
1695 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 ); | 1747 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 ); |
1696 | // setMaximumHeight( mGridSpacingY+1 ); | 1748 | // setMaximumHeight( mGridSpacingY+1 ); |
1697 | viewport()->repaint( false ); | 1749 | viewport()->repaint( false ); |
1698 | //setFixedHeight( mGridSpacingY+1 ); | 1750 | //setFixedHeight( mGridSpacingY+1 ); |
1699 | //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize); | 1751 | //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize); |
1700 | } | 1752 | } |
1701 | else { | 1753 | else { |
1702 | mGridSpacingY = KOPrefs::instance()->mHourSize; | 1754 | mGridSpacingY = KOPrefs::instance()->mHourSize; |
1703 | calculateWorkingHours(); | 1755 | calculateWorkingHours(); |
1704 | marcus_bains(); | 1756 | marcus_bains(); |
1705 | } | 1757 | } |
1706 | } | 1758 | } |
1707 | 1759 | ||
1708 | void KOAgenda::checkScrollBoundaries() | 1760 | void KOAgenda::checkScrollBoundaries() |
1709 | { | 1761 | { |
1710 | // Invalidate old values to force update | 1762 | // Invalidate old values to force update |
1711 | mOldLowerScrollValue = -1; | 1763 | mOldLowerScrollValue = -1; |