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