summaryrefslogtreecommitdiffabout
path: root/korganizer/kotodoviewitem.cpp
Unidiff
Diffstat (limited to 'korganizer/kotodoviewitem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kotodoviewitem.cpp62
1 files changed, 41 insertions, 21 deletions
diff --git a/korganizer/kotodoviewitem.cpp b/korganizer/kotodoviewitem.cpp
index 6559119..66f8d06 100644
--- a/korganizer/kotodoviewitem.cpp
+++ b/korganizer/kotodoviewitem.cpp
@@ -1,46 +1,47 @@
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 24
24#include <kiconloader.h> 25#include <kiconloader.h>
25#include "kotodoviewitem.h" 26#include "kotodoviewitem.h"
26#include "kotodoview.h" 27#include "kotodoview.h"
27#include "koprefs.h" 28#include "koprefs.h"
28 29
29KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo) 30KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo)
30 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) 31 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
31{ 32{
32 construct(); 33 construct();
33} 34}
34 35
35KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo ) 36KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo )
36 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) 37 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
37{ 38{
38 construct(); 39 construct();
39} 40}
40 41
41QString KOTodoViewItem::key(int column,bool) const 42QString KOTodoViewItem::key(int column,bool) const
42{ 43{
43 QMap<int,QString>::ConstIterator it = mKeyMap.find(column); 44 QMap<int,QString>::ConstIterator it = mKeyMap.find(column);
44 if (it == mKeyMap.end()) { 45 if (it == mKeyMap.end()) {
45 return text(column).lower(); 46 return text(column).lower();
46 } else { 47 } else {
@@ -99,66 +100,77 @@ void KOTodoViewItem::construct()
99 QDate d = mTodo->dtDue().date(); 100 QDate d = mTodo->dtDue().date();
100 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 101 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
101 // setSortKey(3,keyd); 102 // setSortKey(3,keyd);
102 if (mTodo->doesFloat()) { 103 if (mTodo->doesFloat()) {
103 setText(4,""); 104 setText(4,"");
104 } 105 }
105 else { 106 else {
106 setText(4,mTodo->dtDueTimeStr()); 107 setText(4,mTodo->dtDueTimeStr());
107 QTime t = mTodo->dtDue().time(); 108 QTime t = mTodo->dtDue().time();
108 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 109 keyt.sprintf("%02d%02d",t.hour(),t.minute());
109 //setSortKey(4,keyt); 110 //setSortKey(4,keyt);
110 } 111 }
111 } else { 112 } else {
112 setText(3,""); 113 setText(3,"");
113 setText(4,""); 114 setText(4,"");
114 } 115 }
115 setSortKey(3,keyd); 116 setSortKey(3,keyd);
116 setSortKey(4,keyt); 117 setSortKey(4,keyt);
117 118
118 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt); 119 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt);
119 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 120 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
120 121
121 122
122 123
123 if (mTodo->hasStartDate()) { 124 keyd = "";
124 setText(5, mTodo->dtStartDateStr()); 125 keyt = "";
125 QDate d = mTodo->dtStart().date(); 126
126 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 127 if (mTodo->isRunning() ) {
127 128 QDate d = mTodo->runStart().date();
128 if (mTodo->doesFloat()) { 129 QTime t = mTodo->runStart().time();
129 setText(6,"");
130 }
131 else {
132 setText(6,mTodo->dtStartTimeStr());
133 QTime t = mTodo->dtStart().time();
134 skeyt.sprintf("%02d%02d",t.hour(),t.minute()); 130 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
135 131 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
136 } 132 keyd = KGlobal::locale()->formatDate( d );
133 keyt = KGlobal::locale()->formatTime( t );
134
137 } else { 135 } else {
138 setText(5,""); 136
139 setText(6,""); 137 if (mTodo->hasStartDate()) {
138 keyd = mTodo->dtStartDateStr();
139 QDate d = mTodo->dtStart().date();
140 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
141
142 if ( !mTodo->doesFloat()) {
143 keyt = mTodo->dtStartTimeStr();
144 QTime t = mTodo->dtStart().time();
145 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
146
147 }
148
149 }
140 } 150 }
151 setText(5,keyd);
152 setText(6,keyt);
141 setSortKey(5,skeyd); 153 setSortKey(5,skeyd);
142 setSortKey(6,skeyt); 154 setSortKey(6,skeyt);
143 155
144 setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No")); 156 setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No"));
145 setText(8,mTodo->categoriesStr()); 157 setText(8,mTodo->categoriesStr());
146 158
147#if 0 159#if 0
148 // Find sort id in description. It's the text behind the last '#' character 160 // Find sort id in description. It's the text behind the last '#' character
149 // found in the description. White spaces are removed from beginning and end 161 // found in the description. White spaces are removed from beginning and end
150 // of sort id. 162 // of sort id.
151 int pos = mTodo->description().findRev('#'); 163 int pos = mTodo->description().findRev('#');
152 if (pos < 0) { 164 if (pos < 0) {
153 setText(6,""); 165 setText(6,"");
154 } else { 166 } else {
155 QString str = mTodo->description().mid(pos+1); 167 QString str = mTodo->description().mid(pos+1);
156 str.stripWhiteSpace(); 168 str.stripWhiteSpace();
157 setText(6,str); 169 setText(6,str);
158 } 170 }
159#endif 171#endif
160 172
161 m_known = false; 173 m_known = false;
162 m_init = false; 174 m_init = false;
163 175
164 setMyPixmap(); 176 setMyPixmap();
@@ -347,55 +359,63 @@ void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, i
347{ 359{
348 QColorGroup _cg = cg; 360 QColorGroup _cg = cg;
349 QColorGroup::ColorRole role; 361 QColorGroup::ColorRole role;
350 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor ) 362 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor )
351 role = QColorGroup::Text; 363 role = QColorGroup::Text;
352 else 364 else
353 role = QColorGroup::Base; 365 role = QColorGroup::Base;
354 //#ifndef KORG_NOLVALTERNATION 366 //#ifndef KORG_NOLVALTERNATION
355 if (isAlternate()) 367 if (isAlternate())
356 _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground()); 368 _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground());
357 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors; 369 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors;
358 QColor colorToSet; 370 QColor colorToSet;
359 if ( setColor ) { 371 if ( setColor ) {
360 QStringList categories = mTodo->categories(); 372 QStringList categories = mTodo->categories();
361 QString cat = categories.first(); 373 QString cat = categories.first();
362 if ( !cat.isEmpty()) { 374 if ( !cat.isEmpty()) {
363 colorToSet = *(KOPrefs::instance()->categoryColor(cat) ); 375 colorToSet = *(KOPrefs::instance()->categoryColor(cat) );
364 } else 376 } else
365 setColor = false; 377 setColor = false;
366 } 378 }
367 bool openMode = !isOpen(); 379 bool openMode = !isOpen();
368 // maybe we are in flat-display-mode 380 // maybe we are in flat-display-mode
369 if ( !firstChild() ) 381 if ( !firstChild() )
370 openMode = false; 382 openMode = false;
371 int odue = mTodo->hasDueSubTodo( openMode ); 383 bool colorRunning = mTodo->isRunning();
372 if (odue == 2) { 384 if ( ! colorRunning && openMode )
373 colorToSet = KOPrefs::instance()->mTodoOverdueColor; 385 colorRunning = mTodo->hasRunningSub();
374 setColor = true; 386 if ( colorRunning ) {
375 } else if ( odue == 1 ) {
376 colorToSet = KOPrefs::instance()->mTodoDueTodayColor;
377 setColor = true; 387 setColor = true;
388 colorToSet = KOPrefs::instance()->mTodoRunColor;
389 } else {
390 int odue = mTodo->hasDueSubTodo( openMode );
391 if (odue == 2) {
392 colorToSet = KOPrefs::instance()->mTodoOverdueColor;
393 setColor = true;
394 } else if ( odue == 1 ) {
395 colorToSet = KOPrefs::instance()->mTodoDueTodayColor;
396 setColor = true;
397 }
378 } 398 }
379 399
380 400
381 if ( setColor ) { 401 if ( setColor ) {
382 _cg.setColor(role,colorToSet ); 402 _cg.setColor(role,colorToSet );
383 if ( role == QColorGroup::Base) { 403 if ( role == QColorGroup::Base) {
384 int rgb = colorToSet.red(); 404 int rgb = colorToSet.red();
385 rgb += colorToSet.blue()/2; 405 rgb += colorToSet.blue()/2;
386 rgb += colorToSet.green(); 406 rgb += colorToSet.green();
387 if ( rgb < 200 ) 407 if ( rgb < 200 )
388 _cg.setColor(QColorGroup::Text,Qt::white ); 408 _cg.setColor(QColorGroup::Text,Qt::white );
389 } 409 }
390 } 410 }
391 //#endif 411 //#endif
392 if ( column > 0 ){ 412 if ( column > 0 ){
393 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) { 413 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) {
394 p->save(); 414 p->save();
395 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5); 415 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5);
396 416
397 p->fillRect( 0, 0, width, height(), _cg.base() ); // background 417 p->fillRect( 0, 0, width, height(), _cg.base() ); // background
398 // p->setPen(Qt::black ); //border 418 // p->setPen(Qt::black ); //border
399 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling 419 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling
400 QColor fc = KOPrefs::instance()->mHighlightColor; 420 QColor fc = KOPrefs::instance()->mHighlightColor;
401 if ( mTodo->percentComplete() == 100 ) 421 if ( mTodo->percentComplete() == 100 )