korganizer Library API Documentation

koprojectview.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 // $Id: koprojectview.cpp,v 1.11 2002/07/20 17:40:33 cschumac Exp $
00021 
00022 #include <qlayout.h>
00023 #include <qheader.h>
00024 #include <qpushbutton.h>
00025 #include <qfont.h>
00026 #include <qlabel.h>
00027 #include <qlineedit.h>
00028 #include <qlistbox.h>
00029 #include <qpopupmenu.h>
00030 #include <qstrlist.h>
00031 #include <qlistview.h>
00032 
00033 #include <kapplication.h>
00034 #include <kdebug.h>
00035 #include <klocale.h>
00036 #include <kglobal.h>
00037 #include <kiconloader.h>
00038 #include <kmessagebox.h>
00039 #include <kconfig.h>
00040 
00041 #include <libkcal/vcaldrag.h>
00042 
00043 #include "KGantt.h"
00044 
00045 #include "koprojectview.h"
00046 using namespace KOrg;
00047 #include "koprojectview.moc"
00048 
00049 KOProjectViewItem::KOProjectViewItem(Todo *event,KGanttItem* parentTask,
00050                                      const QString& text,
00051                                      const QDateTime& start,
00052                                      const QDateTime& end) :
00053   KGanttItem(parentTask,text,start,end)
00054 {
00055   mEvent = event;
00056 }
00057 
00058 KOProjectViewItem::~KOProjectViewItem()
00059 {
00060 }
00061 
00062 Todo *KOProjectViewItem::event()
00063 {
00064   return mEvent;
00065 }
00066 
00067 
00068 KOProjectView::KOProjectView(Calendar *calendar,QWidget* parent,
00069                              const char* name) :
00070   KOrg::BaseView(calendar,parent,name)
00071 {
00072   QBoxLayout *topLayout = new QVBoxLayout(this);
00073 
00074   QBoxLayout *topBar = new QHBoxLayout;
00075   topLayout->addLayout(topBar);
00076 
00077   QLabel *title = new QLabel(i18n("Project View"),this);
00078   title->setFrameStyle(QFrame::Panel|QFrame::Raised);
00079   topBar->addWidget(title,1);
00080 
00081   QPushButton *zoomIn = new QPushButton(i18n("Zoom In"),this);
00082   topBar->addWidget(zoomIn,0);
00083   connect(zoomIn,SIGNAL(clicked()),SLOT(zoomIn()));
00084 
00085   QPushButton *zoomOut = new QPushButton(i18n("Zoom Out"),this);
00086   topBar->addWidget(zoomOut,0);
00087   connect(zoomOut,SIGNAL(clicked()),SLOT(zoomOut()));
00088 
00089   QPushButton *menuButton = new QPushButton(i18n("Select Mode"),this);
00090   topBar->addWidget(menuButton,0);
00091   connect(menuButton,SIGNAL(clicked()),SLOT(showModeMenu()));
00092 
00093   createMainTask();
00094 
00095   mGantt = new KGantt(mMainTask,this);
00096   topLayout->addWidget(mGantt,1);
00097 
00098 #if 0
00099   mGantt->addHoliday(2000, 10, 3);
00100   mGantt->addHoliday(2001, 10, 3);
00101   mGantt->addHoliday(2000, 12, 24);
00102 
00103   for(int i=1; i<7; i++)
00104     mGantt->addHoliday(2001, 1, i);
00105 #endif
00106 }
00107 
00108 void KOProjectView::createMainTask()
00109 {
00110   mMainTask = new KGanttItem(0,i18n("main task"),
00111                          QDateTime::currentDateTime(),
00112                          QDateTime::currentDateTime());
00113   mMainTask->setMode(KGanttItem::Rubberband);
00114   mMainTask->setStyle(KGanttItem::DrawBorder | KGanttItem::DrawText |
00115                       KGanttItem::DrawHandle);
00116 }
00117 
00118 void KOProjectView::readSettings()
00119 {
00120   kdDebug() << "KOProjectView::readSettings()" << endl;
00121 
00122   KConfig *config = kapp->config();
00123 
00124   config->setGroup("Views");
00125 
00126   QValueList<int> sizes = config->readIntListEntry("Separator ProjectView");
00127   if (sizes.count() == 2) {
00128     mGantt->splitter()->setSizes(sizes);
00129   }
00130 }
00131 
00132 void KOProjectView::writeSettings(KConfig *config)
00133 {
00134   kdDebug() << "KOProjectView::writeSettings()" << endl;
00135 
00136   config->setGroup("Views");
00137 
00138   QValueList<int> list = mGantt->splitter()->sizes();
00139   config->writeEntry("Separator ProjectView",list);
00140 }
00141 
00142 
00143 void KOProjectView::updateView()
00144 {
00145   kdDebug() << "KOProjectView::updateView()" << endl;
00146 
00147   // Clear Gantt view
00148   QPtrList<KGanttItem> subs = mMainTask->getSubItems();
00149   KGanttItem *t=subs.first();
00150   while(t) {
00151     KGanttItem *nt=subs.next();
00152     delete t;
00153     t = nt;
00154   }
00155 
00156 #if 0
00157   KGanttItem* t1 = new KGanttItem(mGantt->getMainTask(), "task 1, no subtasks",
00158                              QDateTime::currentDateTime().addDays(10),
00159                              QDateTime::currentDateTime().addDays(20) );
00160 
00161   KGanttItem* t2 = new KGanttItem(mGantt->getMainTask(), "task 2, subtasks, no rubberband",
00162                              QDateTime(QDate(2000,10,1)),
00163                              QDateTime(QDate(2000,10,31)) );
00164 #endif
00165 
00166   QPtrList<Todo> todoList = calendar()->todos();
00167 
00168 /*
00169   kdDebug() << "KOProjectView::updateView(): Todo List:" << endl;
00170   Event *t;
00171   for(t = todoList.first(); t; t = todoList.next()) {
00172     kdDebug() << "  " << t->getSummary() << endl;
00173 
00174     if (t->getRelatedTo()) {
00175       kdDebug() << "      (related to " << t->getRelatedTo()->getSummary() << ")" << endl;
00176     }
00177 
00178     QPtrList<Event> l = t->getRelations();
00179     Event *c;
00180     for(c=l.first();c;c=l.next()) {
00181       kdDebug() << "    - relation: " << c->getSummary() << endl;
00182     }
00183   }
00184 */
00185 
00186   // Put for each Event a KOProjectViewItem in the list view. Don't rely on a
00187   // specific order of events. That means that we have to generate parent items
00188   // recursively for proper hierarchical display of Todos.
00189   mTodoMap.clear();
00190   Todo *todo;
00191   for(todo = todoList.first(); todo; todo = todoList.next()) {
00192     if (!mTodoMap.contains(todo)) {
00193       insertTodoItem(todo);
00194     }
00195   }
00196 }
00197 
00198 QMap<Todo *,KGanttItem *>::ConstIterator
00199     KOProjectView::insertTodoItem(Todo *todo)
00200 {
00201 //  kdDebug() << "KOProjectView::insertTodoItem(): " << todo->getSummary() << endl;
00202   Todo *relatedTodo = dynamic_cast<Todo *>(todo->relatedTo());
00203   if (relatedTodo) {
00204 //    kdDebug() << "  has Related" << endl;
00205     QMap<Todo *,KGanttItem *>::ConstIterator itemIterator;
00206     itemIterator = mTodoMap.find(relatedTodo);
00207     if (itemIterator == mTodoMap.end()) {
00208 //      kdDebug() << "    related not yet in list" << endl;
00209       itemIterator = insertTodoItem (relatedTodo);
00210     }
00211     KGanttItem *task = createTask(*itemIterator,todo);
00212     return mTodoMap.insert(todo,task);
00213   } else {
00214 //    kdDebug() << "  no Related" << endl;
00215     KGanttItem *task = createTask(mMainTask,todo);
00216     return mTodoMap.insert(todo,task);
00217   }
00218 }
00219 
00220 KGanttItem *KOProjectView::createTask(KGanttItem *parent,Todo *todo)
00221 {
00222   QDateTime startDt;
00223   QDateTime endDt;
00224 
00225   if (todo->hasStartDate() && !todo->hasDueDate()) {
00226     // start date but no due date
00227     startDt = todo->dtStart();
00228     endDt = QDateTime::currentDateTime();
00229   } else if (!todo->hasStartDate() && todo->hasDueDate()) {
00230     // due date but no start date
00231     startDt = todo->dtDue();
00232     endDt = todo->dtDue();
00233   } else if (!todo->hasStartDate() || !todo->hasDueDate()) {
00234     startDt = QDateTime::currentDateTime();
00235     endDt = QDateTime::currentDateTime();
00236   } else {
00237     startDt = todo->dtStart();
00238     endDt = todo->dtDue();
00239   }
00240 
00241   KGanttItem *task = new KOProjectViewItem(todo,parent,todo->summary(),startDt,
00242                                        endDt);
00243   connect(task,SIGNAL(changed(KGanttItem*, KGanttItem::Change)),
00244           SLOT(taskChanged(KGanttItem*,KGanttItem::Change)));
00245   if (todo->relations().count() > 0) {
00246     task->setBrush(QBrush(QColor(240,240,240), QBrush::Dense4Pattern));
00247   }
00248 
00249   return task;
00250 }
00251 
00252 void KOProjectView::updateConfig()
00253 {
00254   // TODO: to be implemented.
00255 }
00256 
00257 QPtrList<Incidence> KOProjectView::selectedIncidences()
00258 {
00259   QPtrList<Incidence> selected;
00260 
00261 /*
00262   KOProjectViewItem *item = (KOProjectViewItem *)(mTodoListView->selectedItem());
00263   if (item) selected.append(item->event());
00264 */
00265 
00266   return selected;
00267 }
00268 
00269 DateList KOProjectView::selectedDates()
00270 {
00271   DateList selected;
00272   return selected;
00273 }
00274 
00275 void KOProjectView::changeEventDisplay(Event *, int)
00276 {
00277   updateView();
00278 }
00279 
00280 void KOProjectView::showDates(const QDate &, const QDate &)
00281 {
00282   updateView();
00283 }
00284 
00285 void KOProjectView::showEvents(QPtrList<Event>)
00286 {
00287   kdDebug() << "KOProjectView::selectEvents(): not yet implemented" << endl;
00288 }
00289 
00290 #if 0
00291 void KOProjectView::editItem(QListViewItem *item)
00292 {
00293   emit editEventSignal(((KOProjectViewItem *)item)->event());
00294 }
00295 
00296 void KOProjectView::showItem(QListViewItem *item)
00297 {
00298   emit showTodoSignal(((KOProjectViewItem *)item)->event());
00299 }
00300 
00301 void KOProjectView::popupMenu(QListViewItem *item,const QPoint &,int)
00302 {
00303   mActiveItem = (KOProjectViewItem *)item;
00304   if (item) mItemPopupMenu->popup(QCursor::pos());
00305   else mPopupMenu->popup(QCursor::pos());
00306 }
00307 
00308 void KOProjectView::newTodo()
00309 {
00310   emit newTodoSignal();
00311 }
00312 
00313 void KOProjectView::newSubTodo()
00314 {
00315   if (mActiveItem) {
00316     emit newSubTodoSignal(mActiveItem->event());
00317   }
00318 }
00319 
00320 void KOProjectView::editTodo()
00321 {
00322   if (mActiveItem) {
00323     emit editEventSignal(mActiveItem->event());
00324   }
00325 }
00326 
00327 void KOProjectView::showTodo()
00328 {
00329   if (mActiveItem) {
00330     emit showTodoSignal(mActiveItem->event());
00331   }
00332 }
00333 
00334 void KOProjectView::deleteTodo()
00335 {
00336   if (mActiveItem) {
00337     if (mActiveItem->childCount()) {
00338       KMessageBox::sorry(this,i18n("Cannot delete To-Do which has children."),
00339                          i18n("Delete To-Do"));
00340     } else {
00341       emit deleteEventSignal(mActiveItem->event());
00342     }
00343   }
00344 }
00345 
00346 void KOProjectView::purgeCompleted()
00347 {
00348   int result = KMessageBox::warningContinueCancel(this,
00349       i18n("Delete all completed To-Dos?"),i18n("Purge To-Dos"),i18n("Purge"));
00350 
00351   if (result == KMessageBox::Continue) {
00352     QPtrList<Todo> todoCal = calendar()->getTodoList();
00353 
00354     Todo *aTodo;
00355     for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
00356     if (aTodo->isCompleted())
00357       calendar()->deleteTodo(aTodo);
00358     }
00359     updateView();
00360   }
00361 }
00362 
00363 void KOProjectView::itemClicked(QListViewItem *item)
00364 {
00365   if (!item) return;
00366 
00367   KOProjectViewItem *todoItem = (KOProjectViewItem *)item;
00368   int completed = todoItem->event()->isCompleted();  // Completed or not?
00369 
00370   if (todoItem->isOn()) {
00371     if (!completed) {
00372       todoItem->event()->setCompleted(true);
00373     }
00374   } else {
00375     if (completed) {
00376       todoItem->event()->setCompleted(false);
00377     }
00378   }
00379 }
00380 #endif
00381 
00382 void KOProjectView::showModeMenu()
00383 {
00384   mGantt->menu()->popup(QCursor::pos());
00385 }
00386 
00387 void KOProjectView::taskChanged(KGanttItem *task,KGanttItem::Change change)
00388 {
00389   if (task == mMainTask) return;
00390 
00391   KOProjectViewItem *item = (KOProjectViewItem *)task;
00392 
00393   if (change == KGanttItem::StartChanged) {
00394     item->event()->setDtStart(task->getStart());
00395   } else if (change == KGanttItem::EndChanged) {
00396     item->event()->setDtDue(task->getEnd());
00397   }
00398 }
00399 
00400 void KOProjectView::zoomIn()
00401 {
00402   mGantt->zoom(2);
00403 }
00404 
00405 void KOProjectView::zoomOut()
00406 {
00407   mGantt->zoom(0.5);
00408 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:31 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001