summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kotodoviewitem.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/korganizer/kotodoviewitem.cpp b/korganizer/kotodoviewitem.cpp
index 848e9e7..519bb16 100644
--- a/korganizer/kotodoviewitem.cpp
+++ b/korganizer/kotodoviewitem.cpp
@@ -1,249 +1,258 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <klocale.h> 20#include <klocale.h>
21#include <kdebug.h> 21#include <kdebug.h>
22#include <qapp.h> 22#include <qapp.h>
23#include <kglobal.h> 23#include <kglobal.h>
24 24
25#include <kiconloader.h> 25#include <kiconloader.h>
26#include "kotodoviewitem.h" 26#include "kotodoviewitem.h"
27#include "kotodoview.h" 27#include "kotodoview.h"
28#include "koprefs.h" 28#include "koprefs.h"
29 29
30KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo) 30KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo)
31 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) 31 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
32{ 32{
33 construct(); 33 construct();
34} 34}
35 35
36KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo ) 36KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo )
37 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) 37 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
38{ 38{
39 construct(); 39 construct();
40} 40}
41 41
42QString KOTodoViewItem::key(int column,bool) const 42QString KOTodoViewItem::key(int column,bool) const
43{ 43{
44 if ( column == 0 )
45 return text(0).lower();
46 if ( column == 1 ) {
47 if ( mTodo->isCompleted() ) {
48 return "6"+QString::number(mTodo->priority())+text(0).lower();
49 }
50 return QString::number(mTodo->priority())+text(0).lower();
51 }
44 QMap<int,QString>::ConstIterator it = mKeyMap.find(column); 52 QMap<int,QString>::ConstIterator it = mKeyMap.find(column);
45 if (it == mKeyMap.end()) { 53 if (it == mKeyMap.end()) {
46 return text(column).lower(); 54 return text(column).lower();
47 } else { 55 } else {
56 if ( column == 2 ) {
57 return *it+text(0).lower();
58 }
48 return *it; 59 return *it;
49 } 60 }
50} 61}
51 62
52void KOTodoViewItem:: setup() 63void KOTodoViewItem:: setup()
53{ 64{
54 65
55 int h = 20; 66 int h = 20;
56 if ( listView () ) { 67 if ( listView () ) {
57 QFontMetrics fm ( listView ()->font () ); 68 QFontMetrics fm ( listView ()->font () );
58 h = fm.height(); 69 h = fm.height();
59 } 70 }
60 setHeight( h ); 71 setHeight( h );
61 72
62} 73}
63void KOTodoViewItem::setSortKey(int column,const QString &key) 74void KOTodoViewItem::setSortKey(int column,const QString &key)
64{ 75{
65 mKeyMap.insert(column,key); 76 mKeyMap.insert(column,key);
66} 77}
67 78
68#if QT_VERSION >= 0x030000 79#if QT_VERSION >= 0x030000
69void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w, 80void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w,
70 int y,int h) 81 int y,int h)
71{ 82{
72 QListViewItem::paintBranches(p,cg,w,y,h); 83 QListViewItem::paintBranches(p,cg,w,y,h);
73} 84}
74#else 85#else
75#endif 86#endif
76 87
77void KOTodoViewItem::construct() 88void KOTodoViewItem::construct()
78{ 89{
79 // qDebug("KOTodoViewItem::construct() "); 90 // qDebug("KOTodoViewItem::construct() ");
80 m_init = true; 91 m_init = true;
81 QString keyd = "=="; 92 QString keyd = "==";
82 QString keyt = "=="; 93 QString keyt = "==";
83 QString skeyd = "=="; 94 QString skeyd = "==";
84 QString skeyt = "=="; 95 QString skeyt = "==";
85 96
86 setOn(mTodo->isCompleted()); 97 setOn(mTodo->isCompleted());
87 setText(0,mTodo->summary()); 98 setText(0,mTodo->summary());
88 setText(1,QString::number(mTodo->priority())); 99 setText(1,QString::number(mTodo->priority()));
89 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); 100 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
90 if (mTodo->percentComplete()<100) { 101 if (mTodo->percentComplete()<100) {
91 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 102 setSortKey(2,QString::number(mTodo->percentComplete()));
92 else setSortKey(2,QString::number(mTodo->percentComplete()));
93 } 103 }
94 else { 104 else {
95 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 105 setSortKey(2,"999");
96 else setSortKey(2,QString::number(99));
97 } 106 }
98 if (mTodo->hasDueDate()) { 107 if (mTodo->hasDueDate()) {
99 setText(3, mTodo->dtDueDateStr()); 108 setText(3, mTodo->dtDueDateStr());
100 QDate d = mTodo->dtDue().date(); 109 QDate d = mTodo->dtDue().date();
101 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 110 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
102 // setSortKey(3,keyd); 111 // setSortKey(3,keyd);
103 if (mTodo->doesFloat()) { 112 if (mTodo->doesFloat()) {
104 setText(4,""); 113 setText(4,"");
105 } 114 }
106 else { 115 else {
107 setText(4,mTodo->dtDueTimeStr()); 116 setText(4,mTodo->dtDueTimeStr());
108 QTime t = mTodo->dtDue().time(); 117 QTime t = mTodo->dtDue().time();
109 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 118 keyt.sprintf("%02d%02d",t.hour(),t.minute());
110 //setSortKey(4,keyt); 119 //setSortKey(4,keyt);
111 } 120 }
112 } else { 121 } else {
113 setText(3,""); 122 setText(3,"");
114 setText(4,""); 123 setText(4,"");
115 } 124 }
116 setSortKey(3,keyd); 125 setSortKey(3,keyd);
117 setSortKey(4,keyt); 126 setSortKey(4,keyt);
118 127#if 0
119 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt); 128 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt);
120 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 129 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
121 130#endif
122 keyd = ""; 131 keyd = "";
123 keyt = ""; 132 keyt = "";
124 133
125 if (mTodo->isRunning() ) { 134 if (mTodo->isRunning() ) {
126 QDate d = mTodo->runStart().date(); 135 QDate d = mTodo->runStart().date();
127 QTime t = mTodo->runStart().time(); 136 QTime t = mTodo->runStart().time();
128 skeyt.sprintf("%02d%02d",t.hour(),t.minute()); 137 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
129 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 138 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
130 keyd = KGlobal::locale()->formatDate( d , true); 139 keyd = KGlobal::locale()->formatDate( d , true);
131 keyt = KGlobal::locale()->formatTime( t ); 140 keyt = KGlobal::locale()->formatTime( t );
132 141
133 } else { 142 } else {
134 143
135 if (mTodo->hasStartDate()) { 144 if (mTodo->hasStartDate()) {
136 keyd = mTodo->dtStartDateStr(); 145 keyd = mTodo->dtStartDateStr();
137 QDate d = mTodo->dtStart().date(); 146 QDate d = mTodo->dtStart().date();
138 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 147 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
139 148
140 if ( !mTodo->doesFloat()) { 149 if ( !mTodo->doesFloat()) {
141 keyt = mTodo->dtStartTimeStr(); 150 keyt = mTodo->dtStartTimeStr();
142 QTime t = mTodo->dtStart().time(); 151 QTime t = mTodo->dtStart().time();
143 skeyt.sprintf("%02d%02d",t.hour(),t.minute()); 152 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
144 153
145 } 154 }
146 155
147 } 156 }
148 } 157 }
149 setText(5,keyd); 158 setText(5,keyd);
150 setText(6,keyt); 159 setText(6,keyt);
151 setSortKey(5,skeyd); 160 setSortKey(5,skeyd);
152 setSortKey(6,skeyt); 161 setSortKey(6,skeyt);
153 162
154 //setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No")); 163 //setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No"));
155 setText(7,mTodo->categoriesStr()); 164 setText(7,mTodo->categoriesStr());
156 setText(8,KOPrefs::instance()->calName( mTodo->calID())); 165 setText(8,KOPrefs::instance()->calName( mTodo->calID()));
157 setText(9, KGlobal::locale()->formatDateTime( mTodo->lastModified(), true, true )); 166 setText(9, KGlobal::locale()->formatDateTime( mTodo->lastModified(), true, true ));
158 setText(10, KGlobal::locale()->formatDateTime( mTodo->created(), true, true )); 167 setText(10, KGlobal::locale()->formatDateTime( mTodo->created(), true, true ));
159 setText(11, KGlobal::locale()->formatDateTime( mTodo->lastModifiedSub(), true, true )); 168 setText(11, KGlobal::locale()->formatDateTime( mTodo->lastModifiedSub(), true, true ));
160 QString key; 169 QString key;
161 QDate d; 170 QDate d;
162 QTime t; 171 QTime t;
163 setSortKey(9,mTodo->lastModifiedSortKey()); 172 setSortKey(9,mTodo->lastModifiedSortKey());
164 d = mTodo->created().date(); 173 d = mTodo->created().date();
165 t = mTodo->created().time(); 174 t = mTodo->created().time();
166 key.sprintf("%04d%02d%02d%02d%02d%02d",d.year(),d.month(),d.day(),t.hour(),t.minute(),t.second() ); 175 key.sprintf("%04d%02d%02d%02d%02d%02d",d.year(),d.month(),d.day(),t.hour(),t.minute(),t.second() );
167 setSortKey(10,key); 176 setSortKey(10,key);
168 setSortKey(11,mTodo->lastModifiedSubSortKey()); 177 setSortKey(11,mTodo->lastModifiedSubSortKey());
169 178
170#if 0 179#if 0
171 // Find sort id in description. It's the text behind the last '#' character 180 // Find sort id in description. It's the text behind the last '#' character
172 // found in the description. White spaces are removed from beginning and end 181 // found in the description. White spaces are removed from beginning and end
173 // of sort id. 182 // of sort id.
174 int pos = mTodo->description().findRev('#'); 183 int pos = mTodo->description().findRev('#');
175 if (pos < 0) { 184 if (pos < 0) {
176 setText(6,""); 185 setText(6,"");
177 } else { 186 } else {
178 QString str = mTodo->description().mid(pos+1); 187 QString str = mTodo->description().mid(pos+1);
179 str.stripWhiteSpace(); 188 str.stripWhiteSpace();
180 setText(6,str); 189 setText(6,str);
181 } 190 }
182#endif 191#endif
183 192
184 m_known = false; 193 m_known = false;
185 m_init = false; 194 m_init = false;
186 195
187 setMyPixmap(); 196 setMyPixmap();
188 197
189} 198}
190void KOTodoViewItem::setMyPixmap() 199void KOTodoViewItem::setMyPixmap()
191{ 200{
192 int size = 5; 201 int size = 5;
193 QPixmap pixi = QPixmap( 1, 1 ); 202 QPixmap pixi = QPixmap( 1, 1 );
194 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) { 203 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) {
195// pixi = SmallIcon("redcross16"); 204// pixi = SmallIcon("redcross16");
196// } else { 205// } else {
197 QPainter p; 206 QPainter p;
198 207
199 int pixSize = 0; 208 int pixSize = 0;
200 QPixmap pPix = QPixmap( size, size ); 209 QPixmap pPix = QPixmap( size, size );
201 if ( mTodo->description().length() > 0 ) { 210 if ( mTodo->description().length() > 0 ) {
202 pixi.resize(size, pixSize+size); 211 pixi.resize(size, pixSize+size);
203 pPix.fill( Qt::darkGreen ); 212 pPix.fill( Qt::darkGreen );
204 p.begin( &pixi ); 213 p.begin( &pixi );
205 p. drawPixmap ( 0, pixSize, pPix); 214 p. drawPixmap ( 0, pixSize, pPix);
206 p.end(); 215 p.end();
207 pixSize += size; 216 pixSize += size;
208 } 217 }
209 if ( mTodo->isAlarmEnabled() && mTodo->alarmEnabled()) { 218 if ( mTodo->isAlarmEnabled() && mTodo->alarmEnabled()) {
210 pixi.resize(size, pixSize+size); 219 pixi.resize(size, pixSize+size);
211 pPix.fill( Qt::red ); 220 pPix.fill( Qt::red );
212 p.begin( &pixi ); 221 p.begin( &pixi );
213 p. drawPixmap ( 0, pixSize, pPix); 222 p. drawPixmap ( 0, pixSize, pPix);
214 p.end(); 223 p.end();
215 pixSize += size; 224 pixSize += size;
216 } 225 }
217 if ( mTodo->doesRecur() ) { 226 if ( mTodo->doesRecur() ) {
218 pixi.resize(size, pixSize+size); 227 pixi.resize(size, pixSize+size);
219 pPix.fill( Qt::blue ); 228 pPix.fill( Qt::blue );
220 p.begin( &pixi ); 229 p.begin( &pixi );
221 p. drawPixmap ( 0, pixSize, pPix); 230 p. drawPixmap ( 0, pixSize, pPix);
222 p.end(); 231 p.end();
223 pixSize += size; 232 pixSize += size;
224 } 233 }
225 // } 234 // }
226 if ( pixi.width() > 1 ) { 235 if ( pixi.width() > 1 ) {
227 setPixmap ( 0,pixi ) ; 236 setPixmap ( 0,pixi ) ;
228 } else { 237 } else {
229 setPixmap ( 0,QPixmap() ) ; 238 setPixmap ( 0,QPixmap() ) ;
230 } 239 }
231} 240}
232void KOTodoViewItem::stateChange(bool state) 241void KOTodoViewItem::stateChange(bool state)
233{ 242{
234 // qDebug("KOTodoViewItem::stateChange %d ", state); 243 // qDebug("KOTodoViewItem::stateChange %d ", state);
235 // do not change setting on startup 244 // do not change setting on startup
236 if ( m_init ) return; 245 if ( m_init ) return;
237 if (isOn()!=state) { 246 if (isOn()!=state) {
238 setOn(state); 247 setOn(state);
239 //qDebug("SETON "); 248 //qDebug("SETON ");
240 return; 249 return;
241 } 250 }
242 if ( mTodo->isCompleted() == state ) { 251 if ( mTodo->isCompleted() == state ) {
243 //qDebug("STATECHANGE:nothing to do "); 252 //qDebug("STATECHANGE:nothing to do ");
244 return; 253 return;
245 } 254 }
246 QString keyd = "=="; 255 QString keyd = "==";
247 QString keyt = "=="; 256 QString keyt = "==";
248 //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1()); 257 //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1());
249 if ( mTodo->doesRecur() ){ 258 if ( mTodo->doesRecur() ){