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 @@ -35,2 +35,4 @@ #include "password.h" +#include "mainwindow.h" +#include "cfg.h" @@ -50,3 +52,11 @@ -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 ) @@ -54,4 +64,5 @@ Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol ) info = i; - currencySymbol = symbol; + _pCfg=cfg; + // Title bar if ( info->name() != "" ) @@ -68,2 +79,3 @@ Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol ) + // Setup layout to make everything pretty @@ -76,3 +88,2 @@ Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol ) layout->addWidget( mainWidget ); - mainWidget->addTab( initInfo(), "checkbook/infotab", tr( "Info" ) ); @@ -80,3 +91,7 @@ Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol ) 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 *) ) ); @@ -90,5 +105,6 @@ Checkbook::~Checkbook() +// --- initInfo --------------------------------------------------------------- QWidget *Checkbook::initInfo() { - QWidget *control = new QWidget( mainWidget ); + QWidget *control = new QWidget( mainWidget, tr("Info") ); @@ -130,8 +146,3 @@ QWidget *Checkbook::initInfo() 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 ); @@ -185,5 +196,7 @@ QWidget *Checkbook::initInfo() + +// --- initTransactions ------------------------------------------------------- QWidget *Checkbook::initTransactions() { - QWidget *control = new QWidget( mainWidget ); + QWidget *control = new QWidget( mainWidget, tr("Transactions") ); @@ -193,9 +206,22 @@ QWidget *Checkbook::initTransactions() - 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" ) ); @@ -204,6 +230,8 @@ QWidget *Checkbook::initTransactions() 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 ); @@ -212,3 +240,5 @@ QWidget *Checkbook::initTransactions() this, SLOT( slotEditTran() ) ); + _sortCol=COL_ID; + // Buttons QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control ); @@ -231,2 +261,4 @@ QWidget *Checkbook::initTransactions() + +// --- initCharts ------------------------------------------------------------- QWidget *Checkbook::initCharts() @@ -235,3 +267,3 @@ QWidget *Checkbook::initCharts() - QWidget *control = new QWidget( mainWidget ); + QWidget *control = new QWidget( mainWidget, tr("Charts") ); @@ -261,2 +293,3 @@ QWidget *Checkbook::initCharts() +// --- loadCheckbook ---------------------------------------------------------- void Checkbook::loadCheckbook() @@ -283,2 +316,6 @@ void Checkbook::loadCheckbook() } + if( i<=0 ) { + typeList->insertItem( temptext, 0 ); + typeList->setCurrentItem(0); + } bankEdit->setText( info->bank() ); @@ -293,3 +330,2 @@ void Checkbook::loadCheckbook() QString stramount; - for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) @@ -301,29 +337,49 @@ void Checkbook::loadCheckbook() } - 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() @@ -400,2 +456,4 @@ void Checkbook::slotNameChanged( const QString &newname ) + +// ---slotStartingBalanceChanged ---------------------------------------------- void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) @@ -407,6 +465,8 @@ void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) + void Checkbook::slotNewTran() { - highTranNum++; - TranInfo *traninfo = new TranInfo( highTranNum ); + TranInfo *traninfo = new TranInfo( info->getNextNumber() ); + if( !_dLastNew.isNull() ) + traninfo->setDate(_dLastNew); @@ -414,3 +474,3 @@ void Checkbook::slotNewTran() traninfo, - currencySymbol ); + _pCfg ); currtran->showMaximized(); @@ -424,14 +484,12 @@ void Checkbook::slotNewTran() 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(); } @@ -439,3 +497,2 @@ void Checkbook::slotNewTran() { - highTranNum--; delete traninfo; @@ -448,8 +505,5 @@ void Checkbook::slotEditTran() if ( !curritem ) - { return; - } - TranInfo *traninfo = info->findTransaction( curritem->text( 0 ), curritem->text( 1 ), - curritem->text( 2 ) ); + TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) ); @@ -457,3 +511,3 @@ void Checkbook::slotEditTran() traninfo, - currencySymbol ); + _pCfg ); currtran->showMaximized(); @@ -461,5 +515,5 @@ void Checkbook::slotEditTran() { - 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() ); @@ -471,5 +525,5 @@ void Checkbook::slotEditTran() 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(); @@ -484,7 +538,5 @@ void Checkbook::slotDeleteTran() if ( !curritem ) - { return; - } - TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) ); + TranInfo *traninfo = info->findTransaction( curritem->text(COL_ID) ); @@ -591,3 +643,3 @@ void Checkbook::drawCategoryChart( bool withdrawals ) -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, @@ -596,2 +648,3 @@ CBListItem::CBListItem( QListView *parent, QString label1, QString label2, { + _pTran=pTran; m_known = FALSE; @@ -654 +707,24 @@ bool CBListItem::isAltBackground() } + + +// --- 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(); +} |