-rw-r--r-- | korganizer/koagenda.cpp | 42 | ||||
-rw-r--r-- | korganizer/koagendaitem.cpp | 20 | ||||
-rw-r--r-- | korganizer/koagendaitem.h | 1 |
3 files changed, 44 insertions, 19 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp index 88f5d99..796d633 100644 --- a/korganizer/koagenda.cpp +++ b/korganizer/koagenda.cpp @@ -768,838 +768,843 @@ void KOAgenda::startSelectAction(QPoint viewportPos) mSelectionYTop = gy * mGridSpacingY; mSelectionHeight = mGridSpacingY; // 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; repaintContents( (KOGlobals::self()->reverseLayout() ? mColumns - 1 - mSelectionCellX : mSelectionCellX) * mGridSpacingX, mSelectionYTop, mGridSpacingX, mSelectionHeight , false); 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 ) { 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()->typeID() != todoID ); 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(), + int diff = moveItem->resizeMe(mGridSpacingX, mGridSpacingX* moveItem->cellWidth(), mGridSpacingY * moveItem->cellHeight()); moveItem->raise(); - moveChild(moveItem,x,y); + moveChild(moveItem,x+diff,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 diff = mActionItem->resizeMe(mGridSpacingX , + mGridSpacingX * mActionItem->cellWidth(), + mActionItem->height()); int x,y; gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); - moveChild(mActionItem,x,childY(mActionItem)); + moveChild(mActionItem,x+diff,childY(mActionItem)); } } else if (mActionType == RESIZERIGHT) { if (mCurrentCellX >= mActionItem->cellX()) { mActionItem->expandRight(gx - mCurrentCellX); - mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), + mActionItem->resizeMe(mGridSpacingX, 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()->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()->typeID() == todoID ) { mSelectedItem = 0; //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth()); modifiedItem->mLastMoveXPos = mCurrentCellX; emit itemModified( modifiedItem, mActionType ); } else { 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(); } placeItem = modifiedItem; while ( placeItem ) { oldconflictItems = placeItem->conflictItems(); for ( item=oldconflictItems.first(); item != 0; item=oldconflictItems.next() ) { globalFlagBlockAgendaItemUpdate = 0; item->repaintMe(); globalFlagBlockAgendaItemUpdate = 1; item->repaint(false); } placeItem = placeItem->nextMultiItem(); } /* oldconflictItems = modifiedItem->conflictItems(); for ( item=oldconflictItems.first(); item != 0; item=oldconflictItems.next() ) { globalFlagBlockAgendaItemUpdate = 0; item->paintMe(false); globalFlagBlockAgendaItemUpdate = 1; item->repaint(false); } */ } } if ( mActionItem ) emit incidenceSelected( mActionItem->incidence() ); mScrollUpTimer.stop(); mScrollDownTimer.stop(); setCursor( arrowCursor ); mActionItem = 0; mActionType = NOP; mItemMoved = 0; } void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,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; int x,y; viewportToContents(viewportPos.x(),viewportPos.y(),x,y); // kdDebug() << "contents: " << x << "," << y << "\n" << endl; int gx,gy; contentsToGrid(x,y,gx,gy); // Change cursor to resize cursor if appropriate if (mAllDayMode) { int gridDistanceX = (x - gx * mGridSpacingX); if (gridDistanceX < mResizeBorderWidth && moveItem->cellX() == gx) { setCursor(sizeHorCursor); } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && moveItem->cellXWidth() == gx) { setCursor(sizeHorCursor); } else { setCursor(arrowCursor); } } else { int gridDistanceY = (y - gy * mGridSpacingY); if (gridDistanceY < mResizeBorderWidth && moveItem->cellYTop() == gy && !moveItem->firstMultiItem()) { setCursor(sizeVerCursor); } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth && moveItem->cellYBottom() == gy && !moveItem->lastMultiItem()) { setCursor(sizeVerCursor); } else { setCursor(arrowCursor); } } } /* Place item in cell and take care that multiple items using the same cell do not overlap. This method is not yet optimal. It doesnīt use the maximum space it can get in all cases. At the moment the method has a bug: When an item is placed only the sub cell widths of the items are changed, which are within the Y region the item to place spans. When the sub cell width change of one of this items affects a cell, where other items are, which do not overlap in Y with the item to place, the display gets corrupted, although the corruption looks quite nice. */ void KOAgenda::placeSubCells(KOAgendaItem *placeItem) { QPtrList<KOAgendaItem> conflictItems; int maxSubCells = 0; QIntDict<KOAgendaItem> subCellDict(7); KOAgendaItem *item; for ( item=mItems.first(); item != 0; item=mItems.next() ) { if (item != placeItem) { if (placeItem->cellX() <= item->cellXWidth() && placeItem->cellXWidth() >= item->cellX()) { if ((placeItem->cellYTop() <= item->cellYBottom()) && (placeItem->cellYBottom() >= item->cellYTop())) { conflictItems.append(item); if (item->subCells() > maxSubCells) maxSubCells = item->subCells(); subCellDict.insert(item->subCell(),item); } } } } if (conflictItems.count() > 0) { // Look for unused sub cell and insert item int i; for(i=0;i<maxSubCells;++i) { if (!subCellDict.find(i)) { placeItem->setSubCell(i); break; } } if (i == maxSubCells) { placeItem->setSubCell(maxSubCells); maxSubCells++; // add new item to number of sub cells } // Prepare for sub cell geometry adjustment int newSubCellWidth; if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells; else newSubCellWidth = mGridSpacingX / maxSubCells; conflictItems.append(placeItem); // Adjust sub cell geometry of all direct conflict items for ( item=conflictItems.first(); item != 0; item=conflictItems.next() ) { item->setSubCells(maxSubCells); + int diff = 0; if (mAllDayMode) { - item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); + diff = item->resizeMe( mGridSpacingX, item->cellWidth() * mGridSpacingX, newSubCellWidth); } else { item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); } int x,y; gridToContents(item->cellX(),item->cellYTop(),x,y); if (mAllDayMode) { y += item->subCell() * newSubCellWidth; } else { x += item->subCell() * newSubCellWidth; } - moveChild(item,x,y); + moveChild(item,x+diff,y); // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y); //item->updateItem(); } // Adjust sub cell geometry of all conflict items of all conflict items for ( item=conflictItems.first(); item != 0; item=conflictItems.next() ) { if ( placeItem != item ) { KOAgendaItem *item2; QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems(); for ( item2=conflictItems2.first(); item2 != 0; item2=conflictItems2.next() ) { if ( item2->subCells() != maxSubCells) { item2->setSubCells(maxSubCells); + int diff = 0; if (mAllDayMode) { - item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth); + diff = item2->resizeMe(mGridSpacingX, item2->cellWidth() * mGridSpacingX, newSubCellWidth); } else { item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY); } int x,y; gridToContents(item2->cellX(),item2->cellYTop(),x,y); if (mAllDayMode) { y += item2->subCell() * newSubCellWidth; } else { x += item2->subCell() * newSubCellWidth; } - moveChild(item2,x,y); + moveChild(item2,x+diff,y); //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() ); } } } } } else { placeItem->setSubCell(0); placeItem->setSubCells(1); - if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY); + int diff = 0; + if (mAllDayMode) diff = placeItem->resizeMe( mGridSpacingX, placeItem->width(),mGridSpacingY); else placeItem->resize(mGridSpacingX,placeItem->height()); int x,y; gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y); - moveChild(placeItem,x,y); + moveChild(placeItem,x+diff,y); } placeItem->setConflictItems(conflictItems); // for ( item=conflictItems.first(); item != 0; // item=conflictItems.next() ) { // //item->updateItem(); // //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() ); // } // placeItem->updateItem(); } void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch) { if ( globalFlagBlockAgenda ) return; if ( mInvalidPixmap ) { mInvalidPixmap = false; qDebug("KO: dc Upsizing Pixmaps %s", QDateTime::currentDateTime().toString().latin1()); computeSizes(); emit updateViewSignal(); return; } //qDebug("KOAgenda::drawContents %s", QDateTime::currentDateTime().toString().latin1()); if ( ! mAllDayMode ) { // currently not working for //qDebug("KOAgenda::drawContents "); #if 0 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) { qDebug("WAU "); drawContentsToPainter(); } #endif QPaintDevice* pd = p->device(); p->end(); int vx, vy; int selectionX = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - mSelectionCellX) * mGridSpacingX : mSelectionCellX * mGridSpacingX; contentsToViewport ( cx, cy, vx,vy); //qDebug(" %d %d %d %d %d", cx, cy, cw,ch,mGridSpacingX-1) ; if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) { if ( mGridSpacingX == cw && mSelectionHeight > 0 && ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) ) { int vxSel, vySel; contentsToViewport ( selectionX, mSelectionYTop, vxSel,vySel); int off = mSelectionHeight; if ( vySel < 0 ) off += vySel; //qDebug("OFF %d %d %d", off,vySel, vy ); bitBlt ( pd, vx, vy+off, &mPaintPixmap, cx, cy+off, cw , ch-off ,CopyROP); } else { bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); } } if ( mSelectionHeight > 0 ) { //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { contentsToViewport ( selectionX, mSelectionYTop, vx,vy); // bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); int hei = mSelectionHeight; int offset = 0; while ( hei > 0 ) { int p_hei = 5; if ( hei < 5 ) p_hei = hei; hei -= 5; bitBlt ( pd, vx+1, vy+offset, &mHighlightPixmap, 0, 0, mGridSpacingX-1, p_hei ,CopyROP); offset += 5; } } } p->begin( pd ); } else { #if 0 qDebug("mCurPixWid %d %d ",mCurPixWid, contentsWidth() ); if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) { qDebug("WAUWAU "); drawContentsToPainter(); } #endif QPaintDevice* pd = p->device(); p->end(); int vx, vy; int selectionX = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - mSelectionCellX) * mGridSpacingX : mSelectionCellX * mGridSpacingX; contentsToViewport ( cx, cy, vx,vy); // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ; if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); if ( mSelectionHeight > 0 ) { //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { contentsToViewport ( selectionX, mSelectionYTop, vx,vy); //bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); int hei = mSelectionHeight; int offset = 0; while ( hei > 0 ) { int p_hei = 5; if ( hei < 5 ) p_hei = hei; hei -= 5; bitBlt ( pd, vx+1, vy+offset, &mHighlightPixmap, 0, 0, mGridSpacingX-1, p_hei ,CopyROP); offset += 5; } } } p->begin( pd ); } } void KOAgenda::finishUpdate() { KOAgendaItem *item; globalFlagBlockAgendaItemPaint = 1; // Adjust sub cell geometry of all conflict items of all conflict items of all conflict items ... of the conflict item with the max number of conflictitems for ( item=mItems.first(); item != 0; item=mItems.next() ) { if ( !item->checkLayout() ) { //qDebug(" conflictitem found "); int newSubCellWidth; + int diff = 0; if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells(); else newSubCellWidth = mGridSpacingX / item->subCells(); if (mAllDayMode) { - item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); + diff = item->resizeMe(mGridSpacingX, item->cellWidth() * mGridSpacingX, newSubCellWidth); } else { item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); } int x,y; gridToContents(item->cellX(),item->cellYTop(),x,y); if (mAllDayMode) { y += item->subCell() * newSubCellWidth; } else { x += item->subCell() * newSubCellWidth; } - moveChild(item,x,y); + moveChild(item,x+diff,y); } } for ( item=mItems.first(); item != 0; item=mItems.next() ) { if ( !item->isVisible() ) item->show(); } globalFlagBlockAgendaItemUpdate = 0; for ( item=mItems.first(); item != 0; item=mItems.next() ) { item->repaintMe( ); } globalFlagBlockAgendaItemUpdate = 1; qApp->processEvents(); globalFlagBlockAgendaItemPaint = 0; for ( item=mItems.first(); item != 0; item=mItems.next() ) { item->repaint( false ); } marcus_bains(); } /* Draw grid in the background of the agenda. */ void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch) { if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask ) return; if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 ) return; int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight(); if ( ch < 1 ) ch = 1; if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) { mPaintPixmap.resize( contentsWidth()+42, ch ); } mCurPixWid = contentsWidth(); mCurPixHei = ch; if ( mHighlightPixmap.width() < mGridSpacingX-1 ) { mHighlightPixmap.resize( mGridSpacingX-1, 5 ); mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor ); } mPixPainter.begin( &mPaintPixmap) ; //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() ); QPainter * p ; if (paint == 0) { mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor); p = &mPixPainter; } else p = paint ; // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch); //--cx;++cw; int lGridSpacingY = mGridSpacingY*2; uint selDay; QDate curDate = QDate::currentDate(); if ( !backgroundOnly ) { for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) { if ( mSelectedDates[selDay] == curDate && KOPrefs::instance()->mHighlightCurrentDay) { int x1 = cx; int y1 = 0; if (y1 < cy) y1 = cy; int x2 = cx+cw-1; int y2 = contentsHeight(); if (y2 > cy+ch-1) y2=cy+ch-1; if (x2 >= x1 && y2 >= y1) { int gxStart = selDay; //int gxEnd = gxStart ; int xStart = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gxStart)*mGridSpacingX : gxStart*mGridSpacingX; if (xStart < x1) xStart = x1; int xEnd = KOGlobals::self()->reverseLayout() ? (mColumns - gxStart)*mGridSpacingX-1 : (gxStart+1)*mGridSpacingX-1; if (xEnd > x2) xEnd = x2; if ( KOPrefs::instance()->mUseHighlightLightColor ) p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, KOPrefs::instance()->mAgendaBgColor.light()); else p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, KOPrefs::instance()->mAgendaBgColor.dark()); } } } } // Highlight working hours if ( !backgroundOnly ) if (mWorkingHoursEnable) { int x1 = cx; int y1 = mWorkingHoursYTop; if (y1 < cy) y1 = cy; int x2 = cx+cw-1; // int x2 = mGridSpacingX * 5 - 1; // if (x2 > cx+cw-1) x2 = cx + cw - 1; int y2 = mWorkingHoursYBottom; if (y2 > cy+ch-1) y2=cy+ch-1; if (x2 >= x1 && y2 >= y1) { // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX ); int gxStart = x1/mGridSpacingX; int gxEnd = x2/mGridSpacingX; while(gxStart <= gxEnd) { if (gxStart < int(mHolidayMask->count()) && !mHolidayMask->at(gxStart)) { int xStart = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gxStart)*mGridSpacingX : gxStart*mGridSpacingX; if (xStart < x1) xStart = x1; int xEnd = KOGlobals::self()->reverseLayout() ? (mColumns - gxStart)*mGridSpacingX-1 : (gxStart+1)*mGridSpacingX-1; if (xEnd > x2) xEnd = x2; if ( mSelectedDates[gxStart] == curDate && KOPrefs::instance()->mHighlightCurrentDay ) { if ( KOPrefs::instance()->mUseHighlightLightColor ) p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, KOPrefs::instance()->mWorkingHoursColor.light()); else p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, KOPrefs::instance()->mWorkingHoursColor.dark()); } else { p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, KOPrefs::instance()->mWorkingHoursColor); } } ++gxStart; } } } /* int selectionX = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - mSelectionCellX) * mGridSpacingX : mSelectionCellX * mGridSpacingX; // Draw selection if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { // TODO: paint only part within cx,cy,cw,ch p->fillRect( selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight, KOPrefs::instance()->mHighlightColor ); } */ // Draw vertical lines of grid int x = ((int)(cx/mGridSpacingX))*mGridSpacingX; if ( mGridSpacingX > 0 ) { while (x < cx + cw) { p->drawLine(x,cy,x,cy+ch); x+=mGridSpacingX; } } // Draw horizontal lines of grid int y = ((int)(cy/lGridSpacingY))*lGridSpacingY; if ( lGridSpacingY > 0 ) { while (y < cy + ch) { p->setPen( SolidLine ); p->drawLine(cx,y,cx+cw,y); y+=lGridSpacingY; p->setPen( DotLine ); p->drawLine(cx,y,cx+cw,y); y+=lGridSpacingY; } p->setPen( SolidLine ); } mPixPainter.end() ; } /* Convert srcollview contents coordinates to agenda grid coordinates. */ void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy) { gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX : x/mGridSpacingX; gy = y/mGridSpacingY; } /* Convert agenda grid coordinates to scrollview contents coordinates. */ void KOAgenda::gridToContents (int gx, int gy, int& x, int& y) { x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX: gx*mGridSpacingX; y = gy*mGridSpacingY; } @@ -1647,494 +1652,495 @@ QTime KOAgenda::getEndTime() { int tim = (contentsY ()+viewport()->height())*24/contentsHeight (); if ( tim > 23 ) return QTime ( 23,59,59); return QTime ( tim,0,0); } void KOAgenda::hideUnused() { // experimental only // return; KOAgendaItem *item; for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) { item->hide(); } } KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view) { KOAgendaItem *fi; for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) { if ( fi->incidence() == event ) { mUnusedItems.remove(); fi->init( event, qd ); return fi; } } fi=mUnusedItems.first(); if ( fi ) { mUnusedItems.remove(); fi->init( event, qd ); return fi; } // qDebug("new KOAgendaItem "); KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode ); agendaItem->installEventFilter(this); addChild(agendaItem,0,0); return agendaItem; } KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo ) { KOAgendaItem *item; for ( item=mItems.first(); item != 0; item=mItems.next() ) { if ( item->incidence() == todo ) { mItems.remove(); return item; } } return 0; } void KOAgenda::updateTodo( Todo * todo, int days, bool remove) { // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )|| KOAgendaItem *item; item = getItemForTodo ( todo ); //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove); if ( item ) { blockSignals( true ); //qDebug("item found "); item->hide(); item->setCellX(-2, -1 ); item->select(false); mUnusedItems.append( item ); mItems.remove( item ); QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); KOAgendaItem *itemit; //globalFlagBlockAgendaItemPaint = 1; for ( itemit=oldconflictItems.first(); itemit != 0; itemit=oldconflictItems.next() ) { if ( itemit != item ) placeSubCells(itemit); } qApp->processEvents(); //globalFlagBlockAgendaItemPaint = 0; for ( itemit=oldconflictItems.first(); itemit != 0; itemit=oldconflictItems.next() ) { globalFlagBlockAgendaItemUpdate = 0; if ( itemit != item ) itemit->repaintMe(); globalFlagBlockAgendaItemUpdate = 1; //qDebug("sigleshot "); QTimer::singleShot( 0, itemit, SLOT ( repaintItem() )); //itemit->repaint( false ); repaintItem() } blockSignals( false ); } if ( remove ) { //qDebug("remove****************************************** "); return; } if ( todo->hasCompletedDate() && !KOPrefs::instance()->mShowCompletedTodoInAgenda ) return; //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ "); QDate currentDate = QDate::currentDate(); bool overdue = (!todo->isCompleted()) && (todo->dtDue() < currentDate)&& ( KOPrefs::instance()->mShowTodoInAgenda ); QDateTime dt; if ( todo->hasCompletedDate() ) dt = todo->completed(); else dt = todo->dtDue(); if ( overdue ) { days += todo->dtDue().date().daysTo( currentDate ); } else currentDate = dt.date(); if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) { if ( ! mAllDayMode ) return; // aldayagenda globalFlagBlockAgendaItemPaint = 1; item = insertAllDayItem(todo, currentDate,days, days); item->show(); } else { if ( mAllDayMode ) return; // mAgenda globalFlagBlockAgendaItemPaint = 1; int endY = timeToY(dt.time()) - 1; int hi = 12/KOPrefs::instance()->mHourSize; int startY = endY - 1-hi; item = insertItem(todo,currentDate,days,startY,endY); item->show(); } qApp->processEvents(); globalFlagBlockAgendaItemPaint = 0; QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); KOAgendaItem *itemit; for ( itemit=oldconflictItems.first(); itemit != 0; itemit=oldconflictItems.next() ) { globalFlagBlockAgendaItemUpdate = 0; itemit->repaintMe(); globalFlagBlockAgendaItemUpdate = 1; itemit->repaint(); } globalFlagBlockAgendaItemUpdate = 0; item->repaintMe(); globalFlagBlockAgendaItemUpdate = 1; item->repaint(); } /* Insert KOAgendaItem into agenda. */ KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom) { if (mAllDayMode) { qDebug("KOAgenda: calling insertItem in all-day mode is illegal. "); return 0; } KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); //agendaItem->setFrameStyle(WinPanel|Raised); int YSize = YBottom - YTop + 1; if (YSize < 0) { YSize = 1; } int iheight = mGridSpacingY * YSize; agendaItem->resize(mGridSpacingX,iheight ); agendaItem->setCellXY(X,YTop,YBottom); agendaItem->setCellXWidth(X); //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY); mItems.append(agendaItem); placeSubCells(agendaItem); //agendaItem->show(); return agendaItem; } /* Insert all-day KOAgendaItem into agenda. */ KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd) { if (!mAllDayMode) { return 0; } KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); agendaItem->setCellXY(XBegin,0,0); agendaItem->setCellXWidth(XEnd); - agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY); + agendaItem->resizeMe(mGridSpacingX, mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY); //addChild(agendaItem,XBegin*mGridSpacingX,0); mItems.append(agendaItem); placeSubCells(agendaItem); //agendaItem->show(); return agendaItem; } void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, int YTop,int YBottom) { if (mAllDayMode) { ; return; } int cellX,cellYTop,cellYBottom; QString newtext; int width = XEnd - XBegin + 1; int count = 0; KOAgendaItem *current = 0; QPtrList<KOAgendaItem> multiItems; for (cellX = XBegin;cellX <= XEnd;++cellX) { if (cellX == XBegin) cellYTop = YTop; else cellYTop = 0; if (cellX == XEnd) cellYBottom = YBottom; else cellYBottom = rows() - 1; newtext = QString("(%1/%2): ").arg(++count).arg(width); newtext.append(event->summary()); current = insertItem(event,qd,cellX,cellYTop,cellYBottom); current->setText(newtext); multiItems.append(current); } KOAgendaItem *next = 0; KOAgendaItem *last = multiItems.last(); KOAgendaItem *first = multiItems.first(); KOAgendaItem *setFirst,*setLast; current = first; while (current) { next = multiItems.next(); if (current == first) setFirst = 0; else setFirst = first; if (current == last) setLast = 0; else setLast = last; current->setMultiItem(setFirst,next,setLast); current = next; } } //QSizePolicy KOAgenda::sizePolicy() const //{ // Thought this would make the all-day event agenda minimum size and the // normal agenda take the remaining space. But it doesnīt work. The QSplitter // donīt seem to think that an Expanding widget needs more space than a // Preferred one. // But it doesnīt hurt, so it stays. // if (mAllDayMode) { // return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); // } else { // return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); // } //} void KOAgenda::finishResize ( ) { //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) "); if ( globalFlagBlockAgenda == 0 ) { finishUpdate(); //qDebug("finishUpdate() called "); } } /* Overridden from QScrollView to provide proper resizing of KOAgendaItems. */ void KOAgenda::resizeEvent ( QResizeEvent *ev ) { mSelectionHeight = 0; mResizeTimer.start( 150 , true ); computeSizes(); QScrollView::resizeEvent( ev ); return; } void KOAgenda::computeSizes() { if ( globalFlagBlockStartup ) return; int frameOffset = frameWidth() * 2 +1; if (mAllDayMode) { mGridSpacingX = (width()-frameOffset) / mColumns; mGridSpacingY = height() - 2 * frameWidth() - 1; resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1); // mGridSpacingY = height(); // resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); KOAgendaItem *item; int subCellWidth; for ( item=mItems.first(); item != 0; item=mItems.next() ) { subCellWidth = mGridSpacingY / item->subCells(); - item->resize(mGridSpacingX * item->cellWidth(),subCellWidth); - moveChild(item,KOGlobals::self()->reverseLayout() ? + int diff = 0; + diff = item->resizeMe(mGridSpacingX ,mGridSpacingX * item->cellWidth(),subCellWidth); + moveChild(item,(KOGlobals::self()->reverseLayout() ? (mColumns - 1 - item->cellX()) * mGridSpacingX : - item->cellX() * mGridSpacingX, + item->cellX() * mGridSpacingX) + diff, item->subCell() * subCellWidth); } KOPrefs::instance()->mAllDaySize = mGridSpacingY; } else { mGridSpacingX = (width() - verticalScrollBar()->width()-frameOffset)/mColumns; if (height() > mGridSpacingY * mRows + 1 ) { KOPrefs::instance()->mHourSize = ((height())/mRows)+1; mGridSpacingY = KOPrefs::instance()->mHourSize ; resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); emit resizedSignal(); } else resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); KOAgendaItem *item; int subCellWidth; for ( item=mItems.first(); item != 0; item=mItems.next() ) { subCellWidth = mGridSpacingX / item->subCells(); item->resize(subCellWidth,item->height()); moveChild(item,(KOGlobals::self()->reverseLayout() ? (mColumns - 1 - item->cellX()) * mGridSpacingX : item->cellX() * mGridSpacingX) + item->subCell() * subCellWidth,childY(item)); } } int cw = contentsWidth(); int ch = contentsHeight(); if ( mAllDayMode ) { QPixmap* paintPixAll = KOAgendaItem::paintPixAllday(); if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 ) { //qDebug("paintPixAll->resize "); paintPixAll->resize( cw, ch ); } } else { QPixmap* paintPix = KOAgendaItem::paintPix(); if ( paintPix->width() < cw || paintPix->height() < ch ) { //qDebug("paintPix->resize "); paintPix->resize( cw , ch ); } } checkScrollBoundaries(); drawContentsToPainter(); viewport()->repaint(false); } void KOAgenda::scrollUp() { scrollBy(0,-mScrollOffset); } void KOAgenda::scrollDown() { scrollBy(0,mScrollOffset); } void KOAgenda::popupAlarm() { if (!mClickedItem) { qDebug("KOAgenda::popupAlarm() called without having a clicked item "); return; } // TODO: deal correctly with multiple alarms Alarm* alarm; QPtrList<Alarm> list(mClickedItem->incidence()->alarms()); for(alarm=list.first();alarm;alarm=list.next()) { alarm->toggleAlarm(); } emit itemModified( mClickedItem , KOGlobals::EVENTEDITED ); mClickedItem->paintMe( true ); mClickedItem->repaint( false ); } /* Calculates the minimum width */ int KOAgenda::minimumWidth() const { // TODO:: develop a way to dynamically determine the minimum width int min = 100; return min; } void KOAgenda::updateConfig() { if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor) viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor); if ( mAllDayMode ) { mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize; //mGridSpacingY = KOPrefs::instance()->mAllDaySize; resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 ); // setMaximumHeight( mGridSpacingY+1 ); viewport()->repaint( false ); //setFixedHeight( mGridSpacingY+1 ); //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize); } else { mGridSpacingY = KOPrefs::instance()->mHourSize; calculateWorkingHours(); } } void KOAgenda::checkScrollBoundaries() { // Invalidate old values to force update mOldLowerScrollValue = -1; mOldUpperScrollValue = -1; checkScrollBoundaries(verticalScrollBar()->value()); } void KOAgenda::checkScrollBoundaries(int v) { if ( mGridSpacingY == 0 ) return; int yMin = v/mGridSpacingY; int yMax = (v+visibleHeight())/mGridSpacingY; // kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl; if (yMin != mOldLowerScrollValue) { mOldLowerScrollValue = yMin; emit lowerYChanged(yMin); } if (yMax != mOldUpperScrollValue) { mOldUpperScrollValue = yMax; emit upperYChanged(yMax); } } void KOAgenda::deselectItem() { if (mSelectedItem.isNull()) return; mSelectedItem->select(false); mSelectedItem = 0; } void KOAgenda::selectItem(KOAgendaItem *item) { if ((KOAgendaItem *)mSelectedItem == item) return; deselectItem(); if (item == 0) { emit incidenceSelected( 0 ); return; } mSelectedItem = item; mSelectedItem->select(); emit incidenceSelected( mSelectedItem->incidence() ); } // This function seems never be called. void KOAgenda::keyPressEvent( QKeyEvent *kev ) { switch(kev->key()) { case Key_PageDown: verticalScrollBar()->addPage(); break; case Key_PageUp: verticalScrollBar()->subtractPage(); break; case Key_Down: verticalScrollBar()->addLine(); break; case Key_Up: verticalScrollBar()->subtractLine(); break; default: ; } } void KOAgenda::calculateWorkingHours() { // mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours; mWorkingHoursEnable = !mAllDayMode; mWorkingHoursYTop = mGridSpacingY * KOPrefs::instance()->mWorkingHoursStart * 4; mWorkingHoursYBottom = mGridSpacingY * KOPrefs::instance()->mWorkingHoursEnd * 4 - 1; } DateList KOAgenda::dateList() const { return mSelectedDates; } void KOAgenda::setDateList(const DateList &selectedDates) { mSelectedDates = selectedDates; diff --git a/korganizer/koagendaitem.cpp b/korganizer/koagendaitem.cpp index 49ad9b8..7a685d8 100644 --- a/korganizer/koagendaitem.cpp +++ b/korganizer/koagendaitem.cpp @@ -467,384 +467,402 @@ void KOAgendaItem::paintMe( bool selected, QPainter* paint ) } } pa.end(); } QPixmap * KOAgendaItem::paintPix() { static QPixmap* mPaintPix = 0; if ( ! mPaintPix ) { int w = QApplication::desktop()->width(); int h = QApplication::desktop()->height(); mPaintPix = new QPixmap(w,h); } return mPaintPix ; } QPixmap * KOAgendaItem::paintPixAllday() { static QPixmap* mPaintPixA = 0; if ( ! mPaintPixA ) { int w = QApplication::desktop()->width(); int h = QApplication::desktop()->height()/5; mPaintPixA = new QPixmap(w,h); } return mPaintPixA ; } void KOAgendaItem::repaintItem() { globalFlagBlockAgendaItemPaint = 0; globalFlagBlockAgenda = 0; repaint( false ); } void KOAgendaItem::paintEvent ( QPaintEvent *e ) { if ( globalFlagBlockAgendaItemPaint ) return; if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 ) return; int yy; if ( mAllDay ) yy = y(); else yy = mCellYTop * ( height() / cellHeight() ); int xx = x(); if ( xPaintCoord != xx || yPaintCoord != yy || wPaintCoord != width() || hPaintCoord != height()) { xPaintCoord= xx; yPaintCoord = yy; wPaintCoord = width(); hPaintCoord = height(); globalFlagBlockAgendaItemUpdate = 0; paintMe( mSelected ); //qDebug("calling paintMe "); globalFlagBlockAgendaItemUpdate = 1; if ( mSelected ) return; } int rx, ry, rw, rh; rx = e->rect().x(); ry = e->rect().y(); rw = e->rect().width(); rh = e->rect().height(); //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height()); QPixmap* paintFrom ; if ( mSelected ) { paintMe( mSelected ); return; } else { if ( mAllDay ) paintFrom = paintPixAllday(); else paintFrom = paintPix(); } xx += rx; if ( xx < 0 ) { rw = rw + xx; rx -= xx; xx = 0; if ( rw <= 1 ) { //qDebug("KOAgendaItem::Width1 <= 1 (%d). Returning. %s",rw,mDisplayedText.latin1()); return; } } if ( paintFrom->width() < xx+rw ) { rw = paintFrom->width() - xx; if ( rw <= 1 ) { //qDebug("KOAgendaItem::Width2 <= 1 (%d). Returning.%s ",rw,mDisplayedText.latin1() ); return; } } //qDebug("%d %d %d %d %d %d %d",rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh); bitBlt (this, rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh ,CopyROP); } void KOAgendaItem::computeText() { mDisplayedText = mIncidence->summary(); if ( (mIncidence->typeID() == todoID ) ) { if ( static_cast<Todo*>(mIncidence)->hasDueDate() ) { if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() ) mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")"; else if ( !(mIncidence->doesFloat())) mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")"; } } else { if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda) mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + " - " + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ; if ( mAllDay ) { if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) { if ( mIncidence->doesRecur() ) { mDisplayedText += " (" + mIncidence->recurrence()->recurrenceText() + ")"; } else { mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) ; } } } } if ( !mIncidence->location().isEmpty() ) { if ( mAllDay ) mDisplayedText += " ("; else mDisplayedText += "\n("; mDisplayedText += mIncidence->location() +")"; } #ifdef DESKTOP_VERSION QString tipText = mIncidence->summary(); if ( !mIncidence->doesFloat() ) { if ( mIncidence->typeID() == eventID ) { if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) { tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr(); tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr(); } else { tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr(); tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr(); } } else if ( mIncidence->typeID() == todoID ) { if (mIncidence->hasStartDate()) tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartStr(); if (((Todo*)mIncidence)->hasDueDate()) tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueStr(); } } else if ( mIncidence->typeID() == todoID ) { if (mIncidence->hasStartDate()) tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartDateStr(); if (((Todo*)mIncidence)->hasDueDate()) tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueDateStr(); } if (!mIncidence->location().isEmpty()) { tipText += "\n"+i18n("Location: ")+mIncidence->location(); } QToolTip::add(this,tipText,toolTipGroup(),""); #endif } void KOAgendaItem::updateItem() { computeText(); //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y()); paintMe( mSelected ); repaint( false); } void KOAgendaItem::resizeEvent ( QResizeEvent *ev ) { //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1()); paintMe( mSelected ); repaint( false ); } /* Return height of item in units of agenda cells */ int KOAgendaItem::cellHeight() { int ret = mCellYBottom - mCellYTop + 1; if ( ret <= 0 ) { ret = 1; mCellYBottom = 0; mCellYTop = 0; } return ret; } - +// it may be that allday agenda items have a needed width > 32000 +// this code is to fix this problem +int KOAgendaItem::resizeMe( int grid, int wid, int hei ) +{ + int diff = 0; + if ( mCellX < -3 && mAllDay ) { + diff = (mCellX + 3) * -grid; + //qDebug("%s: cellX %d diff %d wid %d grid %d ", mDisplayedText.latin1(), mCellX, diff, wid, grid); + if ( diff >= wid ) { + // qDebug("KOAgendaItem::resizeMe: diff >= wid: diff %d wid %d ", diff, wid); + //diff = 0; + } + } + if ( wid == width() || diff >= wid ) + resize( wid, hei ); + else + resize( wid - diff, hei ); + return diff; +} /* Return height of item in units of agenda cells */ int KOAgendaItem::cellWidth() { return mCellXWidth - mCellX + 1; } void KOAgendaItem::setItemDate(QDate qd) { mDate = qd; } void KOAgendaItem::setCellXY(int X, int YTop, int YBottom) { mCellX = X; mCellYTop = YTop; mCellYBottom = YBottom; } void KOAgendaItem::setCellXWidth(int xwidth) { mCellXWidth = xwidth; } void KOAgendaItem::setCellX(int XLeft, int XRight) { mCellX = XLeft; mCellXWidth = XRight; } void KOAgendaItem::setCellY(int YTop, int YBottom) { mCellYTop = YTop; mCellYBottom = YBottom; } void KOAgendaItem::setSubCell(int subCell) { mSubCell = subCell; } void KOAgendaItem::setSubCells(int subCells) { mSubCells = subCells; } void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next, KOAgendaItem *last) { mFirstMultiItem = first; mNextMultiItem = next; mLastMultiItem = last; } void KOAgendaItem::startMove() { mStartCellX = mCellX; mStartCellXWidth = mCellXWidth; mStartCellYTop = mCellYTop; mStartCellYBottom = mCellYBottom; } void KOAgendaItem::resetMove() { mCellX = mStartCellX; mCellXWidth = mStartCellXWidth; mCellYTop = mStartCellYTop; mCellYBottom = mStartCellYBottom; } void KOAgendaItem::moveRelative(int dx, int dy) { int newX = cellX() + dx; int newXWidth = cellXWidth() + dx; int newYTop = cellYTop() + dy; int newYBottom = cellYBottom() + dy; setCellXY(newX,newYTop,newYBottom); setCellXWidth(newXWidth); } void KOAgendaItem::expandTop(int dy) { int newYTop = cellYTop() + dy; int newYBottom = cellYBottom(); if (newYTop > newYBottom) newYTop = newYBottom; setCellY(newYTop, newYBottom); } void KOAgendaItem::expandBottom(int dy) { int newYTop = cellYTop(); int newYBottom = cellYBottom() + dy; if (newYBottom < newYTop) newYBottom = newYTop; setCellY(newYTop, newYBottom); } void KOAgendaItem::expandLeft(int dx) { int newX = cellX() + dx; int newXWidth = cellXWidth(); if (newX > newXWidth) newX = newXWidth; setCellX(newX,newXWidth); } void KOAgendaItem::expandRight(int dx) { int newX = cellX(); int newXWidth = cellXWidth() + dx; if (newXWidth < newX) newXWidth = newX; setCellX(newX,newXWidth); } QToolTipGroup *KOAgendaItem::toolTipGroup() { if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); return mToolTipGroup; } void KOAgendaItem::dragEnterEvent( QDragEnterEvent *e ) { #ifndef KORG_NODND if ( ICalDrag::canDecode( e ) || VCalDrag::canDecode( e ) || !QTextDrag::canDecode( e ) ) { e->ignore(); return; } e->accept(); #endif } void KOAgendaItem::dropEvent( QDropEvent *e ) { #ifndef KORG_NODND QString text; if(QTextDrag::decode(e,text)) { kdDebug() << "Dropped : " << text << endl; QStringList emails = QStringList::split(",",text); for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { kdDebug() << " Email: " << (*it) << endl; int pos = (*it).find("<"); QString name = (*it).left(pos); QString email = (*it).mid(pos); if (!email.isEmpty()) { mIncidence->addAttendee(new Attendee(name,email)); } } } #endif } QPtrList<KOAgendaItem> KOAgendaItem::conflictItems() { return mConflictItems; } void KOAgendaItem::setConflictItems(QPtrList<KOAgendaItem> ci) { mConflictItems = ci; KOAgendaItem *item; for ( item=mConflictItems.first(); item != 0; item=mConflictItems.next() ) { item->addConflictItem(this); } } void KOAgendaItem::addConflictItem(KOAgendaItem *ci) { if (mConflictItems.find(ci)<0) mConflictItems.append(ci); } bool KOAgendaItem::checkLayout() { if ( !mConflictItems.count() ) return true; int max = 0; KOAgendaItem *item; for ( item=mConflictItems.first(); item != 0; item=mConflictItems.next() ) { if ( item->subCells() > max ) max = item->subCells(); } if ( max > subCells() ) { setSubCells( max ); return false; } return true; } diff --git a/korganizer/koagendaitem.h b/korganizer/koagendaitem.h index 2b26e95..97acd4c 100644 --- a/korganizer/koagendaitem.h +++ b/korganizer/koagendaitem.h @@ -1,166 +1,167 @@ /* This file is part of KOrganizer. Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef KOAGENDAITEM_H #define KOAGENDAITEM_H #include <qframe.h> #include <qlabel.h> #include <qpixmap.h> #include <qdatetime.h> #include <qpalette.h> #include <libkcal/incidence.h> class KOAgendaItemWhatsThis; class QToolTipGroup; class QDragEnterEvent; class QDropEvent; using namespace KCal; /* The KOAgendaItem has to make sure that it receives all mouse events, which are to be used for dragging and resizing. That means it has to be installed as eventfiler for its children, if it has children, and it has to pass mouse events from the cildren to itself. See eventFilter(). */ class KOAgendaItem : public QWidget { Q_OBJECT public: KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent, bool allday, const char *name=0, WFlags f=0 ); ~KOAgendaItem(); QString getWhatsThisText(); void init ( Incidence *incidence, QDate qd ); int cellX() { return mCellX; } int cellXWidth() { return mCellXWidth; } int cellYTop() { return mCellYTop; } int cellYBottom() { return mCellYBottom; } int cellHeight(); int cellWidth(); int subCell() { return mSubCell; } int subCells() { return mSubCells; } void setCellXY(int X, int YTop, int YBottom); void setCellY(int YTop, int YBottom); void setCellX(int XLeft, int XRight); void setCellXWidth(int xwidth); void setSubCell(int subCell); void setSubCells(int subCells); /** Start movement */ void startMove(); /** Reset to original values */ void resetMove(); void moveRelative(int dx,int dy); void expandTop(int dy); void expandBottom(int dy); void expandLeft(int dx); void expandRight(int dx); int mLastMoveXPos; void setMultiItem(KOAgendaItem *first,KOAgendaItem *next, KOAgendaItem *last); KOAgendaItem *firstMultiItem() { return mFirstMultiItem; } KOAgendaItem *nextMultiItem() { return mNextMultiItem; } KOAgendaItem *lastMultiItem() { return mLastMultiItem; } Incidence *incidence() const { return mIncidence; } QDate itemDate() { return mDate; } /** Update the date of this item's occurence (not in the event) */ void setItemDate(QDate qd); void setText ( const QString & text ) { mDisplayedText = text; } QString text () { return mDisplayedText; } virtual bool eventFilter ( QObject *, QEvent * ); static QToolTipGroup *toolTipGroup(); QPtrList<KOAgendaItem> conflictItems(); void setConflictItems(QPtrList<KOAgendaItem>); void addConflictItem(KOAgendaItem *ci); void paintMe( bool, QPainter* painter = 0 ); void repaintMe(); static QPixmap * paintPix(); static QPixmap * paintPixAllday(); void updateItem(); void computeText(); void recreateIncidence(); bool checkLayout(); void initColor (); bool isAllDay() { return mAllDay; } + int resizeMe( int grid, int wid, int hei ); public slots: bool updateIcons( QPainter *, bool ); void select(bool=true); void repaintItem(); protected: void dragEnterEvent(QDragEnterEvent *e); void dropEvent(QDropEvent *e); void paintEvent ( QPaintEvent * ); void resizeEvent ( QResizeEvent *ev ); private: KOAgendaItemWhatsThis* mKOAgendaItemWhatsThis; bool mAllDay; bool mWhiteText; int mCellX; int mCellXWidth; int mCellYTop,mCellYBottom; int mSubCell; // subcell number of this item int mSubCells; // Total number of subcells in cell of this item int xPaintCoord; int yPaintCoord; int wPaintCoord; int hPaintCoord; // Variables to remember start position int mStartCellX; int mStartCellXWidth; int mStartCellYTop,mStartCellYBottom; int mLastMovePos; // Multi item pointers KOAgendaItem *mFirstMultiItem; KOAgendaItem *mNextMultiItem; KOAgendaItem *mLastMultiItem; int mFontPixelSize; Incidence *mIncidence; // corresponding event or todo QDate mDate; //date this events occurs (for recurrence) //void showIcon( QLabel*, int ); //QLabel *mTodoIconLabel; //QLabel *mItemLabel; //QWidget *mIconBox; //QLabel *mIconAlarm,*mIconRecur,*mIconReadonly; //QLabel *mIconReply,*mIconGroup,*mIconOrganizer; //QLabel *mIconMoreInfo; static QToolTipGroup *mToolTipGroup; QColor mBackgroundColor; QColorGroup mColorGroup; QString mDisplayedText; bool mSelected; QPtrList<KOAgendaItem> mConflictItems; }; #endif // KOAGENDAITEM_H |