-rw-r--r-- | korganizer/koagenda.cpp | 11 | ||||
-rw-r--r-- | korganizer/koagenda.h | 1 | ||||
-rw-r--r-- | korganizer/koagendaitem.cpp | 34 | ||||
-rw-r--r-- | korganizer/koagendaitem.h | 1 | ||||
-rw-r--r-- | korganizer/koagendaview.cpp | 11 | ||||
-rw-r--r-- | korganizer/koagendaview.h | 1 | ||||
-rw-r--r-- | korganizer/koeventpopupmenu.cpp | 44 | ||||
-rw-r--r-- | korganizer/koeventpopupmenu.h | 4 | ||||
-rw-r--r-- | korganizer/koeventview.cpp | 1 | ||||
-rw-r--r-- | korganizer/kolistview.cpp | 8 |
10 files changed, 89 insertions, 27 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp index ce73168..f860f7d 100644 --- a/korganizer/koagenda.cpp +++ b/korganizer/koagenda.cpp @@ -27,769 +27,778 @@ #ifndef _WIN32_ #define protected public #include <qwidget.h> #undef protected #endif #include <qintdict.h> #include <qdatetime.h> #include <qapplication.h> #include <qpopupmenu.h> #include <qcursor.h> #include <qpainter.h> #include <kdebug.h> #include <klocale.h> #include <kiconloader.h> #include <kglobal.h> #include "koagendaitem.h" #include "koprefs.h" #include "koglobals.h" #include "koagenda.h" #include <libkcal/event.h> #include <libkcal/todo.h> #ifndef DESKTOP_VERSION #include <qpe/qpeapplication.h> #endif //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; } int MarcusBains::todayColumn() { QDate currentDate = QDate::currentDate(); DateList dateList = agenda->dateList(); DateList::ConstIterator it; int col = 0; for(it = dateList.begin(); it != dateList.end(); ++it) { if((*it) == currentDate) return KOGlobals::self()->reverseLayout() ? agenda->columns() - 1 - col : col; ++col; } return -1; } void MarcusBains::updateLoc() { updateLocation(); } void MarcusBains::updateLocation(bool recalculate) { QTime tim = QTime::currentTime(); //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1()); if((tim.hour() == 0) && (oldTime.hour()==23)) recalculate = true; int mins = tim.hour()*60 + tim.minute(); int minutesPerCell = 24 * 60 / agenda->rows(); int y = mins*agenda->gridSpacingY()/minutesPerCell; int today = recalculate ? todayColumn() : oldToday; int x = agenda->gridSpacingX()*today; bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled); oldTime = tim; oldToday = today; if(disabled || (today<0)) { hide(); mTimeBox->hide(); return; } else { show(); mTimeBox->show(); } if(recalculate) setFixedSize(agenda->gridSpacingX(),1); agenda->moveChild(this, x, y); raise(); if(recalculate) //mTimeBox->setFont(QFont("helvetica",10)); mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont); mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds)); mTimeBox->adjustSize(); // the -2 below is there because there is a bug in this program // somewhere, where the last column of this widget is a few pixels // narrower than the other columns. int offs = (today==agenda->columns()-1) ? -4 : 0; agenda->moveChild(mTimeBox, x+agenda->gridSpacingX()-mTimeBox->width()+offs-1, y-mTimeBox->height()); mTimeBox->raise(); //mTimeBox->setAutoMask(true); minutes->start(5000,true); } //////////////////////////////////////////////////////////////////////////// /* 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) { mAllAgendaPopup = 0; mColumns = columns; mRows = rows; mGridSpacingY = rowSize; mAllDayMode = false; #ifndef DESKTOP_VERSION //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) { mAllAgendaPopup = 0; 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 ); #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 ); mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("This 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); } 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() { mSelectionCellX = 0; mSelectionYTop = 0; mSelectionHeight = 0; } void KOAgenda::marcus_bains() { if(mMarcusBains) mMarcusBains->updateLocation(true); } void KOAgenda::changeColumns(int columns) { if (columns == 0) { qDebug("KOAgenda::changeColumns() called with argument 0 "); return; } clear(); mColumns = columns; computeSizes(); } /* 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); } } void KOAgenda::popupMenu() { mPopupTimer->stop(); if ( mPopupKind == 1 || mPopupKind == 3 ) { if (mActionItem ) { endItemAction(); } mLeftMouseDown = false; // no more leftMouse computation if (mPopupItem) { //mClickedItem = mPopupItem; selectItem(mPopupItem); if ( mAllAgendaPopup && KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 1 ) mAllAgendaPopup->installEventFilter( this ); emit showIncidencePopupSignal(mPopupItem->incidence()); } } else if ( mPopupKind == 2 || mPopupKind == 4 ) { 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 } if ( KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 2 ) mNewItemPopup->installEventFilter( this ); mNewItemPopup->popup( mPopupPos); } mLeftMouseDown = false; mPopupItem = 0; mPopupKind = 0; } - +void KOAgenda::categoryChanged(Incidence * inc) +{ + KOAgendaItem *item; + for ( item=mItems.first(); item != 0; item=mItems.next() ) { + if ( item->incidence() == inc ) { + item->initColor (); + item->updateItem(); + } + } +} bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) { static int startX = 0; static int startY = 0; int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 7 : 9 ); static bool blockMoving = true; //qDebug("KOAgenda::eventFilter_mous "); if ( object == mNewItemPopup ) { //qDebug("mNewItemPopup "); if ( me->type() == QEvent::MouseButtonRelease ) { mNewItemPopup->removeEventFilter( this ); int dX = me->globalPos().x() - mPopupPos.x();; if ( dX < 0 ) dX = -dX; int dY = me->globalPos().y() - mPopupPos.y(); if ( dY < 0 ) dY = -dY; if ( dX > blockmoveDist || dY > blockmoveDist ) { mNewItemPopup->hide(); } } return true; } if ( object == mAllAgendaPopup ) { //qDebug(" mAllAgendaPopup "); if ( me->type() == QEvent::MouseButtonRelease ) { mAllAgendaPopup->removeEventFilter( this ); int dX = me->globalPos().x() - mPopupPos.x();; if ( dX < 0 ) dX = -dX; int dY = me->globalPos().y() - mPopupPos.y(); if ( dY < 0 ) dY = -dY; if ( dX > blockmoveDist || dY > blockmoveDist ) { mAllAgendaPopup->hide(); } } return true; } QPoint viewportPos; if (object != viewport()) { blockmoveDist = blockmoveDist*2; viewportPos = ((QWidget *)object)->mapToParent(me->pos()); } else { viewportPos = me->pos(); } bool objIsNotViewport = (object != viewport()); bool leftButt = false; #ifdef DESKTOP_VERSION leftButt = (me->button() == LeftButton); #endif switch (me->type()) { case QEvent::MouseButtonPress: if (me->button() == LeftButton) { mPopupTimer->start( 600 ); mLeftMouseDown = true; } blockMoving = true; startX = viewportPos.x(); startY = viewportPos.y(); mPopupPos = me->globalPos(); if ( objIsNotViewport && !leftButt ) { KOAgendaItem * tempItem = (KOAgendaItem *)object; if (mAllDayMode) { if ( tempItem->height() > 10 ) { int minV = tempItem->height()/4; if ( minV > (blockmoveDist/2)-2 ) { if ( minV > blockmoveDist ) minV = blockmoveDist; else minV = (blockmoveDist/2); } bool border = false; int diff = tempItem->y() - viewportPos.y(); if ( diff < 0 ) diff *= -1; if ( diff < minV ) { border = true; objIsNotViewport = false; } if ( ! border ) { diff = tempItem->y() + tempItem->height()- viewportPos.y(); if ( diff < 0 ) diff *= -1; if ( diff < minV ) { border = true; objIsNotViewport = false; } } } } else { // not allday if ( tempItem->width() > 10 ) { int minH = tempItem->width()/4; if ( minH > (blockmoveDist/2)-2 ) { if ( minH > blockmoveDist ) minH = blockmoveDist; else minH = (blockmoveDist/2); } bool border = false; int diff = tempItem->x() - viewportPos.x(); if ( diff < 0 ) diff *= -1; if ( diff < minH ) { border = true; objIsNotViewport = false; } if ( ! border ) { diff = tempItem->x() + tempItem->width() - viewportPos.x(); if ( diff < 0 ) diff *= -1; if ( diff < minH ) { border = true; objIsNotViewport = false; } } } } } if ( objIsNotViewport ) { mPopupItem = (KOAgendaItem *)object; mPopupKind = 1; if (me->button() == RightButton) { mPopupKind = 3; popupMenu(); } else if (me->button() == LeftButton) { mActionItem = (KOAgendaItem *)object; if (mActionItem) { emit signalClearSelection(); slotClearSelection(); selectItem(mActionItem); Incidence *incidence = mActionItem->incidence(); if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { mActionItem = 0; } else { startItemAction(viewportPos); } } } } else { // ---------- viewport() mPopupItem = 0; mPopupKind = 2; selectItem(0); mActionItem = 0; if (me->button() == RightButton) { int x,y; viewportToContents(viewportPos.x(),viewportPos.y(),x,y); int gx,gy; contentsToGrid(x,y,gx,gy); mCurrentCellX = gx; mCurrentCellY = gy; mStartCellX = gx; mStartCellY = gy; mPopupKind = 4; 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: //qDebug("mm "); if ( !mLeftMouseDown ) return false; 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; } void KOAgenda::newItem( int item ) { if ( item == 1 ) { //new event newEventSignal(mStartCellX ,mStartCellY ); } else if ( item == 2 ) { //new event newTodoSignal(mStartCellX ,mStartCellY ); } else { emit showDateView( item, mStartCellX ); // 3Day view // 4Week view // 5Month view // 6Journal view } } void KOAgenda::slotClearSelection() { if (mSelectionHeight) { int selectionX = mSelectionCellX * mGridSpacingX; int top = mSelectionYTop - 2 *mGridSpacingY; int hei = mSelectionHeight + 4 *mGridSpacingY; clearSelection(); repaintContents( selectionX, top, mGridSpacingX, hei ,false ); } } void KOAgenda::startSelectAction(QPoint viewportPos) { emit signalClearSelection(); slotClearSelection(); 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 new selection mSelectionCellX = gx; 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); diff --git a/korganizer/koagenda.h b/korganizer/koagenda.h index fb9983e..de6acac 100644 --- a/korganizer/koagenda.h +++ b/korganizer/koagenda.h @@ -1,300 +1,301 @@ /* This file is part of KOrganizer. Copyright (c) 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. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef KOAGENDA_H #define KOAGENDA_H #include <qscrollview.h> #include <qtimer.h> #include <qmemarray.h> #include <qpainter.h> #include <qpixmap.h> #include <qguardedptr.h> #include "koagendaitem.h" #include "koeventview.h" class QPopupMenu; class QTime; class KConfig; class QFrame; class KOAgenda; class KCal::Event; class KCal::Todo; using namespace KCal; class MarcusBains : public QFrame { Q_OBJECT public: MarcusBains(KOAgenda *agenda=0,const char *name=0); virtual ~MarcusBains(); public slots: void updateLocation(bool recalculate=false); void updateLoc(); private: int todayColumn(); QTimer *minutes; QLabel *mTimeBox; KOAgenda *agenda; QTime oldTime; int oldToday; }; class KOAgenda : public QScrollView { Q_OBJECT public: enum MouseActionType { NOP, MOVE, SELECT, RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT }; KOAgenda ( int columns, int rows, int columnSize, QWidget * parent=0, const char * name=0, WFlags f=0 ); KOAgenda ( int columns, QWidget * parent=0, const char * name=0, WFlags f=0 ); virtual ~KOAgenda(); Incidence *selectedIncidence() const; QDate selectedIncidenceDate() const; virtual bool eventFilter ( QObject *, QEvent * ); void contentsToGrid (int x, int y, int& gx, int& gy); void gridToContents (int gx, int gy, int& x, int& y); int timeToY (const QTime &time); QTime gyToTime (int y); void setStartHour(int startHour); KOAgendaItem *insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom); KOAgendaItem *insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd); void insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, int YTop,int YBottom); void changeColumns(int columns); int columns() { return mColumns; } int rows() { return mRows; } int gridSpacingX() const { return mGridSpacingX; } int gridSpacingY() const { return mGridSpacingY; } // virtual QSizePolicy sizePolicy() const; void clear(); void clearSelection(); void hideUnused(); /** Calculates the minimum width */ virtual int minimumWidth() const; /** Update configuration from preference settings */ void updateConfig(); void checkScrollBoundaries(); 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(); void setPopup( KOEventPopupMenu * p ) { mAllAgendaPopup = p; } public slots: + void categoryChanged(Incidence * inc); void slotClearSelection(); void popupMenu(); 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 signalClearSelection(); void showDateView( int, int); 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: KOEventPopupMenu * mAllAgendaPopup; 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: void init(); void marcus_bains(); bool mAllDayMode; bool blockResize; bool mLeftMouseDown; KOAgendaItem *mPopupItem; QTimer* mPopupTimer; int mPopupKind; QPoint mPopupPos; 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 diff --git a/korganizer/koagendaitem.cpp b/korganizer/koagendaitem.cpp index a8e0678..a42d07b 100644 --- a/korganizer/koagendaitem.cpp +++ b/korganizer/koagendaitem.cpp @@ -1,527 +1,531 @@ /* 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. */ #include <qlabel.h> #include <qlayout.h> #include <qhbox.h> #include <qvbox.h> #include <qtooltip.h> #include <qwhatsthis.h> #include <qdragobject.h> #include <qdrawutil.h> #include <qpainter.h> #include <kiconloader.h> #include <kdebug.h> #include <kglobal.h> #include <klocale.h> #ifndef DESKTOP_VERSION #include <qpe/qpeapplication.h> #define AGENDA_ICON_SIZE 5 #else #include <qapplication.h> #define AGENDA_ICON_SIZE 7 #endif #include <libkcal/icaldrag.h> #include <libkcal/vcaldrag.h> #include <libkcal/kincidenceformatter.h> extern int globalFlagBlockAgenda; extern int globalFlagBlockAgendaItemPaint; extern int globalFlagBlockAgendaItemUpdate; #include "koprefs.h" #include "koagendaitem.h" //#include "koagendaitem.moc" //-------------------------------------------------------------------------- QToolTipGroup *KOAgendaItem::mToolTipGroup = 0; //-------------------------------------------------------------------------- class KOAgendaItemWhatsThis :public QWhatsThis { public: KOAgendaItemWhatsThis( KOAgendaItem* view ) : QWhatsThis( view ),_view (view) { }; protected: virtual QString text( const QPoint& ) { return _view->getWhatsThisText() ; } private: KOAgendaItem * _view; }; KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool allday, const char *name,WFlags) : QWidget(parent, name), mIncidence(incidence), mDate(qd) { #ifndef DESKTOP_VERSION //QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); #endif mKOAgendaItemWhatsThis = new KOAgendaItemWhatsThis(this); int wflags = getWFlags() |WRepaintNoErase;// WResizeNoErase setWFlags ( wflags); mAllDay = allday; init ( incidence, qd ); //setMouseTracking(true); //setAcceptDrops(true); xPaintCoord = -1; yPaintCoord = -1; } QString KOAgendaItem::getWhatsThisText() { if ( mIncidence ) return KIncidenceFormatter::instance()->getFormattedText( mIncidence, KOPrefs::instance()->mWTshowDetails, KOPrefs::instance()->mWTshowCreated, KOPrefs::instance()->mWTshowChanged); return "KOAgendaItem::getWhatsThisText()::internal error"; } -void KOAgendaItem::init ( Incidence *incidence, QDate qd ) + +void KOAgendaItem::initColor () { - mIncidence = incidence; - mDate = qd; - mFirstMultiItem = 0; - mNextMultiItem = 0; - mLastMultiItem = 0; - computeText(); - - if ( (incidence->typeID() == todoID ) && - ( !((static_cast<Todo*>(incidence))->isCompleted()) && - ((static_cast<Todo*>(incidence))->dtDue().date() <= QDate::currentDate()) ) ) { - if ( (static_cast<Todo*>(incidence))->dtDue() < QDateTime::currentDateTime().date()) + if ( (mIncidence->typeID() == todoID ) && + ( !((static_cast<Todo*>(mIncidence))->isCompleted()) && + ((static_cast<Todo*>(mIncidence))->dtDue().date() <= QDate::currentDate()) ) ) { + if ( (static_cast<Todo*>(mIncidence))->dtDue() < QDateTime::currentDateTime().date()) mBackgroundColor = KOPrefs::instance()->mTodoOverdueColor ; else mBackgroundColor = KOPrefs::instance()->mTodoDueTodayColor; } else { QStringList categories = mIncidence->categories(); QString cat = categories.first(); if (cat.isEmpty()) { - if ( (incidence->typeID() == todoID ) &&((static_cast<Todo*>(incidence))->isCompleted()) ) + if ( (mIncidence->typeID() == todoID ) &&((static_cast<Todo*>(mIncidence))->isCompleted()) ) mBackgroundColor =KOPrefs::instance()->mTodoDoneColor; else - mBackgroundColor =KOPrefs::instance()->defaultColor( incidence->calID() ); + mBackgroundColor =KOPrefs::instance()->defaultColor( mIncidence->calID() ); } else { mBackgroundColor = *KOPrefs::instance()->categoryColor(cat); - if ( (incidence->typeID() == todoID ) &&((static_cast<Todo*>(incidence))->isCompleted()) ) { + if ( (mIncidence->typeID() == todoID ) &&((static_cast<Todo*>(mIncidence))->isCompleted()) ) { if ( mBackgroundColor == KOPrefs::instance()->mEventColor ) mBackgroundColor = KOPrefs::instance()->mTodoDoneColor; } } } QColor BackgroundColor ( mBackgroundColor ); if ( mIncidence->calID() > 1 ) { BackgroundColor = KOPrefs::instance()->defaultColor( mIncidence->calID() ); } mColorGroup = QColorGroup( BackgroundColor.light(), BackgroundColor.dark(),BackgroundColor.light(), BackgroundColor.dark(),BackgroundColor, black, BackgroundColor) ; setBackgroundColor( mBackgroundColor ); mWhiteText = (mBackgroundColor.red() + mBackgroundColor.green() + mBackgroundColor.blue() < 250); +} +void KOAgendaItem::init ( Incidence *incidence, QDate qd ) +{ + mIncidence = incidence; + mDate = qd; + mFirstMultiItem = 0; + mNextMultiItem = 0; + mLastMultiItem = 0; + computeText(); + initColor(); mConflictItems.clear(); setCellXY(0,0,1); setCellXWidth(0); setSubCell(0); setSubCells(1); setMultiItem(0,0,0); startMove(); mSelected = true; select(false); QFontMetrics fontinf(KOPrefs::instance()->mAgendaViewFont); mFontPixelSize = fontinf.height();; hide(); xPaintCoord = -1; yPaintCoord = -1; } KOAgendaItem::~KOAgendaItem() { #if QT_VERSION >= 0x030000 #else delete mKOAgendaItemWhatsThis; #endif } void KOAgendaItem::recreateIncidence() { #if 0 Incidence* newInc = mIncidence->clone(); newInc->recreate(); if ( mIncidence->doesRecur() ) { mIncidence->addExDate( mDate ); newInc->recurrence()->unsetRecurs(); int len = mIncidence->dtStart().secsTo( ((Event*)mIncidence)->dtEnd()); QTime tim = mIncidence->dtStart().time(); newInc->setDtStart( QDateTime(mDate, tim) ); ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); } #endif mIncidence = mIncidence->recreateCloneException( mDate ); } bool KOAgendaItem::updateIcons(QPainter * p, bool horLayout) { int size = AGENDA_ICON_SIZE; int yOff = 0; int xOff = 0; int x = pos().x() +3; int y; if ( mAllDay ) y = pos().y()+3; else y = mCellYTop * ( height() / cellHeight() ) +3; if (mIncidence->cancelled()) { int xpos = xOff*( 1 +AGENDA_ICON_SIZE )+x; int ypos = yOff*( 1 +AGENDA_ICON_SIZE)+y; p->drawLine( xpos, ypos, xpos+AGENDA_ICON_SIZE-1, ypos+AGENDA_ICON_SIZE-1 ); p->drawLine( xpos, ypos+AGENDA_ICON_SIZE-1, xpos+AGENDA_ICON_SIZE-1, ypos ); if ( horLayout ) ++xOff; else ++yOff; } if (mIncidence->isAlarmEnabled() && mIncidence->alarmEnabled()) { p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, red ); if ( horLayout ) ++xOff; else ++yOff; } if (mIncidence->recurrence()->doesRecur()) { p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, blue ); if ( horLayout ) ++xOff; else ++yOff; } if (mIncidence->description().length() > 0) { p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkGreen ); if ( horLayout ) ++xOff; else ++yOff; } if (mIncidence->isReadOnly()) { p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, white ); if ( horLayout ) ++xOff; else ++yOff; } if (mIncidence->attendeeCount()>0) { if (mIncidence->organizer() == KOPrefs::instance()->email()) { p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, black ); if ( horLayout ) ++xOff; else ++yOff; } else { Attendee *me = mIncidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); if (me!=0) { } else { p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, yellow ); if ( horLayout ) ++xOff; else ++yOff; } p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkYellow ); if ( horLayout ) ++xOff; else ++yOff; } } return ( yOff || xOff ); } void KOAgendaItem::select(bool selected) { //qDebug("select %d %d",firstMultiItem(), nextMultiItem() ); if (mSelected == selected) return; mSelected = selected; if ( ! isVisible() ) return; if ( firstMultiItem() ) firstMultiItem()->select( selected ); if ( !firstMultiItem() && nextMultiItem() ) { KOAgendaItem * placeItem = nextMultiItem(); while ( placeItem ) { placeItem->select( selected ); placeItem = placeItem->nextMultiItem(); } } globalFlagBlockAgendaItemUpdate = 0; paintMe( selected ); globalFlagBlockAgendaItemUpdate = 1; repaint( false ); } /* The eventFilter has to filter the mouse events of the agenda item childs. The events are fed into the event handling method of KOAgendaItem. This allows the KOAgenda to handle the KOAgendaItems by using an eventFilter. */ bool KOAgendaItem::eventFilter ( QObject *object, QEvent *e ) { if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonDblClick || e->type() == QEvent::MouseButtonRelease || e->type() == QEvent::MouseMove) { QMouseEvent *me = (QMouseEvent *)e; QPoint itemPos = this->mapFromGlobal(((QWidget *)object)-> mapToGlobal(me->pos())); QMouseEvent returnEvent (e->type(),itemPos,me->button(),me->state()); return event(&returnEvent); } else { return false; } } void KOAgendaItem::repaintMe( ) { paintMe ( mSelected ); } void KOAgendaItem::paintMe( bool selected, QPainter* paint ) { if ( globalFlagBlockAgendaItemUpdate && ! selected) return; QPainter pa; if ( mSelected ) { pa.begin( paintPixSel() ); } else { if ( mAllDay ) pa.begin( paintPixAllday() ); else pa.begin( paintPix() ); } int x, yy, w, h; float nfh = 7.0; x = pos().x(); w = width(); h = height (); if ( mAllDay ) yy = y(); else yy = mCellYTop * ( height() / cellHeight() ); xPaintCoord= x; yPaintCoord = yy; wPaintCoord = width(); hPaintCoord = height(); //qDebug("paintMe %s %d %d %d %d",incidence()->summary().latin1(), x, yy, width(), height()); if ( paint == 0 ) paint = &pa; bool horLayout = ( w < h ); int maxhei = mFontPixelSize+4; if ( horLayout ) maxhei += AGENDA_ICON_SIZE -4; bool small = ( h < maxhei ); if ( ! small ) paint->setFont(KOPrefs::instance()->mAgendaViewFont); else { QFont f = KOPrefs::instance()->mAgendaViewFont; f.setBold( false ); int fh = f.pointSize(); nfh = (((float)height())/(float)(mFontPixelSize+4))*fh; if ( nfh < 6 ) nfh = 6; f.setPointSize( nfh ); paint->setFont(f); } paint->fillRect ( x, yy, w, h, mBackgroundColor ); static const QPixmap completedPxmp = SmallIcon("greenhook16"); static const QPixmap overduePxmp = SmallIcon("redcross16"); if ( mIncidence->typeID() == todoID ) { Todo* tempTodo = static_cast<Todo*>(mIncidence); int xx = pos().x()+(width()-completedPxmp.width()-3 ); int yyy = yy+3; if ( tempTodo->isCompleted() ) paint->drawPixmap ( xx, yyy, completedPxmp ); else { paint->drawPixmap ( xx, yyy, overduePxmp ); } } bool addIcon = false; if ( ! small || w > 3 * h || h > 3* w ) addIcon = updateIcons( paint, horLayout ); //qDrawShadePanel (paint, x, yy, w, h, mColorGroup, selected , 2, 0); qDrawWinPanel (paint, x, yy, w, h, mColorGroup, selected ,0); //qDebug("draw rect %d %d %d %d ",x, yy, w, h ); if ( ! small ) { x += 3; yy += 3;w -= 6; h-= 5; } else { x += 2; yy += 1;w -= 4; h-= 4; if ( nfh < 6.01 ) { yy -= 2; h += 4; } else if ( nfh < h -2 ) ++yy; } int align; #ifndef DESKTOP_VERSION align = ( AlignLeft|WordBreak|AlignTop); #else align = ( AlignLeft|BreakAnywhere|WordBreak|AlignTop); #endif if ( addIcon ) { if ( ! horLayout ) { x += AGENDA_ICON_SIZE+3; w -= (AGENDA_ICON_SIZE+3); } else { yy+= AGENDA_ICON_SIZE+2; h -=(AGENDA_ICON_SIZE+3); } } if ( mWhiteText ) paint->setPen ( white); if ( x < 0 ) { w = w+x-3; x = 3; if ( w > parentWidget()->width() ){ w = parentWidget()->width() - 6; #ifndef DESKTOP_VERSION align = ( AlignHCenter|WordBreak|AlignTop); #else align = ( AlignHCenter|BreakAnywhere|WordBreak|AlignTop); #endif } } QRect dr; if ( w + x > parentWidget()->width() ) w = parentWidget()->width()-x; paint->drawText ( x, yy, w, h, align, mDisplayedText, -1, &dr ); //qDebug("%d %d %d %d ", x, yy, w, h ); if ( mIncidence->cancelled() ){ small = ( height() < 20 ); if ( ! small ) { QFontMetrics fm ( paint->font() ); paint->drawLine(dr.left(), yy+fm.height()/2, dr.right()-2, yy+fm.height()/2); } } pa.end(); } void KOAgendaItem::resizePixmap( int w , int h ) { paintPix()->resize( w, h ); paintPixSel()->resize( w, h ); } 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()/3; mPaintPixA = new QPixmap(w,h); } return mPaintPixA ; } QPixmap * KOAgendaItem::paintPixSel() { static QPixmap* mPaintPixSel = 0; if ( ! mPaintPixSel ) { int w = QApplication::desktop()->width(); int h = QApplication::desktop()->height(); mPaintPixSel = new QPixmap(w,h); } return mPaintPixSel ; } 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; } 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 ) { paintFrom = paintPixSel(); } else { if ( mAllDay ) paintFrom = paintPixAllday(); else paintFrom = paintPix(); } xx += rx; if ( xx < 0 ) { rw = rw + xx; diff --git a/korganizer/koagendaitem.h b/korganizer/koagendaitem.h index d1b1940..dc2316a 100644 --- a/korganizer/koagendaitem.h +++ b/korganizer/koagendaitem.h @@ -1,165 +1,166 @@ /* 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 void resizePixmap( int, int ); static QPixmap * paintPix(); static QPixmap * paintPixSel(); static QPixmap * paintPixAllday(); void updateItem(); void computeText(); void recreateIncidence(); bool checkLayout(); + void initColor (); public slots: bool updateIcons( QPainter *, bool ); void select(bool=true); 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 diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp index c851ab5..a42227c 100644 --- a/korganizer/koagendaview.cpp +++ b/korganizer/koagendaview.cpp @@ -93,883 +93,892 @@ TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : setHScrollBarMode(AlwaysOff); setVScrollBarMode(AlwaysOff); resizeContents(50,mRows * mCellHeight); viewport()->setBackgroundMode( PaletteBackground ); } void TimeLabels::setCellHeight(int height) { mCellHeight = height; } /* Optimization so that only the "dirty" portion of the scroll view is redrawn. Unfortunately, this is not called by default paintEvent() method. */ void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) { cx = contentsX() + frameWidth()*2; cw = contentsWidth() ; // end of workaround int cell = ((int)(cy/mCellHeight)); int y = cell * mCellHeight; QFontMetrics fm = fontMetrics(); QString hour; QString suffix = "am"; int timeHeight = fm.ascent(); QFont nFont = font(); p->setFont( font()); if (!KGlobal::locale()->use12Clock()) { suffix = "00"; } else if (cell > 11) suffix = "pm"; if ( timeHeight > mCellHeight ) { timeHeight = mCellHeight-1; int pointS = nFont.pointSize(); while ( pointS > 4 ) { nFont.setPointSize( pointS ); fm = QFontMetrics( nFont ); if ( fm.ascent() < mCellHeight ) break; -- pointS; } fm = QFontMetrics( nFont ); timeHeight = fm.ascent(); } //timeHeight -= (timeHeight/4-2); QFont sFont = nFont; sFont.setPointSize( sFont.pointSize()/2 ); QFontMetrics fmS( sFont ); int sHei = fmS.ascent() ; //sHei -= (sHei/4-2); int startW = mMiniWidth - frameWidth()-2 ; int tw2 = fmS.width(suffix); timeHeight = (timeHeight-1) /2 -1; //testline //p->drawLine(0,0,0,contentsHeight()); while (y < cy + ch+mCellHeight) { p->drawLine(startW-tw2+1 ,y,cw+2,y); hour.setNum(cell); // handle 24h and am/pm time formats if (KGlobal::locale()->use12Clock()) { if (cell == 12) suffix = "pm"; if (cell == 0) hour.setNum(12); if (cell > 12) hour.setNum(cell - 12); } // center and draw the time label int timeWidth = fm.width(hour); int offset = startW - timeWidth - tw2 -1 ; p->setFont( nFont ); p->drawText( offset, y+ timeHeight, hour); p->setFont( sFont ); offset = startW - tw2; p->drawText( offset, y -1, suffix); // increment indices y += mCellHeight; cell++; } } /** Calculates the minimum width. */ int TimeLabels::minimumWidth() const { return mMiniWidth; } /** updates widget's internal state */ void TimeLabels::updateConfig() { mRedrawNeeded = true; // set the font // config->setGroup("Fonts"); // QFont font = config->readFontEntry("TimeBar Font"); setFont(KOPrefs::instance()->mTimeBarFont); QString test = "20"; if (KGlobal::locale()->use12Clock()) test = "12"; mMiniWidth = fontMetrics().width(test); if (KGlobal::locale()->use12Clock()) test = "pm"; else { test = "00"; } QFont sFont = font(); sFont.setPointSize( sFont.pointSize()/2 ); QFontMetrics fmS( sFont ); mMiniWidth += fmS.width( test ) + frameWidth()*2+4 ; // update geometry restrictions based on new settings setFixedWidth( mMiniWidth ); // update HourSize mCellHeight = KOPrefs::instance()->mHourSize*4; resizeContents(mMiniWidth,mRows * mCellHeight+1); } /** update time label positions */ void TimeLabels::positionChanged() { int adjustment = mAgenda->contentsY(); setContentsPos(0, adjustment); } /** */ void TimeLabels::setAgenda(KOAgenda* agenda) { mAgenda = agenda; } void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) { mMouseDownY = e->pos().y(); mOrgCap = topLevelWidget()->caption(); } void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) { int diff = mMouseDownY - e->pos().y(); if ( diff < 10 && diff > -10 ) return; int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; if ( tSize < 4 ) tSize = 4; if ( tSize > 22 ) tSize = 22; tSize = (tSize-2)/2; topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); } void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) { topLevelWidget()->setCaption( mOrgCap ); int diff = mMouseDownY - e->pos().y(); if ( diff < 10 && diff > -10 ) return; int tSize = KOPrefs::instance()->mHourSize + (diff/10); if ( tSize < 4 ) tSize = 4; if ( tSize > 22 ) tSize = 22; tSize = (tSize/2)*2; if ( tSize == KOPrefs::instance()->mHourSize ) return; KOPrefs::instance()->mHourSize = tSize; emit scaleChanged(); } /** This is called in response to repaint() */ void TimeLabels::paintEvent(QPaintEvent*) { // kdDebug() << "paintevent..." << endl; // this is another hack! // QPainter painter(this); //QString c repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight()); } //////////////////////////////////////////////////////////////////////////// EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name) : QFrame(parent,name) { mColumns = 1; mTopBox = 0; mLocation = loc; mTopLayout = 0; mPaintWidget = 0; mXOffset = 0; if (mLocation == Top) mPixmap = SmallIcon("1uparrow"); else mPixmap = SmallIcon("1downarrow"); mEnabled.resize(mColumns); mEnabled.fill( false ); setMinimumHeight(mPixmap.height()); } EventIndicator::~EventIndicator() { } void EventIndicator::drawContents(QPainter *p) { // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl; KDGanttSplitterHandle* han = 0; if ( mPaintWidget ) han = mPaintWidget->firstHandle(); if ( ! han ) { int i; for(i=0;i<mColumns;++i) { if (mEnabled[i]) { int cellWidth = contentsRect().right()/mColumns; int xOffset = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - i)*cellWidth + (cellWidth -mPixmap.width())/2 : i*cellWidth + (cellWidth -mPixmap.width()) /2; p->drawPixmap(QPoint(1+xOffset,0),mPixmap); } } } else { han->repaint(); //mPaintWidget->setBackgroundColor( red ); QPainter pa( han ); int i; bool setColor = false; for(i=0;i<mColumns;++i) { if (mEnabled[i]) { setColor = true; int cellWidth = contentsRect().right()/mColumns; int xOffset = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : i*cellWidth + cellWidth/2 -mPixmap.width()/2; pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap); //qDebug("222draw pix %d ",xOffset ); } } pa.end(); } } void EventIndicator::setXOffset( int x ) { mXOffset = x; } void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w ) { mPaintWidget = w; setMaximumHeight(0); setMinimumHeight(0); } void EventIndicator::changeColumns(int columns) { mColumns = columns; mEnabled.resize(mColumns); update(); } void EventIndicator::enableColumn(int column, bool enable) { mEnabled[column] = enable; } //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) : KOEventView (cal,parent,name) { mBlockUpdating = true; mStartHour = 8; mSelectedDates.append(QDate::currentDate()); mLayoutDayLabels = 0; mDayLabelsFrame = 0; mDayLabels = 0; bool isRTL = KOGlobals::self()->reverseLayout(); QPixmap expandPix; if ( KOPrefs::instance()->mVerticalScreen ) { expandPix = SmallIcon( "1updownarrow" ); } else { expandPix = SmallIcon("1leftrightarrow" ); } QBoxLayout *topLayout = new QVBoxLayout(this); // Create day name labels for agenda columns // Create agenda splitter mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this); mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); topLayout->addWidget( mSplitterAgenda ); mAllDayFrame = new QHBox(mSplitterAgenda); mAllDayFrame->setFocusPolicy(NoFocus); QWidget *agendaFrame = new QWidget(mSplitterAgenda); agendaFrame->setFocusPolicy(NoFocus); // Create all-day agenda widget mDummyAllDayLeft = new QVBox( mAllDayFrame ); mExpandButton = new QPushButton(mDummyAllDayLeft); mExpandButton->setPixmap( expandPix ); int widebut = mExpandButton->sizeHint().width()+4; int heibut = mExpandButton->sizeHint().height()+4; if ( heibut > widebut ) widebut = heibut ; //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, // QSizePolicy::Fixed ) ); mExpandButton->setFixedSize( widebut, widebut); connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) ); mExpandButton->setFocusPolicy(NoFocus); mAllDayAgenda = new KOAgenda(1,mAllDayFrame); mAllDayAgenda->setFocusPolicy(NoFocus); QLabel *dummyAllDayRight = new QLabel (mAllDayFrame); // Create event context menu for all day agenda //mAllDayAgendaPopup = eventPopup(); // Create agenda frame QGridLayout *agendaLayout = new QGridLayout(agendaFrame,4,3); // QHBox *agendaFrame = new QHBox(splitterAgenda); // create event indicator bars mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame); #ifndef DESKTOP_VERSION mEventIndicatorTop->setPaintWidget( mSplitterAgenda ); #endif mDayLabelsFrame = new QHBox(agendaFrame); //topLayout->addWidget(mDayLabelsFrame); mDayLabels = new QFrame (mDayLabelsFrame); mLayoutDayLabels = new QHBoxLayout(mDayLabels); agendaLayout->addMultiCellWidget(mDayLabelsFrame ,0,0,0,2); agendaLayout->addWidget(mEventIndicatorTop,1,1); mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom, agendaFrame); agendaLayout->addWidget(mEventIndicatorBottom,3,1); QWidget *dummyAgendaRight = new QWidget(agendaFrame); agendaLayout->addWidget(dummyAgendaRight,1,2); // Create time labels mTimeLabels = new TimeLabels(24,agendaFrame); agendaLayout->addWidget(mTimeLabels,2,0); connect(mTimeLabels,SIGNAL( scaleChanged()), this,SLOT(updateConfig())); // Create agenda mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame); agendaLayout->addMultiCellWidget(mAgenda,2,2,1,2); agendaLayout->setColStretch(1,1); mAgenda->setFocusPolicy(NoFocus); // Create event context menu for agenda mAllAgendaPopup = eventPopup(); #if 0 mAllAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")), i18n("Toggle Alarm"),mAgenda, SLOT(popupAlarm()),true); #endif connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), mAllAgendaPopup,SLOT(showIncidencePopup(Incidence *))); connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), mAllAgendaPopup,SLOT(showIncidencePopup(Incidence *))); + + connect(mAllAgendaPopup,SIGNAL(categoryChanged(Incidence *)), + this,SLOT(categoryChanged(Incidence *))); + + mAgenda->setPopup( mAllAgendaPopup ); mAllDayAgenda->setPopup( mAllAgendaPopup ); // make connections between dependent widgets mTimeLabels->setAgenda(mAgenda); // Update widgets to reflect user preferences // updateConfig(); // createDayLabels(); // these blank widgets make the All Day Event box line up with the agenda dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); // Scrolling connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)), mTimeLabels, SLOT(positionChanged())); connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)), SLOT(setContentsPos(int))); connect(mAgenda,SIGNAL(showDateView( int, int)),SLOT(slotShowDateView( int, int ))); connect(mAllDayAgenda,SIGNAL(showDateView( int, int )), SLOT(slotShowDateView( int, int ) )); // Create/Show/Edit/Delete Event connect(mAgenda,SIGNAL(newEventSignal(int,int)), SLOT(newEvent(int,int))); connect(mAgenda,SIGNAL(newTodoSignal(int,int)), SLOT(newTodo(int,int))); connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)), SLOT(newEvent(int,int,int,int))); connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)), SLOT(newEventAllDay(int,int))); connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)), SLOT(newTodoAllDay(int,int))); connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)), SLOT(newEventAllDay(int,int))); connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), SLOT(newTimeSpanSelected(int,int,int,int))); connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), SLOT(newTimeSpanSelectedAllDay(int,int,int,int))); connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)), SIGNAL(editIncidenceSignal(Incidence *))); connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)), SIGNAL(editIncidenceSignal(Incidence *))); connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)), SIGNAL(showIncidenceSignal(Incidence *))); connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)), SIGNAL(showIncidenceSignal(Incidence *))); connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), SIGNAL(deleteIncidenceSignal(Incidence *))); connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), SIGNAL(deleteIncidenceSignal(Incidence *))); connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), SLOT(updateEventDates(KOAgendaItem *, int ))); connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), SLOT(updateEventDates(KOAgendaItem *, int))); // event indicator update connect(mAgenda,SIGNAL(lowerYChanged(int)), SLOT(updateEventIndicatorTop(int))); connect(mAgenda,SIGNAL(upperYChanged(int)), SLOT(updateEventIndicatorBottom(int))); // drag signals /* connect(mAgenda,SIGNAL(startDragSignal(Event *)), SLOT(startDrag(Event *))); connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)), SLOT(startDrag(Event *))); */ // synchronize selections connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), mAllDayAgenda, SLOT( deselectItem() ) ); connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), mAgenda, SLOT( deselectItem() ) ); connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), SIGNAL( incidenceSelected( Incidence * ) ) ); connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), SIGNAL( incidenceSelected( Incidence * ) ) ); connect( mAgenda, SIGNAL( resizedSignal() ), SLOT( updateConfig( ) ) ); connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ), SLOT( addToCalSlot(Incidence *, Incidence * ) ) ); connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ), SLOT( addToCalSlot(Incidence * , Incidence *) ) ); // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); connect( mAllDayAgenda, SIGNAL( signalClearSelection() ),mAgenda, SLOT( slotClearSelection()) ); connect( mAgenda, SIGNAL( signalClearSelection() ),mAllDayAgenda, SLOT( slotClearSelection()) ); } void KOAgendaView::toggleAllDay() { if ( mSplitterAgenda->firstHandle() ) mSplitterAgenda->firstHandle()->toggle(); } void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld ) { calendar()->addIncidence( inc ); if ( incOld ) { if ( incOld->typeID() == todoID ) emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED ); else emit incidenceChanged(incOld, KOGlobals::EVENTEDITED); } } - +void KOAgendaView::categoryChanged(Incidence * inc) +{ + mAgenda->categoryChanged( inc ); + mAllDayAgenda->categoryChanged( inc ); +} KOAgendaView::~KOAgendaView() { delete mAllAgendaPopup; //delete mAllDayAgendaPopup; delete KOAgendaItem::paintPix(); delete KOAgendaItem::paintPixSel(); } void KOAgendaView::resizeEvent( QResizeEvent* e ) { //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); bool uc = false; int ow = e->oldSize().width(); int oh = e->oldSize().height(); int w = e->size().width(); int h = e->size().height(); if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) uc = true; //qDebug("view changed %d %d %d %d ", ow, oh , w , h); } mUpcomingWidth = e->size().width() ; if ( mBlockUpdating || uc ) { mBlockUpdating = false; //mAgenda->setMinimumSize(800 , 600 ); //qDebug("mAgenda->resize+++++++++++++++ "); updateConfig(); //qDebug("KOAgendaView::Updating now possible "); } else createDayLabels(); //qDebug("resizeEvent end "); } void KOAgendaView::slotDaylabelClicked( int num ) { QDate firstDate = mSelectedDates.first(); if ( num == -1 ) emit showDateView( 6, firstDate ); else if (num >= 0 ) { if ( mSelectedDates.count() == 1) emit showDateView( 9, firstDate.addDays( num ) ); else emit showDateView( 3, firstDate.addDays( num ) ); } else showDateView( 10, firstDate.addDays(1) ); } KOAgendaButton* KOAgendaView::getNewDaylabel() { KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels); connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) ); mDayLabelsList.append( dayLabel ); mLayoutDayLabels->addWidget(dayLabel); return dayLabel ; } void KOAgendaView::createDayLabels() { if ( mBlockUpdating || globalFlagBlockLabel == 1) { // qDebug(" KOAgendaView::createDayLabels() blocked "); return; } int newHight; if ( !mSelectedDates.count()) return; // ### Before deleting and recreating we could check if mSelectedDates changed... // It would remove some flickering and gain speed (since this is called by // each updateView() call) int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - mAgenda->frameWidth()*2; mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); if ( maxWid < 20 ) maxWid = 20; QFont dlf = KOPrefs::instance()->mTimeLabelsFont; QFontMetrics fm ( dlf ); dlf.setBold( true ); int selCount = mSelectedDates.count(); int widModulo = maxWid - (mAgenda->gridSpacingX() * selCount)+1; QString dayTest = "Mon 20"; //QString dayTest = "Mon 20"; int wid = fm.width( dayTest ); //maxWid -= ( selCount * 3 ); //working for QLabels if ( QApplication::desktop()->width() <= 320 ) maxWid -= ( selCount * 3 ); //working for QPushButton else maxWid -= ( selCount * 4 ); //working for QPushButton if ( maxWid < 0 ) maxWid = 20; int needWid = wid * selCount; //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); //if ( needWid > maxWid ) // qDebug("DAYLABELS TOOOOOOO BIG "); while ( needWid > maxWid ) { dayTest = dayTest.left( dayTest.length() - 1 ); wid = fm.width( dayTest ); needWid = wid * selCount; } int maxLen = dayTest.length(); int fontPoint = dlf.pointSize(); if ( maxLen < 2 ) { int fontPoint = dlf.pointSize(); while ( fontPoint > 4 ) { --fontPoint; dlf.setPointSize( fontPoint ); QFontMetrics f( dlf ); wid = f.width( "30" ); needWid = wid * selCount; if ( needWid < maxWid ) break; } maxLen = 2; } //qDebug("Max len %d ", dayTest.length() ); if ( !KOPrefs::instance()->mTimeLabelsFont.bold() ) dlf.setBold( false ); QFontMetrics tempF( dlf ); newHight = tempF.height(); mDayLabels->setFont( dlf ); // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; // mLayoutDayLabels->addSpacing(mTimeLabels->width()); //mLayoutDayLabels->addSpacing( 2 ); // QFont lFont = dlf; bool appendLabels = false; KOAgendaButton *dayLabel; dayLabel = mDayLabelsList.first(); if ( !dayLabel ) { appendLabels = true; dayLabel = getNewDaylabel(); } dayLabel->setFixedWidth( mTimeLabels->width()+mAgenda->frameWidth() ); dayLabel->setFont( dlf ); dayLabel->setNum( -1 ); //dayLabel->setAlignment(QLabel::AlignHCenter); dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); dayLabel->show(); DateList::ConstIterator dit; bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); int counter = -1; for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { ++counter; QDate date = *dit; // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); if ( ! appendLabels ) { dayLabel = mDayLabelsList.next(); if ( !dayLabel ) appendLabels = true; } if ( appendLabels ) { dayLabel = getNewDaylabel(); } dayLabel->setMinimumWidth( 1 ); dayLabel->setMaximumWidth( 10240 ); dayLabel->setFont( dlf ); dayLabel->show(); dayLabel->setAutoRepeat( false ); dayLabel->setNum( counter ); QString str; int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date); QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true ); switch ( maxLen ) { case 2: str = QString::number( date.day() ); break; case 3: str = dayName.left( 1 ) +QString::number( date.day()); break; case 4: str = dayName.left( 1 ) + " " +QString::number( date.day()); break; case 5: str = dayName.left( 2 ) + " " +QString::number( date.day()); break; case 6: str = dayName.left( 3 ) + " " +QString::number( date.day()); break; default: break; } if ( oneday ) { QString addString; if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) addString = i18n("Today"); else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) addString = i18n("Tomorrow"); else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) addString = i18n("Yesterday"); else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) addString = i18n("Day before yesterday"); else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) addString = i18n("Day after tomorrow"); if ( !addString.isEmpty() ) { str = addString+", " + str; } else { str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer); } } dayLabel->setText(str); //dayLabel->setAlignment(QLabel::AlignHCenter); if (date == QDate::currentDate()) { QFont bFont = dlf; bFont.setBold( true ); dayLabel->setFont(bFont); } //dayLayout->addWidget(dayLabel); #ifndef KORG_NOPLUGINS CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); CalendarDecoration *it; for(it = cds.first(); it; it = cds.next()) { QString text = it->shortText( date ); if ( !text.isEmpty() ) { QLabel *label = new QLabel(text,mDayLabels); label->setAlignment(AlignCenter); dayLayout->addWidget(label); } } for(it = cds.first(); it; it = cds.next()) { QWidget *wid = it->smallWidget(mDayLabels,date); if ( wid ) { // wid->setHeight(20); dayLayout->addWidget(wid); } } #endif } if ( ! appendLabels ) { dayLabel = mDayLabelsList.next(); if ( !dayLabel ) appendLabels = true; } if ( appendLabels ) { dayLabel = getNewDaylabel(); } //dayLabel->hide();//test only dayLabel->setText(">"); dayLabel->setFont( dlf ); dayLabel->setAutoRepeat( true ); dayLabel->show(); dayLabel->setNum( -2 ); dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ widModulo ); //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); if ( !appendLabels ) { dayLabel = mDayLabelsList.next(); while ( dayLabel ) { //qDebug("!dayLabel %d",dayLabel ); dayLabel->hide(); dayLabel = mDayLabelsList.next(); } } mDayLabelsFrame->setFixedHeight( newHight + 4 ); } int KOAgendaView::maxDatesHint() { // Not sure about the max number of events, so return 0 for now. return 0; } int KOAgendaView::currentDateCount() { return mSelectedDates.count(); } QPtrList<Incidence> KOAgendaView::selectedIncidences() { QPtrList<Incidence> selected; Incidence *incidence; incidence = mAgenda->selectedIncidence(); if (incidence) selected.append(incidence); incidence = mAllDayAgenda->selectedIncidence(); if (incidence) selected.append(incidence); return selected; } DateList KOAgendaView::selectedDates() { DateList selected; QDate qd; qd = mAgenda->selectedIncidenceDate(); if (qd.isValid()) selected.append(qd); qd = mAllDayAgenda->selectedIncidenceDate(); if (qd.isValid()) selected.append(qd); return selected; } void KOAgendaView::updateView() { if ( mBlockUpdating ) return; // kdDebug() << "KOAgendaView::updateView()" << endl; fillAgenda(); } /* Update configuration settings for the agenda view. This method is not complete. */ void KOAgendaView::updateConfig() { if ( mBlockUpdating ) return; if ( mAgenda->height() > 96 * KOPrefs::instance()->mHourSize ) { int old = KOPrefs::instance()->mHourSize; KOPrefs::instance()->mHourSize = mAgenda->height()/96 +1; //qDebug("KOPrefs::instance()->mHourSize adjusted %d to %d ", old,KOPrefs::instance()->mHourSize ); } // update config for children mTimeLabels->updateConfig(); mAgenda->storePosition(); mAgenda->updateConfig(); mAllDayAgenda->updateConfig(); // widget synchronization //TODO: find a better way, maybe signal/slot mTimeLabels->positionChanged(); // for some reason, this needs to be called explicitly mTimeLabels->repaint(); mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); // ToolTips displaying summary of events KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance() ->mEnableToolTips); //setHolidayMasks(); //createDayLabels(); called by via updateView(); mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth()); updateView(); mAgenda->restorePosition(); } void KOAgendaView::updateEventDates(KOAgendaItem *item, int type) { int xxx = item->cellX(); //qDebug("KOAgendaView::updateEventDates %d %d %d %d %d", xxx, mMinY.at(xxx),mMaxY.at(xxx),item->cellYTop(),item->cellYBottom() ); if ( mMinY.at(xxx) > item->cellYTop() ) mMinY.at(xxx) = item->cellYTop(); if ( mMaxY.at(xxx) < item->cellYBottom() ) mMaxY.at(xxx) = item->cellYBottom(); QDateTime startDt,endDt; QDate startDate; int lenInSecs; // if ( type == KOAgenda::RESIZETOP ) // qDebug("RESIZETOP "); // if ( type == KOAgenda::RESIZEBOTTOM ) // qDebug("RESIZEBOTTOM "); // if ( type == KOAgenda::MOVE ) // qDebug("MOVE "); if ( item->incidence()->typeID() == eventID ) { startDt =item->incidence()->dtStart(); endDt = item->incidence()->dtEnd(); lenInSecs = startDt.secsTo( endDt ); diff --git a/korganizer/koagendaview.h b/korganizer/koagendaview.h index cc953fc..a1cf308 100644 --- a/korganizer/koagendaview.h +++ b/korganizer/koagendaview.h @@ -1,293 +1,294 @@ /* 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. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef KOAGENDAVIEW_H #define KOAGENDAVIEW_H #include <qscrollview.h> #include <qdatetime.h> #include <qpushbutton.h> #include <qlayout.h> #ifndef DESKTOP_VERSION #include <qksplitter.h> #else #include <qsplitter.h> #endif #include <qmemarray.h> #include "koeventview.h" class QHBox; class QFrame; class QLabel; class QPushButton; class CalendarView; class KOAgenda; class KOAgendaItem; class KConfig; class KDGanttMinimizeSplitter; class KOAgendaButton : public QPushButton { Q_OBJECT public: KOAgendaButton( QWidget *parent=0, const char *name=0 ) : QPushButton( parent, name ) { mNum = -3; setFlat( true ); setFocusPolicy(NoFocus); setSizePolicy(QSizePolicy( QSizePolicy::Expanding ,QSizePolicy::Expanding )); connect( this, SIGNAL( clicked() ), this, SLOT ( bClicked() ) ); }; QSize sizeHint () const { return QSize( 5,5) ;} void setNum( int n) { mNum = n; } private slots: void bClicked() {emit numClicked( mNum);} signals: void numClicked( int ); private: int mNum; }; class TimeLabels : public QScrollView { Q_OBJECT public: TimeLabels(int rows,QWidget *parent=0,const char *name=0,WFlags f=0); void setCellHeight(int height); /** Calculates the minimum width */ virtual int minimumWidth() const; /** updates widget's internal state */ void updateConfig(); /** */ void setAgenda(KOAgenda* agenda); /** */ virtual void paintEvent(QPaintEvent* e); void contentsMousePressEvent ( QMouseEvent * ) ; void contentsMouseReleaseEvent ( QMouseEvent * ); void contentsMouseMoveEvent ( QMouseEvent * ); public slots: /** update time label positions */ void positionChanged(); signals: void scaleChanged(); protected: void drawContents(QPainter *p,int cx, int cy, int cw, int ch); private: QPixmap myPix; bool mRedrawNeeded; int mMiniWidth; int mMouseDownY; QString mOrgCap; int mRows; int mCellHeight; /** */ KOAgenda* mAgenda; }; class EventIndicator : public QFrame { Q_OBJECT public: enum Location { Top, Bottom }; EventIndicator(Location loc=Top,QWidget *parent=0,const char *name=0); virtual ~EventIndicator(); void changeColumns(int columns); void setPaintWidget( KDGanttMinimizeSplitter* ); void setXOffset( int ); void enableColumn(int column, bool enable); protected: void drawContents(QPainter *); private: int mXOffset; KDGanttMinimizeSplitter* mPaintWidget; int mColumns; QHBox *mTopBox; QBoxLayout *mTopLayout; Location mLocation; QPixmap mPixmap; QMemArray<bool> mEnabled; }; /** KOAgendaView is the agenda-like view used to display events in an one or multi-day view. */ class KOAgendaView : public KOEventView { Q_OBJECT public: KOAgendaView(Calendar *cal,QWidget *parent = 0,const char *name = 0 ); virtual ~KOAgendaView(); void setStartHour( int ); void toggleAllDay(); /** Returns maximum number of days supported by the koagendaview */ virtual int maxDatesHint(); /** Returns number of currently shown dates. */ virtual int currentDateCount(); /** returns the currently selected events */ virtual QPtrList<Incidence> selectedIncidences(); /** returns the currently selected events */ virtual DateList selectedDates(); /** Remove all events from view */ void clearView(); void clearList(); KOAgenda *agenda() { return mAgenda;} virtual void printPreview(CalPrinter *calPrinter, const QDate &, const QDate &); /** start-datetime of selection */ QDateTime selectionStart() {return mTimeSpanBegin;} /** end-datetime of selection */ QDateTime selectionEnd() {return mTimeSpanEnd;} /** returns true if selection is for whole day */ bool selectedIsAllDay() {return mTimeSpanInAllDay;} /** make selected start/end invalid */ void deleteSelectedDateTime(); void repaintAgenda(); public slots: void setInitStartHour(); virtual void updateView(); virtual void updateConfig(); virtual void showDates(const QDate &start, const QDate &end); virtual void showEvents(QPtrList<Event> eventList); void updateTodo( Todo *, int ); void changeEventDisplay(Event *, int); void clearSelection(); void newTodo(int gx,int gy); void newEvent(int gx,int gy); void newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd); void newEventAllDay(int gx, int gy); void newTodoAllDay(int gx, int gy); void startDrag(Event *); void readSettings(); void readSettings(KConfig *); void writeSettings(KConfig *); void setContentsPos(int y); void scrollOneHourUp(); void scrollOneHourDown(); void addToCalSlot(Incidence *, Incidence *); void slotShowDateView( int, int ); signals: void showDateView( int, QDate ); void newTodoSignal( QDateTime ,bool ); void toggleExpand(); void selectWeekNum( int ); void todoMoved( Todo *, int ); void incidenceChanged(Incidence * , int ); // void cloneIncidenceSignal(Incidence *); protected: KOAgendaButton* getNewDaylabel(); bool mBlockUpdating; int mUpcomingWidth; /** Fill agenda beginning with date startDate */ void fillAgenda(const QDate &startDate); void resizeEvent( QResizeEvent* e ); /** Fill agenda using the current set value for the start date */ void fillAgenda(); /** Create labels for the selected dates. */ void createDayLabels(); /** Set the masks on the agenda widgets indicating, which days are holidays. */ void setHolidayMasks(); protected slots: + void categoryChanged( Incidence * ); void slotDaylabelClicked( int ); /** Update event belonging to agenda item */ void updateEventDates(KOAgendaItem *item, int mode = -1); //void updateMovedTodo(); void updateEventIndicatorTop(int newY); void updateEventIndicatorBottom(int newY); /** Updates data for selected timespan */ void newTimeSpanSelected(int gxStart, int gyStart, int gxEnd, int gyEnd); /** Updates data for selected timespan for all day event*/ void newTimeSpanSelectedAllDay(int gxStart, int gyStart, int gxEnd, int gyEnd); private: // view widgets QFrame *mDayLabels; QHBox *mDayLabelsFrame; QBoxLayout *mLayoutDayLabels; QFrame *mAllDayFrame; KOAgenda *mAllDayAgenda; KOAgenda *mAgenda; TimeLabels *mTimeLabels; QWidget *mDummyAllDayLeft; KDGanttMinimizeSplitter* mSplitterAgenda; QPushButton *mExpandButton; DateList mSelectedDates; // List of dates to be displayed int mViewType; bool mWeekStartsMonday; int mStartHour; KOEventPopupMenu *mAllAgendaPopup; //KOEventPopupMenu *mAllDayAgendaPopup; EventIndicator *mEventIndicatorTop; EventIndicator *mEventIndicatorBottom; QMemArray<int> mMinY; QMemArray<int> mMaxY; QMemArray<bool> mHolidayMask; QPtrList<KOAgendaButton> mDayLabelsList; QDateTime mTimeSpanBegin; QDateTime mTimeSpanEnd; bool mTimeSpanInAllDay; void keyPressEvent ( QKeyEvent * e ); }; #endif // KOAGENDAVIEW_H diff --git a/korganizer/koeventpopupmenu.cpp b/korganizer/koeventpopupmenu.cpp index 17ef81e..90caaf4 100644 --- a/korganizer/koeventpopupmenu.cpp +++ b/korganizer/koeventpopupmenu.cpp @@ -1,130 +1,168 @@ /* 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. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qcursor.h> #include <klocale.h> #include <kdebug.h> #include <kiconloader.h> #include <libkcal/event.h> #include "koeventpopupmenu.h" +#include "koprefs.h" -KOEventPopupMenu::KOEventPopupMenu() +KOEventPopupMenu::KOEventPopupMenu(): QPopupMenu() { mCurrentIncidence = 0; mHasAdditionalItems = false; mSingleOnlyItems.append( insertItem (i18n("&Show"),this,SLOT(popupShow()))); mEditOnlyItems.append(insertItem (i18n("&Edit..."),this,SLOT(popupEdit()))); mEditOnlyItems.append(insertItem (i18n("&Delete"), this,SLOT(popupDelete()))); mEditOnlyItems.append(insertItem (i18n("&Clone..."), this,SLOT(popupClone()))); mEditOnlyItems.append(insertItem (i18n("&Move..."), this,SLOT(popupMove()))); #ifndef DESKTOP_VERSION mEditOnlyItems.append(insertItem (i18n("&Beam..."), this,SLOT(popupBeam()))); #endif mEditOnlyItems.append(insertItem (i18n("&Toggle Cancel"), this,SLOT(popupCancel()))); isDisabled = false; + mCatPopup = new QPopupMenu ( this ); + mCatPopup->setCheckable (true); + connect(mCatPopup,SIGNAL( aboutToShow ()), this ,SLOT( fillCatPopup())); + connect(mCatPopup,SIGNAL( activated ( int ) ), this ,SLOT( computeCatPopup( int ))); + mEditOnlyItems.append(insertItem (i18n("Categories"),mCatPopup )); QValueList<int>::Iterator it; for( it = mEditOnlyItems.begin(); it != mEditOnlyItems.end(); ++it ) { mSingleOnlyItems.append(*it); } + } void KOEventPopupMenu::enableDefault( bool enable ) { isDisabled = !enable; QValueList<int>::Iterator it; for( it = mSingleOnlyItems.begin(); it != mSingleOnlyItems.end(); ++it ) { setItemEnabled(*it,enable); } } +void KOEventPopupMenu::fillCatPopup() +{ + mCatPopup->clear(); + QStringList checkedCategories = mCurrentIncidence->categories(); + int index = 0; + for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); + it != KOPrefs::instance()->mCustomCategories.end (); + ++it) { + mCatPopup->insertItem (*it, index ); + if (checkedCategories.find (*it) != checkedCategories.end ()) { + mCatPopup->setItemChecked (index, true); + } + ++index; + } +} +void KOEventPopupMenu::computeCatPopup( int index ) +{ + QStringList categories = mCurrentIncidence->categories(); + QString colcat = categories.first(); + if (categories.find (KOPrefs::instance()->mCustomCategories[index]) != categories.end ()) + categories.remove (KOPrefs::instance()->mCustomCategories[index]); + else + categories.insert (categories.end(), KOPrefs::instance()->mCustomCategories[index]); + categories.sort (); + if ( !colcat.isEmpty() ) { + if ( categories.find ( colcat ) != categories.end () ) { + categories.remove( colcat ); + categories.prepend( colcat ); + } + } + mCurrentIncidence->setCategories( categories ); + emit categoryChanged( mCurrentIncidence ); +} void KOEventPopupMenu::showIncidencePopup(Incidence *incidence) { mCurrentIncidence = incidence; if (mCurrentIncidence) { // Enable/Disabled menu items only valid for editable events. if ( !isDisabled ) { QValueList<int>::Iterator it; for( it = mEditOnlyItems.begin(); it != mEditOnlyItems.end(); ++it ) { setItemEnabled(*it,!mCurrentIncidence->isReadOnly()); } } popup(QCursor::pos()); - } else { - kdDebug() << "KOEventPopupMenu::showEventPopup(): No event selected" << endl; } } void KOEventPopupMenu::addAdditionalItem(const QIconSet &icon,const QString &text, const QObject *receiver, const char *member, bool editOnly) { if (!mHasAdditionalItems) { mHasAdditionalItems = true; insertSeparator(); } int id = insertItem(icon,text,receiver,member); if (editOnly) mEditOnlyItems.append(id); } void KOEventPopupMenu::popupShow() { if (mCurrentIncidence) emit showIncidenceSignal(mCurrentIncidence); } void KOEventPopupMenu::popupEdit() { if (mCurrentIncidence) emit editIncidenceSignal(mCurrentIncidence); } void KOEventPopupMenu::popupDelete() { if (mCurrentIncidence) emit deleteIncidenceSignal(mCurrentIncidence); } void KOEventPopupMenu::popupClone() { if (mCurrentIncidence) emit cloneIncidenceSignal(mCurrentIncidence); } void KOEventPopupMenu::popupCancel() { if (mCurrentIncidence) emit cancelIncidenceSignal(mCurrentIncidence); } void KOEventPopupMenu::popupMove() { if (mCurrentIncidence) emit moveIncidenceSignal(mCurrentIncidence); } void KOEventPopupMenu::popupBeam() { if (mCurrentIncidence) emit beamIncidenceSignal(mCurrentIncidence); } diff --git a/korganizer/koeventpopupmenu.h b/korganizer/koeventpopupmenu.h index 8fb51fa..3d8b595 100644 --- a/korganizer/koeventpopupmenu.h +++ b/korganizer/koeventpopupmenu.h @@ -1,76 +1,80 @@ /* 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. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef KOEVENTPOPUPMENU_H #define KOEVENTPOPUPMENU_H // // Context menu for event views with standard event actions // #include <qpopupmenu.h> #include <libkcal/incidence.h> using namespace KCal; class KOEventPopupMenu : public QPopupMenu { Q_OBJECT public: KOEventPopupMenu(); void addAdditionalItem(const QIconSet &icon,const QString &text, const QObject *receiver, const char *member, bool editOnly=false); public slots: void showIncidencePopup(Incidence *); void enableDefault( bool ); protected slots: void popupShow(); void popupEdit(); void popupDelete(); void popupClone(); void popupCancel(); void popupMove(); void popupBeam(); + void fillCatPopup(); + void computeCatPopup( int ); signals: void editIncidenceSignal(Incidence *); void showIncidenceSignal(Incidence *); void deleteIncidenceSignal(Incidence *); void cloneIncidenceSignal(Incidence *); void cancelIncidenceSignal(Incidence *); void moveIncidenceSignal(Incidence *); void beamIncidenceSignal(Incidence *); + void categoryChanged( Incidence * ); private: Incidence *mCurrentIncidence; bool mHasAdditionalItems; QValueList<int> mEditOnlyItems; QValueList<int> mSingleOnlyItems; bool isDisabled; + QPopupMenu *mCatPopup; }; #endif diff --git a/korganizer/koeventview.cpp b/korganizer/koeventview.cpp index bce2626..1d26930 100644 --- a/korganizer/koeventview.cpp +++ b/korganizer/koeventview.cpp @@ -1,130 +1,129 @@ /* 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. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qpopupmenu.h> #include <qcursor.h> #include <klocale.h> #include <kdebug.h> #include <kiconloader.h> #include <kmessagebox.h> #include <libkcal/calendar.h> #include "koprefs.h" #include "koeventview.h" using namespace KOrg; //--------------------------------------------------------------------------- KOEventView::KOEventView(Calendar *cal,QWidget *parent,const char *name) : KOrg::BaseView(cal,parent,name) { } //--------------------------------------------------------------------------- KOEventView::~KOEventView() { } //--------------------------------------------------------------------------- KOEventPopupMenu *KOEventView::eventPopup() { KOEventPopupMenu *eventPopup = new KOEventPopupMenu; connect(eventPopup,SIGNAL(editIncidenceSignal(Incidence *)), SIGNAL(editIncidenceSignal(Incidence *))); connect(eventPopup,SIGNAL(showIncidenceSignal(Incidence *)), SIGNAL(showIncidenceSignal(Incidence *))); connect(eventPopup,SIGNAL(deleteIncidenceSignal(Incidence *)), SIGNAL(deleteIncidenceSignal(Incidence *))); connect(eventPopup,SIGNAL(cancelIncidenceSignal(Incidence *)), SIGNAL(cancelIncidenceSignal(Incidence *))); connect(eventPopup,SIGNAL(cloneIncidenceSignal(Incidence *)), SIGNAL(cloneIncidenceSignal(Incidence *))); connect(eventPopup,SIGNAL(beamIncidenceSignal(Incidence *)), SIGNAL(beamIncidenceSignal(Incidence *))); connect(eventPopup,SIGNAL(moveIncidenceSignal(Incidence *)), SIGNAL(moveIncidenceSignal(Incidence *))); return eventPopup; } //--------------------------------------------------------------------------- void KOEventView::showIncidencePopup(QPopupMenu *popup,Incidence *event) { mCurrentIncidence = event; if (event) popup->popup(QCursor::pos()); - else kdDebug() << "KOEventView::showEventPopup(): No event selected" << endl; } //--------------------------------------------------------------------------- void KOEventView::popupShow() { emit showIncidenceSignal(mCurrentIncidence); } //--------------------------------------------------------------------------- void KOEventView::popupEdit() { emit editIncidenceSignal(mCurrentIncidence); } //--------------------------------------------------------------------------- void KOEventView::popupDelete() { emit deleteIncidenceSignal(mCurrentIncidence); } void KOEventView::popupClone() { emit cloneIncidenceSignal(mCurrentIncidence); } void KOEventView::popupCancel() { emit cancelIncidenceSignal(mCurrentIncidence); } //--------------------------------------------------------------------------- void KOEventView::defaultAction( Incidence *incidence ) { if ( !incidence ) return; if ( incidence->isReadOnly() ) emit showIncidenceSignal(incidence); else { if ( KOPrefs::instance()->mEditOnDoubleClick ) emit editIncidenceSignal(incidence); else emit showIncidenceSignal(incidence); } } //--------------------------------------------------------------------------- diff --git a/korganizer/kolistview.cpp b/korganizer/kolistview.cpp index 8f17e6e..43e1113 100644 --- a/korganizer/kolistview.cpp +++ b/korganizer/kolistview.cpp @@ -1,622 +1,622 @@ /* This file is part of KOrganizer. Copyright (c) 1999 Preston Brown 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. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qlistview.h> #include <qlayout.h> #include <qlabel.h> #include <qpopupmenu.h> #include <qprogressbar.h> #include <qfileinfo.h> #include <qmessagebox.h> #include <qdialog.h> #include <qtextstream.h> #include <qdir.h> #include <qwhatsthis.h> #include <qregexp.h> #include <qpainter.h> #include <qpaintdevicemetrics.h> #include <klocale.h> #include <kdebug.h> #include <kiconloader.h> #include <kglobal.h> #include <libkdepim/kpimglobalprefs.h> #include <libkcal/calendar.h> #include <libkcal/calendarlocal.h> #include <libkcal/icalformat.h> #include <libkcal/vcalformat.h> #include <libkcal/recurrence.h> #include <libkcal/filestorage.h> #include <libkdepim/categoryselectdialog.h> #include <libkcal/kincidenceformatter.h> #ifndef DESKTOP_VERSION #include <qpe/qpeapplication.h> #else #include <qapplication.h> #endif #ifndef KORG_NOPRINTER #include "calprinter.h" #endif #include "koglobals.h" #include "koprefs.h" #include "kfiledialog.h" #include "kolistview.h" #include "koeventviewer.h" extern QPixmap* sgListViewCompletedPix[6]; class KOListViewWhatsThis :public QWhatsThis { public: KOListViewWhatsThis( QWidget *wid, KOListView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { }; protected: virtual QString text( const QPoint& p) { return _view->getWhatsThisText(p) ; } private: QWidget* _wid; KOListView * _view; }; ListItemVisitor::ListItemVisitor(KOListViewItem *item, QDate date ) { mItem = item; mDate = date; } ListItemVisitor::~ListItemVisitor() { } bool ListItemVisitor::visit(Event *e) { bool ok = false; QString start, end; QDate ds, de; if ( e->doesRecur() ) { ds = e->getNextOccurence( QDateTime( mDate, QTime(0,0,0)), &ok ).date(); if ( ok ) { int days = e->dtStart().date().daysTo(e->dtEnd().date() ); start = KGlobal::locale()->formatDate(ds,true); de = ds.addDays( days); end = KGlobal::locale()->formatDate(de,true); } } if ( ! ok ) { start =e->dtStartDateStr(); end = e->dtEndDateStr(); ds = e->dtStart().date(); de = e->dtEnd().date(); } mItem->setText(0,e->summary()); mItem->setText(1,start); if ( e->doesFloat() ) mItem->setText(2,"---"); else mItem->setText(2,e->dtStartTimeStr()); mItem->setText(3,end); if ( e->doesFloat() ) mItem->setText(4,"---"); else mItem->setText(4,e->dtEndTimeStr()); if ( e->isAlarmEnabled() ) { mItem->setText(5,e->alarms().first()->offsetText() ); } else { mItem->setText(5, i18n("No")); } mItem->setText(6, e->recurrence()->recurrenceText()); if( ! e->doesRecur() ) mItem->setSortKey( 6, "-" ); mItem->setText(7,"---"); mItem->setText(8,"---"); mItem->setText(9, e->cancelled() ? i18n("Yes") : i18n("No")); mItem->setText(10,e->categoriesStr()); mItem->setText(11, KOPrefs::instance()->calName( e->calID() )); QString key; QTime t = e->doesFloat() ? QTime(0,0) : e->dtStart().time(); key.sprintf("%04d%02d%02d%02d%02d",ds.year(),ds.month(),ds.day(),t.hour(),t.minute()); mItem->setSortKey(1,key); t = e->doesFloat() ? QTime(0,0) : e->dtEnd().time(); key.sprintf("%04d%02d%02d%02d%02d",de.year(),de.month(),de.day(),t.hour(),t.minute()); mItem->setSortKey(3,key); return true; } bool ListItemVisitor::visit(Todo *t) { mItem->setText(0,t->summary()); if ( t->isCompleted() ) { mItem->setSortKey(0,"99"+ t->summary().left(10)); } else mItem->setSortKey(0,QString::number( t->percentComplete() )+ t->summary().left(10)); mItem->setPixmap( 0, *(sgListViewCompletedPix[t->percentComplete()/20])); if (t->hasStartDate()) { mItem->setText(1,t->dtStartDateStr()); if (t->doesFloat()) { mItem->setText(2,"---"); } else { mItem->setText(2,t->dtStartTimeStr()); } } else { mItem->setText(1,"---"); mItem->setText(2,"---"); } mItem->setText(3,"---"); mItem->setText(4,"---"); if ( t->isAlarmEnabled() ) { mItem->setText(5,t->alarms().first()->offsetText() ); } else { mItem->setText(5, i18n("No")); } mItem->setText(6, t->recurrence()->recurrenceText()); if( ! t->doesRecur() ) mItem->setSortKey( 6, "-" ); if (t->hasDueDate()) { mItem->setText(7,t->dtDueDateStr()); if (t->doesFloat()) { mItem->setText(8,"---"); } else { mItem->setText(8,t->dtDueTimeStr()); } } else { mItem->setText(7,"---"); mItem->setText(8,"---"); } mItem->setText(9, t->cancelled() ? i18n("Yes") : i18n("No")); mItem->setText(10,t->categoriesStr()); mItem->setText(11, KOPrefs::instance()->calName( t->calID() )); QString key; QDate d; if (t->hasDueDate()) { d = t->dtDue().date(); QTime tm = t->doesFloat() ? QTime(0,0) : t->dtDue().time(); key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute()); mItem->setSortKey(7,key); } if ( t->hasStartDate() ) { d = t->dtStart().date(); QTime tm = t->doesFloat() ? QTime(0,0) : t->dtStart().time(); key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute()); mItem->setSortKey(1,key); } return true; } bool ListItemVisitor::visit(Journal * j) { QString des; if ( !j->summary().isEmpty() ) { des = j->summary(); } else { des = j->description().left(30); des = des.simplifyWhiteSpace (); des.replace (QRegExp ("\\n"),"" ); des.replace (QRegExp ("\\r"),"" ); } mItem->setText(0,i18n("Journal: ")+des.left(25)); mItem->setText(1,j->dtStartDateStr()); mItem->setText(2,"---"); mItem->setText(3,"---"); mItem->setText(4,"---"); mItem->setText(5,"---"); mItem->setText(6,"---"); mItem->setText(7,j->dtStartDateStr()); mItem->setText(8,"---"); mItem->setText(9,"---"); - mItem->setText(10,i18n("Last Modified: ")+ KGlobal::locale()->formatDateTime( j->lastModified() , true) ); + mItem->setText(10,j->categoriesStr()); mItem->setText(11, KOPrefs::instance()->calName( j->calID() )); QString key; QDate d = j->dtStart().date(); key.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); mItem->setSortKey(1,key); mItem->setSortKey(7,key); return true; } KOListView::KOListView(Calendar *calendar, QWidget *parent, const char *name) : KOEventView(calendar, parent, name) { mActiveItem = 0; mForceShowCompletedTodos = false; mListView = new KOListViewListView(this); mListView->addColumn(i18n("Summary")); mListView->addColumn(i18n("Start Date")); mListView->addColumn(i18n("Start Time")); mListView->addColumn(i18n("End Date")); mListView->addColumn(i18n("End Time")); mListView->addColumn(i18n("Alarm")); // alarm set? mListView->addColumn(i18n("Recurs")); // recurs? mListView->addColumn(i18n("Due Date")); mListView->addColumn(i18n("Due Time")); mListView->addColumn(i18n("Cancelled")); mListView->addColumn(i18n("Categories")); mListView->addColumn(i18n("Calendar")); mListView->setColumnAlignment(0,AlignLeft); mListView->setColumnAlignment(1,AlignLeft); mListView->setColumnAlignment(2,AlignHCenter); mListView->setColumnAlignment(3,AlignLeft); mListView->setColumnAlignment(4,AlignHCenter); mListView->setColumnAlignment(5,AlignLeft); mListView->setColumnAlignment(6,AlignLeft); mListView->setColumnAlignment(7,AlignLeft); mListView->setColumnAlignment(8,AlignLeft); mListView->setColumnAlignment(9,AlignLeft); mListView->setColumnAlignment(10,AlignLeft); mListView->setColumnAlignment(11,AlignLeft); mKOListViewWhatsThis = new KOListViewWhatsThis(mListView->viewport(),this); int iii = 0; for ( iii = 0; iii< 12 ; ++iii ) mListView->setColumnWidthMode( iii, QListView::Manual ); QBoxLayout *layoutTop = new QVBoxLayout(this); layoutTop->addWidget(mListView); mListView->setFont ( KOPrefs::instance()->mListViewFont ); mPopupMenu = eventPopup(); mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Select all"),this, SLOT(allSelection()),true); mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Deselect all"),this, SLOT(clearSelection()),true); mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Delete all selected"),this, SLOT(deleteAll()),true); mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Hide all selected"),this, SLOT(hideAll()),true); mPopupMenu->insertSeparator(); #ifdef DESKTOP_VERSION mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Print complete list"),this, SLOT(printList()),true); mPopupMenu->insertSeparator(); #endif mCalPopup = new QPopupMenu ( this ); mPopupMenu->insertItem( i18n("Set Calendar"), mCalPopup ); QObject::connect(mCalPopup,SIGNAL(aboutToShow()),this, SLOT( populateCalPopup() )); QObject::connect(mCalPopup,SIGNAL(activated( int )),this, SLOT( setCalendar( int ) )); QPopupMenu * exportPO = new QPopupMenu ( this ); mPopupMenu->insertItem( i18n("Export selected"), exportPO ); exportPO->insertItem( i18n("As iCal (ics) file..."),this, SLOT(saveToFile())); exportPO->insertItem( i18n("As vCal (vcs) file..."),this, SLOT(saveToFileVCS())); exportPO->insertItem( i18n("Journal/Details..."),this, SLOT(saveDescriptionToFile())); // mPopupMenu->insertSeparator(); mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Add Categ. to selected..."),this, SLOT(addCat()),true); mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Set Categ. for selected..."),this, SLOT(setCat()),true); //mPopupMenu->insertSeparator(); mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Set alarm for selected..."),this, SLOT(setAlarm()),true); #ifndef DESKTOP_VERSION mPopupMenu->insertSeparator(); mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Beam selected via IR"),this, SLOT(beamSelected()),true); #endif /* mPopupMenu = new QPopupMenu; mPopupMenu->insertItem(i18n("Edit Event"), this, SLOT (editEvent())); mPopupMenu->insertItem(SmallIcon("delete"), i18n("Delete Event"), this, SLOT (deleteEvent())); mPopupMenu->insertSeparator(); mPopupMenu->insertItem(i18n("Show Dates"), this, SLOT(showDates())); mPopupMenu->insertItem(i18n("Hide Dates"), this, SLOT(hideDates())); */ QObject::connect(mListView,SIGNAL( newEvent()), this,SIGNAL(signalNewEvent())); QObject::connect(mListView,SIGNAL(doubleClicked(QListViewItem *)), this,SLOT(defaultItemAction(QListViewItem *))); QObject::connect(mListView,SIGNAL(rightButtonPressed( QListViewItem *, const QPoint &, int )), this,SLOT(popupMenu(QListViewItem *,const QPoint &,int))); QObject::connect(mListView,SIGNAL(currentChanged(QListViewItem *)), SLOT(processSelectionChange(QListViewItem *))); QObject::connect(mListView,SIGNAL(showIncidence(Incidence *)), SIGNAL(showIncidenceSignal(Incidence *)) ); readSettings(KOGlobals::config(),"KOListView Layout"); } KOListView::~KOListView() { delete mPopupMenu; #if QT_VERSION >= 0x030000 #else delete mKOListViewWhatsThis; #endif } QString KOListView::getWhatsThisText(QPoint p) { KOListViewItem* item = ( KOListViewItem* ) mListView->itemAt( p ); if ( item ) return KIncidenceFormatter::instance()->getFormattedText( item->data(), KOPrefs::instance()->mWTshowDetails, KOPrefs::instance()->mWTshowCreated, KOPrefs::instance()->mWTshowChanged); return i18n("That is the list view" ); } void KOListView::setCalendar( int c ) { int result = QMessageBox::warning( this, i18n("KO/Pi: Information!"), i18n("This adds the selected\nitems to the calendar\n%1\nand removes them from\ntheir current calendar!").arg( KOPrefs::instance()->calName( c ) ), i18n("Continue"), i18n("Cancel"), 0, 0, 1 ); if ( result != 0 ) { return; } QPtrList<Incidence> delSel = getSelectedIncidences() ; int icount = delSel.count(); if ( icount ) { Incidence *incidence = delSel.first(); while ( incidence ) { incidence->setCalID( c ); KOListViewItem * item = getItemForEvent( incidence ); if ( item ) { ListItemVisitor v(item, mStartDate ); incidence->accept(v); } incidence = delSel.next(); } } QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; KopiCalendarFile * cal = calendars.first(); while ( cal ) { mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); if ( cal->isStandard ) mCalendar->setDefaultCalendar( cal->mCalNumber ); cal = calendars.next(); } mCalendar->setSyncEventsReadOnly(); mCalendar->reInitAlarmSettings(); } void KOListView::populateCalPopup() { mCalPopup->clear(); KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); while ( kkf ) { mCalPopup->insertItem( kkf->mName, kkf->mCalNumber); kkf = KOPrefs::instance()->mCalendars.next(); } } void KOListView::updateList() { // qDebug(" KOListView::updateList() "); } void KOListView::clearList() { clear (); } void KOListView::addCat( ) { setCategories( false ); } void KOListView::setCat() { setCategories( true ); } void KOListView::setAlarm() { KOAlarmPrefs kap( this); if ( !kap.exec() ) return; QStringList itemList; QPtrList<KOListViewItem> sel ; QListViewItem *qitem = mListView->firstChild (); while ( qitem ) { if ( qitem->isSelected() ) { Incidence* inc = ((KOListViewItem *) qitem)->data(); if ( inc->typeID() != journalID ) { if ( inc->typeID() == todoID ) { if ( ((Todo*)inc)->hasDueDate() ) sel.append(((KOListViewItem *)qitem)); } else sel.append(((KOListViewItem *)qitem)); } } qitem = qitem->nextSibling(); } int count = 0; KOListViewItem * item, *temp; item = sel.first(); Incidence* inc; while ( item ) { inc = item->data(); ++count; if (kap.mAlarmButton->isChecked()) { if (inc->alarms().count() == 0) inc->newAlarm(); QPtrList<Alarm> alarms = inc->alarms(); Alarm *alarm; for (alarm = alarms.first(); alarm; alarm = alarms.next() ) { alarm->setEnabled(true); int j = kap.mAlarmTimeEdit->value()* -60; if (kap.mAlarmIncrCombo->currentItem() == 1) j = j * 60; else if (kap.mAlarmIncrCombo->currentItem() == 2) j = j * (60 * 24); alarm->setStartOffset( j ); if (!kap.mAlarmProgram.isEmpty() && kap.mAlarmProgramButton->isOn()) { alarm->setProcedureAlarm(kap.mAlarmProgram); } else if (!kap.mAlarmSound.isEmpty() && kap.mAlarmSoundButton->isOn()) alarm->setAudioAlarm(kap.mAlarmSound); else alarm->setType(Alarm::Invalid); //alarm->setAudioAlarm("default"); // TODO: Deal with multiple alarms break; // For now, stop after the first alarm } } else { Alarm* alarm = inc->alarms().first(); if ( alarm ) { alarm->setEnabled(false); alarm->setType(Alarm::Invalid); } } ListItemVisitor v(item, mStartDate ); inc->accept(v); item = sel.next(); } topLevelWidget()->setCaption( i18n("Changed alarm for %1 items").arg( count ) ); qDebug("KO: Set alarm for %d items", count); calendar()->reInitAlarmSettings(); QTimer::singleShot( 1, this, SLOT ( resetFocus() ) ); } void KOListView::setCategories( bool removeOld ) { KPIM::CategorySelectDialog* csd = new KPIM::CategorySelectDialog( KOPrefs::instance(), 0 ); csd->setColorEnabled(); if (! csd->exec()) { delete csd; return; } QStringList catList = csd->selectedCategories(); delete csd; // if ( catList.count() == 0 ) // return; //catList.sort(); QString categoriesStr = catList.join(","); int i; QStringList itemList; QPtrList<KOListViewItem> sel ; QListViewItem *qitem = mListView->firstChild (); while ( qitem ) { if ( qitem->isSelected() ) { sel.append(((KOListViewItem *)qitem)); } qitem = qitem->nextSibling(); } KOListViewItem * item, *temp; item = sel.first(); if( item ) { Incidence* inc = item->data() ; bool setSub = false; if( inc->typeID() == todoID && sel.count() == 1 && inc->relations().count() > 0 ) { int result = KMessageBox::warningYesNoCancel(this, i18n("The todo\n%1\nhas subtodos!\nDo you want to set\nthe categories for\nall subtodos as well?").arg( inc->summary().left ( 25 ) ), i18n("Todo has subtodos"), i18n("Yes"), i18n("No")); if (result == KMessageBox::Cancel) item = 0; if (result == KMessageBox::Yes) setSub = true; } while ( item ) { inc = item->data(); if ( removeOld ) { inc->setCategories( catList, setSub ); } else { inc->addCategories( catList, setSub ); } ListItemVisitor v(item, mStartDate ); inc->accept(v); item = sel.next(); } } QTimer::singleShot( 1, this, SLOT ( resetFocus() ) ); } void KOListView::beamSelected() { QPtrList<Incidence> delSel = getSelectedIncidences() ; int icount = delSel.count(); if ( icount ) { emit beamIncidenceList( delSel ); return; QString fn ; fn = QDir::homeDirPath()+"/kopitempbeamfile.vcs"; QString mes; bool createbup = true; if ( createbup ) { QString description = "\n"; CalendarLocal* cal = new CalendarLocal(); cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); Incidence *incidence = delSel.first(); while ( incidence ) { Incidence *in = incidence->clone(); description += in->summary() + "\n"; cal->addIncidence( in ); incidence = delSel.next(); } FileStorage storage( cal, fn, new VCalFormat ); storage.save(); delete cal; mes = i18n("KO/Pi: Ready for beaming"); topLevelWidget()->setCaption(mes); #ifndef DESKTOP_VERSION Ir *ir = new Ir( this ); connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); ir->send( fn, description, "text/x-vCalendar" ); #endif } } } @@ -630,778 +630,774 @@ void KOListView::beamDone( Ir *ir ) void KOListView::saveDescriptionToFile() { int result = QMessageBox::warning( this, i18n("KO/Pi: Information!"), i18n("This saves the text/details of selected\nJournals and Events/Todos\nto a text file."), i18n("Continue"), i18n("Cancel"), 0, 0, 1 ); if ( result != 0 ) { return; } QPtrList<Incidence> delSel = getSelectedIncidences() ; int icount = delSel.count(); if ( icount ) { QString fn = KOPrefs::instance()->mLastSaveFile; fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this ); if ( fn == "" ) return; QFileInfo info; info.setFile( fn ); QString mes; bool createbup = true; if ( info. exists() ) { mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, i18n("Overwrite!"), i18n("Cancel"), 0, 0, 1 ); if ( result != 0 ) { createbup = false; } } if ( createbup ) { QString text = i18n("KO/Pi Description/Journal save file.\nSave date: ") + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), false); Incidence *incidence = delSel.first(); icount = 0; while ( incidence ) { if ( incidence->typeID() == journalID ) { text += "\n************************************\n"; if ( !incidence->summary().isEmpty() ) text += i18n("Journal: %1 from ").arg( incidence->summary() ) +incidence->dtStartDateStr( false ); else text += i18n("Journal from: ") +incidence->dtStartDateStr( false ); if ( !incidence->location().isEmpty() ) text +="\n(" + i18n("Location: ") + incidence->location()+ ")"; text +="\n" + i18n("Last modified: ") +KGlobal::locale()->formatDateTime(incidence->lastModified(), false); text +="\n" + i18n("Description: ") + "\n"+ incidence->description(); ++icount; } else { if ( !incidence->description().isEmpty() ) { text += "\n************************************\n"; if ( incidence->typeID() == todoID ) text += i18n("To-Do: "); text += incidence->summary(); if ( !incidence->location().isEmpty() ) text +="\n(" + i18n("Location: ") + incidence->location()+ ")"; if ( incidence->hasStartDate() ) text +="\n"+ i18n("Start Date: ") + incidence->dtStartStr( false ); text +="\n"+ i18n("Last modified: ") +KGlobal::locale()->formatDateTime(incidence->lastModified(), false); text += "\n" + i18n("Description: ") + "\n" + incidence->description(); ++icount; } } incidence = delSel.next(); } QFile file( fn ); if (!file.open( IO_WriteOnly ) ) { topLevelWidget()->setCaption(i18n("File open error - nothing saved!") ); return; } QTextStream ts( &file ); ts << text; file.close(); //qDebug("%s ", text.latin1()); mes = i18n("KO/Pi:Saved %1 descriptions/journals").arg(icount ); KOPrefs::instance()->mLastSaveFile = fn; topLevelWidget()->setCaption(mes); } } } void KOListView::saveToFileVCS() { writeToFile( false ); } void KOListView::saveToFile() { writeToFile( true ); } QPtrList<Incidence> KOListView::getSelectedIncidences( bool includeEvents, bool includeTodos, bool includeJournals, bool onlyDueTodos ) { QPtrList<Incidence> delSel ; bool addSubTodos = false; bool askSubTodos = true; QListViewItem *item = mListView->firstChild (); while ( item ) { if ( item->isSelected() ) { Incidence* inc = ((KOListViewItem *)item)->data(); if ( ( addSubTodos && delSel.findRef( inc ) == -1) || !addSubTodos ) { if ( (inc->typeID() == todoID && includeTodos) || (inc->typeID() == eventID && includeEvents) || (inc->typeID() == journalID && includeJournals) ) { if ( inc->typeID() == todoID && onlyDueTodos ) { if ( ((Todo*)inc)->hasDueDate() ) delSel.append( inc ); } else delSel.append( inc ); } } if ( inc->typeID() == todoID ) { Todo * todo = (Todo*) inc; if ( todo->relations().count() ) { if ( askSubTodos ) { int result = KMessageBox::warningYesNoCancel(this, i18n("One (or more) selected\ntodo has subtodos!\nDo you want to select\nall subtodos of all\nselected todos as well?"), i18n("Todo has subtodos"), i18n("Yes"), i18n("No")); if ( result == KMessageBox::Cancel ) { delSel.clear(); return delSel; } if (result == KMessageBox::Yes) addSubTodos = true; askSubTodos = false; } if ( addSubTodos ) { inc->addRelationsToList( &delSel ); } } } } item = item->nextSibling(); } return delSel; } void KOListView::writeToFile( bool iCal ) { QPtrList<Incidence> delSel = getSelectedIncidences(); // all inc allowed; if ( !iCal ) { bool journal = false; Incidence *incidence = delSel.first(); while ( incidence ) { if ( incidence->typeID() == journalID ) { journal = true; break; } incidence = delSel.next(); } if ( journal ) { int result = KMessageBox::warningContinueCancel(this, i18n("The journal entries can not be\nexported to a vCalendar file."), i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), true); if (result != KMessageBox::Continue) return; } } if ( delSel.count() ) { QString fn = KOPrefs::instance()->mLastSaveFile; QString extension; if ( iCal ) { if ( fn.right( 4 ).lower() == ".vcs" ) { fn = fn.left( fn.length() -3) + "ics"; } } else { if ( fn.right( 4 ).lower() == ".ics" ) { fn = fn.left( fn.length() -3) + "vcs"; } } fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this ); if ( fn == "" ) return; QFileInfo info; info.setFile( fn ); QString mes; bool createbup = true; if ( info. exists() ) { mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, i18n("Overwrite!"), i18n("Cancel"), 0, 0, 1 ); if ( result != 0 ) { createbup = false; } } if ( createbup ) { CalendarLocal cal; cal.setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); Incidence *incidence = delSel.first(); while ( incidence ) { cal.addIncidence( incidence->clone() ); incidence = delSel.next(); } if ( iCal ) { ICalFormat format; format.save( &cal, fn ); } else { VCalFormat format; format.save( &cal, fn ); } mes = i18n("KO/Pi:Saved %1").arg(fn ); KOPrefs::instance()->mLastSaveFile = fn; topLevelWidget()->setCaption(mes); } } QTimer::singleShot( 1, this, SLOT ( resetFocus() ) ); } void KOListView::hideAll() { QPtrList<QListViewItem> delSel ; QListViewItem *item = mListView->firstChild (); while ( item ) { if ( item->isSelected() ) { delSel.append(item); } item = item->nextSibling(); } item = delSel.first() ; while ( item ) { QListViewItem * del = item; item = delSel.next(); delete del; } } void KOListView::printList() { mListView->printList(); } void KOListView::deleteAll() { QPtrList<Incidence> delSel = getSelectedIncidences(); // all inc allowed;; if ( delSel.count() ) { int icount = delSel.count(); Incidence *incidence = delSel.first(); Incidence *toDelete; KOPrefs *p = KOPrefs::instance(); bool confirm = p->mConfirm; QString mess; mess = mess.sprintf( i18n("You have %d item(s) selected.\n"), icount ); if ( KMessageBox::Continue == KMessageBox::warningContinueCancel(this, mess + i18n("All selected items will be\npermanently deleted.\n(Deleting items will take\nsome time on a PDA)\n"), i18n("KO/Pi Confirmation"),i18n("Delete")) ) { p->mConfirm = false; int delCounter = 0; QDialog dia ( this, "p-dialog", true ); QLabel lab (i18n("Close dialog to abort deletion!"), &dia ); QVBoxLayout lay( &dia ); lay.setMargin(7); lay.setSpacing(7); lay.addWidget( &lab); QProgressBar bar( icount, &dia ); lay.addWidget( &bar); int w = 220; int h = 50; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); dia.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); //dia.resize( 240,50 ); dia.show(); while ( incidence ) { bar.setProgress( delCounter ); mess = mess.sprintf( i18n("Deleting item %d ..."), ++delCounter ); dia.setCaption( mess ); qApp->processEvents(); toDelete = (incidence); incidence = delSel.next(); emit deleteIncidenceSignal(toDelete ); if ( dia.result() != 0 ) break; } mess = mess.sprintf( i18n("%d items remaining in list."), count() ); topLevelWidget ()->setCaption( mess ); p->mConfirm = confirm; } } } int KOListView::maxDatesHint() { return 0; } int KOListView::currentDateCount() { return 0; } QPtrList<Incidence> KOListView::selectedIncidences() { QPtrList<Incidence> eventList; QListViewItem *item = mListView->firstChild (); while ( item ) { if ( item->isSelected() ) { eventList.append(((KOListViewItem *)item)->data()); } item = item->nextSibling(); } // // QListViewItem *item = mListView->selectedItem(); //if (item) eventList.append(((KOListViewItem *)item)->data()); return eventList; } DateList KOListView::selectedDates() { DateList eventList; return eventList; } void KOListView::showDates(bool show) { // Shouldn't we set it to a value greater 0? When showDates is called with // show == true at first, then the columnwidths are set to zero. static int oldColWidth1 = 0; static int oldColWidth3 = 0; if (!show) { oldColWidth1 = mListView->columnWidth(1); oldColWidth3 = mListView->columnWidth(3); mListView->setColumnWidth(1, 0); mListView->setColumnWidth(3, 0); } else { mListView->setColumnWidth(1, oldColWidth1); mListView->setColumnWidth(3, oldColWidth3); } mListView->repaint(); } void KOListView::printPreview(CalPrinter *calPrinter, const QDate &fd, const QDate &td) { #ifndef KORG_NOPRINTER calPrinter->preview(CalPrinter::Day, fd, td); #endif } void KOListView::showDates() { showDates(true); } void KOListView::hideDates() { showDates(false); } void KOListView::resetFocus() { topLevelWidget()->setActiveWindow(); topLevelWidget()->raise(); mListView->setFocus(); } void KOListView::updateView() { mListView->setFocus(); if ( mListView->firstChild () ) mListView->setCurrentItem( mListView->firstChild () ); } void KOListView::updateConfig() { mListView->setFont ( KOPrefs::instance()->mListViewFont ); updateView(); } void KOListView::setStartDate(const QDate &start) { mStartDate = start; } void KOListView::showDates(const QDate &start, const QDate &end) { clear(); mStartDate = start; QDate date = start; - QPtrList<Journal> j_list; while( date <= end ) { addEvents(calendar()->events(date)); addTodos(calendar()->todos(date)); - Journal* jo = calendar()->journal(date); - if ( jo ) - j_list.append( jo ); + addJournals( calendar()->journals4Date(date) ); date = date.addDays( 1 ); } - addJournals(j_list); emit incidenceSelected( 0 ); updateView(); } void KOListView::addEvents(QPtrList<Event> eventList) { Event *ev; for(ev = eventList.first(); ev; ev = eventList.next()) { addIncidence(ev); } if ( !mListView->currentItem() ){ updateView(); } } void KOListView::addTodos(QPtrList<Todo> eventList) { Todo *ev; for(ev = eventList.first(); ev; ev = eventList.next()) { addIncidence(ev); } if ( !mListView->currentItem() ){ updateView(); } } void KOListView::addJournals(QPtrList<Journal> eventList) { Journal *ev; for(ev = eventList.first(); ev; ev = eventList.next()) { addIncidence(ev); } if ( !mListView->currentItem() ){ updateView(); } } void KOListView::showCompletedTodos() { mForceShowCompletedTodos = true; } void KOListView::addIncidence(Incidence *incidence) { if ( mUidDict.find( incidence->uid() ) ) return; // mListView->setFont ( KOPrefs::instance()->mListViewFont ); if ( incidence->typeID() == todoID ) { if ( ! mForceShowCompletedTodos ) { if ( !KOPrefs::instance()->mShowCompletedTodo && ((Todo*)incidence)->isCompleted() ) return; } } mUidDict.insert( incidence->uid(), incidence ); KOListViewItem *item = new KOListViewItem( incidence, mListView ); ListItemVisitor v(item, mStartDate ); if (incidence->accept(v)) { return; } else delete item; } void KOListView::showEvents(QPtrList<Event> eventList) { clear(); addEvents(eventList); // After new creation of list view no events are selected. emit incidenceSelected( 0 ); } int KOListView::count() { return mListView->childCount(); } void KOListView::changeEventDisplay(Event *event, int action) { KOListViewItem *item; switch(action) { case KOGlobals::EVENTADDED: addIncidence( event ); break; case KOGlobals::EVENTEDITED: item = getItemForEvent(event); if (item) { mUidDict.remove( event->uid() ); delete item; addIncidence( event ); } break; case KOGlobals::EVENTDELETED: item = getItemForEvent(event); if (item) { mUidDict.remove( event->uid() ); delete item; } break; default: ; } } KOListViewItem *KOListView::getItemForEvent(Incidence *event) { KOListViewItem *item = (KOListViewItem *)mListView->firstChild(); while (item) { if (item->data() == event) return item; item = (KOListViewItem *)item->nextSibling(); } return 0; } void KOListView::defaultItemAction(QListViewItem *i) { KOListViewItem *item = static_cast<KOListViewItem *>( i ); if ( item ) defaultAction( item->data() ); } void KOListView::popupMenu(QListViewItem *item,const QPoint &,int) { mActiveItem = (KOListViewItem *)item; if (mActiveItem) { Incidence *incidence = mActiveItem->data(); mPopupMenu->enableDefault( !mListView->hasMultiSelection( item ) ); mPopupMenu->showIncidencePopup(incidence); /* if ( incidence && incidence->type() == "Event" ) { Event *event = static_cast<Event *>( incidence ); mPopupMenu->showEventPopup(event); } */ } } void KOListView::readSettings(KConfig *config, QString setting) { // qDebug("KOListView::readSettings "); mListView->restoreLayout(config,setting); } void KOListView::writeSettings(KConfig *config, QString setting) { // qDebug("KOListView::writeSettings "); mListView->saveLayout(config, setting); } void KOListView::processSelectionChange(QListViewItem *) { KOListViewItem *item = static_cast<KOListViewItem *>( mListView->currentItem() ); if ( !item ) { emit incidenceSelected( 0 ); } else { emit incidenceSelected( item->data() ); } } void KOListView::clearSelection() { mListView->selectAll( false ); } void KOListView::allSelection() { mListView->selectAll( true ); } void KOListView::clear() { mListView->clear(); mUidDict.clear(); } Incidence* KOListView::currentItem() { if ( mListView->currentItem() ) return ((KOListViewItem*) mListView->currentItem())->data(); return 0; } void KOListView::keyPressEvent ( QKeyEvent *e) { if ( e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace ) { deleteAll(); return; } e->ignore(); } void KOListViewListView::keyPressEvent ( QKeyEvent *e) { switch ( e->key() ) { case Qt::Key_Down: if ( e->state() == ShiftButton ) { QListViewItem* cn = currentItem(); if ( !cn ) cn = firstChild(); if ( !cn ) return; while ( cn->nextSibling() ) cn = cn->nextSibling(); setCurrentItem ( cn ); ensureItemVisible ( cn ); e->accept(); return; } if ( e->state() == ControlButton ) { int count = childCount (); int jump = count / 5; QListViewItem* cn; cn = currentItem(); if ( ! cn ) return; if ( jump == 0 ) jump = 1; while ( jump && cn->nextSibling() ) { cn = cn->nextSibling(); --jump; } setCurrentItem ( cn ); ensureItemVisible ( cn ); } else QListView::keyPressEvent ( e ) ; e->accept(); break; case Qt::Key_Up: if ( e->state() == ShiftButton ) { QListViewItem* cn = firstChild(); if ( cn ) { setCurrentItem ( cn ); ensureItemVisible ( cn ); } e->accept(); return; } if ( e->state() == ControlButton ) { int count = childCount (); int jump = count / 5; QListViewItem* cn; cn = currentItem(); if ( ! cn ) return; if ( jump == 0 ) jump = 1; while ( jump && cn->itemAbove ()) { cn = cn->itemAbove (); --jump; } setCurrentItem ( cn ); ensureItemVisible ( cn ); } else QListView::keyPressEvent ( e ) ; e->accept(); break; case Qt::Key_I: { QListViewItem* cn; cn = currentItem(); if ( cn ) { KOListViewItem* ci = (KOListViewItem*)( cn ); if ( ci ){ //emit showIncidence( ci->data()); cn = cn->nextSibling(); if ( cn ) { setCurrentItem ( cn ); ensureItemVisible ( cn ); } emit showIncidence( ci->data()); } } e->accept(); } break; case Qt::Key_Return: case Qt::Key_Enter: { QListViewItem* cn; cn = currentItem(); if ( cn ) { KOListViewItem* ci = (KOListViewItem*)( cn ); if ( ci ){ if ( e->state() == ShiftButton ) ci->setSelected( false ); else ci->setSelected( true ); cn = cn->nextSibling(); if ( cn ) { setCurrentItem ( cn ); ensureItemVisible ( cn ); } } } e->accept(); } break; default: e->ignore(); } } KOListViewListView::KOListViewListView(KOListView * lv ) : KListView( lv, "kolistlistview", false ) { mYMousePos = 0; mPopupTimer = new QTimer(this); connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu())); #ifndef DESKTOP_VERSION //QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); #endif setSelectionMode( QListView::Multi ); setMultiSelection( true); } bool KOListViewListView::hasMultiSelection(QListViewItem* item) { int selCount = 0; QListViewItem *qitem = firstChild (); while ( qitem ) { if ( qitem->isSelected() && item != qitem ) return true; qitem = qitem->nextSibling(); } return false; } void KOListViewListView::contentsMouseDoubleClickEvent(QMouseEvent *e) { if (!e) return; QPoint vp = contentsToViewport(e->pos()); QListViewItem *item = itemAt(vp); if (!item) { emit newEvent(); return; } KListView::contentsMouseDoubleClickEvent(e); } #if 0 void KOListViewListView::contentsMousePressEvent(QMouseEvent *e) { //qDebug("contentsMousePressEvent++++ "); KListView::contentsMousePressEvent( e ); if ( e->button() == RightButton ) { QListViewItem* ci = currentItem(); clearSelection () ; if ( ci ) ci->setSelected( true ); } } void KOListViewListView::contentsMouseReleaseEvent(QMouseEvent *e) { KListView::contentsMouseReleaseEvent(e); } void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e) { KListView::contentsMouseMoveEvent(e); } #endif void KOListViewListView::popupMenu() { mPopupTimer->stop(); QMouseEvent* e = new QMouseEvent( QEvent::MouseButtonPress, mEventPos ,mEventGlobalPos, RightButton , RightButton ); QApplication::postEvent( this->viewport(), e ); } void KOListViewListView::contentsMousePressEvent(QMouseEvent *e) { //qDebug("contentsMousePressEvent++++ %d %d", e->pos().y(), e->globalPos().y()); mYMousePos = mapToGlobal( (e->pos())).y(); if ( e->button() == LeftButton ) { mPopupTimer->start( 600 ); mEventPos = contentsToViewport(e->pos()); mEventGlobalPos = e->globalPos(); } KListView::contentsMousePressEvent( e ); if ( e->button() == RightButton ) { QListViewItem* ci = currentItem(); //clearSelection(); if ( ci ) ci->setSelected( true ); |