summaryrefslogtreecommitdiffabout
path: root/korganizer
authorzautrix <zautrix>2005-06-17 07:51:48 (UTC)
committer zautrix <zautrix>2005-06-17 07:51:48 (UTC)
commit825c34c11200f8ff0229cfb00b82b1880ef55b94 (patch) (unidiff)
tree243df776d77afe55ca36ca8a78586a9e2fca1888 /korganizer
parenta04fff3ce192e0bebf9243a1fbedb97cf7108d2b (diff)
downloadkdepimpi-825c34c11200f8ff0229cfb00b82b1880ef55b94.zip
kdepimpi-825c34c11200f8ff0229cfb00b82b1880ef55b94.tar.gz
kdepimpi-825c34c11200f8ff0229cfb00b82b1880ef55b94.tar.bz2
fixes
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kotodoview.cpp56
-rw-r--r--korganizer/kotodoview.h18
-rw-r--r--korganizer/kotodoviewitem.cpp2
3 files changed, 71 insertions, 5 deletions
diff --git a/korganizer/kotodoview.cpp b/korganizer/kotodoview.cpp
index b2ff33b..99e6a3a 100644
--- a/korganizer/kotodoview.cpp
+++ b/korganizer/kotodoview.cpp
@@ -1,1462 +1,1510 @@
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#include <qdialog.h>
29#include <qlabel.h>
30#include <qpushbutton.h>
28 31
29#include <qinputdialog.h> 32#include <qinputdialog.h>
30 33
31#include <qvbox.h> 34#include <qvbox.h>
32#include <kdebug.h> 35#include <kdebug.h>
33#include "koprefs.h" 36#include "koprefs.h"
34#include <klocale.h> 37#include <klocale.h>
35#include <kglobal.h> 38#include <kglobal.h>
36#include <kiconloader.h> 39#include <kiconloader.h>
37#include <kmessagebox.h> 40#include <kmessagebox.h>
38 41
39#include <libkcal/icaldrag.h> 42#include <libkcal/icaldrag.h>
40#include <libkcal/vcaldrag.h> 43#include <libkcal/vcaldrag.h>
41#include <libkcal/calfilter.h> 44#include <libkcal/calfilter.h>
42#include <libkcal/dndfactory.h> 45#include <libkcal/dndfactory.h>
43#include <libkcal/calendarresources.h> 46#include <libkcal/calendarresources.h>
44#include <libkcal/resourcecalendar.h> 47#include <libkcal/resourcecalendar.h>
45#include <kresources/resourceselectdialog.h> 48#include <kresources/resourceselectdialog.h>
46#include <libkcal/kincidenceformatter.h> 49#include <libkcal/kincidenceformatter.h>
47#ifndef DESKTOP_VERSION 50#ifndef DESKTOP_VERSION
48#include <qpe/qpeapplication.h> 51#include <qpe/qpeapplication.h>
49#else 52#else
50#include <qapplication.h> 53#include <qapplication.h>
51#endif 54#endif
52#ifndef KORG_NOPRINTER 55#ifndef KORG_NOPRINTER
53#include "calprinter.h" 56#include "calprinter.h"
54#endif 57#endif
55#include "docprefs.h" 58#include "docprefs.h"
56 59
57#include "kotodoview.h" 60#include "kotodoview.h"
58using namespace KOrg; 61using namespace KOrg;
59 62
60 63
64KOStopTodoPrefs::KOStopTodoPrefs( Todo* todo, QWidget *parent, const char *name ) :
65 QDialog( parent, name, true )
66{
67 mTodo = todo;
68 setCaption( i18n("Stop todo") );
69 QVBoxLayout* lay = new QVBoxLayout( this );
70 lay->setSpacing( 3 );
71 lay->setMargin( 3 );
72 QLabel * lab = new QLabel( i18n("%1\nis running!").arg( todo->summary() ), this );
73 lay->addWidget( lab );
74 lab->setAlignment( AlignHCenter );
75
76 QPushButton * ok = new QPushButton( i18n("Stop and save"), this );
77 lay->addWidget( ok );
78 QPushButton * cancel = new QPushButton( i18n("Continue running"), this );
79 lay->addWidget( cancel );
80 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
81 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
82 ok = new QPushButton( i18n("Stop - do not save"), this );
83 connect ( ok,SIGNAL(clicked() ),this , SLOT ( doNotSave() ) );
84 lay->addWidget( ok );
85 resize( 200, 200 );
86}
87
88void KOStopTodoPrefs::accept()
89{
90 qDebug("KOStopTodoPrefs::accept() ");
91 QDialog::accept();
92}
93void KOStopTodoPrefs::doNotSave()
94{
95
96 int result = KMessageBox::warningContinueCancel(this,
97 i18n("Do you really want to set\nthe state to stopped\nwithout saving the data?"),mTodo->summary() );
98 if (result != KMessageBox::Continue) return;
99 mTodo->stopRunning();
100 QDialog::accept();
101}
102
103
61class KOTodoViewWhatsThis :public QWhatsThis 104class KOTodoViewWhatsThis :public QWhatsThis
62{ 105{
63public: 106public:
64 KOTodoViewWhatsThis( QWidget *wid, KOTodoView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { }; 107 KOTodoViewWhatsThis( QWidget *wid, KOTodoView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { };
65 108
66protected: 109protected:
67 virtual QString text( const QPoint& p) 110 virtual QString text( const QPoint& p)
68 { 111 {
69 return _view->getWhatsThisText(p) ; 112 return _view->getWhatsThisText(p) ;
70 } 113 }
71private: 114private:
72 QWidget* _wid; 115 QWidget* _wid;
73 KOTodoView * _view; 116 KOTodoView * _view;
74}; 117};
75 118
76KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent, 119KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent,
77 const char *name) : 120 const char *name) :
78 KListView(parent,name) 121 KListView(parent,name)
79{ 122{
80 mName = QString ( name ); 123 mName = QString ( name );
81 mCalendar = calendar; 124 mCalendar = calendar;
82#ifndef DESKTOP_VERSION 125#ifndef DESKTOP_VERSION
83 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); 126 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold );
84#endif 127#endif
85 mOldCurrent = 0; 128 mOldCurrent = 0;
86 mMousePressed = false; 129 mMousePressed = false;
87 130
88 setAcceptDrops(true); 131 setAcceptDrops(true);
89 viewport()->setAcceptDrops(true); 132 viewport()->setAcceptDrops(true);
90 int size = 16; 133 int size = 16;
91 if (qApp->desktop()->width() < 300 ) 134 if (qApp->desktop()->width() < 300 )
92 size = 12; 135 size = 12;
93 setTreeStepSize( size + 6 ); 136 setTreeStepSize( size + 6 );
94 137
95} 138}
96 139
97void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e) 140void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e)
98{ 141{
99#ifndef KORG_NODND 142#ifndef KORG_NODND
100// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl; 143// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl;
101 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 144 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
102 !QTextDrag::canDecode( e ) ) { 145 !QTextDrag::canDecode( e ) ) {
103 e->ignore(); 146 e->ignore();
104 return; 147 return;
105 } 148 }
106 149
107 mOldCurrent = currentItem(); 150 mOldCurrent = currentItem();
108#endif 151#endif
109} 152}
110 153
111 154
112void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e) 155void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e)
113{ 156{
114#ifndef KORG_NODND 157#ifndef KORG_NODND
115// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl; 158// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl;
116 159
117 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 160 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
118 !QTextDrag::canDecode( e ) ) { 161 !QTextDrag::canDecode( e ) ) {
119 e->ignore(); 162 e->ignore();
120 return; 163 return;
121 } 164 }
122 165
123 e->accept(); 166 e->accept();
124#endif 167#endif
125} 168}
126 169
127void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *) 170void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *)
128{ 171{
129#ifndef KORG_NODND 172#ifndef KORG_NODND
130// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl; 173// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl;
131 174
132 setCurrentItem(mOldCurrent); 175 setCurrentItem(mOldCurrent);
133 setSelected(mOldCurrent,true); 176 setSelected(mOldCurrent,true);
134#endif 177#endif
135} 178}
136 179
137void KOTodoListView::contentsDropEvent(QDropEvent *e) 180void KOTodoListView::contentsDropEvent(QDropEvent *e)
138{ 181{
139#ifndef KORG_NODND 182#ifndef KORG_NODND
140// kdDebug() << "KOTodoListView::contentsDropEvent" << endl; 183// kdDebug() << "KOTodoListView::contentsDropEvent" << endl;
141 184
142 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 185 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
143 !QTextDrag::canDecode( e ) ) { 186 !QTextDrag::canDecode( e ) ) {
144 e->ignore(); 187 e->ignore();
145 return; 188 return;
146 } 189 }
147 190
148 DndFactory factory( mCalendar ); 191 DndFactory factory( mCalendar );
149 Todo *todo = factory.createDropTodo(e); 192 Todo *todo = factory.createDropTodo(e);
150 193
151 if (todo) { 194 if (todo) {
152 e->acceptAction(); 195 e->acceptAction();
153 196
154 KOTodoViewItem *destination = 197 KOTodoViewItem *destination =
155 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos())); 198 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos()));
156 Todo *destinationEvent = 0; 199 Todo *destinationEvent = 0;
157 if (destination) destinationEvent = destination->todo(); 200 if (destination) destinationEvent = destination->todo();
158 201
159 Todo *existingTodo = mCalendar->todo(todo->uid()); 202 Todo *existingTodo = mCalendar->todo(todo->uid());
160 203
161 if(existingTodo) { 204 if(existingTodo) {
162 Incidence *to = destinationEvent; 205 Incidence *to = destinationEvent;
163 while(to) { 206 while(to) {
164 if (to->uid() == todo->uid()) { 207 if (to->uid() == todo->uid()) {
165 KMessageBox::sorry(this, 208 KMessageBox::sorry(this,
166 i18n("Cannot move Todo to itself\nor a child of itself"), 209 i18n("Cannot move Todo to itself\nor a child of itself"),
167 i18n("Drop Todo")); 210 i18n("Drop Todo"));
168 delete todo; 211 delete todo;
169 return; 212 return;
170 } 213 }
171 to = to->relatedTo(); 214 to = to->relatedTo();
172 } 215 }
173 internalDrop = true; 216 internalDrop = true;
174 if ( destinationEvent ) 217 if ( destinationEvent )
175 reparentTodoSignal( destinationEvent, existingTodo ); 218 reparentTodoSignal( destinationEvent, existingTodo );
176 else 219 else
177 unparentTodoSignal(existingTodo); 220 unparentTodoSignal(existingTodo);
178 delete todo; 221 delete todo;
179 } else { 222 } else {
180 mCalendar->addTodo(todo); 223 mCalendar->addTodo(todo);
181 emit todoDropped(todo, KOGlobals::EVENTADDED); 224 emit todoDropped(todo, KOGlobals::EVENTADDED);
182 if ( destinationEvent ) 225 if ( destinationEvent )
183 reparentTodoSignal( destinationEvent, todo ); 226 reparentTodoSignal( destinationEvent, todo );
184 } 227 }
185 } 228 }
186 else { 229 else {
187 QString text; 230 QString text;
188 if (QTextDrag::decode(e,text)) { 231 if (QTextDrag::decode(e,text)) {
189 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) ); 232 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) );
190 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) )); 233 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) ));
191 qDebug("Dropped : " + text); 234 qDebug("Dropped : " + text);
192 QStringList emails = QStringList::split(",",text); 235 QStringList emails = QStringList::split(",",text);
193 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 236 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
194 int pos = (*it).find("<"); 237 int pos = (*it).find("<");
195 QString name = (*it).left(pos); 238 QString name = (*it).left(pos);
196 QString email = (*it).mid(pos); 239 QString email = (*it).mid(pos);
197 if (!email.isEmpty() && todoi) { 240 if (!email.isEmpty() && todoi) {
198 todoi->todo()->addAttendee(new Attendee(name,email)); 241 todoi->todo()->addAttendee(new Attendee(name,email));
199 } 242 }
200 } 243 }
201 } 244 }
202 else { 245 else {
203 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable "); 246 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable ");
204 e->ignore(); 247 e->ignore();
205 } 248 }
206 } 249 }
207#endif 250#endif
208} 251}
209void KOTodoListView::wheelEvent (QWheelEvent *e) 252void KOTodoListView::wheelEvent (QWheelEvent *e)
210{ 253{
211 QListView::wheelEvent (e); 254 QListView::wheelEvent (e);
212} 255}
213 256
214void KOTodoListView::contentsMousePressEvent(QMouseEvent* e) 257void KOTodoListView::contentsMousePressEvent(QMouseEvent* e)
215{ 258{
216 259
217 QPoint p(contentsToViewport(e->pos())); 260 QPoint p(contentsToViewport(e->pos()));
218 QListViewItem *i = itemAt(p); 261 QListViewItem *i = itemAt(p);
219 bool rootClicked = true; 262 bool rootClicked = true;
220 if (i) { 263 if (i) {
221 // if the user clicked into the root decoration of the item, don't 264 // if the user clicked into the root decoration of the item, don't
222 // try to start a drag! 265 // try to start a drag!
223 int X = p.x(); 266 int X = p.x();
224 //qDebug("%d %d %d", X, header()->sectionPos(0), treeStepSize() ); 267 //qDebug("%d %d %d", X, header()->sectionPos(0), treeStepSize() );
225 if (X > header()->sectionPos(0) + 268 if (X > header()->sectionPos(0) +
226 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) + 269 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) +
227 itemMargin() +i->height()|| 270 itemMargin() +i->height()||
228 X < header()->sectionPos(0)) { 271 X < header()->sectionPos(0)) {
229 rootClicked = false; 272 rootClicked = false;
230 } 273 }
231 } else { 274 } else {
232 rootClicked = false; 275 rootClicked = false;
233 } 276 }
234#ifndef KORG_NODND 277#ifndef KORG_NODND
235 mMousePressed = false; 278 mMousePressed = false;
236 if (! rootClicked && !( e->button() == RightButton) ) { 279 if (! rootClicked && !( e->button() == RightButton) ) {
237 mPressPos = e->pos(); 280 mPressPos = e->pos();
238 mMousePressed = true; 281 mMousePressed = true;
239 } else { 282 } else {
240 mMousePressed = false; 283 mMousePressed = false;
241 } 284 }
242#endif 285#endif
243 //qDebug("KOTodoListView::contentsMousePressEvent %d", rootClicked); 286 //qDebug("KOTodoListView::contentsMousePressEvent %d", rootClicked);
244#ifndef DESKTOP_VERSION 287#ifndef DESKTOP_VERSION
245 if (!( e->button() == RightButton && rootClicked) ) 288 if (!( e->button() == RightButton && rootClicked) )
246 QListView::contentsMousePressEvent(e); 289 QListView::contentsMousePressEvent(e);
247#else 290#else
248 QListView::contentsMousePressEvent(e); 291 QListView::contentsMousePressEvent(e);
249#endif 292#endif
250} 293}
251void KOTodoListView::paintEvent(QPaintEvent* e) 294void KOTodoListView::paintEvent(QPaintEvent* e)
252{ 295{
253 emit paintNeeded(); 296 emit paintNeeded();
254 QListView::paintEvent( e); 297 QListView::paintEvent( e);
255} 298}
256void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e) 299void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e)
257{ 300{
258 301
259#ifndef KORG_NODND 302#ifndef KORG_NODND
260 //QListView::contentsMouseMoveEvent(e); 303 //QListView::contentsMouseMoveEvent(e);
261 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() > 304 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() >
262 QApplication::startDragDistance()*3) { 305 QApplication::startDragDistance()*3) {
263 mMousePressed = false; 306 mMousePressed = false;
264 QListViewItem *item = itemAt(contentsToViewport(mPressPos)); 307 QListViewItem *item = itemAt(contentsToViewport(mPressPos));
265 if (item) { 308 if (item) {
266 DndFactory factory( mCalendar ); 309 DndFactory factory( mCalendar );
267 ICalDrag *vd = factory.createDrag( 310 ICalDrag *vd = factory.createDrag(
268 ((KOTodoViewItem *)item)->todo(),viewport()); 311 ((KOTodoViewItem *)item)->todo(),viewport());
269 internalDrop = false; 312 internalDrop = false;
270 // we cannot do any senseful here, because the DnD is still broken in Qt 313 // we cannot do any senseful here, because the DnD is still broken in Qt
271 if (vd->drag()) { 314 if (vd->drag()) {
272 if ( !internalDrop ) { 315 if ( !internalDrop ) {
273 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() ); 316 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() );
274 qDebug("Dnd: External move: Delete drag source "); 317 qDebug("Dnd: External move: Delete drag source ");
275 } else 318 } else
276 qDebug("Dnd: Internal move "); 319 qDebug("Dnd: Internal move ");
277 320
278 } else { 321 } else {
279 if ( !internalDrop ) { 322 if ( !internalDrop ) {
280 qDebug("Dnd: External Copy"); 323 qDebug("Dnd: External Copy");
281 } else 324 } else
282 qDebug("DnD: Internal copy: Copy pending"); 325 qDebug("DnD: Internal copy: Copy pending");
283 } 326 }
284 } 327 }
285 } 328 }
286#endif 329#endif
287} 330}
288void KOTodoListView::keyReleaseEvent ( QKeyEvent *e ) 331void KOTodoListView::keyReleaseEvent ( QKeyEvent *e )
289{ 332{
290 if ( !e->isAutoRepeat() ) { 333 if ( !e->isAutoRepeat() ) {
291 mFlagKeyPressed = false; 334 mFlagKeyPressed = false;
292 } 335 }
293} 336}
294 337
295 338
296void KOTodoListView::keyPressEvent ( QKeyEvent * e ) 339void KOTodoListView::keyPressEvent ( QKeyEvent * e )
297{ 340{
298 qApp->processEvents(); 341 qApp->processEvents();
299 if ( e->isAutoRepeat() && !mFlagKeyPressed ) { 342 if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
300 e->ignore(); 343 e->ignore();
301 // qDebug(" ignore %d",e->isAutoRepeat() ); 344 // qDebug(" ignore %d",e->isAutoRepeat() );
302 return; 345 return;
303 } 346 }
304 if (! e->isAutoRepeat() ) 347 if (! e->isAutoRepeat() )
305 mFlagKeyPressed = true; 348 mFlagKeyPressed = true;
306 QListViewItem* cn; 349 QListViewItem* cn;
307 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) { 350 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) {
308 cn = currentItem(); 351 cn = currentItem();
309 if ( cn ) { 352 if ( cn ) {
310 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 353 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
311 if ( ci ){ 354 if ( ci ){
312 if ( e->state() == ShiftButton ) 355 if ( e->state() == ShiftButton )
313 ci->setOn( false ); 356 ci->setOn( false );
314 else 357 else
315 ci->setOn( true ); 358 ci->setOn( true );
316 cn = cn->itemBelow(); 359 cn = cn->itemBelow();
317 if ( cn ) { 360 if ( cn ) {
318 setCurrentItem ( cn ); 361 setCurrentItem ( cn );
319 ensureItemVisible ( cn ); 362 ensureItemVisible ( cn );
320 } 363 }
321 364
322 } 365 }
323 } 366 }
324 367
325 return; 368 return;
326 } 369 }
327 370
328 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) { 371 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) {
329 switch ( e->key() ) { 372 switch ( e->key() ) {
330 case Qt::Key_Down: 373 case Qt::Key_Down:
331 case Qt::Key_Up: 374 case Qt::Key_Up:
332 QListView::keyPressEvent ( e ); 375 QListView::keyPressEvent ( e );
333 break; 376 break;
334 case Qt::Key_Left: 377 case Qt::Key_Left:
335 case Qt::Key_Right: 378 case Qt::Key_Right:
336 QListView::keyPressEvent ( e ); 379 QListView::keyPressEvent ( e );
337 e->accept(); 380 e->accept();
338 return; 381 return;
339 break; 382 break;
340 default: 383 default:
341 e->ignore(); 384 e->ignore();
342 break; 385 break;
343 } 386 }
344 return; 387 return;
345 } 388 }
346 e->ignore(); 389 e->ignore();
347} 390}
348void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e) 391void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e)
349{ 392{
350 QListView::contentsMouseReleaseEvent(e); 393 QListView::contentsMouseReleaseEvent(e);
351 mMousePressed = false; 394 mMousePressed = false;
352} 395}
353 396
354void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e) 397void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
355{ 398{
356 if (!e) return; 399 if (!e) return;
357 400
358 QPoint vp = contentsToViewport(e->pos()); 401 QPoint vp = contentsToViewport(e->pos());
359 402
360 QListViewItem *item = itemAt(vp); 403 QListViewItem *item = itemAt(vp);
361 404
362 emit double_Clicked(item); 405 emit double_Clicked(item);
363 if (!item) return; 406 if (!item) return;
364 407
365 emit doubleClicked(item,vp,0); 408 emit doubleClicked(item,vp,0);
366} 409}
367 410
368///////////////////////////////////////////////////////////////////////////// 411/////////////////////////////////////////////////////////////////////////////
369 412
370KOQuickTodo::KOQuickTodo(QWidget *parent) : 413KOQuickTodo::KOQuickTodo(QWidget *parent) :
371 QLineEdit(parent) 414 QLineEdit(parent)
372{ 415{
373 setText(i18n("Click to add a new Todo")); 416 setText(i18n("Click to add a new Todo"));
374} 417}
375 418
376void KOQuickTodo::focusInEvent(QFocusEvent *ev) 419void KOQuickTodo::focusInEvent(QFocusEvent *ev)
377{ 420{
378 if ( text()==i18n("Click to add a new Todo") ) 421 if ( text()==i18n("Click to add a new Todo") )
379 setText(""); 422 setText("");
380 QLineEdit::focusInEvent(ev); 423 QLineEdit::focusInEvent(ev);
381} 424}
382 425
383void KOQuickTodo::focusOutEvent(QFocusEvent *ev) 426void KOQuickTodo::focusOutEvent(QFocusEvent *ev)
384{ 427{
385 setText(i18n("Click to add a new Todo")); 428 setText(i18n("Click to add a new Todo"));
386 QLineEdit::focusOutEvent(ev); 429 QLineEdit::focusOutEvent(ev);
387} 430}
388 431
389///////////////////////////////////////////////////////////////////////////// 432/////////////////////////////////////////////////////////////////////////////
390 433
391KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) : 434KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) :
392 KOrg::BaseView(calendar,parent,name) 435 KOrg::BaseView(calendar,parent,name)
393{ 436{
394 mPendingUpdateBeforeRepaint = false; 437 mPendingUpdateBeforeRepaint = false;
395 isFlatDisplay = false; 438 isFlatDisplay = false;
396 mNavigator = 0; 439 mNavigator = 0;
397 QBoxLayout *topLayout = new QVBoxLayout(this); 440 QBoxLayout *topLayout = new QVBoxLayout(this);
398 mName = QString ( name ); 441 mName = QString ( name );
399 mBlockUpdate = false; 442 mBlockUpdate = false;
400 mQuickAdd = new KOQuickTodo(this); 443 mQuickAdd = new KOQuickTodo(this);
401 topLayout->addWidget(mQuickAdd); 444 topLayout->addWidget(mQuickAdd);
402 445
403 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide(); 446 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide();
404 447
405 mTodoListView = new KOTodoListView(calendar,this, name ); 448 mTodoListView = new KOTodoListView(calendar,this, name );
406 topLayout->addWidget(mTodoListView); 449 topLayout->addWidget(mTodoListView);
407 //mTodoListView->header()->setMaximumHeight(30); 450 //mTodoListView->header()->setMaximumHeight(30);
408 mTodoListView->setRootIsDecorated(true); 451 mTodoListView->setRootIsDecorated(true);
409 mTodoListView->setAllColumnsShowFocus(true); 452 mTodoListView->setAllColumnsShowFocus(true);
410 453
411 mTodoListView->setShowSortIndicator(true); 454 mTodoListView->setShowSortIndicator(true);
412 455
413 mTodoListView->addColumn(i18n("Todo")); 456 mTodoListView->addColumn(i18n("Todo"));
414 mTodoListView->addColumn(i18n("Prio")); 457 mTodoListView->addColumn(i18n("Prio"));
415 mTodoListView->setColumnAlignment(1,AlignHCenter); 458 mTodoListView->setColumnAlignment(1,AlignHCenter);
416 mTodoListView->addColumn(i18n("Complete")); 459 mTodoListView->addColumn(i18n("Complete"));
417 mTodoListView->setColumnAlignment(2,AlignCenter); 460 mTodoListView->setColumnAlignment(2,AlignCenter);
418 461
419 mTodoListView->addColumn(i18n("Due Date")); 462 mTodoListView->addColumn(i18n("Due Date"));
420 mTodoListView->setColumnAlignment(3,AlignLeft); 463 mTodoListView->setColumnAlignment(3,AlignLeft);
421 mTodoListView->addColumn(i18n("Due Time")); 464 mTodoListView->addColumn(i18n("Due Time"));
422 mTodoListView->setColumnAlignment(4,AlignHCenter); 465 mTodoListView->setColumnAlignment(4,AlignHCenter);
423 466
424 mTodoListView->addColumn(i18n("Start Date")); 467 mTodoListView->addColumn(i18n("Start Date"));
425 mTodoListView->setColumnAlignment(5,AlignLeft); 468 mTodoListView->setColumnAlignment(5,AlignLeft);
426 mTodoListView->addColumn(i18n("Start Time")); 469 mTodoListView->addColumn(i18n("Start Time"));
427 mTodoListView->setColumnAlignment(6,AlignHCenter); 470 mTodoListView->setColumnAlignment(6,AlignHCenter);
428 471
429 mTodoListView->addColumn(i18n("Cancelled")); 472 mTodoListView->addColumn(i18n("Cancelled"));
430 mTodoListView->addColumn(i18n("Categories")); 473 mTodoListView->addColumn(i18n("Categories"));
431 mTodoListView->addColumn(i18n("Calendar")); 474 mTodoListView->addColumn(i18n("Calendar"));
432#if 0 475#if 0
433 mTodoListView->addColumn(i18n("Sort Id")); 476 mTodoListView->addColumn(i18n("Sort Id"));
434 mTodoListView->setColumnAlignment(4,AlignHCenter); 477 mTodoListView->setColumnAlignment(4,AlignHCenter);
435#endif 478#endif
436 479
437 mTodoListView->setMinimumHeight( 60 ); 480 mTodoListView->setMinimumHeight( 60 );
438 mTodoListView->setItemsRenameable( true ); 481 mTodoListView->setItemsRenameable( true );
439 mTodoListView->setRenameable( 0 ); 482 mTodoListView->setRenameable( 0 );
440 mTodoListView->setColumnWidth( 0, 120 ); 483 mTodoListView->setColumnWidth( 0, 120 );
441 int iii = 0; 484 int iii = 0;
442 for ( iii = 0; iii< 10 ; ++iii ) 485 for ( iii = 0; iii< 10 ; ++iii )
443 mTodoListView->setColumnWidthMode( iii, QListView::Manual ); 486 mTodoListView->setColumnWidthMode( iii, QListView::Manual );
444 487
445 488
446 mKOTodoViewWhatsThis = new KOTodoViewWhatsThis(mTodoListView->viewport(),this); 489 mKOTodoViewWhatsThis = new KOTodoViewWhatsThis(mTodoListView->viewport(),this);
447 490
448 mPriorityPopupMenu = new QPopupMenu(this); 491 mPriorityPopupMenu = new QPopupMenu(this);
449 for (int i = 1; i <= 5; i++) { 492 for (int i = 1; i <= 5; i++) {
450 QString label = QString ("%1").arg (i); 493 QString label = QString ("%1").arg (i);
451 mPriority[mPriorityPopupMenu->insertItem (label)] = i; 494 mPriority[mPriorityPopupMenu->insertItem (label)] = i;
452 } 495 }
453 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int))); 496 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int)));
454 497
455 mPercentageCompletedPopupMenu = new QPopupMenu(this); 498 mPercentageCompletedPopupMenu = new QPopupMenu(this);
456 for (int i = 0; i <= 100; i+=20) { 499 for (int i = 0; i <= 100; i+=20) {
457 QString label = QString ("%1 %").arg (i); 500 QString label = QString ("%1 %").arg (i);
458 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i; 501 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i;
459 } 502 }
460 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int))); 503 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int)));
461 504
462 505
463 506
464 mItemPopupMenu = new QPopupMenu(this); 507 mItemPopupMenu = new QPopupMenu(this);
465 mItemPopupMenu->insertItem(i18n("Show..."), this, 508 mItemPopupMenu->insertItem(i18n("Show..."), this,
466 SLOT (showTodo())); 509 SLOT (showTodo()));
467 mItemPopupMenu->insertItem(i18n("Edit..."), this, 510 mItemPopupMenu->insertItem(i18n("Edit..."), this,
468 SLOT (editTodo())); 511 SLOT (editTodo()));
469 mItemPopupMenu->insertItem( i18n("Delete"), this, 512 mItemPopupMenu->insertItem( i18n("Delete"), this,
470 SLOT (deleteTodo())); 513 SLOT (deleteTodo()));
471 mItemPopupMenu->insertItem( i18n("Clone..."), this, 514 mItemPopupMenu->insertItem( i18n("Clone..."), this,
472 SLOT (cloneTodo())); 515 SLOT (cloneTodo()));
473 mItemPopupMenu->insertItem( i18n("Move..."), this, 516 mItemPopupMenu->insertItem( i18n("Move..."), this,
474 SLOT (moveTodo())); 517 SLOT (moveTodo()));
475#ifndef DESKTOP_VERSION 518#ifndef DESKTOP_VERSION
476 mItemPopupMenu->insertItem( i18n("Beam..."), this, 519 mItemPopupMenu->insertItem( i18n("Beam..."), this,
477 SLOT (beamTodo())); 520 SLOT (beamTodo()));
478#endif 521#endif
479 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this, 522 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this,
480 SLOT (cancelTodo())); 523 SLOT (cancelTodo()));
481 mItemPopupMenu->insertSeparator(); 524 mItemPopupMenu->insertSeparator();
482 mItemPopupMenu->insertItem( i18n("Start/Stop todo..."), this, 525 mItemPopupMenu->insertItem( i18n("Start/Stop todo..."), this,
483 SLOT (toggleRunningItem())); 526 SLOT (toggleRunningItem()));
484 mItemPopupMenu->insertSeparator(); 527 mItemPopupMenu->insertSeparator();
485 /* 528 /*
486 mItemPopupMenu->insertItem( i18n("New Todo..."), this, 529 mItemPopupMenu->insertItem( i18n("New Todo..."), this,
487 SLOT (newTodo())); 530 SLOT (newTodo()));
488 */ 531 */
489 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this, 532 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this,
490 SLOT (newSubTodo())); 533 SLOT (newSubTodo()));
491 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this, 534 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this,
492 SLOT (unparentTodo()),0,21); 535 SLOT (unparentTodo()),0,21);
493 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this, 536 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this,
494 SLOT (reparentTodo()),0,22); 537 SLOT (reparentTodo()),0,22);
495 mItemPopupMenu->insertSeparator(); 538 mItemPopupMenu->insertSeparator();
496#if 0 539#if 0
497 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"), 540 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"),
498 this, SLOT( purgeCompleted() ) ); 541 this, SLOT( purgeCompleted() ) );
499 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"), 542 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"),
500 this, SLOT( toggleCompleted() ),0, 33 ); 543 this, SLOT( toggleCompleted() ),0, 33 );
501 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 544 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
502 this, SLOT( toggleQuickTodo() ),0, 34 ); 545 this, SLOT( toggleQuickTodo() ),0, 34 );
503 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 546 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
504 this, SLOT( toggleRunning() ),0, 35 ); 547 this, SLOT( toggleRunning() ),0, 35 );
505 548
506#endif 549#endif
507 mPopupMenu = new QPopupMenu(this); 550 mPopupMenu = new QPopupMenu(this);
508 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this, 551 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this,
509 SLOT (newTodo()),0,1); 552 SLOT (newTodo()),0,1);
510 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"), 553 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"),
511 this, SLOT(purgeCompleted()),0,2); 554 this, SLOT(purgeCompleted()),0,2);
512 mPopupMenu->insertItem(i18n("Show Completed"), 555 mPopupMenu->insertItem(i18n("Show Completed"),
513 this, SLOT( toggleCompleted() ),0,3 ); 556 this, SLOT( toggleCompleted() ),0,3 );
514 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 557 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
515 this, SLOT( toggleRunning() ),0,5 ); 558 this, SLOT( toggleRunning() ),0,5 );
516 mPopupMenu->insertItem(i18n(" set all open","Display all opened"), 559 mPopupMenu->insertItem(i18n(" set all open","Display all opened"),
517 this, SLOT( setAllOpen() ),0,6 ); 560 this, SLOT( setAllOpen() ),0,6 );
518 mPopupMenu->insertItem(i18n(" set all close","Display all closed"), 561 mPopupMenu->insertItem(i18n(" set all close","Display all closed"),
519 this, SLOT( setAllClose() ),0,7 ); 562 this, SLOT( setAllClose() ),0,7 );
520 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"), 563 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"),
521 this, SLOT( setAllFlat() ),0,8 ); 564 this, SLOT( setAllFlat() ),0,8 );
522 mPopupMenu->insertSeparator(); 565 mPopupMenu->insertSeparator();
523 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 566 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
524 this, SLOT( toggleQuickTodo() ),0,4 ); 567 this, SLOT( toggleQuickTodo() ),0,4 );
525 mDocPrefs = new DocPrefs( name ); 568 mDocPrefs = new DocPrefs( name );
526 569
527 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu ); 570 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu );
528 mPopupMenu->setCheckable( true ); 571 mPopupMenu->setCheckable( true );
529 mItemPopupMenu->setCheckable( true ); 572 mItemPopupMenu->setCheckable( true );
530 573
531 574
532 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 575 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
533 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 576 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
534 577
535 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 578 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
536 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 579 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
537 580
538 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 581 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
539 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 582 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
540 583
541 584
542 // Double clicking conflicts with opening/closing the subtree 585 // Double clicking conflicts with opening/closing the subtree
543 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ), 586 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ),
544 SLOT( editItem( QListViewItem *) ) ); 587 SLOT( editItem( QListViewItem *) ) );
545 /* 588 /*
546 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *, 589 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *,
547 const QPoint &,int ) ), 590 const QPoint &,int ) ),
548 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 591 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
549 */ 592 */
550 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *, 593 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *,
551 const QPoint &,int ) ), 594 const QPoint &,int ) ),
552 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 595 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
553 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ), 596 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ),
554 SLOT( itemClicked( QListViewItem * ) ) ); 597 SLOT( itemClicked( QListViewItem * ) ) );
555 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ), 598 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ),
556 SLOT( itemDoubleClicked( QListViewItem * ) ) ); 599 SLOT( itemDoubleClicked( QListViewItem * ) ) );
557 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 600 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
558 SLOT( updateView() ) ); 601 SLOT( updateView() ) );
559 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 602 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
560 SLOT( todoModified(Todo *, int) ) ); 603 SLOT( todoModified(Todo *, int) ) );
561 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ), 604 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ),
562 SLOT( itemStateChanged( QListViewItem * ) ) ); 605 SLOT( itemStateChanged( QListViewItem * ) ) );
563 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ), 606 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ),
564 SLOT( itemStateChanged( QListViewItem * ) ) ); 607 SLOT( itemStateChanged( QListViewItem * ) ) );
565 connect( mTodoListView, SIGNAL( paintNeeded() ), 608 connect( mTodoListView, SIGNAL( paintNeeded() ),
566 SLOT( paintNeeded()) ); 609 SLOT( paintNeeded()) );
567 610
568#if 0 611#if 0
569 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)), 612 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)),
570 SLOT(selectionChanged(QListViewItem *))); 613 SLOT(selectionChanged(QListViewItem *)));
571 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)), 614 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)),
572 SLOT(selectionChanged(QListViewItem *))); 615 SLOT(selectionChanged(QListViewItem *)));
573 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)), 616 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)),
574 SLOT(selectionChanged(QListViewItem *))); 617 SLOT(selectionChanged(QListViewItem *)));
575#endif 618#endif
576 619
577 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) )); 620 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) ));
578 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) )); 621 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) ));
579 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) )); 622 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) ));
580 623
581 connect( mTodoListView, SIGNAL(selectionChanged() ), 624 connect( mTodoListView, SIGNAL(selectionChanged() ),
582 SLOT( processSelectionChange() ) ); 625 SLOT( processSelectionChange() ) );
583 connect( mQuickAdd, SIGNAL( returnPressed () ), 626 connect( mQuickAdd, SIGNAL( returnPressed () ),
584 SLOT( addQuickTodo() ) ); 627 SLOT( addQuickTodo() ) );
585 628
586} 629}
587 630
588KOTodoView::~KOTodoView() 631KOTodoView::~KOTodoView()
589{ 632{
590 633
591#if QT_VERSION >= 0x030000 634#if QT_VERSION >= 0x030000
592 635
593#else 636#else
594 delete mKOTodoViewWhatsThis; 637 delete mKOTodoViewWhatsThis;
595#endif 638#endif
596 639
597 delete mDocPrefs; 640 delete mDocPrefs;
598} 641}
599QString KOTodoView::getWhatsThisText(QPoint p) 642QString KOTodoView::getWhatsThisText(QPoint p)
600{ 643{
601 KOTodoViewItem* item = ( KOTodoViewItem* ) mTodoListView->itemAt( p ); 644 KOTodoViewItem* item = ( KOTodoViewItem* ) mTodoListView->itemAt( p );
602 if ( item ) 645 if ( item )
603 return KIncidenceFormatter::instance()->getFormattedText( item->todo(), 646 return KIncidenceFormatter::instance()->getFormattedText( item->todo(),
604 KOPrefs::instance()->mWTshowDetails, 647 KOPrefs::instance()->mWTshowDetails,
605 KOPrefs::instance()->mWTshowCreated, 648 KOPrefs::instance()->mWTshowCreated,
606 KOPrefs::instance()->mWTshowChanged); 649 KOPrefs::instance()->mWTshowChanged);
607 return i18n("That is the todo view" ); 650 return i18n("That is the todo view" );
608 651
609} 652}
610 653
611void KOTodoView::jumpToDate () 654void KOTodoView::jumpToDate ()
612{ 655{
613 // if (mActiveItem) { 656 // if (mActiveItem) {
614// mActiveItem->todo()); 657// mActiveItem->todo());
615// if ( mActiveItem->todo()->hasDueDate() ) 658// if ( mActiveItem->todo()->hasDueDate() )
616// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() ); 659// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() );
617} 660}
618void KOTodoView::paintNeeded() 661void KOTodoView::paintNeeded()
619{ 662{
620 if ( mPendingUpdateBeforeRepaint ) { 663 if ( mPendingUpdateBeforeRepaint ) {
621 updateView(); 664 updateView();
622 mPendingUpdateBeforeRepaint = false; 665 mPendingUpdateBeforeRepaint = false;
623 } 666 }
624} 667}
625void KOTodoView::paintEvent(QPaintEvent * pevent) 668void KOTodoView::paintEvent(QPaintEvent * pevent)
626{ 669{
627 if ( mPendingUpdateBeforeRepaint ) { 670 if ( mPendingUpdateBeforeRepaint ) {
628 updateView(); 671 updateView();
629 mPendingUpdateBeforeRepaint = false; 672 mPendingUpdateBeforeRepaint = false;
630 } 673 }
631 KOrg::BaseView::paintEvent( pevent); 674 KOrg::BaseView::paintEvent( pevent);
632} 675}
633 676
634void KOTodoView::updateView() 677void KOTodoView::updateView()
635{ 678{
636 pendingSubtodo = 0; 679 pendingSubtodo = 0;
637 if ( mBlockUpdate ) { 680 if ( mBlockUpdate ) {
638 return; 681 return;
639 } 682 }
640 if ( !isVisible() ) { 683 if ( !isVisible() ) {
641 mPendingUpdateBeforeRepaint = true; 684 mPendingUpdateBeforeRepaint = true;
642 return; 685 return;
643 } 686 }
644 storeCurrentItem(); 687 storeCurrentItem();
645 //qDebug("KOTodoView::updateView() %x", this); 688 //qDebug("KOTodoView::updateView() %x", this);
646 if ( isFlatDisplay ) { 689 if ( isFlatDisplay ) {
647 displayAllFlat(); 690 displayAllFlat();
648 resetCurrentItem(); 691 resetCurrentItem();
649 return; 692 return;
650 } 693 }
651 //qDebug("update "); 694 //qDebug("update ");
652// kdDebug() << "KOTodoView::updateView()" << endl; 695// kdDebug() << "KOTodoView::updateView()" << endl;
653 QFont fo = KOPrefs::instance()->mTodoViewFont; 696 QFont fo = KOPrefs::instance()->mTodoViewFont;
654 697
655 698
656 mTodoListView->clear(); 699 mTodoListView->clear();
657 if ( mName == "todolistsmall" ) { 700 if ( mName == "todolistsmall" ) {
658 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) { 701 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) {
659 int ps = fo.pointSize() -2; 702 int ps = fo.pointSize() -2;
660 if ( ps > 12 ) 703 if ( ps > 12 )
661 ps -= 2; 704 ps -= 2;
662 fo.setPointSize( ps ); 705 fo.setPointSize( ps );
663 } 706 }
664 } 707 }
665 708
666 mTodoListView->setFont( fo ); 709 mTodoListView->setFont( fo );
667 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont ); 710 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont );
668 //mTodoListView->header()->setMaximumHeight(fm.height()); 711 //mTodoListView->header()->setMaximumHeight(fm.height());
669 QPtrList<Todo> todoList = calendar()->todos(); 712 QPtrList<Todo> todoList = calendar()->todos();
670 713
671/* 714/*
672 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl; 715 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl;
673 Event *t; 716 Event *t;
674 for(t = todoList.first(); t; t = todoList.next()) { 717 for(t = todoList.first(); t; t = todoList.next()) {
675 kdDebug() << " " << t->getSummary() << endl; 718 kdDebug() << " " << t->getSummary() << endl;
676 719
677 if (t->getRelatedTo()) { 720 if (t->getRelatedTo()) {
678 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl; 721 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl;
679 } 722 }
680 723
681 QPtrList<Event> l = t->getRelations(); 724 QPtrList<Event> l = t->getRelations();
682 Event *c; 725 Event *c;
683 for(c=l.first();c;c=l.next()) { 726 for(c=l.first();c;c=l.next()) {
684 kdDebug() << " - relation: " << c->getSummary() << endl; 727 kdDebug() << " - relation: " << c->getSummary() << endl;
685 } 728 }
686 } 729 }
687*/ 730*/
688 731
689 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a 732 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a
690 // specific order of events. That means that we have to generate parent items 733 // specific order of events. That means that we have to generate parent items
691 // recursively for proper hierarchical display of Todos. 734 // recursively for proper hierarchical display of Todos.
692 mTodoMap.clear(); 735 mTodoMap.clear();
693 Todo *todo; 736 Todo *todo;
694 todo = todoList.first();// todo; todo = todoList.next()) { 737 todo = todoList.first();// todo; todo = todoList.next()) {
695 while ( todo ) { 738 while ( todo ) {
696 bool next = true; 739 bool next = true;
697 // qDebug("todo %s ", todo->summary().latin1()); 740 // qDebug("todo %s ", todo->summary().latin1());
698 Incidence *incidence = todo->relatedTo(); 741 Incidence *incidence = todo->relatedTo();
699 while ( incidence ) { 742 while ( incidence ) {
700 if ( incidence->typeID() == todoID ) { 743 if ( incidence->typeID() == todoID ) {
701 //qDebug("related %s ",incidence->summary().latin1() ); 744 //qDebug("related %s ",incidence->summary().latin1() );
702 if ( !(todoList.contains ( ((Todo* )incidence ) ) ) && incidence->calEnabled() ) { 745 if ( !(todoList.contains ( ((Todo* )incidence ) ) ) && incidence->calEnabled() ) {
703 //qDebug("related not found "); 746 //qDebug("related not found ");
704 todoList.remove( ); 747 todoList.remove( );
705 todo = todoList.current(); 748 todo = todoList.current();
706 next = false; 749 next = false;
707 incidence = 0; 750 incidence = 0;
708 751
709 } else { 752 } else {
710 //qDebug("related found "); 753 //qDebug("related found ");
711 incidence = incidence->relatedTo(); 754 incidence = incidence->relatedTo();
712 } 755 }
713 } else 756 } else
714 incidence = 0; 757 incidence = 0;
715 } 758 }
716 if ( next ) 759 if ( next )
717 todo = todoList.next(); 760 todo = todoList.next();
718 } 761 }
719 762
720 for(todo = todoList.first(); todo; todo = todoList.next()) { 763 for(todo = todoList.first(); todo; todo = todoList.next()) {
721 if (!mTodoMap.contains(todo) && checkTodo( todo ) ) 764 if (!mTodoMap.contains(todo) && checkTodo( todo ) )
722 { 765 {
723 insertTodoItem(todo); 766 insertTodoItem(todo);
724 } 767 }
725 } 768 }
726 // Restore opened/closed state 769 // Restore opened/closed state
727 mTodoListView->blockSignals( true ); 770 mTodoListView->blockSignals( true );
728 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() ); 771 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() );
729 mTodoListView->blockSignals( false ); 772 mTodoListView->blockSignals( false );
730 resetCurrentItem(); 773 resetCurrentItem();
731 processSelectionChange(); 774 processSelectionChange();
732} 775}
733 776
734void KOTodoView::storeCurrentItem() 777void KOTodoView::storeCurrentItem()
735{ 778{
736 mCurItem = 0; 779 mCurItem = 0;
737 mCurItemRootParent = 0; 780 mCurItemRootParent = 0;
738 mCurItemParent = 0; 781 mCurItemParent = 0;
739 mCurItemAbove = 0; 782 mCurItemAbove = 0;
740 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 783 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
741 if (mActiveItem) { 784 if (mActiveItem) {
742 mCurItem = mActiveItem->todo(); 785 mCurItem = mActiveItem->todo();
743 KOTodoViewItem* activeItemAbove = (KOTodoViewItem*)mActiveItem->itemAbove (); 786 KOTodoViewItem* activeItemAbove = (KOTodoViewItem*)mActiveItem->itemAbove ();
744 if ( activeItemAbove ) 787 if ( activeItemAbove )
745 mCurItemAbove = activeItemAbove->todo(); 788 mCurItemAbove = activeItemAbove->todo();
746 mCurItemRootParent = mCurItem; 789 mCurItemRootParent = mCurItem;
747 mCurItemParent = mCurItemRootParent->relatedTo(); 790 mCurItemParent = mCurItemRootParent->relatedTo();
748 while ( mCurItemRootParent->relatedTo() != 0 ) 791 while ( mCurItemRootParent->relatedTo() != 0 )
749 mCurItemRootParent = mCurItemRootParent->relatedTo(); 792 mCurItemRootParent = mCurItemRootParent->relatedTo();
750 } 793 }
751 mActiveItem = 0; 794 mActiveItem = 0;
752} 795}
753 796
754void KOTodoView::resetCurrentItem() 797void KOTodoView::resetCurrentItem()
755{ 798{
756 mTodoListView->setFocus(); 799 mTodoListView->setFocus();
757 KOTodoViewItem* foundItem = 0; 800 KOTodoViewItem* foundItem = 0;
758 KOTodoViewItem* foundItemRoot = 0; 801 KOTodoViewItem* foundItemRoot = 0;
759 KOTodoViewItem* foundItemParent = 0; 802 KOTodoViewItem* foundItemParent = 0;
760 KOTodoViewItem* foundItemAbove = 0; 803 KOTodoViewItem* foundItemAbove = 0;
761 if ( mTodoListView->firstChild () ) { 804 if ( mTodoListView->firstChild () ) {
762 if ( mCurItem ) { 805 if ( mCurItem ) {
763 KOTodoViewItem* item = (KOTodoViewItem*)mTodoListView->firstChild (); 806 KOTodoViewItem* item = (KOTodoViewItem*)mTodoListView->firstChild ();
764 while ( item ) { 807 while ( item ) {
765 if ( item->todo() == mCurItem ) { 808 if ( item->todo() == mCurItem ) {
766 foundItem = item; 809 foundItem = item;
767 break; 810 break;
768 } else if ( item->todo() == mCurItemAbove ) { 811 } else if ( item->todo() == mCurItemAbove ) {
769 foundItemAbove = item; 812 foundItemAbove = item;
770 813
771 } 814 }
772 if ( item->todo() == mCurItemRootParent ) { 815 if ( item->todo() == mCurItemRootParent ) {
773 foundItemRoot = item; 816 foundItemRoot = item;
774 } 817 }
775 if ( item->todo() == mCurItemParent ) { 818 if ( item->todo() == mCurItemParent ) {
776 foundItemParent = item; 819 foundItemParent = item;
777 } 820 }
778 item = (KOTodoViewItem*)item->itemBelow(); 821 item = (KOTodoViewItem*)item->itemBelow();
779 } 822 }
780 if ( ! foundItem ) { 823 if ( ! foundItem ) {
781 if ( foundItemParent ) { 824 if ( foundItemParent ) {
782 foundItem = foundItemParent; 825 foundItem = foundItemParent;
783 } else { 826 } else {
784 if ( foundItemRoot ) 827 if ( foundItemRoot )
785 foundItem = foundItemRoot; 828 foundItem = foundItemRoot;
786 else 829 else
787 foundItem = foundItemAbove; 830 foundItem = foundItemAbove;
788 } 831 }
789 } 832 }
790 } 833 }
791 if ( foundItem ) { 834 if ( foundItem ) {
792 mTodoListView->setCurrentItem( foundItem ); 835 mTodoListView->setCurrentItem( foundItem );
793 mTodoListView->ensureItemVisible( foundItem ); 836 mTodoListView->ensureItemVisible( foundItem );
794 } else { 837 } else {
795 mTodoListView->setCurrentItem( mTodoListView->firstChild () ); 838 mTodoListView->setCurrentItem( mTodoListView->firstChild () );
796 } 839 }
797 } 840 }
798 mTodoListView->setFocus(); 841 mTodoListView->setFocus();
799} 842}
800//Incidence * mCurItem, *mCurItemRootParent,*mCurItemAbove; 843//Incidence * mCurItem, *mCurItemRootParent,*mCurItemAbove;
801bool KOTodoView::checkTodo( Todo * todo ) 844bool KOTodoView::checkTodo( Todo * todo )
802{ 845{
803 846
804 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() ) 847 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() )
805 return false; 848 return false;
806 if ( !todo->isCompleted() ) { 849 if ( !todo->isCompleted() ) {
807 if ( todo->hasDueDate() && todo->dtDue().date() <= QDate::currentDate() ) 850 if ( todo->hasDueDate() && todo->dtDue().date() <= QDate::currentDate() )
808 return true; 851 return true;
809 } 852 }
810 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) { 853 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) {
811 if ( todo->hasStartDate() ) 854 if ( todo->hasStartDate() )
812 if ( mNavigator->selectedDates().last() < todo->dtStart().date() ) 855 if ( mNavigator->selectedDates().last() < todo->dtStart().date() )
813 return false; 856 return false;
814 if ( todo->hasDueDate() ) 857 if ( todo->hasDueDate() )
815 if ( mNavigator->selectedDates().first() > todo->dtDue().date() ) 858 if ( mNavigator->selectedDates().first() > todo->dtDue().date() )
816 return false; 859 return false;
817 } 860 }
818 return true; 861 return true;
819} 862}
820 863
821void KOTodoView::restoreItemState( QListViewItem *item ) 864void KOTodoView::restoreItemState( QListViewItem *item )
822{ 865{
823 pendingSubtodo = 0; 866 pendingSubtodo = 0;
824 while( item ) { 867 while( item ) {
825 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 868 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
826 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) ); 869 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) );
827 if( item->childCount() > 0 ) restoreItemState( item->firstChild() ); 870 if( item->childCount() > 0 ) restoreItemState( item->firstChild() );
828 item = item->nextSibling(); 871 item = item->nextSibling();
829 } 872 }
830} 873}
831 874
832 875
833QMap<Todo *,KOTodoViewItem *>::ConstIterator 876QMap<Todo *,KOTodoViewItem *>::ConstIterator
834KOTodoView::insertTodoItem(Todo *todo) 877KOTodoView::insertTodoItem(Todo *todo)
835{ 878{
836 879
837 // kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl; 880 // kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl;
838 // TODO: Check, if dynmaic cast is necessary 881 // TODO: Check, if dynmaic cast is necessary
839 882
840 pendingSubtodo = 0; 883 pendingSubtodo = 0;
841 Incidence *incidence = todo->relatedTo(); 884 Incidence *incidence = todo->relatedTo();
842 while ( incidence && !incidence->calEnabled() ) 885 while ( incidence && !incidence->calEnabled() )
843 incidence = incidence->relatedTo(); 886 incidence = incidence->relatedTo();
844 if (incidence && incidence->typeID() == todoID ) { 887 if (incidence && incidence->typeID() == todoID ) {
845 Todo *relatedTodo = static_cast<Todo *>(incidence); 888 Todo *relatedTodo = static_cast<Todo *>(incidence);
846 889
847 // kdDebug() << " has Related" << endl; 890 // kdDebug() << " has Related" << endl;
848 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 891 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
849 itemIterator = mTodoMap.find(relatedTodo); 892 itemIterator = mTodoMap.find(relatedTodo);
850 if (itemIterator == mTodoMap.end()) { 893 if (itemIterator == mTodoMap.end()) {
851 // kdDebug() << " related not yet in list" << endl; 894 // kdDebug() << " related not yet in list" << endl;
852 itemIterator = insertTodoItem (relatedTodo); 895 itemIterator = insertTodoItem (relatedTodo);
853 } 896 }
854 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem 897 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem
855 // and one into the map. Sure finding is more easy but why? -zecke 898 // and one into the map. Sure finding is more easy but why? -zecke
856 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this); 899 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this);
857 return mTodoMap.insert(todo,todoItem); 900 return mTodoMap.insert(todo,todoItem);
858 } else { 901 } else {
859 // kdDebug() << " no Related" << endl; 902 // kdDebug() << " no Related" << endl;
860 // see above -zecke 903 // see above -zecke
861 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 904 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
862 return mTodoMap.insert(todo,todoItem); 905 return mTodoMap.insert(todo,todoItem);
863 } 906 }
864} 907}
865 908
866 909
867void KOTodoView::updateConfig() 910void KOTodoView::updateConfig()
868{ 911{
869 updateView(); 912 updateView();
870 mTodoListView->repaintContents(); 913 mTodoListView->repaintContents();
871} 914}
872 915
873QPtrList<Incidence> KOTodoView::selectedIncidences() 916QPtrList<Incidence> KOTodoView::selectedIncidences()
874{ 917{
875 QPtrList<Incidence> selected; 918 QPtrList<Incidence> selected;
876 919
877 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 920 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
878// if (!item) item = mActiveItem; 921// if (!item) item = mActiveItem;
879 if (item) selected.append(item->todo()); 922 if (item) selected.append(item->todo());
880 923
881 return selected; 924 return selected;
882} 925}
883 926
884QPtrList<Todo> KOTodoView::selectedTodos() 927QPtrList<Todo> KOTodoView::selectedTodos()
885{ 928{
886 QPtrList<Todo> selected; 929 QPtrList<Todo> selected;
887 930
888 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 931 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
889// if (!item) item = mActiveItem; 932// if (!item) item = mActiveItem;
890 if (item) selected.append(item->todo()); 933 if (item) selected.append(item->todo());
891 934
892 return selected; 935 return selected;
893} 936}
894 937
895void KOTodoView::changeEventDisplay(Event *, int) 938void KOTodoView::changeEventDisplay(Event *, int)
896{ 939{
897 updateView(); 940 updateView();
898} 941}
899 942
900void KOTodoView::showDates(const QDate &, const QDate &) 943void KOTodoView::showDates(const QDate &, const QDate &)
901{ 944{
902} 945}
903 946
904void KOTodoView::showEvents(QPtrList<Event>) 947void KOTodoView::showEvents(QPtrList<Event>)
905{ 948{
906 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl; 949 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl;
907} 950}
908 951
909void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd, 952void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd,
910 const QDate &td) 953 const QDate &td)
911{ 954{
912#ifndef KORG_NOPRINTER 955#ifndef KORG_NOPRINTER
913 calPrinter->preview(CalPrinter::Todolist, fd, td); 956 calPrinter->preview(CalPrinter::Todolist, fd, td);
914#endif 957#endif
915} 958}
916 959
917void KOTodoView::editItem(QListViewItem *item ) 960void KOTodoView::editItem(QListViewItem *item )
918{ 961{
919 emit editTodoSignal(((KOTodoViewItem *)item)->todo()); 962 emit editTodoSignal(((KOTodoViewItem *)item)->todo());
920} 963}
921 964
922void KOTodoView::showItem(QListViewItem *item,const QPoint &,int) 965void KOTodoView::showItem(QListViewItem *item,const QPoint &,int)
923{ 966{
924 emit showTodoSignal(((KOTodoViewItem *)item)->todo()); 967 emit showTodoSignal(((KOTodoViewItem *)item)->todo());
925} 968}
926 969
927void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column) 970void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column)
928{ 971{
929 pendingSubtodo = 0; 972 pendingSubtodo = 0;
930 mActiveItem = (KOTodoViewItem *)item; 973 mActiveItem = (KOTodoViewItem *)item;
931 if (item) { 974 if (item) {
932 switch (column){ 975 switch (column){
933 case 1: 976 case 1:
934 mPriorityPopupMenu->popup(QCursor::pos ()); break; 977 mPriorityPopupMenu->popup(QCursor::pos ()); break;
935 case 2: 978 case 2:
936 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break; 979 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break;
937 case 3: 980 case 3:
938 moveTodo(); 981 moveTodo();
939 break; 982 break;
940 case 8: 983 case 8:
941 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break; 984 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break;
942 default: 985 default:
943 mItemPopupMenu->popup(QCursor::pos()); 986 mItemPopupMenu->popup(QCursor::pos());
944 } 987 }
945 } else mPopupMenu->popup(QCursor::pos()); 988 } else mPopupMenu->popup(QCursor::pos());
946} 989}
947void KOTodoView::newTodo() 990void KOTodoView::newTodo()
948{ 991{
949 emit newTodoSignal(); 992 emit newTodoSignal();
950} 993}
951 994
952void KOTodoView::newSubTodo() 995void KOTodoView::newSubTodo()
953{ 996{
954 if (mActiveItem) { 997 if (mActiveItem) {
955 emit newSubTodoSignal(mActiveItem->todo()); 998 emit newSubTodoSignal(mActiveItem->todo());
956 } 999 }
957} 1000}
958void KOTodoView::unparentTodo() 1001void KOTodoView::unparentTodo()
959{ 1002{
960 if (mActiveItem) { 1003 if (mActiveItem) {
961 emit unparentTodoSignal(mActiveItem->todo()); 1004 emit unparentTodoSignal(mActiveItem->todo());
962 } 1005 }
963} 1006}
964 1007
965void KOTodoView::reparentTodo() 1008void KOTodoView::reparentTodo()
966{ 1009{
967 if (mActiveItem) { 1010 if (mActiveItem) {
968 topLevelWidget()->setCaption(i18n("Click on new parent item")); 1011 topLevelWidget()->setCaption(i18n("Click on new parent item"));
969 pendingSubtodo = mActiveItem; 1012 pendingSubtodo = mActiveItem;
970 } 1013 }
971} 1014}
972void KOTodoView::editTodo() 1015void KOTodoView::editTodo()
973{ 1016{
974 if (mActiveItem) { 1017 if (mActiveItem) {
975 emit editTodoSignal(mActiveItem->todo()); 1018 emit editTodoSignal(mActiveItem->todo());
976 } 1019 }
977} 1020}
978void KOTodoView::cloneTodo() 1021void KOTodoView::cloneTodo()
979{ 1022{
980 if (mActiveItem) { 1023 if (mActiveItem) {
981 emit cloneTodoSignal((Incidence*)mActiveItem->todo()); 1024 emit cloneTodoSignal((Incidence*)mActiveItem->todo());
982 } 1025 }
983} 1026}
984void KOTodoView::cancelTodo() 1027void KOTodoView::cancelTodo()
985{ 1028{
986 if (mActiveItem) { 1029 if (mActiveItem) {
987 emit cancelTodoSignal((Incidence*)mActiveItem->todo()); 1030 emit cancelTodoSignal((Incidence*)mActiveItem->todo());
988 } 1031 }
989} 1032}
990void KOTodoView::moveTodo() 1033void KOTodoView::moveTodo()
991{ 1034{
992 if (mActiveItem) { 1035 if (mActiveItem) {
993 emit moveTodoSignal((Incidence*)mActiveItem->todo()); 1036 emit moveTodoSignal((Incidence*)mActiveItem->todo());
994 } 1037 }
995} 1038}
996void KOTodoView::beamTodo() 1039void KOTodoView::beamTodo()
997{ 1040{
998 if (mActiveItem) { 1041 if (mActiveItem) {
999 emit beamTodoSignal((Incidence*)mActiveItem->todo()); 1042 emit beamTodoSignal((Incidence*)mActiveItem->todo());
1000 } 1043 }
1001} 1044}
1002 1045
1003 1046
1004void KOTodoView::showTodo() 1047void KOTodoView::showTodo()
1005{ 1048{
1006 if (mActiveItem) { 1049 if (mActiveItem) {
1007 emit showTodoSignal(mActiveItem->todo()); 1050 emit showTodoSignal(mActiveItem->todo());
1008 } 1051 }
1009} 1052}
1010 1053
1011void KOTodoView::deleteTodo() 1054void KOTodoView::deleteTodo()
1012{ 1055{
1013 if (mActiveItem) { 1056 if (mActiveItem) {
1014 emit deleteTodoSignal(mActiveItem->todo()); 1057 emit deleteTodoSignal(mActiveItem->todo());
1015 } 1058 }
1016} 1059}
1017 1060
1018void KOTodoView::setNewPriority(int index) 1061void KOTodoView::setNewPriority(int index)
1019{ 1062{
1020 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 1063 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
1021 mActiveItem->todo()->setPriority(mPriority[index]); 1064 mActiveItem->todo()->setPriority(mPriority[index]);
1022 mActiveItem->construct(); 1065 mActiveItem->construct();
1023 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED); 1066 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED);
1024 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 1067 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
1025 } 1068 }
1026} 1069}
1027 1070
1028void KOTodoView::setNewPercentage(int index) 1071void KOTodoView::setNewPercentage(int index)
1029{ 1072{
1030 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 1073 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
1031 1074
1032 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) { 1075 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) {
1033 mActiveItem->setOn( true ); 1076 mActiveItem->setOn( true );
1034 return; 1077 return;
1035 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) { 1078 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) {
1036 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent())); 1079 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent()));
1037 if ( par && par->isOn() ) 1080 if ( par && par->isOn() )
1038 par->setOn( false ); 1081 par->setOn( false );
1039 } 1082 }
1040 if (mPercentage[index] == 100) { 1083 if (mPercentage[index] == 100) {
1041 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime()); 1084 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime());
1042 } else { 1085 } else {
1043 mActiveItem->todo()->setCompleted(false); 1086 mActiveItem->todo()->setCompleted(false);
1044 } 1087 }
1045 mActiveItem->todo()->setPercentComplete(mPercentage[index]); 1088 mActiveItem->todo()->setPercentComplete(mPercentage[index]);
1046 mActiveItem->construct(); 1089 mActiveItem->construct();
1047 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED); 1090 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED);
1048 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 1091 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
1049 } 1092 }
1050} 1093}
1051 1094
1052 1095
1053QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem) 1096QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem)
1054{ 1097{
1055 QPopupMenu* tempMenu = new QPopupMenu (this); 1098 QPopupMenu* tempMenu = new QPopupMenu (this);
1056 QStringList checkedCategories = todoItem->todo()->categories (); 1099 QStringList checkedCategories = todoItem->todo()->categories ();
1057 1100
1058 tempMenu->setCheckable (true); 1101 tempMenu->setCheckable (true);
1059 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); 1102 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin ();
1060 it != KOPrefs::instance()->mCustomCategories.end (); 1103 it != KOPrefs::instance()->mCustomCategories.end ();
1061 ++it) { 1104 ++it) {
1062 int index = tempMenu->insertItem (*it); 1105 int index = tempMenu->insertItem (*it);
1063 mCategory[index] = *it; 1106 mCategory[index] = *it;
1064 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true); 1107 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true);
1065 } 1108 }
1066 1109
1067 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int))); 1110 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int)));
1068 return tempMenu; 1111 return tempMenu;
1069 1112
1070 1113
1071} 1114}
1072void KOTodoView::changedCategories(int index) 1115void KOTodoView::changedCategories(int index)
1073{ 1116{
1074 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 1117 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
1075 QStringList categories = mActiveItem->todo()->categories (); 1118 QStringList categories = mActiveItem->todo()->categories ();
1076 QString colcat = categories.first(); 1119 QString colcat = categories.first();
1077 if (categories.find (mCategory[index]) != categories.end ()) 1120 if (categories.find (mCategory[index]) != categories.end ())
1078 categories.remove (mCategory[index]); 1121 categories.remove (mCategory[index]);
1079 else 1122 else
1080 categories.insert (categories.end(), mCategory[index]); 1123 categories.insert (categories.end(), mCategory[index]);
1081 categories.sort (); 1124 categories.sort ();
1082 if ( !colcat.isEmpty() ) { 1125 if ( !colcat.isEmpty() ) {
1083 if ( categories.find ( colcat ) != categories.end () ) { 1126 if ( categories.find ( colcat ) != categories.end () ) {
1084 categories.remove( colcat ); 1127 categories.remove( colcat );
1085 categories.prepend( colcat ); 1128 categories.prepend( colcat );
1086 } 1129 }
1087 } 1130 }
1088 mActiveItem->todo()->setCategories (categories); 1131 mActiveItem->todo()->setCategories (categories);
1089 mActiveItem->construct(); 1132 mActiveItem->construct();
1090 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 1133 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
1091 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED); 1134 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED);
1092 } 1135 }
1093} 1136}
1094void KOTodoView::itemDoubleClicked(QListViewItem *item) 1137void KOTodoView::itemDoubleClicked(QListViewItem *item)
1095{ 1138{
1096 if ( pendingSubtodo != 0 ) { 1139 if ( pendingSubtodo != 0 ) {
1097 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 1140 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
1098 } 1141 }
1099 pendingSubtodo = 0; 1142 pendingSubtodo = 0;
1100 //int row = mTodoListView->header()->sectionAt ( mTodoListView->header()->mapFromGlobal( QCursor::pos()).x() ); 1143 //int row = mTodoListView->header()->sectionAt ( mTodoListView->header()->mapFromGlobal( QCursor::pos()).x() );
1101 int row = mTodoListView->header()->sectionAt ( mTodoListView->viewportToContents(mTodoListView->viewport()->mapFromGlobal( QCursor::pos())) .x() ); 1144 int row = mTodoListView->header()->sectionAt ( mTodoListView->viewportToContents(mTodoListView->viewport()->mapFromGlobal( QCursor::pos())) .x() );
1102 //qDebug("ROW %d ", row); 1145 //qDebug("ROW %d ", row);
1103 if (!item) { 1146 if (!item) {
1104 newTodo(); 1147 newTodo();
1105 return; 1148 return;
1106 } else { 1149 } else {
1107 if ( row == 2 || row == 1 ) { 1150 if ( row == 2 || row == 1 ) {
1108 mActiveItem = (KOTodoViewItem *) item; 1151 mActiveItem = (KOTodoViewItem *) item;
1109 newSubTodo(); 1152 newSubTodo();
1110 return; 1153 return;
1111 } 1154 }
1112 if ( row == 5 || row == 6 ) { 1155 if ( row == 5 || row == 6 ) {
1113 mActiveItem = (KOTodoViewItem *) item; 1156 mActiveItem = (KOTodoViewItem *) item;
1114 toggleRunningItem(); 1157 toggleRunningItem();
1115 return; 1158 return;
1116 } 1159 }
1117 } 1160 }
1118 if ( KOPrefs::instance()->mEditOnDoubleClick ) 1161 if ( KOPrefs::instance()->mEditOnDoubleClick )
1119 editItem( item ); 1162 editItem( item );
1120 else 1163 else
1121 showItem( item , QPoint(), 0 ); 1164 showItem( item , QPoint(), 0 );
1122} 1165}
1123void KOTodoView::toggleRunningItem() 1166void KOTodoView::toggleRunningItem()
1124{ 1167{
1125 // qDebug("KOTodoView::toggleRunning() "); 1168 // qDebug("KOTodoView::toggleRunning() ");
1126 if ( ! mActiveItem ) 1169 if ( ! mActiveItem )
1127 return; 1170 return;
1128 Todo * t = mActiveItem->todo(); 1171 Todo * t = mActiveItem->todo();
1129 if ( t->isRunning() ) { 1172 if ( t->isRunning() ) {
1130#if 0
1131 int result = KMessageBox::warningContinueCancel(this,
1132 i18n("The todo\n%1\nis started.\nDo you want to set\nthe state to stopped?").arg(mActiveItem->text(0).left( 25 ) ),i18n("Todo is started"),i18n("Stop todo"),i18n("Cancel"), true);
1133#endif
1134 1173
1174
1175 KOStopTodoPrefs tp ( t, this );
1176 tp.exec();
1177
1178
1179#if 0
1135 int result = KMessageBox::warningYesNoCancel(this, 1180 int result = KMessageBox::warningYesNoCancel(this,
1136 i18n("The todo\n%1\nis started.\nDo you want to set\nthe state to stopped?").arg(mActiveItem->text(0).left( 25 ) ),i18n("Todo is started"),i18n("Stop"),i18n("Stop+note")); 1181 i18n("The todo\n%1\nis started.\nDo you want to set\nthe state to stopped?").arg(mActiveItem->text(0).left( 25 ) ),i18n("Todo is started"),i18n("Stop"),i18n("Stop+note"));
1137 if (result == KMessageBox::Cancel) return; 1182 if (result == KMessageBox::Cancel) return;
1138 if ( result == KMessageBox::No ) { 1183 if ( result == KMessageBox::No ) {
1139 QString comment = QInputDialog::getText(mActiveItem->text(0).left( 25 ),i18n("Comment for todo:") ); 1184 QString comment = QInputDialog::getText(mActiveItem->text(0).left( 25 ),i18n("Comment for todo:") );
1140 t->setRunningFalse( comment ); 1185 t->setRunningFalse( comment );
1141 } else { 1186 } else {
1142 t->setRunning( false ); 1187 t->setRunning( false );
1143 } 1188 }
1144 mActiveItem->construct(); 1189 mActiveItem->construct();
1190
1191
1192#endif
1145 } else { 1193 } else {
1146 int result = KMessageBox::warningContinueCancel(this, 1194 int result = KMessageBox::warningContinueCancel(this,
1147 i18n("The todo\n%1\nis stopped.\nDo you want to set\nthe state to started?").arg(mActiveItem->text(0).left( 25 ) ),i18n("Todo is stopped"),i18n("Start todo"),i18n("Cancel"), true); 1195 i18n("The todo\n%1\nis stopped.\nDo you want to set\nthe state to started?").arg(mActiveItem->text(0).left( 25 ) ),i18n("Todo is stopped"),i18n("Start todo"),i18n("Cancel"), true);
1148 if (result != KMessageBox::Continue) return; 1196 if (result != KMessageBox::Continue) return;
1149 t->setRunning( true ); 1197 t->setRunning( true );
1150 mActiveItem->construct(); 1198 mActiveItem->construct();
1151 } 1199 }
1152} 1200}
1153 1201
1154void KOTodoView::itemClicked(QListViewItem *item) 1202void KOTodoView::itemClicked(QListViewItem *item)
1155{ 1203{
1156 //qDebug("KOTodoView::itemClicked %d", item); 1204 //qDebug("KOTodoView::itemClicked %d", item);
1157 if (!item) { 1205 if (!item) {
1158 if ( pendingSubtodo != 0 ) { 1206 if ( pendingSubtodo != 0 ) {
1159 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 1207 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
1160 } 1208 }
1161 pendingSubtodo = 0; 1209 pendingSubtodo = 0;
1162 return; 1210 return;
1163 } 1211 }
1164 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1212 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
1165 if ( pendingSubtodo != 0 ) { 1213 if ( pendingSubtodo != 0 ) {
1166 bool allowReparent = true; 1214 bool allowReparent = true;
1167 QListViewItem *par = item; 1215 QListViewItem *par = item;
1168 while ( par ) { 1216 while ( par ) {
1169 if ( par == pendingSubtodo ) { 1217 if ( par == pendingSubtodo ) {
1170 allowReparent = false; 1218 allowReparent = false;
1171 break; 1219 break;
1172 } 1220 }
1173 par = par->parent(); 1221 par = par->parent();
1174 } 1222 }
1175 if ( !allowReparent ) { 1223 if ( !allowReparent ) {
1176 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!")); 1224 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!"));
1177 pendingSubtodo = 0; 1225 pendingSubtodo = 0;
1178 } else { 1226 } else {
1179 Todo* newParent = todoItem->todo(); 1227 Todo* newParent = todoItem->todo();
1180 Todo* newSub = pendingSubtodo->todo(); 1228 Todo* newSub = pendingSubtodo->todo();
1181 pendingSubtodo = 0; 1229 pendingSubtodo = 0;
1182 emit reparentTodoSignal( newParent,newSub ); 1230 emit reparentTodoSignal( newParent,newSub );
1183 return; 1231 return;
1184 } 1232 }
1185 } 1233 }
1186 1234
1187} 1235}
1188 1236
1189void KOTodoView::setDocumentId( const QString &id ) 1237void KOTodoView::setDocumentId( const QString &id )
1190{ 1238{
1191 1239
1192 mDocPrefs->setDoc( id ); 1240 mDocPrefs->setDoc( id );
1193} 1241}
1194 1242
1195void KOTodoView::itemStateChanged( QListViewItem *item ) 1243void KOTodoView::itemStateChanged( QListViewItem *item )
1196{ 1244{
1197 if (!item) return; 1245 if (!item) return;
1198 1246
1199 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1247 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
1200 1248
1201// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl; 1249// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl;
1202 1250
1203 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() ); 1251 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() );
1204} 1252}
1205 1253
1206void KOTodoView::saveLayout(KConfig *config, const QString &group) const 1254void KOTodoView::saveLayout(KConfig *config, const QString &group) const
1207{ 1255{
1208 mTodoListView->saveLayout(config,group); 1256 mTodoListView->saveLayout(config,group);
1209} 1257}
1210 1258
1211void KOTodoView::restoreLayout(KConfig *config, const QString &group) 1259void KOTodoView::restoreLayout(KConfig *config, const QString &group)
1212{ 1260{
1213 mTodoListView->restoreLayout(config,group); 1261 mTodoListView->restoreLayout(config,group);
1214} 1262}
1215 1263
1216void KOTodoView::processSelectionChange() 1264void KOTodoView::processSelectionChange()
1217{ 1265{
1218// kdDebug() << "KOTodoView::processSelectionChange()" << endl; 1266// kdDebug() << "KOTodoView::processSelectionChange()" << endl;
1219 1267
1220 KOTodoViewItem *item = 1268 KOTodoViewItem *item =
1221 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() ); 1269 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() );
1222 1270
1223 if ( !item ) { 1271 if ( !item ) {
1224 emit incidenceSelected( 0 ); 1272 emit incidenceSelected( 0 );
1225 } else { 1273 } else {
1226 emit incidenceSelected( item->todo() ); 1274 emit incidenceSelected( item->todo() );
1227 } 1275 }
1228} 1276}
1229 1277
1230void KOTodoView::modified(bool b) 1278void KOTodoView::modified(bool b)
1231{ 1279{
1232 emit isModified(b); 1280 emit isModified(b);
1233} 1281}
1234void KOTodoView::setTodoModified( Todo* todo ) 1282void KOTodoView::setTodoModified( Todo* todo )
1235{ 1283{
1236 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED ); 1284 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED );
1237} 1285}
1238void KOTodoView::clearSelection() 1286void KOTodoView::clearSelection()
1239{ 1287{
1240 mTodoListView->selectAll( false ); 1288 mTodoListView->selectAll( false );
1241} 1289}
1242void KOTodoView::setAllOpen() 1290void KOTodoView::setAllOpen()
1243{ 1291{
1244 if ( isFlatDisplay ) { 1292 if ( isFlatDisplay ) {
1245 isFlatDisplay = false; 1293 isFlatDisplay = false;
1246 mPopupMenu->setItemChecked( 8,false ); 1294 mPopupMenu->setItemChecked( 8,false );
1247 updateView(); 1295 updateView();
1248 } else { 1296 } else {
1249 storeCurrentItem(); 1297 storeCurrentItem();
1250 } 1298 }
1251 setOpen(mTodoListView->firstChild(), true); 1299 setOpen(mTodoListView->firstChild(), true);
1252 resetCurrentItem(); 1300 resetCurrentItem();
1253} 1301}
1254void KOTodoView::setAllClose() 1302void KOTodoView::setAllClose()
1255{ 1303{
1256 if ( isFlatDisplay ) { 1304 if ( isFlatDisplay ) {
1257 isFlatDisplay = false; 1305 isFlatDisplay = false;
1258 mPopupMenu->setItemChecked( 8,false ); 1306 mPopupMenu->setItemChecked( 8,false );
1259 updateView(); 1307 updateView();
1260 } else { 1308 } else {
1261 storeCurrentItem(); 1309 storeCurrentItem();
1262 } 1310 }
1263 setOpen(mTodoListView->firstChild(), false); 1311 setOpen(mTodoListView->firstChild(), false);
1264 resetCurrentItem(); 1312 resetCurrentItem();
1265} 1313}
1266void KOTodoView::setOpen( QListViewItem* item, bool setOpenI) 1314void KOTodoView::setOpen( QListViewItem* item, bool setOpenI)
1267{ 1315{
1268 1316
1269 while ( item ) { 1317 while ( item ) {
1270 setOpen( item->firstChild(), setOpenI ); 1318 setOpen( item->firstChild(), setOpenI );
1271 item->setOpen( setOpenI ); 1319 item->setOpen( setOpenI );
1272 item = item->nextSibling(); 1320 item = item->nextSibling();
1273 } 1321 }
1274} 1322}
1275 1323
1276void KOTodoView::displayAllFlat() 1324void KOTodoView::displayAllFlat()
1277{ 1325{
1278 pendingSubtodo = 0; 1326 pendingSubtodo = 0;
1279 if ( mBlockUpdate ) { 1327 if ( mBlockUpdate ) {
1280 return; 1328 return;
1281 } 1329 }
1282 mPopupMenu->setItemChecked( 8,true ); 1330 mPopupMenu->setItemChecked( 8,true );
1283 isFlatDisplay = true; 1331 isFlatDisplay = true;
1284 QPtrList<Todo> todoList = calendar()->todos(); 1332 QPtrList<Todo> todoList = calendar()->todos();
1285 mTodoMap.clear(); 1333 mTodoMap.clear();
1286 mTodoListView->clear(); 1334 mTodoListView->clear();
1287 Todo *todo; 1335 Todo *todo;
1288 for(todo = todoList.first(); todo; todo = todoList.next()) { 1336 for(todo = todoList.first(); todo; todo = todoList.next()) {
1289 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 1337 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
1290 mTodoMap.insert(todo,todoItem); 1338 mTodoMap.insert(todo,todoItem);
1291 } 1339 }
1292 mTodoListView->setFocus(); 1340 mTodoListView->setFocus();
1293 processSelectionChange(); 1341 processSelectionChange();
1294} 1342}
1295 1343
1296void KOTodoView::setAllFlat() 1344void KOTodoView::setAllFlat()
1297{ 1345{
1298 if ( isFlatDisplay ) { 1346 if ( isFlatDisplay ) {
1299 isFlatDisplay = false; 1347 isFlatDisplay = false;
1300 mPopupMenu->setItemChecked( 8,false ); 1348 mPopupMenu->setItemChecked( 8,false );
1301 updateView(); 1349 updateView();
1302 return; 1350 return;
1303 } 1351 }
1304 storeCurrentItem(); 1352 storeCurrentItem();
1305 displayAllFlat(); 1353 displayAllFlat();
1306 resetCurrentItem(); 1354 resetCurrentItem();
1307} 1355}
1308 1356
1309void KOTodoView::purgeCompleted() 1357void KOTodoView::purgeCompleted()
1310{ 1358{
1311 emit purgeCompletedSignal(); 1359 emit purgeCompletedSignal();
1312 1360
1313} 1361}
1314void KOTodoView::toggleQuickTodo() 1362void KOTodoView::toggleQuickTodo()
1315{ 1363{
1316 if ( mQuickAdd->isVisible() ) { 1364 if ( mQuickAdd->isVisible() ) {
1317 mQuickAdd->hide(); 1365 mQuickAdd->hide();
1318 KOPrefs::instance()->mEnableQuickTodo = false; 1366 KOPrefs::instance()->mEnableQuickTodo = false;
1319 } 1367 }
1320 else { 1368 else {
1321 mQuickAdd->show(); 1369 mQuickAdd->show();
1322 KOPrefs::instance()->mEnableQuickTodo = true; 1370 KOPrefs::instance()->mEnableQuickTodo = true;
1323 } 1371 }
1324 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 1372 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
1325 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 1373 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
1326} 1374}
1327 1375
1328void KOTodoView::toggleRunning() 1376void KOTodoView::toggleRunning()
1329{ 1377{
1330 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos; 1378 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos;
1331 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 1379 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
1332 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 1380 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
1333 updateView(); 1381 updateView();
1334} 1382}
1335 1383
1336void KOTodoView::toggleCompleted() 1384void KOTodoView::toggleCompleted()
1337{ 1385{
1338 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo; 1386 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo;
1339 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 1387 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
1340 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 1388 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
1341 updateView(); 1389 updateView();
1342} 1390}
1343 1391
1344void KOTodoView::addQuickTodo() 1392void KOTodoView::addQuickTodo()
1345{ 1393{
1346 Todo *todo = new Todo(); 1394 Todo *todo = new Todo();
1347 todo->setSummary(mQuickAdd->text()); 1395 todo->setSummary(mQuickAdd->text());
1348 todo->setOrganizer(KOPrefs::instance()->email()); 1396 todo->setOrganizer(KOPrefs::instance()->email());
1349 CalFilter * cf = mCalendar->filter(); 1397 CalFilter * cf = mCalendar->filter();
1350 if ( cf ) { 1398 if ( cf ) {
1351 if ( cf->isEnabled()&& cf->showCategories()) { 1399 if ( cf->isEnabled()&& cf->showCategories()) {
1352 todo->setCategories(cf->categoryList()); 1400 todo->setCategories(cf->categoryList());
1353 } 1401 }
1354 if ( cf->isEnabled() ) 1402 if ( cf->isEnabled() )
1355 todo->setSecrecy( cf->getSecrecy()); 1403 todo->setSecrecy( cf->getSecrecy());
1356 } 1404 }
1357 mCalendar->addTodo(todo); 1405 mCalendar->addTodo(todo);
1358 mQuickAdd->setText(""); 1406 mQuickAdd->setText("");
1359 todoModified (todo, KOGlobals::EVENTADDED ); 1407 todoModified (todo, KOGlobals::EVENTADDED );
1360 updateView(); 1408 updateView();
1361} 1409}
1362 1410
1363void KOTodoView::keyPressEvent ( QKeyEvent * e ) 1411void KOTodoView::keyPressEvent ( QKeyEvent * e )
1364{ 1412{
1365 // e->ignore(); 1413 // e->ignore();
1366 //return; 1414 //return;
1367 //qDebug("KOTodoView::keyPressEvent "); 1415 //qDebug("KOTodoView::keyPressEvent ");
1368 switch ( e->key() ) { 1416 switch ( e->key() ) {
1369 case Qt::Key_Down: 1417 case Qt::Key_Down:
1370 case Qt::Key_Up: 1418 case Qt::Key_Up:
1371 QWidget::keyPressEvent ( e ); 1419 QWidget::keyPressEvent ( e );
1372 break; 1420 break;
1373 1421
1374 case Qt::Key_Q: 1422 case Qt::Key_Q:
1375 toggleQuickTodo(); 1423 toggleQuickTodo();
1376 break; 1424 break;
1377 case Qt::Key_U: 1425 case Qt::Key_U:
1378 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1426 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1379 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1427 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1380 unparentTodo(); 1428 unparentTodo();
1381 e->accept(); 1429 e->accept();
1382 } else 1430 } else
1383 e->ignore(); 1431 e->ignore();
1384 break; 1432 break;
1385 case Qt::Key_S: 1433 case Qt::Key_S:
1386 if ( e->state() == Qt::ControlButton ) { 1434 if ( e->state() == Qt::ControlButton ) {
1387 e->ignore(); 1435 e->ignore();
1388 break; 1436 break;
1389 } 1437 }
1390 if ( e->state() == Qt::ShiftButton ) { 1438 if ( e->state() == Qt::ShiftButton ) {
1391 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1439 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1392 reparentTodo(); 1440 reparentTodo();
1393 e->accept(); 1441 e->accept();
1394 } else 1442 } else
1395 e->ignore(); 1443 e->ignore();
1396 break; 1444 break;
1397 case Qt::Key_P: 1445 case Qt::Key_P:
1398 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1446 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1399 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1447 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1400 if ( pendingSubtodo ) 1448 if ( pendingSubtodo )
1401 itemClicked(mActiveItem); 1449 itemClicked(mActiveItem);
1402 e->accept(); 1450 e->accept();
1403 } else 1451 } else
1404 e->ignore(); 1452 e->ignore();
1405 break; 1453 break;
1406 case Qt::Key_Escape: 1454 case Qt::Key_Escape:
1407 if ( pendingSubtodo ) { 1455 if ( pendingSubtodo ) {
1408 itemClicked(0); 1456 itemClicked(0);
1409 e->accept(); 1457 e->accept();
1410 } else 1458 } else
1411 e->ignore(); 1459 e->ignore();
1412 break; 1460 break;
1413 default: 1461 default:
1414 e->ignore(); 1462 e->ignore();
1415 } 1463 }
1416 1464
1417 if ( true ) { 1465 if ( true ) {
1418 if ( e->key() == Qt::Key_I ) { 1466 if ( e->key() == Qt::Key_I ) {
1419 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem(); 1467 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem();
1420 if ( cn ) { 1468 if ( cn ) {
1421 mActiveItem = cn; 1469 mActiveItem = cn;
1422 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 1470 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
1423 if ( ci ){ 1471 if ( ci ){
1424 showTodo(); 1472 showTodo();
1425 cn = (KOTodoViewItem*)cn->itemBelow(); 1473 cn = (KOTodoViewItem*)cn->itemBelow();
1426 if ( cn ) { 1474 if ( cn ) {
1427 mTodoListView->setCurrentItem ( cn ); 1475 mTodoListView->setCurrentItem ( cn );
1428 mTodoListView->ensureItemVisible ( cn ); 1476 mTodoListView->ensureItemVisible ( cn );
1429 } 1477 }
1430 1478
1431 } 1479 }
1432 } 1480 }
1433 e->accept(); 1481 e->accept();
1434 1482
1435 } 1483 }
1436 1484
1437 } 1485 }
1438 1486
1439} 1487}
1440void KOTodoView::updateTodo( Todo * t, int type ) 1488void KOTodoView::updateTodo( Todo * t, int type )
1441{ 1489{
1442 if ( mBlockUpdate) 1490 if ( mBlockUpdate)
1443 return; 1491 return;
1444 1492
1445 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 1493 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
1446 itemIterator = mTodoMap.find(t); 1494 itemIterator = mTodoMap.find(t);
1447 if (itemIterator != mTodoMap.end()) { 1495 if (itemIterator != mTodoMap.end()) {
1448 (*itemIterator)->construct(); 1496 (*itemIterator)->construct();
1449 } else { 1497 } else {
1450 if ( type == KOGlobals::EVENTADDED ) { 1498 if ( type == KOGlobals::EVENTADDED ) {
1451 insertTodoItem( t ); 1499 insertTodoItem( t );
1452 } 1500 }
1453 } 1501 }
1454 1502
1455} 1503}
1456 1504
1457void KOTodoView::todoModified(Todo * t , int p ) 1505void KOTodoView::todoModified(Todo * t , int p )
1458{ 1506{
1459 mBlockUpdate = true; 1507 mBlockUpdate = true;
1460 emit todoModifiedSignal ( t, p ); 1508 emit todoModifiedSignal ( t, p );
1461 mBlockUpdate = false; 1509 mBlockUpdate = false;
1462} 1510}
diff --git a/korganizer/kotodoview.h b/korganizer/kotodoview.h
index 1ffc34a..ceabdba 100644
--- a/korganizer/kotodoview.h
+++ b/korganizer/kotodoview.h
@@ -1,265 +1,283 @@
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#ifndef KOTODOVIEW_H 23#ifndef KOTODOVIEW_H
24#define KOTODOVIEW_H 24#define KOTODOVIEW_H
25 25
26#include <qfont.h> 26#include <qfont.h>
27#include <qfontmetrics.h> 27#include <qfontmetrics.h>
28#include <qlineedit.h> 28#include <qlineedit.h>
29#include <qptrlist.h> 29#include <qptrlist.h>
30#include <qstrlist.h> 30#include <qstrlist.h>
31#include <qlistbox.h> 31#include <qlistbox.h>
32#include <qpopupmenu.h> 32#include <qpopupmenu.h>
33#include <qlabel.h> 33#include <qlabel.h>
34#include <qmap.h> 34#include <qmap.h>
35#include <qdialog.h>
36#include <qlabel.h>
35#include <qlistview.h> 37#include <qlistview.h>
36#include <klistview.h> 38#include <klistview.h>
37 39
38#include <libkcal/calendar.h> 40#include <libkcal/calendar.h>
39#include <libkcal/todo.h> 41#include <libkcal/todo.h>
40 42
41#include <korganizer/baseview.h> 43#include <korganizer/baseview.h>
42 44
43#include "kotodoviewitem.h" 45#include "kotodoviewitem.h"
44#include "koprefs.h" 46#include "koprefs.h"
45#include "koglobals.h" 47#include "koglobals.h"
46#include "datenavigator.h" 48#include "datenavigator.h"
47 49
48class QDragEnterEvent; 50class QDragEnterEvent;
49class QDragMoveEvent; 51class QDragMoveEvent;
50class QDragLeaveEvent; 52class QDragLeaveEvent;
51class QDropEvent; 53class QDropEvent;
52class KOTodoViewWhatsThis; 54class KOTodoViewWhatsThis;
53 55
54class DocPrefs; 56class DocPrefs;
55 57
58
59class KOStopTodoPrefs : public QDialog
60{
61 Q_OBJECT
62 public:
63 KOStopTodoPrefs( Todo* todo, QWidget *parent=0, const char *name=0 ) ;
64
65
66private slots:
67 void doNotSave();
68 void accept();
69private:
70 Todo* mTodo;
71
72};
73
56class KOTodoListView : public KListView 74class KOTodoListView : public KListView
57{ 75{
58 Q_OBJECT 76 Q_OBJECT
59 public: 77 public:
60 KOTodoListView(Calendar *,QWidget *parent=0,const char *name=0); 78 KOTodoListView(Calendar *,QWidget *parent=0,const char *name=0);
61 virtual ~KOTodoListView() {} 79 virtual ~KOTodoListView() {}
62 80
63 signals: 81 signals:
64 void paintNeeded(); 82 void paintNeeded();
65 void todoDropped(Todo *, int); 83 void todoDropped(Todo *, int);
66 void double_Clicked(QListViewItem *item); 84 void double_Clicked(QListViewItem *item);
67 void reparentTodoSignal( Todo *,Todo * ); 85 void reparentTodoSignal( Todo *,Todo * );
68 void unparentTodoSignal(Todo *); 86 void unparentTodoSignal(Todo *);
69 void deleteTodo( Todo * ); 87 void deleteTodo( Todo * );
70 protected: 88 protected:
71 void wheelEvent (QWheelEvent *e); 89 void wheelEvent (QWheelEvent *e);
72 void contentsDragEnterEvent(QDragEnterEvent *); 90 void contentsDragEnterEvent(QDragEnterEvent *);
73 void contentsDragMoveEvent(QDragMoveEvent *); 91 void contentsDragMoveEvent(QDragMoveEvent *);
74 void contentsDragLeaveEvent(QDragLeaveEvent *); 92 void contentsDragLeaveEvent(QDragLeaveEvent *);
75 void contentsDropEvent(QDropEvent *); 93 void contentsDropEvent(QDropEvent *);
76 94
77 void contentsMousePressEvent(QMouseEvent *); 95 void contentsMousePressEvent(QMouseEvent *);
78 void contentsMouseMoveEvent(QMouseEvent *); 96 void contentsMouseMoveEvent(QMouseEvent *);
79 void contentsMouseReleaseEvent(QMouseEvent *); 97 void contentsMouseReleaseEvent(QMouseEvent *);
80 void contentsMouseDoubleClickEvent(QMouseEvent *); 98 void contentsMouseDoubleClickEvent(QMouseEvent *);
81 99
82 private: 100 private:
83 void paintEvent(QPaintEvent * pevent); 101 void paintEvent(QPaintEvent * pevent);
84 bool internalDrop; 102 bool internalDrop;
85 QString mName; 103 QString mName;
86 Calendar *mCalendar; 104 Calendar *mCalendar;
87 QPoint mPressPos; 105 QPoint mPressPos;
88 bool mMousePressed; 106 bool mMousePressed;
89 QListViewItem *mOldCurrent; 107 QListViewItem *mOldCurrent;
90 bool mFlagKeyPressed; 108 bool mFlagKeyPressed;
91 void keyPressEvent ( QKeyEvent * ) ; 109 void keyPressEvent ( QKeyEvent * ) ;
92 void keyReleaseEvent ( QKeyEvent * ) ; 110 void keyReleaseEvent ( QKeyEvent * ) ;
93}; 111};
94 112
95 113
96/** 114/**
97 This is the line-edit on top of the todoview for fast addition of new todos 115 This is the line-edit on top of the todoview for fast addition of new todos
98*/ 116*/
99class KOQuickTodo : public QLineEdit 117class KOQuickTodo : public QLineEdit
100{ 118{
101 public: 119 public:
102 KOQuickTodo(QWidget *parent=0); 120 KOQuickTodo(QWidget *parent=0);
103 protected: 121 protected:
104 void focusInEvent(QFocusEvent *ev); 122 void focusInEvent(QFocusEvent *ev);
105 void focusOutEvent(QFocusEvent *ev); 123 void focusOutEvent(QFocusEvent *ev);
106}; 124};
107 125
108 126
109/** 127/**
110 This class provides a multi-column list view of todo events. 128 This class provides a multi-column list view of todo events.
111 129
112 @short multi-column list view of todo events. 130 @short multi-column list view of todo events.
113 @author Cornelius Schumacher <schumacher@kde.org> 131 @author Cornelius Schumacher <schumacher@kde.org>
114*/ 132*/
115class KOTodoView : public KOrg::BaseView 133class KOTodoView : public KOrg::BaseView
116{ 134{
117 Q_OBJECT 135 Q_OBJECT
118 public: 136 public:
119 KOTodoView(Calendar *, QWidget* parent=0, const char* name=0 ); 137 KOTodoView(Calendar *, QWidget* parent=0, const char* name=0 );
120 ~KOTodoView(); 138 ~KOTodoView();
121 139
122 QPtrList<Incidence> selectedIncidences(); 140 QPtrList<Incidence> selectedIncidences();
123 QPtrList<Todo> selectedTodos(); 141 QPtrList<Todo> selectedTodos();
124 142
125 DateList selectedDates() 143 DateList selectedDates()
126 {DateList q; 144 {DateList q;
127 return q;} 145 return q;}
128 146
129 /** Return number of shown dates. TodoView does not show dates, */ 147 /** Return number of shown dates. TodoView does not show dates, */
130 int currentDateCount() { return 0; } 148 int currentDateCount() { return 0; }
131 149
132 void printPreview(CalPrinter *calPrinter, const QDate &fd, const QDate &td); 150 void printPreview(CalPrinter *calPrinter, const QDate &fd, const QDate &td);
133 151
134 void setDocumentId( const QString & ); 152 void setDocumentId( const QString & );
135 153
136 void saveLayout(KConfig *config, const QString &group) const; 154 void saveLayout(KConfig *config, const QString &group) const;
137 void restoreLayout(KConfig *config, const QString &group); 155 void restoreLayout(KConfig *config, const QString &group);
138 /** Create a popup menu to set categories */ 156 /** Create a popup menu to set categories */
139 QPopupMenu *getCategoryPopupMenu (KOTodoViewItem *todoItem); 157 QPopupMenu *getCategoryPopupMenu (KOTodoViewItem *todoItem);
140 void setNavigator( DateNavigator* nav ) {mNavigator = nav;} 158 void setNavigator( DateNavigator* nav ) {mNavigator = nav;}
141 QString getWhatsThisText(QPoint p); 159 QString getWhatsThisText(QPoint p);
142 void clearList() {mTodoListView->clear(); } 160 void clearList() {mTodoListView->clear(); }
143 161
144 public slots: 162 public slots:
145 void updateView(); 163 void updateView();
146 void updateConfig(); 164 void updateConfig();
147 165
148 void changeEventDisplay(Event *, int); 166 void changeEventDisplay(Event *, int);
149 167
150 void showDates(const QDate &start, const QDate &end); 168 void showDates(const QDate &start, const QDate &end);
151 void showEvents(QPtrList<Event> eventList); 169 void showEvents(QPtrList<Event> eventList);
152 170
153 void clearSelection(); 171 void clearSelection();
154 void jumpToDate (); 172 void jumpToDate ();
155 173
156 void editItem(QListViewItem *item); 174 void editItem(QListViewItem *item);
157 void showItem(QListViewItem *item,const QPoint &,int); 175 void showItem(QListViewItem *item,const QPoint &,int);
158 void popupMenu(QListViewItem *item,const QPoint &,int); 176 void popupMenu(QListViewItem *item,const QPoint &,int);
159 void newTodo(); 177 void newTodo();
160 void newSubTodo(); 178 void newSubTodo();
161 void unparentTodo(); 179 void unparentTodo();
162 void reparentTodo(); 180 void reparentTodo();
163 void showTodo(); 181 void showTodo();
164 void editTodo(); 182 void editTodo();
165 void cloneTodo(); 183 void cloneTodo();
166 void cancelTodo(); 184 void cancelTodo();
167 void moveTodo(); 185 void moveTodo();
168 void beamTodo(); 186 void beamTodo();
169 void deleteTodo(); 187 void deleteTodo();
170 188
171 void setNewPriority(int); 189 void setNewPriority(int);
172 void setNewPercentage(int); 190 void setNewPercentage(int);
173 void changedCategories(int); 191 void changedCategories(int);
174 192
175 void setAllOpen(); 193 void setAllOpen();
176 void setAllClose(); 194 void setAllClose();
177 void setAllFlat(); 195 void setAllFlat();
178 void displayAllFlat(); 196 void displayAllFlat();
179 197
180 void purgeCompleted(); 198 void purgeCompleted();
181 void toggleCompleted(); 199 void toggleCompleted();
182 void toggleRunning(); 200 void toggleRunning();
183 void toggleQuickTodo(); 201 void toggleQuickTodo();
184 void updateTodo( Todo *, int ); 202 void updateTodo( Todo *, int );
185 203
186 void itemClicked(QListViewItem *); 204 void itemClicked(QListViewItem *);
187 void itemStateChanged(QListViewItem *); 205 void itemStateChanged(QListViewItem *);
188 void modified(bool); 206 void modified(bool);
189 void itemDoubleClicked(QListViewItem *item); 207 void itemDoubleClicked(QListViewItem *item);
190 208
191 signals: 209 signals:
192 void newTodoSignal(); 210 void newTodoSignal();
193 void newSubTodoSignal(Todo *); 211 void newSubTodoSignal(Todo *);
194 void unparentTodoSignal(Todo *); 212 void unparentTodoSignal(Todo *);
195 void reparentTodoSignal( Todo *,Todo * ); 213 void reparentTodoSignal( Todo *,Todo * );
196 void showTodoSignal(Todo *); 214 void showTodoSignal(Todo *);
197 215
198 void editTodoSignal(Todo *); 216 void editTodoSignal(Todo *);
199 void deleteTodoSignal(Todo *); 217 void deleteTodoSignal(Todo *);
200 void todoModifiedSignal (Todo *, int); 218 void todoModifiedSignal (Todo *, int);
201 219
202 void isModified(bool); 220 void isModified(bool);
203 void cloneTodoSignal( Incidence * ); 221 void cloneTodoSignal( Incidence * );
204 void cancelTodoSignal( Incidence * ); 222 void cancelTodoSignal( Incidence * );
205 void moveTodoSignal( Incidence * ); 223 void moveTodoSignal( Incidence * );
206 void beamTodoSignal( Incidence * ); 224 void beamTodoSignal( Incidence * );
207 void purgeCompletedSignal(); 225 void purgeCompletedSignal();
208 226
209 protected slots: 227 protected slots:
210 void toggleRunningItem(); 228 void toggleRunningItem();
211 void paintNeeded(); 229 void paintNeeded();
212 void processSelectionChange(); 230 void processSelectionChange();
213 void addQuickTodo(); 231 void addQuickTodo();
214 void setTodoModified( Todo* ); 232 void setTodoModified( Todo* );
215 void todoModified(Todo *, int ); 233 void todoModified(Todo *, int );
216 234
217 private: 235 private:
218 /* 236 /*
219 * the TodoEditor approach is rather unscaling in the long 237 * the TodoEditor approach is rather unscaling in the long
220 * run. 238 * run.
221 * Korganizer keeps it in memory and we need to update 239 * Korganizer keeps it in memory and we need to update
222 * 1. make KOTodoViewItem a QObject again? 240 * 1. make KOTodoViewItem a QObject again?
223 * 2. add a public method for setting one todo modified? 241 * 2. add a public method for setting one todo modified?
224 * 3. add a private method for setting a todo modified + friend here? 242 * 3. add a private method for setting a todo modified + friend here?
225 * -- zecke 2002-07-08 243 * -- zecke 2002-07-08
226 */ 244 */
227 KOTodoViewWhatsThis* mKOTodoViewWhatsThis; 245 KOTodoViewWhatsThis* mKOTodoViewWhatsThis;
228 friend class KOTodoListView; 246 friend class KOTodoListView;
229 void paintEvent(QPaintEvent * pevent); 247 void paintEvent(QPaintEvent * pevent);
230 bool mPendingUpdateBeforeRepaint; 248 bool mPendingUpdateBeforeRepaint;
231 friend class KOTodoViewItem; 249 friend class KOTodoViewItem;
232 QMap<Todo *,KOTodoViewItem *>::ConstIterator insertTodoItem(Todo *todo); 250 QMap<Todo *,KOTodoViewItem *>::ConstIterator insertTodoItem(Todo *todo);
233 void restoreItemState( QListViewItem * ); 251 void restoreItemState( QListViewItem * );
234 252
235 bool checkTodo( Todo * ); 253 bool checkTodo( Todo * );
236 bool isFlatDisplay; 254 bool isFlatDisplay;
237 void setOpen( QListViewItem*, bool setOpen); 255 void setOpen( QListViewItem*, bool setOpen);
238 KOTodoListView *mTodoListView; 256 KOTodoListView *mTodoListView;
239 QPopupMenu *mItemPopupMenu; 257 QPopupMenu *mItemPopupMenu;
240 QPopupMenu *mPopupMenu; 258 QPopupMenu *mPopupMenu;
241 QPopupMenu *mPriorityPopupMenu; 259 QPopupMenu *mPriorityPopupMenu;
242 QPopupMenu *mPercentageCompletedPopupMenu; 260 QPopupMenu *mPercentageCompletedPopupMenu;
243 QPopupMenu *mCategoryPopupMenu; 261 QPopupMenu *mCategoryPopupMenu;
244 262
245 QMap<int, int> mPercentage; 263 QMap<int, int> mPercentage;
246 QMap<int, int> mPriority; 264 QMap<int, int> mPriority;
247 QMap<int, QString> mCategory; 265 QMap<int, QString> mCategory;
248 KOTodoViewItem *mActiveItem; 266 KOTodoViewItem *mActiveItem;
249 267
250 QMap<Todo *,KOTodoViewItem *> mTodoMap; 268 QMap<Todo *,KOTodoViewItem *> mTodoMap;
251 QString mName; 269 QString mName;
252 270
253 DocPrefs *mDocPrefs; 271 DocPrefs *mDocPrefs;
254 QString mCurrentDoc; 272 QString mCurrentDoc;
255 KOQuickTodo *mQuickAdd; 273 KOQuickTodo *mQuickAdd;
256 bool mBlockUpdate; 274 bool mBlockUpdate;
257 void keyPressEvent ( QKeyEvent * ) ; 275 void keyPressEvent ( QKeyEvent * ) ;
258 KOTodoViewItem * pendingSubtodo; 276 KOTodoViewItem * pendingSubtodo;
259 DateNavigator* mNavigator; 277 DateNavigator* mNavigator;
260 void storeCurrentItem(); 278 void storeCurrentItem();
261 void resetCurrentItem(); 279 void resetCurrentItem();
262 Incidence * mCurItem, *mCurItemRootParent, *mCurItemParent,*mCurItemAbove; 280 Incidence * mCurItem, *mCurItemRootParent, *mCurItemParent,*mCurItemAbove;
263}; 281};
264 282
265#endif 283#endif
diff --git a/korganizer/kotodoviewitem.cpp b/korganizer/kotodoviewitem.cpp
index f62aab8..0cf6e4c 100644
--- a/korganizer/kotodoviewitem.cpp
+++ b/korganizer/kotodoviewitem.cpp
@@ -1,526 +1,526 @@
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 19
20#include <klocale.h> 20#include <klocale.h>
21#include <kdebug.h> 21#include <kdebug.h>
22#include <qapp.h> 22#include <qapp.h>
23#include <kglobal.h> 23#include <kglobal.h>
24 24
25#include <kiconloader.h> 25#include <kiconloader.h>
26#include "kotodoviewitem.h" 26#include "kotodoviewitem.h"
27#include "kotodoview.h" 27#include "kotodoview.h"
28#include "koprefs.h" 28#include "koprefs.h"
29 29
30KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo) 30KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo)
31 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) 31 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
32{ 32{
33 construct(); 33 construct();
34} 34}
35 35
36KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo ) 36KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo )
37 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) 37 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
38{ 38{
39 construct(); 39 construct();
40} 40}
41 41
42QString KOTodoViewItem::key(int column,bool) const 42QString KOTodoViewItem::key(int column,bool) const
43{ 43{
44 QMap<int,QString>::ConstIterator it = mKeyMap.find(column); 44 QMap<int,QString>::ConstIterator it = mKeyMap.find(column);
45 if (it == mKeyMap.end()) { 45 if (it == mKeyMap.end()) {
46 return text(column).lower(); 46 return text(column).lower();
47 } else { 47 } else {
48 return *it; 48 return *it;
49 } 49 }
50} 50}
51 51
52void KOTodoViewItem:: setup() 52void KOTodoViewItem:: setup()
53{ 53{
54 54
55 int h = 20; 55 int h = 20;
56 if ( listView () ) { 56 if ( listView () ) {
57 QFontMetrics fm ( listView ()->font () ); 57 QFontMetrics fm ( listView ()->font () );
58 h = fm.height(); 58 h = fm.height();
59 } 59 }
60 setHeight( h ); 60 setHeight( h );
61 61
62} 62}
63void KOTodoViewItem::setSortKey(int column,const QString &key) 63void KOTodoViewItem::setSortKey(int column,const QString &key)
64{ 64{
65 mKeyMap.insert(column,key); 65 mKeyMap.insert(column,key);
66} 66}
67 67
68#if QT_VERSION >= 0x030000 68#if QT_VERSION >= 0x030000
69void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w, 69void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w,
70 int y,int h) 70 int y,int h)
71{ 71{
72 QListViewItem::paintBranches(p,cg,w,y,h); 72 QListViewItem::paintBranches(p,cg,w,y,h);
73} 73}
74#else 74#else
75#endif 75#endif
76 76
77void KOTodoViewItem::construct() 77void KOTodoViewItem::construct()
78{ 78{
79 // qDebug("KOTodoViewItem::construct() "); 79 // qDebug("KOTodoViewItem::construct() ");
80 m_init = true; 80 m_init = true;
81 QString keyd = "=="; 81 QString keyd = "==";
82 QString keyt = "=="; 82 QString keyt = "==";
83 QString skeyd = "=="; 83 QString skeyd = "==";
84 QString skeyt = "=="; 84 QString skeyt = "==";
85 85
86 setOn(mTodo->isCompleted()); 86 setOn(mTodo->isCompleted());
87 setText(0,mTodo->summary()); 87 setText(0,mTodo->summary());
88 setText(1,QString::number(mTodo->priority())); 88 setText(1,QString::number(mTodo->priority()));
89 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); 89 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
90 if (mTodo->percentComplete()<100) { 90 if (mTodo->percentComplete()<100) {
91 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 91 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
92 else setSortKey(2,QString::number(mTodo->percentComplete())); 92 else setSortKey(2,QString::number(mTodo->percentComplete()));
93 } 93 }
94 else { 94 else {
95 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 95 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
96 else setSortKey(2,QString::number(99)); 96 else setSortKey(2,QString::number(99));
97 } 97 }
98 if (mTodo->hasDueDate()) { 98 if (mTodo->hasDueDate()) {
99 setText(3, mTodo->dtDueDateStr()); 99 setText(3, mTodo->dtDueDateStr());
100 QDate d = mTodo->dtDue().date(); 100 QDate d = mTodo->dtDue().date();
101 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 101 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
102 // setSortKey(3,keyd); 102 // setSortKey(3,keyd);
103 if (mTodo->doesFloat()) { 103 if (mTodo->doesFloat()) {
104 setText(4,""); 104 setText(4,"");
105 } 105 }
106 else { 106 else {
107 setText(4,mTodo->dtDueTimeStr()); 107 setText(4,mTodo->dtDueTimeStr());
108 QTime t = mTodo->dtDue().time(); 108 QTime t = mTodo->dtDue().time();
109 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 109 keyt.sprintf("%02d%02d",t.hour(),t.minute());
110 //setSortKey(4,keyt); 110 //setSortKey(4,keyt);
111 } 111 }
112 } else { 112 } else {
113 setText(3,""); 113 setText(3,"");
114 setText(4,""); 114 setText(4,"");
115 } 115 }
116 setSortKey(3,keyd); 116 setSortKey(3,keyd);
117 setSortKey(4,keyt); 117 setSortKey(4,keyt);
118 118
119 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt); 119 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt);
120 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 120 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
121 121
122 122
123 123
124 keyd = ""; 124 keyd = "";
125 keyt = ""; 125 keyt = "";
126 126
127 if (mTodo->isRunning() ) { 127 if (mTodo->isRunning() ) {
128 QDate d = mTodo->runStart().date(); 128 QDate d = mTodo->runStart().date();
129 QTime t = mTodo->runStart().time(); 129 QTime t = mTodo->runStart().time();
130 skeyt.sprintf("%02d%02d",t.hour(),t.minute()); 130 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
131 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 131 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
132 keyd = KGlobal::locale()->formatDate( d , true); 132 keyd = KGlobal::locale()->formatDate( d , true);
133 keyt = KGlobal::locale()->formatTime( t ); 133 keyt = KGlobal::locale()->formatTime( t );
134 134
135 } else { 135 } else {
136 136
137 if (mTodo->hasStartDate()) { 137 if (mTodo->hasStartDate()) {
138 keyd = mTodo->dtStartDateStr(); 138 keyd = mTodo->dtStartDateStr();
139 QDate d = mTodo->dtStart().date(); 139 QDate d = mTodo->dtStart().date();
140 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 140 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
141 141
142 if ( !mTodo->doesFloat()) { 142 if ( !mTodo->doesFloat()) {
143 keyt = mTodo->dtStartTimeStr(); 143 keyt = mTodo->dtStartTimeStr();
144 QTime t = mTodo->dtStart().time(); 144 QTime t = mTodo->dtStart().time();
145 skeyt.sprintf("%02d%02d",t.hour(),t.minute()); 145 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
146 146
147 } 147 }
148 148
149 } 149 }
150 } 150 }
151 setText(5,keyd); 151 setText(5,keyd);
152 setText(6,keyt); 152 setText(6,keyt);
153 setSortKey(5,skeyd); 153 setSortKey(5,skeyd);
154 setSortKey(6,skeyt); 154 setSortKey(6,skeyt);
155 155
156 setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No")); 156 setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No"));
157 setText(8,mTodo->categoriesStr()); 157 setText(8,mTodo->categoriesStr());
158 setText(9,KOPrefs::instance()->calName( mTodo->calID())); 158 setText(9,KOPrefs::instance()->calName( mTodo->calID()));
159 159
160#if 0 160#if 0
161 // Find sort id in description. It's the text behind the last '#' character 161 // Find sort id in description. It's the text behind the last '#' character
162 // found in the description. White spaces are removed from beginning and end 162 // found in the description. White spaces are removed from beginning and end
163 // of sort id. 163 // of sort id.
164 int pos = mTodo->description().findRev('#'); 164 int pos = mTodo->description().findRev('#');
165 if (pos < 0) { 165 if (pos < 0) {
166 setText(6,""); 166 setText(6,"");
167 } else { 167 } else {
168 QString str = mTodo->description().mid(pos+1); 168 QString str = mTodo->description().mid(pos+1);
169 str.stripWhiteSpace(); 169 str.stripWhiteSpace();
170 setText(6,str); 170 setText(6,str);
171 } 171 }
172#endif 172#endif
173 173
174 m_known = false; 174 m_known = false;
175 m_init = false; 175 m_init = false;
176 176
177 setMyPixmap(); 177 setMyPixmap();
178 178
179} 179}
180void KOTodoViewItem::setMyPixmap() 180void KOTodoViewItem::setMyPixmap()
181{ 181{
182 int size = 5; 182 int size = 5;
183 QPixmap pixi = QPixmap( 1, 1 ); 183 QPixmap pixi = QPixmap( 1, 1 );
184 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) { 184 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) {
185// pixi = SmallIcon("redcross16"); 185// pixi = SmallIcon("redcross16");
186// } else { 186// } else {
187 QPainter p; 187 QPainter p;
188 188
189 int pixSize = 0; 189 int pixSize = 0;
190 QPixmap pPix = QPixmap( size, size ); 190 QPixmap pPix = QPixmap( size, size );
191 if ( mTodo->description().length() > 0 ) { 191 if ( mTodo->description().length() > 0 ) {
192 pixi.resize(size, pixSize+size); 192 pixi.resize(size, pixSize+size);
193 pPix.fill( Qt::darkGreen ); 193 pPix.fill( Qt::darkGreen );
194 p.begin( &pixi ); 194 p.begin( &pixi );
195 p. drawPixmap ( 0, pixSize, pPix); 195 p. drawPixmap ( 0, pixSize, pPix);
196 p.end(); 196 p.end();
197 pixSize += size; 197 pixSize += size;
198 } 198 }
199 if ( mTodo->isAlarmEnabled() && mTodo->alarmEnabled()) { 199 if ( mTodo->isAlarmEnabled() && mTodo->alarmEnabled()) {
200 pixi.resize(size, pixSize+size); 200 pixi.resize(size, pixSize+size);
201 pPix.fill( Qt::red ); 201 pPix.fill( Qt::red );
202 p.begin( &pixi ); 202 p.begin( &pixi );
203 p. drawPixmap ( 0, pixSize, pPix); 203 p. drawPixmap ( 0, pixSize, pPix);
204 p.end(); 204 p.end();
205 pixSize += size; 205 pixSize += size;
206 } 206 }
207 if ( mTodo->doesRecur() ) { 207 if ( mTodo->doesRecur() ) {
208 pixi.resize(size, pixSize+size); 208 pixi.resize(size, pixSize+size);
209 pPix.fill( Qt::blue ); 209 pPix.fill( Qt::blue );
210 p.begin( &pixi ); 210 p.begin( &pixi );
211 p. drawPixmap ( 0, pixSize, pPix); 211 p. drawPixmap ( 0, pixSize, pPix);
212 p.end(); 212 p.end();
213 pixSize += size; 213 pixSize += size;
214 } 214 }
215 // } 215 // }
216 if ( pixi.width() > 1 ) { 216 if ( pixi.width() > 1 ) {
217 setPixmap ( 0,pixi ) ; 217 setPixmap ( 0,pixi ) ;
218 } else { 218 } else {
219 setPixmap ( 0,QPixmap() ) ; 219 setPixmap ( 0,QPixmap() ) ;
220 } 220 }
221} 221}
222void KOTodoViewItem::stateChange(bool state) 222void KOTodoViewItem::stateChange(bool state)
223{ 223{
224 // qDebug("KOTodoViewItem::stateChange %d ", state); 224 // qDebug("KOTodoViewItem::stateChange %d ", state);
225 // do not change setting on startup 225 // do not change setting on startup
226 if ( m_init ) return; 226 if ( m_init ) return;
227 if (isOn()!=state) { 227 if (isOn()!=state) {
228 setOn(state); 228 setOn(state);
229 //qDebug("SETON "); 229 //qDebug("SETON ");
230 return; 230 return;
231 } 231 }
232 if ( mTodo->isCompleted() == state ) { 232 if ( mTodo->isCompleted() == state ) {
233 //qDebug("STATECHANGE:nothing to do "); 233 //qDebug("STATECHANGE:nothing to do ");
234 return; 234 return;
235 } 235 }
236 QString keyd = "=="; 236 QString keyd = "==";
237 QString keyt = "=="; 237 QString keyt = "==";
238 //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1()); 238 //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1());
239 if ( mTodo->doesRecur() ){ 239 if ( mTodo->doesRecur() ){
240 QDateTime start = mTodo->dtStart(); 240 QDateTime start = mTodo->dtStart();
241 mTodo->setCompleted(state); 241 mTodo->setCompleted(state);
242 if ( start != mTodo->dtStart() ) { 242 if ( start != mTodo->dtStart() ) {
243 if ( state && !mTodo->isCompleted() ) { 243 if ( state && !mTodo->isCompleted() ) {
244 setOn( false ); 244 setOn( false );
245 state = false; 245 state = false;
246 } 246 }
247 } 247 }
248 } else 248 } else
249 mTodo->setCompleted(state); 249 mTodo->setCompleted(state);
250 250
251 if (state) mTodo->setCompleted(QDateTime::currentDateTime()); 251 if (state) mTodo->setCompleted(QDateTime::currentDateTime());
252 252
253 if (mTodo->hasDueDate()) { 253 if (mTodo->hasDueDate()) {
254 setText(3, mTodo->dtDueDateStr()); 254 setText(3, mTodo->dtDueDateStr());
255 QDate d = mTodo->dtDue().date(); 255 QDate d = mTodo->dtDue().date();
256 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 256 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
257 setSortKey(3,keyd); 257 setSortKey(3,keyd);
258 if (mTodo->doesFloat()) { 258 if (mTodo->doesFloat()) {
259 setText(4,""); 259 setText(4,"");
260 } 260 }
261 else { 261 else {
262 setText(4,mTodo->dtDueTimeStr()); 262 setText(4,mTodo->dtDueTimeStr());
263 QTime t = mTodo->dtDue().time(); 263 QTime t = mTodo->dtDue().time();
264 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 264 keyt.sprintf("%02d%02d",t.hour(),t.minute());
265 setSortKey(4,keyt); 265 setSortKey(4,keyt);
266 } 266 }
267 } 267 }
268 if (mTodo->hasStartDate()) { 268 if (mTodo->hasStartDate()) {
269 QString skeyt = "=="; 269 QString skeyt = "==";
270 QString skeyd = "=="; 270 QString skeyd = "==";
271 setText(5, mTodo->dtStartDateStr()); 271 setText(5, mTodo->dtStartDateStr());
272 QDate d = mTodo->dtStart().date(); 272 QDate d = mTodo->dtStart().date();
273 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 273 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
274 274
275 if (mTodo->doesFloat()) { 275 if (mTodo->doesFloat()) {
276 setText(6,""); 276 setText(6,"");
277 } 277 }
278 else { 278 else {
279 setText(6,mTodo->dtStartTimeStr()); 279 setText(6,mTodo->dtStartTimeStr());
280 QTime t = mTodo->dtStart().time(); 280 QTime t = mTodo->dtStart().time();
281 skeyt.sprintf("%02d%02d",t.hour(),t.minute()); 281 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
282 282
283 } 283 }
284 setSortKey(5,skeyd); 284 setSortKey(5,skeyd);
285 setSortKey(6,skeyt); 285 setSortKey(6,skeyt);
286 } 286 }
287 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt); 287 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt);
288 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 288 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
289 289
290 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); 290 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
291 if (mTodo->percentComplete()<100) { 291 if (mTodo->percentComplete()<100) {
292 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 292 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
293 else setSortKey(2,QString::number(mTodo->percentComplete())); 293 else setSortKey(2,QString::number(mTodo->percentComplete()));
294 } 294 }
295 else { 295 else {
296 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 296 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
297 else setSortKey(2,QString::number(99)); 297 else setSortKey(2,QString::number(99));
298 } 298 }
299 if ( state ) { 299 if ( state ) {
300 QListViewItem * myChild = firstChild(); 300 QListViewItem * myChild = firstChild();
301 KOTodoViewItem *item; 301 KOTodoViewItem *item;
302 while( myChild ) { 302 while( myChild ) {
303 //qDebug("stateCH "); 303 //qDebug("stateCH ");
304 item = static_cast<KOTodoViewItem*>(myChild); 304 item = static_cast<KOTodoViewItem*>(myChild);
305 item->stateChange(state); 305 item->stateChange(state);
306 myChild = myChild->nextSibling(); 306 myChild = myChild->nextSibling();
307 } 307 }
308 } else { 308 } else {
309 QListViewItem * myChild = parent(); 309 QListViewItem * myChild = parent();
310 if ( myChild ) 310 if ( myChild )
311 (static_cast<KOTodoViewItem*>(myChild))->stateChange(state); 311 (static_cast<KOTodoViewItem*>(myChild))->stateChange(state);
312 } 312 }
313 mTodoView->modified(true); 313 mTodoView->modified(true);
314 setMyPixmap(); 314 setMyPixmap();
315 mTodoView->setTodoModified( mTodo ); 315 mTodoView->setTodoModified( mTodo );
316} 316}
317 317
318bool KOTodoViewItem::isAlternate() 318bool KOTodoViewItem::isAlternate()
319{ 319{
320 320
321 KOTodoListView *lv = static_cast<KOTodoListView *>(listView()); 321 KOTodoListView *lv = static_cast<KOTodoListView *>(listView());
322 if (lv && lv->alternateBackground().isValid()) 322 if (lv && lv->alternateBackground().isValid())
323 { 323 {
324 KOTodoViewItem *above = 0; 324 KOTodoViewItem *above = 0;
325 above = static_cast<KOTodoViewItem *>(itemAbove()); 325 above = static_cast<KOTodoViewItem *>(itemAbove());
326 m_known = above ? above->m_known : true; 326 m_known = above ? above->m_known : true;
327 if (m_known) 327 if (m_known)
328 { 328 {
329 m_odd = above ? !above->m_odd : false; 329 m_odd = above ? !above->m_odd : false;
330 } 330 }
331 else 331 else
332 { 332 {
333 KOTodoViewItem *item; 333 KOTodoViewItem *item;
334 bool previous = true; 334 bool previous = true;
335 if (QListViewItem::parent()) 335 if (QListViewItem::parent())
336 { 336 {
337 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()); 337 item = static_cast<KOTodoViewItem *>(QListViewItem::parent());
338 if (item) 338 if (item)
339 previous = item->m_odd; 339 previous = item->m_odd;
340 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild()); 340 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild());
341 } 341 }
342 else 342 else
343 { 343 {
344 item = static_cast<KOTodoViewItem *>(lv->firstChild()); 344 item = static_cast<KOTodoViewItem *>(lv->firstChild());
345 } 345 }
346 346
347 while(item) 347 while(item)
348 { 348 {
349 item->m_odd = previous = !previous; 349 item->m_odd = previous = !previous;
350 item->m_known = true; 350 item->m_known = true;
351 item = static_cast<KOTodoViewItem *>(item->nextSibling()); 351 item = static_cast<KOTodoViewItem *>(item->nextSibling());
352 } 352 }
353 } 353 }
354 return m_odd; 354 return m_odd;
355 } 355 }
356 return false; 356 return false;
357} 357}
358 358
359void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 359void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
360{ 360{
361 QColorGroup _cg = cg; 361 QColorGroup _cg = cg;
362 QColorGroup::ColorRole role; 362 QColorGroup::ColorRole role;
363 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor ) 363 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor && !mTodo->isRunning())
364 role = QColorGroup::Text; 364 role = QColorGroup::Text;
365 else 365 else
366 role = QColorGroup::Base; 366 role = QColorGroup::Base;
367 //#ifndef KORG_NOLVALTERNATION 367 //#ifndef KORG_NOLVALTERNATION
368 if (isAlternate()) 368 if (isAlternate())
369 _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground()); 369 _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground());
370 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors; 370 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors;
371 QColor colorToSet; 371 QColor colorToSet;
372 if ( column == 0 && mTodo->calID() > 1 ) { 372 if ( column == 0 && mTodo->calID() > 1 ) {
373 setColor = true; 373 setColor = true;
374 colorToSet = KOPrefs::instance()->defaultColor( mTodo->calID() ); 374 colorToSet = KOPrefs::instance()->defaultColor( mTodo->calID() );
375 } else if ( setColor ) { 375 } else if ( setColor ) {
376 QStringList categories = mTodo->categories(); 376 QStringList categories = mTodo->categories();
377 QString cat = categories.first(); 377 QString cat = categories.first();
378 if ( !cat.isEmpty()) { 378 if ( !cat.isEmpty()) {
379 colorToSet = *(KOPrefs::instance()->categoryColor(cat) ); 379 colorToSet = *(KOPrefs::instance()->categoryColor(cat) );
380 } else 380 } else
381 setColor = false; 381 setColor = false;
382 } 382 }
383 bool openMode = !isOpen(); 383 bool openMode = !isOpen();
384 // maybe we are in flat-display-mode 384 // maybe we are in flat-display-mode
385 if ( !firstChild() ) 385 if ( !firstChild() )
386 openMode = false; 386 openMode = false;
387 bool colorRunning = mTodo->isRunning(); 387 bool colorRunning = mTodo->isRunning();
388 if ( ! colorRunning && openMode ) 388 if ( ! colorRunning && openMode )
389 colorRunning = mTodo->hasRunningSub(); 389 colorRunning = mTodo->hasRunningSub();
390 if ( colorRunning ) { 390 if ( colorRunning ) {
391 setColor = true; 391 setColor = true;
392 colorToSet = KOPrefs::instance()->mTodoRunColor; 392 colorToSet = KOPrefs::instance()->mTodoRunColor;
393 } else { 393 } else {
394 int odue = mTodo->hasDueSubTodo( openMode ); 394 int odue = mTodo->hasDueSubTodo( openMode );
395 if (odue == 2) { 395 if (odue == 2) {
396 colorToSet = KOPrefs::instance()->mTodoOverdueColor; 396 colorToSet = KOPrefs::instance()->mTodoOverdueColor;
397 setColor = true; 397 setColor = true;
398 } else if ( odue == 1 ) { 398 } else if ( odue == 1 ) {
399 colorToSet = KOPrefs::instance()->mTodoDueTodayColor; 399 colorToSet = KOPrefs::instance()->mTodoDueTodayColor;
400 setColor = true; 400 setColor = true;
401 } 401 }
402 } 402 }
403 403
404 404
405 if ( setColor ) { 405 if ( setColor ) {
406 _cg.setColor(role,colorToSet ); 406 _cg.setColor(role,colorToSet );
407 if ( role == QColorGroup::Base) { 407 if ( role == QColorGroup::Base) {
408 int rgb = colorToSet.red(); 408 int rgb = colorToSet.red();
409 rgb += colorToSet.blue()/2; 409 rgb += colorToSet.blue()/2;
410 rgb += colorToSet.green(); 410 rgb += colorToSet.green();
411 if ( rgb < 200 ) 411 if ( rgb < 200 )
412 _cg.setColor(QColorGroup::Text,Qt::white ); 412 _cg.setColor(QColorGroup::Text,Qt::white );
413 } 413 }
414 } 414 }
415 //#endif 415 //#endif
416 if ( column > 0 ){ 416 if ( column > 0 ){
417 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) { 417 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) {
418 p->save(); 418 p->save();
419 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5); 419 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5);
420 420
421 p->fillRect( 0, 0, width, height(), _cg.base() ); // background 421 p->fillRect( 0, 0, width, height(), _cg.base() ); // background
422 // p->setPen(Qt::black ); //border 422 // p->setPen(Qt::black ); //border
423 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling 423 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling
424 QColor fc = KOPrefs::instance()->mHighlightColor; 424 QColor fc = KOPrefs::instance()->mHighlightColor;
425 if ( mTodo->percentComplete() == 100 ) 425 if ( mTodo->percentComplete() == 100 )
426 fc = darkGreen; 426 fc = darkGreen;
427 p->drawRect( 2, 2, width-4, height()-4); 427 p->drawRect( 2, 2, width-4, height()-4);
428 p->fillRect( 3, 3, progress, height()-6, 428 p->fillRect( 3, 3, progress, height()-6,
429 fc ); 429 fc );
430 p->restore(); 430 p->restore();
431 } else { 431 } else {
432 QCheckListItem::paintCell(p, _cg, column, width, alignment); 432 QCheckListItem::paintCell(p, _cg, column, width, alignment);
433 } 433 }
434 return; 434 return;
435 } 435 }
436 436
437 int align = alignment; 437 int align = alignment;
438 438
439 if ( !p ) 439 if ( !p )
440 return; 440 return;
441 441
442 p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) ); 442 p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) );
443 443
444 QListView *lv = listView(); 444 QListView *lv = listView();
445 if ( !lv ) 445 if ( !lv )
446 return; 446 return;
447 int marg = 2;//lv->itemMargin(); 447 int marg = 2;//lv->itemMargin();
448 int r = 0; 448 int r = 0;
449 QCheckListItem::Type myType = QCheckListItem::CheckBox; 449 QCheckListItem::Type myType = QCheckListItem::CheckBox;
450 int BoxSize = 20; 450 int BoxSize = 20;
451 int boxOffset = 2; 451 int boxOffset = 2;
452 int xOffset = 2; 452 int xOffset = 2;
453 if (qApp->desktop()->width() < 300 ) { 453 if (qApp->desktop()->width() < 300 ) {
454 BoxSize = 14; 454 BoxSize = 14;
455 boxOffset = -1; 455 boxOffset = -1;
456 xOffset = 1; 456 xOffset = 1;
457 // marg = 0; 457 // marg = 0;
458 } 458 }
459 if ( height() < BoxSize ) { 459 if ( height() < BoxSize ) {
460 boxOffset = boxOffset - ((BoxSize - height())/2) ; 460 boxOffset = boxOffset - ((BoxSize - height())/2) ;
461 // qDebug("boxOffset %d height %d", boxOffset, height() ); 461 // qDebug("boxOffset %d height %d", boxOffset, height() );
462 BoxSize = height(); 462 BoxSize = height();
463 463
464 } 464 }
465 //bool winStyle = lv->style() == WindowsStyle; 465 //bool winStyle = lv->style() == WindowsStyle;
466 466
467 int lineStart = 5; 467 int lineStart = 5;
468 if ( myType == Controller ) { 468 if ( myType == Controller ) {
469 if ( !pixmap( 0 ) ) 469 if ( !pixmap( 0 ) )
470 r += BoxSize + 4; 470 r += BoxSize + 4;
471 } else { 471 } else {
472 ASSERT( lv ); //### 472 ASSERT( lv ); //###
473 //QFontMetrics fm( lv->font() ); 473 //QFontMetrics fm( lv->font() );
474 //int d = fm.height(); 474 //int d = fm.height();
475 int x = 0; 475 int x = 0;
476 int y = (height() - BoxSize) / 2; 476 int y = (height() - BoxSize) / 2;
477 //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) ); 477 //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) );
478 if ( myType == CheckBox ) { 478 if ( myType == CheckBox ) {
479 if ( isEnabled() ) 479 if ( isEnabled() )
480 p->setPen( QPen( _cg.text(), 1 ) ); 480 p->setPen( QPen( _cg.text(), 1 ) );
481 else 481 else
482 p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) ); 482 p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) );
483 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 ); 483 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 );
484 lineStart = x+marg; 484 lineStart = x+marg;
485 ///////////////////// 485 /////////////////////
486 x++; 486 x++;
487 y++; 487 y++;
488 if ( isOn() ) { 488 if ( isOn() ) {
489 QPointArray a( 7*2 ); 489 QPointArray a( 7*2 );
490 int i, xx, yy; 490 int i, xx, yy;
491 xx = x+xOffset+marg+(boxOffset/2); 491 xx = x+xOffset+marg+(boxOffset/2);
492 yy = y+5+boxOffset; 492 yy = y+5+boxOffset;
493 for ( i=0; i<3; i++ ) { 493 for ( i=0; i<3; i++ ) {
494 a.setPoint( 2*i, xx, yy ); 494 a.setPoint( 2*i, xx, yy );
495 a.setPoint( 2*i+1, xx, yy+2 ); 495 a.setPoint( 2*i+1, xx, yy+2 );
496 // qDebug(" "); 496 // qDebug(" ");
497 xx++; yy++; 497 xx++; yy++;
498 } 498 }
499 yy -= 2; 499 yy -= 2;
500 for ( i=3; i<7; i++ ) { 500 for ( i=3; i<7; i++ ) {
501 a.setPoint( 2*i, xx, yy ); 501 a.setPoint( 2*i, xx, yy );
502 a.setPoint( 2*i+1, xx, yy+2 ); 502 a.setPoint( 2*i+1, xx, yy+2 );
503 xx++; yy--; 503 xx++; yy--;
504 } 504 }
505 p->setPen( darkGreen ); 505 p->setPen( darkGreen );
506 p->drawLineSegments( a ); 506 p->drawLineSegments( a );
507 } 507 }
508 //////////////////////// 508 ////////////////////////
509 } 509 }
510 r += BoxSize + 4; 510 r += BoxSize + 4;
511 } 511 }
512 512
513 p->translate( r, 0 ); 513 p->translate( r, 0 );
514 p->setPen( QPen( _cg.text() ) ); 514 p->setPen( QPen( _cg.text() ) );
515 QListViewItem::paintCell( p, _cg, column, width - r, align ); 515 QListViewItem::paintCell( p, _cg, column, width - r, align );
516 if ( mTodo->cancelled () ) { 516 if ( mTodo->cancelled () ) {
517 p->setPen( black ); 517 p->setPen( black );
518 QRect br = p->boundingRect( 1,1,1,1,0,mTodo->summary() ); 518 QRect br = p->boundingRect( 1,1,1,1,0,mTodo->summary() );
519 int wid = br.width() +lineStart; 519 int wid = br.width() +lineStart;
520 if ( wid > width-3 ) 520 if ( wid > width-3 )
521 wid = width-3; 521 wid = width-3;
522 p->drawLine( lineStart, height()/2+1, wid, height()/2+1 ); 522 p->drawLine( lineStart, height()/2+1, wid, height()/2+1 );
523 523
524 } 524 }
525 525
526} 526}