-rw-r--r-- | core/pim/todo/tableview.cpp | 86 |
1 files changed, 80 insertions, 6 deletions
diff --git a/core/pim/todo/tableview.cpp b/core/pim/todo/tableview.cpp index d9cda09..2e252d5 100644 --- a/core/pim/todo/tableview.cpp +++ b/core/pim/todo/tableview.cpp | |||
@@ -18,47 +18,68 @@ | |||
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 | 31 | ||
31 | #include <qcombobox.h> | 32 | #include <qcombobox.h> |
32 | #include <qlineedit.h> | 33 | #include <qlineedit.h> |
33 | #include <qtimer.h> | 34 | #include <qtimer.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 | ||
46 | using namespace Todo; | 46 | using namespace Todo; |
47 | 47 | ||
48 | namespace { | 48 | namespace { |
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 | TableView::EditorWidget::EditorWidget() : m_wid(0l), m_row(-1), m_col(-1) { | ||
54 | } | ||
55 | void TableView::EditorWidget::setCellWidget(QWidget* wid, int row, int col ) { | ||
56 | m_wid = wid; | ||
57 | m_row = row; | ||
58 | m_col = col; | ||
59 | } | ||
60 | void TableView::EditorWidget::releaseCellWidget() { | ||
61 | m_wid = 0; | ||
62 | m_row = m_col = -1; | ||
63 | } | ||
64 | QWidget* TableView::EditorWidget::cellWidget()const { | ||
65 | return m_wid; | ||
66 | } | ||
67 | int TableView::EditorWidget::cellRow()const { | ||
68 | return m_row; | ||
69 | } | ||
70 | int TableView::EditorWidget::cellCol()const { | ||
71 | return m_col; | ||
72 | } | ||
73 | |||
53 | 74 | ||
54 | void TableView::initConfig() { | 75 | void TableView::initConfig() { |
55 | Config config( "todo" ); | 76 | Config config( "todo" ); |
56 | config.setGroup( "Options" ); | 77 | config.setGroup( "Options" ); |
57 | m_completeStrokeWidth = config.readNumEntry( "CompleteStrokeWidth", 8 ); | 78 | m_completeStrokeWidth = config.readNumEntry( "CompleteStrokeWidth", 8 ); |
58 | for (int i = 0; i < numCols(); i++ ) { | 79 | for (int i = 0; i < numCols(); i++ ) { |
59 | int width = config.readNumEntry("Width"+QString::number(i), -1 ); | 80 | int width = config.readNumEntry("Width"+QString::number(i), -1 ); |
60 | setColumnWidth(i, width == -1 ? columnWidth(i) : width ); | 81 | setColumnWidth(i, width == -1 ? columnWidth(i) : width ); |
61 | } | 82 | } |
62 | } | 83 | } |
63 | 84 | ||
64 | TableView::TableView( MainWindow* window, QWidget* wid ) | 85 | TableView::TableView( MainWindow* window, QWidget* wid ) |
@@ -134,29 +155,42 @@ TableView::~TableView() { | |||
134 | for (int i = 0; i < numCols(); i++ ) | 155 | for (int i = 0; i < numCols(); i++ ) |
135 | config.writeEntry("Width"+QString::number(i), columnWidth(i) ); | 156 | config.writeEntry("Width"+QString::number(i), columnWidth(i) ); |
136 | } | 157 | } |
137 | void TableView::slotShowMenu() { | 158 | void TableView::slotShowMenu() { |
138 | QPopupMenu *menu = todoWindow()->contextMenu( current(), sorted()[currentRow()].recurrence().doesRecur() ); | 159 | QPopupMenu *menu = todoWindow()->contextMenu( current(), sorted()[currentRow()].recurrence().doesRecur() ); |
139 | menu->exec(QCursor::pos() ); | 160 | menu->exec(QCursor::pos() ); |
140 | delete menu; | 161 | delete menu; |
141 | } | 162 | } |
142 | QString TableView::type() const { | 163 | QString TableView::type() const { |
143 | return QString::fromLatin1( tr("Table View") ); | 164 | return QString::fromLatin1( tr("Table View") ); |
144 | } | 165 | } |
145 | int TableView::current() { | 166 | int TableView::current() { |
146 | if (numRows() == 0 ) return 1; | 167 | if (numRows() == 0 ) return 0; |
147 | int uid = sorted().uidAt(currentRow() ); | 168 | int uid = sorted().uidAt(currentRow() ); |
148 | 169 | ||
149 | return uid; | 170 | return uid; |
150 | } | 171 | } |
172 | int TableView::next() { | ||
173 | if ( numRows() == 0 ) return 0; | ||
174 | if ( currentRow() + 1 >= numRows() ) return 0; | ||
175 | setCurrentCell( currentRow() +1, currentColumn() ); | ||
176 | return sorted().uidAt( currentRow() ); | ||
177 | } | ||
178 | int TableView::prev() { | ||
179 | if ( numRows() == 0 ) return 0; | ||
180 | if ( currentRow() - 1 < 0 ) return 0; | ||
181 | setCurrentCell( currentRow() -1, currentColumn() ); | ||
182 | return sorted().uidAt( currentRow() ); | ||
183 | |||
184 | } | ||
151 | QString TableView::currentRepresentation() { | 185 | QString TableView::currentRepresentation() { |
152 | OTodo to = sorted()[currentRow()]; | 186 | OTodo to = sorted()[currentRow()]; |
153 | return to.summary().isEmpty() ? to.description().left(20) : to.summary() ; | 187 | return to.summary().isEmpty() ? to.description().left(20) : to.summary() ; |
154 | } | 188 | } |
155 | /* show overdue */ | 189 | /* show overdue */ |
156 | void TableView::showOverDue( bool ) { | 190 | void TableView::showOverDue( bool ) { |
157 | clear(); | 191 | clear(); |
158 | updateView(); | 192 | updateView(); |
159 | } | 193 | } |
160 | 194 | ||
161 | void TableView::updateView( ) { | 195 | void TableView::updateView( ) { |
162 | qWarning("update view"); | 196 | qWarning("update view"); |
@@ -210,29 +244,29 @@ void TableView::addEvent( const OTodo&) { | |||
210 | void TableView::replaceEvent( const OTodo& ev) { | 244 | void TableView::replaceEvent( const OTodo& ev) { |
211 | addEvent( ev ); | 245 | addEvent( ev ); |
212 | } | 246 | } |
213 | /* | 247 | /* |
214 | * re aligning table can be slow too | 248 | * re aligning table can be slow too |
215 | * FIXME: look what performs better | 249 | * FIXME: look what performs better |
216 | * either this or the old align table | 250 | * either this or the old align table |
217 | */ | 251 | */ |
218 | void TableView::removeEvent( int ) { | 252 | void TableView::removeEvent( int ) { |
219 | updateView(); | 253 | updateView(); |
220 | } | 254 | } |
221 | void TableView::setShowCompleted( bool b) { | 255 | void TableView::setShowCompleted( bool b) { |
222 | qWarning("Show Completed %d" + b ); | 256 | qWarning("Show Completed %d" , b ); |
223 | updateView(); | 257 | updateView(); |
224 | } | 258 | } |
225 | void TableView::setShowDeadline( bool b ) { | 259 | void TableView::setShowDeadline( bool b ) { |
226 | qWarning( "Show DeadLine %d" + b ); | 260 | qWarning( "Show DeadLine %d" , b ); |
227 | if ( b ) | 261 | if ( b ) |
228 | showColumn( 3 ); | 262 | showColumn( 3 ); |
229 | else | 263 | else |
230 | hideColumn( 3 ); | 264 | hideColumn( 3 ); |
231 | 265 | ||
232 | // Try to intelligently size columns | 266 | // Try to intelligently size columns |
233 | // TODO - would use width() below, but doesn't have valid value at time of c'tor | 267 | // TODO - would use width() below, but doesn't have valid value at time of c'tor |
234 | int col2width = 238; | 268 | int col2width = 238; |
235 | int width = m_pic_completed.width(); | 269 | int width = m_pic_completed.width(); |
236 | setColumnWidth( 0, width ); | 270 | setColumnWidth( 0, width ); |
237 | col2width -= width; | 271 | col2width -= width; |
238 | width = fontMetrics().boundingRect( horizontalHeader()->label( 1 ) ).width() + 8; | 272 | width = fontMetrics().boundingRect( horizontalHeader()->label( 1 ) ).width() + 8; |
@@ -250,46 +284,57 @@ void TableView::setShowCategory( const QString& str) { | |||
250 | if ( str != m_oleCat || m_first ) | 284 | if ( str != m_oleCat || m_first ) |
251 | updateView(); | 285 | updateView(); |
252 | 286 | ||
253 | m_oleCat = str; | 287 | m_oleCat = str; |
254 | m_first = false; | 288 | m_first = false; |
255 | 289 | ||
256 | } | 290 | } |
257 | void TableView::clear() { | 291 | void TableView::clear() { |
258 | setNumRows(0); | 292 | setNumRows(0); |
259 | } | 293 | } |
260 | void TableView::slotClicked(int row, int col, int, | 294 | void TableView::slotClicked(int row, int col, int, |
261 | const QPoint& point) { | 295 | const QPoint& point) { |
296 | if ( m_editorWidget.cellWidget() ) { | ||
297 | //setCellContentFromEditor(m_editorWidget.cellRow(), m_editorWidget.cellCol() ); | ||
298 | endEdit(m_editorWidget.cellRow(), m_editorWidget.cellCol(), | ||
299 | true, true ); | ||
300 | m_editorWidget.releaseCellWidget(); | ||
301 | } | ||
302 | |||
262 | if ( !cellGeometry(row, col ).contains(point ) ) | 303 | if ( !cellGeometry(row, col ).contains(point ) ) |
263 | return; | 304 | return; |
264 | 305 | ||
265 | int ui= sorted().uidAt( row ); | 306 | int ui= sorted().uidAt( row ); |
266 | 307 | ||
267 | 308 | ||
268 | switch( col ) { | 309 | switch( col ) { |
269 | case 0:{ | 310 | case 0:{ |
270 | int x = point.x() -columnPos( col ); | 311 | int x = point.x() -columnPos( col ); |
271 | int y = point.y() -rowPos( row ); | 312 | int y = point.y() -rowPos( row ); |
272 | int w = columnWidth( col ); | 313 | int w = columnWidth( col ); |
273 | int h = rowHeight( row ); | 314 | int h = rowHeight( row ); |
274 | if ( x >= ( w - BoxSize ) / 2 && | 315 | if ( x >= ( w - BoxSize ) / 2 && |
275 | x <= ( w - BoxSize ) / 2 + BoxSize && | 316 | x <= ( w - BoxSize ) / 2 + BoxSize && |
276 | y >= ( h - BoxSize ) / 2 && | 317 | y >= ( h - BoxSize ) / 2 && |
277 | y <= ( h - BoxSize ) / 2 + BoxSize ) { | 318 | y <= ( h - BoxSize ) / 2 + BoxSize ) { |
278 | TodoView::complete(sorted()[row] ); | 319 | TodoView::complete(sorted()[row] ); |
279 | } | 320 | } |
280 | } | 321 | } |
281 | break; | 322 | break; |
282 | 323 | ||
283 | case 1: | 324 | // Priority emit a double click... |
325 | case 1:{ | ||
326 | QWidget* wid = beginEdit( row, col, FALSE ); | ||
327 | m_editorWidget.setCellWidget( wid, row, col ); | ||
328 | } | ||
284 | break; | 329 | break; |
285 | 330 | ||
286 | case 2: { | 331 | case 2: { |
287 | m_menuTimer->stop(); | 332 | m_menuTimer->stop(); |
288 | showTodo( ui ); | 333 | showTodo( ui ); |
289 | break; | 334 | break; |
290 | } | 335 | } |
291 | case 3: { | 336 | case 3: { |
292 | m_menuTimer->stop(); | 337 | m_menuTimer->stop(); |
293 | TodoView::edit( ui ); | 338 | TodoView::edit( ui ); |
294 | break; | 339 | break; |
295 | } | 340 | } |
@@ -437,24 +482,25 @@ QWidget* TableView::createEditor(int row, int col, bool )const { | |||
437 | /* summary */ | 482 | /* summary */ |
438 | case 2:{ | 483 | case 2:{ |
439 | QLineEdit* edit = new QLineEdit( viewport() ); | 484 | QLineEdit* edit = new QLineEdit( viewport() ); |
440 | edit->setText( sorted()[row].summary() ); | 485 | edit->setText( sorted()[row].summary() ); |
441 | return edit; | 486 | return edit; |
442 | } | 487 | } |
443 | case 0: | 488 | case 0: |
444 | default: | 489 | default: |
445 | return 0l; | 490 | return 0l; |
446 | } | 491 | } |
447 | } | 492 | } |
448 | void TableView::setCellContentFromEditor(int row, int col ) { | 493 | void TableView::setCellContentFromEditor(int row, int col ) { |
494 | qWarning("set cell content from editor"); | ||
449 | if ( col == 1 ) { | 495 | if ( col == 1 ) { |
450 | QWidget* wid = cellWidget(row, 1 ); | 496 | QWidget* wid = cellWidget(row, 1 ); |
451 | if ( wid->inherits("QComboBox") ) { | 497 | if ( wid->inherits("QComboBox") ) { |
452 | int pri = ((QComboBox*)wid)->currentItem() + 1; | 498 | int pri = ((QComboBox*)wid)->currentItem() + 1; |
453 | OTodo todo = sorted()[row]; | 499 | OTodo todo = sorted()[row]; |
454 | if ( todo.priority() != pri ) { | 500 | if ( todo.priority() != pri ) { |
455 | todo.setPriority( pri ); | 501 | todo.setPriority( pri ); |
456 | TodoView::update( todo.uid(), todo ); | 502 | TodoView::update( todo.uid(), todo ); |
457 | updateView(); | 503 | updateView(); |
458 | } | 504 | } |
459 | } | 505 | } |
460 | }else if ( col == 2) { | 506 | }else if ( col == 2) { |
@@ -533,22 +579,50 @@ void TableView::contentsMouseReleaseEvent( QMouseEvent* e) { | |||
533 | if ( row == rowAt( e->y() ) && row != -1 && | 579 | if ( row == rowAt( e->y() ) && row != -1 && |
534 | colOld != colNew ) { | 580 | colOld != colNew ) { |
535 | TodoView::complete( sorted()[row] ); | 581 | TodoView::complete( sorted()[row] ); |
536 | return; | 582 | return; |
537 | } | 583 | } |
538 | QTable::contentsMouseReleaseEvent( e ); | 584 | QTable::contentsMouseReleaseEvent( e ); |
539 | } | 585 | } |
540 | void TableView::contentsMouseMoveEvent( QMouseEvent* e ) { | 586 | void TableView::contentsMouseMoveEvent( QMouseEvent* e ) { |
541 | m_menuTimer->stop(); | 587 | m_menuTimer->stop(); |
542 | QTable::contentsMouseMoveEvent( e ); | 588 | QTable::contentsMouseMoveEvent( e ); |
543 | } | 589 | } |
544 | void TableView::keyPressEvent( QKeyEvent* event) { | 590 | void TableView::keyPressEvent( QKeyEvent* event) { |
591 | if ( m_editorWidget.cellWidget() ) { | ||
592 | // setCellContentFromEditor(m_editorWidget.cellRow(), m_editorWidget.cellCol() ); | ||
593 | endEdit(m_editorWidget.cellRow(), m_editorWidget.cellCol(), | ||
594 | true, true ); | ||
595 | m_editorWidget.releaseCellWidget(); | ||
596 | setFocus(); | ||
597 | } | ||
598 | int row = currentRow(); | ||
599 | int col = currentColumn(); | ||
600 | |||
601 | char key = ::toupper( event->ascii() ); | ||
602 | /* let QTable also handle the d later */ | ||
603 | if ( key == 'D' ) | ||
604 | removeQuery( sorted().uidAt( row ) ); | ||
605 | |||
606 | |||
545 | switch( event->key() ) { | 607 | switch( event->key() ) { |
546 | case Qt::Key_F33: | 608 | case Qt::Key_F33: |
547 | case Qt::Key_Enter: | 609 | case Qt::Key_Enter: |
548 | case Qt::Key_Return: | 610 | case Qt::Key_Return: |
549 | showTodo( sorted().uidAt( currentRow() ) ); | 611 | case Qt::Key_Space: |
612 | if ( col == 0 ) { | ||
613 | TodoView::complete(sorted()[row]); | ||
614 | }else if ( col == 1 ) { | ||
615 | QWidget* wid = beginEdit(row, col, FALSE ); | ||
616 | m_editorWidget.setCellWidget( wid, row, col ); | ||
617 | }else if ( col == 2 ) { | ||
618 | showTodo( sorted().uidAt( currentRow() ) ); | ||
619 | }else if ( col == 3 ) { | ||
620 | TodoView::edit( sorted().uidAt(row) ); | ||
621 | } | ||
622 | |||
550 | break; | 623 | break; |
551 | default: | 624 | default: |
552 | QTable::keyPressEvent( event ); | 625 | QTable::keyPressEvent( event ); |
553 | } | 626 | } |
554 | } | 627 | } |
628 | |||