27 #include "kotodoviewitem.h"
28 #include "kotodoview.h"
30 #include "koglobals.h"
32 #include <libkcal/incidenceformatter.h>
34 #include <tdelocale.h>
36 #include <tqpainter.h>
39 #include <tqpainter.h>
42 : TQCheckListItem( parent ,
"", CheckBox ), mTodo( todo ), mTodoView( kotodo )
48 : TQCheckListItem( parent,
"", CheckBox ), mTodo( todo ), mTodoView( kotodo )
53 inline int KOTodoViewItem::compareDueDates(
const KOTodoViewItem *b )
const
55 if ( mEffectiveDueDate.isValid() &&
56 !b->mEffectiveDueDate.isValid() )
58 else if ( !mEffectiveDueDate.isValid() &&
59 b->mEffectiveDueDate.isValid() )
62 return b->mEffectiveDueDate.secsTo( mEffectiveDueDate );
65 int KOTodoViewItem::compare( TQListViewItem *it,
int col,
bool ascending )
const
69 return TQListViewItem::compare( it, col, ascending );
74 return ascending ? 1 : -1;
76 return ascending ? -1 : 1;
81 case KOTodoView::eSummaryColumn:
82 return mTodo->
summary().localeAwareCompare( i->todo()->
summary() );
84 case KOTodoView::eRecurColumn:
87 case KOTodoView::ePriorityColumn:
92 return compareDueDates( i );
95 case KOTodoView::ePercentColumn:
98 case KOTodoView::eDueDateColumn:
99 c = compareDueDates( i );
105 case KOTodoView::eCategoriesColumn:
108 case KOTodoView::eFolderColumn:
109 return TQListViewItem::compare( it, col, ascending );
112 case KOTodoView::eDescriptionColumn:
117 Q_ASSERT(
false &&
"unknown column to compare" );
118 return TQListViewItem::compare( it, col, ascending );
122 void KOTodoViewItem::paintBranches(TQPainter *p,
const TQColorGroup & cg,
int w,
125 TQListViewItem::paintBranches(p,cg,w,y,h);
128 void KOTodoViewItem::construct()
130 if ( !mTodo )
return;
134 setText( KOTodoView::eSummaryColumn, mTodo->
summary());
135 static const TQPixmap recurPxmp = KOGlobals::self()->smallIcon(
"recur");
137 setPixmap( KOTodoView::eRecurColumn, recurPxmp );
140 setText( KOTodoView::ePriorityColumn, i18n(
"--") );
142 setText( KOTodoView::ePriorityColumn, TQString::number(mTodo->
priority()) );
144 setText( KOTodoView::ePercentColumn, TQString::number(mTodo->
percentComplete()) );
151 setText( KOTodoView::eDueDateColumn, dtStr );
152 mEffectiveDueDate = mTodo->
dtDue();
155 if ( !myParent->mEffectiveDueDate.isValid() ||
156 myParent->mEffectiveDueDate > mEffectiveDueDate ) {
157 myParent->mEffectiveDueDate = mEffectiveDueDate;
160 setText( KOTodoView::eDueDateColumn,
"" );
162 setText( KOTodoView::eCategoriesColumn, mTodo->
categoriesStr() );
164 setText( KOTodoView::eFolderColumn,
165 IncidenceFormatter::resourceString( mTodoView->
calendar(), mTodo ) );
173 setText( KOTodoView::eDescriptionColumn,
"" );
176 str.stripWhiteSpace();
177 setText( KOTodoView::eDescriptionColumn, str );
185 void KOTodoViewItem::stateChange(
bool state )
188 if ( m_init || !mTodo )
return;
195 kdDebug(5850) <<
"State changed, modified " << state << endl;
196 mTodoView->setNewPercentageDelayed(
this, state ? 100 : 0 );
199 bool KOTodoViewItem::isAlternate()
201 #ifndef KORG_NOLVALTERNATION
202 KOTodoListView *lv =
static_cast<KOTodoListView *
>(listView());
203 if (lv && lv->alternateBackground().isValid())
207 m_known = above ? above->m_known :
true;
210 m_odd = above ? !above->m_odd :
false;
215 bool previous =
true;
216 if (TQListViewItem::parent())
220 previous = item->m_odd;
221 item =
dynamic_cast<KOTodoViewItem *
>(TQListViewItem::parent()->firstChild());
230 item->m_odd = previous = !previous;
231 item->m_known =
true;
243 void KOTodoViewItem::paintCell(TQPainter *p,
const TQColorGroup &cg,
int column,
int width,
int alignment)
245 TQColorGroup _cg = cg;
247 if ( !mTodo )
return;
248 #ifndef KORG_NOLVALTERNATION
250 _cg.setColor(TQColorGroup::Base,
static_cast< KOTodoListView*
>(listView())->alternateBackground());
252 if (mTodo->
dtDue().date()==TQDate::currentDate() &&
254 _cg.setColor(TQColorGroup::Base, KOPrefs::instance()->mTodoDueTodayColor);
255 _cg.setColor(TQColorGroup::Text, getTextColor(KOPrefs::instance()->mTodoDueTodayColor));
257 if (mTodo->
dtDue().date() < TQDate::currentDate() &&
259 _cg.setColor(TQColorGroup::Base, KOPrefs::instance()->mTodoOverdueColor);
260 _cg.setColor(TQColorGroup::Text, getTextColor(KOPrefs::instance()->mTodoOverdueColor));
266 if ( column == KOTodoView::ePercentColumn ) {
268 int progress = (int)(( (width-6)*mTodo->
percentComplete())/100.0 + 0.5);
270 p->fillRect( 0, 0, width, height(), _cg.base() );
271 p->setPen( TDEGlobalSettings::textColor() );
272 p->setBrush( TDEGlobalSettings::baseColor() );
273 p->drawRect( 2, 2, width-4, height()-4);
274 p->fillRect( 3, 3, progress, height()-6,
275 TDEGlobalSettings::highlightColor() );
278 TQCheckListItem::paintCell(p, _cg, column, width, alignment);
TQString description() const
TQString categoriesStr() const
TDE_DEPRECATED TQString dtDueTimeStr() const
TDE_DEPRECATED TQString dtDueDateStr(bool shortfmt=true) const
int percentComplete() const
TQDateTime dtDue(bool first=false) const
This class provides a way of displaying a single Event of Todo-Type in a KTodoView.
KOTodoViewItem(TQListView *parent, Todo *todo, KOTodoView *kotodo)
Constructor.
This class provides a multi-column list view of todo events.
virtual Calendar * calendar()
Return calendar object of this view.