summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/checkbook.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/checkbook/checkbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/checkbook.cpp93
1 files changed, 79 insertions, 14 deletions
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp
index ab25516..09b0b46 100644
--- a/noncore/apps/checkbook/checkbook.cpp
+++ b/noncore/apps/checkbook/checkbook.cpp
@@ -1,10 +1,10 @@
/*
                This file is part of the OPIE Project
=.
-             .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
+             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This file is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
@@ -36,16 +36,16 @@
#include <qpe/qpeapplication.h>
#include <qpe/qpemessagebox.h>
#include <qpe/resource.h>
#include <qcombobox.h>
#include <qfile.h>
+#include <qfontmetrics.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
-#include <qlistview.h>
#include <qmultilineedit.h>
#include <qpushbutton.h>
#include <qwhatsthis.h>
#include <qwidget.h>
Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, char symbol )
@@ -198,18 +198,20 @@ QWidget *Checkbook::initTransactions()
control );
QWhatsThis::add( balanceLabel, tr( "This area shows the current balance in this checkbook." ) );
layout->addMultiCellWidget( balanceLabel, 0, 0, 0, 2 );
tranTable = new QListView( control );
QWhatsThis::add( tranTable, tr( "This is a listing of all transactions entered for this checkbook.\n\nTo sort entries by a specific field, click on the column name." ) );
- tranTable->addColumn( tr( "ID" ) );
+ tranTable->addColumn( tr( "Num" ) );
tranTable->addColumn( tr( "Date" ) );
+ //tranTable->addColumn( tr( "Cleared" ) );
tranTable->addColumn( tr( "Description" ) );
int colnum = tranTable->addColumn( tr( "Amount" ) );
tranTable->setColumnAlignment( colnum, Qt::AlignRight );
tranTable->setAllColumnsShowFocus( TRUE );
+ tranTable->setSorting( 1 );
layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 );
QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold );
connect( tranTable, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ),
this, SLOT( slotEditTran() ) );
QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control );
@@ -311,14 +313,13 @@ void Checkbook::loadCheckbook()
stramount.sprintf( "%c%.2f", currencySymbol, amount );
// Add to transaction list
transactions.inSort( tran );
// Add to transaction table
- ( void ) new QListViewItem( tranTable, QString::number( i ), tran->datestr(),
- trandesc, stramount );
+ ( void ) new CBListItem( tranTable, tran->number(), tran->datestr(), trandesc, stramount );
}
else
{
delete tran;
}
}
@@ -331,17 +332,20 @@ void Checkbook::adjustBalance( float amount )
{
currBalance += amount;
balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) );
}
-TranInfo *Checkbook::findTranByID( int id )
+TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, const QString &desc )
{
TranInfo *traninfo = transactions.first();
- while ( traninfo && traninfo->id() != id )
+ while ( traninfo )
{
+ if ( traninfo->number() == checknum && traninfo->datestr() == date &&
+ traninfo->desc() == desc )
+ break;
traninfo = transactions.next();
}
return( traninfo );
}
void Checkbook::accept()
@@ -415,14 +419,14 @@ void Checkbook::slotNewTran()
stramount.sprintf( "%c%.2f", currencySymbol, amount );
// Add to transaction list
transactions.inSort( traninfo );
// Add to transaction table
- ( void ) new QListViewItem( tranTable, QString::number( highTranNum ),
- traninfo->datestr(), traninfo->desc(), stramount );
+ ( void ) new CBListItem( tranTable, traninfo->number(), traninfo->datestr(), traninfo->desc(),
+ stramount );
adjustBalance( amount );
}
else
{
highTranNum--;
@@ -436,14 +440,13 @@ void Checkbook::slotEditTran()
QListViewItem *curritem = tranTable->currentItem();
if ( !curritem )
{
return;
}
- int tranid = curritem->text( 0 ).toInt( &ok );
- TranInfo *traninfo = findTranByID( tranid );
+ TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) );
float origamt = traninfo->amount();
if ( traninfo->withdrawal() )
{
origamt *= -1;
}
@@ -479,15 +482,13 @@ void Checkbook::slotDeleteTran()
QListViewItem *curritem = tranTable->currentItem();
if ( !curritem )
{
return;
}
- bool ok;
- int tranid = curritem->text( 0 ).toInt( &ok );
- TranInfo *traninfo = findTranByID( tranid );
+ TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) );
if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) )
{
float amount = traninfo->amount();
if ( traninfo->withdrawal() )
{
@@ -591,6 +592,70 @@ void Checkbook::drawCategoryChart( bool withdrawals )
}
}
}
graphInfo = new GraphInfo( GraphInfo::PieChart, list );
}
+
+CBListItem::CBListItem( QListView *parent, QString label1, QString label2,
+ QString label3, QString label4, QString label5, QString label6, QString label7,
+ QString label8 )
+ : QListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 )
+{
+ m_known = FALSE;
+ owner = parent;
+}
+
+void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align )
+{
+ QColorGroup _cg = cg;
+ const QPixmap *pm = listView()->viewport()->backgroundPixmap();
+ if ( pm && !pm->isNull() )
+ {
+ _cg.setBrush( QColorGroup::Base, QBrush( cg.base(), *pm ) );
+ p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
+ }
+ else if ( isAltBackground() )
+ _cg.setColor(QColorGroup::Base, QColor( 200, 255, 200 ) );
+
+ QListViewItem::paintCell(p, _cg, column, width, align);
+}
+
+bool CBListItem::isAltBackground()
+{
+ QListView *lv = static_cast<QListView *>( listView() );
+ if ( lv )
+ {
+ CBListItem *above = 0;
+ above = (CBListItem *)( itemAbove() );
+ m_known = above ? above->m_known : true;
+ if ( m_known )
+ {
+ m_odd = above ? !above->m_odd : false;
+ }
+ else
+ {
+ CBListItem *item;
+ bool previous = true;
+ if ( parent() )
+ {
+ item = (CBListItem *)( parent() );
+ if ( item )
+ previous = item->m_odd;
+ item = (CBListItem *)( parent()->firstChild() );
+ }
+ else
+ {
+ item = (CBListItem *)( lv->firstChild() );
+ }
+
+ while(item)
+ {
+ item->m_odd = previous = !previous;
+ item->m_known = true;
+ item = (CBListItem *)( item->nextSibling() );
+ }
+ }
+ return m_odd;
+ }
+ return false;
+} \ No newline at end of file