00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
#include <qpainter.h>
00026
00027
#include <klocale.h>
00028
#include <kdebug.h>
00029
#include <qpainter.h>
00030
#include <qpixmap.h>
00031
00032
#include "kotodoviewitem.h"
00033
#include "kotodoview.h"
00034
#include "koprefs.h"
00035
#include "koglobals.h"
00036
00037 KOTodoViewItem::KOTodoViewItem(
QListView *parent, Todo *todo,
KOTodoView *kotodo)
00038 :
QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
00039 {
00040 construct();
00041 }
00042
00043 KOTodoViewItem::KOTodoViewItem(
KOTodoViewItem *parent, Todo *todo,
KOTodoView *kotodo )
00044 :
QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
00045 {
00046 construct();
00047 }
00048
00049
00050
int KOTodoViewItem::compare(
QListViewItem *i,
int col,
bool ascending )
const
00051
{
00052
if ( i && ( col == eDueDateColumn ) ) {
00053
QString thiskey( key( col, ascending ) );
00054
QString ikey( i->key( col, ascending ) );
00055
if ( thiskey.isEmpty() ) {
00056
if ( ikey.isEmpty() )
00057
return 0;
00058
else
00059
if ( ascending )
return 1;
00060
else return -1;
00061 }
else {
00062
if ( ikey.isEmpty() )
00063
if ( ascending )
return -1;
00064
else return 1;
00065
else
00066
return QCheckListItem::compare( i, col, ascending );
00067 }
00068 }
else return QCheckListItem::compare( i, col, ascending );
00069 }
00070
00071
QString KOTodoViewItem::key(
int column,
bool )
const
00072
{
00073
QMap<int,QString>::ConstIterator it = mKeyMap.find( column );
00074
if ( it == mKeyMap.end() ) {
00075
return text( column );
00076 }
else {
00077
return *it;
00078 }
00079 }
00080
00081
void KOTodoViewItem::setSortKey(
int column,
const QString &key)
00082 {
00083 mKeyMap.insert(column,key);
00084 }
00085
00086
#if QT_VERSION >= 300
00087
void KOTodoViewItem::paintBranches(
QPainter *p,
const QColorGroup & cg,
int w,
00088
int y,
int h)
00089 {
00090 QListViewItem::paintBranches(p,cg,w,y,h);
00091 }
00092
#else
00093
#endif
00094
00095
void KOTodoViewItem::construct()
00096 {
00097
if ( !mTodo )
return;
00098 m_init =
true;
00099
QString keyd =
"9";
00100
00101 setOn( mTodo->isCompleted() );
00102 setText( eSummaryColumn, mTodo->summary());
00103
static const QPixmap recurPxmp = KOGlobals::self()->smallIcon(
"recur");
00104
if ( mTodo->doesRecur() ) {
00105 setPixmap( eRecurColumn, recurPxmp );
00106 setSortKey( eRecurColumn,
"1" );
00107 }
00108
else setSortKey( eRecurColumn,
"0" );
00109 setText( ePriorityColumn, QString::number(mTodo->priority()) );
00110 setText( ePercentColumn, QString::number(mTodo->percentComplete()) );
00111
if ( mTodo->percentComplete()<100 ) {
00112
if (mTodo->isCompleted()) setSortKey( ePercentColumn, QString::number(999) );
00113
else setSortKey( ePercentColumn, QString::number( mTodo->percentComplete() ) );
00114 }
00115
else {
00116
if (mTodo->isCompleted()) setSortKey( ePercentColumn, QString::number(999) );
00117
else setSortKey( ePercentColumn, QString::number(99) );
00118 }
00119
00120
if (mTodo->hasDueDate()) {
00121
QString dtStr = mTodo->dtDueDateStr();
00122
QString keyt =
"";
00123
if (!mTodo->doesFloat()) {
00124 dtStr +=
" " + mTodo->dtDueTimeStr();
00125 }
00126 setText( eDueDateColumn, dtStr );
00127 keyd = mTodo->dtDue().toString(Qt::ISODate);
00128 }
else {
00129 keyd =
"";
00130 setText( eDueDateColumn,
"" );
00131 }
00132 keyd += QString::number( mTodo->priority() );
00133 setSortKey( eDueDateColumn, keyd );
00134
00135
QString priorityKey = QString::number( mTodo->priority() ) + keyd;
00136
if ( mTodo->isCompleted() ) setSortKey( ePriorityColumn,
"1" + priorityKey );
00137
else setSortKey( ePriorityColumn,
"0" + priorityKey );
00138
00139 setText( eCategoriesColumn, mTodo->categoriesStr() );
00140
00141
#if 0
00142
00143
00144
00145
int pos = mTodo->description().findRev(
'#');
00146
if (pos < 0) {
00147 setText( eDescriptionColumn,
"" );
00148 }
else {
00149
QString str = mTodo->description().mid(pos+1);
00150 str.stripWhiteSpace();
00151 setText( eDescriptionColumn, str );
00152 }
00153
#endif
00154
00155 m_known =
false;
00156 m_init =
false;
00157 }
00158
00159
void KOTodoViewItem::stateChange(
bool state)
00160 {
00161
00162
if ( m_init || !mTodo )
return;
00163
00164 kdDebug(5850) <<
"State changed, modified " << state << endl;
00165
QString keyd =
"9";
00166
00167 Todo*oldTodo = mTodo->clone();
00168
00169
if (state)
00170 mTodoView->
emitCompletedSignal( mTodo );
00171
else mTodo->setPercentComplete(0);
00172
00173
if (mTodo->hasDueDate()) {
00174
QString dtStr = mTodo->dtDueDateStr();
00175
QString keyt =
"";
00176
if (!mTodo->doesFloat()) {
00177 dtStr +=
" " + mTodo->dtDueTimeStr();
00178 }
00179 setText( eDueDateColumn, dtStr );
00180 keyd = mTodo->dtDue().toString(Qt::ISODate);
00181 }
else {
00182 setText( eDueDateColumn,
"" );
00183 }
00184 setSortKey( eDueDateColumn, keyd );
00185
00186
QString priorityKey = QString::number( mTodo->priority() ) + keyd;
00187
if ( mTodo->isCompleted() ) setSortKey( ePriorityColumn,
"1" + priorityKey );
00188
else setSortKey( ePriorityColumn,
"0" + priorityKey );
00189
00190 setText( ePercentColumn, QString::number(mTodo->percentComplete()));
00191
if (mTodo->percentComplete()<100) {
00192
if (mTodo->isCompleted()) setSortKey( ePercentColumn, QString::number(999) );
00193
else setSortKey( ePercentColumn, QString::number(mTodo->percentComplete()) );
00194 }
00195
else {
00196
if (mTodo->isCompleted()) setSortKey( ePercentColumn, QString::number(999) );
00197
else setSortKey( ePercentColumn, QString::number(99) );
00198 }
00199
00200
QListViewItem *myChild = firstChild();
00201
KOTodoViewItem *item;
00202
while( myChild ) {
00203 item = static_cast<KOTodoViewItem*>(myChild);
00204 item->
stateChange(state);
00205 myChild = myChild->nextSibling();
00206 }
00207 mTodoView->
setTodoModified( oldTodo, mTodo );
00208
delete oldTodo;
00209 }
00210
00211
bool KOTodoViewItem::isAlternate()
00212 {
00213
#ifndef KORG_NOLVALTERNATION
00214
KOTodoListView *lv = static_cast<KOTodoListView *>(listView());
00215
if (lv && lv->alternateBackground().isValid())
00216 {
00217
KOTodoViewItem *above = 0;
00218 above = dynamic_cast<KOTodoViewItem *>(itemAbove());
00219 m_known = above ? above->
m_known :
true;
00220
if (m_known)
00221 {
00222 m_odd = above ? !above->
m_odd :
false;
00223 }
00224
else
00225 {
00226
KOTodoViewItem *item;
00227
bool previous =
true;
00228
if (QListViewItem::parent())
00229 {
00230 item = dynamic_cast<KOTodoViewItem *>(QListViewItem::parent());
00231
if (item)
00232 previous = item->
m_odd;
00233 item = dynamic_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild());
00234 }
00235
else
00236 {
00237 item = dynamic_cast<KOTodoViewItem *>(lv->firstChild());
00238 }
00239
00240
while(item)
00241 {
00242 item->
m_odd = previous = !previous;
00243 item->
m_known =
true;
00244 item = dynamic_cast<KOTodoViewItem *>(item->nextSibling());
00245 }
00246 }
00247
return m_odd;
00248 }
00249
return false;
00250
#else
00251
return false;
00252
#endif
00253
}
00254
00255
void KOTodoViewItem::paintCell(
QPainter *p,
const QColorGroup &cg,
int column,
int width,
int alignment)
00256 {
00257
QColorGroup _cg = cg;
00258
00259
if ( !mTodo )
return;
00260
#ifndef KORG_NOLVALTERNATION
00261
if (isAlternate())
00262 _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground());
00263
if (mTodo->hasDueDate()) {
00264
if (mTodo->dtDue().date()==QDate::currentDate() &&
00265 !mTodo->isCompleted()) {
00266 _cg.setColor(QColorGroup::Base, KOPrefs::instance()->mTodoDueTodayColor);
00267 _cg.setColor(QColorGroup::Text, getTextColor(KOPrefs::instance()->mTodoDueTodayColor));
00268 }
00269
if (mTodo->dtDue().date() < QDate::currentDate() &&
00270 !mTodo->isCompleted()) {
00271 _cg.setColor(QColorGroup::Base, KOPrefs::instance()->mTodoOverdueColor);
00272 _cg.setColor(QColorGroup::Text, getTextColor(KOPrefs::instance()->mTodoOverdueColor));
00273 }
00274 }
00275
#endif
00276
00277
00278
if ( column == ePercentColumn ) {
00279 p->save();
00280
int progress = (
int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5);
00281
00282 p->fillRect( 0, 0, width, height(), _cg.base() );
00283 p->setPen( KGlobalSettings::textColor() );
00284 p->setBrush( KGlobalSettings::baseColor() );
00285 p->drawRect( 2, 2, width-4, height()-4);
00286 p->fillRect( 3, 3, progress, height()-6,
00287 KGlobalSettings::highlightColor() );
00288 p->restore();
00289 }
else {
00290 QCheckListItem::paintCell(p, _cg, column, width, alignment);
00291 }
00292 }