summaryrefslogtreecommitdiff
authorzecke <zecke>2002-10-23 21:07:13 (UTC)
committer zecke <zecke>2002-10-23 21:07:13 (UTC)
commit71f52c08e595cb3bfa3697baa97b4279325fa9ac (patch) (unidiff)
treec33c935ea2da643c5c08ef564898a76a66ebd951
parent60bd9ae80a48f1e2bbd1e1d75a53de0039e979d0 (diff)
downloadopie-71f52c08e595cb3bfa3697baa97b4279325fa9ac.zip
opie-71f52c08e595cb3bfa3697baa97b4279325fa9ac.tar.gz
opie-71f52c08e595cb3bfa3697baa97b4279325fa9ac.tar.bz2
Fix not beeing resizable.. now the Deadline is too wide...
Fix a crash when being somewhere else but releasing the mouse over the table bug Fix one more thing I don't remember Add InlineEditing of summaries. It would actually work on double click but we use the single click for viewing.. Ok these things need to be configurable
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
@@ -24,12 +24,13 @@
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"
@@ -50,25 +51,27 @@ TableView::TableView( MainWindow* window, QWidget* wid )
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 );
@@ -308,84 +311,84 @@ void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool
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: {
@@ -396,12 +399,18 @@ QWidget* TableView::createEditor(int row, int col, bool )const {
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 ) {
@@ -413,12 +422,23 @@ void TableView::setCellContentFromEditor(int row, int col ) {
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/*
@@ -426,12 +446,13 @@ void TableView::slotPriority() {
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;
@@ -463,14 +484,15 @@ void TableView::timerEvent( QTimerEvent* ev ) {
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 }