Diffstat (limited to 'noncore/apps/checkbook/checkbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/checkbook.cpp | 91 |
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 | |||
@@ -46,19 +46,21 @@ | |||
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 -------------------------------------------------------------- |
61 | Checkbook::Checkbook( QWidget *parent, CBInfo *i, Cfg *cfg ) | 63 | Checkbook::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; |
@@ -221,12 +223,15 @@ QWidget *Checkbook::initTransactions() | |||
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 ); |
@@ -234,13 +239,15 @@ QWidget *Checkbook::initTransactions() | |||
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() ) ); |
@@ -333,13 +340,13 @@ void Checkbook::loadCheckbook() | |||
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() ) { |
@@ -355,12 +362,13 @@ void Checkbook::loadCheckbook() | |||
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 ---------------------------------------------------------- |
362 | void Checkbook::adjustBalance() | 370 | void 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(); |
@@ -393,12 +401,13 @@ void Checkbook::accept() | |||
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 ---------------------------------------------------- | ||
399 | void Checkbook::slotPasswordClicked() | 408 | void 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 ) |
@@ -461,19 +470,20 @@ void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) | |||
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 ------------------------------------------------------------ | ||
467 | void Checkbook::slotNewTran() | 477 | void 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 |
@@ -481,60 +491,107 @@ void Checkbook::slotNewTran() | |||
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 ----------------------------------------------------------- | ||
502 | void Checkbook::slotEditTran() | 522 | void 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 ----------------------------------------------------------- | ||
565 | void 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 --------------------------------------------------------- | ||
535 | void Checkbook::slotDeleteTran() | 592 | void 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 | ||
@@ -588,13 +645,13 @@ void Checkbook::drawBalanceChart() | |||
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 ) ); |
@@ -663,12 +720,13 @@ void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int | |||
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 -------------------------------------------- | ||
669 | bool CBListItem::isAltBackground() | 727 | bool 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; |
@@ -720,11 +778,12 @@ void 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 | |||