summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/tableview.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/core/pim/todo/tableview.cpp b/core/pim/todo/tableview.cpp
index 39f0d72..8cd2e7e 100644
--- a/core/pim/todo/tableview.cpp
+++ b/core/pim/todo/tableview.cpp
@@ -1,362 +1,363 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 <> 3             .=l. Copyright (c) 2002 <>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This program is free software; you can 5 _;:,     .>    :=|. This program is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU General Public 7:`=1 )Y*s>-.--   : the terms of the GNU General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This program is distributed in the hope that 12    .i_,=:_.      -<s. This program is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include <qtimer.h> 29#include <qtimer.h>
30#include <qpoint.h> 30#include <qpoint.h>
31#include <qpopupmenu.h> 31#include <qpopupmenu.h>
32 32
33#include "mainwindow.h" 33#include "mainwindow.h"
34//#include "tableitems.h" 34//#include "tableitems.h"
35#include "tableview.h" 35#include "tableview.h"
36 36
37using namespace Todo; 37using namespace Todo;
38 38
39 39
40TableView::TableView( MainWindow* window, QWidget* wid ) 40TableView::TableView( MainWindow* window, QWidget* wid )
41 : QTable( wid ), TodoView( window ) { 41 : QTable( wid ), TodoView( window ) {
42 setUpdatesEnabled( false ); 42 setUpdatesEnabled( false );
43 viewport()->setUpdatesEnabled( false ); 43 viewport()->setUpdatesEnabled( false );
44 m_enablePaint = false; 44 m_enablePaint = false;
45 setNumRows(0); 45 setNumRows(0);
46 setNumCols(4); 46 setNumCols(4);
47 47
48 setSorting( TRUE ); 48 setSorting( TRUE );
49 setSelectionMode( NoSelection ); 49 setSelectionMode( NoSelection );
50 setColumnStretchable( 2, TRUE ); 50 setColumnStretchable( 2, TRUE );
51 setColumnWidth(0, 20 ); 51 setColumnWidth(0, 20 );
52 setColumnWidth(1, 35 ); 52 setColumnWidth(1, 35 );
53 53
54 setLeftMargin( 0 ); 54 setLeftMargin( 0 );
55 verticalHeader()->hide(); 55 verticalHeader()->hide();
56 56
57 horizontalHeader()->setLabel(0, tr("C.") ); 57 horizontalHeader()->setLabel(0, tr("C.") );
58 horizontalHeader()->setLabel(1, tr("Prior.") ); 58 horizontalHeader()->setLabel(1, tr("Prior.") );
59 horizontalHeader()->setLabel(2, tr("Description" ) ); 59 horizontalHeader()->setLabel(2, tr("Description" ) );
60 60
61 setColumnStretchable(3, FALSE ); 61 setColumnStretchable(3, FALSE );
62 setColumnWidth(3, 20 ); 62 setColumnWidth(3, 20 );
63 horizontalHeader()->setLabel(3, tr("Deadline") ); 63 horizontalHeader()->setLabel(3, tr("Deadline") );
64 64
65 if ( todoWindow()->showDeadline() ) 65 if ( todoWindow()->showDeadline() )
66 showColumn( 3); 66 showColumn( 3);
67 else 67 else
68 hideColumn(3 ); 68 hideColumn(3 );
69 69
70 connect((QTable*)this, SIGNAL( clicked( int, int, int, const QPoint& ) ), 70 connect((QTable*)this, SIGNAL( clicked( int, int, int, const QPoint& ) ),
71 this, SLOT( slotClicked(int, int, int, const QPoint& ) ) ); 71 this, SLOT( slotClicked(int, int, int, const QPoint& ) ) );
72 connect((QTable*)this, SIGNAL( pressed( int, int, int, const QPoint& ) ), 72 connect((QTable*)this, SIGNAL( pressed( int, int, int, const QPoint& ) ),
73 this, SLOT( slotPressed(int, int, int, const QPoint& ) ) ); 73 this, SLOT( slotPressed(int, int, int, const QPoint& ) ) );
74 connect((QTable*)this, SIGNAL(valueChanged(int, int) ), 74 connect((QTable*)this, SIGNAL(valueChanged(int, int) ),
75 this, SLOT( slotValueChanged(int, int) ) ); 75 this, SLOT( slotValueChanged(int, int) ) );
76 connect((QTable*)this, SIGNAL(currentChanged(int, int) ), 76 connect((QTable*)this, SIGNAL(currentChanged(int, int) ),
77 this, SLOT( slotCurrentChanged(int, int) ) ); 77 this, SLOT( slotCurrentChanged(int, int) ) );
78 78
79 m_menuTimer = new QTimer( this ); 79 m_menuTimer = new QTimer( this );
80 connect( m_menuTimer, SIGNAL(timeout()), 80 connect( m_menuTimer, SIGNAL(timeout()),
81 this, SLOT(slotShowMenu()) ); 81 this, SLOT(slotShowMenu()) );
82 82
83 m_enablePaint = true; 83 m_enablePaint = true;
84 setUpdatesEnabled( true ); 84 setUpdatesEnabled( true );
85 viewport()->setUpdatesEnabled( true ); 85 viewport()->setUpdatesEnabled( true );
86 viewport()->update(); 86 viewport()->update();
87} 87}
88/* a new day has started 88/* a new day has started
89 * update the day 89 * update the day
90 */ 90 */
91void TableView::newDay() { 91void TableView::newDay() {
92 clear(); 92 clear();
93 setTodos( begin(),end() ); 93 setTodos( begin(),end() );
94} 94}
95TableView::~TableView() { 95TableView::~TableView() {
96 96
97} 97}
98void TableView::slotShowMenu() { 98void TableView::slotShowMenu() {
99 QPopupMenu *menu = todoWindow()->contextMenu( current() ); 99 QPopupMenu *menu = todoWindow()->contextMenu( current() );
100 menu->exec(QCursor::pos() ); 100 menu->exec(QCursor::pos() );
101 delete menu; 101 delete menu;
102} 102}
103OTodo TableView::find(int uid ) { 103OTodo TableView::find(int uid ) {
104 OTodo ev = TodoView::event( uid ); 104 OTodo ev = TodoView::event( uid );
105 return ev; 105 return ev;
106} 106}
107void TableView::updateFromTable( const OTodo& ev, CheckItem* item ) { 107void TableView::updateFromTable( const OTodo& ev, CheckItem* item ) {
108 TodoView::update( ev.uid(), ev ); 108 TodoView::update( ev.uid(), ev );
109 109
110 /* update the other columns */ 110 /* update the other columns */
111 /* if completed or not we need to update 111 /* if completed or not we need to update
112 * the table 112 * the table
113 * 113 *
114 * We've two cases 114 * We've two cases
115 * either item or !item 115 * either item or !item
116 * this makes cases more easy 116 * this makes cases more easy
117 */ 117 */
118 if ( !item ) { 118 if ( !item ) {
119 item = m_cache[ev.uid()]; 119 item = m_cache[ev.uid()];
120 } 120 }
121 DueTextItem *due = dueItem( item->row() ); 121 DueTextItem *due = dueItem( item->row() );
122 due->setCompleted( ev.isCompleted() ); 122 due->setCompleted( ev.isCompleted() );
123} 123}
124QString TableView::type() const { 124QString TableView::type() const {
125 return QString::fromLatin1( tr("Table View") ); 125 return QString::fromLatin1( tr("Table View") );
126} 126}
127int TableView::current() { 127int TableView::current() {
128 int cur = 0; 128 int cur = 0;
129 CheckItem* i = checkItem( currentRow() ); 129 CheckItem* i = checkItem( currentRow() );
130 if (i ) 130 if (i )
131 cur = i->uid(); 131 cur = i->uid();
132 132
133 return cur; 133 return cur;
134} 134}
135QString TableView::currentRepresentation() { 135QString TableView::currentRepresentation() {
136 return text( currentRow(), 2); 136 return text( currentRow(), 2);
137} 137}
138/* show overdue */ 138/* show overdue */
139void TableView::showOverDue( bool ) { 139void TableView::showOverDue( bool ) {
140 clear(); 140 clear();
141 setTodos( begin(), end() ); 141 setTodos( begin(), end() );
142} 142}
143 143
144void TableView::setTodos( OTodoAccess::List::Iterator it, 144void TableView::setTodos( OTodoAccess::List::Iterator it,
145 OTodoAccess::List::Iterator end ) { 145 OTodoAccess::List::Iterator end ) {
146 qWarning("setTodos"); 146 qWarning("setTodos");
147 QTime time; 147 QTime time;
148 time.start(); 148 time.start();
149 m_enablePaint = false; 149 m_enablePaint = false;
150 setUpdatesEnabled( false ); 150 setUpdatesEnabled( false );
151 viewport()->setUpdatesEnabled( false ); 151 viewport()->setUpdatesEnabled( false );
152 clear(); 152 clear();
153 QString currentCat = todoWindow()->currentCategory(); 153 QString currentCat = todoWindow()->currentCategory();
154 bool showCompleted = todoWindow()->currentCatId(); 154 bool showCompleted = todoWindow()->showCompleted();
155 bool showOverDue = todoWindow()->showOverDue(); 155 bool showOverDue = todoWindow()->showOverDue();
156 qWarning( "Current Category:" + todoWindow()->currentCategory() ); 156 qWarning( "Current Category:" + todoWindow()->currentCategory() );
157 int id = todoWindow()->currentCatId(); 157 int id = todoWindow()->currentCatId();
158 QTime t; 158 QTime t;
159 t.start(); 159 t.start();
160 setNumRows( it.count() ); 160 setNumRows( it.count() );
161 uint i = 0; 161 uint i = 0;
162 for (; it != end; ++it ) { 162 for (; it != end; ++it ) {
163 OTodo todo = (*it); 163 OTodo todo = (*it);
164 /* test if the categories match */ 164 /* test if the categories match */
165 if ( !currentCat.isEmpty() && 165 if ( !currentCat.isEmpty() &&
166 !todo.categories().contains( id ) ) { 166 !todo.categories().contains( id ) ) {
167 continue; 167 continue;
168 } 168 }
169 /* the item is completed but we shouldn't show it */ 169 /* the item is completed but we shouldn't show it */
170 if ( !showCompleted && todo.isCompleted() ) { 170 if ( !showCompleted && todo.isCompleted() ) {
171 qWarning("isCompleted ");
171 continue; 172 continue;
172 } 173 }
173 /* the item is not overdue but we should only show overdue */ 174 /* the item is not overdue but we should only show overdue */
174 if ( showOverDue && !todo.isOverdue() ) { 175 if ( showOverDue && !todo.isOverdue() ) {
175 continue; 176 continue;
176 } 177 }
177 /* now it's fine to add it */ 178 /* now it's fine to add it */
178 insertTodo( todo, i ); 179 insertTodo( todo, i );
179 i++; 180 i++;
180 } 181 }
181 setNumRows( i ); 182 setNumRows( i );
182 int elc = time.elapsed(); 183 int elc = time.elapsed();
183 qWarning("Adding took %d", elc/1000 ); 184 qWarning("Adding took %d", elc/1000 );
184 setUpdatesEnabled( true ); 185 setUpdatesEnabled( true );
185 viewport()->setUpdatesEnabled( true ); 186 viewport()->setUpdatesEnabled( true );
186 viewport()->update(); 187 viewport()->update();
187 m_enablePaint = true; 188 m_enablePaint = true;
188 int el = time.elapsed(); 189 int el = time.elapsed();
189 qWarning("adding took %d", el/1000 ); 190 qWarning("adding took %d", el/1000 );
190} 191}
191void TableView::setTodo( int uid, const OTodo& ev ) { 192void TableView::setTodo( int uid, const OTodo& ev ) {
192 QMap<int, CheckItem*>::Iterator it = m_cache.find( uid ); 193 QMap<int, CheckItem*>::Iterator it = m_cache.find( uid );
193 194
194 if ( it != m_cache.end() ) { 195 if ( it != m_cache.end() ) {
195 int row = it.data()->row(); 196 int row = it.data()->row();
196 197
197 /* update checked */ 198 /* update checked */
198 CheckItem* check = checkItem(row ); 199 CheckItem* check = checkItem(row );
199 if (check) 200 if (check)
200 check->setChecked( ev.isCompleted() ); 201 check->setChecked( ev.isCompleted() );
201 202
202 /* update the text */ 203 /* update the text */
203 QString sum = ev.summary(); 204 QString sum = ev.summary();
204 setText(row, 2, sum.isEmpty() ? 205 setText(row, 2, sum.isEmpty() ?
205 ev.description().left(40).simplifyWhiteSpace() : 206 ev.description().left(40).simplifyWhiteSpace() :
206 sum ); 207 sum );
207 208
208 /* update priority */ 209 /* update priority */
209 setText(row, 1, QString::number( ev.priority() ) ); 210 setText(row, 1, QString::number( ev.priority() ) );
210 211
211 /* update DueDate */ 212 /* update DueDate */
212 DueTextItem *due = dueItem( row ); 213 DueTextItem *due = dueItem( row );
213 due->setToDoEvent( ev ); 214 due->setToDoEvent( ev );
214 } 215 }
215} 216}
216void TableView::addEvent( const OTodo& ev) { 217void TableView::addEvent( const OTodo& ev) {
217 int row= numRows(); 218 int row= numRows();
218 setNumRows( row + 1 ); 219 setNumRows( row + 1 );
219 insertTodo( ev, row ); 220 insertTodo( ev, row );
220} 221}
221/* 222/*
222 * find the event 223 * find the event
223 * and then replace the complete row 224 * and then replace the complete row
224 */ 225 */
225void TableView::replaceEvent( const OTodo& ev) { 226void TableView::replaceEvent( const OTodo& ev) {
226 setTodo( ev.uid(), ev ); 227 setTodo( ev.uid(), ev );
227} 228}
228/* 229/*
229 * re aligning table can be slow too 230 * re aligning table can be slow too
230 * FIXME: look what performs better 231 * FIXME: look what performs better
231 * either this or the old align table 232 * either this or the old align table
232 */ 233 */
233void TableView::removeEvent( int ) { 234void TableView::removeEvent( int ) {
234 clear(); 235 clear();
235 setTodos( begin(), end() ); 236 setTodos( begin(), end() );
236} 237}
237void TableView::setShowCompleted( bool b) { 238void TableView::setShowCompleted( bool b) {
238 qWarning("Show Completed %d" + b ); 239 qWarning("Show Completed %d" + b );
239 setTodos( begin(), end() ); 240 setTodos( begin(), end() );
240} 241}
241void TableView::setShowDeadline( bool b) { 242void TableView::setShowDeadline( bool b) {
242 qWarning("Show DeadLine %d" + b ); 243 qWarning("Show DeadLine %d" + b );
243 if (b) 244 if (b)
244 showColumn(3 ); 245 showColumn(3 );
245 else 246 else
246 hideColumn(3 ); 247 hideColumn(3 );
247} 248}
248void TableView::setShowCategory( const QString& ) { 249void TableView::setShowCategory( const QString& ) {
249 qWarning("setShowCategory"); 250 qWarning("setShowCategory");
250 setTodos( begin(), end() ); 251 setTodos( begin(), end() );
251} 252}
252void TableView::clear() { 253void TableView::clear() {
253 m_cache.clear(); 254 m_cache.clear();
254 int rows = numRows(); 255 int rows = numRows();
255 for (int r = 0; r < rows; r++ ) { 256 for (int r = 0; r < rows; r++ ) {
256 for (int c = 0; c < numCols(); c++ ) { 257 for (int c = 0; c < numCols(); c++ ) {
257 if ( cellWidget(r, c) ) 258 if ( cellWidget(r, c) )
258 clearCellWidget(r, c ); 259 clearCellWidget(r, c );
259 clearCell(r, c); 260 clearCell(r, c);
260 } 261 }
261 } 262 }
262 setNumRows( 0); 263 setNumRows( 0);
263} 264}
264QArray<int> TableView::completed() { 265QArray<int> TableView::completed() {
265 int row = numRows(); 266 int row = numRows();
266 QArray<int> ids( row ); 267 QArray<int> ids( row );
267 268
268 int j=0; 269 int j=0;
269 for (int i = 0; i < row; i++ ) { 270 for (int i = 0; i < row; i++ ) {
270 CheckItem* item = checkItem(i ); 271 CheckItem* item = checkItem(i );
271 if (item->isChecked() ) { 272 if (item->isChecked() ) {
272 ids[j] = item->uid(); 273 ids[j] = item->uid();
273 j++; 274 j++;
274 } 275 }
275 } 276 }
276 ids.resize( j ); 277 ids.resize( j );
277 return ids; 278 return ids;
278} 279}
279void TableView::slotClicked(int row, int col, int, 280void TableView::slotClicked(int row, int col, int,
280 const QPoint& point) { 281 const QPoint& point) {
281 if ( !cellGeometry(row, col ).contains(point ) ) 282 if ( !cellGeometry(row, col ).contains(point ) )
282 return; 283 return;
283 284
284 285
285 switch( col ) { 286 switch( col ) {
286 case 0: { 287 case 0: {
287 CheckItem* item = checkItem( row ); 288 CheckItem* item = checkItem( row );
288 /* 289 /*
289 * let's see if we centered clicked 290 * let's see if we centered clicked
290 */ 291 */
291 if ( item ) { 292 if ( item ) {
292 int x = point.x() -columnPos( col ); 293 int x = point.x() -columnPos( col );
293 int y = point.y() -rowPos( row ); 294 int y = point.y() -rowPos( row );
294 int w = columnWidth( col ); 295 int w = columnWidth( col );
295 int h = rowHeight( row ); 296 int h = rowHeight( row );
296 if ( x >= ( w - OCheckItem::BoxSize ) / 2 && 297 if ( x >= ( w - OCheckItem::BoxSize ) / 2 &&
297 x <= ( w - OCheckItem::BoxSize ) / 2 + OCheckItem::BoxSize && 298 x <= ( w - OCheckItem::BoxSize ) / 2 + OCheckItem::BoxSize &&
298 y >= ( h - OCheckItem::BoxSize ) / 2 && 299 y >= ( h - OCheckItem::BoxSize ) / 2 &&
299 y <= ( h - OCheckItem::BoxSize ) / 2 + OCheckItem::BoxSize ) 300 y <= ( h - OCheckItem::BoxSize ) / 2 + OCheckItem::BoxSize )
300 item->toggle(); 301 item->toggle();
301 } 302 }
302 } 303 }
303 break; 304 break;
304 305
305 case 1: 306 case 1:
306 break; 307 break;
307 308
308 case 2: { 309 case 2: {
309 m_menuTimer->stop(); 310 m_menuTimer->stop();
310 showTodo( checkItem(row)->uid() ); 311 showTodo( checkItem(row)->uid() );
311 break; 312 break;
312 } 313 }
313 case 3: { 314 case 3: {
314 m_menuTimer->stop(); 315 m_menuTimer->stop();
315 TodoView::edit( checkItem(row)->uid() ); 316 TodoView::edit( checkItem(row)->uid() );
316 break; 317 break;
317 } 318 }
318 } 319 }
319 320
320 321
321} 322}
322void TableView::slotPressed(int row, int col, int, 323void TableView::slotPressed(int row, int col, int,
323 const QPoint& point) { 324 const QPoint& point) {
324 325
325 /* TextColumn column */ 326 /* TextColumn column */
326 if ( col == 2 && cellGeometry( row, col ).contains( point ) ) 327 if ( col == 2 && cellGeometry( row, col ).contains( point ) )
327 m_menuTimer->start( 750, TRUE ); 328 m_menuTimer->start( 750, TRUE );
328} 329}
329void TableView::slotValueChanged( int, int ) { 330void TableView::slotValueChanged( int, int ) {
330 qWarning("Value Changed"); 331 qWarning("Value Changed");
331} 332}
332void TableView::slotCurrentChanged(int, int ) { 333void TableView::slotCurrentChanged(int, int ) {
333 m_menuTimer->stop(); 334 m_menuTimer->stop();
334} 335}
335/* 336/*
336 * hardcode to column 0 337 * hardcode to column 0
337 */ 338 */
338CheckItem* TableView::checkItem( int row ) { 339CheckItem* TableView::checkItem( int row ) {
339 CheckItem *i = static_cast<CheckItem*>( item( row, 0 ) ); 340 CheckItem *i = static_cast<CheckItem*>( item( row, 0 ) );
340 return i; 341 return i;
341} 342}
342DueTextItem* TableView::dueItem( int row ) { 343DueTextItem* TableView::dueItem( int row ) {
343 DueTextItem* i = static_cast<DueTextItem*> ( item(row, 3 ) ); 344 DueTextItem* i = static_cast<DueTextItem*> ( item(row, 3 ) );
344 return i; 345 return i;
345} 346}
346QWidget* TableView::widget() { 347QWidget* TableView::widget() {
347 return this; 348 return this;
348} 349}
349/* 350/*
350 * We need to overwrite sortColumn 351 * We need to overwrite sortColumn
351 * because we want to sort whole row 352 * because we want to sort whole row
352 * based 353 * based
353 */ 354 */
354void TableView::sortColumn( int row, bool asc, bool ) { 355void TableView::sortColumn( int row, bool asc, bool ) {
355 QTable::sortColumn( row, asc, TRUE ); 356 QTable::sortColumn( row, asc, TRUE );
356 357
357} 358}
358void TableView::viewportPaintEvent( QPaintEvent* e) { 359void TableView::viewportPaintEvent( QPaintEvent* e) {
359 qWarning("Paint event" ); 360 qWarning("Paint event" );
360 if (m_enablePaint ) 361 if (m_enablePaint )
361 QTable::viewportPaintEvent( e ); 362 QTable::viewportPaintEvent( e );
362} 363}