kplato

kpttaskappointmentsview.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Dag Andersen <danders@get2net.dk>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library 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 GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kpttaskappointmentsview.h"
00021 
00022 #include "kptappointment.h"
00023 #include "kpttask.h"
00024 
00025 #include <qapplication.h>
00026 #include <kcalendarsystem.h>
00027 #include <kglobal.h>
00028 #include <klocale.h>
00029 
00030 #include <qheader.h>
00031 
00032 namespace KPlato
00033 {
00034 
00035 TaskAppointmentsView::ResourceItem::ResourceItem(Resource *r, QListView *parent, bool highlight)
00036     : DoubleListViewBase::MasterListItem(parent, r->name(), highlight),
00037       resource(r) {
00038       
00039       setFormat(0, 'f', 1);
00040     //kdDebug()<<k_funcinfo<<endl;
00041 }
00042 TaskAppointmentsView::ResourceItem::ResourceItem(Resource *r, QListViewItem *p, bool highlight)
00043     : DoubleListViewBase::MasterListItem(p, r->name(), highlight),
00044       resource(r) {
00045       
00046       setFormat(0, 'f', 1);
00047     //kdDebug()<<k_funcinfo<<endl;
00048 }
00049 
00050 TaskAppointmentsView::ResourceItem::ResourceItem(QString text, QListViewItem *parent, bool highlight)
00051     : DoubleListViewBase::MasterListItem(parent, text, highlight),
00052       resource(0) {
00053       
00054       setFormat(0, 'f', 1);
00055     //kdDebug()<<k_funcinfo<<endl;
00056 }
00057 
00058 //-------------------------------------------
00059 TaskAppointmentsView::TaskAppointmentsView(QWidget *parent)
00060     : DoubleListViewBase(parent),
00061       m_task(0) {
00062     
00063     setNameHeader(i18n("Resource"));
00064     
00065     
00066     QValueList<int> list = sizes();
00067     int tot = list[0] + list[1];
00068     list[0] = QMIN(35, tot);
00069     list[1] = tot-list[0];
00070     setSizes(list);
00071 }
00072 
00073 void TaskAppointmentsView::zoom(double zoom) {
00074     Q_UNUSED(zoom);
00075 }
00076 
00077 
00078 void TaskAppointmentsView::draw(Task *task) {
00079     m_task = task;
00080     draw();
00081 }
00082 
00083 void TaskAppointmentsView::draw() {
00084     //kdDebug()<<k_funcinfo<<endl;
00085     clearLists();
00086     if (!m_task)
00087         return;
00088     
00089     QPtrList<Appointment> lst = m_task->appointments();
00090     QPtrListIterator<Appointment> it(lst);
00091     for (; it.current(); ++it) {
00092         Resource *r = it.current()->resource()->resource();
00093         TaskAppointmentsView::ResourceItem *item = new TaskAppointmentsView::ResourceItem(r, masterListView());
00094         
00095         item->effortMap = it.current()->plannedPrDay(m_task->startTime().date(), m_task->endTime().date());
00096     }
00097     slotUpdate();
00098 }
00099 
00100 void TaskAppointmentsView::drawContents(QPainter* painter)
00101 {
00102   this->DoubleListViewBase::drawContents(painter);
00103 }
00104 
00105 void TaskAppointmentsView::slotUpdate() {
00106     //kdDebug()<<k_funcinfo<<endl;
00107     if (!m_task)
00108         return;
00109     QApplication::setOverrideCursor(Qt::waitCursor);
00110     createSlaveItems();
00111     KLocale *locale = KGlobal::locale();
00112     const KCalendarSystem *cal = locale->calendar();
00113     
00114     // Add columns for selected period/periods
00115     QDate start = m_task->startTime().date();
00116     QDate end = m_task->endTime().date();
00117     //kdDebug()<<k_funcinfo<<start.toString()<<" - "<<end.toString()<<endl;
00118     int c=0;
00119     for (QDate dt = start; dt <= end; dt = cal->addDays(dt, 1), ++c) {
00120         QString df = locale->formatDate(dt, true);
00121         addSlaveColumn(df);
00122     }
00123     QListViewItemIterator it(masterListView());
00124     for (;it.current(); ++it) {
00125         TaskAppointmentsView::ResourceItem *item = static_cast<TaskAppointmentsView::ResourceItem*>(it.current());
00126         if (!item) {
00127             continue;
00128         }
00129         double eff;
00130         int col=0;
00131         for (QDate d=start; d <= end; d = cal->addDays(d, 1), ++col) {
00132             eff = (double)(item->effortMap.effortOnDate(d).minutes())/60.0;
00133             item->setSlaveItem(col, eff);
00134             item->addToTotal(eff);
00135         }
00136     }
00137     calculate();
00138     QApplication::restoreOverrideCursor();
00139 }
00140 
00141 
00142 void TaskAppointmentsView::print(KPrinter &/*printer*/) {
00143     kdDebug()<<k_funcinfo<<endl;
00144 }
00145 
00146 // bool TaskAppointmentsView::setContext(Context::TaskAppointmentsView &context) {
00147 //     //kdDebug()<<k_funcinfo<<endl;
00148 //     
00149 //     QValueList<int> list;
00150 //     list << context.accountsviewsize << context.periodviewsize;
00151 //     m_dlv->setSizes(list);
00152 //     m_date = context.date;
00153 //     if (!m_date.isValid())
00154 //         m_date = QDate::currentDate();
00155 //     m_period = context.period;
00156 //     m_cumulative = context.cumulative;
00157 //     
00158 //     return true;
00159 // }
00160 // 
00161 // void TaskAppointmentsView::getContext(Context::TaskAppointmentsView &context) const {
00162 //     //kdDebug()<<k_funcinfo<<endl;
00163 //     context.accountsviewsize = m_dlv->sizes()[0];
00164 //     context.periodviewsize = m_dlv->sizes()[1];
00165 //     context.date = m_date;
00166 //     context.period = m_period;
00167 //     context.cumulative = m_cumulative;
00168 //     //kdDebug()<<k_funcinfo<<"sizes="<<sizes()[0]<<","<<sizes()[1]<<endl;
00169 // }
00170 
00171 void TaskAppointmentsView::clear() {
00172     clearLists();
00173 }
00174 
00175 void TaskAppointmentsView::createSlaveItems() {
00176     DoubleListViewBase::createSlaveItems();
00177     setSlaveFormat(0, 'f', 1);
00178 }
00179 
00180 }  //KPlato namespace
00181 
00182 #include "kpttaskappointmentsview.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys