summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kotodoview.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/korganizer/kotodoview.cpp b/korganizer/kotodoview.cpp
index c5b9a21..03a8f1c 100644
--- a/korganizer/kotodoview.cpp
+++ b/korganizer/kotodoview.cpp
@@ -1,1299 +1,1303 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qlayout.h> 24#include <qlayout.h>
25#include <qheader.h> 25#include <qheader.h>
26#include <qcursor.h> 26#include <qcursor.h>
27#include <qwhatsthis.h> 27#include <qwhatsthis.h>
28 28
29#include <qvbox.h> 29#include <qvbox.h>
30#include <kdebug.h> 30#include <kdebug.h>
31#include "koprefs.h" 31#include "koprefs.h"
32#include <klocale.h> 32#include <klocale.h>
33#include <kglobal.h> 33#include <kglobal.h>
34#include <kiconloader.h> 34#include <kiconloader.h>
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36 36
37#include <libkcal/icaldrag.h> 37#include <libkcal/icaldrag.h>
38#include <libkcal/vcaldrag.h> 38#include <libkcal/vcaldrag.h>
39#include <libkcal/calfilter.h> 39#include <libkcal/calfilter.h>
40#include <libkcal/dndfactory.h> 40#include <libkcal/dndfactory.h>
41#include <libkcal/calendarresources.h> 41#include <libkcal/calendarresources.h>
42#include <libkcal/resourcecalendar.h> 42#include <libkcal/resourcecalendar.h>
43#include <kresources/resourceselectdialog.h> 43#include <kresources/resourceselectdialog.h>
44#include <libkcal/kincidenceformatter.h> 44#include <libkcal/kincidenceformatter.h>
45#ifndef DESKTOP_VERSION 45#ifndef DESKTOP_VERSION
46#include <qpe/qpeapplication.h> 46#include <qpe/qpeapplication.h>
47#else 47#else
48#include <qapplication.h> 48#include <qapplication.h>
49#endif 49#endif
50#ifndef KORG_NOPRINTER 50#ifndef KORG_NOPRINTER
51#include "calprinter.h" 51#include "calprinter.h"
52#endif 52#endif
53#include "docprefs.h" 53#include "docprefs.h"
54 54
55#include "kotodoview.h" 55#include "kotodoview.h"
56using namespace KOrg; 56using namespace KOrg;
57 57
58 58
59class KOTodoViewWhatsThis :public QWhatsThis 59class KOTodoViewWhatsThis :public QWhatsThis
60{ 60{
61public: 61public:
62 KOTodoViewWhatsThis( QWidget *wid, KOTodoView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { }; 62 KOTodoViewWhatsThis( QWidget *wid, KOTodoView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { };
63 63
64protected: 64protected:
65 virtual QString text( const QPoint& p) 65 virtual QString text( const QPoint& p)
66 { 66 {
67 return _view->getWhatsThisText(p) ; 67 return _view->getWhatsThisText(p) ;
68 } 68 }
69private: 69private:
70 QWidget* _wid; 70 QWidget* _wid;
71 KOTodoView * _view; 71 KOTodoView * _view;
72}; 72};
73 73
74KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent, 74KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent,
75 const char *name) : 75 const char *name) :
76 KListView(parent,name) 76 KListView(parent,name)
77{ 77{
78 mName = QString ( name ); 78 mName = QString ( name );
79 mCalendar = calendar; 79 mCalendar = calendar;
80#ifndef DESKTOP_VERSION 80#ifndef DESKTOP_VERSION
81 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); 81 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold );
82#endif 82#endif
83 mOldCurrent = 0; 83 mOldCurrent = 0;
84 mMousePressed = false; 84 mMousePressed = false;
85 85
86 setAcceptDrops(true); 86 setAcceptDrops(true);
87 viewport()->setAcceptDrops(true); 87 viewport()->setAcceptDrops(true);
88 int size = 16; 88 int size = 16;
89 if (qApp->desktop()->width() < 300 ) 89 if (qApp->desktop()->width() < 300 )
90 size = 12; 90 size = 12;
91 setTreeStepSize( size + 6 ); 91 setTreeStepSize( size + 6 );
92 92
93} 93}
94 94
95void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e) 95void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e)
96{ 96{
97#ifndef KORG_NODND 97#ifndef KORG_NODND
98// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl; 98// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl;
99 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 99 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
100 !QTextDrag::canDecode( e ) ) { 100 !QTextDrag::canDecode( e ) ) {
101 e->ignore(); 101 e->ignore();
102 return; 102 return;
103 } 103 }
104 104
105 mOldCurrent = currentItem(); 105 mOldCurrent = currentItem();
106#endif 106#endif
107} 107}
108 108
109 109
110void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e) 110void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e)
111{ 111{
112#ifndef KORG_NODND 112#ifndef KORG_NODND
113// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl; 113// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl;
114 114
115 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 115 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
116 !QTextDrag::canDecode( e ) ) { 116 !QTextDrag::canDecode( e ) ) {
117 e->ignore(); 117 e->ignore();
118 return; 118 return;
119 } 119 }
120 120
121 e->accept(); 121 e->accept();
122#endif 122#endif
123} 123}
124 124
125void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *) 125void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *)
126{ 126{
127#ifndef KORG_NODND 127#ifndef KORG_NODND
128// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl; 128// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl;
129 129
130 setCurrentItem(mOldCurrent); 130 setCurrentItem(mOldCurrent);
131 setSelected(mOldCurrent,true); 131 setSelected(mOldCurrent,true);
132#endif 132#endif
133} 133}
134 134
135void KOTodoListView::contentsDropEvent(QDropEvent *e) 135void KOTodoListView::contentsDropEvent(QDropEvent *e)
136{ 136{
137#ifndef KORG_NODND 137#ifndef KORG_NODND
138// kdDebug() << "KOTodoListView::contentsDropEvent" << endl; 138// kdDebug() << "KOTodoListView::contentsDropEvent" << endl;
139 139
140 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 140 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
141 !QTextDrag::canDecode( e ) ) { 141 !QTextDrag::canDecode( e ) ) {
142 e->ignore(); 142 e->ignore();
143 return; 143 return;
144 } 144 }
145 145
146 DndFactory factory( mCalendar ); 146 DndFactory factory( mCalendar );
147 Todo *todo = factory.createDropTodo(e); 147 Todo *todo = factory.createDropTodo(e);
148 148
149 if (todo) { 149 if (todo) {
150 e->acceptAction(); 150 e->acceptAction();
151 151
152 KOTodoViewItem *destination = 152 KOTodoViewItem *destination =
153 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos())); 153 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos()));
154 Todo *destinationEvent = 0; 154 Todo *destinationEvent = 0;
155 if (destination) destinationEvent = destination->todo(); 155 if (destination) destinationEvent = destination->todo();
156 156
157 Todo *existingTodo = mCalendar->todo(todo->uid()); 157 Todo *existingTodo = mCalendar->todo(todo->uid());
158 158
159 if(existingTodo) { 159 if(existingTodo) {
160 Incidence *to = destinationEvent; 160 Incidence *to = destinationEvent;
161 while(to) { 161 while(to) {
162 if (to->uid() == todo->uid()) { 162 if (to->uid() == todo->uid()) {
163 KMessageBox::sorry(this, 163 KMessageBox::sorry(this,
164 i18n("Cannot move To-Do to itself\nor a child of itself"), 164 i18n("Cannot move To-Do to itself\nor a child of itself"),
165 i18n("Drop To-Do")); 165 i18n("Drop To-Do"));
166 delete todo; 166 delete todo;
167 return; 167 return;
168 } 168 }
169 to = to->relatedTo(); 169 to = to->relatedTo();
170 } 170 }
171 internalDrop = true; 171 internalDrop = true;
172 if ( destinationEvent ) 172 if ( destinationEvent )
173 reparentTodoSignal( destinationEvent, existingTodo ); 173 reparentTodoSignal( destinationEvent, existingTodo );
174 else 174 else
175 unparentTodoSignal(existingTodo); 175 unparentTodoSignal(existingTodo);
176 delete todo; 176 delete todo;
177 } else { 177 } else {
178 mCalendar->addTodo(todo); 178 mCalendar->addTodo(todo);
179 emit todoDropped(todo, KOGlobals::EVENTADDED); 179 emit todoDropped(todo, KOGlobals::EVENTADDED);
180 if ( destinationEvent ) 180 if ( destinationEvent )
181 reparentTodoSignal( destinationEvent, todo ); 181 reparentTodoSignal( destinationEvent, todo );
182 } 182 }
183 } 183 }
184 else { 184 else {
185 QString text; 185 QString text;
186 if (QTextDrag::decode(e,text)) { 186 if (QTextDrag::decode(e,text)) {
187 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) ); 187 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) );
188 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) )); 188 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) ));
189 qDebug("Dropped : " + text); 189 qDebug("Dropped : " + text);
190 QStringList emails = QStringList::split(",",text); 190 QStringList emails = QStringList::split(",",text);
191 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 191 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
192 int pos = (*it).find("<"); 192 int pos = (*it).find("<");
193 QString name = (*it).left(pos); 193 QString name = (*it).left(pos);
194 QString email = (*it).mid(pos); 194 QString email = (*it).mid(pos);
195 if (!email.isEmpty() && todoi) { 195 if (!email.isEmpty() && todoi) {
196 todoi->todo()->addAttendee(new Attendee(name,email)); 196 todoi->todo()->addAttendee(new Attendee(name,email));
197 } 197 }
198 } 198 }
199 } 199 }
200 else { 200 else {
201 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable "); 201 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable ");
202 e->ignore(); 202 e->ignore();
203 } 203 }
204 } 204 }
205#endif 205#endif
206} 206}
207 207
208void KOTodoListView::contentsMousePressEvent(QMouseEvent* e) 208void KOTodoListView::contentsMousePressEvent(QMouseEvent* e)
209{ 209{
210#ifndef KORG_NODND 210#ifndef KORG_NODND
211 QPoint p(contentsToViewport(e->pos())); 211 QPoint p(contentsToViewport(e->pos()));
212 QListViewItem *i = itemAt(p); 212 QListViewItem *i = itemAt(p);
213 mMousePressed = false; 213 mMousePressed = false;
214 if (i) { 214 if (i) {
215 // if the user clicked into the root decoration of the item, don't 215 // if the user clicked into the root decoration of the item, don't
216 // try to start a drag! 216 // try to start a drag!
217 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) + 217 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) +
218 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) + 218 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) +
219 itemMargin() || 219 itemMargin() ||
220 p.x() < header()->sectionPos(header()->mapToIndex(0))) { 220 p.x() < header()->sectionPos(header()->mapToIndex(0))) {
221 if (e->button()==Qt::LeftButton) { 221 if (e->button()==Qt::LeftButton) {
222 mPressPos = e->pos(); 222 mPressPos = e->pos();
223 mMousePressed = true; 223 mMousePressed = true;
224 } 224 }
225 } 225 }
226 } 226 }
227#endif 227#endif
228 QListView::contentsMousePressEvent(e); 228 QListView::contentsMousePressEvent(e);
229} 229}
230void KOTodoListView::paintEvent(QPaintEvent* e) 230void KOTodoListView::paintEvent(QPaintEvent* e)
231{ 231{
232 emit paintNeeded(); 232 emit paintNeeded();
233 QListView::paintEvent( e); 233 QListView::paintEvent( e);
234} 234}
235void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e) 235void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e)
236{ 236{
237 237
238#ifndef KORG_NODND 238#ifndef KORG_NODND
239 //QListView::contentsMouseMoveEvent(e); 239 //QListView::contentsMouseMoveEvent(e);
240 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() > 240 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() >
241 QApplication::startDragDistance()*3) { 241 QApplication::startDragDistance()*3) {
242 mMousePressed = false; 242 mMousePressed = false;
243 QListViewItem *item = itemAt(contentsToViewport(mPressPos)); 243 QListViewItem *item = itemAt(contentsToViewport(mPressPos));
244 if (item) { 244 if (item) {
245 DndFactory factory( mCalendar ); 245 DndFactory factory( mCalendar );
246 ICalDrag *vd = factory.createDrag( 246 ICalDrag *vd = factory.createDrag(
247 ((KOTodoViewItem *)item)->todo(),viewport()); 247 ((KOTodoViewItem *)item)->todo(),viewport());
248 internalDrop = false; 248 internalDrop = false;
249 // we cannot do any senseful here, because the DnD is still broken in Qt 249 // we cannot do any senseful here, because the DnD is still broken in Qt
250 if (vd->drag()) { 250 if (vd->drag()) {
251 if ( !internalDrop ) { 251 if ( !internalDrop ) {
252 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() ); 252 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() );
253 qDebug("Dnd: External move: Delete drag source "); 253 qDebug("Dnd: External move: Delete drag source ");
254 } else 254 } else
255 qDebug("Dnd: Internal move "); 255 qDebug("Dnd: Internal move ");
256 256
257 } else { 257 } else {
258 if ( !internalDrop ) { 258 if ( !internalDrop ) {
259 qDebug("Dnd: External Copy"); 259 qDebug("Dnd: External Copy");
260 } else 260 } else
261 qDebug("DnD: Internal copy: Copy pending"); 261 qDebug("DnD: Internal copy: Copy pending");
262 } 262 }
263 } 263 }
264 } 264 }
265#endif 265#endif
266} 266}
267void KOTodoListView::keyPressEvent ( QKeyEvent * e ) 267void KOTodoListView::keyPressEvent ( QKeyEvent * e )
268{ 268{
269 269
270 QListViewItem* cn; 270 QListViewItem* cn;
271 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) { 271 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) {
272 cn = currentItem(); 272 cn = currentItem();
273 if ( cn ) { 273 if ( cn ) {
274 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 274 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
275 if ( ci ){ 275 if ( ci ){
276 if ( e->state() == ShiftButton ) 276 if ( e->state() == ShiftButton )
277 ci->setOn( false ); 277 ci->setOn( false );
278 else 278 else
279 ci->setOn( true ); 279 ci->setOn( true );
280 cn = cn->itemBelow(); 280 cn = cn->itemBelow();
281 if ( cn ) { 281 if ( cn ) {
282 setCurrentItem ( cn ); 282 setCurrentItem ( cn );
283 ensureItemVisible ( cn ); 283 ensureItemVisible ( cn );
284 } 284 }
285 285
286 } 286 }
287 } 287 }
288 288
289 return; 289 return;
290 } 290 }
291 291
292 // qDebug("KOTodoListView::keyPressEvent "); 292 // qDebug("KOTodoListView::keyPressEvent ");
293 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) { 293 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) {
294 switch ( e->key() ) { 294 switch ( e->key() ) {
295 case Qt::Key_Down: 295 case Qt::Key_Down:
296 case Qt::Key_Up: 296 case Qt::Key_Up:
297 QListView::keyPressEvent ( e ); 297 QListView::keyPressEvent ( e );
298 break; 298 break;
299 case Qt::Key_Left: 299 case Qt::Key_Left:
300 case Qt::Key_Right: 300 case Qt::Key_Right:
301 QListView::keyPressEvent ( e ); 301 QListView::keyPressEvent ( e );
302 e->accept(); 302 e->accept();
303 return; 303 return;
304 break; 304 break;
305 default: 305 default:
306 e->ignore(); 306 e->ignore();
307 break; 307 break;
308 } 308 }
309 return; 309 return;
310 } 310 }
311 e->ignore(); 311 e->ignore();
312} 312}
313void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e) 313void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e)
314{ 314{
315 QListView::contentsMouseReleaseEvent(e); 315 QListView::contentsMouseReleaseEvent(e);
316 mMousePressed = false; 316 mMousePressed = false;
317} 317}
318 318
319void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e) 319void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
320{ 320{
321 if (!e) return; 321 if (!e) return;
322 322
323 QPoint vp = contentsToViewport(e->pos()); 323 QPoint vp = contentsToViewport(e->pos());
324 324
325 QListViewItem *item = itemAt(vp); 325 QListViewItem *item = itemAt(vp);
326 326
327 emit double_Clicked(item); 327 emit double_Clicked(item);
328 if (!item) return; 328 if (!item) return;
329 329
330 emit doubleClicked(item,vp,0); 330 emit doubleClicked(item,vp,0);
331} 331}
332 332
333///////////////////////////////////////////////////////////////////////////// 333/////////////////////////////////////////////////////////////////////////////
334 334
335KOQuickTodo::KOQuickTodo(QWidget *parent) : 335KOQuickTodo::KOQuickTodo(QWidget *parent) :
336 QLineEdit(parent) 336 QLineEdit(parent)
337{ 337{
338 setText(i18n("Click to add a new Todo")); 338 setText(i18n("Click to add a new Todo"));
339} 339}
340 340
341void KOQuickTodo::focusInEvent(QFocusEvent *ev) 341void KOQuickTodo::focusInEvent(QFocusEvent *ev)
342{ 342{
343 if ( text()==i18n("Click to add a new Todo") ) 343 if ( text()==i18n("Click to add a new Todo") )
344 setText(""); 344 setText("");
345 QLineEdit::focusInEvent(ev); 345 QLineEdit::focusInEvent(ev);
346} 346}
347 347
348void KOQuickTodo::focusOutEvent(QFocusEvent *ev) 348void KOQuickTodo::focusOutEvent(QFocusEvent *ev)
349{ 349{
350 setText(i18n("Click to add a new Todo")); 350 setText(i18n("Click to add a new Todo"));
351 QLineEdit::focusOutEvent(ev); 351 QLineEdit::focusOutEvent(ev);
352} 352}
353 353
354///////////////////////////////////////////////////////////////////////////// 354/////////////////////////////////////////////////////////////////////////////
355 355
356KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) : 356KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) :
357 KOrg::BaseView(calendar,parent,name) 357 KOrg::BaseView(calendar,parent,name)
358{ 358{
359 mPendingUpdateBeforeRepaint = false; 359 mPendingUpdateBeforeRepaint = false;
360 isFlatDisplay = false; 360 isFlatDisplay = false;
361 mNavigator = 0; 361 mNavigator = 0;
362 QBoxLayout *topLayout = new QVBoxLayout(this); 362 QBoxLayout *topLayout = new QVBoxLayout(this);
363 mName = QString ( name ); 363 mName = QString ( name );
364 mBlockUpdate = false; 364 mBlockUpdate = false;
365 mQuickAdd = new KOQuickTodo(this); 365 mQuickAdd = new KOQuickTodo(this);
366 topLayout->addWidget(mQuickAdd); 366 topLayout->addWidget(mQuickAdd);
367 367
368 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide(); 368 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide();
369 369
370 mTodoListView = new KOTodoListView(calendar,this, name ); 370 mTodoListView = new KOTodoListView(calendar,this, name );
371 topLayout->addWidget(mTodoListView); 371 topLayout->addWidget(mTodoListView);
372 //mTodoListView->header()->setMaximumHeight(30); 372 //mTodoListView->header()->setMaximumHeight(30);
373 mTodoListView->setRootIsDecorated(true); 373 mTodoListView->setRootIsDecorated(true);
374 mTodoListView->setAllColumnsShowFocus(true); 374 mTodoListView->setAllColumnsShowFocus(true);
375 375
376 mTodoListView->setShowSortIndicator(true); 376 mTodoListView->setShowSortIndicator(true);
377 377
378 mTodoListView->addColumn(i18n("Todo")); 378 mTodoListView->addColumn(i18n("Todo"));
379 mTodoListView->addColumn(i18n("Prio")); 379 mTodoListView->addColumn(i18n("Prio"));
380 mTodoListView->setColumnAlignment(1,AlignHCenter); 380 mTodoListView->setColumnAlignment(1,AlignHCenter);
381 mTodoListView->addColumn(i18n("Complete")); 381 mTodoListView->addColumn(i18n("Complete"));
382 mTodoListView->setColumnAlignment(2,AlignCenter); 382 mTodoListView->setColumnAlignment(2,AlignCenter);
383 383
384 mTodoListView->addColumn(i18n("Due Date")); 384 mTodoListView->addColumn(i18n("Due Date"));
385 mTodoListView->setColumnAlignment(3,AlignLeft); 385 mTodoListView->setColumnAlignment(3,AlignLeft);
386 mTodoListView->addColumn(i18n("Due Time")); 386 mTodoListView->addColumn(i18n("Due Time"));
387 mTodoListView->setColumnAlignment(4,AlignHCenter); 387 mTodoListView->setColumnAlignment(4,AlignHCenter);
388 388
389 mTodoListView->addColumn(i18n("Start Date")); 389 mTodoListView->addColumn(i18n("Start Date"));
390 mTodoListView->setColumnAlignment(5,AlignLeft); 390 mTodoListView->setColumnAlignment(5,AlignLeft);
391 mTodoListView->addColumn(i18n("Start Time")); 391 mTodoListView->addColumn(i18n("Start Time"));
392 mTodoListView->setColumnAlignment(6,AlignHCenter); 392 mTodoListView->setColumnAlignment(6,AlignHCenter);
393 393
394 mTodoListView->addColumn(i18n("Cancelled")); 394 mTodoListView->addColumn(i18n("Cancelled"));
395 mTodoListView->addColumn(i18n("Categories")); 395 mTodoListView->addColumn(i18n("Categories"));
396#if 0 396#if 0
397 mTodoListView->addColumn(i18n("Sort Id")); 397 mTodoListView->addColumn(i18n("Sort Id"));
398 mTodoListView->setColumnAlignment(4,AlignHCenter); 398 mTodoListView->setColumnAlignment(4,AlignHCenter);
399#endif 399#endif
400 400
401 mTodoListView->setMinimumHeight( 60 ); 401 mTodoListView->setMinimumHeight( 60 );
402 mTodoListView->setItemsRenameable( true ); 402 mTodoListView->setItemsRenameable( true );
403 mTodoListView->setRenameable( 0 ); 403 mTodoListView->setRenameable( 0 );
404 mTodoListView->setColumnWidth( 0, 120 ); 404 mTodoListView->setColumnWidth( 0, 120 );
405 mTodoListView->setColumnWidthMode(0, QListView::Manual); 405 mTodoListView->setColumnWidthMode(0, QListView::Manual);
406 mTodoListView->setColumnWidthMode(1, QListView::Manual); 406 mTodoListView->setColumnWidthMode(1, QListView::Manual);
407 mTodoListView->setColumnWidthMode(2, QListView::Manual); 407 mTodoListView->setColumnWidthMode(2, QListView::Manual);
408 mTodoListView->setColumnWidthMode(3, QListView::Manual); 408 mTodoListView->setColumnWidthMode(3, QListView::Manual);
409 mTodoListView->setColumnWidthMode(4, QListView::Manual); 409 mTodoListView->setColumnWidthMode(4, QListView::Manual);
410 mTodoListView->setColumnWidthMode(5, QListView::Manual); 410 mTodoListView->setColumnWidthMode(5, QListView::Manual);
411 mTodoListView->setColumnWidthMode(6, QListView::Manual); 411 mTodoListView->setColumnWidthMode(6, QListView::Manual);
412 mTodoListView->setColumnWidthMode(7, QListView::Manual); 412 mTodoListView->setColumnWidthMode(7, QListView::Manual);
413 mTodoListView->setColumnWidthMode(8, QListView::Manual); 413 mTodoListView->setColumnWidthMode(8, QListView::Manual);
414 414
415 415
416 new KOTodoViewWhatsThis(mTodoListView->viewport(),this); 416 new KOTodoViewWhatsThis(mTodoListView->viewport(),this);
417 417
418 mPriorityPopupMenu = new QPopupMenu(this); 418 mPriorityPopupMenu = new QPopupMenu(this);
419 for (int i = 1; i <= 5; i++) { 419 for (int i = 1; i <= 5; i++) {
420 QString label = QString ("%1").arg (i); 420 QString label = QString ("%1").arg (i);
421 mPriority[mPriorityPopupMenu->insertItem (label)] = i; 421 mPriority[mPriorityPopupMenu->insertItem (label)] = i;
422 } 422 }
423 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int))); 423 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int)));
424 424
425 mPercentageCompletedPopupMenu = new QPopupMenu(this); 425 mPercentageCompletedPopupMenu = new QPopupMenu(this);
426 for (int i = 0; i <= 100; i+=20) { 426 for (int i = 0; i <= 100; i+=20) {
427 QString label = QString ("%1 %").arg (i); 427 QString label = QString ("%1 %").arg (i);
428 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i; 428 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i;
429 } 429 }
430 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int))); 430 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int)));
431 431
432 432
433 433
434 mItemPopupMenu = new QPopupMenu(this); 434 mItemPopupMenu = new QPopupMenu(this);
435 mItemPopupMenu->insertItem(i18n("Show..."), this, 435 mItemPopupMenu->insertItem(i18n("Show..."), this,
436 SLOT (showTodo())); 436 SLOT (showTodo()));
437 mItemPopupMenu->insertItem(i18n("Edit..."), this, 437 mItemPopupMenu->insertItem(i18n("Edit..."), this,
438 SLOT (editTodo())); 438 SLOT (editTodo()));
439 mItemPopupMenu->insertItem( i18n("Delete"), this, 439 mItemPopupMenu->insertItem( i18n("Delete"), this,
440 SLOT (deleteTodo())); 440 SLOT (deleteTodo()));
441 mItemPopupMenu->insertItem( i18n("Clone..."), this, 441 mItemPopupMenu->insertItem( i18n("Clone..."), this,
442 SLOT (cloneTodo())); 442 SLOT (cloneTodo()));
443 mItemPopupMenu->insertItem( i18n("Move..."), this, 443 mItemPopupMenu->insertItem( i18n("Move..."), this,
444 SLOT (moveTodo())); 444 SLOT (moveTodo()));
445 mItemPopupMenu->insertItem( i18n("Beam..."), this, 445 mItemPopupMenu->insertItem( i18n("Beam..."), this,
446 SLOT (beamTodo())); 446 SLOT (beamTodo()));
447 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this, 447 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this,
448 SLOT (cancelTodo())); 448 SLOT (cancelTodo()));
449 mItemPopupMenu->insertSeparator(); 449 mItemPopupMenu->insertSeparator();
450 450
451 mItemPopupMenu->insertItem( i18n("New Todo..."), this, 451 mItemPopupMenu->insertItem( i18n("New Todo..."), this,
452 SLOT (newTodo())); 452 SLOT (newTodo()));
453 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this, 453 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this,
454 SLOT (newSubTodo())); 454 SLOT (newSubTodo()));
455 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this, 455 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this,
456 SLOT (unparentTodo()),0,21); 456 SLOT (unparentTodo()),0,21);
457 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this, 457 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this,
458 SLOT (reparentTodo()),0,22); 458 SLOT (reparentTodo()),0,22);
459 mItemPopupMenu->insertSeparator(); 459 mItemPopupMenu->insertSeparator();
460#if 0 460#if 0
461 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"), 461 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"),
462 this, SLOT( purgeCompleted() ) ); 462 this, SLOT( purgeCompleted() ) );
463 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"), 463 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"),
464 this, SLOT( toggleCompleted() ),0, 33 ); 464 this, SLOT( toggleCompleted() ),0, 33 );
465 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 465 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
466 this, SLOT( toggleQuickTodo() ),0, 34 ); 466 this, SLOT( toggleQuickTodo() ),0, 34 );
467 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 467 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
468 this, SLOT( toggleRunning() ),0, 35 ); 468 this, SLOT( toggleRunning() ),0, 35 );
469 469
470#endif 470#endif
471 mPopupMenu = new QPopupMenu(this); 471 mPopupMenu = new QPopupMenu(this);
472 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this, 472 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this,
473 SLOT (newTodo()),0,1); 473 SLOT (newTodo()),0,1);
474 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"), 474 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"),
475 this, SLOT(purgeCompleted()),0,2); 475 this, SLOT(purgeCompleted()),0,2);
476 mPopupMenu->insertItem(i18n("Show Completed"), 476 mPopupMenu->insertItem(i18n("Show Completed"),
477 this, SLOT( toggleCompleted() ),0,3 ); 477 this, SLOT( toggleCompleted() ),0,3 );
478 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 478 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
479 this, SLOT( toggleQuickTodo() ),0,4 ); 479 this, SLOT( toggleQuickTodo() ),0,4 );
480 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 480 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
481 this, SLOT( toggleRunning() ),0,5 ); 481 this, SLOT( toggleRunning() ),0,5 );
482 mPopupMenu->insertItem(i18n(" set all open","Display all opened"), 482 mPopupMenu->insertItem(i18n(" set all open","Display all opened"),
483 this, SLOT( setAllOpen() ),0,6 ); 483 this, SLOT( setAllOpen() ),0,6 );
484 mPopupMenu->insertItem(i18n(" set all close","Display all closed"), 484 mPopupMenu->insertItem(i18n(" set all close","Display all closed"),
485 this, SLOT( setAllClose() ),0,7 ); 485 this, SLOT( setAllClose() ),0,7 );
486 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"), 486 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"),
487 this, SLOT( setAllFlat() ),0,8 ); 487 this, SLOT( setAllFlat() ),0,8 );
488 mDocPrefs = new DocPrefs( name ); 488 mDocPrefs = new DocPrefs( name );
489 489
490 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu ); 490 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu );
491 mPopupMenu->setCheckable( true ); 491 mPopupMenu->setCheckable( true );
492 mItemPopupMenu->setCheckable( true ); 492 mItemPopupMenu->setCheckable( true );
493 493
494 494
495 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 495 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
496 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 496 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
497 497
498 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 498 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
499 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 499 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
500 500
501 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 501 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
502 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 502 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
503 503
504 504
505 // Double clicking conflicts with opening/closing the subtree 505 // Double clicking conflicts with opening/closing the subtree
506 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ), 506 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ),
507 SLOT( editItem( QListViewItem *) ) ); 507 SLOT( editItem( QListViewItem *) ) );
508 /* 508 /*
509 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *, 509 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *,
510 const QPoint &,int ) ), 510 const QPoint &,int ) ),
511 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 511 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
512 */ 512 */
513 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *, 513 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *,
514 const QPoint &,int ) ), 514 const QPoint &,int ) ),
515 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 515 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
516 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ), 516 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ),
517 SLOT( itemClicked( QListViewItem * ) ) ); 517 SLOT( itemClicked( QListViewItem * ) ) );
518 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ), 518 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ),
519 SLOT( itemDoubleClicked( QListViewItem * ) ) ); 519 SLOT( itemDoubleClicked( QListViewItem * ) ) );
520 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 520 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
521 SLOT( updateView() ) ); 521 SLOT( updateView() ) );
522 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 522 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
523 SLOT( todoModified(Todo *, int) ) ); 523 SLOT( todoModified(Todo *, int) ) );
524 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ), 524 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ),
525 SLOT( itemStateChanged( QListViewItem * ) ) ); 525 SLOT( itemStateChanged( QListViewItem * ) ) );
526 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ), 526 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ),
527 SLOT( itemStateChanged( QListViewItem * ) ) ); 527 SLOT( itemStateChanged( QListViewItem * ) ) );
528 connect( mTodoListView, SIGNAL( paintNeeded() ), 528 connect( mTodoListView, SIGNAL( paintNeeded() ),
529 SLOT( paintNeeded()) ); 529 SLOT( paintNeeded()) );
530 530
531#if 0 531#if 0
532 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)), 532 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)),
533 SLOT(selectionChanged(QListViewItem *))); 533 SLOT(selectionChanged(QListViewItem *)));
534 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)), 534 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)),
535 SLOT(selectionChanged(QListViewItem *))); 535 SLOT(selectionChanged(QListViewItem *)));
536 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)), 536 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)),
537 SLOT(selectionChanged(QListViewItem *))); 537 SLOT(selectionChanged(QListViewItem *)));
538#endif 538#endif
539 539
540 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) )); 540 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) ));
541 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) )); 541 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) ));
542 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) )); 542 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) ));
543 543
544 connect( mTodoListView, SIGNAL(selectionChanged() ), 544 connect( mTodoListView, SIGNAL(selectionChanged() ),
545 SLOT( processSelectionChange() ) ); 545 SLOT( processSelectionChange() ) );
546 connect( mQuickAdd, SIGNAL( returnPressed () ), 546 connect( mQuickAdd, SIGNAL( returnPressed () ),
547 SLOT( addQuickTodo() ) ); 547 SLOT( addQuickTodo() ) );
548 548
549} 549}
550 550
551KOTodoView::~KOTodoView() 551KOTodoView::~KOTodoView()
552{ 552{
553 delete mDocPrefs; 553 delete mDocPrefs;
554} 554}
555QString KOTodoView::getWhatsThisText(QPoint p) 555QString KOTodoView::getWhatsThisText(QPoint p)
556{ 556{
557 KOTodoViewItem* item = ( KOTodoViewItem* ) mTodoListView->itemAt( p ); 557 KOTodoViewItem* item = ( KOTodoViewItem* ) mTodoListView->itemAt( p );
558 if ( item ) 558 if ( item )
559 return KIncidenceFormatter::instance()->getFormattedText( item->todo() ); 559 return KIncidenceFormatter::instance()->getFormattedText( item->todo() );
560 return i18n("That is the todo view" ); 560 return i18n("That is the todo view" );
561 561
562} 562}
563 563
564void KOTodoView::jumpToDate () 564void KOTodoView::jumpToDate ()
565{ 565{
566 // if (mActiveItem) { 566 // if (mActiveItem) {
567// mActiveItem->todo()); 567// mActiveItem->todo());
568// if ( mActiveItem->todo()->hasDueDate() ) 568// if ( mActiveItem->todo()->hasDueDate() )
569// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() ); 569// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() );
570} 570}
571void KOTodoView::paintNeeded() 571void KOTodoView::paintNeeded()
572{ 572{
573 if ( mPendingUpdateBeforeRepaint ) { 573 if ( mPendingUpdateBeforeRepaint ) {
574 updateView(); 574 updateView();
575 mPendingUpdateBeforeRepaint = false; 575 mPendingUpdateBeforeRepaint = false;
576 } 576 }
577} 577}
578void KOTodoView::paintEvent(QPaintEvent * pevent) 578void KOTodoView::paintEvent(QPaintEvent * pevent)
579{ 579{
580 if ( mPendingUpdateBeforeRepaint ) { 580 if ( mPendingUpdateBeforeRepaint ) {
581 updateView(); 581 updateView();
582 mPendingUpdateBeforeRepaint = false; 582 mPendingUpdateBeforeRepaint = false;
583 } 583 }
584 KOrg::BaseView::paintEvent( pevent); 584 KOrg::BaseView::paintEvent( pevent);
585} 585}
586 586
587void KOTodoView::updateView() 587void KOTodoView::updateView()
588{ 588{
589 pendingSubtodo = 0; 589 pendingSubtodo = 0;
590 if ( mBlockUpdate ) { 590 if ( mBlockUpdate ) {
591 return; 591 return;
592 } 592 }
593 if ( !isVisible() ) { 593 if ( !isVisible() ) {
594 mPendingUpdateBeforeRepaint = true; 594 mPendingUpdateBeforeRepaint = true;
595 return; 595 return;
596 } 596 }
597 //qDebug("KOTodoView::updateView() %x", this); 597 //qDebug("KOTodoView::updateView() %x", this);
598 if ( isFlatDisplay ) { 598 if ( isFlatDisplay ) {
599 setAllFlat(); 599 setAllFlat();
600 return; 600 return;
601 } 601 }
602 //qDebug("update "); 602 //qDebug("update ");
603// kdDebug() << "KOTodoView::updateView()" << endl; 603// kdDebug() << "KOTodoView::updateView()" << endl;
604 QFont fo = KOPrefs::instance()->mTodoViewFont; 604 QFont fo = KOPrefs::instance()->mTodoViewFont;
605 mTodoListView->clear(); 605 mTodoListView->clear();
606 if ( mName == "todolistsmall" ) { 606 if ( mName == "todolistsmall" ) {
607 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) { 607 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) {
608 int ps = fo.pointSize() -2; 608 int ps = fo.pointSize() -2;
609 if ( ps > 12 ) 609 if ( ps > 12 )
610 ps -= 2; 610 ps -= 2;
611 fo.setPointSize( ps ); 611 fo.setPointSize( ps );
612 } 612 }
613 } 613 }
614 614
615 mTodoListView->setFont( fo ); 615 mTodoListView->setFont( fo );
616 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont ); 616 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont );
617 //mTodoListView->header()->setMaximumHeight(fm.height()); 617 //mTodoListView->header()->setMaximumHeight(fm.height());
618 QPtrList<Todo> todoList = calendar()->todos(); 618 QPtrList<Todo> todoList = calendar()->todos();
619 619
620/* 620/*
621 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl; 621 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl;
622 Event *t; 622 Event *t;
623 for(t = todoList.first(); t; t = todoList.next()) { 623 for(t = todoList.first(); t; t = todoList.next()) {
624 kdDebug() << " " << t->getSummary() << endl; 624 kdDebug() << " " << t->getSummary() << endl;
625 625
626 if (t->getRelatedTo()) { 626 if (t->getRelatedTo()) {
627 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl; 627 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl;
628 } 628 }
629 629
630 QPtrList<Event> l = t->getRelations(); 630 QPtrList<Event> l = t->getRelations();
631 Event *c; 631 Event *c;
632 for(c=l.first();c;c=l.next()) { 632 for(c=l.first();c;c=l.next()) {
633 kdDebug() << " - relation: " << c->getSummary() << endl; 633 kdDebug() << " - relation: " << c->getSummary() << endl;
634 } 634 }
635 } 635 }
636*/ 636*/
637 637
638 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a 638 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a
639 // specific order of events. That means that we have to generate parent items 639 // specific order of events. That means that we have to generate parent items
640 // recursively for proper hierarchical display of Todos. 640 // recursively for proper hierarchical display of Todos.
641 mTodoMap.clear(); 641 mTodoMap.clear();
642 Todo *todo; 642 Todo *todo;
643 todo = todoList.first();// todo; todo = todoList.next()) { 643 todo = todoList.first();// todo; todo = todoList.next()) {
644 while ( todo ) { 644 while ( todo ) {
645 bool next = true; 645 bool next = true;
646 // qDebug("todo %s ", todo->summary().latin1()); 646 // qDebug("todo %s ", todo->summary().latin1());
647 Incidence *incidence = todo->relatedTo(); 647 Incidence *incidence = todo->relatedTo();
648 while ( incidence ) { 648 while ( incidence ) {
649 if ( incidence->type() == "Todo") { 649 if ( incidence->type() == "Todo") {
650 //qDebug("related %s ",incidence->summary().latin1() ); 650 //qDebug("related %s ",incidence->summary().latin1() );
651 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) { 651 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) {
652 //qDebug("related not found "); 652 //qDebug("related not found ");
653 todoList.remove( ); 653 todoList.remove( );
654 todo = todoList.current(); 654 todo = todoList.current();
655 next = false; 655 next = false;
656 incidence = 0; 656 incidence = 0;
657 657
658 } else { 658 } else {
659 //qDebug("related found "); 659 //qDebug("related found ");
660 incidence = incidence->relatedTo(); 660 incidence = incidence->relatedTo();
661 } 661 }
662 } else 662 } else
663 incidence = 0; 663 incidence = 0;
664 } 664 }
665 if ( next ) 665 if ( next )
666 todo = todoList.next(); 666 todo = todoList.next();
667 } 667 }
668// qDebug("again .... "); 668// qDebug("again .... ");
669// for(todo = todoList.first(); todo; todo = todoList.next()) { 669// for(todo = todoList.first(); todo; todo = todoList.next()) {
670 670
671// qDebug("yytodo %s ", todo->summary().latin1()); 671// qDebug("yytodo %s ", todo->summary().latin1());
672// } 672// }
673 //qDebug("for "); 673 //qDebug("for ");
674 for(todo = todoList.first(); todo; todo = todoList.next()) { 674 for(todo = todoList.first(); todo; todo = todoList.next()) {
675 if (!mTodoMap.contains(todo) && checkTodo( todo ) ) 675 if (!mTodoMap.contains(todo) && checkTodo( todo ) )
676 { 676 {
677 insertTodoItem(todo); 677 insertTodoItem(todo);
678 } 678 }
679 } 679 }
680 //qDebug("for end "); 680 //qDebug("for end ");
681 // Restore opened/closed state 681 // Restore opened/closed state
682 mTodoListView->blockSignals( true ); 682 mTodoListView->blockSignals( true );
683 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() ); 683 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() );
684 mTodoListView->blockSignals( false ); 684 mTodoListView->blockSignals( false );
685 mTodoListView->setFocus(); 685 mTodoListView->setFocus();
686 processSelectionChange(); 686 processSelectionChange();
687} 687}
688 688
689bool KOTodoView::checkTodo( Todo * todo ) 689bool KOTodoView::checkTodo( Todo * todo )
690{ 690{
691 691
692 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() ) 692 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() )
693 return false; 693 return false;
694 if ( !todo->isCompleted() ) {
695 if ( todo->hasDueDate() && todo->dtDue().date() <= QDate::currentDate() )
696 return true;
697 }
694 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) { 698 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) {
695 if ( todo->hasStartDate() ) 699 if ( todo->hasStartDate() )
696 if ( mNavigator->selectedDates().last() < todo->dtStart().date() ) 700 if ( mNavigator->selectedDates().last() < todo->dtStart().date() )
697 return false; 701 return false;
698 if ( todo->hasDueDate() ) 702 if ( todo->hasDueDate() )
699 if ( mNavigator->selectedDates().first() > todo->dtDue().date() ) 703 if ( mNavigator->selectedDates().first() > todo->dtDue().date() )
700 return false; 704 return false;
701 } 705 }
702 return true; 706 return true;
703} 707}
704 708
705void KOTodoView::restoreItemState( QListViewItem *item ) 709void KOTodoView::restoreItemState( QListViewItem *item )
706{ 710{
707 pendingSubtodo = 0; 711 pendingSubtodo = 0;
708 while( item ) { 712 while( item ) {
709 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 713 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
710 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) ); 714 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) );
711 if( item->childCount() > 0 ) restoreItemState( item->firstChild() ); 715 if( item->childCount() > 0 ) restoreItemState( item->firstChild() );
712 item = item->nextSibling(); 716 item = item->nextSibling();
713 } 717 }
714} 718}
715 719
716 720
717QMap<Todo *,KOTodoViewItem *>::ConstIterator 721QMap<Todo *,KOTodoViewItem *>::ConstIterator
718 KOTodoView::insertTodoItem(Todo *todo) 722 KOTodoView::insertTodoItem(Todo *todo)
719{ 723{
720 724
721// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl; 725// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl;
722 // TODO: Check, if dynmaic cast is necessary 726 // TODO: Check, if dynmaic cast is necessary
723 727
724 pendingSubtodo = 0; 728 pendingSubtodo = 0;
725 Incidence *incidence = todo->relatedTo(); 729 Incidence *incidence = todo->relatedTo();
726 if (incidence && incidence->type() == "Todo") { 730 if (incidence && incidence->type() == "Todo") {
727 Todo *relatedTodo = static_cast<Todo *>(incidence); 731 Todo *relatedTodo = static_cast<Todo *>(incidence);
728 732
729// kdDebug() << " has Related" << endl; 733// kdDebug() << " has Related" << endl;
730 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 734 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
731 itemIterator = mTodoMap.find(relatedTodo); 735 itemIterator = mTodoMap.find(relatedTodo);
732 if (itemIterator == mTodoMap.end()) { 736 if (itemIterator == mTodoMap.end()) {
733// kdDebug() << " related not yet in list" << endl; 737// kdDebug() << " related not yet in list" << endl;
734 itemIterator = insertTodoItem (relatedTodo); 738 itemIterator = insertTodoItem (relatedTodo);
735 } 739 }
736 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem 740 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem
737 // and one into the map. Sure finding is more easy but why? -zecke 741 // and one into the map. Sure finding is more easy but why? -zecke
738 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this); 742 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this);
739 return mTodoMap.insert(todo,todoItem); 743 return mTodoMap.insert(todo,todoItem);
740 } else { 744 } else {
741// kdDebug() << " no Related" << endl; 745// kdDebug() << " no Related" << endl;
742 // see above -zecke 746 // see above -zecke
743 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 747 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
744 return mTodoMap.insert(todo,todoItem); 748 return mTodoMap.insert(todo,todoItem);
745 } 749 }
746} 750}
747 751
748 752
749void KOTodoView::updateConfig() 753void KOTodoView::updateConfig()
750{ 754{
751 updateView(); 755 updateView();
752 mTodoListView->repaintContents(); 756 mTodoListView->repaintContents();
753} 757}
754 758
755QPtrList<Incidence> KOTodoView::selectedIncidences() 759QPtrList<Incidence> KOTodoView::selectedIncidences()
756{ 760{
757 QPtrList<Incidence> selected; 761 QPtrList<Incidence> selected;
758 762
759 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 763 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
760// if (!item) item = mActiveItem; 764// if (!item) item = mActiveItem;
761 if (item) selected.append(item->todo()); 765 if (item) selected.append(item->todo());
762 766
763 return selected; 767 return selected;
764} 768}
765 769
766QPtrList<Todo> KOTodoView::selectedTodos() 770QPtrList<Todo> KOTodoView::selectedTodos()
767{ 771{
768 QPtrList<Todo> selected; 772 QPtrList<Todo> selected;
769 773
770 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 774 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
771// if (!item) item = mActiveItem; 775// if (!item) item = mActiveItem;
772 if (item) selected.append(item->todo()); 776 if (item) selected.append(item->todo());
773 777
774 return selected; 778 return selected;
775} 779}
776 780
777void KOTodoView::changeEventDisplay(Event *, int) 781void KOTodoView::changeEventDisplay(Event *, int)
778{ 782{
779 updateView(); 783 updateView();
780} 784}
781 785
782void KOTodoView::showDates(const QDate &, const QDate &) 786void KOTodoView::showDates(const QDate &, const QDate &)
783{ 787{
784} 788}
785 789
786void KOTodoView::showEvents(QPtrList<Event>) 790void KOTodoView::showEvents(QPtrList<Event>)
787{ 791{
788 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl; 792 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl;
789} 793}
790 794
791void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd, 795void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd,
792 const QDate &td) 796 const QDate &td)
793{ 797{
794#ifndef KORG_NOPRINTER 798#ifndef KORG_NOPRINTER
795 calPrinter->preview(CalPrinter::Todolist, fd, td); 799 calPrinter->preview(CalPrinter::Todolist, fd, td);
796#endif 800#endif
797} 801}
798 802
799void KOTodoView::editItem(QListViewItem *item ) 803void KOTodoView::editItem(QListViewItem *item )
800{ 804{
801 // qDebug("editItem(QListViewItem *item ) "); 805 // qDebug("editItem(QListViewItem *item ) ");
802 emit editTodoSignal(((KOTodoViewItem *)item)->todo()); 806 emit editTodoSignal(((KOTodoViewItem *)item)->todo());
803} 807}
804 808
805void KOTodoView::showItem(QListViewItem *item,const QPoint &,int) 809void KOTodoView::showItem(QListViewItem *item,const QPoint &,int)
806{ 810{
807 emit showTodoSignal(((KOTodoViewItem *)item)->todo()); 811 emit showTodoSignal(((KOTodoViewItem *)item)->todo());
808} 812}
809 813
810void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column) 814void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column)
811{ 815{
812 pendingSubtodo = 0; 816 pendingSubtodo = 0;
813 mActiveItem = (KOTodoViewItem *)item; 817 mActiveItem = (KOTodoViewItem *)item;
814 if (item) { 818 if (item) {
815 switch (column){ 819 switch (column){
816 case 1: 820 case 1:
817 mPriorityPopupMenu->popup(QCursor::pos ()); break; 821 mPriorityPopupMenu->popup(QCursor::pos ()); break;
818 case 2: 822 case 2:
819 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break; 823 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break;
820 case 3: 824 case 3:
821 moveTodo(); 825 moveTodo();
822 break; 826 break;
823 case 8: 827 case 8:
824 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break; 828 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break;
825 default: 829 default:
826 mItemPopupMenu->popup(QCursor::pos()); 830 mItemPopupMenu->popup(QCursor::pos());
827 } 831 }
828 } else mPopupMenu->popup(QCursor::pos()); 832 } else mPopupMenu->popup(QCursor::pos());
829} 833}
830void KOTodoView::newTodo() 834void KOTodoView::newTodo()
831{ 835{
832 emit newTodoSignal(); 836 emit newTodoSignal();
833} 837}
834 838
835void KOTodoView::newSubTodo() 839void KOTodoView::newSubTodo()
836{ 840{
837 if (mActiveItem) { 841 if (mActiveItem) {
838 emit newSubTodoSignal(mActiveItem->todo()); 842 emit newSubTodoSignal(mActiveItem->todo());
839 } 843 }
840} 844}
841void KOTodoView::unparentTodo() 845void KOTodoView::unparentTodo()
842{ 846{
843 if (mActiveItem) { 847 if (mActiveItem) {
844 emit unparentTodoSignal(mActiveItem->todo()); 848 emit unparentTodoSignal(mActiveItem->todo());
845 } 849 }
846} 850}
847 851
848void KOTodoView::reparentTodo() 852void KOTodoView::reparentTodo()
849{ 853{
850 if (mActiveItem) { 854 if (mActiveItem) {
851 qDebug("KOTodoView::reparentTodo() "); 855 qDebug("KOTodoView::reparentTodo() ");
852 topLevelWidget()->setCaption(i18n("Click on new parent item")); 856 topLevelWidget()->setCaption(i18n("Click on new parent item"));
853 pendingSubtodo = mActiveItem; 857 pendingSubtodo = mActiveItem;
854 } 858 }
855} 859}
856void KOTodoView::editTodo() 860void KOTodoView::editTodo()
857{ 861{
858 if (mActiveItem) { 862 if (mActiveItem) {
859 emit editTodoSignal(mActiveItem->todo()); 863 emit editTodoSignal(mActiveItem->todo());
860 } 864 }
861} 865}
862void KOTodoView::cloneTodo() 866void KOTodoView::cloneTodo()
863{ 867{
864 if (mActiveItem) { 868 if (mActiveItem) {
865 emit cloneTodoSignal((Incidence*)mActiveItem->todo()); 869 emit cloneTodoSignal((Incidence*)mActiveItem->todo());
866 } 870 }
867} 871}
868void KOTodoView::cancelTodo() 872void KOTodoView::cancelTodo()
869{ 873{
870 if (mActiveItem) { 874 if (mActiveItem) {
871 emit cancelTodoSignal((Incidence*)mActiveItem->todo()); 875 emit cancelTodoSignal((Incidence*)mActiveItem->todo());
872 } 876 }
873} 877}
874void KOTodoView::moveTodo() 878void KOTodoView::moveTodo()
875{ 879{
876 if (mActiveItem) { 880 if (mActiveItem) {
877 emit moveTodoSignal((Incidence*)mActiveItem->todo()); 881 emit moveTodoSignal((Incidence*)mActiveItem->todo());
878 } 882 }
879} 883}
880void KOTodoView::beamTodo() 884void KOTodoView::beamTodo()
881{ 885{
882 if (mActiveItem) { 886 if (mActiveItem) {
883 emit beamTodoSignal((Incidence*)mActiveItem->todo()); 887 emit beamTodoSignal((Incidence*)mActiveItem->todo());
884 } 888 }
885} 889}
886 890
887 891
888void KOTodoView::showTodo() 892void KOTodoView::showTodo()
889{ 893{
890 if (mActiveItem) { 894 if (mActiveItem) {
891 emit showTodoSignal(mActiveItem->todo()); 895 emit showTodoSignal(mActiveItem->todo());
892 } 896 }
893} 897}
894 898
895void KOTodoView::deleteTodo() 899void KOTodoView::deleteTodo()
896{ 900{
897 if (mActiveItem) { 901 if (mActiveItem) {
898 emit deleteTodoSignal(mActiveItem->todo()); 902 emit deleteTodoSignal(mActiveItem->todo());
899 } 903 }
900} 904}
901 905
902void KOTodoView::setNewPriority(int index) 906void KOTodoView::setNewPriority(int index)
903{ 907{
904 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 908 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
905 mActiveItem->todo()->setPriority(mPriority[index]); 909 mActiveItem->todo()->setPriority(mPriority[index]);
906 mActiveItem->construct(); 910 mActiveItem->construct();
907 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED); 911 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED);
908 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 912 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
909 } 913 }
910} 914}
911 915
912void KOTodoView::setNewPercentage(int index) 916void KOTodoView::setNewPercentage(int index)
913{ 917{
914 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 918 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
915 919
916 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) { 920 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) {
917 mActiveItem->setOn( true ); 921 mActiveItem->setOn( true );
918 return; 922 return;
919 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) { 923 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) {
920 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent())); 924 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent()));
921 if ( par && par->isOn() ) 925 if ( par && par->isOn() )
922 par->setOn( false ); 926 par->setOn( false );
923 } 927 }
924 if (mPercentage[index] == 100) { 928 if (mPercentage[index] == 100) {
925 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime()); 929 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime());
926 } else { 930 } else {
927 mActiveItem->todo()->setCompleted(false); 931 mActiveItem->todo()->setCompleted(false);
928 } 932 }
929 mActiveItem->todo()->setPercentComplete(mPercentage[index]); 933 mActiveItem->todo()->setPercentComplete(mPercentage[index]);
930 mActiveItem->construct(); 934 mActiveItem->construct();
931 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED); 935 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED);
932 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 936 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
933 } 937 }
934} 938}
935 939
936 940
937QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem) 941QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem)
938{ 942{
939 QPopupMenu* tempMenu = new QPopupMenu (this); 943 QPopupMenu* tempMenu = new QPopupMenu (this);
940 QStringList checkedCategories = todoItem->todo()->categories (); 944 QStringList checkedCategories = todoItem->todo()->categories ();
941 945
942 tempMenu->setCheckable (true); 946 tempMenu->setCheckable (true);
943 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); 947 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin ();
944 it != KOPrefs::instance()->mCustomCategories.end (); 948 it != KOPrefs::instance()->mCustomCategories.end ();
945 ++it) { 949 ++it) {
946 int index = tempMenu->insertItem (*it); 950 int index = tempMenu->insertItem (*it);
947 mCategory[index] = *it; 951 mCategory[index] = *it;
948 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true); 952 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true);
949 } 953 }
950 954
951 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int))); 955 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int)));
952 return tempMenu; 956 return tempMenu;
953 957
954 958
955} 959}
956void KOTodoView::changedCategories(int index) 960void KOTodoView::changedCategories(int index)
957{ 961{
958 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 962 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
959 QStringList categories = mActiveItem->todo()->categories (); 963 QStringList categories = mActiveItem->todo()->categories ();
960 if (categories.find (mCategory[index]) != categories.end ()) 964 if (categories.find (mCategory[index]) != categories.end ())
961 categories.remove (mCategory[index]); 965 categories.remove (mCategory[index]);
962 else 966 else
963 categories.insert (categories.end(), mCategory[index]); 967 categories.insert (categories.end(), mCategory[index]);
964 categories.sort (); 968 categories.sort ();
965 mActiveItem->todo()->setCategories (categories); 969 mActiveItem->todo()->setCategories (categories);
966 mActiveItem->construct(); 970 mActiveItem->construct();
967 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 971 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
968 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED); 972 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED);
969 } 973 }
970} 974}
971void KOTodoView::itemDoubleClicked(QListViewItem *item) 975void KOTodoView::itemDoubleClicked(QListViewItem *item)
972{ 976{
973 if ( pendingSubtodo != 0 ) { 977 if ( pendingSubtodo != 0 ) {
974 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 978 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
975 } 979 }
976 pendingSubtodo = 0; 980 pendingSubtodo = 0;
977 if (!item) { 981 if (!item) {
978 newTodo(); 982 newTodo();
979 return; 983 return;
980 } 984 }
981 if ( KOPrefs::instance()->mEditOnDoubleClick ) 985 if ( KOPrefs::instance()->mEditOnDoubleClick )
982 editItem( item ); 986 editItem( item );
983 else 987 else
984 showItem( item , QPoint(), 0 ); 988 showItem( item , QPoint(), 0 );
985} 989}
986void KOTodoView::itemClicked(QListViewItem *item) 990void KOTodoView::itemClicked(QListViewItem *item)
987{ 991{
988 992
989 if (!item) { 993 if (!item) {
990 if ( pendingSubtodo != 0 ) { 994 if ( pendingSubtodo != 0 ) {
991 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 995 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
992 } 996 }
993 pendingSubtodo = 0; 997 pendingSubtodo = 0;
994 return; 998 return;
995 } 999 }
996 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1000 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
997 if ( pendingSubtodo != 0 ) { 1001 if ( pendingSubtodo != 0 ) {
998 bool allowReparent = true; 1002 bool allowReparent = true;
999 QListViewItem *par = item; 1003 QListViewItem *par = item;
1000 while ( par ) { 1004 while ( par ) {
1001 if ( par == pendingSubtodo ) { 1005 if ( par == pendingSubtodo ) {
1002 allowReparent = false; 1006 allowReparent = false;
1003 break; 1007 break;
1004 } 1008 }
1005 par = par->parent(); 1009 par = par->parent();
1006 } 1010 }
1007 if ( !allowReparent ) { 1011 if ( !allowReparent ) {
1008 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!")); 1012 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!"));
1009 qDebug("Recursive reparenting not possible "); 1013 qDebug("Recursive reparenting not possible ");
1010 pendingSubtodo = 0; 1014 pendingSubtodo = 0;
1011 } else { 1015 } else {
1012 Todo* newParent = todoItem->todo(); 1016 Todo* newParent = todoItem->todo();
1013 Todo* newSub = pendingSubtodo->todo(); 1017 Todo* newSub = pendingSubtodo->todo();
1014 pendingSubtodo = 0; 1018 pendingSubtodo = 0;
1015 emit reparentTodoSignal( newParent,newSub ); 1019 emit reparentTodoSignal( newParent,newSub );
1016 return; 1020 return;
1017 } 1021 }
1018 } 1022 }
1019#if 0 1023#if 0
1020 // handled by the item itself 1024 // handled by the item itself
1021 bool completed = todoItem->todo()->isCompleted(); // Completed or not? 1025 bool completed = todoItem->todo()->isCompleted(); // Completed or not?
1022 qDebug("com %d ",completed ); 1026 qDebug("com %d ",completed );
1023 qDebug("itemclicked "); 1027 qDebug("itemclicked ");
1024 if (todoItem->isOn()) { 1028 if (todoItem->isOn()) {
1025 qDebug("on "); 1029 qDebug("on ");
1026 if (!completed) { 1030 if (!completed) {
1027 qDebug("set true "); 1031 qDebug("set true ");
1028 todoItem->todo()->setCompleted(QDateTime::currentDateTime()); 1032 todoItem->todo()->setCompleted(QDateTime::currentDateTime());
1029 } 1033 }
1030 } else { 1034 } else {
1031 qDebug("not on "); 1035 qDebug("not on ");
1032 if (completed) { 1036 if (completed) {
1033 qDebug("set false "); 1037 qDebug("set false ");
1034 todoItem->todo()->setCompleted(false); 1038 todoItem->todo()->setCompleted(false);
1035 } 1039 }
1036 } 1040 }
1037#endif 1041#endif
1038} 1042}
1039 1043
1040void KOTodoView::setDocumentId( const QString &id ) 1044void KOTodoView::setDocumentId( const QString &id )
1041{ 1045{
1042 kdDebug() << "KOTodoView::setDocumentId()" << endl; 1046 kdDebug() << "KOTodoView::setDocumentId()" << endl;
1043 1047
1044 mDocPrefs->setDoc( id ); 1048 mDocPrefs->setDoc( id );
1045} 1049}
1046 1050
1047void KOTodoView::itemStateChanged( QListViewItem *item ) 1051void KOTodoView::itemStateChanged( QListViewItem *item )
1048{ 1052{
1049 if (!item) return; 1053 if (!item) return;
1050 1054
1051 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1055 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
1052 1056
1053// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl; 1057// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl;
1054 1058
1055 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() ); 1059 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() );
1056} 1060}
1057 1061
1058void KOTodoView::saveLayout(KConfig *config, const QString &group) const 1062void KOTodoView::saveLayout(KConfig *config, const QString &group) const
1059{ 1063{
1060 mTodoListView->saveLayout(config,group); 1064 mTodoListView->saveLayout(config,group);
1061} 1065}
1062 1066
1063void KOTodoView::restoreLayout(KConfig *config, const QString &group) 1067void KOTodoView::restoreLayout(KConfig *config, const QString &group)
1064{ 1068{
1065 mTodoListView->restoreLayout(config,group); 1069 mTodoListView->restoreLayout(config,group);
1066} 1070}
1067 1071
1068void KOTodoView::processSelectionChange() 1072void KOTodoView::processSelectionChange()
1069{ 1073{
1070// kdDebug() << "KOTodoView::processSelectionChange()" << endl; 1074// kdDebug() << "KOTodoView::processSelectionChange()" << endl;
1071 1075
1072 KOTodoViewItem *item = 1076 KOTodoViewItem *item =
1073 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() ); 1077 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() );
1074 1078
1075 if ( !item ) { 1079 if ( !item ) {
1076 emit incidenceSelected( 0 ); 1080 emit incidenceSelected( 0 );
1077 } else { 1081 } else {
1078 emit incidenceSelected( item->todo() ); 1082 emit incidenceSelected( item->todo() );
1079 } 1083 }
1080} 1084}
1081 1085
1082void KOTodoView::modified(bool b) 1086void KOTodoView::modified(bool b)
1083{ 1087{
1084 emit isModified(b); 1088 emit isModified(b);
1085} 1089}
1086void KOTodoView::setTodoModified( Todo* todo ) 1090void KOTodoView::setTodoModified( Todo* todo )
1087{ 1091{
1088 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED ); 1092 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED );
1089} 1093}
1090void KOTodoView::clearSelection() 1094void KOTodoView::clearSelection()
1091{ 1095{
1092 mTodoListView->selectAll( false ); 1096 mTodoListView->selectAll( false );
1093} 1097}
1094void KOTodoView::setAllOpen() 1098void KOTodoView::setAllOpen()
1095{ 1099{
1096 if ( isFlatDisplay ) { 1100 if ( isFlatDisplay ) {
1097 isFlatDisplay = false; 1101 isFlatDisplay = false;
1098 mPopupMenu->setItemChecked( 8,false ); 1102 mPopupMenu->setItemChecked( 8,false );
1099 updateView(); 1103 updateView();
1100 } 1104 }
1101 setOpen(mTodoListView->firstChild(), true); 1105 setOpen(mTodoListView->firstChild(), true);
1102} 1106}
1103void KOTodoView::setAllClose() 1107void KOTodoView::setAllClose()
1104{ 1108{
1105 if ( isFlatDisplay ) { 1109 if ( isFlatDisplay ) {
1106 isFlatDisplay = false; 1110 isFlatDisplay = false;
1107 mPopupMenu->setItemChecked( 8,false ); 1111 mPopupMenu->setItemChecked( 8,false );
1108 updateView(); 1112 updateView();
1109 } 1113 }
1110 setOpen(mTodoListView->firstChild(), false); 1114 setOpen(mTodoListView->firstChild(), false);
1111} 1115}
1112void KOTodoView::setOpen( QListViewItem* item, bool setOpenI) 1116void KOTodoView::setOpen( QListViewItem* item, bool setOpenI)
1113{ 1117{
1114 1118
1115 while ( item ) { 1119 while ( item ) {
1116 setOpen( item->firstChild(), setOpenI ); 1120 setOpen( item->firstChild(), setOpenI );
1117 item->setOpen( setOpenI ); 1121 item->setOpen( setOpenI );
1118 item = item->nextSibling(); 1122 item = item->nextSibling();
1119 } 1123 }
1120} 1124}
1121 1125
1122void KOTodoView::setAllFlat() 1126void KOTodoView::setAllFlat()
1123{ 1127{
1124 if ( isFlatDisplay ) { 1128 if ( isFlatDisplay ) {
1125 isFlatDisplay = false; 1129 isFlatDisplay = false;
1126 mPopupMenu->setItemChecked( 8,false ); 1130 mPopupMenu->setItemChecked( 8,false );
1127 updateView(); 1131 updateView();
1128 return; 1132 return;
1129 } 1133 }
1130 pendingSubtodo = 0; 1134 pendingSubtodo = 0;
1131 if ( mBlockUpdate ) { 1135 if ( mBlockUpdate ) {
1132 return; 1136 return;
1133 } 1137 }
1134 mPopupMenu->setItemChecked( 8,true ); 1138 mPopupMenu->setItemChecked( 8,true );
1135 isFlatDisplay = true; 1139 isFlatDisplay = true;
1136 QPtrList<Todo> todoList = calendar()->todos(); 1140 QPtrList<Todo> todoList = calendar()->todos();
1137 mTodoMap.clear(); 1141 mTodoMap.clear();
1138 mTodoListView->clear(); 1142 mTodoListView->clear();
1139 Todo *todo; 1143 Todo *todo;
1140 for(todo = todoList.first(); todo; todo = todoList.next()) { 1144 for(todo = todoList.first(); todo; todo = todoList.next()) {
1141 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 1145 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
1142 mTodoMap.insert(todo,todoItem); 1146 mTodoMap.insert(todo,todoItem);
1143 } 1147 }
1144 mTodoListView->setFocus(); 1148 mTodoListView->setFocus();
1145 processSelectionChange(); 1149 processSelectionChange();
1146} 1150}
1147 1151
1148void KOTodoView::purgeCompleted() 1152void KOTodoView::purgeCompleted()
1149{ 1153{
1150 emit purgeCompletedSignal(); 1154 emit purgeCompletedSignal();
1151} 1155}
1152void KOTodoView::toggleQuickTodo() 1156void KOTodoView::toggleQuickTodo()
1153{ 1157{
1154 if ( mQuickAdd->isVisible() ) { 1158 if ( mQuickAdd->isVisible() ) {
1155 mQuickAdd->hide(); 1159 mQuickAdd->hide();
1156 KOPrefs::instance()->mEnableQuickTodo = false; 1160 KOPrefs::instance()->mEnableQuickTodo = false;
1157 } 1161 }
1158 else { 1162 else {
1159 mQuickAdd->show(); 1163 mQuickAdd->show();
1160 KOPrefs::instance()->mEnableQuickTodo = true; 1164 KOPrefs::instance()->mEnableQuickTodo = true;
1161 } 1165 }
1162 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 1166 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
1163 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 1167 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
1164} 1168}
1165 1169
1166void KOTodoView::toggleRunning() 1170void KOTodoView::toggleRunning()
1167{ 1171{
1168 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos; 1172 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos;
1169 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 1173 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
1170 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 1174 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
1171 updateView(); 1175 updateView();
1172} 1176}
1173 1177
1174void KOTodoView::toggleCompleted() 1178void KOTodoView::toggleCompleted()
1175{ 1179{
1176 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo; 1180 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo;
1177 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 1181 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
1178 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 1182 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
1179 updateView(); 1183 updateView();
1180} 1184}
1181 1185
1182void KOTodoView::addQuickTodo() 1186void KOTodoView::addQuickTodo()
1183{ 1187{
1184 Todo *todo = new Todo(); 1188 Todo *todo = new Todo();
1185 todo->setSummary(mQuickAdd->text()); 1189 todo->setSummary(mQuickAdd->text());
1186 todo->setOrganizer(KOPrefs::instance()->email()); 1190 todo->setOrganizer(KOPrefs::instance()->email());
1187 CalFilter * cf = mCalendar->filter(); 1191 CalFilter * cf = mCalendar->filter();
1188 if ( cf ) { 1192 if ( cf ) {
1189 if ( cf->isEnabled()&& cf->showCategories()) { 1193 if ( cf->isEnabled()&& cf->showCategories()) {
1190 todo->setCategories(cf->categoryList()); 1194 todo->setCategories(cf->categoryList());
1191 } 1195 }
1192 if ( cf->isEnabled() ) 1196 if ( cf->isEnabled() )
1193 todo->setSecrecy( cf->getSecrecy()); 1197 todo->setSecrecy( cf->getSecrecy());
1194 } 1198 }
1195 mCalendar->addTodo(todo); 1199 mCalendar->addTodo(todo);
1196 mQuickAdd->setText(""); 1200 mQuickAdd->setText("");
1197 todoModified (todo, KOGlobals::EVENTADDED ); 1201 todoModified (todo, KOGlobals::EVENTADDED );
1198 updateView(); 1202 updateView();
1199} 1203}
1200void KOTodoView::keyPressEvent ( QKeyEvent * e ) 1204void KOTodoView::keyPressEvent ( QKeyEvent * e )
1201{ 1205{
1202 // e->ignore(); 1206 // e->ignore();
1203 //return; 1207 //return;
1204 //qDebug("KOTodoView::keyPressEvent "); 1208 //qDebug("KOTodoView::keyPressEvent ");
1205 switch ( e->key() ) { 1209 switch ( e->key() ) {
1206 case Qt::Key_Down: 1210 case Qt::Key_Down:
1207 case Qt::Key_Up: 1211 case Qt::Key_Up:
1208 QWidget::keyPressEvent ( e ); 1212 QWidget::keyPressEvent ( e );
1209 break; 1213 break;
1210 1214
1211 case Qt::Key_Q: 1215 case Qt::Key_Q:
1212 toggleQuickTodo(); 1216 toggleQuickTodo();
1213 break; 1217 break;
1214 case Qt::Key_U: 1218 case Qt::Key_U:
1215 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1219 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1216 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1220 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1217 unparentTodo(); 1221 unparentTodo();
1218 e->accept(); 1222 e->accept();
1219 } else 1223 } else
1220 e->ignore(); 1224 e->ignore();
1221 break; 1225 break;
1222 case Qt::Key_S: 1226 case Qt::Key_S:
1223 if ( e->state() == Qt::ControlButton ) { 1227 if ( e->state() == Qt::ControlButton ) {
1224 e->ignore(); 1228 e->ignore();
1225 break; 1229 break;
1226 } 1230 }
1227 if ( e->state() == Qt::ShiftButton ) { 1231 if ( e->state() == Qt::ShiftButton ) {
1228 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1232 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1229 reparentTodo(); 1233 reparentTodo();
1230 e->accept(); 1234 e->accept();
1231 } else 1235 } else
1232 e->ignore(); 1236 e->ignore();
1233 break; 1237 break;
1234 case Qt::Key_P: 1238 case Qt::Key_P:
1235 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1239 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1236 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1240 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1237 if ( pendingSubtodo ) 1241 if ( pendingSubtodo )
1238 itemClicked(mActiveItem); 1242 itemClicked(mActiveItem);
1239 e->accept(); 1243 e->accept();
1240 } else 1244 } else
1241 e->ignore(); 1245 e->ignore();
1242 break; 1246 break;
1243 case Qt::Key_Escape: 1247 case Qt::Key_Escape:
1244 if ( pendingSubtodo ) { 1248 if ( pendingSubtodo ) {
1245 itemClicked(0); 1249 itemClicked(0);
1246 e->accept(); 1250 e->accept();
1247 } else 1251 } else
1248 e->ignore(); 1252 e->ignore();
1249 break; 1253 break;
1250 default: 1254 default:
1251 e->ignore(); 1255 e->ignore();
1252 } 1256 }
1253 1257
1254 if ( true ) { 1258 if ( true ) {
1255 if ( e->key() == Qt::Key_I ) { 1259 if ( e->key() == Qt::Key_I ) {
1256 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem(); 1260 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem();
1257 if ( cn ) { 1261 if ( cn ) {
1258 mActiveItem = cn; 1262 mActiveItem = cn;
1259 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 1263 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
1260 if ( ci ){ 1264 if ( ci ){
1261 showTodo(); 1265 showTodo();
1262 cn = (KOTodoViewItem*)cn->itemBelow(); 1266 cn = (KOTodoViewItem*)cn->itemBelow();
1263 if ( cn ) { 1267 if ( cn ) {
1264 mTodoListView->setCurrentItem ( cn ); 1268 mTodoListView->setCurrentItem ( cn );
1265 mTodoListView->ensureItemVisible ( cn ); 1269 mTodoListView->ensureItemVisible ( cn );
1266 } 1270 }
1267 1271
1268 } 1272 }
1269 } 1273 }
1270 e->accept(); 1274 e->accept();
1271 1275
1272 } 1276 }
1273 1277
1274 } 1278 }
1275 1279
1276} 1280}
1277void KOTodoView::updateTodo( Todo * t, int type ) 1281void KOTodoView::updateTodo( Todo * t, int type )
1278{ 1282{
1279 if ( mBlockUpdate) 1283 if ( mBlockUpdate)
1280 return; 1284 return;
1281 1285
1282 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 1286 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
1283 itemIterator = mTodoMap.find(t); 1287 itemIterator = mTodoMap.find(t);
1284 if (itemIterator != mTodoMap.end()) { 1288 if (itemIterator != mTodoMap.end()) {
1285 (*itemIterator)->construct(); 1289 (*itemIterator)->construct();
1286 } else { 1290 } else {
1287 if ( type == KOGlobals::EVENTADDED ) { 1291 if ( type == KOGlobals::EVENTADDED ) {
1288 insertTodoItem( t ); 1292 insertTodoItem( t );
1289 } 1293 }
1290 } 1294 }
1291 1295
1292} 1296}
1293 1297
1294void KOTodoView::todoModified(Todo * t , int p ) 1298void KOTodoView::todoModified(Todo * t , int p )
1295{ 1299{
1296 mBlockUpdate = true; 1300 mBlockUpdate = true;
1297 emit todoModifiedSignal ( t, p ); 1301 emit todoModifiedSignal ( t, p );
1298 mBlockUpdate = false; 1302 mBlockUpdate = false;
1299} 1303}