author | mickeyl <mickeyl> | 2003-10-27 19:51:32 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-10-27 19:51:32 (UTC) |
commit | 951d1d4125a80dc814f95d2956853bf53ca52e9a (patch) (unidiff) | |
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) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/checkbook.cpp | 228 |
1 files changed, 152 insertions, 76 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 | |||
@@ -30,12 +30,14 @@ | |||
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" | ||
37 | #include "cfg.h" | ||
36 | 38 | ||
37 | #include <opie/otabwidget.h> | 39 | #include <opie/otabwidget.h> |
38 | #include <qpe/qpeapplication.h> | 40 | #include <qpe/qpeapplication.h> |
39 | #include <qpe/qpemessagebox.h> | 41 | #include <qpe/qpemessagebox.h> |
40 | #include <qpe/resource.h> | 42 | #include <qpe/resource.h> |
41 | 43 | ||
@@ -45,55 +47,69 @@ | |||
45 | #include <qlayout.h> | 47 | #include <qlayout.h> |
46 | #include <qlineedit.h> | 48 | #include <qlineedit.h> |
47 | #include <qmultilineedit.h> | 49 | #include <qmultilineedit.h> |
48 | #include <qpushbutton.h> | 50 | #include <qpushbutton.h> |
49 | #include <qwhatsthis.h> | 51 | #include <qwhatsthis.h> |
50 | 52 | ||
51 | Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol ) | 53 | #define COL_ID 0 |
54 | #define COL_NUM 1 | ||
55 | #define COL_DATE 2 | ||
56 | #define COL_DESC 3 | ||
57 | #define COL_AMOUNT 4 | ||
58 | #define COL_BAL 5 | ||
59 | |||
60 | // --- Checkbook -------------------------------------------------------------- | ||
61 | Checkbook::Checkbook( QWidget *parent, CBInfo *i, Cfg *cfg ) | ||
52 | : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) | 62 | : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) |
53 | { | 63 | { |
54 | info = i; | 64 | info = i; |
55 | currencySymbol = symbol; | 65 | _pCfg=cfg; |
56 | 66 | ||
67 | // Title bar | ||
57 | if ( info->name() != "" ) | 68 | if ( info->name() != "" ) |
58 | { | 69 | { |
59 | QString tempstr = info->name(); | 70 | QString tempstr = info->name(); |
60 | tempstr.append( " - " ); | 71 | tempstr.append( " - " ); |
61 | tempstr.append( tr( "Checkbook" ) ); | 72 | tempstr.append( tr( "Checkbook" ) ); |
62 | setCaption( tempstr ); | 73 | setCaption( tempstr ); |
63 | } | 74 | } |
64 | else | 75 | else |
65 | { | 76 | { |
66 | setCaption( tr( "New checkbook" ) ); | 77 | setCaption( tr( "New checkbook" ) ); |
67 | } | 78 | } |
68 | 79 | ||
80 | |||
69 | // Setup layout to make everything pretty | 81 | // Setup layout to make everything pretty |
70 | QVBoxLayout *layout = new QVBoxLayout( this ); | 82 | QVBoxLayout *layout = new QVBoxLayout( this ); |
71 | layout->setMargin( 2 ); | 83 | layout->setMargin( 2 ); |
72 | layout->setSpacing( 4 ); | 84 | layout->setSpacing( 4 ); |
73 | 85 | ||
74 | // Setup tabs for all info | 86 | // Setup tabs for all info |
75 | mainWidget = new OTabWidget( this ); | 87 | mainWidget = new OTabWidget( this ); |
76 | layout->addWidget( mainWidget ); | 88 | layout->addWidget( mainWidget ); |
77 | |||
78 | mainWidget->addTab( initInfo(), "checkbook/infotab", tr( "Info" ) ); | 89 | mainWidget->addTab( initInfo(), "checkbook/infotab", tr( "Info" ) ); |
79 | mainWidget->addTab( initTransactions(), "checkbook/trantab", tr( "Transactions" ) ); | 90 | mainWidget->addTab( initTransactions(), "checkbook/trantab", tr( "Transactions" ) ); |
80 | mainWidget->addTab( initCharts(), "checkbook/charttab", tr( "Charts" ) ); | 91 | mainWidget->addTab( initCharts(), "checkbook/charttab", tr( "Charts" ) ); |
81 | mainWidget->setCurrentTab( tr( "Info" ) ); | 92 | if( _pCfg->isShowLastTab() ) |
93 | mainWidget->setCurrentTab( info->getLastTab() ); | ||
94 | else | ||
95 | mainWidget->setCurrentTab( tr( "Info" ) ); | ||
96 | connect( mainWidget, SIGNAL( currentChanged(QWidget *) ), this, SLOT( slotTab(QWidget *) ) ); | ||
82 | 97 | ||
83 | // Load checkbook information | 98 | // Load checkbook information |
84 | loadCheckbook(); | 99 | loadCheckbook(); |
85 | } | 100 | } |
86 | 101 | ||
87 | Checkbook::~Checkbook() | 102 | Checkbook::~Checkbook() |
88 | { | 103 | { |
89 | } | 104 | } |
90 | 105 | ||
106 | // --- initInfo --------------------------------------------------------------- | ||
91 | QWidget *Checkbook::initInfo() | 107 | QWidget *Checkbook::initInfo() |
92 | { | 108 | { |
93 | QWidget *control = new QWidget( mainWidget ); | 109 | QWidget *control = new QWidget( mainWidget, tr("Info") ); |
94 | 110 | ||
95 | QVBoxLayout *vb = new QVBoxLayout( control ); | 111 | QVBoxLayout *vb = new QVBoxLayout( control ); |
96 | 112 | ||
97 | QScrollView *sv = new QScrollView( control ); | 113 | QScrollView *sv = new QScrollView( control ); |
98 | vb->addWidget( sv, 0, 0 ); | 114 | vb->addWidget( sv, 0, 0 ); |
99 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 115 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
@@ -125,19 +141,14 @@ QWidget *Checkbook::initInfo() | |||
125 | // Type of account | 141 | // Type of account |
126 | label = new QLabel( tr( "Type:" ), container ); | 142 | label = new QLabel( tr( "Type:" ), container ); |
127 | QWhatsThis::add( label, tr( "Select type of checkbook here." ) ); | 143 | QWhatsThis::add( label, tr( "Select type of checkbook here." ) ); |
128 | layout->addWidget( label, 2, 0 ); | 144 | layout->addWidget( label, 2, 0 ); |
129 | typeList = new QComboBox( container ); | 145 | typeList = new QComboBox( container ); |
130 | QWhatsThis::add( typeList, tr( "Select type of checkbook here." ) ); | 146 | QWhatsThis::add( typeList, tr( "Select type of checkbook here." ) ); |
131 | typeList->insertItem( tr( "Savings" ) ); // 0 | 147 | typeList->insertStringList( _pCfg->getAccountTypes() ); |
132 | typeList->insertItem( tr( "Checking" ) ); // 1 | 148 | layout->addWidget( typeList, 2, 1 ); |
133 | typeList->insertItem( tr( "CD" ) ); // 2 | ||
134 | typeList->insertItem( tr( "Money market" ) );// 3 | ||
135 | typeList->insertItem( tr( "Mutual fund" ) );// 4 | ||
136 | typeList->insertItem( tr( "Other" ) ); // 5 | ||
137 | layout->addWidget( typeList, 2, 1 ); | ||
138 | 149 | ||
139 | // Bank/institution name | 150 | // Bank/institution name |
140 | label = new QLabel( tr( "Bank:" ), container ); | 151 | label = new QLabel( tr( "Bank:" ), container ); |
141 | QWhatsThis::add( label, tr( "Enter name of the bank for this checkbook here." ) ); | 152 | QWhatsThis::add( label, tr( "Enter name of the bank for this checkbook here." ) ); |
142 | layout->addWidget( label, 3, 0 ); | 153 | layout->addWidget( label, 3, 0 ); |
143 | bankEdit = new QLineEdit( container ); | 154 | bankEdit = new QLineEdit( container ); |
@@ -180,40 +191,59 @@ QWidget *Checkbook::initInfo() | |||
180 | notesEdit->setMaximumHeight( 65 ); | 191 | notesEdit->setMaximumHeight( 65 ); |
181 | layout->addMultiCellWidget( notesEdit, 8, 8, 0, 1 ); | 192 | layout->addMultiCellWidget( notesEdit, 8, 8, 0, 1 ); |
182 | 193 | ||
183 | return control; | 194 | return control; |
184 | } | 195 | } |
185 | 196 | ||
197 | |||
198 | // --- initTransactions ------------------------------------------------------- | ||
186 | QWidget *Checkbook::initTransactions() | 199 | QWidget *Checkbook::initTransactions() |
187 | { | 200 | { |
188 | QWidget *control = new QWidget( mainWidget ); | 201 | QWidget *control = new QWidget( mainWidget, tr("Transactions") ); |
189 | 202 | ||
190 | QGridLayout *layout = new QGridLayout( control ); | 203 | QGridLayout *layout = new QGridLayout( control ); |
191 | layout->setSpacing( 2 ); | 204 | layout->setSpacing( 2 ); |
192 | layout->setMargin( 4 ); | 205 | layout->setMargin( 4 ); |
193 | 206 | ||
194 | balanceLabel = new QLabel( tr( "Current balance: %10.00" ).arg( currencySymbol ), | 207 | // Sort selector |
195 | control ); | 208 | QLabel *label = new QLabel( tr( "Sort by:" ), control ); |
196 | QWhatsThis::add( balanceLabel, tr( "This area shows the current balance in this checkbook." ) ); | 209 | QWhatsThis::add( label, tr( "Select checkbook sorting here." ) ); |
197 | layout->addMultiCellWidget( balanceLabel, 0, 0, 0, 2 ); | 210 | layout->addMultiCellWidget( label, 0, 0, 0, 1 ); |
198 | 211 | _cbSortType=new QComboBox( control ); | |
199 | tranTable = new QListView( control ); | 212 | _cbSortType->insertItem( tr("Entry Order") ); |
213 | _cbSortType->insertItem( tr("Date") ); | ||
214 | _cbSortType->insertItem( tr("Number") ); | ||
215 | layout->addMultiCellWidget( _cbSortType, 0, 0, 1, 2 ); | ||
216 | connect( _cbSortType, SIGNAL( activated(const QString &) ), this, SLOT( slotSortChanged( const QString & ) ) ); | ||
217 | |||
218 | // Table | ||
219 | tranTable = new QListView( control ); | ||
220 | QFont fnt(QPEApplication::font()); | ||
221 | fnt.setPointSize( fnt.pointSize()-1 ); | ||
222 | tranTable->setFont( fnt ); | ||
200 | 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." ) ); | 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." ) ); |
201 | tranTable->addColumn( tr( "Num" ) ); | 224 | tranTable->addColumn( tr( "Id" ) ); |
225 | tranTable->setColumnWidthMode( COL_ID, QListView::Manual ); | ||
226 | tranTable->setColumnWidth( COL_ID, 0); | ||
227 | tranTable->addColumn( tr( "Num" ) ); | ||
202 | tranTable->addColumn( tr( "Date" ) ); | 228 | tranTable->addColumn( tr( "Date" ) ); |
203 | //tranTable->addColumn( tr( "Cleared" ) ); | 229 | //tranTable->addColumn( tr( "Cleared" ) ); |
204 | tranTable->addColumn( tr( "Description" ) ); | 230 | tranTable->addColumn( tr( "Description" ) ); |
205 | int colnum = tranTable->addColumn( tr( "Amount" ) ); | 231 | int column = tranTable->addColumn( tr( "Amount" ) ); |
206 | tranTable->setColumnAlignment( colnum, Qt::AlignRight ); | 232 | tranTable->setColumnAlignment( column, Qt::AlignRight ); |
233 | column=tranTable->addColumn( tr("Balance") ); | ||
234 | tranTable->setColumnAlignment( column, Qt::AlignRight ); | ||
207 | tranTable->setAllColumnsShowFocus( TRUE ); | 235 | tranTable->setAllColumnsShowFocus( TRUE ); |
208 | tranTable->setSorting( 1 ); | 236 | tranTable->setSorting( -1 ); |
209 | layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 ); | 237 | layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 ); |
210 | QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold ); | 238 | QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold ); |
211 | connect( tranTable, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ), | 239 | connect( tranTable, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ), |
212 | this, SLOT( slotEditTran() ) ); | 240 | this, SLOT( slotEditTran() ) ); |
241 | _sortCol=COL_ID; | ||
213 | 242 | ||
243 | // Buttons | ||
214 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control ); | 244 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control ); |
215 | QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) ); | 245 | QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) ); |
216 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) ); | 246 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) ); |
217 | layout->addWidget( btn, 2, 0 ); | 247 | layout->addWidget( btn, 2, 0 ); |
218 | 248 | ||
219 | btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), control ); | 249 | btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), control ); |
@@ -226,17 +256,19 @@ QWidget *Checkbook::initTransactions() | |||
226 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDeleteTran() ) ); | 256 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDeleteTran() ) ); |
227 | layout->addWidget( btn, 2, 2 ); | 257 | layout->addWidget( btn, 2, 2 ); |
228 | 258 | ||
229 | return( control ); | 259 | return( control ); |
230 | } | 260 | } |
231 | 261 | ||
262 | |||
263 | // --- initCharts ------------------------------------------------------------- | ||
232 | QWidget *Checkbook::initCharts() | 264 | QWidget *Checkbook::initCharts() |
233 | { | 265 | { |
234 | graphInfo = 0x0; | 266 | graphInfo = 0x0; |
235 | 267 | ||
236 | QWidget *control = new QWidget( mainWidget ); | 268 | QWidget *control = new QWidget( mainWidget, tr("Charts") ); |
237 | 269 | ||
238 | QGridLayout *layout = new QGridLayout( control ); | 270 | QGridLayout *layout = new QGridLayout( control ); |
239 | layout->setSpacing( 2 ); | 271 | layout->setSpacing( 2 ); |
240 | layout->setMargin( 4 ); | 272 | layout->setMargin( 4 ); |
241 | 273 | ||
242 | graphWidget = new Graph( control ); | 274 | graphWidget = new Graph( control ); |
@@ -256,12 +288,13 @@ QWidget *Checkbook::initCharts() | |||
256 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) ); | 288 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) ); |
257 | layout->addWidget( btn, 1, 2 ); | 289 | layout->addWidget( btn, 1, 2 ); |
258 | 290 | ||
259 | return control; | 291 | return control; |
260 | } | 292 | } |
261 | 293 | ||
294 | // --- loadCheckbook ---------------------------------------------------------- | ||
262 | void Checkbook::loadCheckbook() | 295 | void Checkbook::loadCheckbook() |
263 | { | 296 | { |
264 | if ( !info ) | 297 | if ( !info ) |
265 | { | 298 | { |
266 | return; | 299 | return; |
267 | } | 300 | } |
@@ -278,57 +311,80 @@ void Checkbook::loadCheckbook() | |||
278 | typeList->setCurrentItem( i ); | 311 | typeList->setCurrentItem( i ); |
279 | if ( typeList->currentText() == temptext ) | 312 | if ( typeList->currentText() == temptext ) |
280 | { | 313 | { |
281 | break; | 314 | break; |
282 | } | 315 | } |
283 | } | 316 | } |
317 | if( i<=0 ) { | ||
318 | typeList->insertItem( temptext, 0 ); | ||
319 | typeList->setCurrentItem(0); | ||
320 | } | ||
284 | bankEdit->setText( info->bank() ); | 321 | bankEdit->setText( info->bank() ); |
285 | acctNumEdit->setText( info->account() ); | 322 | acctNumEdit->setText( info->account() ); |
286 | pinNumEdit->setText( info->pin() ); | 323 | pinNumEdit->setText( info->pin() ); |
287 | temptext.setNum( info->startingBalance(), 'f', 2 ); | 324 | temptext.setNum( info->startingBalance(), 'f', 2 ); |
288 | balanceEdit->setText( temptext ); | 325 | balanceEdit->setText( temptext ); |
289 | notesEdit->setText( info->notes() ); | 326 | notesEdit->setText( info->notes() ); |
290 | 327 | ||
291 | // Load transactions | 328 | // Load transactions |
292 | float amount; | 329 | float amount; |
293 | QString stramount; | 330 | QString stramount; |
294 | 331 | for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) | |
295 | for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) | ||
296 | { | 332 | { |
297 | amount = tran->amount(); | 333 | amount = tran->amount(); |
298 | if ( tran->withdrawal() ) | 334 | if ( tran->withdrawal() ) |
299 | { | 335 | { |
300 | amount *= -1; | 336 | amount *= -1; |
301 | } | 337 | } |
302 | stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); | 338 | stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); |
303 | ( void ) new CBListItem( tranTable, tran->number(), tran->datestr(), tran->desc(), stramount ); | 339 | ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->number(), tran->datestr(), tran->desc(), stramount ); |
304 | } | 340 | } |
305 | 341 | ||
306 | balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) ); | 342 | // set sort order |
307 | 343 | bool bOk=false; | |
308 | highTranNum = tranList->count(); | 344 | for(int i=0; i<_cbSortType->count(); i++) { |
345 | if( _cbSortType->text(i)==info->getSortOrder() ) { | ||
346 | _cbSortType->setCurrentItem(i); | ||
347 | slotSortChanged( info->getSortOrder() ); | ||
348 | bOk=true; | ||
349 | break; | ||
350 | } | ||
351 | } | ||
352 | if( !bOk ) { | ||
353 | _cbSortType->setCurrentItem(0); | ||
354 | slotSortChanged( _cbSortType->currentText() ); | ||
355 | } | ||
356 | |||
357 | // calc running balance | ||
358 | adjustBalance(); | ||
309 | } | 359 | } |
310 | 360 | ||
361 | // --- adjustBalance ---------------------------------------------------------- | ||
311 | void Checkbook::adjustBalance() | 362 | void Checkbook::adjustBalance() |
312 | { | 363 | { |
313 | balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) ); | 364 | // update running balance in register |
365 | QString sRunning; | ||
366 | float bal=info->startingBalance(); | ||
367 | for(CBListItem *item=(CBListItem *)tranTable->firstChild(); item; item=(CBListItem *)item->nextSibling() ) { | ||
368 | TranInfo *tran=item->getTranInfo(); | ||
369 | bal=bal + (tran->withdrawal() ? -1 : 1)*tran->amount() - tran->fee(); | ||
370 | sRunning.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), bal ); | ||
371 | item->setText( COL_BAL, sRunning); | ||
372 | } | ||
314 | } | 373 | } |
315 | 374 | ||
316 | TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, const QString &desc ) | 375 | // --- resort ----------------------------------------------------------------- |
376 | void Checkbook::resort() | ||
317 | { | 377 | { |
318 | TranInfo *traninfo = tranList->first(); | 378 | tranTable->setSorting(_sortCol); |
319 | while ( traninfo ) | 379 | tranTable->sort(); |
320 | { | 380 | tranTable->setSorting(-1); |
321 | if ( traninfo->number() == checknum && traninfo->datestr() == date && | ||
322 | traninfo->desc() == desc ) | ||
323 | break; | ||
324 | traninfo = tranList->next(); | ||
325 | } | ||
326 | return( traninfo ); | ||
327 | } | 381 | } |
328 | 382 | ||
383 | |||
384 | // --- accept ----------------------------------------------------------------- | ||
329 | void Checkbook::accept() | 385 | void Checkbook::accept() |
330 | { | 386 | { |
331 | info->setName( nameEdit->text() ); | 387 | info->setName( nameEdit->text() ); |
332 | info->setType( typeList->currentText() ); | 388 | info->setType( typeList->currentText() ); |
333 | info->setBank( bankEdit->text() ); | 389 | info->setBank( bankEdit->text() ); |
334 | info->setAccount( acctNumEdit->text() ); | 390 | info->setAccount( acctNumEdit->text() ); |
@@ -395,107 +451,103 @@ void Checkbook::slotNameChanged( const QString &newname ) | |||
395 | QString namestr = newname; | 451 | QString namestr = newname; |
396 | namestr.append( " - " ); | 452 | namestr.append( " - " ); |
397 | namestr.append( tr( "Checkbook" ) ); | 453 | namestr.append( tr( "Checkbook" ) ); |
398 | setCaption( namestr ); | 454 | setCaption( namestr ); |
399 | } | 455 | } |
400 | 456 | ||
457 | |||
458 | // ---slotStartingBalanceChanged ---------------------------------------------- | ||
401 | void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) | 459 | void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) |
402 | { | 460 | { |
403 | bool ok; | 461 | bool ok; |
404 | info->setStartingBalance( newbalance.toFloat( &ok ) ); | 462 | info->setStartingBalance( newbalance.toFloat( &ok ) ); |
405 | adjustBalance(); | 463 | adjustBalance(); |
406 | } | 464 | } |
407 | 465 | ||
466 | |||
408 | void Checkbook::slotNewTran() | 467 | void Checkbook::slotNewTran() |
409 | { | 468 | { |
410 | highTranNum++; | 469 | TranInfo *traninfo = new TranInfo( info->getNextNumber() ); |
411 | TranInfo *traninfo = new TranInfo( highTranNum ); | 470 | if( !_dLastNew.isNull() ) |
471 | traninfo->setDate(_dLastNew); | ||
412 | 472 | ||
413 | Transaction *currtran = new Transaction( this, info->name(), | 473 | Transaction *currtran = new Transaction( this, info->name(), |
414 | traninfo, | 474 | traninfo, |
415 | currencySymbol ); | 475 | _pCfg ); |
416 | currtran->showMaximized(); | 476 | currtran->showMaximized(); |
417 | if ( currtran->exec() == QDialog::Accepted ) | 477 | if ( currtran->exec() == QDialog::Accepted ) |
418 | { | 478 | { |
419 | // Add to transaction list | 479 | // Add to transaction list |
420 | info->addTransaction( traninfo ); | 480 | info->addTransaction( traninfo ); |
421 | 481 | ||
422 | // Add to transaction table | 482 | // Add to transaction table |
423 | float amount; | 483 | float amount; |
424 | QString stramount; | 484 | QString stramount; |
425 | 485 | amount = (traninfo->withdrawal() ? -1 : 1)*traninfo->amount(); | |
426 | amount = traninfo->amount(); | 486 | stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); |
427 | if ( traninfo->withdrawal() ) | 487 | ( void ) new CBListItem( traninfo, tranTable, traninfo->getIdStr(), |
428 | { | 488 | traninfo->number(), traninfo->datestr(), traninfo->desc(), |
429 | amount *= -1; | 489 | stramount ); |
430 | } | 490 | resort(); |
431 | stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); | ||
432 | |||
433 | ( void ) new CBListItem( tranTable, traninfo->number(), traninfo->datestr(), traninfo->desc(), | ||
434 | stramount ); | ||
435 | |||
436 | adjustBalance(); | 491 | adjustBalance(); |
492 | |||
493 | // save last date | ||
494 | _dLastNew = traninfo->date(); | ||
437 | } | 495 | } |
438 | else | 496 | else |
439 | { | 497 | { |
440 | highTranNum--; | ||
441 | delete traninfo; | 498 | delete traninfo; |
442 | } | 499 | } |
443 | } | 500 | } |
444 | 501 | ||
445 | void Checkbook::slotEditTran() | 502 | void Checkbook::slotEditTran() |
446 | { | 503 | { |
447 | QListViewItem *curritem = tranTable->currentItem(); | 504 | QListViewItem *curritem = tranTable->currentItem(); |
448 | if ( !curritem ) | 505 | if ( !curritem ) |
449 | { | ||
450 | return; | 506 | return; |
451 | } | 507 | |
452 | 508 | TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) ); | |
453 | TranInfo *traninfo = info->findTransaction( curritem->text( 0 ), curritem->text( 1 ), | ||
454 | curritem->text( 2 ) ); | ||
455 | 509 | ||
456 | Transaction *currtran = new Transaction( this, info->name(), | 510 | Transaction *currtran = new Transaction( this, info->name(), |
457 | traninfo, | 511 | traninfo, |
458 | currencySymbol ); | 512 | _pCfg ); |
459 | currtran->showMaximized(); | 513 | currtran->showMaximized(); |
460 | if ( currtran->exec() == QDialog::Accepted ) | 514 | if ( currtran->exec() == QDialog::Accepted ) |
461 | { | 515 | { |
462 | curritem->setText( 0, traninfo->number() ); | 516 | curritem->setText( COL_NUM, traninfo->number() ); |
463 | curritem->setText( 1, traninfo->datestr() ); | 517 | curritem->setText( COL_DATE, traninfo->datestr() ); |
464 | curritem->setText( 2, traninfo->desc() ); | 518 | curritem->setText( COL_DESC, traninfo->desc() ); |
465 | 519 | ||
466 | float amount = traninfo->amount(); | 520 | float amount = traninfo->amount(); |
467 | if ( traninfo->withdrawal() ) | 521 | if ( traninfo->withdrawal() ) |
468 | { | 522 | { |
469 | amount *= -1; | 523 | amount *= -1; |
470 | } | 524 | } |
471 | QString stramount; | 525 | QString stramount; |
472 | stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); | 526 | stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); |
473 | curritem->setText( 3, stramount ); | 527 | curritem->setText( COL_AMOUNT, stramount ); |
474 | 528 | resort(); | |
475 | adjustBalance(); | 529 | adjustBalance(); |
476 | } | 530 | } |
477 | 531 | ||
478 | delete currtran; | 532 | delete currtran; |
479 | } | 533 | } |
480 | 534 | ||
481 | void Checkbook::slotDeleteTran() | 535 | void Checkbook::slotDeleteTran() |
482 | { | 536 | { |
483 | QListViewItem *curritem = tranTable->currentItem(); | 537 | QListViewItem *curritem = tranTable->currentItem(); |
484 | if ( !curritem ) | 538 | if ( !curritem ) |
485 | { | ||
486 | return; | 539 | return; |
487 | } | ||
488 | 540 | ||
489 | TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) ); | 541 | TranInfo *traninfo = info->findTransaction( curritem->text(COL_ID) ); |
490 | 542 | ||
491 | if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) ) | 543 | if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) ) |
492 | { | 544 | { |
493 | info->removeTransaction( traninfo ); | 545 | info->removeTransaction( traninfo ); |
494 | delete curritem; | 546 | delete curritem; |
495 | adjustBalance(); | 547 | adjustBalance(); |
496 | } | 548 | } |
497 | } | 549 | } |
498 | 550 | ||
499 | void Checkbook::slotDrawGraph() | 551 | void Checkbook::slotDrawGraph() |
500 | { | 552 | { |
501 | if ( graphInfo ) | 553 | if ( graphInfo ) |
@@ -586,17 +638,18 @@ void Checkbook::drawCategoryChart( bool withdrawals ) | |||
586 | } | 638 | } |
587 | } | 639 | } |
588 | 640 | ||
589 | graphInfo = new GraphInfo( GraphInfo::PieChart, list ); | 641 | graphInfo = new GraphInfo( GraphInfo::PieChart, list ); |
590 | } | 642 | } |
591 | 643 | ||
592 | CBListItem::CBListItem( QListView *parent, QString label1, QString label2, | 644 | CBListItem::CBListItem( TranInfo *pTran, QListView *parent, QString label1, QString label2, |
593 | QString label3, QString label4, QString label5, QString label6, QString label7, | 645 | QString label3, QString label4, QString label5, QString label6, QString label7, |
594 | QString label8 ) | 646 | QString label8 ) |
595 | : QListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 ) | 647 | : QListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 ) |
596 | { | 648 | { |
649 | _pTran=pTran; | ||
597 | m_known = FALSE; | 650 | m_known = FALSE; |
598 | owner = parent; | 651 | owner = parent; |
599 | } | 652 | } |
600 | 653 | ||
601 | void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align ) | 654 | void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align ) |
602 | { | 655 | { |
@@ -649,6 +702,29 @@ bool CBListItem::isAltBackground() | |||
649 | } | 702 | } |
650 | } | 703 | } |
651 | return m_odd; | 704 | return m_odd; |
652 | } | 705 | } |
653 | return false; | 706 | return false; |
654 | } | 707 | } |
708 | |||
709 | |||
710 | // --- slotTab ---------------------------------------------------------------- | ||
711 | void Checkbook::slotTab(QWidget *tab) | ||
712 | { | ||
713 | if( !tab || !info ) return; | ||
714 | info->setLastTab( tab->name() ); | ||
715 | } | ||
716 | |||
717 | |||
718 | // --- slotSortChanged --------------------------------------------------------- | ||
719 | void Checkbook::slotSortChanged( const QString &selc ) | ||
720 | { | ||
721 | if( selc==tr("Entry Order") ) { | ||
722 | _sortCol=COL_ID; | ||
723 | } else if( selc==tr("Number") ) { | ||
724 | _sortCol=COL_NUM; | ||
725 | } else if( selc==tr("Date") ) { | ||
726 | _sortCol=COL_DATE; | ||
727 | } | ||
728 | info->setSortOrder( selc ); | ||
729 | resort(); | ||
730 | } | ||