korganizer

timelineitem.cpp
1/*
2 Copyright (c) 2007 Volker Krause <vkrause@kde.org>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17*/
18
19#include "timelineitem.h"
20
21#include "kohelper.h"
22
23#define protected public
24#include <kdgantt/KDGanttViewSubwidgets.h>
25#undef public
26
27#include <libkcal/calendar.h>
28#include <libkcal/incidenceformatter.h>
29#include <libkcal/resourcecalendar.h>
30
31using namespace KOrg;
32using namespace KCal;
33
34TimelineItem::TimelineItem( const TQString &label, KCal::Calendar *calendar, KDGanttView * parent) :
35 KDGanttViewTaskItem( parent ), mCalendar( calendar )
36{
37 setListViewText( 0, label );
38 setDisplaySubitemsAsGroup( true );
39 if ( listView() )
40 listView()->setRootIsDecorated( false );
41}
42
43void TimelineItem::insertIncidence(KCal::Incidence * incidence, const TQDateTime & _start, const TQDateTime & _end)
44{
45 TQDateTime start = incidence->dtStart(), end = incidence->dtEnd();
46 if ( _start.isValid() )
47 start = _start;
48 if ( _end.isValid() )
49 end = _end;
50 if ( incidence->doesFloat() )
51 end = end.addDays( 1 );
52
53 typedef TQValueList<TimelineSubItem*> ItemList;
54 ItemList list = mItemMap[incidence];
55 for ( ItemList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it )
56 if ( (*it)->startTime() == start && (*it)->endTime() == end )
57 return;
58
59 TimelineSubItem * item = new TimelineSubItem( mCalendar, incidence, this );
60 TQColor c1, c2, c3;
61 colors( c1, c2, c3 );
62 item->setColors( c1, c2, c3 );
63
64 item->setStartTime( start );
65 item->setOriginalStart( start );
66 item->setEndTime( end );
67
68 mItemMap[incidence].append( item );
69}
70
71void TimelineItem::removeIncidence(KCal::Incidence * incidence)
72{
73 typedef TQValueList<TimelineSubItem*> ItemList;
74 ItemList list = mItemMap[incidence];
75 for ( ItemList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it )
76 delete *it;
77 mItemMap.remove( incidence );
78}
79
80void TimelineItem::moveItems(KCal::Incidence * incidence, int delta, int duration)
81{
82 typedef TQValueList<TimelineSubItem*> ItemList;
83 ItemList list = mItemMap[incidence];
84 for ( ItemList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it ) {
85 TQDateTime start = (*it)->originalStart();
86 start = start.addSecs( delta );
87 (*it)->setStartTime( start );
88 (*it)->setOriginalStart( start );
89 (*it)->setEndTime( start.addSecs( duration ) );
90 }
91}
92
93
94TimelineSubItem::TimelineSubItem( KCal::Calendar *calendar,
95 KCal::Incidence *incidence, TimelineItem *parent) :
96 KDGanttViewTaskItem( parent ),
97 mIncidence( incidence ),
98 mLeft( 0 ),
99 mRight( 0 ),
100 mMarkerWidth( 0 )
101{
102 setTooltipText( IncidenceFormatter::toolTipStr( calendar, incidence,
103 originalStart().date(), true ) );
104 if ( !incidence->isReadOnly() ) {
105 setMoveable( true );
106 setResizeable( true );
107 }
108}
109
110TimelineSubItem::~TimelineSubItem()
111{
112 delete mLeft;
113 delete mRight;
114}
115
116void TimelineSubItem::showItem(bool show, int coordY)
117{
118 KDGanttViewTaskItem::showItem( show, coordY );
119 int y;
120 if ( coordY != 0 )
121 y = coordY;
122 else
123 y = getCoordY();
124 int startX = myGanttView->timeHeaderWidget()->getCoordX(myStartTime);
125 int endX = myGanttView->timeHeaderWidget()->getCoordX(myEndTime);
126
127 const int mw = TQMAX( 1, TQMIN( 4, endX - startX ) );
128 if ( !mLeft || mw != mMarkerWidth ) {
129 if ( !mLeft ) {
130 mLeft = new KDCanvasPolygon( myGanttView->timeTableWidget(), this, Type_is_KDGanttViewItem );
131 mLeft->setBrush( TQt::black );
132 }
133 TQPointArray a = TQPointArray( 4 );
134 a.setPoint( 0, 0, -mw -myItemSize/2 - 2 );
135 a.setPoint( 1, mw, -myItemSize/2 - 2 );
136 a.setPoint( 2, mw, myItemSize/2 + 2 );
137 a.setPoint( 3, 0, myItemSize/2 + mw + 2 );
138 mLeft->setPoints( a );
139 }
140 if ( !mRight || mw != mMarkerWidth ) {
141 if ( !mRight ) {
142 mRight = new KDCanvasPolygon( myGanttView->timeTableWidget(), this, Type_is_KDGanttViewItem );
143 mRight->setBrush( TQt::black );
144 }
145 TQPointArray a = TQPointArray( 4 );
146 a.setPoint( 0, -mw, -myItemSize/2 - 2 );
147 a.setPoint( 1, 0, -myItemSize/2 - mw - 2 );
148 a.setPoint( 2, 0, myItemSize/2 + mw + 2 );
149 a.setPoint( 3, -mw, myItemSize/2 + 2 );
150 mRight->setPoints( a );
151 }
152 mMarkerWidth = mw;
153 mLeft->setX( startX );
154 mLeft->setY( y );
155 mLeft->setZ( startShape->z() - 1 );
156 mLeft->show();
157 mRight->setX( endX );
158 mRight->setY( y );
159 mRight->setZ( startShape->z() - 1 );
160 mRight->show();
161}
bool doesFloat() const
virtual TQDateTime dtStart() const
bool isReadOnly() const
virtual TQDateTime dtEnd() const