-rw-r--r-- | korganizer/koagenda.cpp | 264 |
1 files changed, 35 insertions, 229 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp index 114ed75..355f4bb 100644 --- a/korganizer/koagenda.cpp +++ b/korganizer/koagenda.cpp @@ -429,105 +429,98 @@ bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) dY = -dY; if ( dX > blockmoveDist || dY > blockmoveDist ) { mNewItemPopup->hide(); } } return true; } if ( object == mAllAgendaPopup ) { //qDebug(" mAllAgendaPopup "); if ( me->type() == QEvent::MouseButtonRelease ) { mAllAgendaPopup->removeEventFilter( this ); int dX = me->globalPos().x() - mPopupPos.x();; if ( dX < 0 ) dX = -dX; int dY = me->globalPos().y() - mPopupPos.y(); if ( dY < 0 ) dY = -dY; if ( dX > blockmoveDist || dY > blockmoveDist ) { mAllAgendaPopup->hide(); } } return true; } QPoint viewportPos; if (object != viewport()) { viewportPos = ((QWidget *)object)->mapToParent(me->pos()); } else { viewportPos = me->pos(); } switch (me->type()) { case QEvent::MouseButtonPress: if (me->button() == LeftButton) { mPopupTimer->start( 600 ); mLeftMouseDown = true; } blockMoving = true; startX = viewportPos.x(); startY = viewportPos.y(); mPopupPos = me->globalPos(); if (object != viewport()) { mPopupItem = (KOAgendaItem *)object; mPopupKind = 1; if (me->button() == RightButton) { popupMenu(); } else if (me->button() == LeftButton) { mActionItem = (KOAgendaItem *)object; if (mActionItem) { - if ( mSelectionHeight > 0 ) { - int selectionCellX = mSelectionCellX * mGridSpacingX; - int selectionYTop = mSelectionYTop; - int gridSpacingX = mGridSpacingX; - int selectionHeight = mSelectionHeight; - clearSelection(); - repaintContents( selectionCellX, selectionYTop, - gridSpacingX, selectionHeight,false ); - } + emit signalClearSelection(); + slotClearSelection(); selectItem(mActionItem); Incidence *incidence = mActionItem->incidence(); if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { mActionItem = 0; } else { startItemAction(viewportPos); } } } } else { // ---------- viewport() mPopupItem = 0; mPopupKind = 2; selectItem(0); mActionItem = 0; if (me->button() == RightButton) { int x,y; viewportToContents(viewportPos.x(),viewportPos.y(),x,y); int gx,gy; contentsToGrid(x,y,gx,gy); mCurrentCellX = gx; mCurrentCellY = gy; mStartCellX = gx; mStartCellY = gy; popupMenu(); } else if (me->button() == LeftButton) { setCursor(arrowCursor); startSelectAction(viewportPos); } } break; case QEvent::MouseButtonRelease: if (me->button() == LeftButton ) { mPopupTimer->stop(); } if (object != viewport()) { if (me->button() == LeftButton && mLeftMouseDown) { if (mActionItem) { QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { mScrollUpTimer.stop(); mScrollDownTimer.stop(); mActionItem->resetMove(); placeSubCells( mActionItem ); // emit startDragSignal( mActionItem->incidence() ); setCursor( arrowCursor ); mActionItem = 0; @@ -565,387 +558,210 @@ bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) //qDebug("%d %d %d ", dX, dY , blockmoveDist ); if ( dX > blockmoveDist || dY > blockmoveDist ) { blockMoving = false; } } if ( ! blockMoving ) mPopupTimer->stop(); if (object != viewport()) { KOAgendaItem *moveItem = (KOAgendaItem *)object; if (!moveItem->incidence()->isReadOnly() ) { if (!mActionItem) setNoActionCursor(moveItem,viewportPos); else { if ( !blockMoving ) performItemAction(viewportPos); } } } else { // ---------- viewport() mPopupPos = viewport()->mapToGlobal( me->pos() ); if ( mActionType == SELECT ) { performSelectAction( viewportPos ); } } break; case QEvent::MouseButtonDblClick: mPopupTimer->stop(); if (object == viewport()) { selectItem(0); int x,y; viewportToContents(viewportPos.x(),viewportPos.y(),x,y); int gx,gy; contentsToGrid(x,y,gx,gy); emit newEventSignal(gx,gy); } else { KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; selectItem(doubleClickedItem); if ( KOPrefs::instance()->mEditOnDoubleClick ) emit editIncidenceSignal(doubleClickedItem->incidence()); else emit showIncidenceSignal(doubleClickedItem->incidence()); } break; default: break; } return true; -#if 0 - //qDebug("KOAgenda::eventFilter_mous "); - QPoint viewportPos; - if (object != viewport()) { - viewportPos = ((QWidget *)object)->mapToParent(me->pos()); - } else { - viewportPos = me->pos(); - } - static int startX = 0; - static int startY = 0; - static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); - static bool blockMoving = true; - static bool leftMouseDown = false; - bool rightButtonPressed = false; - switch (me->type()) { - case QEvent::MouseButtonPress: - if (me->button() == LeftButton) { - leftMouseDown = true; - } - else if (me->button() == RightButton) { - leftMouseDown = false; - } - blockMoving = true; - startX = viewportPos.x(); - startY = viewportPos.y(); - if (object != viewport()) { // item clicked ************** - if (me->button() == RightButton) { - leftMouseDown = false; - mClickedItem = (KOAgendaItem *)object; - if (mActionItem ) { - endItemAction(); - } - if (mClickedItem) { - selectItem(mClickedItem); - emit showIncidencePopupSignal(mClickedItem->incidence()); - } - return true; - } else if (me->button() == LeftButton) { - mActionItem = (KOAgendaItem *)object; - if (mActionItem) { - if ( mSelectionHeight > 0 ) { - int selectionCellX = mSelectionCellX * mGridSpacingX; - int selectionYTop = mSelectionYTop; - int gridSpacingX = mGridSpacingX; - int selectionHeight = mSelectionHeight; - clearSelection(); - repaintContents( selectionCellX, selectionYTop, - gridSpacingX, selectionHeight,false ); - } - selectItem(mActionItem); - Incidence *incidence = mActionItem->incidence(); - if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { - mActionItem = 0; - } else { - startItemAction(viewportPos); - } - } - } - } else { // ---------- viewport() - selectItem(0); - mActionItem = 0; - if (me->button() == LeftButton ) { - setCursor(arrowCursor); - startSelectAction(viewportPos); - } else if (me->button() == RightButton ) { - setCursor(arrowCursor); - if ( leftMouseDown ) { // we have a simulated right click - clear left mouse action - endSelectAction( false ); // do not emit new event signal - leftMouseDown = false; // no more leftMouse computation - } - int x,y; - viewportToContents(viewportPos.x(),viewportPos.y(),x,y); - int gx,gy; - contentsToGrid(x,y,gx,gy); - mCurrentCellX = gx; - mCurrentCellY = gy; - mStartCellX = gx; - mStartCellY = gy; - mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) ); - } - } - break; - - case QEvent::MouseButtonRelease: - - if (object != viewport()) { - if (me->button() == LeftButton && leftMouseDown) { - if (mActionItem) { - QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); - //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); - if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { - mScrollUpTimer.stop(); - mScrollDownTimer.stop(); - mActionItem->resetMove(); - placeSubCells( mActionItem ); - // emit startDragSignal( mActionItem->incidence() ); - setCursor( arrowCursor ); - mActionItem = 0; - mActionType = NOP; - mItemMoved = 0; - leftMouseDown = false; - return true; - } - endItemAction(); - } - } - - } else { // ---------- viewport() - if (me->button() == LeftButton && leftMouseDown ) { //left click - endSelectAction( true ); // emit new event signal - } - } - if (me->button() == LeftButton) - leftMouseDown = false; - - break; - case QEvent::MouseMove: - if ( !leftMouseDown ) - return true; - if ( blockMoving ) { - int dX, dY; - dX = startX - viewportPos.x(); - if ( dX < 0 ) - dX = -dX; - dY = viewportPos.y() - startY; - if ( dY < 0 ) - dY = -dY; - //qDebug("%d %d %d ", dX, dY , blockmoveDist ); - if ( dX > blockmoveDist || dY > blockmoveDist ) { - blockMoving = false; - } - } - if (object != viewport()) { - KOAgendaItem *moveItem = (KOAgendaItem *)object; - if (!moveItem->incidence()->isReadOnly() ) { - if (!mActionItem) - setNoActionCursor(moveItem,viewportPos); - else { - if ( !blockMoving ) - performItemAction(viewportPos); - } - } - } else { // ---------- viewport() - if ( mActionType == SELECT ) { - performSelectAction( viewportPos ); - } - } - break; - - case QEvent::MouseButtonDblClick: - blockMoving = false; - leftMouseDown = false; - if (object == viewport()) { - selectItem(0); - int x,y; - viewportToContents(viewportPos.x(),viewportPos.y(),x,y); - int gx,gy; - contentsToGrid(x,y,gx,gy); - emit newEventSignal(gx,gy); - } else { - KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; - selectItem(doubleClickedItem); - if ( KOPrefs::instance()->mEditOnDoubleClick ) - emit editIncidenceSignal(doubleClickedItem->incidence()); - else - emit showIncidenceSignal(doubleClickedItem->incidence()); - } - break; - - default: - break; - } - return true; -#endif } void KOAgenda::newItem( int item ) { if ( item == 1 ) { //new event newEventSignal(mStartCellX ,mStartCellY ); } else if ( item == 2 ) { //new event newTodoSignal(mStartCellX ,mStartCellY ); } else { emit showDateView( item, mStartCellX ); // 3Day view // 4Week view // 5Month view // 6Journal view } } +void KOAgenda::slotClearSelection() +{ + if (mSelectionHeight) { + int selectionX = mSelectionCellX * mGridSpacingX; + int top = mSelectionYTop - 2 *mGridSpacingY; + int hei = mSelectionHeight + 4 *mGridSpacingY; + clearSelection(); + repaintContents( selectionX, top, + mGridSpacingX, hei ,false ); + } + +} void KOAgenda::startSelectAction(QPoint viewportPos) { - //emit newStartSelectSignal(); + + emit signalClearSelection(); + slotClearSelection(); - mActionType = SELECT; + mActionType = SELECT; - int x,y; - viewportToContents(viewportPos.x(),viewportPos.y(),x,y); - int gx,gy; - contentsToGrid(x,y,gx,gy); + int x,y; + viewportToContents(viewportPos.x(),viewportPos.y(),x,y); + int gx,gy; + contentsToGrid(x,y,gx,gy); - mStartCellX = gx; - mStartCellY = gy; - mCurrentCellX = gx; - mCurrentCellY = gy; - - // Store coordinates of old selection - int selectionX = mSelectionCellX * mGridSpacingX; - int selectionYTop = mSelectionYTop; - int selectionHeight = mSelectionHeight; + mStartCellX = gx; + mStartCellY = gy; + mCurrentCellX = gx; + mCurrentCellY = gy; - // Store new selection - mSelectionCellX = gx; - mSelectionYTop = gy * mGridSpacingY; - mSelectionHeight = mGridSpacingY; + // Store new selection + mSelectionCellX = gx; + mSelectionYTop = gy * mGridSpacingY; + mSelectionHeight = mGridSpacingY; - // Clear old selection - repaintContents( selectionX, selectionYTop, - mGridSpacingX, selectionHeight,false ); - - // Paint new selection - // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop, - // mGridSpacingX, mSelectionHeight ); + // Paint new selection + repaintContents( mSelectionCellX * mGridSpacingX+1, mSelectionYTop, + mGridSpacingX-1, mSelectionHeight ); } void KOAgenda::performSelectAction(QPoint viewportPos) { int x,y; viewportToContents(viewportPos.x(),viewportPos.y(),x,y); int gx,gy; contentsToGrid(x,y,gx,gy); QPoint clipperPos = clipper()-> mapFromGlobal(viewport()->mapToGlobal(viewportPos)); // Scroll if cursor was moved to upper or lower end of agenda. if (clipperPos.y() < mScrollBorderWidth) { mScrollUpTimer.start(mScrollDelay); } else if (visibleHeight() - clipperPos.y() < mScrollBorderWidth) { mScrollDownTimer.start(mScrollDelay); } else { mScrollUpTimer.stop(); mScrollDownTimer.stop(); } if ( gy > mCurrentCellY ) { mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; -#if 0 - // FIXME: Repaint only the newly selected region - repaintContents( mSelectionCellX * mGridSpacingX, - mCurrentCellY + mGridSpacingY, - mGridSpacingX, - mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY ); -#else + repaintContents( (KOGlobals::self()->reverseLayout() ? mColumns - 1 - mSelectionCellX : mSelectionCellX) * mGridSpacingX, mSelectionYTop, mGridSpacingX, mSelectionHeight , false); -#endif mCurrentCellY = gy; } else if ( gy < mCurrentCellY ) { if ( gy >= mStartCellY ) { int selectionHeight = mSelectionHeight; mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; repaintContents( (KOGlobals::self()->reverseLayout() ? mColumns - 1 - mSelectionCellX : mSelectionCellX) * mGridSpacingX, mSelectionYTop, mGridSpacingX, selectionHeight,false ); mCurrentCellY = gy; } else { } } } void KOAgenda::endSelectAction( bool emitNewEvent ) { mActionType = NOP; mScrollUpTimer.stop(); mScrollDownTimer.stop(); emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); if ( emitNewEvent && mStartCellY < mCurrentCellY ) { - qDebug("ew event signal "); emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); } } void KOAgenda::startItemAction(QPoint viewportPos) { int x,y; viewportToContents(viewportPos.x(),viewportPos.y(),x,y); int gx,gy; contentsToGrid(x,y,gx,gy); mStartCellX = gx; mStartCellY = gy; mCurrentCellX = gx; mCurrentCellY = gy; if (mAllDayMode) { int gridDistanceX = (x - gx * mGridSpacingX); if (gridDistanceX < mResizeBorderWidth && mActionItem->cellX() == mCurrentCellX) { mActionType = RESIZELEFT; setCursor(sizeHorCursor); } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && mActionItem->cellXWidth() == mCurrentCellX) { mActionType = RESIZERIGHT; setCursor(sizeHorCursor); } else { mActionType = MOVE; mActionItem->startMove(); setCursor(sizeAllCursor); } } else { int gridDistanceY = (y - gy * mGridSpacingY); bool allowResize = ( mActionItem->incidence()->type() != "Todo" ); if (allowResize && gridDistanceY < mResizeBorderWidth && mActionItem->cellYTop() == mCurrentCellY && !mActionItem->firstMultiItem()) { mActionType = RESIZETOP; setCursor(sizeVerCursor); } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && mActionItem->cellYBottom() == mCurrentCellY && !mActionItem->lastMultiItem()) { mActionType = RESIZEBOTTOM; setCursor(sizeVerCursor); } else { mActionType = MOVE; mActionItem->startMove(); setCursor(sizeAllCursor); @@ -1055,107 +871,97 @@ void KOAgenda::performItemAction(QPoint viewportPos) if (mCurrentCellX <= mActionItem->cellXWidth()) { mActionItem->expandLeft(gx - mCurrentCellX); mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), mActionItem->height()); int x,y; gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); moveChild(mActionItem,x,childY(mActionItem)); } } else if (mActionType == RESIZERIGHT) { if (mCurrentCellX >= mActionItem->cellX()) { mActionItem->expandRight(gx - mCurrentCellX); mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), mActionItem->height()); } } mCurrentCellX = gx; mCurrentCellY = gy; } } void KOAgenda::endItemAction() { if ( mItemMoved ) { KOAgendaItem *placeItem = mActionItem->firstMultiItem(); if ( !placeItem ) { placeItem = mActionItem; } if ( placeItem->incidence()->recurrence()->doesRecur() ) { Incidence* oldInc = placeItem->incidence(); placeItem->recreateIncidence(); emit addToCalSignal(placeItem->incidence(), oldInc ); } int type = mActionType; if ( mAllDayMode ) type = -1; KOAgendaItem *modifiedItem = placeItem; //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */); QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems(); KOAgendaItem *item; if ( placeItem->incidence()->type() == "Todo" ) { mSelectedItem = 0; //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth()); modifiedItem->mLastMoveXPos = mCurrentCellX; emit itemModified( modifiedItem, mActionType ); } else { -#if 0 - for ( item=oldconflictItems.first(); item != 0; - item=oldconflictItems.next() ) { - placeSubCells(item); - } - while ( placeItem ) { - //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); - placeSubCells( placeItem ); - placeItem = placeItem->nextMultiItem(); - } -#endif + globalFlagBlockAgendaItemPaint = 1; for ( item=oldconflictItems.first(); item != 0; item=oldconflictItems.next() ) { placeSubCells(item); } while ( placeItem ) { //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); oldconflictItems = placeItem->conflictItems(); for ( item=oldconflictItems.first(); item != 0; item=oldconflictItems.next() ) { placeSubCells(item); } placeSubCells( placeItem ); placeItem = placeItem->nextMultiItem(); } globalFlagBlockAgendaItemPaint = 0; for ( item=oldconflictItems.first(); item != 0; item=oldconflictItems.next() ) { globalFlagBlockAgendaItemUpdate = 0; item->repaintMe(); globalFlagBlockAgendaItemUpdate = 1; item->repaint( false ); } placeItem = modifiedItem; while ( placeItem ) { //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); globalFlagBlockAgendaItemUpdate = 0; placeItem->repaintMe(); globalFlagBlockAgendaItemUpdate = 1; placeItem->repaint(false); placeItem = placeItem->nextMultiItem(); } emit itemModified( modifiedItem, mActionType ); placeItem = modifiedItem; while ( placeItem ) { oldconflictItems = placeItem->conflictItems(); for ( item=oldconflictItems.first(); item != 0; item=oldconflictItems.next() ) { placeSubCells(item); } placeSubCells( placeItem ); placeItem = placeItem->nextMultiItem(); } |