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,164 +1,167 @@
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() {
101 clear(); 104 clear();
102 updateView(); 105 updateView();
103} 106}
104TableView::~TableView() { 107TableView::~TableView() {
105 108
106} 109}
107void TableView::slotShowMenu() { 110void TableView::slotShowMenu() {
108 QPopupMenu *menu = todoWindow()->contextMenu( current() ); 111 QPopupMenu *menu = todoWindow()->contextMenu( current() );
109 menu->exec(QCursor::pos() ); 112 menu->exec(QCursor::pos() );
110 delete menu; 113 delete menu;
111} 114}
112QString TableView::type() const { 115QString TableView::type() const {
113 return QString::fromLatin1( tr("Table View") ); 116 return QString::fromLatin1( tr("Table View") );
114} 117}
115int TableView::current() { 118int TableView::current() {
116 int uid = sorted().uidAt(currentRow() ); 119 int uid = sorted().uidAt(currentRow() );
117 qWarning("uid %d", uid ); 120 qWarning("uid %d", uid );
118 return uid; 121 return uid;
119} 122}
120QString TableView::currentRepresentation() { 123QString TableView::currentRepresentation() {
121 return text( currentRow(), 2); 124 return text( currentRow(), 2);
122} 125}
123/* show overdue */ 126/* show overdue */
124void TableView::showOverDue( bool ) { 127void TableView::showOverDue( bool ) {
125 clear(); 128 clear();
126 updateView(); 129 updateView();
127} 130}
128 131
129void TableView::updateView( ) { 132void TableView::updateView( ) {
130 qWarning("update view"); 133 qWarning("update view");
131 m_row = false; 134 m_row = false;
132 static int id; 135 static int id;
133 id = startTimer(2000 ); 136 id = startTimer(2000 );
134 /* FIXME we want one page to be read! 137 /* FIXME we want one page to be read!
135 * 138 *
136 * Calculate that screensize 139 * Calculate that screensize
137 */ 140 */
138 todoWindow()->setReadAhead( 4 ); 141 todoWindow()->setReadAhead( 4 );
139 sort(); 142 sort();
140 OTodoAccess::List::Iterator it, end; 143 OTodoAccess::List::Iterator it, end;
141 it = sorted().begin(); 144 it = sorted().begin();
142 end = sorted().end(); 145 end = sorted().end();
143 146
144 qWarning("setTodos"); 147 qWarning("setTodos");
145 QTime time; 148 QTime time;
146 time.start(); 149 time.start();
147 m_enablePaint = false; 150 m_enablePaint = false;
148 setUpdatesEnabled( false ); 151 setUpdatesEnabled( false );
149 viewport()->setUpdatesEnabled( false ); 152 viewport()->setUpdatesEnabled( false );
150 153
151 setNumRows( it.count() ); 154 setNumRows( it.count() );
152 if ( it.count() == 0 ) 155 if ( it.count() == 0 )
153 killTimer(id); 156 killTimer(id);
154 157
155 int elc = time.elapsed(); 158 int elc = time.elapsed();
156 setUpdatesEnabled( true ); 159 setUpdatesEnabled( true );
157 viewport()->setUpdatesEnabled( true ); 160 viewport()->setUpdatesEnabled( true );
158 viewport()->update(); 161 viewport()->update();
159 162
160 m_enablePaint = true; 163 m_enablePaint = true;
161 int el = time.elapsed(); 164 int el = time.elapsed();
162} 165}
163void TableView::setTodo( int, const OTodo&) { 166void TableView::setTodo( int, const OTodo&) {
164 sort(); 167 sort();
@@ -218,266 +221,285 @@ void TableView::slotClicked(int row, int col, int,
218 221
219 222
220 switch( col ) { 223 switch( col ) {
221 case 0:{ 224 case 0:{
222 int x = point.x() -columnPos( col ); 225 int x = point.x() -columnPos( col );
223 int y = point.y() -rowPos( row ); 226 int y = point.y() -rowPos( row );
224 int w = columnWidth( col ); 227 int w = columnWidth( col );
225 int h = rowHeight( row ); 228 int h = rowHeight( row );
226 if ( x >= ( w - BoxSize ) / 2 && 229 if ( x >= ( w - BoxSize ) / 2 &&
227 x <= ( w - BoxSize ) / 2 + BoxSize && 230 x <= ( w - BoxSize ) / 2 + BoxSize &&
228 y >= ( h - BoxSize ) / 2 && 231 y >= ( h - BoxSize ) / 2 &&
229 y <= ( h - BoxSize ) / 2 + BoxSize ) { 232 y <= ( h - BoxSize ) / 2 + BoxSize ) {
230 OTodo todo = sorted()[row]; 233 OTodo todo = sorted()[row];
231 todo.setCompleted( !todo.isCompleted() ); 234 todo.setCompleted( !todo.isCompleted() );
232 TodoView::update( todo.uid(), todo ); 235 TodoView::update( todo.uid(), todo );
233 updateView(); 236 updateView();
234 } 237 }
235 } 238 }
236 break; 239 break;
237 240
238 case 1: 241 case 1:
239 break; 242 break;
240 243
241 case 2: { 244 case 2: {
242 m_menuTimer->stop(); 245 m_menuTimer->stop();
243 showTodo( ui ); 246 showTodo( ui );
244 break; 247 break;
245 } 248 }
246 case 3: { 249 case 3: {
247 m_menuTimer->stop(); 250 m_menuTimer->stop();
248 TodoView::edit( ui ); 251 TodoView::edit( ui );
249 break; 252 break;
250 } 253 }
251 } 254 }
252 255
253 256
254} 257}
255void TableView::slotPressed(int row, int col, int, 258void TableView::slotPressed(int row, int col, int,
256 const QPoint& point) { 259 const QPoint& point) {
257 260
258 m_prevP = point; 261 m_prevP = point;
259 /* TextColumn column */ 262 /* TextColumn column */
260 if ( col == 2 && cellGeometry( row, col ).contains( point ) ) 263 if ( col == 2 && cellGeometry( row, col ).contains( point ) )
261 m_menuTimer->start( 750, TRUE ); 264 m_menuTimer->start( 750, TRUE );
262} 265}
263void TableView::slotValueChanged( int, int ) { 266void TableView::slotValueChanged( int, int ) {
264 qWarning("Value Changed"); 267 qWarning("Value Changed");
265} 268}
266void TableView::slotCurrentChanged(int, int ) { 269void TableView::slotCurrentChanged(int, int ) {
267 m_menuTimer->stop(); 270 m_menuTimer->stop();
268} 271}
269QWidget* TableView::widget() { 272QWidget* TableView::widget() {
270 return this; 273 return this;
271} 274}
272/* 275/*
273 * We need to overwrite sortColumn 276 * We need to overwrite sortColumn
274 * because we want to sort whole row 277 * because we want to sort whole row
275 * based 278 * based
276 * We event want to set the setOrder 279 * We event want to set the setOrder
277 * to a sort() and update() 280 * to a sort() and update()
278 */ 281 */
279void TableView::sortColumn( int col, bool asc, bool ) { 282void TableView::sortColumn( int col, bool asc, bool ) {
280 qWarning("bool %d", asc ); 283 qWarning("bool %d", asc );
281 setSortOrder( col ); 284 setSortOrder( col );
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}