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.cpp91
1 files changed, 75 insertions, 16 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
@@ -28,55 +28,57 @@
28 28
29#include "checkbook.h" 29#include "checkbook.h"
30#include "cbinfo.h" 30#include "cbinfo.h"
31#include "transaction.h" 31#include "transaction.h"
32#include "traninfo.h" 32#include "traninfo.h"
33#include "graph.h" 33#include "graph.h"
34#include "graphinfo.h" 34#include "graphinfo.h"
35#include "password.h" 35#include "password.h"
36#include "mainwindow.h" 36#include "mainwindow.h"
37#include "cfg.h" 37#include "cfg.h"
38 38
39#include <opie/otabwidget.h> 39#include <opie/otabwidget.h>
40#include <qpe/qpeapplication.h> 40#include <qpe/qpeapplication.h>
41#include <qpe/qpemessagebox.h> 41#include <qpe/qpemessagebox.h>
42#include <qpe/resource.h> 42#include <qpe/resource.h>
43 43
44#include <qcheckbox.h> 44#include <qcheckbox.h>
45#include <qcombobox.h> 45#include <qcombobox.h>
46#include <qlabel.h> 46#include <qlabel.h>
47#include <qlayout.h> 47#include <qlayout.h>
48#include <qlineedit.h> 48#include <qlineedit.h>
49#include <qmultilineedit.h> 49#include <qmultilineedit.h>
50#include <qpushbutton.h> 50#include <qpushbutton.h>
51#include <qwhatsthis.h> 51#include <qwhatsthis.h>
52#include <qpopupmenu.h>
52 53
53#define COL_ID 0 54#define COL_ID 0
54#define COL_NUM 1 55#define COL_SORTDATE 1
55#define COL_DATE 2 56#define COL_NUM 2
56#define COL_DESC 3 57#define COL_DATE 3
57#define COL_AMOUNT 4 58#define COL_DESC 4
58#define COL_BAL 5 59#define COL_AMOUNT 5
60#define COL_BAL 6
59 61
60// --- Checkbook -------------------------------------------------------------- 62// --- Checkbook --------------------------------------------------------------
61Checkbook::Checkbook( QWidget *parent, CBInfo *i, Cfg *cfg ) 63Checkbook::Checkbook( QWidget *parent, CBInfo *i, Cfg *cfg )
62 : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) 64 : QDialog( parent, 0, TRUE, WStyle_ContextHelp )
63{ 65{
64 info = i; 66 info = i;
65 _pCfg=cfg; 67 _pCfg=cfg;
66 68
67 // Title bar 69 // Title bar
68 if ( info->name() != "" ) 70 if ( info->name() != "" )
69 { 71 {
70 QString tempstr = info->name(); 72 QString tempstr = info->name();
71 tempstr.append( " - " ); 73 tempstr.append( " - " );
72 tempstr.append( tr( "Checkbook" ) ); 74 tempstr.append( tr( "Checkbook" ) );
73 setCaption( tempstr ); 75 setCaption( tempstr );
74 } 76 }
75 else 77 else
76 { 78 {
77 setCaption( tr( "New checkbook" ) ); 79 setCaption( tr( "New checkbook" ) );
78 } 80 }
79 81
80 82
81 // Setup layout to make everything pretty 83 // Setup layout to make everything pretty
82 QVBoxLayout *layout = new QVBoxLayout( this ); 84 QVBoxLayout *layout = new QVBoxLayout( this );
@@ -203,62 +205,67 @@ QWidget *Checkbook::initTransactions()
203 QGridLayout *layout = new QGridLayout( control ); 205 QGridLayout *layout = new QGridLayout( control );
204 layout->setSpacing( 2 ); 206 layout->setSpacing( 2 );
205 layout->setMargin( 4 ); 207 layout->setMargin( 4 );
206 208
207 // Sort selector 209 // Sort selector
208 QLabel *label = new QLabel( tr( "Sort by:" ), control ); 210 QLabel *label = new QLabel( tr( "Sort by:" ), control );
209 QWhatsThis::add( label, tr( "Select checkbook sorting here." ) ); 211 QWhatsThis::add( label, tr( "Select checkbook sorting here." ) );
210 layout->addMultiCellWidget( label, 0, 0, 0, 1 ); 212 layout->addMultiCellWidget( label, 0, 0, 0, 1 );
211 _cbSortType=new QComboBox( control ); 213 _cbSortType=new QComboBox( control );
212 _cbSortType->insertItem( tr("Entry Order") ); 214 _cbSortType->insertItem( tr("Entry Order") );
213 _cbSortType->insertItem( tr("Date") ); 215 _cbSortType->insertItem( tr("Date") );
214 _cbSortType->insertItem( tr("Number") ); 216 _cbSortType->insertItem( tr("Number") );
215 layout->addMultiCellWidget( _cbSortType, 0, 0, 1, 2 ); 217 layout->addMultiCellWidget( _cbSortType, 0, 0, 1, 2 );
216 connect( _cbSortType, SIGNAL( activated(const QString &) ), this, SLOT( slotSortChanged( const QString & ) ) ); 218 connect( _cbSortType, SIGNAL( activated(const QString &) ), this, SLOT( slotSortChanged( const QString & ) ) );
217 219
218 // Table 220 // Table
219 tranTable = new QListView( control ); 221 tranTable = new QListView( control );
220 QFont fnt(QPEApplication::font()); 222 QFont fnt(QPEApplication::font());
221 fnt.setPointSize( fnt.pointSize()-1 ); 223 fnt.setPointSize( fnt.pointSize()-1 );
222 tranTable->setFont( fnt ); 224 tranTable->setFont( fnt );
223 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." ) ); 225 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." ) );
224 tranTable->addColumn( tr( "Id" ) ); 226 tranTable->addColumn( tr( "Id" ) );
225 tranTable->setColumnWidthMode( COL_ID, QListView::Manual ); 227 tranTable->setColumnWidthMode( COL_ID, QListView::Manual );
226 tranTable->setColumnWidth( COL_ID, 0); 228 tranTable->setColumnWidth( COL_ID, 0);
229 tranTable->addColumn( tr( "SortDate" ) );
230 tranTable->setColumnWidthMode( COL_SORTDATE, QListView::Manual );
231 tranTable->setColumnWidth( COL_SORTDATE, 0);
227 tranTable->addColumn( tr( "Num" ) ); 232 tranTable->addColumn( tr( "Num" ) );
228 tranTable->addColumn( tr( "Date" ) ); 233 tranTable->addColumn( tr( "Date" ) );
229 //tranTable->addColumn( tr( "Cleared" ) ); 234 //tranTable->addColumn( tr( "Cleared" ) );
230 tranTable->addColumn( tr( "Description" ) ); 235 tranTable->addColumn( tr( "Description" ) );
231 int column = tranTable->addColumn( tr( "Amount" ) ); 236 int column = tranTable->addColumn( tr( "Amount" ) );
232 tranTable->setColumnAlignment( column, Qt::AlignRight ); 237 tranTable->setColumnAlignment( column, Qt::AlignRight );
233 column=tranTable->addColumn( tr("Balance") ); 238 column=tranTable->addColumn( tr("Balance") );
234 tranTable->setColumnAlignment( column, Qt::AlignRight ); 239 tranTable->setColumnAlignment( column, Qt::AlignRight );
235 tranTable->setAllColumnsShowFocus( TRUE ); 240 tranTable->setAllColumnsShowFocus( TRUE );
236 tranTable->setSorting( -1 ); 241 tranTable->setSorting( -1 );
237 layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 ); 242 layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 );
238 QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold ); 243 QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold );
239 connect( tranTable, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ), 244 connect( tranTable, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ),
240 this, SLOT( slotEditTran() ) ); 245 this, SLOT( slotMenuTran(QListViewItem *, const QPoint &) ) );
246 connect( tranTable, SIGNAL( doubleClicked( QListViewItem * ) ),
247 this, SLOT( slotEditTran() ) );
241 _sortCol=COL_ID; 248 _sortCol=COL_ID;
242 249
243 // Buttons 250 // Buttons
244 QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control ); 251 QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control );
245 QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) ); 252 QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) );
246 connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) ); 253 connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) );
247 layout->addWidget( btn, 2, 0 ); 254 layout->addWidget( btn, 2, 0 );
248 255
249 btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), control ); 256 btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), control );
250 QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) ); 257 QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) );
251 connect( btn, SIGNAL( clicked() ), this, SLOT( slotEditTran() ) ); 258 connect( btn, SIGNAL( clicked() ), this, SLOT( slotEditTran() ) );
252 layout->addWidget( btn, 2, 1 ); 259 layout->addWidget( btn, 2, 1 );
253 260
254 btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), control ); 261 btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), control );
255 QWhatsThis::add( btn, tr( "Select a checkbook and then click here to delete it." ) ); 262 QWhatsThis::add( btn, tr( "Select a checkbook and then click here to delete it." ) );
256 connect( btn, SIGNAL( clicked() ), this, SLOT( slotDeleteTran() ) ); 263 connect( btn, SIGNAL( clicked() ), this, SLOT( slotDeleteTran() ) );
257 layout->addWidget( btn, 2, 2 ); 264 layout->addWidget( btn, 2, 2 );
258 265
259 return( control ); 266 return( control );
260} 267}
261 268
262 269
263// --- initCharts ------------------------------------------------------------- 270// --- initCharts -------------------------------------------------------------
264QWidget *Checkbook::initCharts() 271QWidget *Checkbook::initCharts()
@@ -315,108 +322,110 @@ void Checkbook::loadCheckbook()
315 } 322 }
316 } 323 }
317 if( i<=0 ) { 324 if( i<=0 ) {
318 typeList->insertItem( temptext, 0 ); 325 typeList->insertItem( temptext, 0 );
319 typeList->setCurrentItem(0); 326 typeList->setCurrentItem(0);
320 } 327 }
321 bankEdit->setText( info->bank() ); 328 bankEdit->setText( info->bank() );
322 acctNumEdit->setText( info->account() ); 329 acctNumEdit->setText( info->account() );
323 pinNumEdit->setText( info->pin() ); 330 pinNumEdit->setText( info->pin() );
324 temptext.setNum( info->startingBalance(), 'f', 2 ); 331 temptext.setNum( info->startingBalance(), 'f', 2 );
325 balanceEdit->setText( temptext ); 332 balanceEdit->setText( temptext );
326 notesEdit->setText( info->notes() ); 333 notesEdit->setText( info->notes() );
327 334
328 // Load transactions 335 // Load transactions
329 float amount; 336 float amount;
330 QString stramount; 337 QString stramount;
331 for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) 338 for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() )
332 { 339 {
333 amount = tran->amount(); 340 amount = tran->amount();
334 if ( tran->withdrawal() ) 341 if ( tran->withdrawal() )
335 { 342 {
336 amount *= -1; 343 amount *= -1;
337 } 344 }
338 stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); 345 stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
339 ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->number(), tran->datestr(), tran->desc(), stramount ); 346 ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->datestr(false), tran->number(), tran->datestr(true), tran->desc(), stramount );
340 } 347 }
341 348
342 // set sort order 349 // set sort order
343 bool bOk=false; 350 bool bOk=false;
344 for(int i=0; i<_cbSortType->count(); i++) { 351 for(int i=0; i<_cbSortType->count(); i++) {
345 if( _cbSortType->text(i)==info->getSortOrder() ) { 352 if( _cbSortType->text(i)==info->getSortOrder() ) {
346 _cbSortType->setCurrentItem(i); 353 _cbSortType->setCurrentItem(i);
347 slotSortChanged( info->getSortOrder() ); 354 slotSortChanged( info->getSortOrder() );
348 bOk=true; 355 bOk=true;
349 break; 356 break;
350 } 357 }
351 } 358 }
352 if( !bOk ) { 359 if( !bOk ) {
353 _cbSortType->setCurrentItem(0); 360 _cbSortType->setCurrentItem(0);
354 slotSortChanged( _cbSortType->currentText() ); 361 slotSortChanged( _cbSortType->currentText() );
355 } 362 }
356 363
357 // calc running balance 364 // calc running balance
358 adjustBalance(); 365 adjustBalance();
359} 366}
360 367
368
361// --- adjustBalance ---------------------------------------------------------- 369// --- adjustBalance ----------------------------------------------------------
362void Checkbook::adjustBalance() 370void Checkbook::adjustBalance()
363{ 371{
364 // update running balance in register 372 // update running balance in register
365 QString sRunning; 373 QString sRunning;
366 float bal=info->startingBalance(); 374 float bal=info->startingBalance();
367 for(CBListItem *item=(CBListItem *)tranTable->firstChild(); item; item=(CBListItem *)item->nextSibling() ) { 375 for(CBListItem *item=(CBListItem *)tranTable->firstChild(); item; item=(CBListItem *)item->nextSibling() ) {
368 TranInfo *tran=item->getTranInfo(); 376 TranInfo *tran=item->getTranInfo();
369 bal=bal + (tran->withdrawal() ? -1 : 1)*tran->amount() - tran->fee(); 377 bal=bal + (tran->withdrawal() ? -1 : 1)*tran->amount() - tran->fee();
370 sRunning.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), bal ); 378 sRunning.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), bal );
371 item->setText( COL_BAL, sRunning); 379 item->setText( COL_BAL, sRunning);
372 } 380 }
373} 381}
374 382
375// --- resort ----------------------------------------------------------------- 383// --- resort -----------------------------------------------------------------
376void Checkbook::resort() 384void Checkbook::resort()
377{ 385{
378 tranTable->setSorting(_sortCol); 386 tranTable->setSorting(_sortCol);
379 tranTable->sort(); 387 tranTable->sort();
380 tranTable->setSorting(-1); 388 tranTable->setSorting(-1);
381} 389}
382 390
383 391
384// --- accept ----------------------------------------------------------------- 392// --- accept -----------------------------------------------------------------
385void Checkbook::accept() 393void Checkbook::accept()
386{ 394{
387 info->setName( nameEdit->text() ); 395 info->setName( nameEdit->text() );
388 info->setType( typeList->currentText() ); 396 info->setType( typeList->currentText() );
389 info->setBank( bankEdit->text() ); 397 info->setBank( bankEdit->text() );
390 info->setAccount( acctNumEdit->text() ); 398 info->setAccount( acctNumEdit->text() );
391 info->setPin( pinNumEdit->text() ); 399 info->setPin( pinNumEdit->text() );
392 bool ok; 400 bool ok;
393 info->setStartingBalance( balanceEdit->text().toFloat( &ok ) ); 401 info->setStartingBalance( balanceEdit->text().toFloat( &ok ) );
394 info->setNotes( notesEdit->text() ); 402 info->setNotes( notesEdit->text() );
395 403
396 QDialog::accept(); 404 QDialog::accept();
397} 405}
398 406
407// --- slotPasswordClicked ----------------------------------------------------
399void Checkbook::slotPasswordClicked() 408void Checkbook::slotPasswordClicked()
400{ 409{
401 if ( info->password().isNull() && passwordCB->isChecked() ) 410 if ( info->password().isNull() && passwordCB->isChecked() )
402 { 411 {
403 Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); 412 Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) );
404 if ( pw->exec() != QDialog::Accepted ) 413 if ( pw->exec() != QDialog::Accepted )
405 { 414 {
406 passwordCB->setChecked( FALSE ); 415 passwordCB->setChecked( FALSE );
407 delete pw; 416 delete pw;
408 return; 417 return;
409 } 418 }
410 info->setPassword( pw->password ); 419 info->setPassword( pw->password );
411 delete pw; 420 delete pw;
412 421
413 pw = new Password( this, tr( "Confirm password" ), tr( "Please confirm your password:" ) ); 422 pw = new Password( this, tr( "Confirm password" ), tr( "Please confirm your password:" ) );
414 if ( pw->exec() != QDialog::Accepted || pw->password != info->password() ) 423 if ( pw->exec() != QDialog::Accepted || pw->password != info->password() )
415 { 424 {
416 passwordCB->setChecked( FALSE ); 425 passwordCB->setChecked( FALSE );
417 info->setPassword( QString::null ); 426 info->setPassword( QString::null );
418 } 427 }
419 428
420 delete pw; 429 delete pw;
421 } 430 }
422 else if ( !info->password().isNull() && !passwordCB->isChecked() ) 431 else if ( !info->password().isNull() && !passwordCB->isChecked() )
@@ -443,116 +452,164 @@ void Checkbook::slotNameChanged( const QString &newname )
443 info->setName( newname ); 452 info->setName( newname );
444 453
445 // TODO - need filedir 454 // TODO - need filedir
446 //QString namestr = filedir; 455 //QString namestr = filedir;
447 //namestr.append( newname ); 456 //namestr.append( newname );
448 //namestr.append( ".qcb" ); 457 //namestr.append( ".qcb" );
449 //info->setFilename( namestr ); 458 //info->setFilename( namestr );
450 459
451 QString namestr = newname; 460 QString namestr = newname;
452 namestr.append( " - " ); 461 namestr.append( " - " );
453 namestr.append( tr( "Checkbook" ) ); 462 namestr.append( tr( "Checkbook" ) );
454 setCaption( namestr ); 463 setCaption( namestr );
455} 464}
456 465
457 466
458// ---slotStartingBalanceChanged ---------------------------------------------- 467// ---slotStartingBalanceChanged ----------------------------------------------
459void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) 468void Checkbook::slotStartingBalanceChanged( const QString &newbalance )
460{ 469{
461 bool ok; 470 bool ok;
462 info->setStartingBalance( newbalance.toFloat( &ok ) ); 471 info->setStartingBalance( newbalance.toFloat( &ok ) );
463 adjustBalance(); 472 adjustBalance();
464} 473}
465 474
466 475
476// --- slotNewTran ------------------------------------------------------------
467void Checkbook::slotNewTran() 477void Checkbook::slotNewTran()
468{ 478{
469 TranInfo *traninfo = new TranInfo( info->getNextNumber() ); 479 TranInfo *traninfo = new TranInfo( info->getNextNumber() );
470 if( !_dLastNew.isNull() ) 480 if( !_dLastNew.isNull() )
471 traninfo->setDate(_dLastNew); 481 traninfo->setDate(_dLastNew);
472 482
473 Transaction *currtran = new Transaction( this, info->name(), 483 Transaction *currtran = new Transaction( this, true, info->name(),
474 traninfo, 484 traninfo,
475 _pCfg ); 485 _pCfg );
476 currtran->showMaximized(); 486 currtran->showMaximized();
477 if ( currtran->exec() == QDialog::Accepted ) 487 if ( currtran->exec() == QDialog::Accepted )
478 { 488 {
479 // Add to transaction list 489 // Add to transaction list
480 info->addTransaction( traninfo ); 490 info->addTransaction( traninfo );
481 491
482 // Add to transaction table 492 // Add to transaction table
483 float amount; 493 float amount;
484 QString stramount; 494 QString stramount;
485 amount = (traninfo->withdrawal() ? -1 : 1)*traninfo->amount(); 495 amount = (traninfo->withdrawal() ? -1 : 1)*traninfo->amount();
486 stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); 496 stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
487 ( void ) new CBListItem( traninfo, tranTable, traninfo->getIdStr(), 497 ( void ) new CBListItem( traninfo, tranTable, traninfo->getIdStr(), traninfo->datestr(false),
488 traninfo->number(), traninfo->datestr(), traninfo->desc(), 498 traninfo->number(), traninfo->datestr(true), traninfo->desc(),
489 stramount ); 499 stramount );
490 resort(); 500 resort();
491 adjustBalance(); 501 adjustBalance();
492 502
493 // save last date 503 // save last date
494 _dLastNew = traninfo->date(); 504 _dLastNew = traninfo->date();
505
506 // save description in list of payees, if not in there
507 QStringList *pLst=&_pCfg->getPayees();
508 if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) {
509 pLst->append( traninfo->desc() );
510 pLst->sort();
511 _pCfg->setDirty(true);
512 }
495 } 513 }
496 else 514 else
497 { 515 {
498 delete traninfo; 516 delete traninfo;
499 } 517 }
500} 518}
501 519
520
521// --- slotEditTran -----------------------------------------------------------
502void Checkbook::slotEditTran() 522void Checkbook::slotEditTran()
503{ 523{
504 QListViewItem *curritem = tranTable->currentItem(); 524 QListViewItem *curritem = tranTable->currentItem();
505 if ( !curritem ) 525 if ( !curritem )
506 return; 526 return;
507 527
508 TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) ); 528 TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) );
509 529
510 Transaction *currtran = new Transaction( this, info->name(), 530 Transaction *currtran = new Transaction( this, false, info->name(),
511 traninfo, 531 traninfo,
512 _pCfg ); 532 _pCfg );
513 currtran->showMaximized(); 533 currtran->showMaximized();
514 if ( currtran->exec() == QDialog::Accepted ) 534 if ( currtran->exec() == QDialog::Accepted )
515 { 535 {
516 curritem->setText( COL_NUM, traninfo->number() ); 536 curritem->setText( COL_NUM, traninfo->number() );
517 curritem->setText( COL_DATE, traninfo->datestr() ); 537 curritem->setText( COL_SORTDATE, traninfo->datestr(false) );
538 curritem->setText( COL_DATE, traninfo->datestr(true) );
518 curritem->setText( COL_DESC, traninfo->desc() ); 539 curritem->setText( COL_DESC, traninfo->desc() );
519 540
520 float amount = traninfo->amount(); 541 float amount = traninfo->amount();
521 if ( traninfo->withdrawal() ) 542 if ( traninfo->withdrawal() )
522 { 543 {
523 amount *= -1; 544 amount *= -1;
524 } 545 }
525 QString stramount; 546 QString stramount;
526 stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); 547 stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
527 curritem->setText( COL_AMOUNT, stramount ); 548 curritem->setText( COL_AMOUNT, stramount );
528 resort(); 549 resort();
529 adjustBalance(); 550 adjustBalance();
551
552 // save description in list of payees, if not in there
553 QStringList *pLst=&_pCfg->getPayees();
554 if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) {
555 pLst->append( traninfo->desc() );
556 pLst->sort();
557 _pCfg->setDirty(true);
558 }
530 } 559 }
531 560
532 delete currtran; 561 delete currtran;
533} 562}
534 563
564// --- slotMenuTran -----------------------------------------------------------
565void Checkbook::slotMenuTran(QListViewItem *item, const QPoint &pnt)
566{
567 // active item?
568 if( !item )
569 return;
570
571 // Display menu
572 QPopupMenu m;
573 m.insertItem( QWidget::tr( "Edit" ), 1 );
574 m.insertItem( QWidget::tr( "New" ), 2 );
575 m.insertItem( QWidget::tr( "Delete" ), 3 );
576 int r = m.exec( pnt );
577 switch(r) {
578 case 1:
579 slotEditTran();
580 break;
581 case 2:
582 slotNewTran();
583 break;
584 case 3:
585 slotDeleteTran();
586 break;
587 }
588}
589
590
591// --- slotDeleteTran ---------------------------------------------------------
535void Checkbook::slotDeleteTran() 592void Checkbook::slotDeleteTran()
536{ 593{
537 QListViewItem *curritem = tranTable->currentItem(); 594 QListViewItem *curritem = tranTable->currentItem();
538 if ( !curritem ) 595 if ( !curritem )
539 return; 596 return;
540 597
541 TranInfo *traninfo = info->findTransaction( curritem->text(COL_ID) ); 598 TranInfo *traninfo = info->findTransaction( curritem->text(COL_ID) );
542 599
543 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) ) 600 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) )
544 { 601 {
545 info->removeTransaction( traninfo ); 602 info->removeTransaction( traninfo );
546 delete curritem; 603 delete curritem;
547 adjustBalance(); 604 adjustBalance();
548 } 605 }
549} 606}
550 607
551void Checkbook::slotDrawGraph() 608void Checkbook::slotDrawGraph()
552{ 609{
553 if ( graphInfo ) 610 if ( graphInfo )
554 { 611 {
555 delete graphInfo; 612 delete graphInfo;
556 } 613 }
557 614
558 switch ( graphList->currentItem() ) 615 switch ( graphList->currentItem() )
@@ -570,49 +627,49 @@ void Checkbook::slotDrawGraph()
570} 627}
571 628
572void Checkbook::drawBalanceChart() 629void Checkbook::drawBalanceChart()
573{ 630{
574 DataPointList *list = new DataPointList(); 631 DataPointList *list = new DataPointList();
575 632
576 float balance = info->startingBalance(); 633 float balance = info->startingBalance();
577 float amount; 634 float amount;
578 QString label; 635 QString label;
579 int i = 0; 636 int i = 0;
580 int count = tranList->count(); 637 int count = tranList->count();
581 638
582 for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) 639 for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() )
583 { 640 {
584 i++; 641 i++;
585 balance -= tran->fee(); 642 balance -= tran->fee();
586 amount = tran->amount(); 643 amount = tran->amount();
587 if ( tran->withdrawal() ) 644 if ( tran->withdrawal() )
588 { 645 {
589 amount *= -1; 646 amount *= -1;
590 } 647 }
591 balance += amount; 648 balance += amount;
592 if ( i == 1 || i == count / 2 || i == count ) 649 if ( i == 1 || i == count / 2 || i == count )
593 { 650 {
594 label = tran->datestr(); 651 label = tran->datestr(true);
595 } 652 }
596 else 653 else
597 { 654 {
598 label = ""; 655 label = "";
599 } 656 }
600 list->append( new DataPointInfo( label, balance ) ); 657 list->append( new DataPointInfo( label, balance ) );
601 } 658 }
602 659
603 graphInfo = new GraphInfo( GraphInfo::BarChart, list ); 660 graphInfo = new GraphInfo( GraphInfo::BarChart, list );
604} 661}
605 662
606void Checkbook::drawCategoryChart( bool withdrawals ) 663void Checkbook::drawCategoryChart( bool withdrawals )
607{ 664{
608 DataPointList *list = new DataPointList(); 665 DataPointList *list = new DataPointList();
609 666
610 TranInfo *tran = tranList->first(); 667 TranInfo *tran = tranList->first();
611 if ( tran && tran->withdrawal() == withdrawals ) 668 if ( tran && tran->withdrawal() == withdrawals )
612 { 669 {
613 list->append( new DataPointInfo( tran->category(), tran->amount() ) ); 670 list->append( new DataPointInfo( tran->category(), tran->amount() ) );
614 } 671 }
615 tran = tranList->next(); 672 tran = tranList->next();
616 673
617 DataPointInfo *cat; 674 DataPointInfo *cat;
618 for ( ; tran; tran = tranList->next() ) 675 for ( ; tran; tran = tranList->next() )
@@ -645,48 +702,49 @@ CBListItem::CBListItem( TranInfo *pTran, QListView *parent, QString label1, QStr
645 QString label3, QString label4, QString label5, QString label6, QString label7, 702 QString label3, QString label4, QString label5, QString label6, QString label7,
646 QString label8 ) 703 QString label8 )
647 : QListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 ) 704 : QListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 )
648{ 705{
649 _pTran=pTran; 706 _pTran=pTran;
650 m_known = FALSE; 707 m_known = FALSE;
651 owner = parent; 708 owner = parent;
652} 709}
653 710
654void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align ) 711void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align )
655{ 712{
656 QColorGroup _cg = cg; 713 QColorGroup _cg = cg;
657 const QPixmap *pm = listView()->viewport()->backgroundPixmap(); 714 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
658 if ( pm && !pm->isNull() ) 715 if ( pm && !pm->isNull() )
659 { 716 {
660 _cg.setBrush( QColorGroup::Base, QBrush( cg.base(), *pm ) ); 717 _cg.setBrush( QColorGroup::Base, QBrush( cg.base(), *pm ) );
661 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); 718 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
662 } 719 }
663 else if ( isAltBackground() ) 720 else if ( isAltBackground() )
664 _cg.setColor(QColorGroup::Base, cg.background() ); 721 _cg.setColor(QColorGroup::Base, cg.background() );
665 722
666 QListViewItem::paintCell(p, _cg, column, width, align); 723 QListViewItem::paintCell(p, _cg, column, width, align);
667} 724}
668 725
726// --- CBListItem::isAltBackground --------------------------------------------
669bool CBListItem::isAltBackground() 727bool CBListItem::isAltBackground()
670{ 728{
671 QListView *lv = static_cast<QListView *>( listView() ); 729 QListView *lv = static_cast<QListView *>( listView() );
672 if ( lv ) 730 if ( lv )
673 { 731 {
674 CBListItem *above = 0; 732 CBListItem *above = 0;
675 above = (CBListItem *)( itemAbove() ); 733 above = (CBListItem *)( itemAbove() );
676 m_known = above ? above->m_known : true; 734 m_known = above ? above->m_known : true;
677 if ( m_known ) 735 if ( m_known )
678 { 736 {
679 m_odd = above ? !above->m_odd : false; 737 m_odd = above ? !above->m_odd : false;
680 } 738 }
681 else 739 else
682 { 740 {
683 CBListItem *item; 741 CBListItem *item;
684 bool previous = true; 742 bool previous = true;
685 if ( parent() ) 743 if ( parent() )
686 { 744 {
687 item = (CBListItem *)( parent() ); 745 item = (CBListItem *)( parent() );
688 if ( item ) 746 if ( item )
689 previous = item->m_odd; 747 previous = item->m_odd;
690 item = (CBListItem *)( parent()->firstChild() ); 748 item = (CBListItem *)( parent()->firstChild() );
691 } 749 }
692 else 750 else
@@ -702,29 +760,30 @@ bool CBListItem::isAltBackground()
702 } 760 }
703 } 761 }
704 return m_odd; 762 return m_odd;
705 } 763 }
706 return false; 764 return false;
707} 765}
708 766
709 767
710// --- slotTab ---------------------------------------------------------------- 768// --- slotTab ----------------------------------------------------------------
711void Checkbook::slotTab(QWidget *tab) 769void Checkbook::slotTab(QWidget *tab)
712{ 770{
713 if( !tab || !info ) return; 771 if( !tab || !info ) return;
714 info->setLastTab( tab->name() ); 772 info->setLastTab( tab->name() );
715} 773}
716 774
717 775
718// --- slotSortChanged --------------------------------------------------------- 776// --- slotSortChanged ---------------------------------------------------------
719void Checkbook::slotSortChanged( const QString &selc ) 777void Checkbook::slotSortChanged( const QString &selc )
720{ 778{
721 if( selc==tr("Entry Order") ) { 779 if( selc==tr("Entry Order") ) {
722 _sortCol=COL_ID; 780 _sortCol=COL_ID;
723 } else if( selc==tr("Number") ) { 781 } else if( selc==tr("Number") ) {
724 _sortCol=COL_NUM; 782 _sortCol=COL_NUM;
725 } else if( selc==tr("Date") ) { 783 } else if( selc==tr("Date") ) {
726 _sortCol=COL_DATE; 784 _sortCol=COL_SORTDATE;
727 } 785 }
728 info->setSortOrder( selc ); 786 info->setSortOrder( selc );
729 resort(); 787 resort();
730} 788}
789