korganizer

timelineitem.cpp

00001 /*
00002     Copyright (c) 2007 Volker Krause <vkrause@kde.org>
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "timelineitem.h"
00020 
00021 #include "kohelper.h"
00022 
00023 #define protected public
00024 #include <kdgantt/KDGanttViewSubwidgets.h>
00025 #undef public
00026 
00027 #include <libkcal/calendar.h>
00028 #include <libkcal/incidenceformatter.h>
00029 #include <libkcal/resourcecalendar.h>
00030 
00031 using namespace KOrg;
00032 using namespace KCal;
00033 
00034 TimelineItem::TimelineItem( const QString &label, KDGanttView * parent) :
00035     KDGanttViewTaskItem( parent )
00036 {
00037   setListViewText( 0, label );
00038   setDisplaySubitemsAsGroup( true );
00039   if ( listView() )
00040     listView()->setRootIsDecorated( false );
00041 }
00042 
00043 void TimelineItem::insertIncidence(KCal::Incidence * incidence, const QDateTime & _start, const QDateTime & _end)
00044 {
00045   QDateTime start = incidence->dtStart(), end = incidence->dtEnd();
00046   if ( _start.isValid() )
00047     start = _start;
00048   if ( _end.isValid() )
00049     end = _end;
00050   if ( incidence->doesFloat() )
00051     end = end.addDays( 1 );
00052 
00053   typedef QValueList<TimelineSubItem*> ItemList;
00054   ItemList list = mItemMap[incidence];
00055   for ( ItemList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it )
00056     if ( (*it)->startTime() == start && (*it)->endTime() == end )
00057       return;
00058 
00059   TimelineSubItem * item = new TimelineSubItem( incidence, this );
00060   QColor c1, c2, c3;
00061   colors( c1, c2, c3 );
00062   item->setColors( c1, c2, c3 );
00063 
00064   item->setStartTime( start );
00065   item->setOriginalStart( start );
00066   item->setEndTime( end );
00067 
00068   mItemMap[incidence].append( item );
00069 }
00070 
00071 void TimelineItem::removeIncidence(KCal::Incidence * incidence)
00072 {
00073   typedef QValueList<TimelineSubItem*> ItemList;
00074   ItemList list = mItemMap[incidence];
00075   for ( ItemList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it )
00076     delete *it;
00077   mItemMap.remove( incidence );
00078 }
00079 
00080 void TimelineItem::moveItems(KCal::Incidence * incidence, int delta, int duration)
00081 {
00082   typedef QValueList<TimelineSubItem*> ItemList;
00083   ItemList list = mItemMap[incidence];
00084   for ( ItemList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it ) {
00085     QDateTime start = (*it)->originalStart();
00086     start = start.addSecs( delta );
00087     (*it)->setStartTime( start );
00088     (*it)->setOriginalStart( start );
00089     (*it)->setEndTime( start.addSecs( duration ) );
00090   }
00091 }
00092 
00093 
00094 TimelineSubItem::TimelineSubItem(KCal::Incidence * incidence, TimelineItem * parent) :
00095     KDGanttViewTaskItem( parent ),
00096     mIncidence( incidence ),
00097     mLeft( 0 ),
00098     mRight( 0 ),
00099     mMarkerWidth( 0 )
00100 {
00101   setTooltipText( IncidenceFormatter::toolTipString( incidence ) );
00102   if ( !incidence->isReadOnly() ) {
00103     setMoveable( true );
00104     setResizeable( true );
00105   }
00106 }
00107 
00108 TimelineSubItem::~TimelineSubItem()
00109 {
00110   delete mLeft;
00111   delete mRight;
00112 }
00113 
00114 void TimelineSubItem::showItem(bool show, int coordY)
00115 {
00116   KDGanttViewTaskItem::showItem( show, coordY );
00117   int y;
00118   if ( coordY != 0 )
00119     y = coordY;
00120   else
00121     y = getCoordY();
00122   int startX = myGanttView->myTimeHeader->getCoordX(myStartTime);
00123   int endX = myGanttView->myTimeHeader->getCoordX(myEndTime);
00124 
00125   const int mw = QMAX( 1, QMIN( 4, endX - startX ) );
00126   if ( !mLeft || mw != mMarkerWidth ) {
00127     if ( !mLeft ) {
00128       mLeft = new KDCanvasPolygon( myGanttView->myTimeTable, this, Type_is_KDGanttViewItem );
00129       mLeft->setBrush( Qt::black );
00130     }
00131     QPointArray a = QPointArray( 4 );
00132     a.setPoint( 0, 0, -mw -myItemSize/2 - 2 );
00133     a.setPoint( 1, mw, -myItemSize/2 - 2 );
00134     a.setPoint( 2, mw, myItemSize/2 + 2 );
00135     a.setPoint( 3, 0, myItemSize/2 + mw + 2 );
00136     mLeft->setPoints( a );
00137   }
00138   if ( !mRight || mw != mMarkerWidth ) {
00139     if ( !mRight ) {
00140       mRight = new KDCanvasPolygon( myGanttView->myTimeTable, this, Type_is_KDGanttViewItem );
00141       mRight->setBrush( Qt::black );
00142     }
00143     QPointArray a = QPointArray( 4 );
00144     a.setPoint( 0, -mw, -myItemSize/2 - 2 );
00145     a.setPoint( 1, 0, -myItemSize/2 - mw - 2 );
00146     a.setPoint( 2, 0, myItemSize/2 + mw + 2 );
00147     a.setPoint( 3, -mw, myItemSize/2 + 2 );
00148     mRight->setPoints( a );
00149   }
00150   mMarkerWidth = mw;
00151   mLeft->setX( startX );
00152   mLeft->setY( y );
00153   mLeft->setZ( startShape->z() - 1 );
00154   mLeft->show();
00155   mRight->setX( endX );
00156   mRight->setY( y );
00157   mRight->setZ( startShape->z() - 1 );
00158   mRight->show();
00159 }
KDE Home | KDE Accessibility Home | Description of Access Keys