author | simon <simon> | 2002-04-30 14:27:27 (UTC) |
---|---|---|
committer | simon <simon> | 2002-04-30 14:27:27 (UTC) |
commit | 972fbb128294c821ff0f13ea59a83edb015d571e (patch) (unidiff) | |
tree | 29d5de901e2e6c679d4cc76286e3e6e77a49b297 | |
parent | 5dae945f8ec25a811efb10eb71d606ce8da4429f (diff) | |
download | opie-972fbb128294c821ff0f13ea59a83edb015d571e.zip opie-972fbb128294c821ff0f13ea59a83edb015d571e.tar.gz opie-972fbb128294c821ff0f13ea59a83edb015d571e.tar.bz2 |
- XMLTree is in the Opie namespace now
-rw-r--r-- | core/pim/todo/todotable.cpp | 2 | ||||
-rw-r--r-- | core/pim/todo/todotable.h | 4 |
2 files changed, 6 insertions, 0 deletions
diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp index 208a084..2389cdd 100644 --- a/core/pim/todo/todotable.cpp +++ b/core/pim/todo/todotable.cpp | |||
@@ -1,559 +1,561 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | /* Show Deadline was added by Stefan Eilers (se, eilers.stefan@epost.de) | 20 | /* Show Deadline was added by Stefan Eilers (se, eilers.stefan@epost.de) |
21 | */ | 21 | */ |
22 | #include "todotable.h" | 22 | #include "todotable.h" |
23 | 23 | ||
24 | #include <opie/tododb.h> | 24 | #include <opie/tododb.h> |
25 | #include <opie/xmltree.h> | 25 | #include <opie/xmltree.h> |
26 | 26 | ||
27 | #include <qpe/categoryselect.h> | 27 | #include <qpe/categoryselect.h> |
28 | #include <qpe/xmlreader.h> | 28 | #include <qpe/xmlreader.h> |
29 | 29 | ||
30 | #include <qasciidict.h> | 30 | #include <qasciidict.h> |
31 | #include <qcombobox.h> | 31 | #include <qcombobox.h> |
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | #include <qpainter.h> | 33 | #include <qpainter.h> |
34 | #include <qtextcodec.h> | 34 | #include <qtextcodec.h> |
35 | #include <qtimer.h> | 35 | #include <qtimer.h> |
36 | #include <qdatetime.h> | 36 | #include <qdatetime.h> |
37 | #include <qtextstream.h> | 37 | #include <qtextstream.h> |
38 | 38 | ||
39 | #include <qcursor.h> | 39 | #include <qcursor.h> |
40 | #include <qregexp.h> | 40 | #include <qregexp.h> |
41 | 41 | ||
42 | #include <errno.h> | 42 | #include <errno.h> |
43 | #include <stdlib.h> | 43 | #include <stdlib.h> |
44 | 44 | ||
45 | #include <stdio.h> | 45 | #include <stdio.h> |
46 | #include <iostream> | 46 | #include <iostream> |
47 | 47 | ||
48 | using namespace Opie; | ||
49 | |||
48 | namespace { | 50 | namespace { |
49 | 51 | ||
50 | static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ); | 52 | static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ); |
51 | static QString journalFileName(); | 53 | static QString journalFileName(); |
52 | static ToDoEvent xmlToEvent( XMLElement *ev ); | 54 | static ToDoEvent xmlToEvent( XMLElement *ev ); |
53 | } | 55 | } |
54 | CheckItem::CheckItem( QTable *t, const QString &key ) | 56 | CheckItem::CheckItem( QTable *t, const QString &key ) |
55 | : QTableItem( t, Never, "" ), checked( FALSE ), sortKey( key ) | 57 | : QTableItem( t, Never, "" ), checked( FALSE ), sortKey( key ) |
56 | { | 58 | { |
57 | } | 59 | } |
58 | 60 | ||
59 | QString CheckItem::key() const | 61 | QString CheckItem::key() const |
60 | { | 62 | { |
61 | return sortKey; | 63 | return sortKey; |
62 | } | 64 | } |
63 | 65 | ||
64 | void CheckItem::setChecked( bool b ) | 66 | void CheckItem::setChecked( bool b ) |
65 | { | 67 | { |
66 | checked = b; | 68 | checked = b; |
67 | table()->updateCell( row(), col() ); | 69 | table()->updateCell( row(), col() ); |
68 | } | 70 | } |
69 | 71 | ||
70 | void CheckItem::toggle() | 72 | void CheckItem::toggle() |
71 | { | 73 | { |
72 | TodoTable *parent = static_cast<TodoTable*>(table()); | 74 | TodoTable *parent = static_cast<TodoTable*>(table()); |
73 | ToDoEvent newTodo = parent->currentEntry(); | 75 | ToDoEvent newTodo = parent->currentEntry(); |
74 | checked = !checked; | 76 | checked = !checked; |
75 | newTodo.setCompleted( checked ); | 77 | newTodo.setCompleted( checked ); |
76 | table()->updateCell( row(), col() ); | 78 | table()->updateCell( row(), col() ); |
77 | parent->replaceCurrentEntry( newTodo, true ); | 79 | parent->replaceCurrentEntry( newTodo, true ); |
78 | } | 80 | } |
79 | 81 | ||
80 | bool CheckItem::isChecked() const | 82 | bool CheckItem::isChecked() const |
81 | { | 83 | { |
82 | return checked; | 84 | return checked; |
83 | } | 85 | } |
84 | 86 | ||
85 | static const int BoxSize = 10; | 87 | static const int BoxSize = 10; |
86 | 88 | ||
87 | void CheckItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, | 89 | void CheckItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, |
88 | bool ) | 90 | bool ) |
89 | { | 91 | { |
90 | p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); | 92 | p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); |
91 | 93 | ||
92 | int marg = ( cr.width() - BoxSize ) / 2; | 94 | int marg = ( cr.width() - BoxSize ) / 2; |
93 | int x = 0; | 95 | int x = 0; |
94 | int y = ( cr.height() - BoxSize ) / 2; | 96 | int y = ( cr.height() - BoxSize ) / 2; |
95 | p->setPen( QPen( cg.text() ) ); | 97 | p->setPen( QPen( cg.text() ) ); |
96 | p->drawRect( x + marg, y, BoxSize, BoxSize ); | 98 | p->drawRect( x + marg, y, BoxSize, BoxSize ); |
97 | p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 ); | 99 | p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 ); |
98 | p->setPen( darkGreen ); | 100 | p->setPen( darkGreen ); |
99 | x += 1; | 101 | x += 1; |
100 | y += 1; | 102 | y += 1; |
101 | if ( checked ) { | 103 | if ( checked ) { |
102 | QPointArray a( 7*2 ); | 104 | QPointArray a( 7*2 ); |
103 | int i, xx, yy; | 105 | int i, xx, yy; |
104 | xx = x+1+marg; | 106 | xx = x+1+marg; |
105 | yy = y+2; | 107 | yy = y+2; |
106 | for ( i=0; i<3; i++ ) { | 108 | for ( i=0; i<3; i++ ) { |
107 | a.setPoint( 2*i, xx, yy ); | 109 | a.setPoint( 2*i, xx, yy ); |
108 | a.setPoint( 2*i+1, xx, yy+2 ); | 110 | a.setPoint( 2*i+1, xx, yy+2 ); |
109 | xx++; yy++; | 111 | xx++; yy++; |
110 | } | 112 | } |
111 | yy -= 2; | 113 | yy -= 2; |
112 | for ( i=3; i<7; i++ ) { | 114 | for ( i=3; i<7; i++ ) { |
113 | a.setPoint( 2*i, xx, yy ); | 115 | a.setPoint( 2*i, xx, yy ); |
114 | a.setPoint( 2*i+1, xx, yy+2 ); | 116 | a.setPoint( 2*i+1, xx, yy+2 ); |
115 | xx++; yy--; | 117 | xx++; yy--; |
116 | } | 118 | } |
117 | p->drawLineSegments( a ); | 119 | p->drawLineSegments( a ); |
118 | } | 120 | } |
119 | } | 121 | } |
120 | 122 | ||
121 | 123 | ||
122 | ComboItem::ComboItem( QTable *t, EditType et ) | 124 | ComboItem::ComboItem( QTable *t, EditType et ) |
123 | : QTableItem( t, et, "3" ), cb( 0 ) | 125 | : QTableItem( t, et, "3" ), cb( 0 ) |
124 | { | 126 | { |
125 | setReplaceable( FALSE ); | 127 | setReplaceable( FALSE ); |
126 | } | 128 | } |
127 | 129 | ||
128 | QWidget *ComboItem::createEditor() const | 130 | QWidget *ComboItem::createEditor() const |
129 | { | 131 | { |
130 | QString txt = text(); | 132 | QString txt = text(); |
131 | ( (ComboItem*)this )->cb = new QComboBox( table()->viewport() ); | 133 | ( (ComboItem*)this )->cb = new QComboBox( table()->viewport() ); |
132 | cb->insertItem( "1" ); | 134 | cb->insertItem( "1" ); |
133 | cb->insertItem( "2" ); | 135 | cb->insertItem( "2" ); |
134 | cb->insertItem( "3" ); | 136 | cb->insertItem( "3" ); |
135 | cb->insertItem( "4" ); | 137 | cb->insertItem( "4" ); |
136 | cb->insertItem( "5" ); | 138 | cb->insertItem( "5" ); |
137 | cb->setCurrentItem( txt.toInt() - 1 ); | 139 | cb->setCurrentItem( txt.toInt() - 1 ); |
138 | return cb; | 140 | return cb; |
139 | } | 141 | } |
140 | 142 | ||
141 | void ComboItem::setContentFromEditor( QWidget *w ) | 143 | void ComboItem::setContentFromEditor( QWidget *w ) |
142 | { | 144 | { |
143 | TodoTable *parent = static_cast<TodoTable*>(table()); | 145 | TodoTable *parent = static_cast<TodoTable*>(table()); |
144 | ToDoEvent newTodo = parent->currentEntry(); | 146 | ToDoEvent newTodo = parent->currentEntry(); |
145 | 147 | ||
146 | if ( w->inherits( "QComboBox" ) ) | 148 | if ( w->inherits( "QComboBox" ) ) |
147 | setText( ( (QComboBox*)w )->currentText() ); | 149 | setText( ( (QComboBox*)w )->currentText() ); |
148 | else | 150 | else |
149 | QTableItem::setContentFromEditor( w ); | 151 | QTableItem::setContentFromEditor( w ); |
150 | newTodo.setPriority( text().toInt() ); | 152 | newTodo.setPriority( text().toInt() ); |
151 | parent->replaceCurrentEntry( newTodo, true ); | 153 | parent->replaceCurrentEntry( newTodo, true ); |
152 | } | 154 | } |
153 | 155 | ||
154 | void ComboItem::setText( const QString &s ) | 156 | void ComboItem::setText( const QString &s ) |
155 | { | 157 | { |
156 | if ( cb ) | 158 | if ( cb ) |
157 | cb->setCurrentItem( s.toInt() - 1 ); | 159 | cb->setCurrentItem( s.toInt() - 1 ); |
158 | QTableItem::setText( s ); | 160 | QTableItem::setText( s ); |
159 | } | 161 | } |
160 | 162 | ||
161 | QString ComboItem::text() const | 163 | QString ComboItem::text() const |
162 | { | 164 | { |
163 | if ( cb ) | 165 | if ( cb ) |
164 | return cb->currentText(); | 166 | return cb->currentText(); |
165 | return QTableItem::text(); | 167 | return QTableItem::text(); |
166 | } | 168 | } |
167 | DueTextItem::DueTextItem( QTable *t, ToDoEvent *ev ) | 169 | DueTextItem::DueTextItem( QTable *t, ToDoEvent *ev ) |
168 | : QTableItem(t, Never, QString::null ) | 170 | : QTableItem(t, Never, QString::null ) |
169 | { | 171 | { |
170 | setToDoEvent( ev ); | 172 | setToDoEvent( ev ); |
171 | } | 173 | } |
172 | QString DueTextItem::key() const | 174 | QString DueTextItem::key() const |
173 | { | 175 | { |
174 | QString key; | 176 | QString key; |
175 | if( m_hasDate ){ | 177 | if( m_hasDate ){ |
176 | if(m_off == 0 ){ | 178 | if(m_off == 0 ){ |
177 | key.append("b"); | 179 | key.append("b"); |
178 | }else if( m_off > 0 ){ | 180 | }else if( m_off > 0 ){ |
179 | key.append("c"); | 181 | key.append("c"); |
180 | }else if( m_off < 0 ){ | 182 | }else if( m_off < 0 ){ |
181 | key.append("a"); | 183 | key.append("a"); |
182 | } | 184 | } |
183 | key.append(QString::number(m_off ) ); | 185 | key.append(QString::number(m_off ) ); |
184 | }else{ | 186 | }else{ |
185 | key.append("d"); | 187 | key.append("d"); |
186 | } | 188 | } |
187 | return key; | 189 | return key; |
188 | } | 190 | } |
189 | void DueTextItem::setToDoEvent( const ToDoEvent *ev ) | 191 | void DueTextItem::setToDoEvent( const ToDoEvent *ev ) |
190 | { | 192 | { |
191 | m_hasDate = ev->hasDate(); | 193 | m_hasDate = ev->hasDate(); |
192 | m_completed = ev->isCompleted(); | 194 | m_completed = ev->isCompleted(); |
193 | if( ev->hasDate() ){ | 195 | if( ev->hasDate() ){ |
194 | QDate today = QDate::currentDate(); | 196 | QDate today = QDate::currentDate(); |
195 | m_off = today.daysTo(ev->date() ); | 197 | m_off = today.daysTo(ev->date() ); |
196 | //qWarning("DueText m_off=%d", m_off ); | 198 | //qWarning("DueText m_off=%d", m_off ); |
197 | setText( QString::number(m_off) + " day(s) " ); | 199 | setText( QString::number(m_off) + " day(s) " ); |
198 | }else{ | 200 | }else{ |
199 | setText("n.d." ); | 201 | setText("n.d." ); |
200 | m_off = 0; | 202 | m_off = 0; |
201 | } | 203 | } |
202 | //qWarning("m_off=%d", m_off ); | 204 | //qWarning("m_off=%d", m_off ); |
203 | } | 205 | } |
204 | void DueTextItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ) | 206 | void DueTextItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ) |
205 | { | 207 | { |
206 | //qWarning ("paint m_off=%d", m_off ); | 208 | //qWarning ("paint m_off=%d", m_off ); |
207 | QColorGroup cg2(cg); | 209 | QColorGroup cg2(cg); |
208 | QColor text = cg.text(); | 210 | QColor text = cg.text(); |
209 | if( m_hasDate && !m_completed ){ | 211 | if( m_hasDate && !m_completed ){ |
210 | if( m_off < 0 ){ | 212 | if( m_off < 0 ){ |
211 | cg2.setColor(QColorGroup::Text, QColor(red ) ); | 213 | cg2.setColor(QColorGroup::Text, QColor(red ) ); |
212 | }else if( m_off == 0 ){ | 214 | }else if( m_off == 0 ){ |
213 | cg2.setColor(QColorGroup::Text, QColor(yellow) ); // orange isn't predefined | 215 | cg2.setColor(QColorGroup::Text, QColor(yellow) ); // orange isn't predefined |
214 | }else if( m_off > 0){ | 216 | }else if( m_off > 0){ |
215 | cg2.setColor(QColorGroup::Text, QColor(green ) ); | 217 | cg2.setColor(QColorGroup::Text, QColor(green ) ); |
216 | } | 218 | } |
217 | } | 219 | } |
218 | QTableItem::paint(p, cg2, cr, selected ); | 220 | QTableItem::paint(p, cg2, cr, selected ); |
219 | cg2.setColor(QColorGroup::Text, text ); | 221 | cg2.setColor(QColorGroup::Text, text ); |
220 | } | 222 | } |
221 | TodoTable::TodoTable( QWidget *parent, const char *name ) | 223 | TodoTable::TodoTable( QWidget *parent, const char *name ) |
222 | // #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR | 224 | // #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR |
223 | // : QTable( 0, 3, parent, name, TRUE ), | 225 | // : QTable( 0, 3, parent, name, TRUE ), |
224 | // #else | 226 | // #else |
225 | : QTable( 0, 4, parent, name ), | 227 | : QTable( 0, 4, parent, name ), |
226 | // #endif | 228 | // #endif |
227 | showComp( true ), | 229 | showComp( true ), |
228 | enablePainting( true ), | 230 | enablePainting( true ), |
229 | mCat( 0 ), | 231 | mCat( 0 ), |
230 | currFindRow( -2 ), | 232 | currFindRow( -2 ), |
231 | showDeadl( true) | 233 | showDeadl( true) |
232 | { | 234 | { |
233 | mCat.load( categoryFileName() ); | 235 | mCat.load( categoryFileName() ); |
234 | setSorting( TRUE ); | 236 | setSorting( TRUE ); |
235 | setSelectionMode( NoSelection ); | 237 | setSelectionMode( NoSelection ); |
236 | setColumnStretchable( 2, TRUE ); | 238 | setColumnStretchable( 2, TRUE ); |
237 | setColumnWidth( 0, 20 ); | 239 | setColumnWidth( 0, 20 ); |
238 | setColumnWidth( 1, 35 ); | 240 | setColumnWidth( 1, 35 ); |
239 | 241 | ||
240 | setLeftMargin( 0 ); | 242 | setLeftMargin( 0 ); |
241 | verticalHeader()->hide(); | 243 | verticalHeader()->hide(); |
242 | horizontalHeader()->setLabel( 0, tr( "C." ) ); | 244 | horizontalHeader()->setLabel( 0, tr( "C." ) ); |
243 | horizontalHeader()->setLabel( 1, tr( "Prior." ) ); | 245 | horizontalHeader()->setLabel( 1, tr( "Prior." ) ); |
244 | horizontalHeader()->setLabel( 2, tr( "Description" ) ); | 246 | horizontalHeader()->setLabel( 2, tr( "Description" ) ); |
245 | 247 | ||
246 | setColumnStretchable( 3, FALSE ); | 248 | setColumnStretchable( 3, FALSE ); |
247 | setColumnWidth( 3, 20 ); | 249 | setColumnWidth( 3, 20 ); |
248 | horizontalHeader()->setLabel( 3, tr( "Deadline" ) ); | 250 | horizontalHeader()->setLabel( 3, tr( "Deadline" ) ); |
249 | 251 | ||
250 | if (showDeadl){ | 252 | if (showDeadl){ |
251 | showColumn (3); | 253 | showColumn (3); |
252 | }else{ | 254 | }else{ |
253 | hideColumn (3); | 255 | hideColumn (3); |
254 | } | 256 | } |
255 | 257 | ||
256 | connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), | 258 | connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), |
257 | this, SLOT( slotClicked( int, int, int, const QPoint & ) ) ); | 259 | this, SLOT( slotClicked( int, int, int, const QPoint & ) ) ); |
258 | connect( this, SIGNAL( pressed( int, int, int, const QPoint & ) ), | 260 | connect( this, SIGNAL( pressed( int, int, int, const QPoint & ) ), |
259 | this, SLOT( slotPressed( int, int, int, const QPoint & ) ) ); | 261 | this, SLOT( slotPressed( int, int, int, const QPoint & ) ) ); |
260 | connect( this, SIGNAL( valueChanged( int, int ) ), | 262 | connect( this, SIGNAL( valueChanged( int, int ) ), |
261 | this, SLOT( slotCheckPriority( int, int ) ) ); | 263 | this, SLOT( slotCheckPriority( int, int ) ) ); |
262 | connect( this, SIGNAL( currentChanged( int, int ) ), | 264 | connect( this, SIGNAL( currentChanged( int, int ) ), |
263 | this, SLOT( slotCurrentChanged( int, int ) ) ); | 265 | this, SLOT( slotCurrentChanged( int, int ) ) ); |
264 | 266 | ||
265 | menuTimer = new QTimer( this ); | 267 | menuTimer = new QTimer( this ); |
266 | connect( menuTimer, SIGNAL(timeout()), this, SLOT(slotShowMenu()) ); | 268 | connect( menuTimer, SIGNAL(timeout()), this, SLOT(slotShowMenu()) ); |
267 | 269 | ||
268 | mDayTimer = new QTimer( this ); | 270 | mDayTimer = new QTimer( this ); |
269 | connect( mDayTimer, SIGNAL(timeout()), this, SLOT(slotCheckDay() ) ); | 271 | connect( mDayTimer, SIGNAL(timeout()), this, SLOT(slotCheckDay() ) ); |
270 | mDay = QDate::currentDate(); | 272 | mDay = QDate::currentDate(); |
271 | } | 273 | } |
272 | 274 | ||
273 | void TodoTable::addEntry( const ToDoEvent &todo ) | 275 | void TodoTable::addEntry( const ToDoEvent &todo ) |
274 | { | 276 | { |
275 | int row = numRows(); | 277 | int row = numRows(); |
276 | setNumRows( row + 1 ); | 278 | setNumRows( row + 1 ); |
277 | updateJournal( todo, ACTION_ADD ); | 279 | updateJournal( todo, ACTION_ADD ); |
278 | insertIntoTable( new ToDoEvent(todo), row ); | 280 | insertIntoTable( new ToDoEvent(todo), row ); |
279 | setCurrentCell(row, currentColumn()); | 281 | setCurrentCell(row, currentColumn()); |
280 | updateVisible(); | 282 | updateVisible(); |
281 | } | 283 | } |
282 | 284 | ||
283 | void TodoTable::slotClicked( int row, int col, int, const QPoint &pos ) | 285 | void TodoTable::slotClicked( int row, int col, int, const QPoint &pos ) |
284 | { | 286 | { |
285 | if ( !cellGeometry( row, col ).contains(pos) ) | 287 | if ( !cellGeometry( row, col ).contains(pos) ) |
286 | return; | 288 | return; |
287 | // let's switch on the column number... | 289 | // let's switch on the column number... |
288 | switch ( col ) | 290 | switch ( col ) |
289 | { | 291 | { |
290 | case 0: { | 292 | case 0: { |
291 | CheckItem *i = static_cast<CheckItem*>(item( row, col )); | 293 | CheckItem *i = static_cast<CheckItem*>(item( row, col )); |
292 | if ( i ) { | 294 | if ( i ) { |
293 | int x = pos.x() - columnPos( col ); | 295 | int x = pos.x() - columnPos( col ); |
294 | int y = pos.y() - rowPos( row ); | 296 | int y = pos.y() - rowPos( row ); |
295 | int w = columnWidth( col ); | 297 | int w = columnWidth( col ); |
296 | int h = rowHeight( row ); | 298 | int h = rowHeight( row ); |
297 | if ( i && x >= ( w - BoxSize ) / 2 && x <= ( w - BoxSize ) / 2 + BoxSize && | 299 | if ( i && x >= ( w - BoxSize ) / 2 && x <= ( w - BoxSize ) / 2 + BoxSize && |
298 | y >= ( h - BoxSize ) / 2 && y <= ( h - BoxSize ) / 2 + BoxSize ) { | 300 | y >= ( h - BoxSize ) / 2 && y <= ( h - BoxSize ) / 2 + BoxSize ) { |
299 | i->toggle(); | 301 | i->toggle(); |
300 | } | 302 | } |
301 | emit signalDoneChanged( i->isChecked() ); | 303 | emit signalDoneChanged( i->isChecked() ); |
302 | } | 304 | } |
303 | } | 305 | } |
304 | break; | 306 | break; |
305 | case 1: | 307 | case 1: |
306 | break; | 308 | break; |
307 | case 2: | 309 | case 2: |
308 | // may as well edit it... | 310 | // may as well edit it... |
309 | // menuTimer->stop(); | 311 | // menuTimer->stop(); |
310 | // emit signalEdit(); | 312 | // emit signalEdit(); |
311 | // Show detailed view of the selected entry | 313 | // Show detailed view of the selected entry |
312 | { | 314 | { |
313 | menuTimer->stop(); | 315 | menuTimer->stop(); |
314 | ToDoEvent *todo = todoList[static_cast<CheckItem*>(item(row, 0))]; | 316 | ToDoEvent *todo = todoList[static_cast<CheckItem*>(item(row, 0))]; |
315 | emit showDetails( *todo ); | 317 | emit showDetails( *todo ); |
316 | } | 318 | } |
317 | break; | 319 | break; |
318 | case 3: | 320 | case 3: |
319 | // may as well edit it... | 321 | // may as well edit it... |
320 | menuTimer->stop(); | 322 | menuTimer->stop(); |
321 | // emit signalEdit(); | 323 | // emit signalEdit(); |
322 | break; | 324 | break; |
323 | } | 325 | } |
324 | } | 326 | } |
325 | 327 | ||
326 | void TodoTable::slotPressed( int row, int col, int, const QPoint &pos ) | 328 | void TodoTable::slotPressed( int row, int col, int, const QPoint &pos ) |
327 | { | 329 | { |
328 | if ( col == 2 && cellGeometry( row, col ).contains(pos) ) | 330 | if ( col == 2 && cellGeometry( row, col ).contains(pos) ) |
329 | menuTimer->start( 750, TRUE ); | 331 | menuTimer->start( 750, TRUE ); |
330 | } | 332 | } |
331 | 333 | ||
332 | void TodoTable::slotShowMenu() | 334 | void TodoTable::slotShowMenu() |
333 | { | 335 | { |
334 | emit signalShowMenu( QCursor::pos() ); | 336 | emit signalShowMenu( QCursor::pos() ); |
335 | } | 337 | } |
336 | 338 | ||
337 | void TodoTable::slotCurrentChanged( int, int ) | 339 | void TodoTable::slotCurrentChanged( int, int ) |
338 | { | 340 | { |
339 | menuTimer->stop(); | 341 | menuTimer->stop(); |
340 | } | 342 | } |
341 | 343 | ||
342 | void TodoTable::internalAddEntries( QList<ToDoEvent> &list ) | 344 | void TodoTable::internalAddEntries( QList<ToDoEvent> &list ) |
343 | { | 345 | { |
344 | setNumRows( list.count() ); | 346 | setNumRows( list.count() ); |
345 | int row = 0; | 347 | int row = 0; |
346 | ToDoEvent *it; | 348 | ToDoEvent *it; |
347 | for ( it = list.first(); it; it = list.next() ) | 349 | for ( it = list.first(); it; it = list.next() ) |
348 | insertIntoTable( it, row++ ); | 350 | insertIntoTable( it, row++ ); |
349 | } | 351 | } |
350 | 352 | ||
351 | 353 | ||
352 | ToDoEvent TodoTable::currentEntry() const | 354 | ToDoEvent TodoTable::currentEntry() const |
353 | { | 355 | { |
354 | //qWarning ("in currentEntry\n"); | 356 | //qWarning ("in currentEntry\n"); |
355 | 357 | ||
356 | QTableItem *i = item( currentRow(), 0 ); | 358 | QTableItem *i = item( currentRow(), 0 ); |
357 | if ( !i || rowHeight( currentRow() ) <= 0 ) | 359 | if ( !i || rowHeight( currentRow() ) <= 0 ) |
358 | return ToDoEvent(); | 360 | return ToDoEvent(); |
359 | ToDoEvent *todo = todoList[(CheckItem*)i]; | 361 | ToDoEvent *todo = todoList[(CheckItem*)i]; |
360 | todo->setCompleted( ( (CheckItem*)item( currentRow(), 0 ) )->isChecked() ); | 362 | todo->setCompleted( ( (CheckItem*)item( currentRow(), 0 ) )->isChecked() ); |
361 | todo->setPriority( ( (ComboItem*)item( currentRow(), 1 ) )->text().toInt() ); | 363 | todo->setPriority( ( (ComboItem*)item( currentRow(), 1 ) )->text().toInt() ); |
362 | return *todo; | 364 | return *todo; |
363 | } | 365 | } |
364 | 366 | ||
365 | void TodoTable::replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem ) | 367 | void TodoTable::replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem ) |
366 | { | 368 | { |
367 | int row = currentRow(); | 369 | int row = currentRow(); |
368 | updateJournal( todo, ACTION_REPLACE); | 370 | updateJournal( todo, ACTION_REPLACE); |
369 | 371 | ||
370 | if ( !fromTableItem ) { | 372 | if ( !fromTableItem ) { |
371 | journalFreeReplaceEntry( todo, row ); | 373 | journalFreeReplaceEntry( todo, row ); |
372 | updateVisible(); | 374 | updateVisible(); |
373 | } | 375 | } |
374 | } | 376 | } |
375 | 377 | ||
376 | void TodoTable::removeCurrentEntry() | 378 | void TodoTable::removeCurrentEntry() |
377 | { | 379 | { |
378 | ToDoEvent *oldTodo; | 380 | ToDoEvent *oldTodo; |
379 | int row = currentRow(); | 381 | int row = currentRow(); |
380 | CheckItem *chk; | 382 | CheckItem *chk; |
381 | 383 | ||
382 | chk = static_cast<CheckItem*>(item(row, 0 )); | 384 | chk = static_cast<CheckItem*>(item(row, 0 )); |
383 | if ( !chk ) | 385 | if ( !chk ) |
384 | return; | 386 | return; |
385 | oldTodo = todoList[chk]; | 387 | oldTodo = todoList[chk]; |
386 | todoList.remove( chk ); | 388 | todoList.remove( chk ); |
387 | oldTodo->setCompleted( chk->isChecked() ); | 389 | oldTodo->setCompleted( chk->isChecked() ); |
388 | oldTodo->setPriority( static_cast<ComboItem*>(item(row, 1))->text().toInt() ); | 390 | oldTodo->setPriority( static_cast<ComboItem*>(item(row, 1))->text().toInt() ); |
389 | realignTable( row ); | 391 | realignTable( row ); |
390 | updateVisible(); | 392 | updateVisible(); |
391 | updateJournal( *oldTodo, ACTION_REMOVE); | 393 | updateJournal( *oldTodo, ACTION_REMOVE); |
392 | delete oldTodo; | 394 | delete oldTodo; |
393 | } | 395 | } |
394 | 396 | ||
395 | 397 | ||
396 | bool TodoTable::save( const QString &fn ) | 398 | bool TodoTable::save( const QString &fn ) |
397 | { | 399 | { |
398 | QString strNewFile = fn + ".new"; | 400 | QString strNewFile = fn + ".new"; |
399 | QFile::remove( strNewFile ); // just to be sure | 401 | QFile::remove( strNewFile ); // just to be sure |
400 | ToDoDB todoDB( strNewFile ); | 402 | ToDoDB todoDB( strNewFile ); |
401 | for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); | 403 | for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); |
402 | it != todoList.end(); ++it ) { | 404 | it != todoList.end(); ++it ) { |
403 | if ( !item( it.key()->row(), 0 ) ) | 405 | if ( !item( it.key()->row(), 0 ) ) |
404 | continue; | 406 | continue; |
405 | ToDoEvent *todo = *it; | 407 | ToDoEvent *todo = *it; |
406 | // sync item with table | 408 | // sync item with table |
407 | todo->setCompleted( ((CheckItem*)item(it.key()->row(), 0))->isChecked() ); | 409 | todo->setCompleted( ((CheckItem*)item(it.key()->row(), 0))->isChecked() ); |
408 | todo->setPriority( ((ComboItem*)item( it.key()->row(), 1))->text().toInt() ); | 410 | todo->setPriority( ((ComboItem*)item( it.key()->row(), 1))->text().toInt() ); |
409 | todoDB.addEvent( *todo ); | 411 | todoDB.addEvent( *todo ); |
410 | } | 412 | } |
411 | if(!todoDB.save() ){ | 413 | if(!todoDB.save() ){ |
412 | QFile::remove( strNewFile ); | 414 | QFile::remove( strNewFile ); |
413 | return false; | 415 | return false; |
414 | }; | 416 | }; |
415 | // now do the rename | 417 | // now do the rename |
416 | if ( ::rename( strNewFile, fn ) < 0 ) | 418 | if ( ::rename( strNewFile, fn ) < 0 ) |
417 | qWarning( "problem renaming file %s to %s errno %d", | 419 | qWarning( "problem renaming file %s to %s errno %d", |
418 | strNewFile.latin1(), fn.latin1(), errno ); | 420 | strNewFile.latin1(), fn.latin1(), errno ); |
419 | 421 | ||
420 | // remove the journal | 422 | // remove the journal |
421 | QFile::remove( journalFileName() ); | 423 | QFile::remove( journalFileName() ); |
422 | return true; | 424 | return true; |
423 | } | 425 | } |
424 | 426 | ||
425 | void TodoTable::load( const QString &fn ) | 427 | void TodoTable::load( const QString &fn ) |
426 | { | 428 | { |
427 | if ( QFile::exists(journalFileName()) ) { | 429 | if ( QFile::exists(journalFileName()) ) { |
428 | applyJournal(); | 430 | applyJournal(); |
429 | QFile::remove(journalFileName() ); | 431 | QFile::remove(journalFileName() ); |
430 | } | 432 | } |
431 | loadFile( fn ); | 433 | loadFile( fn ); |
432 | // QTable::sortColumn(2,TRUE,TRUE); | 434 | // QTable::sortColumn(2,TRUE,TRUE); |
433 | // QTable::sortColumn(1,TRUE,TRUE); | 435 | // QTable::sortColumn(1,TRUE,TRUE); |
434 | QTable::sortColumn(0,TRUE,TRUE); | 436 | QTable::sortColumn(0,TRUE,TRUE); |
435 | setCurrentCell( 0, 2 ); | 437 | setCurrentCell( 0, 2 ); |
436 | setSorting(true ); | 438 | setSorting(true ); |
437 | mDayTimer->start( 60 * 1000 ); // gone in 60 seconds? | 439 | mDayTimer->start( 60 * 1000 ); // gone in 60 seconds? |
438 | } | 440 | } |
439 | void TodoTable::updateVisible() | 441 | void TodoTable::updateVisible() |
440 | { | 442 | { |
441 | if ( !isUpdatesEnabled() ) | 443 | if ( !isUpdatesEnabled() ) |
442 | return; | 444 | return; |
443 | 445 | ||
444 | if (showDeadl){ | 446 | if (showDeadl){ |
445 | showColumn (3); | 447 | showColumn (3); |
446 | adjustColumn(3); | 448 | adjustColumn(3); |
447 | }else{ | 449 | }else{ |
448 | hideColumn (3); | 450 | hideColumn (3); |
449 | adjustColumn(2); | 451 | adjustColumn(2); |
450 | } | 452 | } |
451 | 453 | ||
452 | int visible = 0; | 454 | int visible = 0; |
453 | int id = mCat.id( "Todo List", showCat ); | 455 | int id = mCat.id( "Todo List", showCat ); |
454 | for ( int row = 0; row < numRows(); row++ ) { | 456 | for ( int row = 0; row < numRows(); row++ ) { |
455 | CheckItem *ci = (CheckItem *)item( row, 0 ); | 457 | CheckItem *ci = (CheckItem *)item( row, 0 ); |
456 | ToDoEvent *t = todoList[ci]; | 458 | ToDoEvent *t = todoList[ci]; |
457 | QArray<int> vlCats = t->categories(); | 459 | QArray<int> vlCats = t->categories(); |
458 | bool hide = false; | 460 | bool hide = false; |
459 | if ( !showComp && ci->isChecked() ) | 461 | if ( !showComp && ci->isChecked() ) |
460 | hide = true; | 462 | hide = true; |
461 | if ( !showCat.isEmpty() ) { | 463 | if ( !showCat.isEmpty() ) { |
462 | if ( showCat == tr( "Unfiled" ) ) { | 464 | if ( showCat == tr( "Unfiled" ) ) { |
463 | if ( vlCats.count() > 0 ) | 465 | if ( vlCats.count() > 0 ) |
464 | hide = true; | 466 | hide = true; |
465 | } else { | 467 | } else { |
466 | // do some comparing, we have to reverse our idea here... which idea? - zecke | 468 | // do some comparing, we have to reverse our idea here... which idea? - zecke |
467 | if ( !hide ) { | 469 | if ( !hide ) { |
468 | hide = true; | 470 | hide = true; |
469 | for ( uint it = 0; it < vlCats.count(); ++it ) { | 471 | for ( uint it = 0; it < vlCats.count(); ++it ) { |
470 | if ( vlCats[it] == id ) { | 472 | if ( vlCats[it] == id ) { |
471 | hide = false; | 473 | hide = false; |
472 | break; | 474 | break; |
473 | } | 475 | } |
474 | } | 476 | } |
475 | } | 477 | } |
476 | } | 478 | } |
477 | } | 479 | } |
478 | if ( hide ) { | 480 | if ( hide ) { |
479 | if ( currentRow() == row ) | 481 | if ( currentRow() == row ) |
480 | setCurrentCell( -1, 0 ); | 482 | setCurrentCell( -1, 0 ); |
481 | if ( rowHeight( row ) > 0 ) | 483 | if ( rowHeight( row ) > 0 ) |
482 | hideRow( row ); | 484 | hideRow( row ); |
483 | } else { | 485 | } else { |
484 | if ( rowHeight( row ) == 0 ) { | 486 | if ( rowHeight( row ) == 0 ) { |
485 | showRow( row ); | 487 | showRow( row ); |
486 | adjustRow( row ); | 488 | adjustRow( row ); |
487 | } | 489 | } |
488 | visible++; | 490 | visible++; |
489 | } | 491 | } |
490 | } | 492 | } |
491 | if ( !visible ) | 493 | if ( !visible ) |
492 | setCurrentCell( -1, 0 ); | 494 | setCurrentCell( -1, 0 ); |
493 | } | 495 | } |
494 | 496 | ||
495 | void TodoTable::viewportPaintEvent( QPaintEvent *pe ) | 497 | void TodoTable::viewportPaintEvent( QPaintEvent *pe ) |
496 | { | 498 | { |
497 | if ( enablePainting ) | 499 | if ( enablePainting ) |
498 | QTable::viewportPaintEvent( pe ); | 500 | QTable::viewportPaintEvent( pe ); |
499 | } | 501 | } |
500 | 502 | ||
501 | void TodoTable::setPaintingEnabled( bool e ) | 503 | void TodoTable::setPaintingEnabled( bool e ) |
502 | { | 504 | { |
503 | if ( e != enablePainting ) { | 505 | if ( e != enablePainting ) { |
504 | if ( !enablePainting ) { | 506 | if ( !enablePainting ) { |
505 | enablePainting = true; | 507 | enablePainting = true; |
506 | rowHeightChanged( 0 ); | 508 | rowHeightChanged( 0 ); |
507 | viewport()->update(); | 509 | viewport()->update(); |
508 | } else { | 510 | } else { |
509 | enablePainting = false; | 511 | enablePainting = false; |
510 | } | 512 | } |
511 | } | 513 | } |
512 | } | 514 | } |
513 | 515 | ||
514 | void TodoTable::clear() | 516 | void TodoTable::clear() |
515 | { | 517 | { |
516 | for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); | 518 | for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); |
517 | it != todoList.end(); ++it ) { | 519 | it != todoList.end(); ++it ) { |
518 | ToDoEvent *todo = it.data(); | 520 | ToDoEvent *todo = it.data(); |
519 | updateJournal( *todo, ACTION_REMOVE ); | 521 | updateJournal( *todo, ACTION_REMOVE ); |
520 | delete todo; | 522 | delete todo; |
521 | } | 523 | } |
522 | todoList.clear(); | 524 | todoList.clear(); |
523 | for ( int r = 0; r < numRows(); ++r ) { | 525 | for ( int r = 0; r < numRows(); ++r ) { |
524 | for ( int c = 0; c < numCols(); ++c ) { | 526 | for ( int c = 0; c < numCols(); ++c ) { |
525 | if ( cellWidget( r, c ) ) | 527 | if ( cellWidget( r, c ) ) |
526 | clearCellWidget( r, c ); | 528 | clearCellWidget( r, c ); |
527 | clearCell( r, c ); | 529 | clearCell( r, c ); |
528 | } | 530 | } |
529 | } | 531 | } |
530 | setNumRows( 0 ); | 532 | setNumRows( 0 ); |
531 | } | 533 | } |
532 | 534 | ||
533 | void TodoTable::sortColumn( int col, bool ascending, bool /*wholeRows*/ ) | 535 | void TodoTable::sortColumn( int col, bool ascending, bool /*wholeRows*/ ) |
534 | { | 536 | { |
535 | // The default for wholeRows is false, however | 537 | // The default for wholeRows is false, however |
536 | // for this todo table we want to exchange complete | 538 | // for this todo table we want to exchange complete |
537 | // rows when sorting. Also, we always want ascending, since | 539 | // rows when sorting. Also, we always want ascending, since |
538 | // the values have a logical order. | 540 | // the values have a logical order. |
539 | QTable::sortColumn( col, ascending, TRUE ); | 541 | QTable::sortColumn( col, ascending, TRUE ); |
540 | updateVisible(); | 542 | updateVisible(); |
541 | } | 543 | } |
542 | 544 | ||
543 | void TodoTable::slotCheckPriority(int row, int col ) | 545 | void TodoTable::slotCheckPriority(int row, int col ) |
544 | { | 546 | { |
545 | // kludgey work around to make forward along the updated priority... | 547 | // kludgey work around to make forward along the updated priority... |
546 | if ( col == 1 ) { | 548 | if ( col == 1 ) { |
547 | // let everyone know!! | 549 | // let everyone know!! |
548 | ComboItem* i = static_cast<ComboItem*>( item( row, col ) ); | 550 | ComboItem* i = static_cast<ComboItem*>( item( row, col ) ); |
549 | emit signalPriorityChanged( i->text().toInt() ); | 551 | emit signalPriorityChanged( i->text().toInt() ); |
550 | } | 552 | } |
551 | } | 553 | } |
552 | 554 | ||
553 | 555 | ||
554 | void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action ) | 556 | void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action ) |
555 | { | 557 | { |
556 | QFile f( journalFileName() ); | 558 | QFile f( journalFileName() ); |
557 | if ( !f.open(IO_WriteOnly|IO_Append) ) | 559 | if ( !f.open(IO_WriteOnly|IO_Append) ) |
558 | return; | 560 | return; |
559 | QString buf; | 561 | QString buf; |
diff --git a/core/pim/todo/todotable.h b/core/pim/todo/todotable.h index 2f6e635..7672f21 100644 --- a/core/pim/todo/todotable.h +++ b/core/pim/todo/todotable.h | |||
@@ -1,240 +1,244 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #ifndef TODOTABLE_H | 21 | #ifndef TODOTABLE_H |
22 | #define TODOTABLE_H | 22 | #define TODOTABLE_H |
23 | 23 | ||
24 | #include <qpe/categories.h> | 24 | #include <qpe/categories.h> |
25 | #include <qpe/stringutil.h> | 25 | #include <qpe/stringutil.h> |
26 | //#include <qpe/task.h> | 26 | //#include <qpe/task.h> |
27 | #include <opie/todoevent.h> | 27 | #include <opie/todoevent.h> |
28 | 28 | ||
29 | #include <qtable.h> | 29 | #include <qtable.h> |
30 | #include <qmap.h> | 30 | #include <qmap.h> |
31 | #include <qguardedptr.h> | 31 | #include <qguardedptr.h> |
32 | 32 | ||
33 | class Node; | 33 | class Node; |
34 | class QComboBox; | 34 | class QComboBox; |
35 | class QTimer; | 35 | class QTimer; |
36 | 36 | ||
37 | class CheckItem : public QTableItem | 37 | class CheckItem : public QTableItem |
38 | { | 38 | { |
39 | public: | 39 | public: |
40 | CheckItem( QTable *t, const QString &sortkey ); | 40 | CheckItem( QTable *t, const QString &sortkey ); |
41 | 41 | ||
42 | void setChecked( bool b ); | 42 | void setChecked( bool b ); |
43 | void toggle(); | 43 | void toggle(); |
44 | bool isChecked() const; | 44 | bool isChecked() const; |
45 | void setKey( const QString &key ) { sortKey = key; } | 45 | void setKey( const QString &key ) { sortKey = key; } |
46 | QString key() const; | 46 | QString key() const; |
47 | 47 | ||
48 | void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ); | 48 | void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ); |
49 | 49 | ||
50 | private: | 50 | private: |
51 | bool checked; | 51 | bool checked; |
52 | QString sortKey; | 52 | QString sortKey; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | class ComboItem : public QTableItem | 55 | class ComboItem : public QTableItem |
56 | { | 56 | { |
57 | public: | 57 | public: |
58 | ComboItem( QTable *t, EditType et ); | 58 | ComboItem( QTable *t, EditType et ); |
59 | QWidget *createEditor() const; | 59 | QWidget *createEditor() const; |
60 | void setContentFromEditor( QWidget *w ); | 60 | void setContentFromEditor( QWidget *w ); |
61 | void setText( const QString &s ); | 61 | void setText( const QString &s ); |
62 | int alignment() const { return Qt::AlignCenter; } | 62 | int alignment() const { return Qt::AlignCenter; } |
63 | 63 | ||
64 | QString text() const; | 64 | QString text() const; |
65 | 65 | ||
66 | private: | 66 | private: |
67 | QGuardedPtr<QComboBox> cb; | 67 | QGuardedPtr<QComboBox> cb; |
68 | 68 | ||
69 | }; | 69 | }; |
70 | 70 | ||
71 | class TodoTextItem : public QTableItem | 71 | class TodoTextItem : public QTableItem |
72 | { | 72 | { |
73 | public: | 73 | public: |
74 | TodoTextItem( QTable *t, const QString & str ) | 74 | TodoTextItem( QTable *t, const QString & str ) |
75 | :QTableItem( t, QTableItem::Never, str ) {} | 75 | :QTableItem( t, QTableItem::Never, str ) {} |
76 | 76 | ||
77 | QString key () const { return Qtopia::buildSortKey( text() ); } | 77 | QString key () const { return Qtopia::buildSortKey( text() ); } |
78 | }; | 78 | }; |
79 | 79 | ||
80 | class DueTextItem : public QTableItem | 80 | class DueTextItem : public QTableItem |
81 | { | 81 | { |
82 | public: | 82 | public: |
83 | DueTextItem( QTable *t, ToDoEvent *ev ); | 83 | DueTextItem( QTable *t, ToDoEvent *ev ); |
84 | QString key() const; | 84 | QString key() const; |
85 | void setToDoEvent( const ToDoEvent *ev ); | 85 | void setToDoEvent( const ToDoEvent *ev ); |
86 | void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ); | 86 | void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ); |
87 | private: | 87 | private: |
88 | int m_off; | 88 | int m_off; |
89 | bool m_hasDate:1; | 89 | bool m_hasDate:1; |
90 | bool m_completed:1; | 90 | bool m_completed:1; |
91 | 91 | ||
92 | }; | 92 | }; |
93 | 93 | ||
94 | 94 | ||
95 | enum journal_action { ACTION_ADD=0, ACTION_REMOVE, ACTION_REPLACE }; | 95 | enum journal_action { ACTION_ADD=0, ACTION_REMOVE, ACTION_REPLACE }; |
96 | 96 | ||
97 | namespace Opie | ||
98 | { | ||
97 | class XMLElement; | 99 | class XMLElement; |
100 | }; | ||
101 | |||
98 | class TodoTable : public QTable | 102 | class TodoTable : public QTable |
99 | { | 103 | { |
100 | Q_OBJECT | 104 | Q_OBJECT |
101 | 105 | ||
102 | public: | 106 | public: |
103 | TodoTable( QWidget *parent = 0, const char * name = 0 ); | 107 | TodoTable( QWidget *parent = 0, const char * name = 0 ); |
104 | void addEntry( const ToDoEvent &todo ); | 108 | void addEntry( const ToDoEvent &todo ); |
105 | void clearFindRow() { currFindRow = -2; } | 109 | void clearFindRow() { currFindRow = -2; } |
106 | 110 | ||
107 | ToDoEvent currentEntry() const; | 111 | ToDoEvent currentEntry() const; |
108 | void replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem = false ); | 112 | void replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem = false ); |
109 | 113 | ||
110 | QStringList categories(); | 114 | QStringList categories(); |
111 | 115 | ||
112 | void setShowCompleted( bool sc ) { showComp = sc; updateVisible(); } | 116 | void setShowCompleted( bool sc ) { showComp = sc; updateVisible(); } |
113 | bool showCompleted() const { return showComp; } | 117 | bool showCompleted() const { return showComp; } |
114 | 118 | ||
115 | void setShowDeadline (bool sd) {showDeadl = sd; updateVisible();} | 119 | void setShowDeadline (bool sd) {showDeadl = sd; updateVisible();} |
116 | bool showDeadline() const { return showDeadl;} | 120 | bool showDeadline() const { return showDeadl;} |
117 | 121 | ||
118 | void setShowCategory( const QString &c ) { showCat = c; updateVisible(); } | 122 | void setShowCategory( const QString &c ) { showCat = c; updateVisible(); } |
119 | const QString &showCategory() const { return showCat; } | 123 | const QString &showCategory() const { return showCat; } |
120 | int showCategoryId() const; | 124 | int showCategoryId() const; |
121 | 125 | ||
122 | bool save( const QString &fn ); | 126 | bool save( const QString &fn ); |
123 | void load( const QString &fn ); | 127 | void load( const QString &fn ); |
124 | void applyJournal( ); | 128 | void applyJournal( ); |
125 | void clear(); | 129 | void clear(); |
126 | void removeCurrentEntry(); | 130 | void removeCurrentEntry(); |
127 | void removeAllEntries() { clear(); }; | 131 | void removeAllEntries() { clear(); }; |
128 | //void removeAllEntriesInCategory(const QString &category ); | 132 | //void removeAllEntriesInCategory(const QString &category ); |
129 | 133 | ||
130 | void setPaintingEnabled( bool e ); | 134 | void setPaintingEnabled( bool e ); |
131 | 135 | ||
132 | virtual void sortColumn( int col, bool ascending, bool /*wholeRows*/ ); | 136 | virtual void sortColumn( int col, bool ascending, bool /*wholeRows*/ ); |
133 | 137 | ||
134 | // int rowHeight( int ) const; | 138 | // int rowHeight( int ) const; |
135 | // int rowPos( int row ) const; | 139 | // int rowPos( int row ) const; |
136 | // virtual int rowAt( int pos ) const; | 140 | // virtual int rowAt( int pos ) const; |
137 | 141 | ||
138 | signals: | 142 | signals: |
139 | void signalEdit(); | 143 | void signalEdit(); |
140 | void signalDoneChanged( bool b ); | 144 | void signalDoneChanged( bool b ); |
141 | void signalPriorityChanged( int i ); | 145 | void signalPriorityChanged( int i ); |
142 | void signalShowMenu( const QPoint & ); | 146 | void signalShowMenu( const QPoint & ); |
143 | void signalNotFound(); | 147 | void signalNotFound(); |
144 | void signalWrapAround(); | 148 | void signalWrapAround(); |
145 | void showDetails( const ToDoEvent & ); | 149 | void showDetails( const ToDoEvent & ); |
146 | protected: | 150 | protected: |
147 | void keyPressEvent( QKeyEvent *e ); | 151 | void keyPressEvent( QKeyEvent *e ); |
148 | 152 | ||
149 | private: | 153 | private: |
150 | void updateVisible(); | 154 | void updateVisible(); |
151 | void viewportPaintEvent( QPaintEvent * ); | 155 | void viewportPaintEvent( QPaintEvent * ); |
152 | void internalAddEntries( QList<ToDoEvent> &list); | 156 | void internalAddEntries( QList<ToDoEvent> &list); |
153 | inline void insertIntoTable( ToDoEvent *todo, int row ); | 157 | inline void insertIntoTable( ToDoEvent *todo, int row ); |
154 | void updateJournal( const ToDoEvent &todo, journal_action action); | 158 | void updateJournal( const ToDoEvent &todo, journal_action action); |
155 | void mergeJournal(); | 159 | void mergeJournal(); |
156 | void journalFreeReplaceEntry( const ToDoEvent &todo, int row ); | 160 | void journalFreeReplaceEntry( const ToDoEvent &todo, int row ); |
157 | void journalFreeRemoveEntry( int row ); | 161 | void journalFreeRemoveEntry( int row ); |
158 | inline void realignTable( int row ); | 162 | inline void realignTable( int row ); |
159 | void loadFile( const QString &strFile); | 163 | void loadFile( const QString &strFile); |
160 | 164 | ||
161 | private slots: | 165 | private slots: |
162 | void slotClicked( int row, int col, int button, const QPoint &pos ); | 166 | void slotClicked( int row, int col, int button, const QPoint &pos ); |
163 | void slotPressed( int row, int col, int button, const QPoint &pos ); | 167 | void slotPressed( int row, int col, int button, const QPoint &pos ); |
164 | void slotCheckPriority(int row, int col ); | 168 | void slotCheckPriority(int row, int col ); |
165 | void slotCurrentChanged(int row, int col ); | 169 | void slotCurrentChanged(int row, int col ); |
166 | void slotDoFind( const QString &findString, bool caseSensetive, | 170 | void slotDoFind( const QString &findString, bool caseSensetive, |
167 | bool backwards, int category ); | 171 | bool backwards, int category ); |
168 | void slotShowMenu(); | 172 | void slotShowMenu(); |
169 | void rowHeightChanged( int row ); | 173 | void rowHeightChanged( int row ); |
170 | void slotCheckDay(); // check the day | 174 | void slotCheckDay(); // check the day |
171 | 175 | ||
172 | private: | 176 | private: |
173 | friend class TodoWindow; | 177 | friend class TodoWindow; |
174 | 178 | ||
175 | QMap<CheckItem*, ToDoEvent *> todoList; | 179 | QMap<CheckItem*, ToDoEvent *> todoList; |
176 | QStringList categoryList; | 180 | QStringList categoryList; |
177 | bool showComp; | 181 | bool showComp; |
178 | QString showCat; | 182 | QString showCat; |
179 | QTimer *menuTimer; | 183 | QTimer *menuTimer; |
180 | QDate mDay; | 184 | QDate mDay; |
181 | QTimer *mDayTimer; // see if the day changed | 185 | QTimer *mDayTimer; // see if the day changed |
182 | bool enablePainting; | 186 | bool enablePainting; |
183 | Categories mCat; | 187 | Categories mCat; |
184 | int currFindRow; | 188 | int currFindRow; |
185 | bool showDeadl:1; | 189 | bool showDeadl:1; |
186 | }; | 190 | }; |
187 | 191 | ||
188 | 192 | ||
189 | inline void TodoTable::insertIntoTable( ToDoEvent *todo, int row ) | 193 | inline void TodoTable::insertIntoTable( ToDoEvent *todo, int row ) |
190 | { | 194 | { |
191 | QString sortKey = (char) ((todo->isCompleted() ? 'a' : 'A') | 195 | QString sortKey = (char) ((todo->isCompleted() ? 'a' : 'A') |
192 | + todo->priority() ) | 196 | + todo->priority() ) |
193 | + Qtopia::buildSortKey( todo->description() ); | 197 | + Qtopia::buildSortKey( todo->description() ); |
194 | CheckItem *chk = new CheckItem( this, sortKey ); | 198 | CheckItem *chk = new CheckItem( this, sortKey ); |
195 | chk->setChecked( todo->isCompleted() ); | 199 | chk->setChecked( todo->isCompleted() ); |
196 | ComboItem *cmb = new ComboItem( this, QTableItem::WhenCurrent ); | 200 | ComboItem *cmb = new ComboItem( this, QTableItem::WhenCurrent ); |
197 | cmb->setText( QString::number( todo->priority() ) ); | 201 | cmb->setText( QString::number( todo->priority() ) ); |
198 | QTableItem *ti = new TodoTextItem( this, todo->description().left(40).simplifyWhiteSpace() ); | 202 | QTableItem *ti = new TodoTextItem( this, todo->description().left(40).simplifyWhiteSpace() ); |
199 | ti->setReplaceable( false ); | 203 | ti->setReplaceable( false ); |
200 | 204 | ||
201 | DueTextItem *due = new DueTextItem(this, todo ); | 205 | DueTextItem *due = new DueTextItem(this, todo ); |
202 | setItem( row, 3, due); | 206 | setItem( row, 3, due); |
203 | 207 | ||
204 | setItem( row, 0, chk ); | 208 | setItem( row, 0, chk ); |
205 | setItem( row, 1, cmb ); | 209 | setItem( row, 1, cmb ); |
206 | setItem( row, 2, ti ); | 210 | setItem( row, 2, ti ); |
207 | 211 | ||
208 | 212 | ||
209 | todoList.insert( chk, todo ); | 213 | todoList.insert( chk, todo ); |
210 | } | 214 | } |
211 | 215 | ||
212 | inline void TodoTable::realignTable( int row ) | 216 | inline void TodoTable::realignTable( int row ) |
213 | { | 217 | { |
214 | QTableItem *ti1, | 218 | QTableItem *ti1, |
215 | *ti2, | 219 | *ti2, |
216 | *ti3, | 220 | *ti3, |
217 | *ti4; | 221 | *ti4; |
218 | int totalRows = numRows(); | 222 | int totalRows = numRows(); |
219 | for ( int curr = row; curr < totalRows - 1; curr++ ) { | 223 | for ( int curr = row; curr < totalRows - 1; curr++ ) { |
220 | // this is bad, we must take the item out and then | 224 | // this is bad, we must take the item out and then |
221 | // set it. In the end, it behaves no worse (time wise) | 225 | // set it. In the end, it behaves no worse (time wise) |
222 | // then the old way of saving the entries to file, clearing | 226 | // then the old way of saving the entries to file, clearing |
223 | // the table re-reading in the file and resetting the table | 227 | // the table re-reading in the file and resetting the table |
224 | ti1 = item( curr + 1, 0 ); | 228 | ti1 = item( curr + 1, 0 ); |
225 | ti2 = item( curr + 1, 1 ); | 229 | ti2 = item( curr + 1, 1 ); |
226 | ti3 = item( curr + 1, 2 ); | 230 | ti3 = item( curr + 1, 2 ); |
227 | ti4 = item( curr + 1, 3 ); | 231 | ti4 = item( curr + 1, 3 ); |
228 | takeItem( ti1 ); | 232 | takeItem( ti1 ); |
229 | takeItem( ti2 ); | 233 | takeItem( ti2 ); |
230 | takeItem( ti3 ); | 234 | takeItem( ti3 ); |
231 | takeItem( ti4 ); | 235 | takeItem( ti4 ); |
232 | setItem( curr, 0, ti1 ); | 236 | setItem( curr, 0, ti1 ); |
233 | setItem( curr, 1, ti2 ); | 237 | setItem( curr, 1, ti2 ); |
234 | setItem( curr, 2, ti3 ); | 238 | setItem( curr, 2, ti3 ); |
235 | setItem( curr, 3, ti4 ); | 239 | setItem( curr, 3, ti4 ); |
236 | } | 240 | } |
237 | setNumRows( totalRows - 1 ); | 241 | setNumRows( totalRows - 1 ); |
238 | } | 242 | } |
239 | 243 | ||
240 | #endif | 244 | #endif |