summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/checkbook.cpp
Unidiff
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,16 +1,16 @@
1/* 1/*
2                This file is part of the OPIE Project 2                This file is part of the OPIE Project
3 =. 3 =.
4             .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> 4             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org>
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can 6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public 8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License, 10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version. 11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that 13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
@@ -30,28 +30,28 @@
30#include "transaction.h" 30#include "transaction.h"
31#include "graph.h" 31#include "graph.h"
32#include "graphinfo.h" 32#include "graphinfo.h"
33 33
34#include <opie/otabwidget.h> 34#include <opie/otabwidget.h>
35#include <qpe/config.h> 35#include <qpe/config.h>
36#include <qpe/qpeapplication.h> 36#include <qpe/qpeapplication.h>
37#include <qpe/qpemessagebox.h> 37#include <qpe/qpemessagebox.h>
38#include <qpe/resource.h> 38#include <qpe/resource.h>
39 39
40#include <qcombobox.h> 40#include <qcombobox.h>
41#include <qfile.h> 41#include <qfile.h>
42#include <qfontmetrics.h>
42#include <qlabel.h> 43#include <qlabel.h>
43#include <qlayout.h> 44#include <qlayout.h>
44#include <qlineedit.h> 45#include <qlineedit.h>
45#include <qlistview.h>
46#include <qmultilineedit.h> 46#include <qmultilineedit.h>
47#include <qpushbutton.h> 47#include <qpushbutton.h>
48#include <qwhatsthis.h> 48#include <qwhatsthis.h>
49#include <qwidget.h> 49#include <qwidget.h>
50 50
51Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, char symbol ) 51Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, char symbol )
52 : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) 52 : QDialog( parent, 0, TRUE, WStyle_ContextHelp )
53{ 53{
54 name = n; 54 name = n;
55 filename = fd; 55 filename = fd;
56 filename.append( name ); 56 filename.append( name );
57 filename.append( ".qcb" ); 57 filename.append( ".qcb" );
@@ -192,30 +192,32 @@ QWidget *Checkbook::initTransactions()
192 192
193 QGridLayout *layout = new QGridLayout( control ); 193 QGridLayout *layout = new QGridLayout( control );
194 layout->setSpacing( 2 ); 194 layout->setSpacing( 2 );
195 layout->setMargin( 4 ); 195 layout->setMargin( 4 );
196 196
197 balanceLabel = new QLabel( tr( "Current balance: %10.00" ).arg( currencySymbol ), 197 balanceLabel = new QLabel( tr( "Current balance: %10.00" ).arg( currencySymbol ),
198 control ); 198 control );
199 QWhatsThis::add( balanceLabel, tr( "This area shows the current balance in this checkbook." ) ); 199 QWhatsThis::add( balanceLabel, tr( "This area shows the current balance in this checkbook." ) );
200 layout->addMultiCellWidget( balanceLabel, 0, 0, 0, 2 ); 200 layout->addMultiCellWidget( balanceLabel, 0, 0, 0, 2 );
201 201
202 tranTable = new QListView( control ); 202 tranTable = new QListView( control );
203 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." ) ); 203 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." ) );
204 tranTable->addColumn( tr( "ID" ) ); 204 tranTable->addColumn( tr( "Num" ) );
205 tranTable->addColumn( tr( "Date" ) ); 205 tranTable->addColumn( tr( "Date" ) );
206 //tranTable->addColumn( tr( "Cleared" ) );
206 tranTable->addColumn( tr( "Description" ) ); 207 tranTable->addColumn( tr( "Description" ) );
207 int colnum = tranTable->addColumn( tr( "Amount" ) ); 208 int colnum = tranTable->addColumn( tr( "Amount" ) );
208 tranTable->setColumnAlignment( colnum, Qt::AlignRight ); 209 tranTable->setColumnAlignment( colnum, Qt::AlignRight );
209 tranTable->setAllColumnsShowFocus( TRUE ); 210 tranTable->setAllColumnsShowFocus( TRUE );
211 tranTable->setSorting( 1 );
210 layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 ); 212 layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 );
211 QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold ); 213 QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold );
212 connect( tranTable, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ), 214 connect( tranTable, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ),
213 this, SLOT( slotEditTran() ) ); 215 this, SLOT( slotEditTran() ) );
214 216
215 QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control ); 217 QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control );
216 QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) ); 218 QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) );
217 connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) ); 219 connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) );
218 layout->addWidget( btn, 2, 0 ); 220 layout->addWidget( btn, 2, 0 );
219 221
220 btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), control ); 222 btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), control );
221 QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) ); 223 QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) );
@@ -305,49 +307,51 @@ void Checkbook::loadCheckbook()
305 amount = tran->amount(); 307 amount = tran->amount();
306 if ( tran->withdrawal() ) 308 if ( tran->withdrawal() )
307 { 309 {
308 amount *= -1; 310 amount *= -1;
309 } 311 }
310 currBalance += amount; 312 currBalance += amount;
311 stramount.sprintf( "%c%.2f", currencySymbol, amount ); 313 stramount.sprintf( "%c%.2f", currencySymbol, amount );
312 314
313 // Add to transaction list 315 // Add to transaction list
314 transactions.inSort( tran ); 316 transactions.inSort( tran );
315 317
316 // Add to transaction table 318 // Add to transaction table
317 ( void ) new QListViewItem( tranTable, QString::number( i ), tran->datestr(), 319 ( void ) new CBListItem( tranTable, tran->number(), tran->datestr(), trandesc, stramount );
318 trandesc, stramount );
319 } 320 }
320 else 321 else
321 { 322 {
322 delete tran; 323 delete tran;
323 } 324 }
324 } 325 }
325 balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); 326 balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) );
326 327
327 highTranNum = transactions.count(); 328 highTranNum = transactions.count();
328} 329}
329 330
330void Checkbook::adjustBalance( float amount ) 331void Checkbook::adjustBalance( float amount )
331{ 332{
332 currBalance += amount; 333 currBalance += amount;
333 balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); 334 balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) );
334 335
335} 336}
336 337
337TranInfo *Checkbook::findTranByID( int id ) 338TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, const QString &desc )
338{ 339{
339 TranInfo *traninfo = transactions.first(); 340 TranInfo *traninfo = transactions.first();
340 while ( traninfo && traninfo->id() != id ) 341 while ( traninfo )
341 { 342 {
343 if ( traninfo->number() == checknum && traninfo->datestr() == date &&
344 traninfo->desc() == desc )
345 break;
342 traninfo = transactions.next(); 346 traninfo = transactions.next();
343 } 347 }
344 return( traninfo ); 348 return( traninfo );
345} 349}
346 350
347void Checkbook::accept() 351void Checkbook::accept()
348{ 352{
349 QFile f( filename ); 353 QFile f( filename );
350 if ( f.exists() ) 354 if ( f.exists() )
351 { 355 {
352 f.remove(); 356 f.remove();
353 } 357 }
@@ -409,47 +413,46 @@ void Checkbook::slotNewTran()
409 float amount = traninfo->amount(); 413 float amount = traninfo->amount();
410 if ( traninfo->withdrawal() ) 414 if ( traninfo->withdrawal() )
411 { 415 {
412 amount *= -1; 416 amount *= -1;
413 } 417 }
414 QString stramount; 418 QString stramount;
415 stramount.sprintf( "%c%.2f", currencySymbol, amount ); 419 stramount.sprintf( "%c%.2f", currencySymbol, amount );
416 420
417 // Add to transaction list 421 // Add to transaction list
418 transactions.inSort( traninfo ); 422 transactions.inSort( traninfo );
419 423
420 // Add to transaction table 424 // Add to transaction table
421 ( void ) new QListViewItem( tranTable, QString::number( highTranNum ), 425 ( void ) new CBListItem( tranTable, traninfo->number(), traninfo->datestr(), traninfo->desc(),
422 traninfo->datestr(), traninfo->desc(), stramount ); 426 stramount );
423 427
424 adjustBalance( amount ); 428 adjustBalance( amount );
425 } 429 }
426 else 430 else
427 { 431 {
428 highTranNum--; 432 highTranNum--;
429 delete traninfo; 433 delete traninfo;
430 } 434 }
431} 435}
432 436
433void Checkbook::slotEditTran() 437void Checkbook::slotEditTran()
434{ 438{
435 bool ok; 439 bool ok;
436 QListViewItem *curritem = tranTable->currentItem(); 440 QListViewItem *curritem = tranTable->currentItem();
437 if ( !curritem ) 441 if ( !curritem )
438 { 442 {
439 return; 443 return;
440 } 444 }
441 445
442 int tranid = curritem->text( 0 ).toInt( &ok ); 446 TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) );
443 TranInfo *traninfo = findTranByID( tranid );
444 float origamt = traninfo->amount(); 447 float origamt = traninfo->amount();
445 if ( traninfo->withdrawal() ) 448 if ( traninfo->withdrawal() )
446 { 449 {
447 origamt *= -1; 450 origamt *= -1;
448 } 451 }
449 452
450 Transaction *currtran = new Transaction( this, name, 453 Transaction *currtran = new Transaction( this, name,
451 traninfo, 454 traninfo,
452 currencySymbol ); 455 currencySymbol );
453 currtran->showMaximized(); 456 currtran->showMaximized();
454 if ( currtran->exec() == QDialog::Accepted ) 457 if ( currtran->exec() == QDialog::Accepted )
455 { 458 {
@@ -473,27 +476,25 @@ void Checkbook::slotEditTran()
473 delete currtran; 476 delete currtran;
474 } 477 }
475} 478}
476 479
477void Checkbook::slotDeleteTran() 480void Checkbook::slotDeleteTran()
478{ 481{
479 QListViewItem *curritem = tranTable->currentItem(); 482 QListViewItem *curritem = tranTable->currentItem();
480 if ( !curritem ) 483 if ( !curritem )
481 { 484 {
482 return; 485 return;
483 } 486 }
484 487
485 bool ok; 488 TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) );
486 int tranid = curritem->text( 0 ).toInt( &ok );
487 TranInfo *traninfo = findTranByID( tranid );
488 489
489 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) ) 490 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) )
490 { 491 {
491 float amount = traninfo->amount(); 492 float amount = traninfo->amount();
492 if ( traninfo->withdrawal() ) 493 if ( traninfo->withdrawal() )
493 { 494 {
494 amount *= -1; 495 amount *= -1;
495 } 496 }
496 497
497 transactions.remove( traninfo ); 498 transactions.remove( traninfo );
498 delete traninfo; 499 delete traninfo;
499 delete curritem; 500 delete curritem;
@@ -585,12 +586,76 @@ void Checkbook::drawCategoryChart( bool withdrawals )
585 { // Found category, add to transaction to category total 586 { // Found category, add to transaction to category total
586 cat->addToValue( tran->amount() ); 587 cat->addToValue( tran->amount() );
587 } 588 }
588 else 589 else
589 { // Didn't find category, add category to list 590 { // Didn't find category, add category to list
590 list->append( new DataPointInfo( tran->category(), tran->amount() ) ); 591 list->append( new DataPointInfo( tran->category(), tran->amount() ) );
591 } 592 }
592 } 593 }
593 } 594 }
594 595
595 graphInfo = new GraphInfo( GraphInfo::PieChart, list ); 596 graphInfo = new GraphInfo( GraphInfo::PieChart, list );
596} 597}
598
599CBListItem::CBListItem( QListView *parent, QString label1, QString label2,
600 QString label3, QString label4, QString label5, QString label6, QString label7,
601 QString label8 )
602 : QListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 )
603{
604 m_known = FALSE;
605 owner = parent;
606}
607
608void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align )
609{
610 QColorGroup _cg = cg;
611 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
612 if ( pm && !pm->isNull() )
613 {
614 _cg.setBrush( QColorGroup::Base, QBrush( cg.base(), *pm ) );
615 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
616 }
617 else if ( isAltBackground() )
618 _cg.setColor(QColorGroup::Base, QColor( 200, 255, 200 ) );
619
620 QListViewItem::paintCell(p, _cg, column, width, align);
621}
622
623bool CBListItem::isAltBackground()
624{
625 QListView *lv = static_cast<QListView *>( listView() );
626 if ( lv )
627 {
628 CBListItem *above = 0;
629 above = (CBListItem *)( itemAbove() );
630 m_known = above ? above->m_known : true;
631 if ( m_known )
632 {
633 m_odd = above ? !above->m_odd : false;
634 }
635 else
636 {
637 CBListItem *item;
638 bool previous = true;
639 if ( parent() )
640 {
641 item = (CBListItem *)( parent() );
642 if ( item )
643 previous = item->m_odd;
644 item = (CBListItem *)( parent()->firstChild() );
645 }
646 else
647 {
648 item = (CBListItem *)( lv->firstChild() );
649 }
650
651 while(item)
652 {
653 item->m_odd = previous = !previous;
654 item->m_known = true;
655 item = (CBListItem *)( item->nextSibling() );
656 }
657 }
658 return m_odd;
659 }
660 return false;
661} \ No newline at end of file