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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include <tqlayout.h> 00021 #include <tqheader.h> 00022 #include <tqpushbutton.h> 00023 #include <tqfont.h> 00024 #include <tqlabel.h> 00025 #include <tqlineedit.h> 00026 #include <tqlistbox.h> 00027 #include <tqpopupmenu.h> 00028 #include <tqstrlist.h> 00029 #include <tqlistview.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 TQString& text, 00050 const TQDateTime& start, 00051 const TQDateTime& 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,TQWidget* parent, 00068 const char* name) : 00069 KOrg::BaseView(calendar,parent,name) 00070 { 00071 TQBoxLayout *topLayout = new TQVBoxLayout(this); 00072 00073 TQBoxLayout *topBar = new TQHBoxLayout; 00074 topLayout->addLayout(topBar); 00075 00076 TQLabel *title = new TQLabel(i18n("Project View"),this); 00077 title->setFrameStyle(TQFrame::Panel|TQFrame::Raised); 00078 topBar->addWidget(title,1); 00079 00080 TQPushButton *zoomIn = new TQPushButton(i18n("Zoom In"),this); 00081 topBar->addWidget(zoomIn,0); 00082 connect(zoomIn,TQT_SIGNAL(clicked()),TQT_SLOT(zoomIn())); 00083 00084 TQPushButton *zoomOut = new TQPushButton(i18n("Zoom Out"),this); 00085 topBar->addWidget(zoomOut,0); 00086 connect(zoomOut,TQT_SIGNAL(clicked()),TQT_SLOT(zoomOut())); 00087 00088 TQPushButton *menuButton = new TQPushButton(i18n("Select Mode"),this); 00089 topBar->addWidget(menuButton,0); 00090 connect(menuButton,TQT_SIGNAL(clicked()),TQT_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 TQDateTime::currentDateTime(), 00111 TQDateTime::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( "korganizerrc", true, false); // Open read-only, no kdeglobals 00123 config.setGroup("Views"); 00124 00125 TQValueList<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 TQValueList<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 TQPtrList<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 TQDateTime::currentDateTime().addDays(10), 00158 TQDateTime::currentDateTime().addDays(20) ); 00159 00160 KGanttItem* t2 = new KGanttItem(mGantt->getMainTask(), "task 2, subtasks, no rubberband", 00161 TQDateTime(TQDate(2000,10,1)), 00162 TQDateTime(TQDate(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 TQPtrList<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 TQMap<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 TQMap<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 TQDateTime startDt; 00222 TQDateTime endDt; 00223 00224 if (todo->hasStartDate() && !todo->hasDueDate()) { 00225 // start date but no due date 00226 startDt = todo->dtStart(); 00227 endDt = TQDateTime::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 = TQDateTime::currentDateTime(); 00234 endDt = TQDateTime::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,TQT_SIGNAL(changed(KGanttItem*, KGanttItem::Change)), 00243 TQT_SLOT(taskChanged(KGanttItem*,KGanttItem::Change))); 00244 if (todo->relations().count() > 0) { 00245 task->setBrush(TQBrush(TQColor(240,240,240), TQBrush::Dense4Pattern)); 00246 } 00247 00248 return task; 00249 } 00250 00251 void KOProjectView::updateConfig() 00252 { 00253 // FIXME: 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 TQDate &, const TQDate &) 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(TQListViewItem *item) 00291 { 00292 emit editIncidenceSignal(((KOProjectViewItem *)item)->event()); 00293 } 00294 00295 void KOProjectView::showItem(TQListViewItem *item) 00296 { 00297 emit showIncidenceSignal(((KOProjectViewItem *)item)->event()); 00298 } 00299 00300 void KOProjectView::popupMenu(TQListViewItem *item,const TQPoint &,int) 00301 { 00302 mActiveItem = (KOProjectViewItem *)item; 00303 if (item) mItemPopupMenu->popup(TQCursor::pos()); 00304 else mPopupMenu->popup(TQCursor::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::itemClicked(TQListViewItem *item) 00320 { 00321 if (!item) return; 00322 00323 KOProjectViewItem *todoItem = (KOProjectViewItem *)item; 00324 int completed = todoItem->event()->isCompleted(); // Completed or not? 00325 00326 if (todoItem->isOn()) { 00327 if (!completed) { 00328 todoItem->event()->setCompleted(true); 00329 } 00330 } else { 00331 if (completed) { 00332 todoItem->event()->setCompleted(false); 00333 } 00334 } 00335 } 00336 #endif 00337 00338 void KOProjectView::showModeMenu() 00339 { 00340 mGantt->menu()->popup(TQCursor::pos()); 00341 } 00342 00343 void KOProjectView::taskChanged(KGanttItem *task,KGanttItem::Change change) 00344 { 00345 if (task == mMainTask) return; 00346 00347 KOProjectViewItem *item = (KOProjectViewItem *)task; 00348 00349 if (change == KGanttItem::StartChanged) { 00350 item->event()->setDtStart(task->getStart()); 00351 } else if (change == KGanttItem::EndChanged) { 00352 item->event()->setDtDue(task->getEnd()); 00353 } 00354 } 00355 00356 void KOProjectView::zoomIn() 00357 { 00358 mGantt->zoom(2); 00359 } 00360 00361 void KOProjectView::zoomOut() 00362 { 00363 mGantt->zoom(0.5); 00364 } 00365 00366 #include "koprojectview.moc"