author | drw <drw> | 2002-10-21 23:04:11 (UTC) |
---|---|---|
committer | drw <drw> | 2002-10-21 23:04:11 (UTC) |
commit | 0b0f3dccd3b6dbb01fd268e2c737fd1a6c163379 (patch) (unidiff) | |
tree | fc39f1647722bb5bc9a935c32567a3da666ae843 /noncore/apps/checkbook/transaction.cpp | |
parent | b466b56f8a17010d651f07149ae5b860296ac710 (diff) | |
download | opie-0b0f3dccd3b6dbb01fd268e2c737fd1a6c163379.zip opie-0b0f3dccd3b6dbb01fd268e2c737fd1a6c163379.tar.gz opie-0b0f3dccd3b6dbb01fd268e2c737fd1a6c163379.tar.bz2 |
New version of Checkbook app
Diffstat (limited to 'noncore/apps/checkbook/transaction.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/transaction.cpp | 260 |
1 files changed, 260 insertions, 0 deletions
diff --git a/noncore/apps/checkbook/transaction.cpp b/noncore/apps/checkbook/transaction.cpp new file mode 100644 index 0000000..7d1781b --- a/dev/null +++ b/noncore/apps/checkbook/transaction.cpp | |||
@@ -0,0 +1,260 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #include "transaction.h" | ||
30 | #include "traninfo.h" | ||
31 | |||
32 | #include <qpe/datebookmonth.h> | ||
33 | #include <qpe/timestring.h> | ||
34 | |||
35 | #include <qbuttongroup.h> | ||
36 | #include <qcombobox.h> | ||
37 | #include <qlabel.h> | ||
38 | #include <qlayout.h> | ||
39 | #include <qlineedit.h> | ||
40 | #include <qmultilineedit.h> | ||
41 | #include <qpopupmenu.h> | ||
42 | #include <qpushbutton.h> | ||
43 | #include <qradiobutton.h> | ||
44 | #include <qscrollview.h> | ||
45 | #include <qstring.h> | ||
46 | |||
47 | #include <stdio.h> | ||
48 | |||
49 | Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *info, | ||
50 | char symbol ) | ||
51 | : QDialog( parent, 0, TRUE, 0 ) | ||
52 | { | ||
53 | setCaption( tr( "Transaction for " ) + acctname ); | ||
54 | |||
55 | tran = info; | ||
56 | currencySymbol = symbol; | ||
57 | |||
58 | QVBoxLayout *vb = new QVBoxLayout( this ); | ||
59 | |||
60 | QScrollView *sv = new QScrollView( this ); | ||
61 | vb->addWidget( sv, 0, 0 ); | ||
62 | sv->setResizePolicy( QScrollView::AutoOneFit ); | ||
63 | sv->setFrameStyle( QFrame::NoFrame ); | ||
64 | |||
65 | QWidget *container = new QWidget( sv->viewport() ); | ||
66 | sv->addChild( container ); | ||
67 | |||
68 | QGridLayout *layout = new QGridLayout( container ); | ||
69 | layout->setSpacing( 2 ); | ||
70 | layout->setMargin( 4 ); | ||
71 | |||
72 | // Withdrawal/Deposit | ||
73 | QButtonGroup *btngrp = new QButtonGroup( container ); | ||
74 | btngrp->setColumnLayout(0, Qt::Vertical ); | ||
75 | btngrp->layout()->setSpacing( 0 ); | ||
76 | btngrp->layout()->setMargin( 0 ); | ||
77 | btngrp->setMaximumWidth( 220 ); | ||
78 | QGridLayout *layout2 = new QGridLayout( btngrp->layout() ); | ||
79 | layout2->setSpacing( 2 ); | ||
80 | layout2->setMargin( 2 ); | ||
81 | withBtn = new QRadioButton( tr( "Withdrawal" ), btngrp ); | ||
82 | layout2->addWidget( withBtn, 0, 0 ); | ||
83 | connect( withBtn, SIGNAL( clicked() ), this, SLOT( slotWithdrawalClicked() ) ); | ||
84 | depBtn = new QRadioButton( tr( "Deposit" ), btngrp ); | ||
85 | layout2->addWidget( depBtn, 0, 1 ); | ||
86 | btngrp->setMaximumSize( 320, withBtn->height() ); | ||
87 | connect( depBtn, SIGNAL( clicked() ), this, SLOT( slotDepositClicked() ) ); | ||
88 | layout->addMultiCellWidget( btngrp, 0, 0, 0, 3 ); | ||
89 | |||
90 | // Date | ||
91 | QLabel *label = new QLabel( tr( "Date:" ), container ); | ||
92 | layout->addWidget( label, 1, 0 ); | ||
93 | dateBtn = new QPushButton( TimeString::shortDate( QDate::currentDate() ), | ||
94 | container ); | ||
95 | QPopupMenu *m1 = new QPopupMenu( container ); | ||
96 | datePicker = new DateBookMonth( m1, 0, TRUE ); | ||
97 | m1->insertItem( datePicker ); | ||
98 | dateBtn->setPopup( m1 ); | ||
99 | connect( datePicker, SIGNAL( dateClicked( int, int, int ) ), | ||
100 | this, SLOT( slotDateChanged( int, int, int ) ) ); | ||
101 | layout->addWidget( dateBtn, 1, 1 ); | ||
102 | |||
103 | // Check number | ||
104 | label = new QLabel( tr( "Number:" ), container ); | ||
105 | layout->addWidget( label, 1, 2 ); | ||
106 | numEdit = new QLineEdit( container ); | ||
107 | numEdit->setMaximumWidth( 40 ); | ||
108 | layout->addWidget( numEdit, 1, 3 ); | ||
109 | |||
110 | // Description | ||
111 | label = new QLabel( tr( "Description:" ), container ); | ||
112 | layout->addWidget( label, 2, 0 ); | ||
113 | descEdit = new QLineEdit( container ); | ||
114 | layout->addMultiCellWidget( descEdit, 2, 2, 1, 3 ); | ||
115 | |||
116 | // Category | ||
117 | label = new QLabel( tr( "Category:" ), container ); | ||
118 | layout->addWidget( label, 3, 0 ); | ||
119 | catList = new QComboBox( container ); | ||
120 | layout->addMultiCellWidget( catList, 3, 3, 1, 3 ); | ||
121 | |||
122 | // Type | ||
123 | label = new QLabel( tr( "Type:" ), container ); | ||
124 | layout->addWidget( label, 4, 0 ); | ||
125 | typeList = new QComboBox( container ); | ||
126 | layout->addMultiCellWidget( typeList, 4, 4, 1, 3 ); | ||
127 | |||
128 | // Amount | ||
129 | label = new QLabel( tr( "Amount:" ), container ); | ||
130 | layout->addWidget( label, 5, 0 ); | ||
131 | amtEdit = new QLineEdit( container ); | ||
132 | layout->addMultiCellWidget( amtEdit, 5, 5, 1, 3 ); | ||
133 | |||
134 | // Fee | ||
135 | label = new QLabel( tr( "Fee:" ), container ); | ||
136 | layout->addWidget( label, 6, 0 ); | ||
137 | feeEdit = new QLineEdit( container ); | ||
138 | layout->addMultiCellWidget( feeEdit, 6, 6, 1, 3 ); | ||
139 | |||
140 | // Notes | ||
141 | label = new QLabel( tr( "Notes:" ), container ); | ||
142 | layout->addWidget( label, 7, 0 ); | ||
143 | noteEdit = new QMultiLineEdit( container ); | ||
144 | layout->addMultiCellWidget( noteEdit, 8, 8, 0, 3 ); | ||
145 | |||
146 | // Populate current values if provided | ||
147 | if ( info ) | ||
148 | { | ||
149 | if ( info->withdrawal() ) | ||
150 | { | ||
151 | withBtn->setChecked( TRUE ); | ||
152 | slotWithdrawalClicked(); | ||
153 | } | ||
154 | else | ||
155 | { | ||
156 | depBtn->setChecked( TRUE ); | ||
157 | slotDepositClicked(); | ||
158 | } | ||
159 | QDate dt = info->date(); | ||
160 | slotDateChanged( dt.year(), dt.month(), dt.day() ); | ||
161 | datePicker->setDate( dt ); | ||
162 | numEdit->setText( info->number() ); | ||
163 | descEdit->setText( info->desc() ); | ||
164 | QString temptext = info->category(); | ||
165 | int i = catList->count(); | ||
166 | while ( i > 0 ) | ||
167 | { | ||
168 | i--; | ||
169 | catList->setCurrentItem( i ); | ||
170 | if ( catList->currentText() == temptext ) | ||
171 | { | ||
172 | break; | ||
173 | } | ||
174 | } | ||
175 | temptext = info->type(); | ||
176 | i = typeList->count(); | ||
177 | while ( i > 0 ) | ||
178 | { | ||
179 | i--; | ||
180 | typeList->setCurrentItem( i ); | ||
181 | if ( typeList->currentText() == temptext ) | ||
182 | { | ||
183 | break; | ||
184 | } | ||
185 | } | ||
186 | amtEdit->setText( QString( "%1" ).arg( info->amount(), 0, 'f', 2 ) ); | ||
187 | feeEdit->setText( QString( "%1" ).arg( info->fee(), 0, 'f', 2 ) ); | ||
188 | noteEdit->setText( info->notes() ); | ||
189 | } | ||
190 | else | ||
191 | { | ||
192 | withBtn->setChecked( TRUE ); | ||
193 | } | ||
194 | } | ||
195 | |||
196 | Transaction::~Transaction() | ||
197 | { | ||
198 | } | ||
199 | |||
200 | void Transaction::accept() | ||
201 | { | ||
202 | tran->setDesc( descEdit->text() ); | ||
203 | tran->setDate( datePicker->selectedDate() ); | ||
204 | tran->setWithdrawal( withBtn->isChecked() ); | ||
205 | tran->setType( typeList->currentText() ); | ||
206 | tran->setCategory( catList->currentText() ); | ||
207 | bool ok; | ||
208 | tran->setAmount( amtEdit->text().toFloat( &ok ) ); | ||
209 | tran->setFee( feeEdit->text().toFloat( &ok ) ); | ||
210 | tran->setNumber( numEdit->text() ); | ||
211 | tran->setNotes( noteEdit->text() ); | ||
212 | |||
213 | QDialog::accept(); | ||
214 | } | ||
215 | |||
216 | void Transaction::slotWithdrawalClicked() | ||
217 | { | ||
218 | catList->clear(); | ||
219 | catList->insertItem( tr( "Automobile" ) ); | ||
220 | catList->insertItem( tr( "Bills" ) ); | ||
221 | catList->insertItem( tr( "CDs" ) ); | ||
222 | catList->insertItem( tr( "Clothing" ) ); | ||
223 | catList->insertItem( tr( "Computer" ) ); | ||
224 | catList->insertItem( tr( "DVDs" ) ); | ||
225 | catList->insertItem( tr( "Eletronics" ) ); | ||
226 | catList->insertItem( tr( "Entertainment" ) ); | ||
227 | catList->insertItem( tr( "Food" ) ); | ||
228 | catList->insertItem( tr( "Gasoline" ) ); | ||
229 | catList->insertItem( tr( "Misc" ) ); | ||
230 | catList->insertItem( tr( "Movies" ) ); | ||
231 | catList->insertItem( tr( "Rent" ) ); | ||
232 | catList->insertItem( tr( "Travel" ) ); | ||
233 | catList->setCurrentItem( 0 ); | ||
234 | typeList->clear(); | ||
235 | typeList->insertItem( tr( "Debit Charge" ) ); | ||
236 | typeList->insertItem( tr( "Written Check" ) ); | ||
237 | typeList->insertItem( tr( "Transfer" ) ); | ||
238 | typeList->insertItem( tr( "Credit Card" ) ); | ||
239 | } | ||
240 | |||
241 | void Transaction::slotDepositClicked() | ||
242 | { | ||
243 | catList->clear(); | ||
244 | catList->insertItem( tr( "Work" ) ); | ||
245 | catList->insertItem( tr( "Family Member" ) ); | ||
246 | catList->insertItem( tr( "Misc. Credit" ) ); | ||
247 | catList->setCurrentItem( 0 ); | ||
248 | typeList->clear(); | ||
249 | typeList->insertItem( tr( "Written Check" ) ); | ||
250 | typeList->insertItem( tr( "Automatic Payment" ) ); | ||
251 | typeList->insertItem( tr( "Transfer" ) ); | ||
252 | typeList->insertItem( tr( "Cash" ) ); | ||
253 | } | ||
254 | |||
255 | void Transaction::slotDateChanged( int y, int m, int d ) | ||
256 | { | ||
257 | QDate date; | ||
258 | date.setYMD( y, m, d ); | ||
259 | dateBtn->setText( TimeString::shortDate( date ) ); | ||
260 | } | ||