-rw-r--r-- | korganizer/kotodoeditor.cpp | 29 | ||||
-rw-r--r-- | korganizer/kotodoviewitem.cpp | 42 |
2 files changed, 69 insertions, 2 deletions
diff --git a/korganizer/kotodoeditor.cpp b/korganizer/kotodoeditor.cpp index 069dda8..9232e09 100644 --- a/korganizer/kotodoeditor.cpp +++ b/korganizer/kotodoeditor.cpp | |||
@@ -196,231 +196,260 @@ void KOTodoEditor::setupGeneral() | |||
196 | 196 | ||
197 | void KOTodoEditor::editTodo(Todo *todo, bool editDescription) | 197 | void KOTodoEditor::editTodo(Todo *todo, bool editDescription) |
198 | { | 198 | { |
199 | //init(); | 199 | //init(); |
200 | 200 | ||
201 | mTodo = todo; | 201 | mTodo = todo; |
202 | readTodo(mTodo); | 202 | readTodo(mTodo); |
203 | if ( editDescription ) { | 203 | if ( editDescription ) { |
204 | showPage( 1 ); | 204 | showPage( 1 ); |
205 | mGeneral->setFocusOn( 1 ); | 205 | mGeneral->setFocusOn( 1 ); |
206 | } else { | 206 | } else { |
207 | showPage( 0 ); | 207 | showPage( 0 ); |
208 | mGeneral->setFocusOn( 2 ); | 208 | mGeneral->setFocusOn( 2 ); |
209 | } | 209 | } |
210 | checkRecurrence(); | 210 | checkRecurrence(); |
211 | } | 211 | } |
212 | 212 | ||
213 | void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay) | 213 | void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay) |
214 | { | 214 | { |
215 | //init(); | 215 | //init(); |
216 | 216 | ||
217 | mTodo = 0; | 217 | mTodo = 0; |
218 | setDefaults(due,relatedTodo,allDay); | 218 | setDefaults(due,relatedTodo,allDay); |
219 | } | 219 | } |
220 | 220 | ||
221 | void KOTodoEditor::loadDefaults() | 221 | void KOTodoEditor::loadDefaults() |
222 | { | 222 | { |
223 | setDefaults(QDateTime::currentDateTime().addDays(7),0,false); | 223 | setDefaults(QDateTime::currentDateTime().addDays(7),0,false); |
224 | } | 224 | } |
225 | 225 | ||
226 | bool KOTodoEditor::processInput( bool emitTime ) | 226 | bool KOTodoEditor::processInput( bool emitTime ) |
227 | { | 227 | { |
228 | if (!validateInput()) return false; | 228 | if (!validateInput()) return false; |
229 | 229 | ||
230 | Todo *todo = 0; | 230 | Todo *todo = 0; |
231 | 231 | ||
232 | if (mTodo) todo = mTodo; | 232 | if (mTodo) todo = mTodo; |
233 | else { | 233 | else { |
234 | todo = new Todo; | 234 | todo = new Todo; |
235 | todo->setOrganizer(KOPrefs::instance()->email()); | 235 | todo->setOrganizer(KOPrefs::instance()->email()); |
236 | } | 236 | } |
237 | 237 | ||
238 | writeTodo(todo); | 238 | writeTodo(todo); |
239 | if ( emitTime ) { | 239 | if ( emitTime ) { |
240 | globalFlagBlockAgenda = 1; | 240 | globalFlagBlockAgenda = 1; |
241 | emit showAgendaView( false ); | 241 | emit showAgendaView( false ); |
242 | if ( todo->hasDueDate() ) | 242 | if ( todo->hasDueDate() ) |
243 | emit jumpToTime( todo->dtDue().date() ); | 243 | emit jumpToTime( todo->dtDue().date() ); |
244 | globalFlagBlockAgenda = 2; | 244 | globalFlagBlockAgenda = 2; |
245 | } | 245 | } |
246 | if (mTodo) { | 246 | if (mTodo) { |
247 | todo->setRevision(todo->revision()+1); | 247 | todo->setRevision(todo->revision()+1); |
248 | emit todoChanged(todo); | 248 | emit todoChanged(todo); |
249 | } else { | 249 | } else { |
250 | mCalendar->addTodo(todo); | 250 | mCalendar->addTodo(todo); |
251 | mTodo = todo; | 251 | mTodo = todo; |
252 | emit todoAdded(todo); | 252 | emit todoAdded(todo); |
253 | } | 253 | } |
254 | 254 | ||
255 | return true; | 255 | return true; |
256 | } | 256 | } |
257 | 257 | ||
258 | void KOTodoEditor::deleteTodo() | 258 | void KOTodoEditor::deleteTodo() |
259 | { | 259 | { |
260 | if (mTodo) { | 260 | if (mTodo) { |
261 | if (KOPrefs::instance()->mConfirm) { | 261 | if (KOPrefs::instance()->mConfirm) { |
262 | switch (msgItemDelete()) { | 262 | switch (msgItemDelete()) { |
263 | case KMessageBox::Continue: // OK | 263 | case KMessageBox::Continue: // OK |
264 | emit todoToBeDeleted(mTodo); | 264 | emit todoToBeDeleted(mTodo); |
265 | emit dialogClose(mTodo); | 265 | emit dialogClose(mTodo); |
266 | mCalendar->deleteTodo(mTodo); | 266 | mCalendar->deleteTodo(mTodo); |
267 | emit todoDeleted(); | 267 | emit todoDeleted(); |
268 | reject(); | 268 | reject(); |
269 | break; | 269 | break; |
270 | } | 270 | } |
271 | } | 271 | } |
272 | else { | 272 | else { |
273 | emit todoToBeDeleted(mTodo); | 273 | emit todoToBeDeleted(mTodo); |
274 | emit dialogClose(mTodo); | 274 | emit dialogClose(mTodo); |
275 | mCalendar->deleteTodo(mTodo); | 275 | mCalendar->deleteTodo(mTodo); |
276 | emit todoDeleted(); | 276 | emit todoDeleted(); |
277 | reject(); | 277 | reject(); |
278 | } | 278 | } |
279 | } else { | 279 | } else { |
280 | reject(); | 280 | reject(); |
281 | } | 281 | } |
282 | } | 282 | } |
283 | 283 | ||
284 | void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay) | 284 | void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay) |
285 | { | 285 | { |
286 | mRelatedTodo = relatedEvent; | 286 | mRelatedTodo = relatedEvent; |
287 | 287 | ||
288 | mGeneral->setDefaults(due,allDay); | 288 | mGeneral->setDefaults(due,allDay); |
289 | mDetails->setDefaults(); | 289 | mDetails->setDefaults(); |
290 | showPage( 0 ); | 290 | showPage( 0 ); |
291 | if ( mRelatedTodo ) { | 291 | if ( mRelatedTodo ) { |
292 | mGeneral->setCategories (mRelatedTodo->categoriesStr ()); | 292 | mGeneral->setCategories (mRelatedTodo->categoriesStr ()); |
293 | mGeneral->setSecrecy (mRelatedTodo->secrecy ()); | 293 | mGeneral->setSecrecy (mRelatedTodo->secrecy ()); |
294 | if ( mRelatedTodo->priority() < 3 ) | 294 | if ( mRelatedTodo->priority() < 3 ) |
295 | mGeneral->mPriorityCombo->setCurrentItem(mRelatedTodo->priority()-1); | 295 | mGeneral->mPriorityCombo->setCurrentItem(mRelatedTodo->priority()-1); |
296 | mGeneral->mSummaryEdit->lineEdit()->setText(mRelatedTodo->summary()+": "); | 296 | mGeneral->mSummaryEdit->lineEdit()->setText(mRelatedTodo->summary()+": "); |
297 | int len = mRelatedTodo->summary().length(); | 297 | int len = mRelatedTodo->summary().length(); |
298 | mGeneral->mSummaryEdit->lineEdit()->setFocus(); | 298 | mGeneral->mSummaryEdit->lineEdit()->setFocus(); |
299 | mGeneral->mSummaryEdit->lineEdit()->setCursorPosition ( len+2 ); | 299 | mGeneral->mSummaryEdit->lineEdit()->setCursorPosition ( len+2 ); |
300 | mGeneral->mSummaryEdit->lineEdit()->setSelection ( 0, len+2 ); | 300 | mGeneral->mSummaryEdit->lineEdit()->setSelection ( 0, len+2 ); |
301 | 301 | ||
302 | } else | 302 | } else |
303 | mGeneral->setFocusOn( 2 ); | 303 | mGeneral->setFocusOn( 2 ); |
304 | tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false ); | 304 | tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false ); |
305 | mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true); | 305 | mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true); |
306 | } | 306 | } |
307 | void KOTodoEditor::checkRecurrence() | 307 | void KOTodoEditor::checkRecurrence() |
308 | { | 308 | { |
309 | if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) { | 309 | if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) { |
310 | tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), true ); | 310 | tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), true ); |
311 | 311 | ||
312 | if ( mTodo ) | 312 | if ( mTodo ) |
313 | mRecurrence->readEvent( mTodo ); | 313 | mRecurrence->readEvent( mTodo ); |
314 | else { | 314 | else { |
315 | bool time = mGeneral->mTimeButton->isChecked(); | 315 | bool time = mGeneral->mTimeButton->isChecked(); |
316 | QDateTime from,to; | 316 | QDateTime from,to; |
317 | if ( time ) { | 317 | if ( time ) { |
318 | to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ; | 318 | to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ; |
319 | from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ; | 319 | from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ; |
320 | } else { | 320 | } else { |
321 | to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ; | 321 | to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ; |
322 | from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ; | 322 | from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ; |
323 | } | 323 | } |
324 | if ( to < from ) | ||
325 | to = from; | ||
324 | mRecurrence->setDefaults(from,to,!time); | 326 | mRecurrence->setDefaults(from,to,!time); |
325 | } | 327 | } |
326 | } else { | 328 | } else { |
327 | tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false ); | 329 | tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false ); |
328 | mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true); | 330 | mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true); |
329 | } | 331 | } |
330 | } | 332 | } |
331 | void KOTodoEditor::readTodo(Todo *todo) | 333 | void KOTodoEditor::readTodo(Todo *todo) |
332 | { | 334 | { |
333 | mGeneral->readTodo(todo); | 335 | mGeneral->readTodo(todo); |
334 | mDetails->readEvent(todo); | 336 | mDetails->readEvent(todo); |
335 | mRelatedTodo = 0;//todo->relatedTo(); | 337 | mRelatedTodo = 0;//todo->relatedTo(); |
336 | // categories | 338 | // categories |
337 | // mCategoryDialog->setSelected(todo->categories()); | 339 | // mCategoryDialog->setSelected(todo->categories()); |
338 | 340 | ||
339 | // We should handle read-only events here. | 341 | // We should handle read-only events here. |
340 | } | 342 | } |
341 | 343 | ||
342 | void KOTodoEditor::writeTodo(Todo *event) | 344 | void KOTodoEditor::writeTodo(Todo *event) |
343 | { | 345 | { |
344 | mGeneral->writeTodo(event); | 346 | mGeneral->writeTodo(event); |
345 | mDetails->writeEvent(event); | 347 | mDetails->writeEvent(event); |
346 | 348 | ||
347 | // set related event, i.e. parent to-do in this case. | 349 | // set related event, i.e. parent to-do in this case. |
348 | if (mRelatedTodo) { | 350 | if (mRelatedTodo) { |
349 | event->setRelatedTo(mRelatedTodo); | 351 | event->setRelatedTo(mRelatedTodo); |
350 | } | 352 | } |
351 | if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) { | 353 | if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) { |
352 | mRecurrence->writeEvent(event); | 354 | mRecurrence->writeEvent(event); |
355 | event->setRecurrenceID( event->dtStart().addSecs(-1) ); | ||
356 | event->setRecurDates(); | ||
357 | #if 0 | ||
358 | bool ok; | ||
359 | QDateTime next = event->getNextOccurence( event->dtStart().addSecs(-1), &ok ); | ||
360 | if ( ok ) { | ||
361 | QDateTime from,to; | ||
362 | bool time = mGeneral->mTimeButton->isChecked(); | ||
363 | if ( time ) { | ||
364 | to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ; | ||
365 | from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ; | ||
366 | } else { | ||
367 | to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ; | ||
368 | from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ; | ||
369 | } | ||
370 | if ( to < from ) | ||
371 | to = from; | ||
372 | int secs = from.secsTo( to ); | ||
373 | event->setRecurrenceID( next ); | ||
374 | event->setDtStart( next ); | ||
375 | event->setDtDue( next.addSecs( secs ) ); | ||
376 | } | ||
377 | else { | ||
378 | event->setHasRecurrenceID( false ); | ||
379 | event->recurrence()->unsetRecurs(); | ||
380 | } | ||
381 | #endif | ||
353 | } else | 382 | } else |
354 | event->recurrence()->unsetRecurs(); | 383 | event->recurrence()->unsetRecurs(); |
355 | } | 384 | } |
356 | 385 | ||
357 | bool KOTodoEditor::validateInput() | 386 | bool KOTodoEditor::validateInput() |
358 | { | 387 | { |
359 | if (!mGeneral->validateInput()) return false; | 388 | if (!mGeneral->validateInput()) return false; |
360 | if (!mDetails->validateInput()) return false; | 389 | if (!mDetails->validateInput()) return false; |
361 | return true; | 390 | return true; |
362 | } | 391 | } |
363 | 392 | ||
364 | int KOTodoEditor::msgItemDelete() | 393 | int KOTodoEditor::msgItemDelete() |
365 | { | 394 | { |
366 | return KMessageBox::warningContinueCancel(this, | 395 | return KMessageBox::warningContinueCancel(this, |
367 | i18n("This item will be permanently deleted."), | 396 | i18n("This item will be permanently deleted."), |
368 | i18n("KOrganizer Confirmation"),i18n("Delete")); | 397 | i18n("KOrganizer Confirmation"),i18n("Delete")); |
369 | } | 398 | } |
370 | 399 | ||
371 | void KOTodoEditor::modified (int modification) | 400 | void KOTodoEditor::modified (int modification) |
372 | { | 401 | { |
373 | if (modification == KOGlobals::CATEGORY_MODIFIED || | 402 | if (modification == KOGlobals::CATEGORY_MODIFIED || |
374 | KOGlobals::UNKNOWN_MODIFIED == modification ) | 403 | KOGlobals::UNKNOWN_MODIFIED == modification ) |
375 | // mCategoryDialog->setSelected (mTodo->categories ()); | 404 | // mCategoryDialog->setSelected (mTodo->categories ()); |
376 | mGeneral->modified (mTodo, modification); | 405 | mGeneral->modified (mTodo, modification); |
377 | 406 | ||
378 | } | 407 | } |
379 | 408 | ||
380 | void KOTodoEditor::slotLoadTemplate() | 409 | void KOTodoEditor::slotLoadTemplate() |
381 | { | 410 | { |
382 | 411 | ||
383 | QString fileName =locateLocal( "templates", "todos" ); | 412 | QString fileName =locateLocal( "templates", "todos" ); |
384 | QDir t_dir; | 413 | QDir t_dir; |
385 | if ( !t_dir.exists(fileName) ) | 414 | if ( !t_dir.exists(fileName) ) |
386 | t_dir.mkdir ( fileName ); | 415 | t_dir.mkdir ( fileName ); |
387 | fileName += "/todo"; | 416 | fileName += "/todo"; |
388 | fileName = KFileDialog::getSaveFileName( fileName , "Load Todo template", this ); | 417 | fileName = KFileDialog::getSaveFileName( fileName , "Load Todo template", this ); |
389 | if ( fileName.length() == 0 ) | 418 | if ( fileName.length() == 0 ) |
390 | return; | 419 | return; |
391 | CalendarLocal cal; | 420 | CalendarLocal cal; |
392 | ICalFormat format; | 421 | ICalFormat format; |
393 | if ( !format.load( &cal, fileName ) ) { | 422 | if ( !format.load( &cal, fileName ) ) { |
394 | KMessageBox::error( this, i18n("Error loading template file\n '%1'.") | 423 | KMessageBox::error( this, i18n("Error loading template file\n '%1'.") |
395 | .arg( fileName ) ); | 424 | .arg( fileName ) ); |
396 | return ; | 425 | return ; |
397 | } | 426 | } |
398 | QPtrList<Todo> todos = cal.todos(); | 427 | QPtrList<Todo> todos = cal.todos(); |
399 | Todo * todo = todos.first(); | 428 | Todo * todo = todos.first(); |
400 | if ( !todo ) { | 429 | if ( !todo ) { |
401 | KMessageBox::error( this, | 430 | KMessageBox::error( this, |
402 | i18n("Template does not\ncontain a valid Todo.")); | 431 | i18n("Template does not\ncontain a valid Todo.")); |
403 | } else { | 432 | } else { |
404 | readTodo( todo ); | 433 | readTodo( todo ); |
405 | } | 434 | } |
406 | 435 | ||
407 | } | 436 | } |
408 | 437 | ||
409 | void KOTodoEditor::slotSaveTemplate() | 438 | void KOTodoEditor::slotSaveTemplate() |
410 | { | 439 | { |
411 | QString fileName =locateLocal( "templates", "todos" ); | 440 | QString fileName =locateLocal( "templates", "todos" ); |
412 | QDir t_dir; | 441 | QDir t_dir; |
413 | if ( !t_dir.exists(fileName) ) | 442 | if ( !t_dir.exists(fileName) ) |
414 | t_dir.mkdir ( fileName ); | 443 | t_dir.mkdir ( fileName ); |
415 | fileName += "/todo"; | 444 | fileName += "/todo"; |
416 | fileName = KFileDialog::getSaveFileName( fileName , "Save as Todo template", this ); | 445 | fileName = KFileDialog::getSaveFileName( fileName , "Save as Todo template", this ); |
417 | if ( fileName.length() > 0 ) | 446 | if ( fileName.length() > 0 ) |
418 | saveTemplate( fileName ); | 447 | saveTemplate( fileName ); |
419 | } | 448 | } |
420 | 449 | ||
421 | void KOTodoEditor::saveTemplate( const QString &templateName ) | 450 | void KOTodoEditor::saveTemplate( const QString &templateName ) |
422 | { | 451 | { |
423 | Todo *todo = new Todo; | 452 | Todo *todo = new Todo; |
424 | writeTodo( todo ); | 453 | writeTodo( todo ); |
425 | saveAsTemplate( todo, templateName ); | 454 | saveAsTemplate( todo, templateName ); |
426 | } | 455 | } |
diff --git a/korganizer/kotodoviewitem.cpp b/korganizer/kotodoviewitem.cpp index 0e847c2..70f00c6 100644 --- a/korganizer/kotodoviewitem.cpp +++ b/korganizer/kotodoviewitem.cpp | |||
@@ -65,299 +65,337 @@ void KOTodoViewItem::setSortKey(int column,const QString &key) | |||
65 | } | 65 | } |
66 | 66 | ||
67 | #if QT_VERSION >= 0x030000 | 67 | #if QT_VERSION >= 0x030000 |
68 | void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w, | 68 | void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w, |
69 | int y,int h) | 69 | int y,int h) |
70 | { | 70 | { |
71 | QListViewItem::paintBranches(p,cg,w,y,h); | 71 | QListViewItem::paintBranches(p,cg,w,y,h); |
72 | } | 72 | } |
73 | #else | 73 | #else |
74 | #endif | 74 | #endif |
75 | 75 | ||
76 | void KOTodoViewItem::construct() | 76 | void KOTodoViewItem::construct() |
77 | { | 77 | { |
78 | // qDebug("KOTodoViewItem::construct() "); | 78 | // qDebug("KOTodoViewItem::construct() "); |
79 | m_init = true; | 79 | m_init = true; |
80 | QString keyd = "=="; | 80 | QString keyd = "=="; |
81 | QString keyt = "=="; | 81 | QString keyt = "=="; |
82 | QString skeyd = "=="; | 82 | QString skeyd = "=="; |
83 | QString skeyt = "=="; | 83 | QString skeyt = "=="; |
84 | 84 | ||
85 | setOn(mTodo->isCompleted()); | 85 | setOn(mTodo->isCompleted()); |
86 | setText(0,mTodo->summary()); | 86 | setText(0,mTodo->summary()); |
87 | setText(1,QString::number(mTodo->priority())); | 87 | setText(1,QString::number(mTodo->priority())); |
88 | setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); | 88 | setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); |
89 | if (mTodo->percentComplete()<100) { | 89 | if (mTodo->percentComplete()<100) { |
90 | if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); | 90 | if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); |
91 | else setSortKey(2,QString::number(mTodo->percentComplete())); | 91 | else setSortKey(2,QString::number(mTodo->percentComplete())); |
92 | } | 92 | } |
93 | else { | 93 | else { |
94 | if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); | 94 | if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); |
95 | else setSortKey(2,QString::number(99)); | 95 | else setSortKey(2,QString::number(99)); |
96 | } | 96 | } |
97 | if (mTodo->hasDueDate()) { | 97 | if (mTodo->hasDueDate()) { |
98 | setText(3, mTodo->dtDueDateStr()); | 98 | setText(3, mTodo->dtDueDateStr()); |
99 | QDate d = mTodo->dtDue().date(); | 99 | QDate d = mTodo->dtDue().date(); |
100 | keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); | 100 | keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); |
101 | // setSortKey(3,keyd); | 101 | // setSortKey(3,keyd); |
102 | if (mTodo->doesFloat()) { | 102 | if (mTodo->doesFloat()) { |
103 | setText(4,""); | 103 | setText(4,""); |
104 | } | 104 | } |
105 | else { | 105 | else { |
106 | setText(4,mTodo->dtDueTimeStr()); | 106 | setText(4,mTodo->dtDueTimeStr()); |
107 | QTime t = mTodo->dtDue().time(); | 107 | QTime t = mTodo->dtDue().time(); |
108 | keyt.sprintf("%02d%02d",t.hour(),t.minute()); | 108 | keyt.sprintf("%02d%02d",t.hour(),t.minute()); |
109 | //setSortKey(4,keyt); | 109 | //setSortKey(4,keyt); |
110 | } | 110 | } |
111 | } else { | 111 | } else { |
112 | setText(3,""); | 112 | setText(3,""); |
113 | setText(4,""); | 113 | setText(4,""); |
114 | } | 114 | } |
115 | setSortKey(3,keyd); | 115 | setSortKey(3,keyd); |
116 | setSortKey(4,keyt); | 116 | setSortKey(4,keyt); |
117 | 117 | ||
118 | if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt); | 118 | if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt); |
119 | else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); | 119 | else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); |
120 | 120 | ||
121 | 121 | ||
122 | 122 | ||
123 | if (mTodo->hasStartDate()) { | 123 | if (mTodo->hasStartDate()) { |
124 | setText(5, mTodo->dtStartDateStr()); | 124 | setText(5, mTodo->dtStartDateStr()); |
125 | QDate d = mTodo->dtStart().date(); | 125 | QDate d = mTodo->dtStart().date(); |
126 | skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); | 126 | skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); |
127 | 127 | ||
128 | if (mTodo->doesFloat()) { | 128 | if (mTodo->doesFloat()) { |
129 | setText(6,""); | 129 | setText(6,""); |
130 | } | 130 | } |
131 | else { | 131 | else { |
132 | setText(6,mTodo->dtStartTimeStr()); | 132 | setText(6,mTodo->dtStartTimeStr()); |
133 | QTime t = mTodo->dtStart().time(); | 133 | QTime t = mTodo->dtStart().time(); |
134 | skeyt.sprintf("%02d%02d",t.hour(),t.minute()); | 134 | skeyt.sprintf("%02d%02d",t.hour(),t.minute()); |
135 | 135 | ||
136 | } | 136 | } |
137 | } else { | 137 | } else { |
138 | setText(5,""); | 138 | setText(5,""); |
139 | setText(6,""); | 139 | setText(6,""); |
140 | } | 140 | } |
141 | setSortKey(5,skeyd); | 141 | setSortKey(5,skeyd); |
142 | setSortKey(6,skeyt); | 142 | setSortKey(6,skeyt); |
143 | 143 | ||
144 | setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No")); | 144 | setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No")); |
145 | setText(8,mTodo->categoriesStr()); | 145 | setText(8,mTodo->categoriesStr()); |
146 | 146 | ||
147 | #if 0 | 147 | #if 0 |
148 | // Find sort id in description. It's the text behind the last '#' character | 148 | // Find sort id in description. It's the text behind the last '#' character |
149 | // found in the description. White spaces are removed from beginning and end | 149 | // found in the description. White spaces are removed from beginning and end |
150 | // of sort id. | 150 | // of sort id. |
151 | int pos = mTodo->description().findRev('#'); | 151 | int pos = mTodo->description().findRev('#'); |
152 | if (pos < 0) { | 152 | if (pos < 0) { |
153 | setText(6,""); | 153 | setText(6,""); |
154 | } else { | 154 | } else { |
155 | QString str = mTodo->description().mid(pos+1); | 155 | QString str = mTodo->description().mid(pos+1); |
156 | str.stripWhiteSpace(); | 156 | str.stripWhiteSpace(); |
157 | setText(6,str); | 157 | setText(6,str); |
158 | } | 158 | } |
159 | #endif | 159 | #endif |
160 | 160 | ||
161 | m_known = false; | 161 | m_known = false; |
162 | m_init = false; | 162 | m_init = false; |
163 | 163 | ||
164 | setMyPixmap(); | 164 | setMyPixmap(); |
165 | 165 | ||
166 | } | 166 | } |
167 | void KOTodoViewItem::setMyPixmap() | 167 | void KOTodoViewItem::setMyPixmap() |
168 | { | 168 | { |
169 | int size = 5; | 169 | int size = 5; |
170 | QPixmap pixi = QPixmap( 1, 1 ); | 170 | QPixmap pixi = QPixmap( 1, 1 ); |
171 | // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) { | 171 | // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) { |
172 | // pixi = SmallIcon("redcross16"); | 172 | // pixi = SmallIcon("redcross16"); |
173 | // } else { | 173 | // } else { |
174 | QPainter p; | 174 | QPainter p; |
175 | 175 | ||
176 | int pixSize = 0; | 176 | int pixSize = 0; |
177 | QPixmap pPix = QPixmap( size, size ); | 177 | QPixmap pPix = QPixmap( size, size ); |
178 | if ( mTodo->description().length() > 0 ) { | 178 | if ( mTodo->description().length() > 0 ) { |
179 | pixi.resize(size, pixSize+size); | 179 | pixi.resize(size, pixSize+size); |
180 | pPix.fill( Qt::darkGreen ); | 180 | pPix.fill( Qt::darkGreen ); |
181 | p.begin( &pixi ); | 181 | p.begin( &pixi ); |
182 | p. drawPixmap ( 0, pixSize, pPix); | 182 | p. drawPixmap ( 0, pixSize, pPix); |
183 | p.end(); | 183 | p.end(); |
184 | pixSize += size; | 184 | pixSize += size; |
185 | } | 185 | } |
186 | if ( mTodo->isAlarmEnabled() ) { | 186 | if ( mTodo->isAlarmEnabled() ) { |
187 | pixi.resize(size, pixSize+size); | 187 | pixi.resize(size, pixSize+size); |
188 | pPix.fill( Qt::red ); | 188 | pPix.fill( Qt::red ); |
189 | p.begin( &pixi ); | 189 | p.begin( &pixi ); |
190 | p. drawPixmap ( 0, pixSize, pPix); | 190 | p. drawPixmap ( 0, pixSize, pPix); |
191 | p.end(); | 191 | p.end(); |
192 | pixSize += size; | 192 | pixSize += size; |
193 | } | ||
194 | if ( mTodo->doesRecur() ) { | ||
195 | pixi.resize(size, pixSize+size); | ||
196 | pPix.fill( Qt::blue ); | ||
197 | p.begin( &pixi ); | ||
198 | p. drawPixmap ( 0, pixSize, pPix); | ||
199 | p.end(); | ||
200 | pixSize += size; | ||
193 | } | 201 | } |
194 | // } | 202 | // } |
195 | if ( pixi.width() > 1 ) { | 203 | if ( pixi.width() > 1 ) { |
196 | setPixmap ( 0,pixi ) ; | 204 | setPixmap ( 0,pixi ) ; |
197 | } else { | 205 | } else { |
198 | setPixmap ( 0,QPixmap() ) ; | 206 | setPixmap ( 0,QPixmap() ) ; |
199 | } | 207 | } |
200 | } | 208 | } |
201 | void KOTodoViewItem::stateChange(bool state) | 209 | void KOTodoViewItem::stateChange(bool state) |
202 | { | 210 | { |
203 | // qDebug("KOTodoViewItem::stateChange "); | 211 | // qDebug("KOTodoViewItem::stateChange %d ", state); |
204 | // do not change setting on startup | 212 | // do not change setting on startup |
205 | if ( m_init ) return; | 213 | if ( m_init ) return; |
206 | if (isOn()!=state) { | 214 | if (isOn()!=state) { |
207 | setOn(state); | 215 | setOn(state); |
208 | //qDebug("SETON "); | 216 | //qDebug("SETON "); |
209 | return; | 217 | return; |
210 | } | 218 | } |
211 | if ( mTodo->isCompleted() == state ) { | 219 | if ( mTodo->isCompleted() == state ) { |
212 | //qDebug("STATECHANGE:nothing to do "); | 220 | //qDebug("STATECHANGE:nothing to do "); |
213 | return; | 221 | return; |
214 | } | 222 | } |
215 | QString keyd = "=="; | 223 | QString keyd = "=="; |
216 | QString keyt = "=="; | 224 | QString keyt = "=="; |
217 | //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1()); | 225 | //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1()); |
218 | mTodo->setCompleted(state); | 226 | if ( mTodo->doesRecur() ){ |
227 | QDateTime start = mTodo->dtStart(); | ||
228 | mTodo->setCompleted(state); | ||
229 | if ( start != mTodo->dtStart() ) { | ||
230 | if ( state && !mTodo->isCompleted() ) { | ||
231 | setOn( false ); | ||
232 | state = false; | ||
233 | } | ||
234 | } | ||
235 | } else | ||
236 | mTodo->setCompleted(state); | ||
237 | |||
219 | if (state) mTodo->setCompleted(QDateTime::currentDateTime()); | 238 | if (state) mTodo->setCompleted(QDateTime::currentDateTime()); |
220 | 239 | ||
221 | if (mTodo->hasDueDate()) { | 240 | if (mTodo->hasDueDate()) { |
222 | setText(3, mTodo->dtDueDateStr()); | 241 | setText(3, mTodo->dtDueDateStr()); |
223 | QDate d = mTodo->dtDue().date(); | 242 | QDate d = mTodo->dtDue().date(); |
224 | keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); | 243 | keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); |
225 | setSortKey(3,keyd); | 244 | setSortKey(3,keyd); |
226 | if (mTodo->doesFloat()) { | 245 | if (mTodo->doesFloat()) { |
227 | setText(4,""); | 246 | setText(4,""); |
228 | } | 247 | } |
229 | else { | 248 | else { |
230 | setText(4,mTodo->dtDueTimeStr()); | 249 | setText(4,mTodo->dtDueTimeStr()); |
231 | QTime t = mTodo->dtDue().time(); | 250 | QTime t = mTodo->dtDue().time(); |
232 | keyt.sprintf("%02d%02d",t.hour(),t.minute()); | 251 | keyt.sprintf("%02d%02d",t.hour(),t.minute()); |
233 | setSortKey(4,keyt); | 252 | setSortKey(4,keyt); |
234 | } | 253 | } |
235 | } | 254 | } |
255 | if (mTodo->hasStartDate()) { | ||
256 | QString skeyt = "=="; | ||
257 | QString skeyd = "=="; | ||
258 | setText(5, mTodo->dtStartDateStr()); | ||
259 | QDate d = mTodo->dtStart().date(); | ||
260 | skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); | ||
261 | |||
262 | if (mTodo->doesFloat()) { | ||
263 | setText(6,""); | ||
264 | } | ||
265 | else { | ||
266 | setText(6,mTodo->dtStartTimeStr()); | ||
267 | QTime t = mTodo->dtStart().time(); | ||
268 | skeyt.sprintf("%02d%02d",t.hour(),t.minute()); | ||
269 | |||
270 | } | ||
271 | setSortKey(5,skeyd); | ||
272 | setSortKey(6,skeyt); | ||
273 | } | ||
236 | if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt); | 274 | if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt); |
237 | else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); | 275 | else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); |
238 | 276 | ||
239 | setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); | 277 | setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); |
240 | if (mTodo->percentComplete()<100) { | 278 | if (mTodo->percentComplete()<100) { |
241 | if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); | 279 | if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); |
242 | else setSortKey(2,QString::number(mTodo->percentComplete())); | 280 | else setSortKey(2,QString::number(mTodo->percentComplete())); |
243 | } | 281 | } |
244 | else { | 282 | else { |
245 | if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); | 283 | if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); |
246 | else setSortKey(2,QString::number(99)); | 284 | else setSortKey(2,QString::number(99)); |
247 | } | 285 | } |
248 | if ( state ) { | 286 | if ( state ) { |
249 | QListViewItem * myChild = firstChild(); | 287 | QListViewItem * myChild = firstChild(); |
250 | KOTodoViewItem *item; | 288 | KOTodoViewItem *item; |
251 | while( myChild ) { | 289 | while( myChild ) { |
252 | //qDebug("stateCH "); | 290 | //qDebug("stateCH "); |
253 | item = static_cast<KOTodoViewItem*>(myChild); | 291 | item = static_cast<KOTodoViewItem*>(myChild); |
254 | item->stateChange(state); | 292 | item->stateChange(state); |
255 | myChild = myChild->nextSibling(); | 293 | myChild = myChild->nextSibling(); |
256 | } | 294 | } |
257 | } else { | 295 | } else { |
258 | QListViewItem * myChild = parent(); | 296 | QListViewItem * myChild = parent(); |
259 | if ( myChild ) | 297 | if ( myChild ) |
260 | (static_cast<KOTodoViewItem*>(myChild))->stateChange(state); | 298 | (static_cast<KOTodoViewItem*>(myChild))->stateChange(state); |
261 | } | 299 | } |
262 | mTodoView->modified(true); | 300 | mTodoView->modified(true); |
263 | setMyPixmap(); | 301 | setMyPixmap(); |
264 | mTodoView->setTodoModified( mTodo ); | 302 | mTodoView->setTodoModified( mTodo ); |
265 | } | 303 | } |
266 | 304 | ||
267 | bool KOTodoViewItem::isAlternate() | 305 | bool KOTodoViewItem::isAlternate() |
268 | { | 306 | { |
269 | 307 | ||
270 | KOTodoListView *lv = static_cast<KOTodoListView *>(listView()); | 308 | KOTodoListView *lv = static_cast<KOTodoListView *>(listView()); |
271 | if (lv && lv->alternateBackground().isValid()) | 309 | if (lv && lv->alternateBackground().isValid()) |
272 | { | 310 | { |
273 | KOTodoViewItem *above = 0; | 311 | KOTodoViewItem *above = 0; |
274 | above = static_cast<KOTodoViewItem *>(itemAbove()); | 312 | above = static_cast<KOTodoViewItem *>(itemAbove()); |
275 | m_known = above ? above->m_known : true; | 313 | m_known = above ? above->m_known : true; |
276 | if (m_known) | 314 | if (m_known) |
277 | { | 315 | { |
278 | m_odd = above ? !above->m_odd : false; | 316 | m_odd = above ? !above->m_odd : false; |
279 | } | 317 | } |
280 | else | 318 | else |
281 | { | 319 | { |
282 | KOTodoViewItem *item; | 320 | KOTodoViewItem *item; |
283 | bool previous = true; | 321 | bool previous = true; |
284 | if (QListViewItem::parent()) | 322 | if (QListViewItem::parent()) |
285 | { | 323 | { |
286 | item = static_cast<KOTodoViewItem *>(QListViewItem::parent()); | 324 | item = static_cast<KOTodoViewItem *>(QListViewItem::parent()); |
287 | if (item) | 325 | if (item) |
288 | previous = item->m_odd; | 326 | previous = item->m_odd; |
289 | item = static_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild()); | 327 | item = static_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild()); |
290 | } | 328 | } |
291 | else | 329 | else |
292 | { | 330 | { |
293 | item = static_cast<KOTodoViewItem *>(lv->firstChild()); | 331 | item = static_cast<KOTodoViewItem *>(lv->firstChild()); |
294 | } | 332 | } |
295 | 333 | ||
296 | while(item) | 334 | while(item) |
297 | { | 335 | { |
298 | item->m_odd = previous = !previous; | 336 | item->m_odd = previous = !previous; |
299 | item->m_known = true; | 337 | item->m_known = true; |
300 | item = static_cast<KOTodoViewItem *>(item->nextSibling()); | 338 | item = static_cast<KOTodoViewItem *>(item->nextSibling()); |
301 | } | 339 | } |
302 | } | 340 | } |
303 | return m_odd; | 341 | return m_odd; |
304 | } | 342 | } |
305 | return false; | 343 | return false; |
306 | } | 344 | } |
307 | 345 | ||
308 | void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) | 346 | void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) |
309 | { | 347 | { |
310 | QColorGroup _cg = cg; | 348 | QColorGroup _cg = cg; |
311 | QColorGroup::ColorRole role; | 349 | QColorGroup::ColorRole role; |
312 | if ( KOPrefs::instance()->mTodoViewUsesForegroundColor ) | 350 | if ( KOPrefs::instance()->mTodoViewUsesForegroundColor ) |
313 | role = QColorGroup::Text; | 351 | role = QColorGroup::Text; |
314 | else | 352 | else |
315 | role = QColorGroup::Base; | 353 | role = QColorGroup::Base; |
316 | //#ifndef KORG_NOLVALTERNATION | 354 | //#ifndef KORG_NOLVALTERNATION |
317 | if (isAlternate()) | 355 | if (isAlternate()) |
318 | _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground()); | 356 | _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground()); |
319 | bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors; | 357 | bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors; |
320 | QColor colorToSet; | 358 | QColor colorToSet; |
321 | if ( setColor ) { | 359 | if ( setColor ) { |
322 | QStringList categories = mTodo->categories(); | 360 | QStringList categories = mTodo->categories(); |
323 | QString cat = categories.first(); | 361 | QString cat = categories.first(); |
324 | if ( !cat.isEmpty()) { | 362 | if ( !cat.isEmpty()) { |
325 | colorToSet = *(KOPrefs::instance()->categoryColor(cat) ); | 363 | colorToSet = *(KOPrefs::instance()->categoryColor(cat) ); |
326 | } else | 364 | } else |
327 | setColor = false; | 365 | setColor = false; |
328 | } | 366 | } |
329 | 367 | ||
330 | int odue = mTodo->hasDueSubTodo( !isOpen()); | 368 | int odue = mTodo->hasDueSubTodo( !isOpen()); |
331 | if (odue == 2) { | 369 | if (odue == 2) { |
332 | colorToSet = KOPrefs::instance()->mTodoOverdueColor; | 370 | colorToSet = KOPrefs::instance()->mTodoOverdueColor; |
333 | setColor = true; | 371 | setColor = true; |
334 | } else if ( odue == 1 ) { | 372 | } else if ( odue == 1 ) { |
335 | colorToSet = KOPrefs::instance()->mTodoDueTodayColor; | 373 | colorToSet = KOPrefs::instance()->mTodoDueTodayColor; |
336 | setColor = true; | 374 | setColor = true; |
337 | } | 375 | } |
338 | 376 | ||
339 | 377 | ||
340 | if ( setColor ) { | 378 | if ( setColor ) { |
341 | _cg.setColor(role,colorToSet ); | 379 | _cg.setColor(role,colorToSet ); |
342 | if ( role == QColorGroup::Base) { | 380 | if ( role == QColorGroup::Base) { |
343 | int rgb = colorToSet.red(); | 381 | int rgb = colorToSet.red(); |
344 | rgb += colorToSet.blue()/2; | 382 | rgb += colorToSet.blue()/2; |
345 | rgb += colorToSet.green(); | 383 | rgb += colorToSet.green(); |
346 | if ( rgb < 200 ) | 384 | if ( rgb < 200 ) |
347 | _cg.setColor(QColorGroup::Text,Qt::white ); | 385 | _cg.setColor(QColorGroup::Text,Qt::white ); |
348 | } | 386 | } |
349 | } | 387 | } |
350 | //#endif | 388 | //#endif |
351 | if ( column > 0 ){ | 389 | if ( column > 0 ){ |
352 | if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) { | 390 | if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) { |
353 | p->save(); | 391 | p->save(); |
354 | int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5); | 392 | int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5); |
355 | 393 | ||
356 | p->fillRect( 0, 0, width, height(), _cg.base() ); // background | 394 | p->fillRect( 0, 0, width, height(), _cg.base() ); // background |
357 | // p->setPen(Qt::black ); //border | 395 | // p->setPen(Qt::black ); //border |
358 | // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling | 396 | // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling |
359 | QColor fc = KOPrefs::instance()->mHighlightColor; | 397 | QColor fc = KOPrefs::instance()->mHighlightColor; |
360 | if ( mTodo->percentComplete() == 100 ) | 398 | if ( mTodo->percentComplete() == 100 ) |
361 | fc = darkGreen; | 399 | fc = darkGreen; |
362 | p->drawRect( 2, 2, width-4, height()-4); | 400 | p->drawRect( 2, 2, width-4, height()-4); |
363 | p->fillRect( 3, 3, progress, height()-6, | 401 | p->fillRect( 3, 3, progress, height()-6, |