kplato

kpttaskappointmentsview.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Dag Andersen <danders@get2net.dk>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library 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 GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kpttaskappointmentsview.h"
21
22#include "kptappointment.h"
23#include "kpttask.h"
24
25#include <tqapplication.h>
26#include <kcalendarsystem.h>
27#include <tdeglobal.h>
28#include <tdelocale.h>
29
30#include <tqheader.h>
31
32namespace KPlato
33{
34
35TaskAppointmentsView::ResourceItem::ResourceItem(Resource *r, TQListView *parent, bool highlight)
36 : DoubleListViewBase::MasterListItem(parent, r->name(), highlight),
37 resource(r) {
38
39 setFormat(0, 'f', 1);
40 //kdDebug()<<k_funcinfo<<endl;
41}
42TaskAppointmentsView::ResourceItem::ResourceItem(Resource *r, TQListViewItem *p, bool highlight)
43 : DoubleListViewBase::MasterListItem(p, r->name(), highlight),
44 resource(r) {
45
46 setFormat(0, 'f', 1);
47 //kdDebug()<<k_funcinfo<<endl;
48}
49
50TaskAppointmentsView::ResourceItem::ResourceItem(TQString text, TQListViewItem *parent, bool highlight)
51 : DoubleListViewBase::MasterListItem(parent, text, highlight),
52 resource(0) {
53
54 setFormat(0, 'f', 1);
55 //kdDebug()<<k_funcinfo<<endl;
56}
57
58//-------------------------------------------
59TaskAppointmentsView::TaskAppointmentsView(TQWidget *parent)
60 : DoubleListViewBase(parent),
61 m_task(0) {
62
63 setNameHeader(i18n("Resource"));
64
65
66 TQValueList<int> list = sizes();
67 int tot = list[0] + list[1];
68 list[0] = TQMIN(35, tot);
69 list[1] = tot-list[0];
70 setSizes(list);
71}
72
73void TaskAppointmentsView::zoom(double zoom) {
74 Q_UNUSED(zoom);
75}
76
77
78void TaskAppointmentsView::draw(Task *task) {
79 m_task = task;
80 draw();
81}
82
83void TaskAppointmentsView::draw() {
84 //kdDebug()<<k_funcinfo<<endl;
85 clearLists();
86 if (!m_task)
87 return;
88
89 TQPtrList<Appointment> lst = m_task->appointments();
90 TQPtrListIterator<Appointment> it(lst);
91 for (; it.current(); ++it) {
92 Resource *r = it.current()->resource()->resource();
93 TaskAppointmentsView::ResourceItem *item = new TaskAppointmentsView::ResourceItem(r, masterListView());
94
95 item->effortMap = it.current()->plannedPrDay(m_task->startTime().date(), m_task->endTime().date());
96 }
97 slotUpdate();
98}
99
100void TaskAppointmentsView::drawContents(TQPainter* painter)
101{
102 this->DoubleListViewBase::drawContents(painter);
103}
104
105void TaskAppointmentsView::slotUpdate() {
106 //kdDebug()<<k_funcinfo<<endl;
107 if (!m_task)
108 return;
109 TQApplication::setOverrideCursor(TQt::waitCursor);
110 createSlaveItems();
111 TDELocale *locale = TDEGlobal::locale();
112 const KCalendarSystem *cal = locale->calendar();
113
114 // Add columns for selected period/periods
115 TQDate start = m_task->startTime().date();
116 TQDate end = m_task->endTime().date();
117 //kdDebug()<<k_funcinfo<<start.toString()<<" - "<<end.toString()<<endl;
118 int c=0;
119 for (TQDate dt = start; dt <= end; dt = cal->addDays(dt, 1), ++c) {
120 TQString df = locale->formatDate(dt, true);
121 addSlaveColumn(df);
122 }
123 TQListViewItemIterator it(masterListView());
124 for (;it.current(); ++it) {
125 TaskAppointmentsView::ResourceItem *item = static_cast<TaskAppointmentsView::ResourceItem*>(it.current());
126 if (!item) {
127 continue;
128 }
129 double eff;
130 int col=0;
131 for (TQDate d=start; d <= end; d = cal->addDays(d, 1), ++col) {
132 eff = (double)(item->effortMap.effortOnDate(d).minutes())/60.0;
133 item->setSlaveItem(col, eff);
134 item->addToTotal(eff);
135 }
136 }
137 calculate();
138 TQApplication::restoreOverrideCursor();
139}
140
141
142void TaskAppointmentsView::print(KPrinter &/*printer*/) {
143 kdDebug()<<k_funcinfo<<endl;
144}
145
146// bool TaskAppointmentsView::setContext(Context::TaskAppointmentsView &context) {
147// //kdDebug()<<k_funcinfo<<endl;
148//
149// TQValueList<int> list;
150// list << context.accountsviewsize << context.periodviewsize;
151// m_dlv->setSizes(list);
152// m_date = context.date;
153// if (!m_date.isValid())
154// m_date = TQDate::currentDate();
155// m_period = context.period;
156// m_cumulative = context.cumulative;
157//
158// return true;
159// }
160//
161// void TaskAppointmentsView::getContext(Context::TaskAppointmentsView &context) const {
162// //kdDebug()<<k_funcinfo<<endl;
163// context.accountsviewsize = m_dlv->sizes()[0];
164// context.periodviewsize = m_dlv->sizes()[1];
165// context.date = m_date;
166// context.period = m_period;
167// context.cumulative = m_cumulative;
168// //kdDebug()<<k_funcinfo<<"sizes="<<sizes()[0]<<","<<sizes()[1]<<endl;
169// }
170
171void TaskAppointmentsView::clear() {
172 clearLists();
173}
174
175void TaskAppointmentsView::createSlaveItems() {
176 DoubleListViewBase::createSlaveItems();
177 setSlaveFormat(0, 'f', 1);
178}
179
180} //KPlato namespace
181
182#include "kpttaskappointmentsview.moc"