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