31 #include <kdgantt/KDGanttViewTaskItem.h>
32 #include <kdgantt/KDGanttViewSubwidgets.h>
34 #include "koeventpopupmenu.h"
35 #include "koglobals.h"
37 #include "timelineitem.h"
39 #include "kotimelineview.h"
44 KOTimelineView::KOTimelineView(
Calendar *calendar, TQWidget *parent,
49 TQVBoxLayout* vbox =
new TQVBoxLayout(
this);
50 mGantt =
new KDGanttView(
this);
51 mGantt->setCalendarMode(
true );
52 mGantt->setShowLegendButton(
false );
53 mGantt->setFixedHorizon(
true );
54 mGantt->removeColumn( 0 );
55 mGantt->addColumn( i18n(
"Calendar") );
56 mGantt->setHeaderVisible(
true );
57 if ( TDEGlobal::locale()->use12Clock() )
58 mGantt->setHourFormat( KDGanttView::Hour_12 );
60 mGantt->setHourFormat( KDGanttView::Hour_24_FourDigit );
63 vbox->addWidget( mGantt );
65 connect( mGantt, TQ_SIGNAL(gvCurrentChanged(KDGanttViewItem*)),
66 TQ_SLOT(itemSelected(KDGanttViewItem*)) );
67 connect( mGantt, TQ_SIGNAL(itemDoubleClicked(KDGanttViewItem*)),
68 TQ_SLOT(itemDoubleClicked(KDGanttViewItem*)) );
69 connect( mGantt, TQ_SIGNAL(itemRightClicked(KDGanttViewItem*)),
70 TQ_SLOT(itemRightClicked(KDGanttViewItem*)) );
71 connect( mGantt, TQ_SIGNAL(gvItemMoved(KDGanttViewItem*)),
72 TQ_SLOT(itemMoved(KDGanttViewItem*)) );
73 connect( mGantt, TQ_SIGNAL(rescaling(KDGanttView::Scale)),
74 TQ_SLOT(overscale(KDGanttView::Scale)) );
75 connect( mGantt, TQ_SIGNAL( dateTimeDoubleClicked(
const TQDateTime& ) ),
76 TQ_SLOT( newEventWithHint(
const TQDateTime& ) ) );
79 KOTimelineView::~KOTimelineView()
93 return KCal::DateList();
107 mHintDate = TQDateTime();
108 mGantt->setHorizonStart( TQDateTime(start) );
109 mGantt->setHorizonEnd( TQDateTime(end.addDays(1)) );
110 mGantt->setMinorScaleCount( 1 );
111 mGantt->setScale( KDGanttView::Hour );
112 mGantt->setMinimumScale( KDGanttView::Hour );
113 mGantt->setMaximumScale( KDGanttView::Hour );
116 mGantt->setUpdateEnabled(
false );
120 TimelineItem *item = 0;
123 item =
new TimelineItem( i18n(
"Calendar"),
calendar(), mGantt );
124 mCalendarItemMap[0][TQString()] = item;
127 for ( CalendarResourceManager::ActiveIterator it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
128 TQColor resourceColor = *KOPrefs::instance()->resourceColor( (*it)->identifier() );
129 if ( (*it)->canHaveSubresources() ) {
130 TQStringList subResources = (*it)->subresources();
131 for ( TQStringList::ConstIterator subit = subResources.constBegin(); subit != subResources.constEnd(); ++subit ) {
132 TQString type = (*it)->subresourceType( *subit );
133 if ( !(*it)->subresourceActive( *subit ) || (!type.isEmpty() && type !=
"event") )
135 item =
new TimelineItem( (*it)->labelForSubresource( *subit ),
calendar(), mGantt );
136 resourceColor = *KOPrefs::instance()->resourceColor( (*it)->identifier() );
137 TQColor subrescol = *KOPrefs::instance()->resourceColor( *subit );
138 if ( subrescol.isValid() )
139 resourceColor = subrescol;
140 if ( resourceColor.isValid() )
141 item->setColors( resourceColor, resourceColor, resourceColor );
142 mCalendarItemMap[*it][*subit] = item;
145 item =
new TimelineItem( (*it)->resourceName(),
calendar(), mGantt );
146 if ( resourceColor.isValid() )
147 item->setColors( resourceColor, resourceColor, resourceColor );
148 mCalendarItemMap[*it][TQString()] = item;
155 for ( TQDate day = start; day <= end; day = day.addDays( 1 ) ) {
157 for ( Event::List::ConstIterator it = events.constBegin(); it != events.constEnd(); ++it ) {
158 insertIncidence( *it, day );
162 mGantt->setUpdateEnabled(
true );
173 if ( mStartDate.isValid() && mEndDate.isValid() )
180 kdDebug() << k_funcinfo << incidence <<
" " << mode << endl;
182 case KOGlobals::INCIDENCEADDED:
183 insertIncidence( incidence );
185 case KOGlobals::INCIDENCEEDITED:
186 removeIncidence( incidence );
187 insertIncidence( incidence );
189 case KOGlobals::INCIDENCEDELETED:
190 removeIncidence( incidence );
197 void KOTimelineView::itemSelected( KDGanttViewItem *item )
199 TimelineSubItem *tlitem =
dynamic_cast<TimelineSubItem*
>( item );
201 emit incidenceSelected( tlitem->incidence(), tlitem->originalStart().date() );
204 void KOTimelineView::itemDoubleClicked( KDGanttViewItem *item )
206 TimelineSubItem *tlitem =
dynamic_cast<TimelineSubItem*
>( item );
212 void KOTimelineView::itemRightClicked( KDGanttViewItem *item )
214 mHintDate = mGantt->getDateTimeForCoordX( TQCursor::pos().x(),
true );
215 TimelineSubItem *tlitem =
dynamic_cast<TimelineSubItem*
>( item );
228 endDt = mHintDate.addSecs( 2 * 60 * 60 );
230 return mHintDate.isValid();
234 void KOTimelineView::newEventWithHint(
const TQDateTime& dt )
240 TimelineItem * KOTimelineView::calendarItemForIncidence(
KCal::Incidence * incidence)
243 TimelineItem *item = 0;
245 item = mCalendarItemMap[0][TQString()];
252 item = mCalendarItemMap[res][subRes];
254 item = mCalendarItemMap[res][TQString()];
260 void KOTimelineView::insertIncidence(
KCal::Incidence * incidence,
const TQDate &day )
262 TimelineItem *item = calendarItemForIncidence( incidence );
264 kdWarning() << k_funcinfo <<
"Help! Something is really wrong here!" << endl;
272 item->insertIncidence( incidence, TQDateTime( day, incidence->
dtStart().time() ),
273 TQDateTime( day, incidence->
dtEnd().time() ) );
275 for ( TQValueList<TQDateTime>::ConstIterator it = l.constBegin();
276 it != l.constEnd(); ++it ) {
277 item->insertIncidence( incidence, *it, incidence->
endDateForStart( *it ) );
281 if ( incidence->
dtStart().date() == day || incidence->
dtStart().date() < mStartDate )
282 item->insertIncidence( incidence );
292 insertIncidence( incidence, TQDate() );
293 for ( TQDate day = mStartDate; day <= mEndDate; day = day.addDays( 1 ) ) {
294 Event::List events =
calendar()->
events( day, EventSortStartDate, SortDirectionAscending );
295 for ( Event::List::ConstIterator it = events.constBegin(); it != events.constEnd(); ++it ) {
296 if ( events.contains( event ) )
297 insertIncidence( *it, day );
304 TimelineItem *item = calendarItemForIncidence( incidence );
306 item->removeIncidence( incidence );
309 typedef TQMap<TQString, KOrg::TimelineItem*> M2_t;
310 typedef TQMap<KCal::ResourceCalendar*, M2_t> M1_t;
311 for ( M1_t::ConstIterator it1 = mCalendarItemMap.constBegin(); it1 != mCalendarItemMap.constEnd(); ++it1 ) {
312 for ( M2_t::ConstIterator it2 = it1.data().constBegin(); it2 != it1.data().constEnd(); ++it2 ) {
314 it2.data()->removeIncidence( incidence );
321 void KOTimelineView::itemMoved(KDGanttViewItem * item)
323 TimelineSubItem *tlit =
dynamic_cast<TimelineSubItem*
>( item );
327 mChanger->beginChange( i, 0, TQString() );
328 TQDateTime newStart = tlit->startTime();
330 newStart = TQDateTime( newStart.date() );
331 int delta = tlit->originalStart().secsTo( newStart );
333 int duration = tlit->startTime().secsTo( tlit->endTime() );
334 int allDayOffset = 0;
336 duration /= (60*60*24);
337 duration *= (60*60*24);
338 allDayOffset = (60*60*24);
339 duration -= allDayOffset;
340 if ( duration < 0 ) duration = 0;
342 i->setDuration( duration );
343 TimelineItem *parent =
static_cast<TimelineItem*
>( tlit->parent() );
344 parent->moveItems( i, tlit->originalStart().secsTo( newStart ), duration + allDayOffset );
345 mChanger->endChange( i, 0, TQString() );
348 void KOTimelineView::overscale(KDGanttView::Scale scale)
351 mGantt->setZoomFactor( 1,
false );
352 mGantt->setScale( KDGanttView::Hour );
353 mGantt->setMinorScaleCount( 12 );
356 #include "kotimelineview.moc"
ResourceCalendar * resource(Incidence *incidence)
CalendarResourceManager * resourceManager() const
virtual Event::List events(EventSortField sortField=EventSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Incidence * incidence(const TQString &uid)
virtual TQDateTime dtStart() const
virtual TQDateTime dtEnd() const
virtual void setDtStart(const TQDateTime &dtStart)
virtual TQValueList< TQDateTime > startDateTimesForDate(const TQDate &date) const
virtual TQDateTime endDateForStart(const TQDateTime &startDt) const
virtual TQString subresourceIdentifier(Incidence *incidence)
virtual bool canHaveSubresources() const
KOEventView is the abstract base class from which all other calendar views for event data are derived...
KOEventPopupMenu * eventPopup()
Construct a standard context menu for an event.
virtual void showDates(const TQDate &, const TQDate &)
Show incidences for the given date range.
virtual KCal::ListBase< KCal::Incidence > selectedIncidences()
virtual bool eventDurationHint(TQDateTime &startDt, TQDateTime &endDt, bool &allDay)
Set the default start/end date/time for new events.
virtual void updateView()
Updates the current display to reflect changes that may have happened in the calendar since the last ...
virtual KCal::DateList selectedIncidenceDates()
virtual int currentDateCount()
Return number of currently shown dates.
virtual void changeIncidenceDisplay(KCal::Incidence *incidence, int mode)
Updates the current display to reflect the changes to one particular incidence.
void editIncidenceSignal(Incidence *, const TQDate &)
instructs the receiver to begin editing the incidence specified in some manner.
void newEventSignal(ResourceCalendar *res, const TQString &subResource)
instructs the receiver to create a new event.
virtual Calendar * calendar()
Return calendar object of this view.