-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,239 +1,241 @@ | |||
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 | ||
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 |