-rw-r--r-- | core/pim/todo/tableview.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/core/pim/todo/tableview.cpp b/core/pim/todo/tableview.cpp index def0efb..3daf370 100644 --- a/core/pim/todo/tableview.cpp +++ b/core/pim/todo/tableview.cpp | |||
@@ -1,300 +1,300 @@ | |||
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 | ||
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) { | 53 | TableView::EditorWidget::EditorWidget() : m_wid(0l), m_row(-1), m_col(-1) { |
54 | } | 54 | } |
55 | void TableView::EditorWidget::setCellWidget(QWidget* wid, int row, int col ) { | 55 | void 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 | } |
60 | void TableView::EditorWidget::releaseCellWidget() { | 60 | void 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 | } |
64 | QWidget* TableView::EditorWidget::cellWidget()const { | 64 | QWidget* TableView::EditorWidget::cellWidget()const { |
65 | return m_wid; | 65 | return m_wid; |
66 | } | 66 | } |
67 | int TableView::EditorWidget::cellRow()const { | 67 | int TableView::EditorWidget::cellRow()const { |
68 | return m_row; | 68 | return m_row; |
69 | } | 69 | } |
70 | int TableView::EditorWidget::cellCol()const { | 70 | int TableView::EditorWidget::cellCol()const { |
71 | return m_col; | 71 | return m_col; |
72 | } | 72 | } |
73 | 73 | ||
74 | 74 | ||
75 | void TableView::initConfig() { | 75 | void 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 | ||
85 | TableView::TableView( MainWindow* window, QWidget* wid ) | 85 | TableView::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("Description" ) ); | 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 | */ |
149 | void TableView::newDay() { | 149 | void TableView::newDay() { |
150 | clear(); | 150 | clear(); |
151 | updateView(); | 151 | updateView(); |
152 | } | 152 | } |
153 | TableView::~TableView() { | 153 | TableView::~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 | } |
159 | void TableView::slotShowMenu() { | 159 | void 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 | } |
164 | QString TableView::type() const { | 164 | QString TableView::type() const { |
165 | return QString::fromLatin1( tr("Table View") ); | 165 | return QString::fromLatin1( tr("Table View") ); |
166 | } | 166 | } |
167 | int TableView::current() { | 167 | int 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 | } |
173 | int TableView::next() { | 173 | int 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 | } |
179 | int TableView::prev() { | 179 | int 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 | } |
186 | QString TableView::currentRepresentation() { | 186 | QString 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 */ |
191 | void TableView::showOverDue( bool ) { | 191 | void TableView::showOverDue( bool ) { |
192 | clear(); | 192 | clear(); |
193 | updateView(); | 193 | updateView(); |
194 | } | 194 | } |
195 | 195 | ||
196 | void TableView::updateView( ) { | 196 | void 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 | } |
230 | void TableView::setTodo( int, const OTodo&) { | 230 | void TableView::setTodo( int, const OTodo&) { |
231 | sort(); | 231 | sort(); |
232 | 232 | ||
233 | /* repaint */ | 233 | /* repaint */ |
234 | repaint(); | 234 | repaint(); |
235 | } | 235 | } |
236 | void TableView::addEvent( const OTodo&) { | 236 | void 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 | */ |
245 | void TableView::replaceEvent( const OTodo& ev) { | 245 | void 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 | */ |
253 | void TableView::removeEvent( int ) { | 253 | void TableView::removeEvent( int ) { |
254 | updateView(); | 254 | updateView(); |
255 | } | 255 | } |
256 | void TableView::setShowCompleted( bool b) { | 256 | void TableView::setShowCompleted( bool b) { |
257 | qWarning("Show Completed %d" , b ); | 257 | qWarning("Show Completed %d" , b ); |
258 | updateView(); | 258 | updateView(); |
259 | } | 259 | } |
260 | void TableView::setShowDeadline( bool b ) { | 260 | void 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 | } |
283 | void TableView::setShowCategory( const QString& str) { | 283 | void 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 | } |
292 | void TableView::clear() { | 292 | void TableView::clear() { |
293 | setNumRows(0); | 293 | setNumRows(0); |
294 | } | 294 | } |
295 | void TableView::slotClicked(int row, int col, int, | 295 | void 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 ); |