summaryrefslogtreecommitdiffabout
path: root/korganizer/koagenda.cpp
Unidiff
Diffstat (limited to 'korganizer/koagenda.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagenda.cpp66
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
@@ -159,44 +159,64 @@ void MarcusBains::updateLocation(bool recalculate)
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*/
167KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, 167KOAgenda::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*/
187KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : 198KOAgenda::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}
@@ -409,26 +429,42 @@ bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me)
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) {
@@ -447,25 +483,29 @@ bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me)
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 {
@@ -511,24 +551,34 @@ bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me)
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
563void 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}
523void KOAgenda::startSelectAction(QPoint viewportPos) 573void 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;
@@ -600,31 +650,33 @@ void KOAgenda::performSelectAction(QPoint viewportPos)
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
612void KOAgenda::endSelectAction() 662void 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
621void KOAgenda::startItemAction(QPoint viewportPos) 673void 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;
@@ -1651,25 +1703,25 @@ void KOAgenda::scrollUp()
1651 scrollBy(0,-mScrollOffset); 1703 scrollBy(0,-mScrollOffset);
1652} 1704}
1653 1705
1654 1706
1655void KOAgenda::scrollDown() 1707void KOAgenda::scrollDown()
1656{ 1708{
1657 scrollBy(0,mScrollOffset); 1709 scrollBy(0,mScrollOffset);
1658} 1710}
1659 1711
1660void KOAgenda::popupAlarm() 1712void 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}