-rw-r--r-- | korganizer/koagenda.cpp | 195 |
1 files changed, 190 insertions, 5 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp index 66ad4ec..14f52b8 100644 --- a/korganizer/koagenda.cpp +++ b/korganizer/koagenda.cpp @@ -57,33 +57,32 @@ //extern bool globalFlagBlockPainting; extern int globalFlagBlockAgenda; extern int globalFlagBlockAgendaItemPaint; extern int globalFlagBlockAgendaItemUpdate; extern int globalFlagBlockStartup; //////////////////////////////////////////////////////////////////////////// MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name) : QFrame(_agenda->viewport(),name), agenda(_agenda) { setLineWidth(0); setMargin(0); setBackgroundColor(Qt::red); minutes = new QTimer(this); connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc())); minutes->start(0, true); - mTimeBox = new QLabel(this); mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom); QPalette pal = mTimeBox->palette(); pal.setColor(QColorGroup::Foreground, Qt::red); mTimeBox->setPalette(pal); //mTimeBox->setAutoMask(true); agenda->addChild(mTimeBox); oldToday = -1; } MarcusBains::~MarcusBains() { delete minutes; } @@ -162,79 +161,82 @@ void MarcusBains::updateLocation(bool recalculate) /* Create an agenda widget with rows rows and columns columns. */ KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, const char *name,WFlags f) : QScrollView(parent,name,f) { mColumns = columns; mRows = rows; mGridSpacingY = rowSize; mAllDayMode = false; #ifndef DESKTOP_VERSION - QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); + //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); #endif mHolidayMask = 0; init(); } /* Create an agenda widget with columns columns and one row. This is used for all-day events. */ KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : QScrollView(parent,name,f) { blockResize = false; mColumns = columns; mRows = 1; //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize); mGridSpacingY = KOPrefs::instance()->mAllDaySize; mAllDayMode = true; #ifndef DESKTOP_VERSION - QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); + //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); #endif mHolidayMask = 0; init(); } 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() { + mPopupTimer = new QTimer(this); + connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu())); + 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 ); @@ -298,33 +300,35 @@ void KOAgenda::init() 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); - } + } + mPopupKind = 0; + mPopupItem = 0; } 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() { @@ -369,36 +373,216 @@ bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) 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); } } - +void KOAgenda::popupMenu() +{ + mPopupTimer->stop(); + if ( mPopupKind == 1 ) { + if (mActionItem ) { + endItemAction(); + } + mLeftMouseDown = false; // no more leftMouse computation + if (mPopupItem) { + selectItem(mPopupItem); + emit showIncidencePopupSignal(mPopupItem->incidence()); + + } + } else if ( mPopupKind == 2 ) { + if ( mLeftMouseDown ) { // we have a simulated right click - clear left mouse action + endSelectAction( false ); // do not emit new event signal + mLeftMouseDown = false; // no more leftMouse computation + } + mNewItemPopup->popup( mPopupPos); + } + mLeftMouseDown = false; + mPopupItem = 0; + mPopupKind = 0; +} 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 int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); + static bool blockMoving = true; + switch (me->type()) { + case QEvent::MouseButtonPress: + if (me->button() == LeftButton) { + mPopupTimer->start( 600 ); + mLeftMouseDown = true; + } + blockMoving = true; + startX = viewportPos.x(); + startY = viewportPos.y(); + 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 ); + } + 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; + mPopupPos = viewport()->mapToGlobal( me->pos() ); + if (me->button() == RightButton) { + 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; + mActionType = NOP; + mItemMoved = 0; + mLeftMouseDown = false; + return true; + } + endItemAction(); + } + } + + } else { // ---------- viewport() + if (me->button() == LeftButton && mLeftMouseDown ) { //left click + endSelectAction( true ); // emit new event signal + } + } + if (me->button() == LeftButton) + mLeftMouseDown = false; + + break; + + case QEvent::MouseMove: + if ( !mLeftMouseDown ) + 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 ( ! 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) { @@ -546,32 +730,33 @@ bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) 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 { QDate day = mSelectedDates[mStartCellX]; emit showDateView( item, day ); // 3Day view // 4Week view // 5Month view |