summaryrefslogtreecommitdiff
authorzecke <zecke>2002-04-18 20:43:35 (UTC)
committer zecke <zecke>2002-04-18 20:43:35 (UTC)
commit877e3d4899013687a0a16caefadabf86703bcf27 (patch) (side-by-side diff)
treeb8df1964ea9ea4dc1a1cbb9cab8a2ff84560a11f
parent56c20411484700350362b5041e3c9db030084caf (diff)
downloadopie-877e3d4899013687a0a16caefadabf86703bcf27.zip
opie-877e3d4899013687a0a16caefadabf86703bcf27.tar.gz
opie-877e3d4899013687a0a16caefadabf86703bcf27.tar.bz2
on day change the deadline gets changed
I use QDate and a Timer for that. Does anyone know a better way?
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/todotable.cpp23
-rw-r--r--core/pim/todo/todotable.h3
2 files changed, 26 insertions, 0 deletions
diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp
index 96cd860..d0bc61c 100644
--- a/core/pim/todo/todotable.cpp
+++ b/core/pim/todo/todotable.cpp
@@ -172,56 +172,59 @@ DueTextItem::DueTextItem( QTable *t, ToDoEvent *ev )
QString DueTextItem::key() const
{
QString key;
if( m_hasDate ){
if(m_off == 0 ){
key.append("b");
}else if( m_off > 0 ){
key.append("c");
}else if( m_off < 0 ){
key.append("a");
}
key.append(QString::number(m_off ) );
}else{
key.append("d");
}
return key;
}
void DueTextItem::setToDoEvent( const ToDoEvent *ev )
{
m_hasDate = ev->hasDate();
m_completed = ev->isCompleted();
if( ev->hasDate() ){
QDate today = QDate::currentDate();
m_off = today.daysTo(ev->date() );
+ //qWarning("DueText m_off=%d", m_off );
setText( QString::number(m_off) + " day(s) " );
}else{
setText("n.d." );
m_off = 0;
}
+ //qWarning("m_off=%d", m_off );
}
void DueTextItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected )
{
+ //qWarning ("paint m_off=%d", m_off );
QColorGroup cg2(cg);
QColor text = cg.text();
if( m_hasDate && !m_completed ){
if( m_off < 0 ){
cg2.setColor(QColorGroup::Text, QColor(red ) );
}else if( m_off == 0 ){
cg2.setColor(QColorGroup::Text, QColor(yellow) ); // orange isn't predefined
}else if( m_off > 0){
cg2.setColor(QColorGroup::Text, QColor(green ) );
}
}
QTableItem::paint(p, cg2, cr, selected );
cg2.setColor(QColorGroup::Text, text );
}
TodoTable::TodoTable( QWidget *parent, const char *name )
// #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR
// : QTable( 0, 3, parent, name, TRUE ),
// #else
: QTable( 0, 4, parent, name ),
// #endif
showComp( true ),
enablePainting( true ),
mCat( 0 ),
currFindRow( -2 ),
@@ -240,48 +243,52 @@ TodoTable::TodoTable( QWidget *parent, const char *name )
horizontalHeader()->setLabel( 1, tr( "Prior." ) );
horizontalHeader()->setLabel( 2, tr( "Description" ) );
setColumnStretchable( 3, FALSE );
setColumnWidth( 3, 20 );
horizontalHeader()->setLabel( 3, tr( "Deadline" ) );
if (showDeadl){
showColumn (3);
}else{
hideColumn (3);
}
connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ),
this, SLOT( slotClicked( int, int, int, const QPoint & ) ) );
connect( this, SIGNAL( pressed( int, int, int, const QPoint & ) ),
this, SLOT( slotPressed( int, int, int, const QPoint & ) ) );
connect( this, SIGNAL( valueChanged( int, int ) ),
this, SLOT( slotCheckPriority( int, int ) ) );
connect( this, SIGNAL( currentChanged( int, int ) ),
this, SLOT( slotCurrentChanged( int, int ) ) );
menuTimer = new QTimer( this );
connect( menuTimer, SIGNAL(timeout()), this, SLOT(slotShowMenu()) );
+
+ mDayTimer = new QTimer( this );
+ connect( mDayTimer, SIGNAL(timeout()), this, SLOT(slotCheckDay() ) );
+ mDay = QDate::currentDate();
}
void TodoTable::addEntry( const ToDoEvent &todo )
{
int row = numRows();
setNumRows( row + 1 );
updateJournal( todo, ACTION_ADD );
insertIntoTable( new ToDoEvent(todo), row );
setCurrentCell(row, currentColumn());
updateVisible();
}
void TodoTable::slotClicked( int row, int col, int, const QPoint &pos )
{
if ( !cellGeometry( row, col ).contains(pos) )
return;
// let's switch on the column number...
switch ( col )
{
case 0: {
CheckItem *i = static_cast<CheckItem*>(item( row, col ));
if ( i ) {
int x = pos.x() - columnPos( col );
int y = pos.y() - rowPos( row );
@@ -400,48 +407,49 @@ bool TodoTable::save( const QString &fn )
return false;
};
// now do the rename
if ( ::rename( strNewFile, fn ) < 0 )
qWarning( "problem renaming file %s to %s errno %d",
strNewFile.latin1(), fn.latin1(), errno );
// remove the journal
QFile::remove( journalFileName() );
return true;
}
void TodoTable::load( const QString &fn )
{
if ( QFile::exists(journalFileName()) ) {
applyJournal();
QFile::remove(journalFileName() );
}
loadFile( fn );
// QTable::sortColumn(2,TRUE,TRUE);
// QTable::sortColumn(1,TRUE,TRUE);
QTable::sortColumn(0,TRUE,TRUE);
setCurrentCell( 0, 2 );
setSorting(true );
+ mDayTimer->start( 60 * 1000 ); // gone in 60 seconds?
}
void TodoTable::updateVisible()
{
if ( !isUpdatesEnabled() )
return;
if (showDeadl){
showColumn (3);
adjustColumn(3);
}else{
hideColumn (3);
adjustColumn(2);
}
int visible = 0;
int id = mCat.id( "Todo List", showCat );
for ( int row = 0; row < numRows(); row++ ) {
CheckItem *ci = (CheckItem *)item( row, 0 );
ToDoEvent *t = todoList[ci];
QArray<int> vlCats = t->categories();
bool hide = false;
if ( !showComp && ci->isChecked() )
hide = true;
if ( !showCat.isEmpty() ) {
@@ -760,48 +768,63 @@ void TodoTable::applyJournal()
QString dummy;
while( el ){
dummy = el->attribute("Action" );
action = dummy.toInt(&ok );
ToDoEvent ev = xmlToEvent( el );
if(ok ){
switch( action){
case ACTION_ADD:
tododb.addEvent(ev );
break;
case ACTION_REMOVE:
tododb.removeEvent( ev );
break;
case ACTION_REPLACE:
tododb.replaceEvent( ev );
break;
}
}
el = el->nextChild();
}
QFile::remove(journalFileName()+ "_new" );
tododb.save();
}
}
+void TodoTable::slotCheckDay()
+{
+ QDate date = QDate::currentDate();
+ if( mDay.daysTo(date )!= 0 ){
+ setPaintingEnabled( FALSE );
+ for(int i=0; i < numRows(); i++ ){
+ ToDoEvent *t = todoList[static_cast<CheckItem*>(item(i, 0))];
+ static_cast<DueTextItem*>(item(i, 3) )->setToDoEvent( t );
+
+ }
+ setPaintingEnabled( TRUE );
+ mDay = date;
+ }
+ mDayTimer->start( 60 * 1000 ); // 60 seconds
+}
// check Action and decide
/*
void TodoTable::doApply(XMLElement *el )
{
QString dummy;
bool ok;
int action;
dummy = el->attribute("Action" );
action = dummy.toInt(&ok );
ToDoEvent ev = xmlToEvent( el );
if( ok ){
switch( action ){
case ACTION_ADD:
addEntry( ev );
break;
case ACTION_REMOVE:{ // find an entry with the same uid and remove it then
break;
}
case ACTION_REPLACE:
break;
}
}
}
*/
diff --git a/core/pim/todo/todotable.h b/core/pim/todo/todotable.h
index 6e371e8..458e07a 100644
--- a/core/pim/todo/todotable.h
+++ b/core/pim/todo/todotable.h
@@ -146,57 +146,60 @@ signals:
protected:
void keyPressEvent( QKeyEvent *e );
private:
void updateVisible();
void viewportPaintEvent( QPaintEvent * );
void internalAddEntries( QList<ToDoEvent> &list);
inline void insertIntoTable( ToDoEvent *todo, int row );
void updateJournal( const ToDoEvent &todo, journal_action action);
void mergeJournal();
void journalFreeReplaceEntry( const ToDoEvent &todo, int row );
void journalFreeRemoveEntry( int row );
inline void realignTable( int row );
void loadFile( const QString &strFile);
private slots:
void slotClicked( int row, int col, int button, const QPoint &pos );
void slotPressed( int row, int col, int button, const QPoint &pos );
void slotCheckPriority(int row, int col );
void slotCurrentChanged(int row, int col );
void slotDoFind( const QString &findString, bool caseSensetive,
bool backwards, int category );
void slotShowMenu();
void rowHeightChanged( int row );
+ void slotCheckDay(); // check the day
private:
friend class TodoWindow;
QMap<CheckItem*, ToDoEvent *> todoList;
QStringList categoryList;
bool showComp;
QString showCat;
QTimer *menuTimer;
+ QDate mDay;
+ QTimer *mDayTimer; // see if the day changed
bool enablePainting;
Categories mCat;
int currFindRow;
bool showDeadl:1;
};
inline void TodoTable::insertIntoTable( ToDoEvent *todo, int row )
{
QString sortKey = (char) ((todo->isCompleted() ? 'a' : 'A')
+ todo->priority() )
+ Qtopia::buildSortKey( todo->description() );
CheckItem *chk = new CheckItem( this, sortKey );
chk->setChecked( todo->isCompleted() );
ComboItem *cmb = new ComboItem( this, QTableItem::WhenCurrent );
cmb->setText( QString::number( todo->priority() ) );
QTableItem *ti = new TodoTextItem( this, todo->description().left(40).simplifyWhiteSpace() );
ti->setReplaceable( false );
DueTextItem *due = new DueTextItem(this, todo );
setItem( row, 3, due);
setItem( row, 0, chk );
setItem( row, 1, cmb );