author | mickeyl <mickeyl> | 2003-10-27 19:51:32 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-10-27 19:51:32 (UTC) |
commit | 951d1d4125a80dc814f95d2956853bf53ca52e9a (patch) (side-by-side diff) | |
tree | 46c7a70b80a7eebb54cd59c46204c28335f3821c /noncore/apps/checkbook/checkbook.cpp | |
parent | f0a15a9866f9eddfe10596e63a1e6300b92b9e3f (diff) | |
download | opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.zip opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.tar.gz opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.tar.bz2 |
merge noncore/apps/* except
- advancedfm (ljp, please...)
- odict (tille, please...)
Diffstat (limited to 'noncore/apps/checkbook/checkbook.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/checkbook.cpp | 206 |
1 files changed, 141 insertions, 65 deletions
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp index 653ee4a..c53e889 100644 --- a/noncore/apps/checkbook/checkbook.cpp +++ b/noncore/apps/checkbook/checkbook.cpp @@ -24,82 +24,98 @@ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "checkbook.h" #include "cbinfo.h" #include "transaction.h" #include "traninfo.h" #include "graph.h" #include "graphinfo.h" #include "password.h" +#include "mainwindow.h" +#include "cfg.h" #include <opie/otabwidget.h> #include <qpe/qpeapplication.h> #include <qpe/qpemessagebox.h> #include <qpe/resource.h> #include <qcheckbox.h> #include <qcombobox.h> #include <qlabel.h> #include <qlayout.h> #include <qlineedit.h> #include <qmultilineedit.h> #include <qpushbutton.h> #include <qwhatsthis.h> -Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol ) +#define COL_ID 0 +#define COL_NUM 1 +#define COL_DATE 2 +#define COL_DESC 3 +#define COL_AMOUNT 4 +#define COL_BAL 5 + +// --- Checkbook -------------------------------------------------------------- +Checkbook::Checkbook( QWidget *parent, CBInfo *i, Cfg *cfg ) : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) { info = i; - currencySymbol = symbol; + _pCfg=cfg; + // Title bar if ( info->name() != "" ) { QString tempstr = info->name(); tempstr.append( " - " ); tempstr.append( tr( "Checkbook" ) ); setCaption( tempstr ); } else { setCaption( tr( "New checkbook" ) ); } + // Setup layout to make everything pretty QVBoxLayout *layout = new QVBoxLayout( this ); layout->setMargin( 2 ); layout->setSpacing( 4 ); // Setup tabs for all info mainWidget = new OTabWidget( this ); layout->addWidget( mainWidget ); - mainWidget->addTab( initInfo(), "checkbook/infotab", tr( "Info" ) ); mainWidget->addTab( initTransactions(), "checkbook/trantab", tr( "Transactions" ) ); mainWidget->addTab( initCharts(), "checkbook/charttab", tr( "Charts" ) ); + if( _pCfg->isShowLastTab() ) + mainWidget->setCurrentTab( info->getLastTab() ); + else mainWidget->setCurrentTab( tr( "Info" ) ); + connect( mainWidget, SIGNAL( currentChanged(QWidget *) ), this, SLOT( slotTab(QWidget *) ) ); // Load checkbook information loadCheckbook(); } Checkbook::~Checkbook() { } +// --- initInfo --------------------------------------------------------------- QWidget *Checkbook::initInfo() { - QWidget *control = new QWidget( mainWidget ); + QWidget *control = new QWidget( mainWidget, tr("Info") ); QVBoxLayout *vb = new QVBoxLayout( control ); QScrollView *sv = new QScrollView( control ); vb->addWidget( sv, 0, 0 ); sv->setResizePolicy( QScrollView::AutoOneFit ); sv->setFrameStyle( QFrame::NoFrame ); QWidget *container = new QWidget( sv->viewport() ); sv->addChild( container ); QGridLayout *layout = new QGridLayout( container ); @@ -119,30 +135,25 @@ QWidget *Checkbook::initInfo() nameEdit = new QLineEdit( container ); QWhatsThis::add( nameEdit, tr( "Enter name of checkbook here." ) ); connect( nameEdit, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotNameChanged( const QString & ) ) ); layout->addWidget( nameEdit, 1, 1 ); // Type of account label = new QLabel( tr( "Type:" ), container ); QWhatsThis::add( label, tr( "Select type of checkbook here." ) ); layout->addWidget( label, 2, 0 ); typeList = new QComboBox( container ); QWhatsThis::add( typeList, tr( "Select type of checkbook here." ) ); - typeList->insertItem( tr( "Savings" ) ); // 0 - typeList->insertItem( tr( "Checking" ) ); // 1 - typeList->insertItem( tr( "CD" ) ); // 2 - typeList->insertItem( tr( "Money market" ) ); // 3 - typeList->insertItem( tr( "Mutual fund" ) ); // 4 - typeList->insertItem( tr( "Other" ) ); // 5 + typeList->insertStringList( _pCfg->getAccountTypes() ); layout->addWidget( typeList, 2, 1 ); // Bank/institution name label = new QLabel( tr( "Bank:" ), container ); QWhatsThis::add( label, tr( "Enter name of the bank for this checkbook here." ) ); layout->addWidget( label, 3, 0 ); bankEdit = new QLineEdit( container ); QWhatsThis::add( bankEdit, tr( "Enter name of the bank for this checkbook here." ) ); layout->addWidget( bankEdit, 3, 1 ); // Account number label = new QLabel( tr( "Account number:" ), container ); @@ -174,75 +185,96 @@ QWidget *Checkbook::initInfo() label = new QLabel( tr( "Notes:" ), container ); QWhatsThis::add( label, tr( "Enter any additional information for this checkbook here." ) ); layout->addWidget( label, 7, 0 ); notesEdit = new QMultiLineEdit( container ); QWhatsThis::add( notesEdit, tr( "Enter any additional information for this checkbook here." ) ); notesEdit->setMinimumHeight( 25 ); notesEdit->setMaximumHeight( 65 ); layout->addMultiCellWidget( notesEdit, 8, 8, 0, 1 ); return control; } + +// --- initTransactions ------------------------------------------------------- QWidget *Checkbook::initTransactions() { - QWidget *control = new QWidget( mainWidget ); + QWidget *control = new QWidget( mainWidget, tr("Transactions") ); QGridLayout *layout = new QGridLayout( control ); layout->setSpacing( 2 ); layout->setMargin( 4 ); - balanceLabel = new QLabel( tr( "Current balance: %10.00" ).arg( currencySymbol ), - control ); - QWhatsThis::add( balanceLabel, tr( "This area shows the current balance in this checkbook." ) ); - layout->addMultiCellWidget( balanceLabel, 0, 0, 0, 2 ); - + // Sort selector + QLabel *label = new QLabel( tr( "Sort by:" ), control ); + QWhatsThis::add( label, tr( "Select checkbook sorting here." ) ); + layout->addMultiCellWidget( label, 0, 0, 0, 1 ); + _cbSortType=new QComboBox( control ); + _cbSortType->insertItem( tr("Entry Order") ); + _cbSortType->insertItem( tr("Date") ); + _cbSortType->insertItem( tr("Number") ); + layout->addMultiCellWidget( _cbSortType, 0, 0, 1, 2 ); + connect( _cbSortType, SIGNAL( activated(const QString &) ), this, SLOT( slotSortChanged( const QString & ) ) ); + + // Table tranTable = new QListView( control ); + QFont fnt(QPEApplication::font()); + fnt.setPointSize( fnt.pointSize()-1 ); + tranTable->setFont( fnt ); 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->setColumnWidthMode( COL_ID, QListView::Manual ); + tranTable->setColumnWidth( COL_ID, 0); 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 ); + int column = tranTable->addColumn( tr( "Amount" ) ); + tranTable->setColumnAlignment( column, Qt::AlignRight ); + column=tranTable->addColumn( tr("Balance") ); + tranTable->setColumnAlignment( column, Qt::AlignRight ); tranTable->setAllColumnsShowFocus( TRUE ); - tranTable->setSorting( 1 ); + 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() ) ); + _sortCol=COL_ID; + // Buttons QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control ); QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) ); layout->addWidget( btn, 2, 0 ); btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), control ); QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotEditTran() ) ); layout->addWidget( btn, 2, 1 ); btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), control ); QWhatsThis::add( btn, tr( "Select a checkbook and then click here to delete it." ) ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotDeleteTran() ) ); layout->addWidget( btn, 2, 2 ); return( control ); } + +// --- initCharts ------------------------------------------------------------- QWidget *Checkbook::initCharts() { graphInfo = 0x0; - QWidget *control = new QWidget( mainWidget ); + QWidget *control = new QWidget( mainWidget, tr("Charts") ); QGridLayout *layout = new QGridLayout( control ); layout->setSpacing( 2 ); layout->setMargin( 4 ); graphWidget = new Graph( control ); QWhatsThis::add( graphWidget, tr( "Select the desired chart below and then click on the Draw button." ) ); layout->addMultiCellWidget( graphWidget, 0, 0, 0, 2 ); graphList = new QComboBox( control ); QWhatsThis::add( graphList, tr( "Click here to select the desired chart type." ) ); graphList->insertItem( tr( "Account balance" ) ); @@ -250,91 +282,115 @@ QWidget *Checkbook::initCharts() graphList->insertItem( tr( "Deposits by category" ) ); layout->addMultiCellWidget( graphList, 1, 1, 0, 1 ); QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control ); QWhatsThis::add( btn, tr( "Click here to draw the selected chart." ) ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) ); layout->addWidget( btn, 1, 2 ); return control; } +// --- loadCheckbook ---------------------------------------------------------- void Checkbook::loadCheckbook() { if ( !info ) { return; } tranList = info->transactions(); passwordCB->setChecked( !info->password().isNull() ); nameEdit->setText( info->name() ); QString temptext = info->type(); int i = typeList->count(); while ( i > 0 ) { i--; typeList->setCurrentItem( i ); if ( typeList->currentText() == temptext ) { break; } } + if( i<=0 ) { + typeList->insertItem( temptext, 0 ); + typeList->setCurrentItem(0); + } bankEdit->setText( info->bank() ); acctNumEdit->setText( info->account() ); pinNumEdit->setText( info->pin() ); temptext.setNum( info->startingBalance(), 'f', 2 ); balanceEdit->setText( temptext ); notesEdit->setText( info->notes() ); // Load transactions float amount; QString stramount; - for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) { amount = tran->amount(); if ( tran->withdrawal() ) { amount *= -1; } - stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); - ( void ) new CBListItem( tranTable, tran->number(), tran->datestr(), tran->desc(), stramount ); + stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); + ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->number(), tran->datestr(), tran->desc(), stramount ); } - balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) ); + // set sort order + bool bOk=false; + for(int i=0; i<_cbSortType->count(); i++) { + if( _cbSortType->text(i)==info->getSortOrder() ) { + _cbSortType->setCurrentItem(i); + slotSortChanged( info->getSortOrder() ); + bOk=true; + break; + } + } + if( !bOk ) { + _cbSortType->setCurrentItem(0); + slotSortChanged( _cbSortType->currentText() ); + } - highTranNum = tranList->count(); + // calc running balance + adjustBalance(); } +// --- adjustBalance ---------------------------------------------------------- void Checkbook::adjustBalance() { - balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) ); + // update running balance in register + QString sRunning; + float bal=info->startingBalance(); + for(CBListItem *item=(CBListItem *)tranTable->firstChild(); item; item=(CBListItem *)item->nextSibling() ) { + TranInfo *tran=item->getTranInfo(); + bal=bal + (tran->withdrawal() ? -1 : 1)*tran->amount() - tran->fee(); + sRunning.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), bal ); + item->setText( COL_BAL, sRunning); + } } -TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, const QString &desc ) -{ - TranInfo *traninfo = tranList->first(); - while ( traninfo ) +// --- resort ----------------------------------------------------------------- +void Checkbook::resort() { - if ( traninfo->number() == checknum && traninfo->datestr() == date && - traninfo->desc() == desc ) - break; - traninfo = tranList->next(); - } - return( traninfo ); + tranTable->setSorting(_sortCol); + tranTable->sort(); + tranTable->setSorting(-1); } + +// --- accept ----------------------------------------------------------------- void Checkbook::accept() { info->setName( nameEdit->text() ); info->setType( typeList->currentText() ); info->setBank( bankEdit->text() ); info->setAccount( acctNumEdit->text() ); info->setPin( pinNumEdit->text() ); bool ok; info->setStartingBalance( balanceEdit->text().toFloat( &ok ) ); info->setNotes( notesEdit->text() ); QDialog::accept(); @@ -389,113 +445,109 @@ void Checkbook::slotNameChanged( const QString &newname ) // TODO - need filedir // QString namestr = filedir; // namestr.append( newname ); // namestr.append( ".qcb" ); // info->setFilename( namestr ); QString namestr = newname; namestr.append( " - " ); namestr.append( tr( "Checkbook" ) ); setCaption( namestr ); } + +// ---slotStartingBalanceChanged ---------------------------------------------- void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) { bool ok; info->setStartingBalance( newbalance.toFloat( &ok ) ); adjustBalance(); } + void Checkbook::slotNewTran() { - highTranNum++; - TranInfo *traninfo = new TranInfo( highTranNum ); + TranInfo *traninfo = new TranInfo( info->getNextNumber() ); + if( !_dLastNew.isNull() ) + traninfo->setDate(_dLastNew); Transaction *currtran = new Transaction( this, info->name(), traninfo, - currencySymbol ); + _pCfg ); currtran->showMaximized(); if ( currtran->exec() == QDialog::Accepted ) { // Add to transaction list info->addTransaction( traninfo ); // Add to transaction table float amount; QString stramount; - - amount = traninfo->amount(); - if ( traninfo->withdrawal() ) - { - amount *= -1; - } - stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); - - ( void ) new CBListItem( tranTable, traninfo->number(), traninfo->datestr(), traninfo->desc(), + amount = (traninfo->withdrawal() ? -1 : 1)*traninfo->amount(); + stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); + ( void ) new CBListItem( traninfo, tranTable, traninfo->getIdStr(), + traninfo->number(), traninfo->datestr(), traninfo->desc(), stramount ); - + resort(); adjustBalance(); + + // save last date + _dLastNew = traninfo->date(); } else { - highTranNum--; delete traninfo; } } void Checkbook::slotEditTran() { QListViewItem *curritem = tranTable->currentItem(); if ( !curritem ) - { return; - } - TranInfo *traninfo = info->findTransaction( curritem->text( 0 ), curritem->text( 1 ), - curritem->text( 2 ) ); + TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) ); Transaction *currtran = new Transaction( this, info->name(), traninfo, - currencySymbol ); + _pCfg ); currtran->showMaximized(); if ( currtran->exec() == QDialog::Accepted ) { - curritem->setText( 0, traninfo->number() ); - curritem->setText( 1, traninfo->datestr() ); - curritem->setText( 2, traninfo->desc() ); + curritem->setText( COL_NUM, traninfo->number() ); + curritem->setText( COL_DATE, traninfo->datestr() ); + curritem->setText( COL_DESC, traninfo->desc() ); float amount = traninfo->amount(); if ( traninfo->withdrawal() ) { amount *= -1; } QString stramount; - stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); - curritem->setText( 3, stramount ); - + stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); + curritem->setText( COL_AMOUNT, stramount ); + resort(); adjustBalance(); } delete currtran; } void Checkbook::slotDeleteTran() { QListViewItem *curritem = tranTable->currentItem(); if ( !curritem ) - { return; - } - TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) ); + TranInfo *traninfo = info->findTransaction( curritem->text(COL_ID) ); if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) ) { info->removeTransaction( traninfo ); delete curritem; adjustBalance(); } } void Checkbook::slotDrawGraph() { if ( graphInfo ) @@ -580,29 +632,30 @@ void Checkbook::drawCategoryChart( bool withdrawals ) cat->addToValue( tran->amount() ); } else { // Didn't find category, add category to list list->append( new DataPointInfo( tran->category(), tran->amount() ) ); } } } graphInfo = new GraphInfo( GraphInfo::PieChart, list ); } -CBListItem::CBListItem( QListView *parent, QString label1, QString label2, +CBListItem::CBListItem( TranInfo *pTran, 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 ) { + _pTran=pTran; 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() ); @@ -643,12 +696,35 @@ bool CBListItem::isAltBackground() while(item) { item->m_odd = previous = !previous; item->m_known = true; item = (CBListItem *)( item->nextSibling() ); } } return m_odd; } return false; } + + +// --- slotTab ---------------------------------------------------------------- +void Checkbook::slotTab(QWidget *tab) +{ + if( !tab || !info ) return; + info->setLastTab( tab->name() ); +} + + +// --- slotSortChanged --------------------------------------------------------- +void Checkbook::slotSortChanged( const QString &selc ) +{ + if( selc==tr("Entry Order") ) { + _sortCol=COL_ID; + } else if( selc==tr("Number") ) { + _sortCol=COL_NUM; + } else if( selc==tr("Date") ) { + _sortCol=COL_DATE; + } + info->setSortOrder( selc ); + resort(); +} |