00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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, KCal::Calendar *calendar, 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( mCalendar, 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::Calendar *calendar,
00095 KCal::Incidence *incidence, TimelineItem *parent) :
00096 KDGanttViewTaskItem( parent ),
00097 mIncidence( incidence ),
00098 mLeft( 0 ),
00099 mRight( 0 ),
00100 mMarkerWidth( 0 )
00101 {
00102 setTooltipText( IncidenceFormatter::toolTipStr( calendar, incidence ) );
00103 if ( !incidence->isReadOnly() ) {
00104 setMoveable( true );
00105 setResizeable( true );
00106 }
00107 }
00108
00109 TimelineSubItem::~TimelineSubItem()
00110 {
00111 delete mLeft;
00112 delete mRight;
00113 }
00114
00115 void TimelineSubItem::showItem(bool show, int coordY)
00116 {
00117 KDGanttViewTaskItem::showItem( show, coordY );
00118 int y;
00119 if ( coordY != 0 )
00120 y = coordY;
00121 else
00122 y = getCoordY();
00123 int startX = myGanttView->timeHeaderWidget()->getCoordX(myStartTime);
00124 int endX = myGanttView->timeHeaderWidget()->getCoordX(myEndTime);
00125
00126 const int mw = QMAX( 1, QMIN( 4, endX - startX ) );
00127 if ( !mLeft || mw != mMarkerWidth ) {
00128 if ( !mLeft ) {
00129 mLeft = new KDCanvasPolygon( myGanttView->timeTableWidget(), this, Type_is_KDGanttViewItem );
00130 mLeft->setBrush( Qt::black );
00131 }
00132 QPointArray a = QPointArray( 4 );
00133 a.setPoint( 0, 0, -mw -myItemSize/2 - 2 );
00134 a.setPoint( 1, mw, -myItemSize/2 - 2 );
00135 a.setPoint( 2, mw, myItemSize/2 + 2 );
00136 a.setPoint( 3, 0, myItemSize/2 + mw + 2 );
00137 mLeft->setPoints( a );
00138 }
00139 if ( !mRight || mw != mMarkerWidth ) {
00140 if ( !mRight ) {
00141 mRight = new KDCanvasPolygon( myGanttView->timeTableWidget(), this, Type_is_KDGanttViewItem );
00142 mRight->setBrush( Qt::black );
00143 }
00144 QPointArray a = QPointArray( 4 );
00145 a.setPoint( 0, -mw, -myItemSize/2 - 2 );
00146 a.setPoint( 1, 0, -myItemSize/2 - mw - 2 );
00147 a.setPoint( 2, 0, myItemSize/2 + mw + 2 );
00148 a.setPoint( 3, -mw, myItemSize/2 + 2 );
00149 mRight->setPoints( a );
00150 }
00151 mMarkerWidth = mw;
00152 mLeft->setX( startX );
00153 mLeft->setY( y );
00154 mLeft->setZ( startShape->z() - 1 );
00155 mLeft->show();
00156 mRight->setX( endX );
00157 mRight->setY( y );
00158 mRight->setZ( startShape->z() - 1 );
00159 mRight->show();
00160 }