summaryrefslogtreecommitdiffabout
path: root/korganizer/kotodoviewitem.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /korganizer/kotodoviewitem.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'korganizer/kotodoviewitem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kotodoviewitem.cpp432
1 files changed, 432 insertions, 0 deletions
diff --git a/korganizer/kotodoviewitem.cpp b/korganizer/kotodoviewitem.cpp
new file mode 100644
index 0000000..85647b1
--- a/dev/null
+++ b/korganizer/kotodoviewitem.cpp
@@ -0,0 +1,432 @@
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4
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
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
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
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18*/
19
20#include <klocale.h>
21#include <kdebug.h>
22#include <qapp.h>
23
24#include <kiconloader.h>
25#include "kotodoviewitem.h"
26#include "kotodoview.h"
27#include "koprefs.h"
28
29KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo)
30 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
31{
32 construct();
33}
34
35KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo )
36 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
37{
38 construct();
39}
40
41QString KOTodoViewItem::key(int column,bool) const
42{
43 QMap<int,QString>::ConstIterator it = mKeyMap.find(column);
44 if (it == mKeyMap.end()) {
45 return text(column);
46 } else {
47 return *it;
48 }
49}
50
51void KOTodoViewItem:: setup()
52{
53
54 int h = 20;
55 if ( listView () ) {
56 QFontMetrics fm ( listView ()->font () );
57 h = fm.height();
58 }
59 setHeight( h );
60
61}
62void KOTodoViewItem::setSortKey(int column,const QString &key)
63{
64 mKeyMap.insert(column,key);
65}
66
67#if QT_VERSION >= 300
68void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w,
69 int y,int h)
70{
71 QListViewItem::paintBranches(p,cg,w,y,h);
72}
73#else
74#endif
75
76void KOTodoViewItem::construct()
77{
78 // qDebug("KOTodoViewItem::construct() ");
79 m_init = true;
80 QString keyd = "==";
81 QString keyt = "==";
82
83 setOn(mTodo->isCompleted());
84 setText(0,mTodo->summary());
85 setText(1,QString::number(mTodo->priority()));
86 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
87 if (mTodo->percentComplete()<100) {
88 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
89 else setSortKey(2,QString::number(mTodo->percentComplete()));
90 }
91 else {
92 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
93 else setSortKey(2,QString::number(99));
94 }
95 if (mTodo->hasDueDate()) {
96 setText(3, mTodo->dtDueDateStr());
97 QDate d = mTodo->dtDue().date();
98 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
99 setSortKey(3,keyd);
100 if (mTodo->doesFloat()) {
101 setText(4,"");
102 }
103 else {
104 setText(4,mTodo->dtDueTimeStr());
105 QTime t = mTodo->dtDue().time();
106 keyt.sprintf("%02d%02d",t.hour(),t.minute());
107 setSortKey(4,keyt);
108 }
109 } else {
110 setText(3,"");
111 setText(4,"");
112 }
113 setSortKey(3,keyd);
114 setSortKey(4,keyt);
115
116 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt);
117 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
118
119 setText(5,mTodo->cancelled() ? i18n("Yes") : i18n("No"));
120 setText(6,mTodo->categoriesStr());
121
122#if 0
123 // Find sort id in description. It's the text behind the last '#' character
124 // found in the description. White spaces are removed from beginning and end
125 // of sort id.
126 int pos = mTodo->description().findRev('#');
127 if (pos < 0) {
128 setText(6,"");
129 } else {
130 QString str = mTodo->description().mid(pos+1);
131 str.stripWhiteSpace();
132 setText(6,str);
133 }
134#endif
135
136 m_known = false;
137 m_init = false;
138
139 setMyPixmap();
140
141}
142void KOTodoViewItem::setMyPixmap()
143{
144 int size = 5;
145 QPixmap pixi = QPixmap( 1, 1 );
146 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) {
147// pixi = SmallIcon("redcross16");
148// } else {
149 QPainter p;
150
151 int pixSize = 0;
152 QPixmap pPix = QPixmap( size, size );
153 if ( mTodo->description().length() > 0 ) {
154 pixi.resize(size, pixSize+size);
155 pPix.fill( Qt::darkGreen );
156 p.begin( &pixi );
157 p. drawPixmap ( 0, pixSize, pPix);
158 p.end();
159 pixSize += size;
160 }
161 if ( mTodo->isAlarmEnabled() ) {
162 pixi.resize(size, pixSize+size);
163 pPix.fill( Qt::red );
164 p.begin( &pixi );
165 p. drawPixmap ( 0, pixSize, pPix);
166 p.end();
167 pixSize += size;
168 }
169 // }
170 if ( pixi.width() > 1 ) {
171 setPixmap ( 0,pixi ) ;
172 }
173
174
175}
176void KOTodoViewItem::stateChange(bool state)
177{
178 // qDebug("KOTodoViewItem::stateChange ");
179 // do not change setting on startup
180 if ( m_init ) return;
181
182 kdDebug() << "State changed, modified " << state << endl;
183 QString keyd = "==";
184 QString keyt = "==";
185
186 if (state) mTodo->setCompleted(state);
187 else mTodo->setPercentComplete(0);
188 if (isOn()!=state) {
189 setOn(state);
190 }
191
192 if (mTodo->hasDueDate()) {
193 setText(3, mTodo->dtDueDateStr());
194 QDate d = mTodo->dtDue().date();
195 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
196 setSortKey(3,keyd);
197 if (mTodo->doesFloat()) {
198 setText(4,"");
199 }
200 else {
201 setText(4,mTodo->dtDueTimeStr());
202 QTime t = mTodo->dtDue().time();
203 keyt.sprintf("%02d%02d",t.hour(),t.minute());
204 setSortKey(4,keyt);
205 }
206 }
207 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt);
208 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
209
210 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
211 if (mTodo->percentComplete()<100) {
212 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
213 else setSortKey(2,QString::number(mTodo->percentComplete()));
214 }
215 else {
216 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
217 else setSortKey(2,QString::number(99));
218 }
219 QListViewItem * myChild = firstChild();
220 KOTodoViewItem *item;
221 while( myChild ) {
222 item = static_cast<KOTodoViewItem*>(myChild);
223 item->stateChange(state);
224 myChild = myChild->nextSibling();
225 }
226 mTodoView->modified(true);
227 mTodoView->setTodoModified( mTodo );
228 setMyPixmap();
229}
230
231bool KOTodoViewItem::isAlternate()
232{
233#ifndef KORG_NOLVALTERNATION
234 KOTodoListView *lv = static_cast<KOTodoListView *>(listView());
235 if (lv && lv->alternateBackground().isValid())
236 {
237 KOTodoViewItem *above = 0;
238 above = dynamic_cast<KOTodoViewItem *>(itemAbove());
239 m_known = above ? above->m_known : true;
240 if (m_known)
241 {
242 m_odd = above ? !above->m_odd : false;
243 }
244 else
245 {
246 KOTodoViewItem *item;
247 bool previous = true;
248 if (QListViewItem::parent())
249 {
250 item = dynamic_cast<KOTodoViewItem *>(QListViewItem::parent());
251 if (item)
252 previous = item->m_odd;
253 item = dynamic_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild());
254 }
255 else
256 {
257 item = dynamic_cast<KOTodoViewItem *>(lv->firstChild());
258 }
259
260 while(item)
261 {
262 item->m_odd = previous = !previous;
263 item->m_known = true;
264 item = dynamic_cast<KOTodoViewItem *>(item->nextSibling());
265 }
266 }
267 return m_odd;
268 }
269 return false;
270#else
271 return false;
272#endif
273}
274
275void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
276{
277 QColorGroup _cg = cg;
278 QColorGroup::ColorRole role;
279 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor )
280 role = QColorGroup::Text;
281 else
282 role = QColorGroup::Base;
283 //#ifndef KORG_NOLVALTERNATION
284 // if (isAlternate())
285 // _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground());
286 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors;
287 QColor colorToSet;
288 if ( setColor ) {
289 QStringList categories = mTodo->categories();
290 QString cat = categories.first();
291 if ( !cat.isEmpty()) {
292 colorToSet = *(KOPrefs::instance()->categoryColor(cat) );
293 } else
294 setColor = false;
295 }
296 if (mTodo->hasDueDate()) {
297 if (mTodo->dtDue().date()==QDate::currentDate() &&
298 !mTodo->isCompleted()) {
299 //_cg.setColor( role , KOPrefs::instance()->mTodoDueTodayColor);
300 colorToSet = KOPrefs::instance()->mTodoDueTodayColor;
301 setColor = true;
302 }
303 if (mTodo->dtDue().date() < QDate::currentDate() &&
304 !mTodo->isCompleted()) {
305 //_cg.setColor( role, KOPrefs::instance()->mTodoOverdueColor);
306 colorToSet = KOPrefs::instance()->mTodoOverdueColor;
307 setColor = true;
308 }
309 }
310
311 if ( setColor ) {
312 _cg.setColor(role,colorToSet );
313 if ( role == QColorGroup::Base) {
314 int rgb = colorToSet.red();
315 rgb += colorToSet.blue()/2;
316 rgb += colorToSet.green();
317 if ( rgb < 200 )
318 _cg.setColor(QColorGroup::Text,Qt::white );
319 }
320 }
321 //#endif
322 if ( column > 0 ){
323 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) {
324 p->save();
325 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5);
326
327 p->fillRect( 0, 0, width, height(), _cg.base() ); // background
328 // p->setPen(Qt::black ); //border
329 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling
330 QColor fc = KOPrefs::instance()->mHighlightColor;
331 if ( mTodo->percentComplete() == 100 )
332 fc = darkGreen;
333 p->drawRect( 2, 2, width-4, height()-4);
334 p->fillRect( 3, 3, progress, height()-6,
335 fc );
336 p->restore();
337 } else {
338 QCheckListItem::paintCell(p, _cg, column, width, alignment);
339 }
340 return;
341 }
342
343 int align = alignment;
344
345 if ( !p )
346 return;
347
348 p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) );
349
350 QListView *lv = listView();
351 if ( !lv )
352 return;
353 int marg = 2;//lv->itemMargin();
354 int r = 0;
355 QCheckListItem::Type myType = QCheckListItem::CheckBox;
356 int BoxSize = 20;
357 int boxOffset = 2;
358 int xOffset = 2;
359 if (qApp->desktop()->width() < 300 ) {
360 BoxSize = 14;
361 boxOffset = -1;
362 xOffset = 1;
363 // marg = 0;
364 }
365 if ( height() < BoxSize ) {
366 boxOffset = boxOffset - ((BoxSize - height())/2) ;
367 // qDebug("boxOffset %d height %d", boxOffset, height() );
368 BoxSize = height();
369
370 }
371 //bool winStyle = lv->style() == WindowsStyle;
372
373 int lineStart = 5;
374 if ( myType == Controller ) {
375 if ( !pixmap( 0 ) )
376 r += BoxSize + 4;
377 } else {
378 ASSERT( lv ); //###
379 //QFontMetrics fm( lv->font() );
380 //int d = fm.height();
381 int x = 0;
382 int y = (height() - BoxSize) / 2;
383 //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) );
384 if ( myType == CheckBox ) {
385 if ( isEnabled() )
386 p->setPen( QPen( _cg.text(), 1 ) );
387 else
388 p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) );
389 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 );
390 lineStart = x+marg;
391 /////////////////////
392 x++;
393 y++;
394 if ( isOn() ) {
395 QPointArray a( 7*2 );
396 int i, xx, yy;
397 xx = x+xOffset+marg+(boxOffset/2);
398 yy = y+5+boxOffset;
399 for ( i=0; i<3; i++ ) {
400 a.setPoint( 2*i, xx, yy );
401 a.setPoint( 2*i+1, xx, yy+2 );
402 // qDebug(" ");
403 xx++; yy++;
404 }
405 yy -= 2;
406 for ( i=3; i<7; i++ ) {
407 a.setPoint( 2*i, xx, yy );
408 a.setPoint( 2*i+1, xx, yy+2 );
409 xx++; yy--;
410 }
411 p->setPen( darkGreen );
412 p->drawLineSegments( a );
413 }
414 ////////////////////////
415 }
416 r += BoxSize + 4;
417 }
418
419 p->translate( r, 0 );
420 p->setPen( QPen( _cg.text() ) );
421 QListViewItem::paintCell( p, _cg, column, width - r, align );
422 if ( mTodo->cancelled () ) {
423 p->setPen( black );
424 QRect br = p->boundingRect( 1,1,1,1,0,mTodo->summary() );
425 int wid = br.width() +lineStart;
426 if ( wid > width-3 )
427 wid = width-3;
428 p->drawLine( lineStart, height()/2+1, wid, height()/2+1 );
429
430 }
431
432}