-rw-r--r-- | core/pim/todo/todotable.h | 207 |
1 files changed, 207 insertions, 0 deletions
diff --git a/core/pim/todo/todotable.h b/core/pim/todo/todotable.h new file mode 100644 index 0000000..4f3a064 --- a/dev/null +++ b/core/pim/todo/todotable.h | |||
@@ -0,0 +1,207 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #ifndef TODOTABLE_H | ||
22 | #define TODOTABLE_H | ||
23 | |||
24 | #include <qpe/categories.h> | ||
25 | #include <qpe/stringutil.h> | ||
26 | #include <qpe/task.h> | ||
27 | |||
28 | #include <qtable.h> | ||
29 | #include <qmap.h> | ||
30 | #include <qguardedptr.h> | ||
31 | |||
32 | class Node; | ||
33 | class QComboBox; | ||
34 | class QTimer; | ||
35 | |||
36 | class CheckItem : public QTableItem | ||
37 | { | ||
38 | public: | ||
39 | CheckItem( QTable *t, const QString &sortkey ); | ||
40 | |||
41 | void setChecked( bool b ); | ||
42 | void toggle(); | ||
43 | bool isChecked() const; | ||
44 | void setKey( const QString &key ) { sortKey = key; } | ||
45 | QString key() const; | ||
46 | |||
47 | void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ); | ||
48 | |||
49 | private: | ||
50 | bool checked; | ||
51 | QString sortKey; | ||
52 | }; | ||
53 | |||
54 | class ComboItem : public QTableItem | ||
55 | { | ||
56 | public: | ||
57 | ComboItem( QTable *t, EditType et ); | ||
58 | QWidget *createEditor() const; | ||
59 | void setContentFromEditor( QWidget *w ); | ||
60 | void setText( const QString &s ); | ||
61 | int alignment() const { return Qt::AlignCenter; } | ||
62 | |||
63 | QString text() const; | ||
64 | |||
65 | private: | ||
66 | QGuardedPtr<QComboBox> cb; | ||
67 | |||
68 | }; | ||
69 | |||
70 | class TodoTextItem : public QTableItem | ||
71 | { | ||
72 | public: | ||
73 | TodoTextItem( QTable *t, const QString & str ) | ||
74 | :QTableItem( t, QTableItem::Never, str ) {} | ||
75 | |||
76 | QString key () const { return Qtopia::buildSortKey( text() ); } | ||
77 | }; | ||
78 | |||
79 | |||
80 | |||
81 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; | ||
82 | |||
83 | class TodoTable : public QTable | ||
84 | { | ||
85 | Q_OBJECT | ||
86 | |||
87 | public: | ||
88 | TodoTable( QWidget *parent = 0, const char * name = 0 ); | ||
89 | void addEntry( const Task &todo ); | ||
90 | void clearFindRow() { currFindRow = -2; } | ||
91 | |||
92 | Task currentEntry() const; | ||
93 | void replaceCurrentEntry( const Task &todo, bool fromTableItem = false ); | ||
94 | |||
95 | QStringList categories(); | ||
96 | |||
97 | void setShowCompleted( bool sc ) { showComp = sc; updateVisible(); } | ||
98 | bool showCompleted() const { return showComp; } | ||
99 | |||
100 | void setShowCategory( const QString &c ) { showCat = c; updateVisible(); } | ||
101 | const QString &showCategory() const { return showCat; } | ||
102 | int showCategoryId() const; | ||
103 | |||
104 | bool save( const QString &fn ); | ||
105 | void load( const QString &fn ); | ||
106 | void clear(); | ||
107 | void removeCurrentEntry(); | ||
108 | |||
109 | void setPaintingEnabled( bool e ); | ||
110 | |||
111 | virtual void sortColumn( int col, bool ascending, bool /*wholeRows*/ ); | ||
112 | |||
113 | // int rowHeight( int ) const; | ||
114 | // int rowPos( int row ) const; | ||
115 | // virtual int rowAt( int pos ) const; | ||
116 | |||
117 | signals: | ||
118 | void signalEdit(); | ||
119 | void signalDoneChanged( bool b ); | ||
120 | void signalPriorityChanged( int i ); | ||
121 | void signalShowMenu( const QPoint & ); | ||
122 | void signalNotFound(); | ||
123 | void signalWrapAround(); | ||
124 | |||
125 | protected: | ||
126 | void keyPressEvent( QKeyEvent *e ); | ||
127 | |||
128 | private: | ||
129 | void updateVisible(); | ||
130 | void viewportPaintEvent( QPaintEvent * ); | ||
131 | void internalAddEntries( QList<Task> &list); | ||
132 | inline void insertIntoTable( Task *todo, int row ); | ||
133 | void updateJournal( const Task &todo, journal_action action, int row = -1); | ||
134 | void mergeJournal(); | ||
135 | void journalFreeReplaceEntry( const Task &todo, int row ); | ||
136 | void journalFreeRemoveEntry( int row ); | ||
137 | inline void realignTable( int row ); | ||
138 | void loadFile( const QString &strFile, bool fromJournal = false ); | ||
139 | |||
140 | private slots: | ||
141 | void slotClicked( int row, int col, int button, const QPoint &pos ); | ||
142 | void slotPressed( int row, int col, int button, const QPoint &pos ); | ||
143 | void slotCheckPriority(int row, int col ); | ||
144 | void slotCurrentChanged(int row, int col ); | ||
145 | void slotDoFind( const QString &findString, bool caseSensetive, | ||
146 | bool backwards, int category ); | ||
147 | void slotShowMenu(); | ||
148 | void rowHeightChanged( int row ); | ||
149 | |||
150 | private: | ||
151 | friend class TodoWindow; | ||
152 | |||
153 | QMap<CheckItem*, Task *> todoList; | ||
154 | QStringList categoryList; | ||
155 | bool showComp; | ||
156 | QString showCat; | ||
157 | QTimer *menuTimer; | ||
158 | bool enablePainting; | ||
159 | Categories mCat; | ||
160 | int currFindRow; | ||
161 | }; | ||
162 | |||
163 | |||
164 | inline void TodoTable::insertIntoTable( Task *todo, int row ) | ||
165 | { | ||
166 | QString sortKey = (char) ((todo->isCompleted() ? 'a' : 'A') | ||
167 | + todo->priority() ) | ||
168 | + Qtopia::buildSortKey( todo->description() ); | ||
169 | CheckItem *chk = new CheckItem( this, sortKey ); | ||
170 | chk->setChecked( todo->isCompleted() ); | ||
171 | ComboItem *cmb = new ComboItem( this, QTableItem::WhenCurrent ); | ||
172 | cmb->setText( QString::number( todo->priority() ) ); | ||
173 | QTableItem *ti = new TodoTextItem( this, todo->description().left(40).simplifyWhiteSpace() ); | ||
174 | ti->setReplaceable( false ); | ||
175 | |||
176 | setItem( row, 0, chk ); | ||
177 | setItem( row, 1, cmb ); | ||
178 | setItem( row, 2, ti ); | ||
179 | |||
180 | todoList.insert( chk, todo ); | ||
181 | } | ||
182 | |||
183 | inline void TodoTable::realignTable( int row ) | ||
184 | { | ||
185 | QTableItem *ti1, | ||
186 | *ti2, | ||
187 | *ti3; | ||
188 | int totalRows = numRows(); | ||
189 | for ( int curr = row; curr < totalRows - 1; curr++ ) { | ||
190 | // this is bad, we must take the item out and then | ||
191 | // set it. In the end, it behaves no worse (time wise) | ||
192 | // then the old way of saving the entries to file, clearing | ||
193 | // the table re-reading in the file and resetting the table | ||
194 | ti1 = item( curr + 1, 0 ); | ||
195 | ti2 = item( curr + 1, 1 ); | ||
196 | ti3 = item( curr + 1, 2 ); | ||
197 | takeItem( ti1 ); | ||
198 | takeItem( ti2 ); | ||
199 | takeItem( ti3 ); | ||
200 | setItem( curr, 0, ti1 ); | ||
201 | setItem( curr, 1, ti2 ); | ||
202 | setItem( curr, 2, ti3 ); | ||
203 | } | ||
204 | setNumRows( totalRows - 1 ); | ||
205 | } | ||
206 | |||
207 | #endif | ||