summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/checkbook.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/checkbook/checkbook.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/checkbook/checkbook.cpp85
1 files changed, 72 insertions, 13 deletions
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp
index c53e889..a42c824 100644
--- a/noncore/apps/checkbook/checkbook.cpp
+++ b/noncore/apps/checkbook/checkbook.cpp
@@ -46,19 +46,21 @@
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qmultilineedit.h>
#include <qpushbutton.h>
#include <qwhatsthis.h>
+#include <qpopupmenu.h>
#define COL_ID 0
-#define COL_NUM 1
-#define COL_DATE 2
-#define COL_DESC 3
-#define COL_AMOUNT 4
-#define COL_BAL 5
+#define COL_SORTDATE 1
+#define COL_NUM 2
+#define COL_DATE 3
+#define COL_DESC 4
+#define COL_AMOUNT 5
+#define COL_BAL 6
// --- Checkbook --------------------------------------------------------------
Checkbook::Checkbook( QWidget *parent, CBInfo *i, Cfg *cfg )
: QDialog( parent, 0, TRUE, WStyle_ContextHelp )
{
info = i;
@@ -221,12 +223,15 @@ QWidget *Checkbook::initTransactions()
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( "SortDate" ) );
+ tranTable->setColumnWidthMode( COL_SORTDATE, QListView::Manual );
+ tranTable->setColumnWidth( COL_SORTDATE, 0);
tranTable->addColumn( tr( "Num" ) );
tranTable->addColumn( tr( "Date" ) );
//tranTable->addColumn( tr( "Cleared" ) );
tranTable->addColumn( tr( "Description" ) );
int column = tranTable->addColumn( tr( "Amount" ) );
tranTable->setColumnAlignment( column, Qt::AlignRight );
@@ -234,12 +239,14 @@ QWidget *Checkbook::initTransactions()
tranTable->setColumnAlignment( column, 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( slotMenuTran(QListViewItem *, const QPoint &) ) );
+ connect( tranTable, SIGNAL( doubleClicked( QListViewItem * ) ),
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." ) );
@@ -333,13 +340,13 @@ void Checkbook::loadCheckbook()
amount = tran->amount();
if ( tran->withdrawal() )
{
amount *= -1;
}
stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
- ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->number(), tran->datestr(), tran->desc(), stramount );
+ ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->datestr(false), tran->number(), tran->datestr(true), tran->desc(), stramount );
}
// set sort order
bool bOk=false;
for(int i=0; i<_cbSortType->count(); i++) {
if( _cbSortType->text(i)==info->getSortOrder() ) {
@@ -355,12 +362,13 @@ void Checkbook::loadCheckbook()
}
// calc running balance
adjustBalance();
}
+
// --- adjustBalance ----------------------------------------------------------
void Checkbook::adjustBalance()
{
// update running balance in register
QString sRunning;
float bal=info->startingBalance();
@@ -393,12 +401,13 @@ void Checkbook::accept()
info->setStartingBalance( balanceEdit->text().toFloat( &ok ) );
info->setNotes( notesEdit->text() );
QDialog::accept();
}
+// --- slotPasswordClicked ----------------------------------------------------
void Checkbook::slotPasswordClicked()
{
if ( info->password().isNull() && passwordCB->isChecked() )
{
Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) );
if ( pw->exec() != QDialog::Accepted )
@@ -461,19 +470,20 @@ void Checkbook::slotStartingBalanceChanged( const QString &newbalance )
bool ok;
info->setStartingBalance( newbalance.toFloat( &ok ) );
adjustBalance();
}
+// --- slotNewTran ------------------------------------------------------------
void Checkbook::slotNewTran()
{
TranInfo *traninfo = new TranInfo( info->getNextNumber() );
if( !_dLastNew.isNull() )
traninfo->setDate(_dLastNew);
- Transaction *currtran = new Transaction( this, info->name(),
+ Transaction *currtran = new Transaction( this, true, info->name(),
traninfo,
_pCfg );
currtran->showMaximized();
if ( currtran->exec() == QDialog::Accepted )
{
// Add to transaction list
@@ -481,60 +491,107 @@ void Checkbook::slotNewTran()
// Add to transaction table
float amount;
QString stramount;
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(),
+ ( void ) new CBListItem( traninfo, tranTable, traninfo->getIdStr(), traninfo->datestr(false),
+ traninfo->number(), traninfo->datestr(true), traninfo->desc(),
stramount );
resort();
adjustBalance();
// save last date
_dLastNew = traninfo->date();
+
+ // save description in list of payees, if not in there
+ QStringList *pLst=&_pCfg->getPayees();
+ if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) {
+ pLst->append( traninfo->desc() );
+ pLst->sort();
+ _pCfg->setDirty(true);
+ }
}
else
{
delete traninfo;
}
}
+
+// --- slotEditTran -----------------------------------------------------------
void Checkbook::slotEditTran()
{
QListViewItem *curritem = tranTable->currentItem();
if ( !curritem )
return;
TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) );
- Transaction *currtran = new Transaction( this, info->name(),
+ Transaction *currtran = new Transaction( this, false, info->name(),
traninfo,
_pCfg );
currtran->showMaximized();
if ( currtran->exec() == QDialog::Accepted )
{
curritem->setText( COL_NUM, traninfo->number() );
- curritem->setText( COL_DATE, traninfo->datestr() );
+ curritem->setText( COL_SORTDATE, traninfo->datestr(false) );
+ curritem->setText( COL_DATE, traninfo->datestr(true) );
curritem->setText( COL_DESC, traninfo->desc() );
float amount = traninfo->amount();
if ( traninfo->withdrawal() )
{
amount *= -1;
}
QString stramount;
stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
curritem->setText( COL_AMOUNT, stramount );
resort();
adjustBalance();
+
+ // save description in list of payees, if not in there
+ QStringList *pLst=&_pCfg->getPayees();
+ if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) {
+ pLst->append( traninfo->desc() );
+ pLst->sort();
+ _pCfg->setDirty(true);
+ }
}
delete currtran;
}
+// --- slotMenuTran -----------------------------------------------------------
+void Checkbook::slotMenuTran(QListViewItem *item, const QPoint &pnt)
+{
+ // active item?
+ if( !item )
+ return;
+
+ // Display menu
+ QPopupMenu m;
+ m.insertItem( QWidget::tr( "Edit" ), 1 );
+ m.insertItem( QWidget::tr( "New" ), 2 );
+ m.insertItem( QWidget::tr( "Delete" ), 3 );
+ int r = m.exec( pnt );
+ switch(r) {
+ case 1:
+ slotEditTran();
+ break;
+ case 2:
+ slotNewTran();
+ break;
+ case 3:
+ slotDeleteTran();
+ break;
+ }
+}
+
+
+// --- slotDeleteTran ---------------------------------------------------------
void Checkbook::slotDeleteTran()
{
QListViewItem *curritem = tranTable->currentItem();
if ( !curritem )
return;
@@ -588,13 +645,13 @@ void Checkbook::drawBalanceChart()
{
amount *= -1;
}
balance += amount;
if ( i == 1 || i == count / 2 || i == count )
{
- label = tran->datestr();
+ label = tran->datestr(true);
}
else
{
label = "";
}
list->append( new DataPointInfo( label, balance ) );
@@ -663,12 +720,13 @@ void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int
else if ( isAltBackground() )
_cg.setColor(QColorGroup::Base, cg.background() );
QListViewItem::paintCell(p, _cg, column, width, align);
}
+// --- CBListItem::isAltBackground --------------------------------------------
bool CBListItem::isAltBackground()
{
QListView *lv = static_cast<QListView *>( listView() );
if ( lv )
{
CBListItem *above = 0;
@@ -720,11 +778,12 @@ 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;
+ _sortCol=COL_SORTDATE;
}
info->setSortOrder( selc );
resort();
}
+