summaryrefslogtreecommitdiff
authorzecke <zecke>2002-10-20 12:10:31 (UTC)
committer zecke <zecke>2002-10-20 12:10:31 (UTC)
commit7948b5910a098d05f4cc7d0fb14b0f216bf41358 (patch) (unidiff)
treec7765042be7eb4373ea90145f1e218fee0cd1c3a
parent940ba90ed4375f79b6a4934d290abf83980b77ad (diff)
downloadopie-7948b5910a098d05f4cc7d0fb14b0f216bf41358.zip
opie-7948b5910a098d05f4cc7d0fb14b0f216bf41358.tar.gz
opie-7948b5910a098d05f4cc7d0fb14b0f216bf41358.tar.bz2
Strike through a row to complete the Record ;)^
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/tableview.cpp39
-rw-r--r--core/pim/todo/tableview.h3
2 files changed, 36 insertions, 6 deletions
diff --git a/core/pim/todo/tableview.cpp b/core/pim/todo/tableview.cpp
index 34b8b3c..c4165db 100644
--- a/core/pim/todo/tableview.cpp
+++ b/core/pim/todo/tableview.cpp
@@ -1,456 +1,483 @@
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 29
29#include <qtimer.h> 30#include <qtimer.h>
30#include <qpoint.h> 31#include <qpoint.h>
31#include <qpopupmenu.h> 32#include <qpopupmenu.h>
32 33
33#include "mainwindow.h" 34#include "mainwindow.h"
34//#include "tableitems.h" 35//#include "tableitems.h"
35#include "tableview.h" 36#include "tableview.h"
36 37
37using namespace Todo; 38using namespace Todo;
38 39
39namespace { 40namespace {
40 static const int BoxSize = 14; 41 static const int BoxSize = 14;
41 static const int RowHeight = 20; 42 static const int RowHeight = 20;
42} 43}
43 44
44 45
45TableView::TableView( MainWindow* window, QWidget* wid ) 46TableView::TableView( MainWindow* window, QWidget* wid )
46 : QTable( wid ), TodoView( window ) { 47 : QTable( wid ), TodoView( window ) {
47 setUpdatesEnabled( false ); 48 setUpdatesEnabled( false );
48 viewport()->setUpdatesEnabled( false ); 49 viewport()->setUpdatesEnabled( false );
49 m_enablePaint = false; 50 m_enablePaint = false;
50 setNumRows(0); 51 setNumRows(0);
51 setNumCols(4); 52 setNumCols(4);
52 53
53 setSorting( TRUE ); 54 setSorting( TRUE );
54 setSelectionMode( NoSelection ); 55 setSelectionMode( NoSelection );
55 setColumnStretchable( 2, TRUE ); 56 setColumnStretchable( 2, TRUE );
56 setColumnWidth(0, 20 ); 57 setColumnWidth(0, 20 );
57 setColumnWidth(1, 35 ); 58 setColumnWidth(1, 35 );
58 59
59 setLeftMargin( 0 ); 60 setLeftMargin( 0 );
60 verticalHeader()->hide(); 61 verticalHeader()->hide();
61 62
62 horizontalHeader()->setLabel(0, tr("C.") ); 63 horizontalHeader()->setLabel(0, tr("C.") );
63 horizontalHeader()->setLabel(1, tr("Prior.") ); 64 horizontalHeader()->setLabel(1, tr("Prior.") );
64 horizontalHeader()->setLabel(2, tr("Description" ) ); 65 horizontalHeader()->setLabel(2, tr("Description" ) );
65 66
66 setColumnStretchable(3, FALSE ); 67 setColumnStretchable(3, FALSE );
67 setColumnWidth(3, 20 ); 68 setColumnWidth(3, 20 );
68 horizontalHeader()->setLabel(3, tr("Deadline") ); 69 horizontalHeader()->setLabel(3, tr("Deadline") );
69 70
70 if ( todoWindow()->showDeadline() ) 71 if ( todoWindow()->showDeadline() )
71 showColumn( 3); 72 showColumn( 3);
72 else 73 else
73 hideColumn(3 ); 74 hideColumn(3 );
74 75
75 connect((QTable*)this, SIGNAL( clicked( int, int, int, const QPoint& ) ), 76 connect((QTable*)this, SIGNAL( clicked( int, int, int, const QPoint& ) ),
76 this, SLOT( slotClicked(int, int, int, const QPoint& ) ) ); 77 this, SLOT( slotClicked(int, int, int, const QPoint& ) ) );
77 connect((QTable*)this, SIGNAL( pressed( int, int, int, const QPoint& ) ), 78 connect((QTable*)this, SIGNAL( pressed( int, int, int, const QPoint& ) ),
78 this, SLOT( slotPressed(int, int, int, const QPoint& ) ) ); 79 this, SLOT( slotPressed(int, int, int, const QPoint& ) ) );
79 connect((QTable*)this, SIGNAL(valueChanged(int, int) ), 80 connect((QTable*)this, SIGNAL(valueChanged(int, int) ),
80 this, SLOT( slotValueChanged(int, int) ) ); 81 this, SLOT( slotValueChanged(int, int) ) );
81 connect((QTable*)this, SIGNAL(currentChanged(int, int) ), 82 connect((QTable*)this, SIGNAL(currentChanged(int, int) ),
82 this, SLOT( slotCurrentChanged(int, int) ) ); 83 this, SLOT( slotCurrentChanged(int, int) ) );
83 84
84 m_menuTimer = new QTimer( this ); 85 m_menuTimer = new QTimer( this );
85 connect( m_menuTimer, SIGNAL(timeout()), 86 connect( m_menuTimer, SIGNAL(timeout()),
86 this, SLOT(slotShowMenu()) ); 87 this, SLOT(slotShowMenu()) );
87 88
88 m_enablePaint = true; 89 m_enablePaint = true;
89 setUpdatesEnabled( true ); 90 setUpdatesEnabled( true );
90 viewport()->setUpdatesEnabled( true ); 91 viewport()->setUpdatesEnabled( true );
91 viewport()->update(); 92 viewport()->update();
92 setSortOrder( 0 ); 93 setSortOrder( 0 );
93 setAscending( TRUE ); 94 setAscending( TRUE );
94 m_first = true; 95 m_first = true;
95} 96}
96/* a new day has started 97/* a new day has started
97 * update the day 98 * update the day
98 */ 99 */
99void TableView::newDay() { 100void TableView::newDay() {
100 clear(); 101 clear();
101 updateView(); 102 updateView();
102} 103}
103TableView::~TableView() { 104TableView::~TableView() {
104 105
105} 106}
106void TableView::slotShowMenu() { 107void TableView::slotShowMenu() {
107 QPopupMenu *menu = todoWindow()->contextMenu( current() ); 108 QPopupMenu *menu = todoWindow()->contextMenu( current() );
108 menu->exec(QCursor::pos() ); 109 menu->exec(QCursor::pos() );
109 delete menu; 110 delete menu;
110} 111}
111QString TableView::type() const { 112QString TableView::type() const {
112 return QString::fromLatin1( tr("Table View") ); 113 return QString::fromLatin1( tr("Table View") );
113} 114}
114int TableView::current() { 115int TableView::current() {
115 int uid = sorted().uidAt(currentRow() ); 116 int uid = sorted().uidAt(currentRow() );
116 qWarning("uid %d", uid ); 117 qWarning("uid %d", uid );
117 return uid; 118 return uid;
118} 119}
119QString TableView::currentRepresentation() { 120QString TableView::currentRepresentation() {
120 return text( currentRow(), 2); 121 return text( currentRow(), 2);
121} 122}
122/* show overdue */ 123/* show overdue */
123void TableView::showOverDue( bool ) { 124void TableView::showOverDue( bool ) {
124 clear(); 125 clear();
125 updateView(); 126 updateView();
126} 127}
127 128
128void TableView::updateView( ) { 129void TableView::updateView( ) {
129 qWarning("update view"); 130 qWarning("update view");
130 m_row = false; 131 m_row = false;
131 static int id; 132 static int id;
132 id = startTimer(2000 ); 133 id = startTimer(2000 );
133 /* FIXME we want one page to be read! 134 /* FIXME we want one page to be read!
134 * 135 *
135 * Calculate that screensize 136 * Calculate that screensize
136 */ 137 */
137 todoWindow()->setReadAhead( 4 ); 138 todoWindow()->setReadAhead( 4 );
138 sort(); 139 sort();
139 OTodoAccess::List::Iterator it, end; 140 OTodoAccess::List::Iterator it, end;
140 it = sorted().begin(); 141 it = sorted().begin();
141 end = sorted().end(); 142 end = sorted().end();
142 143
143 qWarning("setTodos"); 144 qWarning("setTodos");
144 QTime time; 145 QTime time;
145 time.start(); 146 time.start();
146 m_enablePaint = false; 147 m_enablePaint = false;
147 setUpdatesEnabled( false ); 148 setUpdatesEnabled( false );
148 viewport()->setUpdatesEnabled( false ); 149 viewport()->setUpdatesEnabled( false );
149 150
150 QTime t;
151 t.start();
152 setNumRows( it.count() ); 151 setNumRows( it.count() );
153 if ( it.count() == 0 ) 152 if ( it.count() == 0 )
154 killTimer(id); 153 killTimer(id);
154
155 int elc = time.elapsed(); 155 int elc = time.elapsed();
156 qWarning("Adding took %d", elc/1000 );
157 setUpdatesEnabled( true ); 156 setUpdatesEnabled( true );
158 viewport()->setUpdatesEnabled( true ); 157 viewport()->setUpdatesEnabled( true );
159 viewport()->update(); 158 viewport()->update();
160 159
161 m_enablePaint = true; 160 m_enablePaint = true;
162 int el = time.elapsed(); 161 int el = time.elapsed();
163 qWarning("adding took %d", el/1000 );
164} 162}
165void TableView::setTodo( int, const OTodo&) { 163void TableView::setTodo( int, const OTodo&) {
166 sort(); 164 sort();
167 165
168 /* repaint */ 166 /* repaint */
169 repaint(); 167 repaint();
170} 168}
171void TableView::addEvent( const OTodo&) { 169void TableView::addEvent( const OTodo&) {
172 170
173 /* fix problems of not showing the 'Haken' */ 171 /* fix problems of not showing the 'Haken' */
174 updateView(); 172 updateView();
175} 173}
176/* 174/*
177 * find the event 175 * find the event
178 * and then replace the complete row 176 * and then replace the complete row
179 */ 177 */
180void TableView::replaceEvent( const OTodo& ev) { 178void TableView::replaceEvent( const OTodo& ev) {
181 addEvent( ev ); 179 addEvent( ev );
182} 180}
183/* 181/*
184 * re aligning table can be slow too 182 * re aligning table can be slow too
185 * FIXME: look what performs better 183 * FIXME: look what performs better
186 * either this or the old align table 184 * either this or the old align table
187 */ 185 */
188void TableView::removeEvent( int ) { 186void TableView::removeEvent( int ) {
189 updateView(); 187 updateView();
190} 188}
191void TableView::setShowCompleted( bool b) { 189void TableView::setShowCompleted( bool b) {
192 qWarning("Show Completed %d" + b ); 190 qWarning("Show Completed %d" + b );
193 updateView(); 191 updateView();
194} 192}
195void TableView::setShowDeadline( bool b) { 193void TableView::setShowDeadline( bool b) {
196 qWarning("Show DeadLine %d" + b ); 194 qWarning("Show DeadLine %d" + b );
197 if (b) 195 if (b)
198 showColumn(3 ); 196 showColumn(3 );
199 else 197 else
200 hideColumn(3 ); 198 hideColumn(3 );
201} 199}
202void TableView::setShowCategory( const QString& str) { 200void TableView::setShowCategory( const QString& str) {
203 qWarning("setShowCategory"); 201 qWarning("setShowCategory");
204 if ( str != m_oleCat || m_first ) 202 if ( str != m_oleCat || m_first )
205 updateView(); 203 updateView();
206 204
207 m_oleCat = str; 205 m_oleCat = str;
208 m_first = false; 206 m_first = false;
209 207
210} 208}
211void TableView::clear() { 209void TableView::clear() {
212 setNumRows(0); 210 setNumRows(0);
213} 211}
214void TableView::slotClicked(int row, int col, int, 212void TableView::slotClicked(int row, int col, int,
215 const QPoint& point) { 213 const QPoint& point) {
216 if ( !cellGeometry(row, col ).contains(point ) ) 214 if ( !cellGeometry(row, col ).contains(point ) )
217 return; 215 return;
218 216
219 int ui= sorted().uidAt( row ); 217 int ui= sorted().uidAt( row );
220 218
221 219
222 switch( col ) { 220 switch( col ) {
223 case 0:{ 221 case 0:{
224 int x = point.x() -columnPos( col ); 222 int x = point.x() -columnPos( col );
225 int y = point.y() -rowPos( row ); 223 int y = point.y() -rowPos( row );
226 int w = columnWidth( col ); 224 int w = columnWidth( col );
227 int h = rowHeight( row ); 225 int h = rowHeight( row );
228 if ( x >= ( w - BoxSize ) / 2 && 226 if ( x >= ( w - BoxSize ) / 2 &&
229 x <= ( w - BoxSize ) / 2 + BoxSize && 227 x <= ( w - BoxSize ) / 2 + BoxSize &&
230 y >= ( h - BoxSize ) / 2 && 228 y >= ( h - BoxSize ) / 2 &&
231 y <= ( h - BoxSize ) / 2 + BoxSize ) { 229 y <= ( h - BoxSize ) / 2 + BoxSize ) {
232 OTodo todo = sorted()[row]; 230 OTodo todo = sorted()[row];
233 todo.setCompleted( !todo.isCompleted() ); 231 todo.setCompleted( !todo.isCompleted() );
234 TodoView::update( todo.uid(), todo ); 232 TodoView::update( todo.uid(), todo );
235 updateView(); 233 updateView();
236 } 234 }
237 } 235 }
238 break; 236 break;
239 237
240 case 1: 238 case 1:
241 break; 239 break;
242 240
243 case 2: { 241 case 2: {
244 m_menuTimer->stop(); 242 m_menuTimer->stop();
245 showTodo( ui ); 243 showTodo( ui );
246 break; 244 break;
247 } 245 }
248 case 3: { 246 case 3: {
249 m_menuTimer->stop(); 247 m_menuTimer->stop();
250 TodoView::edit( ui ); 248 TodoView::edit( ui );
251 break; 249 break;
252 } 250 }
253 } 251 }
254 252
255 253
256} 254}
257void TableView::slotPressed(int row, int col, int, 255void TableView::slotPressed(int row, int col, int,
258 const QPoint& point) { 256 const QPoint& point) {
259 257
258 m_prevP = point;
260 /* TextColumn column */ 259 /* TextColumn column */
261 if ( col == 2 && cellGeometry( row, col ).contains( point ) ) 260 if ( col == 2 && cellGeometry( row, col ).contains( point ) )
262 m_menuTimer->start( 750, TRUE ); 261 m_menuTimer->start( 750, TRUE );
263} 262}
264void TableView::slotValueChanged( int, int ) { 263void TableView::slotValueChanged( int, int ) {
265 qWarning("Value Changed"); 264 qWarning("Value Changed");
266} 265}
267void TableView::slotCurrentChanged(int, int ) { 266void TableView::slotCurrentChanged(int, int ) {
268 m_menuTimer->stop(); 267 m_menuTimer->stop();
269} 268}
270QWidget* TableView::widget() { 269QWidget* TableView::widget() {
271 return this; 270 return this;
272} 271}
273/* 272/*
274 * We need to overwrite sortColumn 273 * We need to overwrite sortColumn
275 * because we want to sort whole row 274 * because we want to sort whole row
276 * based 275 * based
277 * We event want to set the setOrder 276 * We event want to set the setOrder
278 * to a sort() and update() 277 * to a sort() and update()
279 */ 278 */
280void TableView::sortColumn( int col, bool asc, bool ) { 279void TableView::sortColumn( int col, bool asc, bool ) {
281 qWarning("bool %d", asc ); 280 qWarning("bool %d", asc );
282 setSortOrder( col ); 281 setSortOrder( col );
283 setAscending( asc ); 282 setAscending( asc );
284 updateView(); 283 updateView();
285} 284}
286void TableView::viewportPaintEvent( QPaintEvent* e) { 285void TableView::viewportPaintEvent( QPaintEvent* e) {
287 qWarning("Paint event" );
288 if (m_enablePaint ) 286 if (m_enablePaint )
289 QTable::viewportPaintEvent( e ); 287 QTable::viewportPaintEvent( e );
290} 288}
291/* 289/*
292 * This segment is copyrighted by TT 290 * This segment is copyrighted by TT
293 * it was taken from their todolist 291 * it was taken from their todolist
294 * application this code is GPL 292 * application this code is GPL
295 */ 293 */
296void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) { 294void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) {
297 const QColorGroup &cg = colorGroup(); 295 const QColorGroup &cg = colorGroup();
298 296
299 p->save(); 297 p->save();
300 298
301 OTodo task = sorted()[row]; 299 OTodo task = sorted()[row];
302 300
303 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); 301 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
304 302
305 QPen op = p->pen(); 303 QPen op = p->pen();
306 p->setPen(cg.mid()); 304 p->setPen(cg.mid());
307 p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 ); 305 p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 );
308 p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 ); 306 p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 );
309 p->setPen(op); 307 p->setPen(op);
310 308
311 QFont f = p->font(); 309 QFont f = p->font();
312 QFontMetrics fm(f); 310 QFontMetrics fm(f);
313 311
314 switch(col) { 312 switch(col) {
315 case 0: 313 case 0:
316 { 314 {
317 // completed field 315 // completed field
318 int marg = ( cr.width() - BoxSize ) / 2; 316 int marg = ( cr.width() - BoxSize ) / 2;
319 int x = 0; 317 int x = 0;
320 int y = ( cr.height() - BoxSize ) / 2; 318 int y = ( cr.height() - BoxSize ) / 2;
321 p->setPen( QPen( cg.text() ) ); 319 p->setPen( QPen( cg.text() ) );
322 p->drawRect( x + marg, y, BoxSize, BoxSize ); 320 p->drawRect( x + marg, y, BoxSize, BoxSize );
323 p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 ); 321 p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 );
324 p->setPen( darkGreen ); 322 p->setPen( darkGreen );
325 x += 1; 323 x += 1;
326 y += 1; 324 y += 1;
327 if ( task.isCompleted() ) { 325 if ( task.isCompleted() ) {
328 QPointArray a( 9*2 ); 326 QPointArray a( 9*2 );
329 int i, xx, yy; 327 int i, xx, yy;
330 xx = x+2+marg; 328 xx = x+2+marg;
331 yy = y+4; 329 yy = y+4;
332 for ( i=0; i<4; i++ ) { 330 for ( i=0; i<4; i++ ) {
333 a.setPoint( 2*i, xx, yy ); 331 a.setPoint( 2*i, xx, yy );
334 a.setPoint( 2*i+1, xx, yy+2 ); 332 a.setPoint( 2*i+1, xx, yy+2 );
335 xx++; yy++; 333 xx++; yy++;
336 } 334 }
337 yy -= 2; 335 yy -= 2;
338 for ( i=4; i<9; i++ ) { 336 for ( i=4; i<9; i++ ) {
339 a.setPoint( 2*i, xx, yy ); 337 a.setPoint( 2*i, xx, yy );
340 a.setPoint( 2*i+1, xx, yy+2 ); 338 a.setPoint( 2*i+1, xx, yy+2 );
341 xx++; yy--; 339 xx++; yy--;
342 } 340 }
343 p->drawLineSegments( a ); 341 p->drawLineSegments( a );
344 } 342 }
345 } 343 }
346 break; 344 break;
347 case 1: 345 case 1:
348 // priority field 346 // priority field
349 { 347 {
350 QString text = QString::number(task.priority()); 348 QString text = QString::number(task.priority());
351 p->drawText(2,2 + fm.ascent(), text); 349 p->drawText(2,2 + fm.ascent(), text);
352 } 350 }
353 break; 351 break;
354 case 2: 352 case 2:
355 // description field 353 // description field
356 { 354 {
357 QString text = task.summary().isEmpty() ? 355 QString text = task.summary().isEmpty() ?
358 task.description() : 356 task.description() :
359 task.summary(); 357 task.summary();
360 p->drawText(2,2 + fm.ascent(), text); 358 p->drawText(2,2 + fm.ascent(), text);
361 } 359 }
362 break; 360 break;
363 case 3: 361 case 3:
364 { 362 {
365 QString text; 363 QString text;
366 if (task.hasDueDate()) { 364 if (task.hasDueDate()) {
367 int off = QDate::currentDate().daysTo( task.dueDate() ); 365 int off = QDate::currentDate().daysTo( task.dueDate() );
368 text = QString::number(off) + tr(" day(s)"); 366 text = QString::number(off) + tr(" day(s)");
369 /* 367 /*
370 * set color if not completed 368 * set color if not completed
371 */ 369 */
372 if (!task.isCompleted() ) { 370 if (!task.isCompleted() ) {
373 QColor color = Qt::black; 371 QColor color = Qt::black;
374 if ( off < 0 ) 372 if ( off < 0 )
375 color = Qt::red; 373 color = Qt::red;
376 else if ( off == 0 ) 374 else if ( off == 0 )
377 color = Qt::yellow; 375 color = Qt::yellow;
378 else if ( off > 0 ) 376 else if ( off > 0 )
379 color = Qt::green; 377 color = Qt::green;
380 p->setPen(color ); 378 p->setPen(color );
381 } 379 }
382 } else { 380 } else {
383 text = tr("None"); 381 text = tr("None");
384 } 382 }
385 p->drawText(2,2 + fm.ascent(), text); 383 p->drawText(2,2 + fm.ascent(), text);
386 } 384 }
387 break; 385 break;
388 } 386 }
389 p->restore(); 387 p->restore();
390} 388}
391QWidget* TableView::createEditor(int row, int col, bool )const { 389QWidget* TableView::createEditor(int row, int col, bool )const {
392 switch( col ) { 390 switch( col ) {
393 case 1: { 391 case 1: {
394 /* the priority stuff */ 392 /* the priority stuff */
395 QComboBox* combo = new QComboBox( viewport() ); 393 QComboBox* combo = new QComboBox( viewport() );
396 combo->insertItem( "1" ); 394 combo->insertItem( "1" );
397 combo->insertItem( "2" ); 395 combo->insertItem( "2" );
398 combo->insertItem( "3" ); 396 combo->insertItem( "3" );
399 combo->insertItem( "4" ); 397 combo->insertItem( "4" );
400 combo->insertItem( "5" ); 398 combo->insertItem( "5" );
401 combo->setCurrentItem( sorted()[row].priority()-1 ); 399 combo->setCurrentItem( sorted()[row].priority()-1 );
402 return combo; 400 return combo;
403 } 401 }
404 case 0: 402 case 0:
405 default: 403 default:
406 return 0l; 404 return 0l;
407 } 405 }
408} 406}
409void TableView::setCellContentFromEditor(int row, int col ) { 407void TableView::setCellContentFromEditor(int row, int col ) {
410 if ( col == 1 ) { 408 if ( col == 1 ) {
411 QWidget* wid = cellWidget(row, 1 ); 409 QWidget* wid = cellWidget(row, 1 );
412 if ( wid->inherits("QComboBox") ) { 410 if ( wid->inherits("QComboBox") ) {
413 int pri = ((QComboBox*)wid)->currentItem() + 1; 411 int pri = ((QComboBox*)wid)->currentItem() + 1;
414 OTodo todo = sorted()[row]; 412 OTodo todo = sorted()[row];
415 if ( todo.priority() != pri ) { 413 if ( todo.priority() != pri ) {
416 todo.setPriority( pri ); 414 todo.setPriority( pri );
417 TodoView::update( todo.uid(), todo ); 415 TodoView::update( todo.uid(), todo );
418 updateView(); 416 updateView();
419 } 417 }
420 } 418 }
421 } 419 }
422} 420}
423void TableView::slotPriority() { 421void TableView::slotPriority() {
424 setCellContentFromEditor( currentRow(), currentColumn() ); 422 setCellContentFromEditor( currentRow(), currentColumn() );
425} 423}
426/* 424/*
427 * We'll use the TimerEvent to read ahead or to keep the cahce always 425 * We'll use the TimerEvent to read ahead or to keep the cahce always
428 * filled enough. 426 * filled enough.
429 * We will try to read ahead 4 items in both ways 427 * We will try to read ahead 4 items in both ways
430 * up and down. On odd or even we will currentRow()+-4 or +-9 428 * up and down. On odd or even we will currentRow()+-4 or +-9
431 * 429 *
432 */ 430 */
433void TableView::timerEvent( QTimerEvent* ev ) { 431void TableView::timerEvent( QTimerEvent* ev ) {
434 if (sorted().count() == 0 ) 432 if (sorted().count() == 0 )
435 return; 433 return;
436 434
437 int row = currentRow(); 435 int row = currentRow();
438 qWarning("TimerEvent %d", row);
439 if ( m_row ) { 436 if ( m_row ) {
440 int ro = row-4; 437 int ro = row-4;
441 if (ro < 0 ) ro = 0; 438 if (ro < 0 ) ro = 0;
442 sorted()[ro]; 439 sorted()[ro];
443 440
444 ro = row+4; 441 ro = row+4;
445 sorted()[ro]; 442 sorted()[ro];
446 } else { 443 } else {
447 int ro = row + 8; 444 int ro = row + 8;
448 sorted()[ro]; 445 sorted()[ro];
449 446
450 ro = row-8; 447 ro = row-8;
451 if (ro < 0 ) ro = 0; 448 if (ro < 0 ) ro = 0;
452 sorted()[ro]; 449 sorted()[ro];
453 } 450 }
454 451
455 m_row = !m_row; 452 m_row = !m_row;
456} 453}
454
455// We want a strike through completed ;)
456// durchstreichen to complete
457/*
458 * MouseTracking is off this mean we only receive
459 * these events if the mouse button is pressed
460 * We've the previous point saved
461 * We check if the previous and current Point are
462 * in the same row.
463 * Then we check if they're some pixel horizontal away
464 * if the distance between the two points is greater than
465 * 8 we mark the underlying todo as completed and do a repaint
466 */
467void TableView::contentsMouseReleaseEvent( QMouseEvent* e) {
468 int row = rowAt(m_prevP.y());
469 if ( row == rowAt( e->y() ) ) {
470 if ( abs( m_prevP.x() - e->x() ) >= 8 ) {
471 OTodo todo = sorted()[row];
472 todo.setCompleted( !todo.isCompleted() );
473 TodoView::update( todo.uid(), todo );
474 updateView();
475 return;
476 }
477 }
478 QTable::contentsMouseReleaseEvent( e );
479}
480void TableView::contentsMouseMoveEvent( QMouseEvent* e ) {
481 m_menuTimer->stop();
482 QTable::contentsMouseMoveEvent( e );
483}
diff --git a/core/pim/todo/tableview.h b/core/pim/todo/tableview.h
index fe65ca9..0c3e865 100644
--- a/core/pim/todo/tableview.h
+++ b/core/pim/todo/tableview.h
@@ -1,103 +1,106 @@
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 28
29#ifndef OPIE_TABLE_VIEW_H 29#ifndef OPIE_TABLE_VIEW_H
30#define OPIE_TABLE_VIEW_H 30#define OPIE_TABLE_VIEW_H
31 31
32#include <qtable.h> 32#include <qtable.h>
33#include <qmap.h> 33#include <qmap.h>
34 34
35#include "tableitems.h" 35#include "tableitems.h"
36#include "todoview.h" 36#include "todoview.h"
37 37
38class QTimer; 38class QTimer;
39 39
40namespace Todo { 40namespace Todo {
41 class CheckItem; 41 class CheckItem;
42 class DueTextItem; 42 class DueTextItem;
43 class TableView : public QTable, public TodoView { 43 class TableView : public QTable, public TodoView {
44 Q_OBJECT 44 Q_OBJECT
45 public: 45 public:
46 TableView( MainWindow*, QWidget* parent ); 46 TableView( MainWindow*, QWidget* parent );
47 ~TableView(); 47 ~TableView();
48 48
49 49
50 QString type()const; 50 QString type()const;
51 int current(); 51 int current();
52 QString currentRepresentation(); 52 QString currentRepresentation();
53 53
54 void clear(); 54 void clear();
55 void showOverDue( bool ); 55 void showOverDue( bool );
56 void updateView(); 56 void updateView();
57 void setTodo( int uid, const OTodo& ); 57 void setTodo( int uid, const OTodo& );
58 void addEvent( const OTodo& event ); 58 void addEvent( const OTodo& event );
59 void replaceEvent( const OTodo& ); 59 void replaceEvent( const OTodo& );
60 void removeEvent( int uid ); 60 void removeEvent( int uid );
61 void setShowCompleted( bool ); 61 void setShowCompleted( bool );
62 void setShowDeadline( bool ); 62 void setShowDeadline( bool );
63 63
64 void setShowCategory(const QString& =QString::null ); 64 void setShowCategory(const QString& =QString::null );
65 void newDay(); 65 void newDay();
66 QWidget* widget(); 66 QWidget* widget();
67 void sortColumn(int, bool, bool ); 67 void sortColumn(int, bool, bool );
68 68
69 /* 69 /*
70 * we do our drawing ourselves 70 * we do our drawing ourselves
71 * because we don't want to have 71 * because we don't want to have
72 * 40.000 QTableItems for 10.000 72 * 40.000 QTableItems for 10.000
73 * OTodos where we only show 10 at a time! 73 * OTodos where we only show 10 at a time!
74 */ 74 */
75 void paintCell(QPainter* p, int row, int col, const QRect&, bool ); 75 void paintCell(QPainter* p, int row, int col, const QRect&, bool );
76 private: 76 private:
77 /* reimplented for internal reasons */ 77 /* reimplented for internal reasons */
78 void viewportPaintEvent( QPaintEvent* ); 78 void viewportPaintEvent( QPaintEvent* );
79 QTimer *m_menuTimer; 79 QTimer *m_menuTimer;
80 bool m_enablePaint:1; 80 bool m_enablePaint:1;
81 QString m_oleCat; 81 QString m_oleCat;
82 bool m_first : 1; 82 bool m_first : 1;
83 83
84 protected: 84 protected:
85 void contentsMouseReleaseEvent( QMouseEvent* );
86 void contentsMouseMoveEvent( QMouseEvent* );
85 void timerEvent( QTimerEvent* e ); 87 void timerEvent( QTimerEvent* e );
86 QWidget* createEditor(int row, int col, bool initFromCell )const; 88 QWidget* createEditor(int row, int col, bool initFromCell )const;
87 void setCellContentFromEditor( int row, int col ); 89 void setCellContentFromEditor( int row, int col );
88 90
89private slots: 91private slots:
90 void slotShowMenu(); 92 void slotShowMenu();
91 void slotClicked(int, int, int, 93 void slotClicked(int, int, int,
92 const QPoint& ); 94 const QPoint& );
93 void slotPressed(int, int, int, 95 void slotPressed(int, int, int,
94 const QPoint& ); 96 const QPoint& );
95 void slotValueChanged(int, int); 97 void slotValueChanged(int, int);
96 void slotCurrentChanged(int, int ); 98 void slotCurrentChanged(int, int );
97 void slotPriority(); 99 void slotPriority();
98 private: 100 private:
99 bool m_row : 1; 101 bool m_row : 1;
102 QPoint m_prevP;
100 }; 103 };
101}; 104};
102 105
103#endif 106#endif