summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/tableview.cpp174
1 files changed, 98 insertions, 76 deletions
diff --git a/core/pim/todo/tableview.cpp b/core/pim/todo/tableview.cpp
index c4165db..6299113 100644
--- a/core/pim/todo/tableview.cpp
+++ b/core/pim/todo/tableview.cpp
@@ -1,100 +1,103 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 <> 3             .=l. Copyright (c) 2002 <>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This program is free software; you can 5 _;:,     .>    :=|. This program is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU General Public 7:`=1 )Y*s>-.--   : the terms of the GNU General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This program is distributed in the hope that 12    .i_,=:_.      -<s. This program is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28#include <stdlib.h> 28#include <stdlib.h>
29 29
30#include <qlineedit.h>
30#include <qtimer.h> 31#include <qtimer.h>
31#include <qpoint.h> 32#include <qpoint.h>
32#include <qpopupmenu.h> 33#include <qpopupmenu.h>
33 34
34#include "mainwindow.h" 35#include "mainwindow.h"
35//#include "tableitems.h" 36//#include "tableitems.h"
36#include "tableview.h" 37#include "tableview.h"
37 38
38using namespace Todo; 39using namespace Todo;
39 40
40namespace { 41namespace {
41 static const int BoxSize = 14; 42 static const int BoxSize = 14;
42 static const int RowHeight = 20; 43 static const int RowHeight = 20;
43} 44}
44 45
45 46
46TableView::TableView( MainWindow* window, QWidget* wid ) 47TableView::TableView( MainWindow* window, QWidget* wid )
47 : QTable( wid ), TodoView( window ) { 48 : QTable( wid ), TodoView( window ) {
48 setUpdatesEnabled( false ); 49 setUpdatesEnabled( false );
49 viewport()->setUpdatesEnabled( false ); 50 viewport()->setUpdatesEnabled( false );
50 m_enablePaint = false; 51 m_enablePaint = false;
51 setNumRows(0); 52 setNumRows(0);
52 setNumCols(4); 53 setNumCols(4);
53 54
54 setSorting( TRUE ); 55 setSorting( TRUE );
55 setSelectionMode( NoSelection ); 56 setSelectionMode( NoSelection );
56 setColumnStretchable( 2, TRUE ); 57// setColumnStretchable( 2, TRUE );
58 setColumnStretchable( 3, FALSE );
57 setColumnWidth(0, 20 ); 59 setColumnWidth(0, 20 );
58 setColumnWidth(1, 35 ); 60 setColumnWidth(1, 35 );
61 setColumnWidth(3, 18 );
59 62
60 setLeftMargin( 0 ); 63 setLeftMargin( 0 );
61 verticalHeader()->hide(); 64 verticalHeader()->hide();
62 65
63 horizontalHeader()->setLabel(0, tr("C.") ); 66 horizontalHeader()->setLabel(0, tr("C.") );
64 horizontalHeader()->setLabel(1, tr("Prior.") ); 67 horizontalHeader()->setLabel(1, tr("Prior.") );
65 horizontalHeader()->setLabel(2, tr("Description" ) ); 68 horizontalHeader()->setLabel(2, tr("Description" ) );
66 69
67 setColumnStretchable(3, FALSE ); 70// setColumnStretchable(3, FALSE );
68 setColumnWidth(3, 20 ); 71
69 horizontalHeader()->setLabel(3, tr("Deadline") ); 72 horizontalHeader()->setLabel(3, tr("Deadline") );
70 73
71 if ( todoWindow()->showDeadline() ) 74 if ( todoWindow()->showDeadline() )
72 showColumn( 3); 75 showColumn( 3);
73 else 76 else
74 hideColumn(3 ); 77 hideColumn(3 );
75 78
76 connect((QTable*)this, SIGNAL( clicked( int, int, int, const QPoint& ) ), 79 connect((QTable*)this, SIGNAL( clicked( int, int, int, const QPoint& ) ),
77 this, SLOT( slotClicked(int, int, int, const QPoint& ) ) ); 80 this, SLOT( slotClicked(int, int, int, const QPoint& ) ) );
78 connect((QTable*)this, SIGNAL( pressed( int, int, int, const QPoint& ) ), 81 connect((QTable*)this, SIGNAL( pressed( int, int, int, const QPoint& ) ),
79 this, SLOT( slotPressed(int, int, int, const QPoint& ) ) ); 82 this, SLOT( slotPressed(int, int, int, const QPoint& ) ) );
80 connect((QTable*)this, SIGNAL(valueChanged(int, int) ), 83 connect((QTable*)this, SIGNAL(valueChanged(int, int) ),
81 this, SLOT( slotValueChanged(int, int) ) ); 84 this, SLOT( slotValueChanged(int, int) ) );
82 connect((QTable*)this, SIGNAL(currentChanged(int, int) ), 85 connect((QTable*)this, SIGNAL(currentChanged(int, int) ),
83 this, SLOT( slotCurrentChanged(int, int) ) ); 86 this, SLOT( slotCurrentChanged(int, int) ) );
84 87
85 m_menuTimer = new QTimer( this ); 88 m_menuTimer = new QTimer( this );
86 connect( m_menuTimer, SIGNAL(timeout()), 89 connect( m_menuTimer, SIGNAL(timeout()),
87 this, SLOT(slotShowMenu()) ); 90 this, SLOT(slotShowMenu()) );
88 91
89 m_enablePaint = true; 92 m_enablePaint = true;
90 setUpdatesEnabled( true ); 93 setUpdatesEnabled( true );
91 viewport()->setUpdatesEnabled( true ); 94 viewport()->setUpdatesEnabled( true );
92 viewport()->update(); 95 viewport()->update();
93 setSortOrder( 0 ); 96 setSortOrder( 0 );
94 setAscending( TRUE ); 97 setAscending( TRUE );
95 m_first = true; 98 m_first = true;
96} 99}
97/* a new day has started 100/* a new day has started
98 * update the day 101 * update the day
99 */ 102 */
100void TableView::newDay() { 103void TableView::newDay() {
@@ -282,202 +285,221 @@ void TableView::sortColumn( int col, bool asc, bool ) {
282 setAscending( asc ); 285 setAscending( asc );
283 updateView(); 286 updateView();
284} 287}
285void TableView::viewportPaintEvent( QPaintEvent* e) { 288void TableView::viewportPaintEvent( QPaintEvent* e) {
286 if (m_enablePaint ) 289 if (m_enablePaint )
287 QTable::viewportPaintEvent( e ); 290 QTable::viewportPaintEvent( e );
288} 291}
289/* 292/*
290 * This segment is copyrighted by TT 293 * This segment is copyrighted by TT
291 * it was taken from their todolist 294 * it was taken from their todolist
292 * application this code is GPL 295 * application this code is GPL
293 */ 296 */
294void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) { 297void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) {
295 const QColorGroup &cg = colorGroup(); 298 const QColorGroup &cg = colorGroup();
296 299
297 p->save(); 300 p->save();
298 301
299 OTodo task = sorted()[row]; 302 OTodo task = sorted()[row];
300 303
301 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); 304 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
302 305
303 QPen op = p->pen(); 306 QPen op = p->pen();
304 p->setPen(cg.mid()); 307 p->setPen(cg.mid());
305 p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 ); 308 p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 );
306 p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 ); 309 p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 );
307 p->setPen(op); 310 p->setPen(op);
308 311
309 QFont f = p->font(); 312 QFont f = p->font();
310 QFontMetrics fm(f); 313 QFontMetrics fm(f);
311 314
312 switch(col) { 315 switch(col) {
313 case 0: 316 case 0:
314 { 317 {
315 // completed field 318 // completed field
316 int marg = ( cr.width() - BoxSize ) / 2; 319 int marg = ( cr.width() - BoxSize ) / 2;
317 int x = 0; 320 int x = 0;
318 int y = ( cr.height() - BoxSize ) / 2; 321 int y = ( cr.height() - BoxSize ) / 2;
319 p->setPen( QPen( cg.text() ) ); 322 p->setPen( QPen( cg.text() ) );
320 p->drawRect( x + marg, y, BoxSize, BoxSize ); 323 p->drawRect( x + marg, y, BoxSize, BoxSize );
321 p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 ); 324 p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 );
322 p->setPen( darkGreen ); 325 p->setPen( darkGreen );
323 x += 1; 326 x += 1;
324 y += 1; 327 y += 1;
325 if ( task.isCompleted() ) { 328 if ( task.isCompleted() ) {
326 QPointArray a( 9*2 ); 329 QPointArray a( 9*2 );
327 int i, xx, yy; 330 int i, xx, yy;
328 xx = x+2+marg; 331 xx = x+2+marg;
329 yy = y+4; 332 yy = y+4;
330 for ( i=0; i<4; i++ ) { 333 for ( i=0; i<4; i++ ) {
331 a.setPoint( 2*i, xx, yy ); 334 a.setPoint( 2*i, xx, yy );
332 a.setPoint( 2*i+1, xx, yy+2 ); 335 a.setPoint( 2*i+1, xx, yy+2 );
333 xx++; yy++; 336 xx++; yy++;
334 } 337 }
335 yy -= 2; 338 yy -= 2;
336 for ( i=4; i<9; i++ ) { 339 for ( i=4; i<9; i++ ) {
337 a.setPoint( 2*i, xx, yy ); 340 a.setPoint( 2*i, xx, yy );
338 a.setPoint( 2*i+1, xx, yy+2 ); 341 a.setPoint( 2*i+1, xx, yy+2 );
339 xx++; yy--; 342 xx++; yy--;
340 } 343 }
341 p->drawLineSegments( a ); 344 p->drawLineSegments( a );
342 } 345 }
343 } 346 }
344 break; 347 break;
345 case 1: 348 case 1:
346 // priority field 349 // priority field
347 { 350 {
348 QString text = QString::number(task.priority()); 351 QString text = QString::number(task.priority());
349 p->drawText(2,2 + fm.ascent(), text); 352 p->drawText(2,2 + fm.ascent(), text);
350 } 353 }
351 break; 354 break;
352 case 2: 355 case 2:
353 // description field 356 // description field
354 { 357 {
355 QString text = task.summary().isEmpty() ? 358 QString text = task.summary().isEmpty() ?
356 task.description() : 359 task.description() :
357 task.summary(); 360 task.summary();
358 p->drawText(2,2 + fm.ascent(), text); 361 p->drawText(2,2 + fm.ascent(), text);
359 } 362 }
360 break; 363 break;
361 case 3: 364 case 3:
362 { 365 {
363 QString text; 366 QString text;
364 if (task.hasDueDate()) { 367 if (task.hasDueDate()) {
365 int off = QDate::currentDate().daysTo( task.dueDate() ); 368 int off = QDate::currentDate().daysTo( task.dueDate() );
366 text = QString::number(off) + tr(" day(s)"); 369 text = QString::number(off) + tr(" day(s)");
367 /* 370 /*
368 * set color if not completed 371 * set color if not completed
369 */ 372 */
370 if (!task.isCompleted() ) { 373 if (!task.isCompleted() ) {
371 QColor color = Qt::black; 374 QColor color = Qt::black;
372 if ( off < 0 ) 375 if ( off < 0 )
373 color = Qt::red; 376 color = Qt::red;
374 else if ( off == 0 ) 377 else if ( off == 0 )
375 color = Qt::yellow; 378 color = Qt::yellow;
376 else if ( off > 0 ) 379 else if ( off > 0 )
377 color = Qt::green; 380 color = Qt::green;
378 p->setPen(color ); 381 p->setPen(color );
379 } 382 }
380 } else { 383 } else {
381 text = tr("None"); 384 text = tr("None");
382 } 385 }
383 p->drawText(2,2 + fm.ascent(), text); 386 p->drawText(2,2 + fm.ascent(), text);
384 } 387 }
385 break; 388 break;
386 } 389 }
387 p->restore(); 390 p->restore();
388} 391}
389QWidget* TableView::createEditor(int row, int col, bool )const { 392QWidget* TableView::createEditor(int row, int col, bool )const {
390 switch( col ) { 393 switch( col ) {
391 case 1: { 394 case 1: {
392 /* the priority stuff */ 395 /* the priority stuff */
393 QComboBox* combo = new QComboBox( viewport() ); 396 QComboBox* combo = new QComboBox( viewport() );
394 combo->insertItem( "1" ); 397 combo->insertItem( "1" );
395 combo->insertItem( "2" ); 398 combo->insertItem( "2" );
396 combo->insertItem( "3" ); 399 combo->insertItem( "3" );
397 combo->insertItem( "4" ); 400 combo->insertItem( "4" );
398 combo->insertItem( "5" ); 401 combo->insertItem( "5" );
399 combo->setCurrentItem( sorted()[row].priority()-1 ); 402 combo->setCurrentItem( sorted()[row].priority()-1 );
400 return combo; 403 return combo;
401 } 404 }
405 /* summary */
406 case 2:{
407 QLineEdit* edit = new QLineEdit( viewport() );
408 edit->setText( sorted()[row].summary() );
409 return edit;
410 }
402 case 0: 411 case 0:
403 default: 412 default:
404 return 0l; 413 return 0l;
405 } 414 }
406} 415}
407void TableView::setCellContentFromEditor(int row, int col ) { 416void TableView::setCellContentFromEditor(int row, int col ) {
408 if ( col == 1 ) { 417 if ( col == 1 ) {
409 QWidget* wid = cellWidget(row, 1 ); 418 QWidget* wid = cellWidget(row, 1 );
410 if ( wid->inherits("QComboBox") ) { 419 if ( wid->inherits("QComboBox") ) {
411 int pri = ((QComboBox*)wid)->currentItem() + 1; 420 int pri = ((QComboBox*)wid)->currentItem() + 1;
412 OTodo todo = sorted()[row]; 421 OTodo todo = sorted()[row];
413 if ( todo.priority() != pri ) { 422 if ( todo.priority() != pri ) {
414 todo.setPriority( pri ); 423 todo.setPriority( pri );
415 TodoView::update( todo.uid(), todo ); 424 TodoView::update( todo.uid(), todo );
416 updateView(); 425 updateView();
417 } 426 }
418 } 427 }
428 }else if ( col == 2) {
429 QWidget* wid = cellWidget(row, 2);
430 if ( wid->inherits("QLineEdit") ) {
431 QString text = ((QLineEdit*)wid)->text();
432 OTodo todo = sorted()[row];
433 if ( todo.summary() != text ) {
434 todo.setSummary( text );
435 TodoView::update( todo.uid(), todo );
436 updateView();
437 }
438 }
419 } 439 }
420} 440}
421void TableView::slotPriority() { 441void TableView::slotPriority() {
422 setCellContentFromEditor( currentRow(), currentColumn() ); 442 setCellContentFromEditor( currentRow(), currentColumn() );
423} 443}
424/* 444/*
425 * We'll use the TimerEvent to read ahead or to keep the cahce always 445 * We'll use the TimerEvent to read ahead or to keep the cahce always
426 * filled enough. 446 * filled enough.
427 * We will try to read ahead 4 items in both ways 447 * We will try to read ahead 4 items in both ways
428 * up and down. On odd or even we will currentRow()+-4 or +-9 448 * up and down. On odd or even we will currentRow()+-4 or +-9
429 * 449 *
430 */ 450 */
431void TableView::timerEvent( QTimerEvent* ev ) { 451void TableView::timerEvent( QTimerEvent* ev ) {
452 qWarning("sorted %d", sorted().count() );
432 if (sorted().count() == 0 ) 453 if (sorted().count() == 0 )
433 return; 454 return;
434 455
435 int row = currentRow(); 456 int row = currentRow();
436 if ( m_row ) { 457 if ( m_row ) {
437 int ro = row-4; 458 int ro = row-4;
438 if (ro < 0 ) ro = 0; 459 if (ro < 0 ) ro = 0;
439 sorted()[ro]; 460 sorted()[ro];
440 461
441 ro = row+4; 462 ro = row+4;
442 sorted()[ro]; 463 sorted()[ro];
443 } else { 464 } else {
444 int ro = row + 8; 465 int ro = row + 8;
445 sorted()[ro]; 466 sorted()[ro];
446 467
447 ro = row-8; 468 ro = row-8;
448 if (ro < 0 ) ro = 0; 469 if (ro < 0 ) ro = 0;
449 sorted()[ro]; 470 sorted()[ro];
450 } 471 }
451 472
452 m_row = !m_row; 473 m_row = !m_row;
453} 474}
454 475
455// We want a strike through completed ;) 476// We want a strike through completed ;)
456// durchstreichen to complete 477// durchstreichen to complete
457/* 478/*
458 * MouseTracking is off this mean we only receive 479 * MouseTracking is off this mean we only receive
459 * these events if the mouse button is pressed 480 * these events if the mouse button is pressed
460 * We've the previous point saved 481 * We've the previous point saved
461 * We check if the previous and current Point are 482 * We check if the previous and current Point are
462 * in the same row. 483 * in the same row.
463 * Then we check if they're some pixel horizontal away 484 * Then we check if they're some pixel horizontal away
464 * if the distance between the two points is greater than 485 * if the distance between the two points is greater than
465 * 8 we mark the underlying todo as completed and do a repaint 486 * 8 we mark the underlying todo as completed and do a repaint
466 */ 487 */
467void TableView::contentsMouseReleaseEvent( QMouseEvent* e) { 488void TableView::contentsMouseReleaseEvent( QMouseEvent* e) {
468 int row = rowAt(m_prevP.y()); 489 int row = rowAt(m_prevP.y());
469 if ( row == rowAt( e->y() ) ) { 490 if ( row == rowAt( e->y() ) && row != -1 ) {
470 if ( abs( m_prevP.x() - e->x() ) >= 8 ) { 491 if ( abs( m_prevP.x() - e->x() ) >= 8 ) {
492 qWarning("current row %d", row );
471 OTodo todo = sorted()[row]; 493 OTodo todo = sorted()[row];
472 todo.setCompleted( !todo.isCompleted() ); 494 todo.setCompleted( !todo.isCompleted() );
473 TodoView::update( todo.uid(), todo ); 495 TodoView::update( todo.uid(), todo );
474 updateView(); 496 updateView();
475 return; 497 return;
476 } 498 }
477 } 499 }
478 QTable::contentsMouseReleaseEvent( e ); 500 QTable::contentsMouseReleaseEvent( e );
479} 501}
480void TableView::contentsMouseMoveEvent( QMouseEvent* e ) { 502void TableView::contentsMouseMoveEvent( QMouseEvent* e ) {
481 m_menuTimer->stop(); 503 m_menuTimer->stop();
482 QTable::contentsMouseMoveEvent( e ); 504 QTable::contentsMouseMoveEvent( e );
483} 505}