summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/tableview.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/core/pim/todo/tableview.cpp b/core/pim/todo/tableview.cpp
index cec8b5e..ae27fab 100644
--- a/core/pim/todo/tableview.cpp
+++ b/core/pim/todo/tableview.cpp
@@ -1,543 +1,553 @@
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 <zecke> 3             .=l. Copyright (c) 2002 <zecke>
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#include <cmath> 29#include <cmath>
30 30
31#include <qcombobox.h> 31#include <qcombobox.h>
32#include <qlineedit.h> 32#include <qlineedit.h>
33#include <qtimer.h> 33#include <qtimer.h>
34#include <qpoint.h> 34#include <qpoint.h>
35#include <qpopupmenu.h> 35#include <qpopupmenu.h>
36 36
37#include <qpe/config.h> 37#include <qpe/config.h>
38#include <qpe/resource.h> 38#include <qpe/resource.h>
39 39
40#include <opie/orecur.h> 40#include <opie/orecur.h>
41 41
42#include "mainwindow.h" 42#include "mainwindow.h"
43//#include "tableitems.h" 43//#include "tableitems.h"
44#include "tableview.h" 44#include "tableview.h"
45 45
46using namespace Todo; 46using namespace Todo;
47 47
48namespace { 48namespace {
49 static const int BoxSize = 14; 49 static const int BoxSize = 14;
50 static const int RowHeight = 20; 50 static const int RowHeight = 20;
51} 51}
52 52
53 53
54void TableView::initConfig() { 54void TableView::initConfig() {
55 Config config( "todo" ); 55 Config config( "todo" );
56 config.setGroup( "Options" ); 56 config.setGroup( "Options" );
57 m_completeStrokeWidth = config.readNumEntry( "CompleteStrokeWidth", 8 ); 57 m_completeStrokeWidth = config.readNumEntry( "CompleteStrokeWidth", 8 );
58 for (int i = 0; i < numCols(); i++ ) {
59 int width = config.readNumEntry("Width"+QString::number(i), -1 );
60 setColumnWidth(i, width == -1 ? columnWidth(i) : width );
61 }
58} 62}
59 63
60TableView::TableView( MainWindow* window, QWidget* wid ) 64TableView::TableView( MainWindow* window, QWidget* wid )
61 : QTable( wid ), TodoView( window ) { 65 : QTable( wid ), TodoView( window ) {
62 66
63 // Load icons 67 // Load icons
64 // TODO - probably should be done globally somewhere else, 68 // TODO - probably should be done globally somewhere else,
65 // see also quickeditimpl.cpp/h, taskeditoroverview.cpp/h 69 // see also quickeditimpl.cpp/h, taskeditoroverview.cpp/h
66 m_pic_completed = Resource::loadPixmap( "todo/completed" ); 70 m_pic_completed = Resource::loadPixmap( "todo/completed" );
67 QString namestr; 71 QString namestr;
68 for ( unsigned int i = 1; i < 6; i++ ) { 72 for ( unsigned int i = 1; i < 6; i++ ) {
69 namestr = "todo/priority"; 73 namestr = "todo/priority";
70 namestr.append( QString::number( i ) ); 74 namestr.append( QString::number( i ) );
71 m_pic_priority[ i - 1 ] = Resource::loadPixmap( namestr ); 75 m_pic_priority[ i - 1 ] = Resource::loadPixmap( namestr );
72 } 76 }
73 77
74 setUpdatesEnabled( false ); 78 setUpdatesEnabled( false );
75 viewport()->setUpdatesEnabled( false ); 79 viewport()->setUpdatesEnabled( false );
76 m_enablePaint = false; 80 m_enablePaint = false;
77 setNumRows(0); 81 setNumRows(0);
78 setNumCols(4); 82 setNumCols(4);
79 83
80 horizontalHeader()->setLabel( 0, QWidget::tr("C.") ); 84 horizontalHeader()->setLabel( 0, QWidget::tr("C.") );
81 horizontalHeader()->setLabel( 1, QWidget::tr("Priority") ); 85 horizontalHeader()->setLabel( 1, QWidget::tr("Priority") );
82 horizontalHeader()->setLabel( 2, QWidget::tr("Description" ) ); 86 horizontalHeader()->setLabel( 2, QWidget::tr("Description" ) );
83 horizontalHeader()->setLabel( 3, QWidget::tr("Deadline") ); 87 horizontalHeader()->setLabel( 3, QWidget::tr("Deadline") );
84 88
85 setShowDeadline( todoWindow()->showDeadline() ); 89 setShowDeadline( todoWindow()->showDeadline() );
86 90
87 setSorting( TRUE ); 91 setSorting( TRUE );
88 setSelectionMode( NoSelection ); 92 setSelectionMode( NoSelection );
89 93
90 setLeftMargin( 0 ); 94 setLeftMargin( 0 );
91 verticalHeader()->hide(); 95 verticalHeader()->hide();
92 96
93 connect((QTable*)this, SIGNAL( clicked( int, int, int, const QPoint& ) ), 97 connect((QTable*)this, SIGNAL( clicked( int, int, int, const QPoint& ) ),
94 this, SLOT( slotClicked(int, int, int, const QPoint& ) ) ); 98 this, SLOT( slotClicked(int, int, int, const QPoint& ) ) );
95 connect((QTable*)this, SIGNAL( pressed( int, int, int, const QPoint& ) ), 99 connect((QTable*)this, SIGNAL( pressed( int, int, int, const QPoint& ) ),
96 this, SLOT( slotPressed(int, int, int, const QPoint& ) ) ); 100 this, SLOT( slotPressed(int, int, int, const QPoint& ) ) );
97 connect((QTable*)this, SIGNAL(valueChanged(int, int) ), 101 connect((QTable*)this, SIGNAL(valueChanged(int, int) ),
98 this, SLOT( slotValueChanged(int, int) ) ); 102 this, SLOT( slotValueChanged(int, int) ) );
99 connect((QTable*)this, SIGNAL(currentChanged(int, int) ), 103 connect((QTable*)this, SIGNAL(currentChanged(int, int) ),
100 this, SLOT( slotCurrentChanged(int, int) ) ); 104 this, SLOT( slotCurrentChanged(int, int) ) );
101 105
102 m_menuTimer = new QTimer( this ); 106 m_menuTimer = new QTimer( this );
103 connect( m_menuTimer, SIGNAL(timeout()), 107 connect( m_menuTimer, SIGNAL(timeout()),
104 this, SLOT(slotShowMenu()) ); 108 this, SLOT(slotShowMenu()) );
105 109
110 /* now let's init the config */
111 initConfig();
112
113
106 m_enablePaint = true; 114 m_enablePaint = true;
107 setUpdatesEnabled( true ); 115 setUpdatesEnabled( true );
108 viewport()->setUpdatesEnabled( true ); 116 viewport()->setUpdatesEnabled( true );
109 viewport()->update(); 117 viewport()->update();
110 setSortOrder( 0 ); 118 setSortOrder( 0 );
111 setAscending( TRUE ); 119 setAscending( TRUE );
112 m_first = true; 120 m_first = true;
113 121
114 /* now let's init the config */ 122
115 initConfig();
116} 123}
117/* a new day has started 124/* a new day has started
118 * update the day 125 * update the day
119 */ 126 */
120void TableView::newDay() { 127void TableView::newDay() {
121 clear(); 128 clear();
122 updateView(); 129 updateView();
123} 130}
124TableView::~TableView() { 131TableView::~TableView() {
125 132 Config config( "todo" );
133 config.setGroup( "Options" );
134 for (int i = 0; i < numCols(); i++ )
135 config.writeEntry("Width"+QString::number(i), columnWidth(i) );
126} 136}
127void TableView::slotShowMenu() { 137void TableView::slotShowMenu() {
128 QPopupMenu *menu = todoWindow()->contextMenu( current(), sorted()[currentRow()].recurrence().doesRecur() ); 138 QPopupMenu *menu = todoWindow()->contextMenu( current(), sorted()[currentRow()].recurrence().doesRecur() );
129 menu->exec(QCursor::pos() ); 139 menu->exec(QCursor::pos() );
130 delete menu; 140 delete menu;
131} 141}
132QString TableView::type() const { 142QString TableView::type() const {
133 return QString::fromLatin1( tr("Table View") ); 143 return QString::fromLatin1( tr("Table View") );
134} 144}
135int TableView::current() { 145int TableView::current() {
136 int uid = sorted().uidAt(currentRow() ); 146 int uid = sorted().uidAt(currentRow() );
137 147
138 return uid; 148 return uid;
139} 149}
140QString TableView::currentRepresentation() { 150QString TableView::currentRepresentation() {
141 OTodo to = sorted()[currentRow()]; 151 OTodo to = sorted()[currentRow()];
142 return to.summary().isEmpty() ? to.description().left(20) : to.summary() ; 152 return to.summary().isEmpty() ? to.description().left(20) : to.summary() ;
143} 153}
144/* show overdue */ 154/* show overdue */
145void TableView::showOverDue( bool ) { 155void TableView::showOverDue( bool ) {
146 clear(); 156 clear();
147 updateView(); 157 updateView();
148} 158}
149 159
150void TableView::updateView( ) { 160void TableView::updateView( ) {
151 qWarning("update view"); 161 qWarning("update view");
152 m_row = false; 162 m_row = false;
153 static int id; 163 static int id;
154 id = startTimer(4000 ); 164 id = startTimer(4000 );
155 /* FIXME we want one page to be read! 165 /* FIXME we want one page to be read!
156 * 166 *
157 * Calculate that screensize 167 * Calculate that screensize
158 */ 168 */
159 todoWindow()->setReadAhead( 4 ); 169 todoWindow()->setReadAhead( 4 );
160 sort(); 170 sort();
161 OTodoAccess::List::Iterator it, end; 171 OTodoAccess::List::Iterator it, end;
162 it = sorted().begin(); 172 it = sorted().begin();
163 end = sorted().end(); 173 end = sorted().end();
164 174
165 qWarning("setTodos"); 175 qWarning("setTodos");
166 QTime time; 176 QTime time;
167 time.start(); 177 time.start();
168 m_enablePaint = false; 178 m_enablePaint = false;
169 setUpdatesEnabled( false ); 179 setUpdatesEnabled( false );
170 viewport()->setUpdatesEnabled( false ); 180 viewport()->setUpdatesEnabled( false );
171 181
172 setNumRows( it.count() ); 182 setNumRows( it.count() );
173 if ( it.count() == 0 ) 183 if ( it.count() == 0 )
174 killTimer(id); 184 killTimer(id);
175 185
176// int elc = time.elapsed(); 186// int elc = time.elapsed();
177 setUpdatesEnabled( true ); 187 setUpdatesEnabled( true );
178 viewport()->setUpdatesEnabled( true ); 188 viewport()->setUpdatesEnabled( true );
179 viewport()->update(); 189 viewport()->update();
180 190
181 m_enablePaint = true; 191 m_enablePaint = true;
182// int el = time.elapsed(); 192// int el = time.elapsed();
183} 193}
184void TableView::setTodo( int, const OTodo&) { 194void TableView::setTodo( int, const OTodo&) {
185 sort(); 195 sort();
186 196
187 /* repaint */ 197 /* repaint */
188 repaint(); 198 repaint();
189} 199}
190void TableView::addEvent( const OTodo&) { 200void TableView::addEvent( const OTodo&) {
191 201
192 /* fix problems of not showing the 'Haken' */ 202 /* fix problems of not showing the 'Haken' */
193 updateView(); 203 updateView();
194} 204}
195/* 205/*
196 * find the event 206 * find the event
197 * and then replace the complete row 207 * and then replace the complete row
198 */ 208 */
199void TableView::replaceEvent( const OTodo& ev) { 209void TableView::replaceEvent( const OTodo& ev) {
200 addEvent( ev ); 210 addEvent( ev );
201} 211}
202/* 212/*
203 * re aligning table can be slow too 213 * re aligning table can be slow too
204 * FIXME: look what performs better 214 * FIXME: look what performs better
205 * either this or the old align table 215 * either this or the old align table
206 */ 216 */
207void TableView::removeEvent( int ) { 217void TableView::removeEvent( int ) {
208 updateView(); 218 updateView();
209} 219}
210void TableView::setShowCompleted( bool b) { 220void TableView::setShowCompleted( bool b) {
211 qWarning("Show Completed %d" + b ); 221 qWarning("Show Completed %d" + b );
212 updateView(); 222 updateView();
213} 223}
214void TableView::setShowDeadline( bool b ) { 224void TableView::setShowDeadline( bool b ) {
215 qWarning( "Show DeadLine %d" + b ); 225 qWarning( "Show DeadLine %d" + b );
216 if ( b ) 226 if ( b )
217 showColumn( 3 ); 227 showColumn( 3 );
218 else 228 else
219 hideColumn( 3 ); 229 hideColumn( 3 );
220 230
221 // Try to intelligently size columns 231 // Try to intelligently size columns
222 // TODO - would use width() below, but doesn't have valid value at time of c'tor 232 // TODO - would use width() below, but doesn't have valid value at time of c'tor
223 int col2width = 238; 233 int col2width = 238;
224 int width = m_pic_completed.width(); 234 int width = m_pic_completed.width();
225 setColumnWidth( 0, width ); 235 setColumnWidth( 0, width );
226 col2width -= width; 236 col2width -= width;
227 width = fontMetrics().boundingRect( horizontalHeader()->label( 1 ) ).width() + 8; 237 width = fontMetrics().boundingRect( horizontalHeader()->label( 1 ) ).width() + 8;
228 setColumnWidth( 1, width ); 238 setColumnWidth( 1, width );
229 col2width -= width; 239 col2width -= width;
230 if ( b ) { 240 if ( b ) {
231 width = fontMetrics().boundingRect( horizontalHeader()->label( 3 ) ).width() + 8; 241 width = fontMetrics().boundingRect( horizontalHeader()->label( 3 ) ).width() + 8;
232 setColumnWidth( 3, width ); 242 setColumnWidth( 3, width );
233 col2width -= width; 243 col2width -= width;
234 } 244 }
235 setColumnWidth( 2, col2width ); 245 setColumnWidth( 2, col2width );
236} 246}
237void TableView::setShowCategory( const QString& str) { 247void TableView::setShowCategory( const QString& str) {
238 qWarning("setShowCategory"); 248 qWarning("setShowCategory");
239 if ( str != m_oleCat || m_first ) 249 if ( str != m_oleCat || m_first )
240 updateView(); 250 updateView();
241 251
242 m_oleCat = str; 252 m_oleCat = str;
243 m_first = false; 253 m_first = false;
244 254
245} 255}
246void TableView::clear() { 256void TableView::clear() {
247 setNumRows(0); 257 setNumRows(0);
248} 258}
249void TableView::slotClicked(int row, int col, int, 259void TableView::slotClicked(int row, int col, int,
250 const QPoint& point) { 260 const QPoint& point) {
251 if ( !cellGeometry(row, col ).contains(point ) ) 261 if ( !cellGeometry(row, col ).contains(point ) )
252 return; 262 return;
253 263
254 int ui= sorted().uidAt( row ); 264 int ui= sorted().uidAt( row );
255 265
256 266
257 switch( col ) { 267 switch( col ) {
258 case 0:{ 268 case 0:{
259 int x = point.x() -columnPos( col ); 269 int x = point.x() -columnPos( col );
260 int y = point.y() -rowPos( row ); 270 int y = point.y() -rowPos( row );
261 int w = columnWidth( col ); 271 int w = columnWidth( col );
262 int h = rowHeight( row ); 272 int h = rowHeight( row );
263 if ( x >= ( w - BoxSize ) / 2 && 273 if ( x >= ( w - BoxSize ) / 2 &&
264 x <= ( w - BoxSize ) / 2 + BoxSize && 274 x <= ( w - BoxSize ) / 2 + BoxSize &&
265 y >= ( h - BoxSize ) / 2 && 275 y >= ( h - BoxSize ) / 2 &&
266 y <= ( h - BoxSize ) / 2 + BoxSize ) { 276 y <= ( h - BoxSize ) / 2 + BoxSize ) {
267 TodoView::complete(sorted()[row] ); 277 TodoView::complete(sorted()[row] );
268 } 278 }
269 } 279 }
270 break; 280 break;
271 281
272 case 1: 282 case 1:
273 break; 283 break;
274 284
275 case 2: { 285 case 2: {
276 m_menuTimer->stop(); 286 m_menuTimer->stop();
277 showTodo( ui ); 287 showTodo( ui );
278 break; 288 break;
279 } 289 }
280 case 3: { 290 case 3: {
281 m_menuTimer->stop(); 291 m_menuTimer->stop();
282 TodoView::edit( ui ); 292 TodoView::edit( ui );
283 break; 293 break;
284 } 294 }
285 } 295 }
286 296
287 297
288} 298}
289void TableView::slotPressed(int row, int col, int, 299void TableView::slotPressed(int row, int col, int,
290 const QPoint& point) { 300 const QPoint& point) {
291 301
292 qWarning("pressed row %d col %d x:%d+y:%d", row,col,point.x(),point.y() ); 302 qWarning("pressed row %d col %d x:%d+y:%d", row,col,point.x(),point.y() );
293 m_prevP = point; 303 m_prevP = point;
294 /* TextColumn column */ 304 /* TextColumn column */
295 if ( col == 2 && cellGeometry( row, col ).contains( point ) ) 305 if ( col == 2 && cellGeometry( row, col ).contains( point ) )
296 m_menuTimer->start( 750, TRUE ); 306 m_menuTimer->start( 750, TRUE );
297} 307}
298void TableView::slotValueChanged( int, int ) { 308void TableView::slotValueChanged( int, int ) {
299 qWarning("Value Changed"); 309 qWarning("Value Changed");
300} 310}
301void TableView::slotCurrentChanged(int, int ) { 311void TableView::slotCurrentChanged(int, int ) {
302 m_menuTimer->stop(); 312 m_menuTimer->stop();
303} 313}
304QWidget* TableView::widget() { 314QWidget* TableView::widget() {
305 return this; 315 return this;
306} 316}
307/* 317/*
308 * We need to overwrite sortColumn 318 * We need to overwrite sortColumn
309 * because we want to sort whole row 319 * because we want to sort whole row
310 * based 320 * based
311 * We event want to set the setOrder 321 * We event want to set the setOrder
312 * to a sort() and update() 322 * to a sort() and update()
313 */ 323 */
314void TableView::sortColumn( int col, bool asc, bool ) { 324void TableView::sortColumn( int col, bool asc, bool ) {
315 qWarning("bool %d", asc ); 325 qWarning("bool %d", asc );
316 setSortOrder( col ); 326 setSortOrder( col );
317 setAscending( asc ); 327 setAscending( asc );
318 updateView(); 328 updateView();
319} 329}
320void TableView::viewportPaintEvent( QPaintEvent* e) { 330void TableView::viewportPaintEvent( QPaintEvent* e) {
321 if (m_enablePaint ) 331 if (m_enablePaint )
322 QTable::viewportPaintEvent( e ); 332 QTable::viewportPaintEvent( e );
323} 333}
324/* 334/*
325 * This segment is copyrighted by TT 335 * This segment is copyrighted by TT
326 * it was taken from their todolist 336 * it was taken from their todolist
327 * application this code is GPL 337 * application this code is GPL
328 */ 338 */
329void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) { 339void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) {
330 const QColorGroup &cg = colorGroup(); 340 const QColorGroup &cg = colorGroup();
331 341
332 p->save(); 342 p->save();
333 343
334 OTodo task = sorted()[row]; 344 OTodo task = sorted()[row];
335 345
336 // TODO - give user option for grid or bars? 346 // TODO - give user option for grid or bars?
337 347
338 // Paint alternating background bars 348 // Paint alternating background bars
339 if ( (row % 2 ) == 0 ) { 349 if ( (row % 2 ) == 0 ) {
340 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); 350 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
341 p->setPen( QPen( cg.text() ) ); 351 p->setPen( QPen( cg.text() ) );
342 } 352 }
343 else { 353 else {
344 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Background ) ); 354 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Background ) );
345 p->setPen( QPen( cg.buttonText() ) ); 355 p->setPen( QPen( cg.buttonText() ) );
346 } 356 }
347 357
348 // Paint grid 358 // Paint grid
349 //p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); 359 //p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
350 //QPen op = p->pen(); 360 //QPen op = p->pen();
351 //p->setPen(cg.mid()); 361 //p->setPen(cg.mid());
352 //p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 ); 362 //p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 );
353 //p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 ); 363 //p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 );
354 //p->setPen(op); 364 //p->setPen(op);
355 365
356 QFont f = p->font(); 366 QFont f = p->font();
357 QFontMetrics fm(f); 367 QFontMetrics fm(f);
358 368
359 int marg = ( cr.width() - BoxSize ) / 2; 369 int marg = ( cr.width() - BoxSize ) / 2;
360 int x = 0; 370 int x = 0;
361 int y = ( cr.height() - BoxSize ) / 2; 371 int y = ( cr.height() - BoxSize ) / 2;
362 372
363 switch(col) { 373 switch(col) {
364 case 0: // completed field 374 case 0: // completed field
365 { 375 {
366 //p->setPen( QPen( cg.text() ) ); 376 //p->setPen( QPen( cg.text() ) );
367 //p->drawRect( x + marg, y, BoxSize, BoxSize ); 377 //p->drawRect( x + marg, y, BoxSize, BoxSize );
368 //p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 ); 378 //p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 );
369 if ( task.isCompleted() ) { 379 if ( task.isCompleted() ) {
370 p->drawPixmap( x + marg, y, m_pic_completed ); 380 p->drawPixmap( x + marg, y, m_pic_completed );
371 } 381 }
372 } 382 }
373 break; 383 break;
374 case 1: // priority field 384 case 1: // priority field
375 { 385 {
376 p->drawPixmap( x + marg, y, m_pic_priority[ task.priority() - 1 ] ); 386 p->drawPixmap( x + marg, y, m_pic_priority[ task.priority() - 1 ] );
377 } 387 }
378 break; 388 break;
379 case 2: // description field 389 case 2: // description field
380 { 390 {
381 QString text = task.summary().isEmpty() ? 391 QString text = task.summary().isEmpty() ?
382 task.description().left(20) : 392 task.description().left(20) :
383 task.summary(); 393 task.summary();
384 p->drawText(2,2 + fm.ascent(), text); 394 p->drawText(2,2 + fm.ascent(), text);
385 } 395 }
386 break; 396 break;
387 case 3: 397 case 3:
388 { 398 {
389 QString text; 399 QString text;
390 if (task.hasDueDate()) { 400 if (task.hasDueDate()) {
391 int off = QDate::currentDate().daysTo( task.dueDate() ); 401 int off = QDate::currentDate().daysTo( task.dueDate() );
392 text = tr( "%1 day(s)").arg(QString::number(off)); 402 text = tr( "%1 day(s)").arg(QString::number(off));
393 /* 403 /*
394 * set color if not completed 404 * set color if not completed
395 */ 405 */
396 if (!task.isCompleted() ) { 406 if (!task.isCompleted() ) {
397 QColor color = Qt::black; 407 QColor color = Qt::black;
398 if ( off < 0 ) 408 if ( off < 0 )
399 color = Qt::red; 409 color = Qt::red;
400 else if ( off == 0 ) 410 else if ( off == 0 )
401 color = Qt::yellow; 411 color = Qt::yellow;
402 else if ( off > 0 ) 412 else if ( off > 0 )
403 color = Qt::green; 413 color = Qt::green;
404 p->setPen(color ); 414 p->setPen(color );
405 } 415 }
406 } else { 416 } else {
407 text = tr("None"); 417 text = tr("None");
408 } 418 }
409 p->drawText(2,2 + fm.ascent(), text); 419 p->drawText(2,2 + fm.ascent(), text);
410 } 420 }
411 break; 421 break;
412 } 422 }
413 p->restore(); 423 p->restore();
414} 424}
415QWidget* TableView::createEditor(int row, int col, bool )const { 425QWidget* TableView::createEditor(int row, int col, bool )const {
416 switch( col ) { 426 switch( col ) {
417 case 1: { 427 case 1: {
418 /* the priority stuff */ 428 /* the priority stuff */
419 QComboBox* combo = new QComboBox( viewport() ); 429 QComboBox* combo = new QComboBox( viewport() );
420 for ( int i = 0; i < 5; i++ ) { 430 for ( int i = 0; i < 5; i++ ) {
421 combo->insertItem( m_pic_priority[ i ] ); 431 combo->insertItem( m_pic_priority[ i ] );
422 } 432 }
423 combo->setCurrentItem( sorted()[row].priority()-1 ); 433 combo->setCurrentItem( sorted()[row].priority()-1 );
424 return combo; 434 return combo;
425 } 435 }
426 /* summary */ 436 /* summary */
427 case 2:{ 437 case 2:{
428 QLineEdit* edit = new QLineEdit( viewport() ); 438 QLineEdit* edit = new QLineEdit( viewport() );
429 edit->setText( sorted()[row].summary() ); 439 edit->setText( sorted()[row].summary() );
430 return edit; 440 return edit;
431 } 441 }
432 case 0: 442 case 0:
433 default: 443 default:
434 return 0l; 444 return 0l;
435 } 445 }
436} 446}
437void TableView::setCellContentFromEditor(int row, int col ) { 447void TableView::setCellContentFromEditor(int row, int col ) {
438 if ( col == 1 ) { 448 if ( col == 1 ) {
439 QWidget* wid = cellWidget(row, 1 ); 449 QWidget* wid = cellWidget(row, 1 );
440 if ( wid->inherits("QComboBox") ) { 450 if ( wid->inherits("QComboBox") ) {
441 int pri = ((QComboBox*)wid)->currentItem() + 1; 451 int pri = ((QComboBox*)wid)->currentItem() + 1;
442 OTodo todo = sorted()[row]; 452 OTodo todo = sorted()[row];
443 if ( todo.priority() != pri ) { 453 if ( todo.priority() != pri ) {
444 todo.setPriority( pri ); 454 todo.setPriority( pri );
445 TodoView::update( todo.uid(), todo ); 455 TodoView::update( todo.uid(), todo );
446 updateView(); 456 updateView();
447 } 457 }
448 } 458 }
449 }else if ( col == 2) { 459 }else if ( col == 2) {
450 QWidget* wid = cellWidget(row, 2); 460 QWidget* wid = cellWidget(row, 2);
451 if ( wid->inherits("QLineEdit") ) { 461 if ( wid->inherits("QLineEdit") ) {
452 QString text = ((QLineEdit*)wid)->text(); 462 QString text = ((QLineEdit*)wid)->text();
453 OTodo todo = sorted()[row]; 463 OTodo todo = sorted()[row];
454 if ( todo.summary() != text ) { 464 if ( todo.summary() != text ) {
455 todo.setSummary( text ); 465 todo.setSummary( text );
456 TodoView::update( todo.uid(), todo ); 466 TodoView::update( todo.uid(), todo );
457 updateView(); 467 updateView();
458 } 468 }
459 } 469 }
460 } 470 }
461} 471}
462void TableView::slotPriority() { 472void TableView::slotPriority() {
463 setCellContentFromEditor( currentRow(), currentColumn() ); 473 setCellContentFromEditor( currentRow(), currentColumn() );
464} 474}
465/* 475/*
466 * We'll use the TimerEvent to read ahead or to keep the cahce always 476 * We'll use the TimerEvent to read ahead or to keep the cahce always
467 * filled enough. 477 * filled enough.
468 * We will try to read ahead 4 items in both ways 478 * We will try to read ahead 4 items in both ways
469 * up and down. On odd or even we will currentRow()+-4 or +-9 479 * up and down. On odd or even we will currentRow()+-4 or +-9
470 * 480 *
471 */ 481 */
472void TableView::timerEvent( QTimerEvent* ) { 482void TableView::timerEvent( QTimerEvent* ) {
473// qWarning("sorted %d", sorted().count() ); 483// qWarning("sorted %d", sorted().count() );
474 if (sorted().count() == 0 ) 484 if (sorted().count() == 0 )
475 return; 485 return;
476 486
477 int row = currentRow(); 487 int row = currentRow();
478 if ( m_row ) { 488 if ( m_row ) {
479 int ro = row-4; 489 int ro = row-4;
480 if (ro < 0 ) ro = 0; 490 if (ro < 0 ) ro = 0;
481 sorted()[ro]; 491 sorted()[ro];
482 492
483 ro = row+4; 493 ro = row+4;
484 sorted()[ro]; 494 sorted()[ro];
485 } else { 495 } else {
486 int ro = row + 8; 496 int ro = row + 8;
487 sorted()[ro]; 497 sorted()[ro];
488 498
489 ro = row-8; 499 ro = row-8;
490 if (ro < 0 ) ro = 0; 500 if (ro < 0 ) ro = 0;
491 sorted()[ro]; 501 sorted()[ro];
492 } 502 }
493 503
494 m_row = !m_row; 504 m_row = !m_row;
495} 505}
496 506
497// We want a strike through completed ;) 507// We want a strike through completed ;)
498// durchstreichen to complete 508// durchstreichen to complete
499/* 509/*
500 * MouseTracking is off this mean we only receive 510 * MouseTracking is off this mean we only receive
501 * these events if the mouse button is pressed 511 * these events if the mouse button is pressed
502 * We've the previous point saved 512 * We've the previous point saved
503 * We check if the previous and current Point are 513 * We check if the previous and current Point are
504 * in the same row. 514 * in the same row.
505 * Then we check if they're some pixel horizontal away 515 * Then we check if they're some pixel horizontal away
506 * if the distance between the two points is greater than 516 * if the distance between the two points is greater than
507 * 8 we mark the underlying todo as completed and do a repaint 517 * 8 we mark the underlying todo as completed and do a repaint
508 * 518 *
509 * BUG: When clicking on the Due column and it's scrollable 519 * BUG: When clicking on the Due column and it's scrollable
510 * the todo is marked as completed... 520 * the todo is marked as completed...
511 * REASON: QTable is doing auto scrolling which leads to a move 521 * REASON: QTable is doing auto scrolling which leads to a move
512 * in the x coordinate and this way it's able to pass the 522 * in the x coordinate and this way it's able to pass the
513 * m_completeStrokeWidth criteria 523 * m_completeStrokeWidth criteria
514 * WORKAROUND: strike through needs to strike through the same 524 * WORKAROUND: strike through needs to strike through the same
515 * row and two columns! 525 * row and two columns!
516 */ 526 */
517void TableView::contentsMouseReleaseEvent( QMouseEvent* e) { 527void TableView::contentsMouseReleaseEvent( QMouseEvent* e) {
518 int row = rowAt(m_prevP.y()); 528 int row = rowAt(m_prevP.y());
519 int colOld = columnAt(m_prevP.x() ); 529 int colOld = columnAt(m_prevP.x() );
520 int colNew = columnAt(e->x() ); 530 int colNew = columnAt(e->x() );
521 qWarning("colNew: %d colOld: %d", colNew, colOld ); 531 qWarning("colNew: %d colOld: %d", colNew, colOld );
522 if ( row == rowAt( e->y() ) && row != -1 && 532 if ( row == rowAt( e->y() ) && row != -1 &&
523 colOld != colNew ) { 533 colOld != colNew ) {
524 TodoView::complete( sorted()[row] ); 534 TodoView::complete( sorted()[row] );
525 return; 535 return;
526 } 536 }
527 QTable::contentsMouseReleaseEvent( e ); 537 QTable::contentsMouseReleaseEvent( e );
528} 538}
529void TableView::contentsMouseMoveEvent( QMouseEvent* e ) { 539void TableView::contentsMouseMoveEvent( QMouseEvent* e ) {
530 m_menuTimer->stop(); 540 m_menuTimer->stop();
531 QTable::contentsMouseMoveEvent( e ); 541 QTable::contentsMouseMoveEvent( e );
532} 542}
533void TableView::keyPressEvent( QKeyEvent* event) { 543void TableView::keyPressEvent( QKeyEvent* event) {
534 switch( event->key() ) { 544 switch( event->key() ) {
535 case Qt::Key_F33: 545 case Qt::Key_F33:
536 case Qt::Key_Enter: 546 case Qt::Key_Enter:
537 case Qt::Key_Return: 547 case Qt::Key_Return:
538 showTodo( sorted().uidAt( currentRow() ) ); 548 showTodo( sorted().uidAt( currentRow() ) );
539 break; 549 break;
540 default: 550 default:
541 QTable::keyPressEvent( event ); 551 QTable::keyPressEvent( event );
542 } 552 }
543} 553}