summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/pim/todo/mainwindow.cpp4
-rw-r--r--core/pim/todo/todotable.cpp96
-rw-r--r--core/pim/todo/todotable.h39
3 files changed, 84 insertions, 55 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp
index 33f13aa..a34bcf2 100644
--- a/core/pim/todo/mainwindow.cpp
+++ b/core/pim/todo/mainwindow.cpp
@@ -105,17 +105,16 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) :
// qDebug("after load: t=%d", t.elapsed() );
Config config( "todo" );
config.setGroup( "View" );
bool complete = config.readBoolEntry( "ShowComplete", true );
table->setShowCompleted( complete );
- /* added 20.01.2k2 by se */
bool showdeadline = config.readBoolEntry("ShowDeadLine", true);
table->setShowDeadline (showdeadline);
QString category = config.readEntry( "Category", QString::null );
table->setShowCategory( category );
QPEToolBar *bar = new QPEToolBar( this );
bar->setHorizontalStretchable( TRUE );
@@ -176,17 +175,16 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) :
a->setEnabled( FALSE );
//a->setEnabled( FALSE );
findAction = a;
// qDebug("mainwindow #2: t=%d", t.elapsed() );
completedAction = new QAction( QString::null, tr("Completed tasks"), 0, this, 0, TRUE );
- /* added 20.01.2k2 by se */
showdeadlineAction = new QAction( QString::null, tr( "Show Deadline" ), 0, this, 0, TRUE );
catMenu->setCheckable( true );
populateCategories();
mb->insertItem( tr( "Task" ), edit );
mb->insertItem( tr( "View" ), catMenu );
@@ -359,17 +357,17 @@ void TodoWindow::setCategory( int c )
void TodoWindow::populateCategories()
{
catMenu->clear();
completedAction->addTo( catMenu );
completedAction->setOn( table->showCompleted() );
showdeadlineAction->addTo( catMenu );
showdeadlineAction->setOn( table->showDeadline() );
-
+ catMenu->insertSeparator();
int id, rememberId;
id = 1;
catMenu->insertItem( tr( "All Categories" ), id++ );
// catMenu->insertSeparator();
QStringList categories = table->categories();
categories.append( tr( "Unfiled" ) );
for ( QStringList::Iterator it = categories.begin();
it != categories.end(); ++it ) {
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
@@ -155,19 +155,67 @@ void ComboItem::setText( const QString &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 ),
@@ -242,23 +290,23 @@ void TodoTable::slotClicked( int row, int col, int, const QPoint &pos )
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 );
@@ -363,26 +411,24 @@ void TodoTable::load( const QString &fn )
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);
}
@@ -395,17 +441,17 @@ void TodoTable::updateVisible()
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;
}
}
@@ -461,23 +507,23 @@ void TodoTable::clear()
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!!
@@ -492,17 +538,17 @@ void TodoTable::updateJournal( const ToDoEvent &/*todo*/, journal_action action,
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 )
{
@@ -536,51 +582,33 @@ void TodoTable::journalFreeReplaceEntry( const ToDoEvent &todo, int row )
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 )
{
diff --git a/core/pim/todo/todotable.h b/core/pim/todo/todotable.h
index 288ff90..32df514 100644
--- a/core/pim/todo/todotable.h
+++ b/core/pim/todo/todotable.h
@@ -72,16 +72,29 @@ class TodoTextItem : public QTableItem
{
public:
TodoTextItem( QTable *t, const QString & str )
:QTableItem( t, QTableItem::Never, str ) {}
QString key () const { return Qtopia::buildSortKey( text() ); }
};
+class DueTextItem : public QTableItem
+{
+ public:
+ DueTextItem( QTable *t, ToDoEvent *ev );
+ QString key() const;
+ void setToDoEvent( const ToDoEvent *ev );
+ void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected );
+ private:
+ int m_off;
+ bool m_hasDate:1;
+ bool m_completed:1;
+
+};
enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE };
class TodoTable : public QTable
{
Q_OBJECT
@@ -93,17 +106,16 @@ public:
ToDoEvent currentEntry() const;
void replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem = false );
QStringList categories();
void setShowCompleted( bool sc ) { showComp = sc; updateVisible(); }
bool showCompleted() const { return showComp; }
- /* added 20.01.2k2 by se */
void setShowDeadline (bool sd) {showDeadl = sd; updateVisible();}
bool showDeadline() const { return showDeadl;}
void setShowCategory( const QString &c ) { showCat = c; updateVisible(); }
const QString &showCategory() const { return showCat; }
int showCategoryId() const;
bool save( const QString &fn );
@@ -158,73 +170,64 @@ private:
QMap<CheckItem*, ToDoEvent *> todoList;
QStringList categoryList;
bool showComp;
QString showCat;
QTimer *menuTimer;
bool enablePainting;
Categories mCat;
int currFindRow;
-
- /* added 20.01.2k2 by se */
- bool showDeadl;
+ 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 );
- /* added 20.01.2k2 by se */
- QTableItem *dl = NULL;
- if (todo->hasDate()){
- QDate *today = new QDate (QDate::currentDate());
- if (today){
- dl = new TodoTextItem (this, tr ("%1").
- arg(today->daysTo(todo->date())));
- delete (today);
- }
- }else{
- dl = new TodoTextItem (this,"n.d.");
- }
- setItem( row, 3, dl);
+ DueTextItem *due = new DueTextItem(this, todo );
+ setItem( row, 3, due);
setItem( row, 0, chk );
setItem( row, 1, cmb );
setItem( row, 2, ti );
todoList.insert( chk, todo );
}
inline void TodoTable::realignTable( int row )
{
QTableItem *ti1,
*ti2,
- *ti3;
+ *ti3,
+ *ti4;
int totalRows = numRows();
for ( int curr = row; curr < totalRows - 1; curr++ ) {
// this is bad, we must take the item out and then
// set it. In the end, it behaves no worse (time wise)
// then the old way of saving the entries to file, clearing
// the table re-reading in the file and resetting the table
ti1 = item( curr + 1, 0 );
ti2 = item( curr + 1, 1 );
ti3 = item( curr + 1, 2 );
+ ti4 = item( curr + 1, 3 );
takeItem( ti1 );
takeItem( ti2 );
takeItem( ti3 );
+ takeItem( ti4 );
setItem( curr, 0, ti1 );
setItem( curr, 1, ti2 );
setItem( curr, 2, ti3 );
+ setItem( curr, 3, ti4 );
}
setNumRows( totalRows - 1 );
}
#endif