-rw-r--r-- | korganizer/koagenda.cpp | 179 | ||||
-rw-r--r-- | korganizer/koagenda.h | 1 |
2 files changed, 86 insertions, 94 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp index ec81d44..e8b7c94 100644 --- a/korganizer/koagenda.cpp +++ b/korganizer/koagenda.cpp @@ -302,485 +302,478 @@ void KOAgenda::init() 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: diff --git a/korganizer/koagenda.h b/korganizer/koagenda.h index 2069b22..f3f1772 100644 --- a/korganizer/koagenda.h +++ b/korganizer/koagenda.h @@ -117,175 +117,174 @@ class KOAgenda : public QScrollView void setHolidayMask(QMemArray<bool> *); void setDateList(const DateList &selectedDates); DateList dateList() const; void drawContentsToPainter( QPainter* paint = 0, bool backgroundOnly = false); void finishUpdate(); void printSelection(); void storePosition(); void restorePosition(); public slots: void newItem( int ); void moveChild( QWidget *, int, int ); void scrollUp(); void scrollDown(); void updateTodo( Todo * t, int , bool ); void popupAlarm(); void checkScrollBoundaries(int); /** Deselect selected items. This function does not emit any signals. */ void deselectItem(); /** Select item. If the argument is 0, the currently selected item gets deselected. This function emits the itemSelected(bool) signal to inform about selection/deseelction of events. */ void selectItem(KOAgendaItem *); void finishResize(); signals: void showDateView( int, QDate ); void newEventSignal(); void newEventSignal(int gx,int gy); void newTodoSignal(int gx,int gy); void newEventSignal(int gxStart, int gyStart, int gxEnd, int gyEnd); void newTimeSpanSignal(int gxStart, int gyStart, int gxEnd, int gyEnd); void newStartSelectSignal(); void showIncidenceSignal(Incidence *); void editIncidenceSignal(Incidence *); void deleteIncidenceSignal(Incidence *); void showIncidencePopupSignal(Incidence *); void itemModified(KOAgendaItem *item, int ); void incidenceSelected(Incidence *); void lowerYChanged(int); void upperYChanged(int); void startDragSignal(Incidence *); void addToCalSignal(Incidence *, Incidence *); void resizedSignal(); protected: QPainter mPixPainter; QPixmap mPaintPixmap; QPixmap mHighlightPixmap; void drawContents(QPainter *p,int cx, int cy, int cw, int ch); virtual void resizeEvent ( QResizeEvent * ); /** Handles mouse events. Called from eventFilter */ virtual bool eventFilter_mouse ( QObject *, QMouseEvent * ); /** Start selecting time span. */ void startSelectAction(QPoint viewportPos); /** Select time span. */ void performSelectAction(QPoint viewportPos); /** Emd selecting time span. */ void endSelectAction( bool emitNewEvent = false ); /** Start moving/resizing agenda item */ void startItemAction(QPoint viewportPos); /** Move/resize agenda item */ void performItemAction(QPoint viewportPos); /** End moving/resizing agenda item */ void endItemAction(); /** Set cursor, when no item action is in progress */ void setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos); /** Place agenda item in agenda and adjust other cells if necessary */ void placeSubCells(KOAgendaItem *placeItem); /** Process the keyevent, including the ignored keyevents of eventwidgets. * Implements pgup/pgdn and cursor key navigation in the view. */ void keyPressEvent( QKeyEvent * ); void calculateWorkingHours(); virtual void contentsMousePressEvent ( QMouseEvent * ); private: - bool blockNewEvent; void init(); void marcus_bains(); bool mAllDayMode; bool blockResize; QTimer mResizeTimer; double mContentPosition; // Width and height of agenda cells int mGridSpacingX; int mGridSpacingY; // size of border, where mouse action will resize the KOAgendaItem int mResizeBorderWidth; // size of border, where mouse mve will cause a scroll of the agenda int mScrollBorderWidth; int mScrollDelay; int mScrollOffset; QTimer mScrollUpTimer; QTimer mScrollDownTimer; // Number of Columns/Rows of agenda grid int mColumns; int mRows; // Cells to store Move and Resize coordiantes int mStartCellX; int mStartCellY; int mCurrentCellX; int mCurrentCellY; // Working Hour coordiantes bool mWorkingHoursEnable; int mWorkingHoursYTop; int mWorkingHoursYBottom; // Selection int mSelectionCellX; int mSelectionYTop; int mSelectionHeight; // List of dates to be displayed DateList mSelectedDates; // The KOAgendaItem, which has been right-clicked last KOAgendaItem *mClickedItem; // The KOAgendaItem, which is being moved/resized QGuardedPtr<KOAgendaItem> mActionItem; // Currently selected item QGuardedPtr<KOAgendaItem> mSelectedItem; // The Marcus Bains Line widget. MarcusBains *mMarcusBains; void computeSizes(); MouseActionType mActionType; bool mItemMoved; // List of all Items contained in agenda QPtrList<KOAgendaItem> mItems; QPtrList<KOAgendaItem> mUnusedItems; KOAgendaItem* getNewItem(Incidence * event,QDate qd, QWidget* viewport); QPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems QPopupMenu *mNewItemPopup; int mOldLowerScrollValue; int mOldUpperScrollValue; KOAgendaItem * getItemForTodo ( Todo * todo ); QMemArray<bool> *mHolidayMask; int mCurPixWid; int mCurPixHei; }; #endif // KOAGENDA_H |