summaryrefslogtreecommitdiff
path: root/core/pim/todo/todotable.cpp
Side-by-side diff
Diffstat (limited to 'core/pim/todo/todotable.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/todotable.cpp98
1 files changed, 63 insertions, 35 deletions
diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp
index 3cd0c0e..2acd03c 100644
--- a/core/pim/todo/todotable.cpp
+++ b/core/pim/todo/todotable.cpp
@@ -139,51 +139,99 @@ void ComboItem::setContentFromEditor( QWidget *w )
TodoTable *parent = static_cast<TodoTable*>(table());
ToDoEvent newTodo = parent->currentEntry();
if ( w->inherits( "QComboBox" ) )
setText( ( (QComboBox*)w )->currentText() );
else
QTableItem::setContentFromEditor( w );
newTodo.setPriority( text().toInt() );
parent->replaceCurrentEntry( newTodo, true );
}
void ComboItem::setText( const QString &s )
{
if ( cb )
cb->setCurrentItem( s.toInt() - 1 );
QTableItem::setText( s );
}
QString ComboItem::text() const
{
if ( cb )
return cb->currentText();
return QTableItem::text();
}
-
-
-
+DueTextItem::DueTextItem( QTable *t, ToDoEvent *ev )
+ : QTableItem(t, Never, QString::null )
+{
+ setToDoEvent( 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() );
+ setText( QString::number(m_off) + " day(s) " );
+ }else{
+ setText("n.d." );
+ m_off = 0;
+ }
+}
+void DueTextItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected )
+{
+ 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 ),
showDeadl( true)
{
mCat.load( categoryFileName() );
setSorting( TRUE );
setSelectionMode( NoSelection );
setColumnStretchable( 2, TRUE );
setColumnWidth( 0, 20 );
setColumnWidth( 1, 35 );
setLeftMargin( 0 );
verticalHeader()->hide();
horizontalHeader()->setLabel( 0, tr( "C." ) );
horizontalHeader()->setLabel( 1, tr( "Prior." ) );
horizontalHeader()->setLabel( 2, tr( "Description" ) );
@@ -226,55 +274,55 @@ 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 );
int w = columnWidth( col );
int h = rowHeight( row );
if ( i && x >= ( w - BoxSize ) / 2 && x <= ( w - BoxSize ) / 2 + BoxSize &&
y >= ( h - BoxSize ) / 2 && y <= ( h - BoxSize ) / 2 + BoxSize ) {
i->toggle();
}
emit signalDoneChanged( i->isChecked() );
}
}
break;
case 1:
break;
case 2:
// may as well edit it...
- menuTimer->stop();
+ // menuTimer->stop();
// emit signalEdit();
- break;
- case 3: /* added 20.01.2k2 by se */
+ // fall through
+ case 3:
// may as well edit it...
menuTimer->stop();
- emit signalEdit();
+ // emit signalEdit();
break;
}
}
void TodoTable::slotPressed( int row, int col, int, const QPoint &pos )
{
if ( col == 2 && cellGeometry( row, col ).contains(pos) )
menuTimer->start( 750, TRUE );
}
void TodoTable::slotShowMenu()
{
emit signalShowMenu( QCursor::pos() );
}
void TodoTable::slotCurrentChanged( int, int )
{
menuTimer->stop();
}
void TodoTable::internalAddEntries( QList<ToDoEvent> &list )
{
setNumRows( list.count() );
int row = 0;
@@ -347,81 +395,79 @@ bool TodoTable::save( const QString &fn )
QFile::remove( strNewFile );
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 )
{
loadFile( fn, false );
if ( QFile::exists(journalFileName()) ) {
loadFile( journalFileName(), true );
save( fn );
}
// QTable::sortColumn(2,TRUE,TRUE);
// QTable::sortColumn(1,TRUE,TRUE);
QTable::sortColumn(0,TRUE,TRUE);
setCurrentCell( 0, 2 );
+ setSorting(true );
}
void TodoTable::updateVisible()
{
if ( !isUpdatesEnabled() )
return;
-
-// qDebug("--> updateVisible!");
-
- /* added 20.01.2k2 by se */
+
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() ) {
if ( showCat == tr( "Unfiled" ) ) {
if ( vlCats.count() > 0 )
hide = true;
} else {
- // do some comparing, we have to reverse our idea here...
+ // do some comparing, we have to reverse our idea here... which idea - zecke
if ( !hide ) {
hide = true;
for ( uint it = 0; it < vlCats.count(); ++it ) {
if ( vlCats[it] == id ) {
hide = false;
break;
}
}
}
}
}
if ( hide ) {
if ( currentRow() == row )
setCurrentCell( -1, 0 );
if ( rowHeight( row ) > 0 )
hideRow( row );
} else {
if ( rowHeight( row ) == 0 ) {
showRow( row );
adjustRow( row );
}
visible++;
}
}
@@ -445,158 +491,140 @@ void TodoTable::setPaintingEnabled( bool e )
} else {
enablePainting = false;
}
}
}
void TodoTable::clear()
{
for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin();
it != todoList.end(); ++it ) {
ToDoEvent *todo = *it;
delete todo;
}
todoList.clear();
for ( int r = 0; r < numRows(); ++r ) {
for ( int c = 0; c < numCols(); ++c ) {
if ( cellWidget( r, c ) )
clearCellWidget( r, c );
clearCell( r, c );
}
}
setNumRows( 0 );
}
-void TodoTable::sortColumn( int col, bool /*ascending*/, bool /*wholeRows*/ )
+void TodoTable::sortColumn( int col, bool ascending, bool /*wholeRows*/ )
{
// The default for wholeRows is false, however
// for this todo table we want to exchange complete
// rows when sorting. Also, we always want ascending, since
// the values have a logical order.
- QTable::sortColumn( col, TRUE, TRUE );
+ QTable::sortColumn( col, ascending, TRUE );
updateVisible();
}
void TodoTable::slotCheckPriority(int row, int col )
{
// kludgey work around to make forward along the updated priority...
if ( col == 1 ) {
// let everyone know!!
ComboItem* i = static_cast<ComboItem*>( item( row, col ) );
emit signalPriorityChanged( i->text().toInt() );
}
}
void TodoTable::updateJournal( const ToDoEvent &/*todo*/, journal_action action, int row )
{
QFile f( journalFileName() );
if ( !f.open(IO_WriteOnly|IO_Append) )
return;
QString buf;
QCString str;
buf = "<Task";
// todo.save( buf );
buf += " Action=\"" + QString::number( int(action) ) + "\"";
- buf += " Row=\"" + QString::number( row ) + "\"";
+ buf += " Row=\"" + QString::number( row ) + "\""; // better write the id
buf += "/>\n";
str = buf.utf8();
f.writeBlock( str.data(), str.length() );
f.close();
}
void TodoTable::rowHeightChanged( int row )
{
if ( enablePainting )
QTable::rowHeightChanged( row );
}
void TodoTable::loadFile( const QString &strFile, bool fromJournal )
{
QList<ToDoEvent> list;
ToDoDB todoDB;
QValueList<ToDoEvent> vaList = todoDB.rawToDos();
for(QValueList<ToDoEvent>::ConstIterator it = vaList.begin(); it != vaList.end(); ++it ){
list.append( new ToDoEvent( (*it) ) );
}
vaList.clear();
// qDebug("parsing done=%d", t.elapsed() );
if ( list.count() > 0 ) {
internalAddEntries( list );
list.clear();
}
// qDebug("loading done: t=%d", t.elapsed() );
}
void TodoTable::journalFreeReplaceEntry( const ToDoEvent &todo, int row )
{
QString strTodo;
strTodo = todo.description().left(40).simplifyWhiteSpace();
if ( row == -1 ) {
QMapIterator<CheckItem*, ToDoEvent *> it;
for ( it = todoList.begin(); it != todoList.end(); ++it ) {
if ( *(*it) == todo ) {
row = it.key()->row();
it.key()->setChecked( todo.isCompleted() );
static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) );
item( row, 2 )->setText( strTodo );
- /* added 20.01.2k2 by se */
if (showDeadl){
- if (todo.hasDate()){
- QDate *today = new QDate (QDate::currentDate());
- if (today){
- item (row, 3)->setText (tr ("%1").arg(today->daysTo(todo.date())));
- delete (today);
- }
- }else{
- item (row, 3)->setText ("n.d.");
- }
+ static_cast<DueTextItem*>(item(row,3))->setToDoEvent(&todo );
}
*(*it) = todo;
}
}
} else {
ToDoEvent *t = todoList[static_cast<CheckItem*>(item(row, 0))];
todoList.remove( static_cast<CheckItem*>(item(row, 0)) );
delete t;
static_cast<CheckItem*>(item(row, 0))->setChecked( todo.isCompleted() );
static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) );
item( row, 2 )->setText( strTodo );
- /* added 20.01.2k2 by se */
if (showDeadl){
- if (todo.hasDate()){
- QDate *today = new QDate (QDate::currentDate());
- if (today){
- item (row, 3)->setText (tr ("%1").arg(today->daysTo(todo.date())));
- delete (today);
- }
- }else{
- item (row, 3)->setText ("n.d.");
- }
+ static_cast<DueTextItem*>(item(row,3))->setToDoEvent(&todo );
}
todoList.insert( static_cast<CheckItem*>(item(row,0)), new ToDoEvent(todo) );
}
}
void TodoTable::journalFreeRemoveEntry( int row )
{
CheckItem *chk;
chk = static_cast<CheckItem*>(item(row, 0 ));
if ( !chk )
return;
todoList.remove( chk );
realignTable( row );
}
void TodoTable::keyPressEvent( QKeyEvent *e )
{
if ( e->key() == Key_Space || e->key() == Key_Return ) {
switch ( currentColumn() ) {
case 0: {
CheckItem *i = static_cast<CheckItem*>(item(currentRow(),
currentColumn()));