summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/tableitems.cpp2
-rw-r--r--core/pim/todo/tableview.cpp2
2 files changed, 2 insertions, 2 deletions
diff --git a/core/pim/todo/tableitems.cpp b/core/pim/todo/tableitems.cpp
index 86fe07d..a636de6 100644
--- a/core/pim/todo/tableitems.cpp
+++ b/core/pim/todo/tableitems.cpp
@@ -1,181 +1,181 @@
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 "tableview.h" 28#include "tableview.h"
29 29
30#include "tableitems.h" 30#include "tableitems.h"
31#include <string.h> 31#include <string.h>
32 32
33using namespace Todo; 33using namespace Todo;
34 34
35CheckItem::CheckItem( QTable* t, 35CheckItem::CheckItem( QTable* t,
36 const QString& sortKey, 36 const QString& sortKey,
37 int uid, 37 int uid,
38 const QArray<int>& lis) 38 const QArray<int>& lis)
39 : OCheckItem(t, sortKey), m_uid(uid ), m_cat( lis ) 39 : OCheckItem(t, sortKey), m_uid(uid ), m_cat( lis )
40{ 40{
41} 41}
42CheckItem::~CheckItem() { 42CheckItem::~CheckItem() {
43} 43}
44void CheckItem::setChecked( bool b ) { 44void CheckItem::setChecked( bool b ) {
45 OCheckItem::setChecked(b); 45 OCheckItem::setChecked(b);
46} 46}
47void CheckItem::toggle() { 47void CheckItem::toggle() {
48 TableView* view = static_cast<TableView*>( table() ); 48 TableView* view = static_cast<TableView*>( table() );
49 OTodo ev = view->find( view->current() ); 49 OTodo ev = view->find( view->current() );
50 ev.setCompleted(!isChecked() ); 50 ev.setCompleted(!isChecked() );
51 //view->updateFromTable( ev ); 51 //view->updateFromTable( ev );
52 52
53 OCheckItem::toggle(); 53 OCheckItem::toggle();
54 table()->updateCell( row(), col() ); 54 table()->updateCell( row(), col() );
55} 55}
56int CheckItem::uid() const { 56int CheckItem::uid() const {
57 return m_uid; 57 return m_uid;
58} 58}
59QArray<int> CheckItem::cats() { 59QArray<int> CheckItem::cats() {
60 return m_cat; 60 return m_cat;
61} 61}
62 62
63/* ComboItem */ 63/* ComboItem */
64ComboItem::ComboItem( QTable* t, EditType et ) 64ComboItem::ComboItem( QTable* t, EditType et )
65 : QTableItem( t, et, "3" ), m_cb(0) 65 : QTableItem( t, et, "3" ), m_cb(0)
66{ 66{
67 setReplaceable( FALSE ); 67 setReplaceable( FALSE );
68} 68}
69ComboItem::~ComboItem() { 69ComboItem::~ComboItem() {
70 70
71} 71}
72QWidget* ComboItem::createEditor()const { 72QWidget* ComboItem::createEditor()const {
73 qWarning( "create editor"); 73 qWarning( "create editor");
74 QString txt = text(); 74 QString txt = text();
75 75
76 ( (ComboItem*)this)-> m_cb = new QComboBox( table()->viewport() ); 76 ( (ComboItem*)this)-> m_cb = new QComboBox( table()->viewport() );
77 77
78 m_cb->insertItem( "1" ); 78 m_cb->insertItem( "1" );
79 m_cb->insertItem( "2" ); 79 m_cb->insertItem( "2" );
80 m_cb->insertItem( "3" ); 80 m_cb->insertItem( "3" );
81 m_cb->insertItem( "4" ); 81 m_cb->insertItem( "4" );
82 m_cb->insertItem( "5" ); 82 m_cb->insertItem( "5" );
83 m_cb->setCurrentItem( txt.toInt() - 1 ); 83 m_cb->setCurrentItem( txt.toInt() - 1 );
84 84
85 return m_cb; 85 return m_cb;
86} 86}
87void ComboItem::setContentFromEditor( QWidget* w) { 87void ComboItem::setContentFromEditor( QWidget* w) {
88 TableView* view = static_cast<TableView*>( table() ); 88 TableView* view = static_cast<TableView*>( table() );
89 OTodo ev = view->find( view->current() ); 89 OTodo ev = view->find( view->current() );
90 90
91 if ( w->inherits( "QComboBox" ) ) 91 if ( w->inherits( "QComboBox" ) )
92 setText( ( (QComboBox*)w )->currentText() ); 92 setText( ( (QComboBox*)w )->currentText() );
93 else 93 else
94 QTableItem::setContentFromEditor( w ); 94 QTableItem::setContentFromEditor( w );
95 95
96 ev.setPriority( text().toInt() ); 96 ev.setPriority( text().toInt() );
97 //view->updateFromTable( ev ); 97 //view->updateFromTable( ev );
98} 98}
99void ComboItem::setText( const QString& s ) { 99void ComboItem::setText( const QString& s ) {
100 if ( m_cb ) 100 if ( m_cb )
101 m_cb->setCurrentItem( s.toInt()-1 ); 101 m_cb->setCurrentItem( s.toInt()-1 );
102 102
103 QTableItem::setText( s ); 103 QTableItem::setText( s );
104} 104}
105QString ComboItem::text()const { 105QString ComboItem::text()const {
106 if ( m_cb) 106 if ( m_cb)
107 return m_cb->currentText(); 107 return m_cb->currentText();
108 108
109 return QTableItem::text(); 109 return QTableItem::text();
110} 110}
111 111
112/* TodoTextItem */ 112/* TodoTextItem */
113TodoTextItem::~TodoTextItem() { 113TodoTextItem::~TodoTextItem() {
114 114
115} 115}
116TodoTextItem::TodoTextItem( QTable* t, 116TodoTextItem::TodoTextItem( QTable* t,
117 const QString& string ) 117 const QString& string )
118 : QTableItem( t, QTableItem::Never, string ) 118 : QTableItem( t, QTableItem::Never, string )
119{} 119{}
120 120
121/* DueTextItem */ 121/* DueTextItem */
122DueTextItem::DueTextItem( QTable* t, const OTodo& ev) 122DueTextItem::DueTextItem( QTable* t, const OTodo& ev)
123 : QTableItem(t, Never, QString::null ) 123 : QTableItem(t, Never, QString::null )
124{ 124{
125 setToDoEvent( ev ); 125 setToDoEvent( ev );
126} 126}
127DueTextItem::~DueTextItem() { 127DueTextItem::~DueTextItem() {
128 128
129} 129}
130QString DueTextItem::key() const { 130QString DueTextItem::key() const {
131 QString key; 131 QString key;
132 132
133 if( m_hasDate ){ 133 if( m_hasDate ){
134 if(m_off == 0 ){ 134 if(m_off == 0 ){
135 key.append("b"); 135 key.append("b");
136 }else if( m_off > 0 ){ 136 }else if( m_off > 0 ){
137 key.append("c"); 137 key.append("c");
138 }else if( m_off < 0 ){ 138 }else if( m_off < 0 ){
139 key.append("a"); 139 key.append("a");
140 } 140 }
141 key.append(QString::number(m_off ) ); 141 key.append(QString::number(m_off ) );
142 }else{ 142 }else{
143 key.append("d"); 143 key.append("d");
144 } 144 }
145 return key; 145 return key;
146} 146}
147void DueTextItem::setCompleted( bool comp ) { 147void DueTextItem::setCompleted( bool comp ) {
148 m_completed = comp; 148 m_completed = comp;
149 table()->updateCell( row(), col() ); 149 table()->updateCell( row(), col() );
150} 150}
151void DueTextItem::setToDoEvent( const OTodo& ev ) { 151void DueTextItem::setToDoEvent( const OTodo& ev ) {
152 m_hasDate = ev.hasDueDate(); 152 m_hasDate = ev.hasDueDate();
153 m_completed = ev.isCompleted(); 153 m_completed = ev.isCompleted();
154 154
155 if( ev.hasDueDate() ){ 155 if( ev.hasDueDate() ){
156 QDate today = QDate::currentDate(); 156 QDate today = QDate::currentDate();
157 m_off = today.daysTo(ev.dueDate() ); 157 m_off = today.daysTo(ev.dueDate() );
158 setText( QString::number(m_off) + " day(s) " ); 158 setText( tr( "%1 day(s)" ).arg( QString::number(m_off) ) );
159 }else{ 159 }else{
160 setText("n.d." ); 160 setText("n.d." );
161 m_off = 0; 161 m_off = 0;
162 } 162 }
163} 163}
164void DueTextItem::paint( QPainter* p, const QColorGroup &cg, 164void DueTextItem::paint( QPainter* p, const QColorGroup &cg,
165 const QRect& cr, bool selected ) { 165 const QRect& cr, bool selected ) {
166 QColorGroup cg2(cg); 166 QColorGroup cg2(cg);
167 167
168 QColor text = cg.text(); 168 QColor text = cg.text();
169 if( m_hasDate && !m_completed ){ 169 if( m_hasDate && !m_completed ){
170 if( m_off < 0 ){ 170 if( m_off < 0 ){
171 cg2.setColor(QColorGroup::Text, QColor(red ) ); 171 cg2.setColor(QColorGroup::Text, QColor(red ) );
172 }else if( m_off == 0 ){ 172 }else if( m_off == 0 ){
173 cg2.setColor(QColorGroup::Text, QColor(yellow) ); // orange isn't predefined 173 cg2.setColor(QColorGroup::Text, QColor(yellow) ); // orange isn't predefined
174 }else if( m_off > 0){ 174 }else if( m_off > 0){
175 cg2.setColor(QColorGroup::Text, QColor(green ) ); 175 cg2.setColor(QColorGroup::Text, QColor(green ) );
176 } 176 }
177 } 177 }
178 QTableItem::paint(p, cg2, cr, selected ); 178 QTableItem::paint(p, cg2, cr, selected );
179 /* restore default color */ 179 /* restore default color */
180 cg2.setColor(QColorGroup::Text, text ); 180 cg2.setColor(QColorGroup::Text, text );
181} 181}
diff --git a/core/pim/todo/tableview.cpp b/core/pim/todo/tableview.cpp
index 2434150..f59971e 100644
--- a/core/pim/todo/tableview.cpp
+++ b/core/pim/todo/tableview.cpp
@@ -190,335 +190,335 @@ void TableView::addEvent( const OTodo&) {
190 updateView(); 190 updateView();
191} 191}
192/* 192/*
193 * find the event 193 * find the event
194 * and then replace the complete row 194 * and then replace the complete row
195 */ 195 */
196void TableView::replaceEvent( const OTodo& ev) { 196void TableView::replaceEvent( const OTodo& ev) {
197 addEvent( ev ); 197 addEvent( ev );
198} 198}
199/* 199/*
200 * re aligning table can be slow too 200 * re aligning table can be slow too
201 * FIXME: look what performs better 201 * FIXME: look what performs better
202 * either this or the old align table 202 * either this or the old align table
203 */ 203 */
204void TableView::removeEvent( int ) { 204void TableView::removeEvent( int ) {
205 updateView(); 205 updateView();
206} 206}
207void TableView::setShowCompleted( bool b) { 207void TableView::setShowCompleted( bool b) {
208 qWarning("Show Completed %d" + b ); 208 qWarning("Show Completed %d" + b );
209 updateView(); 209 updateView();
210} 210}
211void TableView::setShowDeadline( bool b) { 211void TableView::setShowDeadline( bool b) {
212 qWarning("Show DeadLine %d" + b ); 212 qWarning("Show DeadLine %d" + b );
213 if (b) 213 if (b)
214 showColumn(3 ); 214 showColumn(3 );
215 else 215 else
216 hideColumn(3 ); 216 hideColumn(3 );
217} 217}
218void TableView::setShowCategory( const QString& str) { 218void TableView::setShowCategory( const QString& str) {
219 qWarning("setShowCategory"); 219 qWarning("setShowCategory");
220 if ( str != m_oleCat || m_first ) 220 if ( str != m_oleCat || m_first )
221 updateView(); 221 updateView();
222 222
223 m_oleCat = str; 223 m_oleCat = str;
224 m_first = false; 224 m_first = false;
225 225
226} 226}
227void TableView::clear() { 227void TableView::clear() {
228 setNumRows(0); 228 setNumRows(0);
229} 229}
230void TableView::slotClicked(int row, int col, int, 230void TableView::slotClicked(int row, int col, int,
231 const QPoint& point) { 231 const QPoint& point) {
232 if ( !cellGeometry(row, col ).contains(point ) ) 232 if ( !cellGeometry(row, col ).contains(point ) )
233 return; 233 return;
234 234
235 int ui= sorted().uidAt( row ); 235 int ui= sorted().uidAt( row );
236 236
237 237
238 switch( col ) { 238 switch( col ) {
239 case 0:{ 239 case 0:{
240 int x = point.x() -columnPos( col ); 240 int x = point.x() -columnPos( col );
241 int y = point.y() -rowPos( row ); 241 int y = point.y() -rowPos( row );
242 int w = columnWidth( col ); 242 int w = columnWidth( col );
243 int h = rowHeight( row ); 243 int h = rowHeight( row );
244 if ( x >= ( w - BoxSize ) / 2 && 244 if ( x >= ( w - BoxSize ) / 2 &&
245 x <= ( w - BoxSize ) / 2 + BoxSize && 245 x <= ( w - BoxSize ) / 2 + BoxSize &&
246 y >= ( h - BoxSize ) / 2 && 246 y >= ( h - BoxSize ) / 2 &&
247 y <= ( h - BoxSize ) / 2 + BoxSize ) { 247 y <= ( h - BoxSize ) / 2 + BoxSize ) {
248 TodoView::complete(sorted()[row] ); 248 TodoView::complete(sorted()[row] );
249 } 249 }
250 } 250 }
251 break; 251 break;
252 252
253 case 1: 253 case 1:
254 break; 254 break;
255 255
256 case 2: { 256 case 2: {
257 m_menuTimer->stop(); 257 m_menuTimer->stop();
258 showTodo( ui ); 258 showTodo( ui );
259 break; 259 break;
260 } 260 }
261 case 3: { 261 case 3: {
262 m_menuTimer->stop(); 262 m_menuTimer->stop();
263 TodoView::edit( ui ); 263 TodoView::edit( ui );
264 break; 264 break;
265 } 265 }
266 } 266 }
267 267
268 268
269} 269}
270void TableView::slotPressed(int row, int col, int, 270void TableView::slotPressed(int row, int col, int,
271 const QPoint& point) { 271 const QPoint& point) {
272 272
273 qWarning("pressed row %d col %d x:%d+y:%d", row,col,point.x(),point.y() ); 273 qWarning("pressed row %d col %d x:%d+y:%d", row,col,point.x(),point.y() );
274 m_prevP = point; 274 m_prevP = point;
275 /* TextColumn column */ 275 /* TextColumn column */
276 if ( col == 2 && cellGeometry( row, col ).contains( point ) ) 276 if ( col == 2 && cellGeometry( row, col ).contains( point ) )
277 m_menuTimer->start( 750, TRUE ); 277 m_menuTimer->start( 750, TRUE );
278} 278}
279void TableView::slotValueChanged( int, int ) { 279void TableView::slotValueChanged( int, int ) {
280 qWarning("Value Changed"); 280 qWarning("Value Changed");
281} 281}
282void TableView::slotCurrentChanged(int, int ) { 282void TableView::slotCurrentChanged(int, int ) {
283 m_menuTimer->stop(); 283 m_menuTimer->stop();
284} 284}
285QWidget* TableView::widget() { 285QWidget* TableView::widget() {
286 return this; 286 return this;
287} 287}
288/* 288/*
289 * We need to overwrite sortColumn 289 * We need to overwrite sortColumn
290 * because we want to sort whole row 290 * because we want to sort whole row
291 * based 291 * based
292 * We event want to set the setOrder 292 * We event want to set the setOrder
293 * to a sort() and update() 293 * to a sort() and update()
294 */ 294 */
295void TableView::sortColumn( int col, bool asc, bool ) { 295void TableView::sortColumn( int col, bool asc, bool ) {
296 qWarning("bool %d", asc ); 296 qWarning("bool %d", asc );
297 setSortOrder( col ); 297 setSortOrder( col );
298 setAscending( asc ); 298 setAscending( asc );
299 updateView(); 299 updateView();
300} 300}
301void TableView::viewportPaintEvent( QPaintEvent* e) { 301void TableView::viewportPaintEvent( QPaintEvent* e) {
302 if (m_enablePaint ) 302 if (m_enablePaint )
303 QTable::viewportPaintEvent( e ); 303 QTable::viewportPaintEvent( e );
304} 304}
305/* 305/*
306 * This segment is copyrighted by TT 306 * This segment is copyrighted by TT
307 * it was taken from their todolist 307 * it was taken from their todolist
308 * application this code is GPL 308 * application this code is GPL
309 */ 309 */
310void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) { 310void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) {
311 const QColorGroup &cg = colorGroup(); 311 const QColorGroup &cg = colorGroup();
312 312
313 p->save(); 313 p->save();
314 314
315 OTodo task = sorted()[row]; 315 OTodo task = sorted()[row];
316 316
317 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); 317 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
318 318
319 QPen op = p->pen(); 319 QPen op = p->pen();
320 p->setPen(cg.mid()); 320 p->setPen(cg.mid());
321 p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 ); 321 p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 );
322 p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 ); 322 p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 );
323 p->setPen(op); 323 p->setPen(op);
324 324
325 QFont f = p->font(); 325 QFont f = p->font();
326 QFontMetrics fm(f); 326 QFontMetrics fm(f);
327 327
328 switch(col) { 328 switch(col) {
329 case 0: 329 case 0:
330 { 330 {
331 // completed field 331 // completed field
332 int marg = ( cr.width() - BoxSize ) / 2; 332 int marg = ( cr.width() - BoxSize ) / 2;
333 int x = 0; 333 int x = 0;
334 int y = ( cr.height() - BoxSize ) / 2; 334 int y = ( cr.height() - BoxSize ) / 2;
335 p->setPen( QPen( cg.text() ) ); 335 p->setPen( QPen( cg.text() ) );
336 p->drawRect( x + marg, y, BoxSize, BoxSize ); 336 p->drawRect( x + marg, y, BoxSize, BoxSize );
337 p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 ); 337 p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 );
338 p->setPen( darkGreen ); 338 p->setPen( darkGreen );
339 x += 1; 339 x += 1;
340 y += 1; 340 y += 1;
341 if ( task.isCompleted() ) { 341 if ( task.isCompleted() ) {
342 QPointArray a( 9*2 ); 342 QPointArray a( 9*2 );
343 int i, xx, yy; 343 int i, xx, yy;
344 xx = x+2+marg; 344 xx = x+2+marg;
345 yy = y+4; 345 yy = y+4;
346 for ( i=0; i<4; i++ ) { 346 for ( i=0; i<4; i++ ) {
347 a.setPoint( 2*i, xx, yy ); 347 a.setPoint( 2*i, xx, yy );
348 a.setPoint( 2*i+1, xx, yy+2 ); 348 a.setPoint( 2*i+1, xx, yy+2 );
349 xx++; yy++; 349 xx++; yy++;
350 } 350 }
351 yy -= 2; 351 yy -= 2;
352 for ( i=4; i<9; i++ ) { 352 for ( i=4; i<9; i++ ) {
353 a.setPoint( 2*i, xx, yy ); 353 a.setPoint( 2*i, xx, yy );
354 a.setPoint( 2*i+1, xx, yy+2 ); 354 a.setPoint( 2*i+1, xx, yy+2 );
355 xx++; yy--; 355 xx++; yy--;
356 } 356 }
357 p->drawLineSegments( a ); 357 p->drawLineSegments( a );
358 } 358 }
359 } 359 }
360 break; 360 break;
361 case 1: 361 case 1:
362 // priority field 362 // priority field
363 { 363 {
364 QString text = QString::number(task.priority()); 364 QString text = QString::number(task.priority());
365 p->drawText(2,2 + fm.ascent(), text); 365 p->drawText(2,2 + fm.ascent(), text);
366 } 366 }
367 break; 367 break;
368 case 2: 368 case 2:
369 // description field 369 // description field
370 { 370 {
371 QString text = task.summary().isEmpty() ? 371 QString text = task.summary().isEmpty() ?
372 task.description().left(20) : 372 task.description().left(20) :
373 task.summary(); 373 task.summary();
374 p->drawText(2,2 + fm.ascent(), text); 374 p->drawText(2,2 + fm.ascent(), text);
375 } 375 }
376 break; 376 break;
377 case 3: 377 case 3:
378 { 378 {
379 QString text; 379 QString text;
380 if (task.hasDueDate()) { 380 if (task.hasDueDate()) {
381 int off = QDate::currentDate().daysTo( task.dueDate() ); 381 int off = QDate::currentDate().daysTo( task.dueDate() );
382 text = QString::number(off) + tr(" day(s)"); 382 text = tr( "%1 day(s)").arg(QString::number(off));
383 /* 383 /*
384 * set color if not completed 384 * set color if not completed
385 */ 385 */
386 if (!task.isCompleted() ) { 386 if (!task.isCompleted() ) {
387 QColor color = Qt::black; 387 QColor color = Qt::black;
388 if ( off < 0 ) 388 if ( off < 0 )
389 color = Qt::red; 389 color = Qt::red;
390 else if ( off == 0 ) 390 else if ( off == 0 )
391 color = Qt::yellow; 391 color = Qt::yellow;
392 else if ( off > 0 ) 392 else if ( off > 0 )
393 color = Qt::green; 393 color = Qt::green;
394 p->setPen(color ); 394 p->setPen(color );
395 } 395 }
396 } else { 396 } else {
397 text = tr("None"); 397 text = tr("None");
398 } 398 }
399 p->drawText(2,2 + fm.ascent(), text); 399 p->drawText(2,2 + fm.ascent(), text);
400 } 400 }
401 break; 401 break;
402 } 402 }
403 p->restore(); 403 p->restore();
404} 404}
405QWidget* TableView::createEditor(int row, int col, bool )const { 405QWidget* TableView::createEditor(int row, int col, bool )const {
406 switch( col ) { 406 switch( col ) {
407 case 1: { 407 case 1: {
408 /* the priority stuff */ 408 /* the priority stuff */
409 QComboBox* combo = new QComboBox( viewport() ); 409 QComboBox* combo = new QComboBox( viewport() );
410 combo->insertItem( "1" ); 410 combo->insertItem( "1" );
411 combo->insertItem( "2" ); 411 combo->insertItem( "2" );
412 combo->insertItem( "3" ); 412 combo->insertItem( "3" );
413 combo->insertItem( "4" ); 413 combo->insertItem( "4" );
414 combo->insertItem( "5" ); 414 combo->insertItem( "5" );
415 combo->setCurrentItem( sorted()[row].priority()-1 ); 415 combo->setCurrentItem( sorted()[row].priority()-1 );
416 return combo; 416 return combo;
417 } 417 }
418 /* summary */ 418 /* summary */
419 case 2:{ 419 case 2:{
420 QLineEdit* edit = new QLineEdit( viewport() ); 420 QLineEdit* edit = new QLineEdit( viewport() );
421 edit->setText( sorted()[row].summary() ); 421 edit->setText( sorted()[row].summary() );
422 return edit; 422 return edit;
423 } 423 }
424 case 0: 424 case 0:
425 default: 425 default:
426 return 0l; 426 return 0l;
427 } 427 }
428} 428}
429void TableView::setCellContentFromEditor(int row, int col ) { 429void TableView::setCellContentFromEditor(int row, int col ) {
430 if ( col == 1 ) { 430 if ( col == 1 ) {
431 QWidget* wid = cellWidget(row, 1 ); 431 QWidget* wid = cellWidget(row, 1 );
432 if ( wid->inherits("QComboBox") ) { 432 if ( wid->inherits("QComboBox") ) {
433 int pri = ((QComboBox*)wid)->currentItem() + 1; 433 int pri = ((QComboBox*)wid)->currentItem() + 1;
434 OTodo todo = sorted()[row]; 434 OTodo todo = sorted()[row];
435 if ( todo.priority() != pri ) { 435 if ( todo.priority() != pri ) {
436 todo.setPriority( pri ); 436 todo.setPriority( pri );
437 TodoView::update( todo.uid(), todo ); 437 TodoView::update( todo.uid(), todo );
438 updateView(); 438 updateView();
439 } 439 }
440 } 440 }
441 }else if ( col == 2) { 441 }else if ( col == 2) {
442 QWidget* wid = cellWidget(row, 2); 442 QWidget* wid = cellWidget(row, 2);
443 if ( wid->inherits("QLineEdit") ) { 443 if ( wid->inherits("QLineEdit") ) {
444 QString text = ((QLineEdit*)wid)->text(); 444 QString text = ((QLineEdit*)wid)->text();
445 OTodo todo = sorted()[row]; 445 OTodo todo = sorted()[row];
446 if ( todo.summary() != text ) { 446 if ( todo.summary() != text ) {
447 todo.setSummary( text ); 447 todo.setSummary( text );
448 TodoView::update( todo.uid(), todo ); 448 TodoView::update( todo.uid(), todo );
449 updateView(); 449 updateView();
450 } 450 }
451 } 451 }
452 } 452 }
453} 453}
454void TableView::slotPriority() { 454void TableView::slotPriority() {
455 setCellContentFromEditor( currentRow(), currentColumn() ); 455 setCellContentFromEditor( currentRow(), currentColumn() );
456} 456}
457/* 457/*
458 * We'll use the TimerEvent to read ahead or to keep the cahce always 458 * We'll use the TimerEvent to read ahead or to keep the cahce always
459 * filled enough. 459 * filled enough.
460 * We will try to read ahead 4 items in both ways 460 * We will try to read ahead 4 items in both ways
461 * up and down. On odd or even we will currentRow()+-4 or +-9 461 * up and down. On odd or even we will currentRow()+-4 or +-9
462 * 462 *
463 */ 463 */
464void TableView::timerEvent( QTimerEvent* ev ) { 464void TableView::timerEvent( QTimerEvent* ev ) {
465// qWarning("sorted %d", sorted().count() ); 465// qWarning("sorted %d", sorted().count() );
466 if (sorted().count() == 0 ) 466 if (sorted().count() == 0 )
467 return; 467 return;
468 468
469 int row = currentRow(); 469 int row = currentRow();
470 if ( m_row ) { 470 if ( m_row ) {
471 int ro = row-4; 471 int ro = row-4;
472 if (ro < 0 ) ro = 0; 472 if (ro < 0 ) ro = 0;
473 sorted()[ro]; 473 sorted()[ro];
474 474
475 ro = row+4; 475 ro = row+4;
476 sorted()[ro]; 476 sorted()[ro];
477 } else { 477 } else {
478 int ro = row + 8; 478 int ro = row + 8;
479 sorted()[ro]; 479 sorted()[ro];
480 480
481 ro = row-8; 481 ro = row-8;
482 if (ro < 0 ) ro = 0; 482 if (ro < 0 ) ro = 0;
483 sorted()[ro]; 483 sorted()[ro];
484 } 484 }
485 485
486 m_row = !m_row; 486 m_row = !m_row;
487} 487}
488 488
489// We want a strike through completed ;) 489// We want a strike through completed ;)
490// durchstreichen to complete 490// durchstreichen to complete
491/* 491/*
492 * MouseTracking is off this mean we only receive 492 * MouseTracking is off this mean we only receive
493 * these events if the mouse button is pressed 493 * these events if the mouse button is pressed
494 * We've the previous point saved 494 * We've the previous point saved
495 * We check if the previous and current Point are 495 * We check if the previous and current Point are
496 * in the same row. 496 * in the same row.
497 * Then we check if they're some pixel horizontal away 497 * Then we check if they're some pixel horizontal away
498 * if the distance between the two points is greater than 498 * if the distance between the two points is greater than
499 * 8 we mark the underlying todo as completed and do a repaint 499 * 8 we mark the underlying todo as completed and do a repaint
500 * 500 *
501 * BUG: When clicking on the Due column and it's scrollable 501 * BUG: When clicking on the Due column and it's scrollable
502 * the todo is marked as completed... 502 * the todo is marked as completed...
503 * REASON: QTable is doing auto scrolling which leads to a move 503 * REASON: QTable is doing auto scrolling which leads to a move
504 * in the x coordinate and this way it's able to pass the 504 * in the x coordinate and this way it's able to pass the
505 * m_completeStrokeWidth criteria 505 * m_completeStrokeWidth criteria
506 * WORKAROUND: strike through needs to strike through the same 506 * WORKAROUND: strike through needs to strike through the same
507 * row and two columns! 507 * row and two columns!
508 */ 508 */
509void TableView::contentsMouseReleaseEvent( QMouseEvent* e) { 509void TableView::contentsMouseReleaseEvent( QMouseEvent* e) {
510 int row = rowAt(m_prevP.y()); 510 int row = rowAt(m_prevP.y());
511 int colOld = columnAt(m_prevP.x() ); 511 int colOld = columnAt(m_prevP.x() );
512 int colNew = columnAt(e->x() ); 512 int colNew = columnAt(e->x() );
513 qWarning("colNew: %d colOld: %d", colNew, colOld ); 513 qWarning("colNew: %d colOld: %d", colNew, colOld );
514 if ( row == rowAt( e->y() ) && row != -1 && 514 if ( row == rowAt( e->y() ) && row != -1 &&
515 colOld != colNew ) { 515 colOld != colNew ) {
516 TodoView::complete( sorted()[row] ); 516 TodoView::complete( sorted()[row] );
517 return; 517 return;
518 } 518 }
519 QTable::contentsMouseReleaseEvent( e ); 519 QTable::contentsMouseReleaseEvent( e );
520} 520}
521void TableView::contentsMouseMoveEvent( QMouseEvent* e ) { 521void TableView::contentsMouseMoveEvent( QMouseEvent* e ) {
522 m_menuTimer->stop(); 522 m_menuTimer->stop();
523 QTable::contentsMouseMoveEvent( e ); 523 QTable::contentsMouseMoveEvent( e );
524} 524}