-rw-r--r-- | korganizer/koagenda.cpp | 179 |
1 files changed, 86 insertions, 93 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp index ec81d44..e8b7c94 100644 --- a/korganizer/koagenda.cpp +++ b/korganizer/koagenda.cpp @@ -206,677 +206,670 @@ KOAgenda::~KOAgenda() { if(mMarcusBains) delete mMarcusBains; } Incidence *KOAgenda::selectedIncidence() const { return (mSelectedItem ? mSelectedItem->incidence() : 0); } QDate KOAgenda::selectedIncidenceDate() const { return (mSelectedItem ? mSelectedItem->itemDate() : QDate()); } void KOAgenda::init() { mNewItemPopup = new QPopupMenu( this ); connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) ); QString pathString = ""; if ( !KOPrefs::instance()->mToolBarMiniIcons ) { if ( QApplication::desktop()->width() < 480 ) pathString += "icons16/"; } else pathString += "iconsmini/"; mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 ); mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 ); mNewItemPopup->insertSeparator ( ); mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 ); mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 ); mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 ); mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 ); mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("Next month"),6 ); mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 ); #ifndef _WIN32_ int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase viewport()->setWFlags ( wflags); #endif mGridSpacingX = 80; mResizeBorderWidth = 8; mScrollBorderWidth = 8; mScrollDelay = 30; mScrollOffset = 10; mPaintPixmap.resize( 20,20); //enableClipper(true); // Grab key strokes for keyboard navigation of agenda. Seems to have no // effect. Has to be fixed. setFocusPolicy(WheelFocus); connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp())); connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown())); connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize())); mStartCellX = 0; mStartCellY = 0; mCurrentCellX = 0; mCurrentCellY = 0; mSelectionCellX = 0; mSelectionYTop = 0; mSelectionHeight = 0; mOldLowerScrollValue = -1; mOldUpperScrollValue = -1; mClickedItem = 0; mActionItem = 0; mActionType = NOP; mItemMoved = false; mSelectedItem = 0; // mItems.setAutoDelete(true); resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); viewport()->update(); setMinimumSize(30, 1); // setMaximumHeight(mGridSpacingY * mRows + 5); // Disable horizontal scrollbar. This is a hack. The geometry should be // controlled in a way that the contents horizontally always fits. Then it is // not necessary to turn off the scrollbar. setHScrollBarMode(AlwaysOff); if ( ! mAllDayMode ) setVScrollBarMode(AlwaysOn); else setVScrollBarMode(AlwaysOff); setStartHour(KOPrefs::instance()->mDayBegins); calculateWorkingHours(); connect(verticalScrollBar(),SIGNAL(valueChanged(int)), SLOT(checkScrollBoundaries(int))); // Create the Marcus Bains line. if(mAllDayMode) mMarcusBains = 0; else { mMarcusBains = new MarcusBains(this); addChild(mMarcusBains); } } void KOAgenda::clear() { KOAgendaItem *item; for ( item=mItems.first(); item != 0; item=mItems.next() ) { mUnusedItems.append( item ); //item->hide(); } mItems.clear(); mSelectedItem = 0; clearSelection(); } void KOAgenda::clearSelection() { mSelectionCellX = 0; mSelectionYTop = 0; mSelectionHeight = 0; } void KOAgenda::marcus_bains() { if(mMarcusBains) mMarcusBains->updateLocation(true); } void KOAgenda::changeColumns(int columns) { if (columns == 0) { kdDebug() << "KOAgenda::changeColumns() called with argument 0" << endl; return; } clear(); mColumns = columns; // setMinimumSize(mColumns * 10, mGridSpacingY + 1); // init(); // update(); //qDebug("KOAgenda::changeColumns "); computeSizes(); // QResizeEvent event( size(), size() ); //QApplication::sendEvent( this, &event ); } /* This is the eventFilter function, which gets all events from the KOAgendaItems contained in the agenda. It has to handle moving and resizing for all items. */ bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) { // kdDebug() << "KOAgenda::eventFilter" << endl; switch(event->type()) { case QEvent::MouseButtonPress: case QEvent::MouseButtonDblClick: case QEvent::MouseButtonRelease: case QEvent::MouseMove: return eventFilter_mouse(object, static_cast<QMouseEvent *>(event)); case (QEvent::Leave): if (!mActionItem) setCursor(arrowCursor); return true; default: return QScrollView::eventFilter(object,event); } } bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) { //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 bool block = true; + static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); + static bool blockMoving = true; + static bool leftMouseDown = false; + static bool rightMouseDown = false; switch (me->type()) { case QEvent::MouseButtonPress: - //qDebug("QEvent::MouseButtonPress: "); - // kdDebug() << "koagenda: filtered button press" << endl; + if (me->button() == LeftButton) + leftMouseDown = true; + else if (me->button() == RightButton) + rightMouseDown = true; + blockMoving = true; + startX = viewportPos.x(); + startY = viewportPos.y(); if (object != viewport()) { if (me->button() == RightButton) { mClickedItem = (KOAgendaItem *)object; if (mClickedItem) { selectItem(mClickedItem); - // emit showIncidencePopupSignal(mClickedItem->incidence()); } - //mItemPopup->popup(QCursor::pos()); - } else { + } 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); - startX = viewportPos.x(); - startY = viewportPos.y(); - block = true; } } } - } else { + } else { // ---------- viewport() selectItem(0); mActionItem = 0; - if (me->button() == RightButton ) { - blockNewEvent = true; - block = false; - } else { - blockNewEvent = false; + if (me->button() == LeftButton ) { setCursor(arrowCursor); startSelectAction(viewportPos); } } break; case QEvent::MouseButtonRelease: - //qDebug("QEvent::MouseButtonRelease: %d",blockNewEvent ); - if (me->button() == RightButton && blockNewEvent && !block) { - int x,y; - viewportToContents(viewportPos.x(),viewportPos.y(),x,y); - int gx,gy; - contentsToGrid(x,y,gx,gy); - if ( object == viewport() ) { - if ( mCurrentCellY < mStartCellY +1 ) { - //qDebug("mCurrentCellY %d mStartCellY %d ", mCurrentCellY,mStartCellY); + if (object != viewport()) { + if (me->button() == RightButton) { + if ( blockMoving ) { + mClickedItem = (KOAgendaItem *)object; + if (mActionItem ) { + endItemAction(); + } + leftMouseDown = false; // no more leftMouse computation + if (mClickedItem) { + selectItem(mClickedItem); + emit showIncidencePopupSignal(mClickedItem->incidence()); + } + } + } else 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; + return true; + } + endItemAction(); + } + } + + } else { // ---------- viewport() + if (me->button() == RightButton) { //right click + if ( blockMoving ) { // we did mot moved the mouse much - popup menu + 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; - } else { - blockNewEvent = false; } - } else { - mClickedItem = (KOAgendaItem *)object; - if (mActionItem ) { - endItemAction(); - } - if (mClickedItem) { - selectItem(mClickedItem); - emit showIncidencePopupSignal(mClickedItem->incidence()); - } - } - } else if (me->button() == RightButton && block ) { - if (object != viewport()) { - mClickedItem = (KOAgendaItem *)object; - if (mActionItem ) { - endItemAction(); - } - if (mClickedItem) { - selectItem(mClickedItem); - emit showIncidencePopupSignal(mClickedItem->incidence()); - } - } - break; - } - block = true; - 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; - return true; } - endItemAction(); - } else if ( mActionType == SELECT ) { - if (me->button() == RightButton ) { - } else { - endSelectAction( !blockNewEvent ); + else if (me->button() == LeftButton && leftMouseDown ) { //left click + endSelectAction( true ); // emit new event signal } } + if (me->button() == LeftButton) + leftMouseDown = false; + else if (me->button() == RightButton) + rightMouseDown = false; break; case QEvent::MouseMove: + if ( !rightMouseDown && !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; - //qDebug("moveItem %d ",moveItem ); - if (!moveItem->incidence()->isReadOnly() /*&& - !moveItem->incidence()->recurrence()->doesRecur()*/ ) + if (!moveItem->incidence()->isReadOnly() ) { if (!mActionItem) setNoActionCursor(moveItem,viewportPos); else { - if ( block ) { - int dX, dY; - dX = startX - viewportPos.x(); - if ( dX < 0 ) - dX = -dX; - dY = viewportPos.y() - startY; - if ( dY < 0 ) - dY = -dY; - int diff = 30; - if ( QApplication::desktop()->width() < 480 ) - diff = 15; - // qDebug(" %d %d ",dX, dY ); - if ( dX > diff || dY > diff ) { - block = false; - } - } - if ( !block ) + if ( !blockMoving ) performItemAction(viewportPos); } - } else { + } + } else { // ---------- viewport() if ( mActionType == SELECT ) { performSelectAction( viewportPos ); } } break; case QEvent::MouseButtonDblClick: 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; } void KOAgenda::newItem( int item ) { if ( item == 1 ) { //new event newEventSignal(mStartCellX ,mStartCellY ); } else if ( item == 2 ) { //new event newTodoSignal(mStartCellX ,mStartCellY ); } else { QDate day = mSelectedDates[mStartCellX]; emit showDateView( item, day ); // 3Day view // 4Week view // 5Month view // 6Journal view } } void KOAgenda::startSelectAction(QPoint viewportPos) { //emit newStartSelectSignal(); mActionType = SELECT; 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; // 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 ); } 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 ) + 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); } } } void KOAgenda::performItemAction(QPoint viewportPos) { // kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; // QPoint point = viewport()->mapToGlobal(viewportPos); // kdDebug() << "Global: " << point.x() << "," << point.y() << endl; // point = clipper()->mapFromGlobal(point); // kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; // kdDebug() << "visible height: " << visibleHeight() << endl; int x,y; viewportToContents(viewportPos.x(),viewportPos.y(),x,y); // kdDebug() << "contents: " << x << "," << y << "\n" << endl; int gx,gy; contentsToGrid(x,y,gx,gy); QPoint clipperPos = clipper()-> mapFromGlobal(viewport()->mapToGlobal(viewportPos)); // Cursor left active agenda area. // This starts a drag. if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/ clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) { if ( mActionType == MOVE ) { mScrollUpTimer.stop(); mScrollDownTimer.stop(); mActionItem->resetMove(); placeSubCells( mActionItem ); // emit startDragSignal( mActionItem->incidence() ); setCursor( arrowCursor ); mActionItem = 0; mActionType = NOP; mItemMoved = 0; return; } } else { switch ( mActionType ) { case MOVE: setCursor( sizeAllCursor ); break; case RESIZETOP: case RESIZEBOTTOM: setCursor( sizeVerCursor ); break; case RESIZELEFT: case RESIZERIGHT: setCursor( sizeHorCursor ); break; default: setCursor( arrowCursor ); } } // Scroll if item 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(); } // Move or resize item if necessary if (mCurrentCellX != gx || mCurrentCellY != gy) { mItemMoved = true; mActionItem->raise(); if (mActionType == MOVE) { // Move all items belonging to a multi item KOAgendaItem *moveItem = mActionItem->firstMultiItem(); bool isMultiItem = (moveItem || mActionItem->lastMultiItem()); if (!moveItem) moveItem = mActionItem; while (moveItem) { int dy; if (isMultiItem) dy = 0; else dy = gy - mCurrentCellY; moveItem->moveRelative(gx - mCurrentCellX,dy); int x,y; gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y); moveItem->resize(mGridSpacingX * moveItem->cellWidth(), mGridSpacingY * moveItem->cellHeight()); moveChild(moveItem,x,y); moveItem = moveItem->nextMultiItem(); } } else if (mActionType == RESIZETOP) { if (mCurrentCellY <= mActionItem->cellYBottom()) { mActionItem->expandTop(gy - mCurrentCellY); mActionItem->resize(mActionItem->width(), mGridSpacingY * mActionItem->cellHeight()); int x,y; gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y); //moveChild(mActionItem,childX(mActionItem),y); QScrollView::moveChild( mActionItem,childX(mActionItem),y ); } } else if (mActionType == RESIZEBOTTOM) { if (mCurrentCellY >= mActionItem->cellYTop()) { mActionItem->expandBottom(gy - mCurrentCellY); mActionItem->resize(mActionItem->width(), mGridSpacingY * mActionItem->cellHeight()); } } else if (mActionType == RESIZELEFT) { 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; |