korganizer Library API Documentation

kotodoviewitem.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #include <klocale.h>
00021 #include <kdebug.h>
00022 
00023 #include "kotodoviewitem.h"
00024 #include "kotodoview.h"
00025 #include "koprefs.h"
00026 
00027 KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo)
00028   : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
00029 {
00030   construct();
00031 }
00032 
00033 KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo )
00034   : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
00035 {
00036   construct();
00037 }
00038 
00039 QString KOTodoViewItem::key(int column,bool) const
00040 {
00041   QMap<int,QString>::ConstIterator it = mKeyMap.find(column);
00042   if (it == mKeyMap.end()) {
00043     return text(column);
00044   } else {
00045     return *it;
00046   }
00047 }
00048 
00049 void KOTodoViewItem::setSortKey(int column,const QString &key)
00050 {
00051   mKeyMap.insert(column,key);
00052 }
00053 
00054 #if QT_VERSION >= 300
00055 void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w,
00056                                    int y,int h)
00057 {
00058   QListViewItem::paintBranches(p,cg,w,y,h);
00059 }
00060 #else
00061 #endif
00062 
00063 void KOTodoViewItem::construct()
00064 {
00065   m_init = true;
00066   QString keyd = "==";
00067   QString keyt = "==";
00068 
00069   setOn(mTodo->isCompleted());
00070   setText(0,mTodo->summary());
00071   setText(1,QString::number(mTodo->priority()));
00072   setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
00073   if (mTodo->percentComplete()<100) {
00074     if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
00075     else setSortKey(2,QString::number(mTodo->percentComplete()));
00076   }
00077   else {
00078     if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
00079     else setSortKey(2,QString::number(99));
00080   }
00081   if (mTodo->hasDueDate()) {
00082     setText(3, mTodo->dtDueDateStr());
00083     QDate d = mTodo->dtDue().date();
00084     keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
00085     setSortKey(3,keyd);
00086     if (mTodo->doesFloat()) {
00087       setText(4,"");
00088     }
00089     else {
00090       setText(4,mTodo->dtDueTimeStr());
00091       QTime t = mTodo->dtDue().time();
00092       keyt.sprintf("%02d%02d",t.hour(),t.minute());
00093       setSortKey(4,keyt);
00094     }
00095   } else {
00096     setText(3,"");
00097     setText(4,"");
00098   }
00099   setSortKey(3,keyd);
00100   setSortKey(4,keyt);
00101 
00102   if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt);
00103   else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
00104 
00105   setText(5,mTodo->categoriesStr());
00106 
00107 #if 0
00108   // Find sort id in description. It's the text behind the last '#' character
00109   // found in the description. White spaces are removed from beginning and end
00110   // of sort id.
00111   int pos = mTodo->description().findRev('#');
00112   if (pos < 0) {
00113     setText(6,"");
00114   } else {
00115     QString str = mTodo->description().mid(pos+1);
00116     str.stripWhiteSpace();
00117     setText(6,str);
00118   }
00119 #endif
00120 
00121   m_known = false;
00122   m_init = false;
00123 }
00124 
00125 void KOTodoViewItem::stateChange(bool state)
00126 {
00127   // do not change setting on startup
00128   if ( m_init ) return;
00129   
00130   kdDebug() << "State changed, modified " << state << endl;
00131   QString keyd = "==";
00132   QString keyt = "==";
00133   
00134   if (state) mTodo->setCompleted(state);
00135   else mTodo->setPercentComplete(0);
00136   if (isOn()!=state) {
00137     setOn(state);
00138   }
00139 
00140   if (mTodo->hasDueDate()) {
00141     setText(3, mTodo->dtDueDateStr());
00142     QDate d = mTodo->dtDue().date();
00143     keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
00144     setSortKey(3,keyd);
00145     if (mTodo->doesFloat()) {
00146       setText(4,"");
00147     }
00148     else {
00149       setText(4,mTodo->dtDueTimeStr());
00150       QTime t = mTodo->dtDue().time();
00151       keyt.sprintf("%02d%02d",t.hour(),t.minute());
00152       setSortKey(4,keyt);
00153     }
00154   }
00155   if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt);
00156   else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
00157   
00158   setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
00159   if (mTodo->percentComplete()<100) {
00160     if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
00161     else setSortKey(2,QString::number(mTodo->percentComplete()));
00162   }
00163   else {
00164     if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
00165     else setSortKey(2,QString::number(99));
00166   }
00167   QListViewItem * myChild = firstChild();
00168   KOTodoViewItem *item;
00169   while( myChild ) {
00170     item = static_cast<KOTodoViewItem*>(myChild);
00171     item->stateChange(state);
00172     myChild = myChild->nextSibling();
00173   }
00174 
00175   mTodoView->modified(true);
00176   mTodoView->setTodoModifiedDelayed( mTodo );
00177 }
00178 
00179 bool KOTodoViewItem::isAlternate()
00180 {
00181   KOTodoListView *lv = static_cast<KOTodoListView *>(listView());
00182   if (lv && lv->alternateBackground().isValid())
00183   {
00184     KOTodoViewItem *above = 0;
00185     above = dynamic_cast<KOTodoViewItem *>(itemAbove());
00186     m_known = above ? above->m_known : true;
00187     if (m_known)
00188     {
00189        m_odd = above ? !above->m_odd : false;
00190     }
00191     else
00192     {
00193        KOTodoViewItem *item;
00194        bool previous = true;
00195        if (QListViewItem::parent())
00196        {
00197           item = dynamic_cast<KOTodoViewItem *>(QListViewItem::parent());
00198           if (item)
00199              previous = item->m_odd;
00200           item = dynamic_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild());
00201        }
00202        else
00203        {
00204           item = dynamic_cast<KOTodoViewItem *>(lv->firstChild());
00205        }
00206 
00207        while(item)
00208        {
00209           item->m_odd = previous = !previous;
00210           item->m_known = true;
00211           item = dynamic_cast<KOTodoViewItem *>(item->nextSibling());
00212        }
00213     }
00214     return m_odd;
00215   }
00216   return false;
00217 }
00218 
00219 void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
00220 {
00221   QColorGroup _cg = cg;
00222   if (isAlternate())
00223         _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground());
00224   if (mTodo->hasDueDate()) {
00225     if (mTodo->dtDue().date()==QDate::currentDate() &&
00226         !mTodo->isCompleted()) {
00227       _cg.setColor(QColorGroup::Base, KOPrefs::instance()->mTodoDueTodayColor);    
00228     }
00229     if (mTodo->dtDue().date() < QDate::currentDate() &&
00230         !mTodo->isCompleted()) {
00231       _cg.setColor(QColorGroup::Base, KOPrefs::instance()->mTodoOverdueColor);
00232     }
00233   }
00234   
00235   QCheckListItem::paintCell(p, _cg, column, width, alignment);
00236 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:32 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001