Diffstat (limited to 'noncore/apps/qashmoney/newtransaction.cpp') (more/less context) (ignore whitespace changes)
-rwxr-xr-x | noncore/apps/qashmoney/newtransaction.cpp | 276 |
1 files changed, 276 insertions, 0 deletions
diff --git a/noncore/apps/qashmoney/newtransaction.cpp b/noncore/apps/qashmoney/newtransaction.cpp new file mode 100755 index 0000000..630a8b8 --- a/dev/null +++ b/noncore/apps/qashmoney/newtransaction.cpp | |||
@@ -0,0 +1,276 @@ | |||
1 | #include "newtransaction.h" | ||
2 | #include "calculator.h" | ||
3 | #include "datepicker.h" | ||
4 | #include "memory.h" | ||
5 | #include "budget.h" | ||
6 | |||
7 | #include <qdatetime.h> | ||
8 | #include <qmultilineedit.h> | ||
9 | |||
10 | extern Budget *budget; | ||
11 | extern Preferences *preferences; | ||
12 | |||
13 | NewTransaction::NewTransaction ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) | ||
14 | { | ||
15 | transactiondescription = ""; | ||
16 | currentlineitem = -1; | ||
17 | currentbudget = -1; | ||
18 | dateedited = FALSE; | ||
19 | setCaption( tr( "Transaction" ) ); | ||
20 | |||
21 | // START FIRST COLUMN | ||
22 | |||
23 | namelabel = new QLabel ( "Transaction", this ); | ||
24 | |||
25 | transactionnamebox = new QHBox ( this ); | ||
26 | transactionname = new QComboBox ( transactionnamebox ); | ||
27 | transactionname->setEditable ( TRUE ); | ||
28 | descriptionbutton = new QPushButton ( transactionnamebox ); | ||
29 | descriptionbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/info.png" ) ); | ||
30 | connect ( descriptionbutton, SIGNAL ( released () ), this, SLOT ( addTransactionDescription() ) ); | ||
31 | |||
32 | amountlabel = new QLabel ( "Amount", this ); | ||
33 | |||
34 | transactionamountbox = new QHBox ( this ); | ||
35 | transactionamount = new QLineEdit ( transactionamountbox ); | ||
36 | transactionamount->setAlignment ( Qt::AlignRight ); | ||
37 | transactionamount->setText ( "0.00" ); | ||
38 | calculatorbutton = new QPushButton( transactionamountbox ); | ||
39 | calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); | ||
40 | connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); | ||
41 | |||
42 | datelabel = new QLabel ( "Date", this ); | ||
43 | |||
44 | transactiondatebox = new QHBox ( this ); | ||
45 | transactiondate = new QLineEdit ( transactiondatebox ); | ||
46 | transactiondate->setAlignment ( Qt::AlignRight ); | ||
47 | transactiondate->setDisabled ( TRUE ); | ||
48 | datebutton = new QPushButton( transactiondatebox ); | ||
49 | datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); | ||
50 | connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) ); | ||
51 | |||
52 | clearedcheckbox = new QCheckBox ( "Cleared", this ); | ||
53 | depositbox = new QCheckBox ( "Credit", this ); | ||
54 | |||
55 | // START SECOND COLUMN | ||
56 | |||
57 | numberlabel = new QLabel ( "Number", this ); | ||
58 | transactionnumber = new QLineEdit ( this ); | ||
59 | |||
60 | budgetlabel = new QLabel ( "Budget", this ); | ||
61 | budgetbox = new QComboBox ( FALSE, this ); | ||
62 | |||
63 | lineitemlabel = new QLabel ( "LineItem", this ); | ||
64 | lineitembox = new QComboBox ( FALSE, this ); | ||
65 | |||
66 | layout = new QGridLayout ( this, 7, 2, 2, 2 ); | ||
67 | layout->addWidget ( namelabel, 0, 0, Qt::AlignLeft ); | ||
68 | layout->addWidget ( transactionnamebox, 1, 0, Qt::AlignLeft ); | ||
69 | layout->addWidget ( amountlabel, 2, 0, Qt::AlignLeft ); | ||
70 | layout->addWidget ( transactionamountbox, 3, 0, Qt::AlignLeft ); | ||
71 | layout->addWidget ( datelabel, 4, 0, Qt::AlignLeft ); | ||
72 | layout->addWidget ( transactiondatebox, 5, 0, Qt::AlignLeft ); | ||
73 | layout->addWidget ( clearedcheckbox, 6, 0, Qt::AlignLeft ); | ||
74 | layout->addWidget ( numberlabel, 0, 1, Qt::AlignLeft ); | ||
75 | layout->addWidget ( transactionnumber, 1, 1, Qt::AlignLeft ); | ||
76 | layout->addWidget ( budgetlabel, 2, 1, Qt::AlignLeft ); | ||
77 | layout->addWidget ( budgetbox, 3, 1, Qt::AlignLeft ); | ||
78 | layout->addWidget ( lineitemlabel, 4, 1, Qt::AlignLeft ); | ||
79 | layout->addWidget ( lineitembox, 5, 1, Qt::AlignLeft ); | ||
80 | layout->addWidget ( depositbox, 6, 1, Qt::AlignLeft ); | ||
81 | |||
82 | if ( budget->getNumberOfBudgets() != 0 ) | ||
83 | { | ||
84 | budgetnameslist = budget->getBudgetNames(); | ||
85 | budgetidslist = budget->getBudgetIDs(); | ||
86 | budgetbox->insertStringList ( *budgetnameslist ); | ||
87 | lineitemlabel->setEnabled ( FALSE ); | ||
88 | lineitembox->setEnabled ( FALSE ); | ||
89 | connect ( budgetbox, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentBudget ( int ) ) ); | ||
90 | connect ( lineitembox, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentLineItem ( int ) ) ); | ||
91 | } | ||
92 | else | ||
93 | { | ||
94 | budgetlabel->setEnabled ( FALSE ); | ||
95 | budgetbox->setEnabled ( FALSE ); | ||
96 | lineitemlabel->setEnabled ( FALSE ); | ||
97 | lineitembox->setEnabled ( FALSE ); | ||
98 | } | ||
99 | |||
100 | } | ||
101 | |||
102 | NewTransaction::~NewTransaction () | ||
103 | { | ||
104 | } | ||
105 | |||
106 | void NewTransaction::showCalculator () | ||
107 | { | ||
108 | Calculator *calculator = new Calculator ( this ); | ||
109 | calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); | ||
110 | if ( calculator->exec () == QDialog::Accepted ) | ||
111 | transactionamount->setText ( calculator->display->text() ); | ||
112 | } | ||
113 | |||
114 | void NewTransaction::showCalendar () | ||
115 | { | ||
116 | QDate newDate = QDate::currentDate (); | ||
117 | DatePicker *dp = new DatePicker ( newDate ); | ||
118 | dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); | ||
119 | |||
120 | int response = dp->exec(); | ||
121 | if ( response == QDialog::Accepted ) | ||
122 | { | ||
123 | // Set date integers | ||
124 | year = dp->getYear(); | ||
125 | month = dp->getMonth(); | ||
126 | day = dp->getDay(); | ||
127 | |||
128 | // Set dateedited to TRUE | ||
129 | // This tells the transactiondisplay object that the user edited an transaction | ||
130 | // and did change the date3 | ||
131 | dateedited = TRUE; | ||
132 | |||
133 | // Display date with our selected format | ||
134 | transactiondate->setText ( preferences->getDate ( year, month, day ) ); | ||
135 | } | ||
136 | } | ||
137 | |||
138 | bool NewTransaction::getDateEdited () | ||
139 | { | ||
140 | return dateedited; | ||
141 | } | ||
142 | |||
143 | int NewTransaction::getDay () | ||
144 | { | ||
145 | return day; | ||
146 | } | ||
147 | |||
148 | int NewTransaction::getMonth () | ||
149 | { | ||
150 | return month; | ||
151 | } | ||
152 | |||
153 | int NewTransaction::getYear () | ||
154 | { | ||
155 | return year; | ||
156 | } | ||
157 | |||
158 | QString NewTransaction::getDescription () | ||
159 | { | ||
160 | return transactiondescription; | ||
161 | } | ||
162 | |||
163 | void NewTransaction::setDescription ( QString description ) | ||
164 | { | ||
165 | transactiondescription = description; | ||
166 | } | ||
167 | |||
168 | void NewTransaction::addTransactionDescription () | ||
169 | { | ||
170 | // Function for adding or editing an transaction description. | ||
171 | QDialog *description = new QDialog ( this, "description", TRUE ); | ||
172 | description->setCaption ( "Notes" ); | ||
173 | QMultiLineEdit *enter = new QMultiLineEdit ( description ); | ||
174 | enter->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) ); | ||
175 | enter->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) ); | ||
176 | enter->setWordWrap ( QMultiLineEdit::WidgetWidth ); | ||
177 | if ( transactiondescription != "(NULL)" ) | ||
178 | enter->setText ( transactiondescription ); | ||
179 | if ( description->exec () == QDialog::Accepted ) | ||
180 | transactiondescription = enter->text (); | ||
181 | } | ||
182 | |||
183 | int NewTransaction::getNameIndex ( QString name ) | ||
184 | { | ||
185 | int counter; | ||
186 | int items = transactionname->count(); | ||
187 | for ( counter = 0; ( items - 1 ); counter++ ) | ||
188 | { | ||
189 | if ( name == transactionname->text ( counter ) ) | ||
190 | { | ||
191 | return counter; | ||
192 | break; | ||
193 | } | ||
194 | } | ||
195 | return 0; | ||
196 | } | ||
197 | |||
198 | void NewTransaction::setCurrentBudget ( int index ) | ||
199 | { | ||
200 | if ( index != 0 ) | ||
201 | { | ||
202 | currentbudget = budgetidslist->operator[] ( index - 1 ).toInt(); | ||
203 | lineitemslist = budget->getLineItems ( currentbudget ); | ||
204 | lineitemidslist = budget->getLineItemIDs ( currentbudget ); | ||
205 | lineitemlabel->setEnabled ( TRUE ); | ||
206 | lineitembox->setEnabled ( TRUE ); | ||
207 | lineitembox->clear(); | ||
208 | lineitembox->insertStringList ( lineitemslist ); | ||
209 | setCurrentLineItem ( 0 ); | ||
210 | } | ||
211 | else | ||
212 | { | ||
213 | lineitembox->clear(); | ||
214 | lineitemlabel->setEnabled ( FALSE ); | ||
215 | lineitembox->setEnabled ( FALSE ); | ||
216 | currentlineitem = -1; | ||
217 | currentbudget = -1; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | void NewTransaction::setCurrentLineItem ( int index ) | ||
222 | { | ||
223 | currentlineitem = ( lineitemidslist.operator[] ( index ).toInt() ); | ||
224 | } | ||
225 | |||
226 | int NewTransaction::getCurrentBudget () | ||
227 | { | ||
228 | return currentbudget; | ||
229 | } | ||
230 | |||
231 | int NewTransaction::getBudgetIndex ( int budgetid ) | ||
232 | { | ||
233 | currentbudget = budgetid; | ||
234 | const QString budget = QString::number ( budgetid ); | ||
235 | return budgetidslist->findIndex ( budget ); | ||
236 | } | ||
237 | |||
238 | int NewTransaction::getLineItemIndex ( int lineitemid ) | ||
239 | { | ||
240 | currentlineitem = lineitemid; | ||
241 | const QString lineitem = QString::number ( lineitemid ); | ||
242 | return lineitemidslist.findIndex ( lineitem ); | ||
243 | } | ||
244 | |||
245 | void NewTransaction::setLineItems () | ||
246 | { | ||
247 | lineitemslist = budget->getLineItems ( currentbudget ); | ||
248 | lineitemidslist = budget->getLineItemIDs ( currentbudget ); | ||
249 | lineitemlabel->setEnabled ( TRUE ); | ||
250 | lineitembox->setEnabled ( TRUE ); | ||
251 | lineitembox->clear(); | ||
252 | lineitembox->insertStringList ( lineitemslist ); | ||
253 | } | ||
254 | |||
255 | int NewTransaction::getCurrentLineItem () | ||
256 | { | ||
257 | return currentlineitem; | ||
258 | } | ||
259 | |||
260 | void NewTransaction::setComboBoxes ( int budgetid, int lineitemid ) | ||
261 | { | ||
262 | const QString budgetname = QString::number ( budgetid ); | ||
263 | budgetbox->setCurrentItem ( ( budgetidslist->findIndex ( budgetname ) ) ); | ||
264 | currentbudget = budgetidslist->operator[] ( budgetbox->currentItem() - 1 ).toInt(); | ||
265 | |||
266 | lineitemslist = budget->getLineItems ( currentbudget ); | ||
267 | lineitemidslist = budget->getLineItemIDs ( currentbudget ); | ||
268 | lineitemlabel->setEnabled ( TRUE ); | ||
269 | lineitembox->setEnabled ( TRUE ); | ||
270 | lineitembox->clear(); | ||
271 | lineitembox->insertStringList ( lineitemslist ); | ||
272 | |||
273 | const QString lineitem = QString::number ( lineitemid ); | ||
274 | lineitembox->setCurrentItem ( lineitemidslist.findIndex ( lineitem ) ); | ||
275 | currentlineitem = ( lineitemidslist.operator[] ( lineitembox->currentItem() ).toInt() ); | ||
276 | } | ||