summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/qcheckentry.cpp
Unidiff
Diffstat (limited to 'noncore/apps/checkbook/qcheckentry.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/qcheckentry.cpp251
1 files changed, 251 insertions, 0 deletions
diff --git a/noncore/apps/checkbook/qcheckentry.cpp b/noncore/apps/checkbook/qcheckentry.cpp
new file mode 100644
index 0000000..9ff02c9
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckentry.cpp
@@ -0,0 +1,251 @@
1#include "qcheckentry.h"
2
3QCheckEntry::QCheckEntry()
4 : QCheckEntryBase()
5{
6 connect(transAmount, SIGNAL(textChanged(const QString &)), this, SLOT(amountChanged(const QString &)));
7 connect(transFee, SIGNAL(textChanged(const QString &)), this, SLOT(transFeeChanged(const QString &)));
8 connect(payment, SIGNAL(clicked()), this, SLOT(paymentClicked()));
9 connect(deposit, SIGNAL(clicked()), this, SLOT(depositClicked()));
10
11 QString todaysdate = QString::number(QDate::currentDate().month());
12 todaysdate.append("/");
13 todaysdate.append(QString::number(QDate::currentDate().day()));
14 todaysdate.append("/");
15 todaysdate.append(QString::number(QDate::currentDate().year()));
16 dateEdit->setText(todaysdate);
17
18 descriptionCombo->setFocus();
19
20 dateEdit->setValidChars("0123456789./-");
21 dateEdit->setMaxLength(10);
22
23 descriptionCombo->lineEdit()->setMaxLength(30);
24
25 checkNumber->setValidChars("0123456789-");
26 checkNumber->setMaxLength(10);
27
28 transAmount->setValidChars("0123456789.");
29
30 transFee->setMaxLength(5);
31 transFee->setValidChars("0123456789.");
32}
33
34void QCheckEntry::paymentClicked()
35{
36 cmbCategory->clear();
37 cmbCategory->insertItem( tr( "Automobile" ) );
38 cmbCategory->insertItem( tr( "Bills" ) );
39 cmbCategory->insertItem( tr( "CDs" ) );
40 cmbCategory->insertItem( tr( "Clothing" ) );
41 cmbCategory->insertItem( tr( "Computer" ) );
42 cmbCategory->insertItem( tr( "DVDs" ) );
43 cmbCategory->insertItem( tr( "Eletronics" ) );
44 cmbCategory->insertItem( tr( "Entertainment" ) );
45 cmbCategory->insertItem( tr( "Food" ) );
46 cmbCategory->insertItem( tr( "Gasoline" ) );
47 cmbCategory->insertItem( tr( "Misc" ) );
48 cmbCategory->insertItem( tr( "Movies" ) );
49 cmbCategory->insertItem( tr( "Rent" ) );
50 cmbCategory->insertItem( tr( "Travel" ) );
51 cmbCategory->setCurrentItem( 0 );
52 transType->clear();
53 transType->insertItem( tr( "Debit Charge" ) );
54 transType->insertItem( tr( "Written Check" ) );
55 transType->insertItem( tr( "Transfer" ) );
56 transType->insertItem( tr( "Credit Card" ) );
57}
58
59void QCheckEntry::depositClicked()
60{
61 cmbCategory->clear();
62 cmbCategory->insertItem( tr( "Work" ) );
63 cmbCategory->insertItem( tr( "Family Member" ) );
64 cmbCategory->insertItem( tr( "Misc. Credit" ) );
65 cmbCategory->setCurrentItem( 0 );
66 transType->clear();
67 transType->insertItem( tr( "Written Check" ) );
68 transType->insertItem( tr( "Automatic Payment" ) );
69 transType->insertItem( tr( "Transfer" ) );
70 transType->insertItem( tr( "Cash" ) );
71}
72
73QStringList QCheckEntry::popupEntry(const QStringList &originaldata)
74{
75 QCheckEntry qce;
76
77 // This is how the list looks:
78 // 0: true or false, true == payment, false == deposit
79 // 1: description of the transaction
80 // 2: category name
81 // 3: transaction type (stores the integer value of the index of the combobox)
82 // 4: check number of the transaction (if any)
83 // 5: transaction amount
84 // 6: transaction fee (e.g. service charge, or ATM charge).
85 // 7: date of the transaction
86 // 8: additional notes
87 // 9: recently used descriptions
88 if (originaldata.count() > 1)
89 {
90 if (originaldata[0] == "true")
91 {
92 qce.payment->setChecked(true);
93 qce.paymentClicked();
94 } else {
95 if (originaldata[0] == "false")
96 {
97 qce.deposit->setChecked(true);
98 qce.depositClicked();
99 }
100 }
101 qce.descriptionCombo->lineEdit()->setText(originaldata[1]);
102 qce.cmbCategory->lineEdit()->setText(originaldata[2]);
103 qce.transType->setCurrentItem(originaldata[3].toInt());
104 qce.checkNumber->setText(originaldata[4]);
105 qce.transAmount->setText(originaldata[5]);
106 qce.transFee->setText(originaldata[6]);
107 qce.dateEdit->setText(originaldata[7]);
108 qce.additionalNotes->setText(originaldata[8]);
109 QStringList recentlist;
110 if (!originaldata[9].isEmpty())
111 {
112 recentlist = QStringList::split(',', originaldata[9], false);
113 }
114 if (!recentlist.isEmpty())
115 {
116 qce.descriptionCombo->insertStringList(recentlist);
117 }
118 } else {
119 QStringList recentlist;
120 if (!originaldata[0].isEmpty())
121 {
122 recentlist = QStringList::split(',', originaldata[0], false);
123 }
124 if (!recentlist.isEmpty())
125 {
126 qce.descriptionCombo->insertStringList(recentlist);
127 }
128 }
129
130 qce.setWFlags(Qt::WType_Modal);
131 qce.showMaximized();
132
133 qce.descriptionCombo->lineEdit()->clear();
134
135 if (qce.exec() == QDialog::Accepted)
136 {
137 // Validate that the user has inputed a valid dollar amount
138 if (qce.transFee->text().contains('.') == 0)
139 {
140 QString text = qce.transFee->text();
141 text.append(".00");
142 qce.transFee->setText(text);
143 } else {
144 QString tmp = qce.transFee->text();
145 if (tmp.mid(tmp.find('.'), tmp.length()).length() == 1)
146 {
147 tmp.append("00");
148 qce.transFee->setText(tmp);
149 } else {
150 if (tmp.mid(tmp.find('.'), tmp.length()).length() == 2)
151 {
152 tmp.append("0");
153 qce.transFee->setText(tmp);
154 }
155 }
156 }
157 if (qce.transAmount->text().contains('.') == 0)
158 {
159 QString text = qce.transAmount->text();
160 text.append(".00");
161 qce.transAmount->setText(text);
162 } else {
163 QString tmp = qce.transAmount->text();
164 if (tmp.mid(tmp.find('.'), tmp.length()).length() == 1)
165 {
166 tmp.append("00");
167 qce.transAmount->setText(tmp);
168 } else {
169 if (tmp.mid(tmp.find('.'), tmp.length()).length() == 2)
170 {
171 tmp.append("0");
172 qce.transAmount->setText(tmp);
173 }
174 }
175 }
176
177 QString recent;
178 if (qce.descriptionCombo->count() != 0)
179 {
180 QStringList recentlist = QStringList::split(',', originaldata[9], false);
181 if (recentlist.count() >= 10)
182 {
183 recentlist.remove(recentlist.last());
184 }
185 recentlist.prepend(qce.descriptionCombo->lineEdit()->text());
186 recent = recentlist.join(",");
187 } else {
188 recent = qce.descriptionCombo->lineEdit()->text();
189 }
190
191 QString checkNumberString = qce.checkNumber->text();
192 if (checkNumberString.isEmpty() == true)
193 {
194 checkNumberString = "0";
195 }
196
197 QString paymentChecked = "true";
198 if (qce.payment->isChecked() == false)
199 {
200 paymentChecked = "false";
201 }
202 QStringList returnvalue;
203 returnvalue << paymentChecked << qce.descriptionCombo->lineEdit()->text() << qce.cmbCategory->lineEdit()->text() << QString::number(qce.transType->currentItem()) << checkNumberString << qce.transAmount->text() << qce.transFee->text() << qce.dateEdit->text() << qce.additionalNotes->text() << recent;
204 return returnvalue;
205 } else {
206 QStringList blank;
207 return blank;
208 }
209}
210
211void QCheckEntry::transFeeChanged(const QString &input)
212{
213 QString tmpinput = input;
214 if (tmpinput.contains('.') > 1)
215 {
216 int first = tmpinput.find('.');
217 tmpinput = tmpinput.remove(tmpinput.find('.', (first + 1)), 1);
218 }
219 if (tmpinput.contains(QRegExp("\\.[0-9][0-9]{2}$")) >= 1)
220 {
221 tmpinput = tmpinput.remove((tmpinput.length() - 1), 1);
222 }
223 transFee->setText(tmpinput);
224}
225
226void QCheckEntry::amountChanged(const QString &input)
227{
228 QString tmpinput = input;
229 if (tmpinput.contains('.') > 1)
230 {
231 int first = tmpinput.find('.');
232 tmpinput = tmpinput.remove(tmpinput.find('.', (first + 1)), 1);
233 }
234 if (tmpinput.contains(QRegExp("\\.[0-9][0-9]{2}$")) >= 1)
235 {
236 tmpinput = tmpinput.remove((tmpinput.length() - 1), 1);
237 }
238 transAmount->setText(tmpinput);
239}
240
241void QCheckEntry::accept()
242{
243 // Does the description combo not have any text in it? Do something if it doesn't!
244 if (descriptionCombo->lineEdit()->text().isEmpty() == true)
245 {
246 QMessageBox::critical(this, "Field Missing.", "<qt>You didn't enter a description for this transaction. Please fill out the \"Transaction Description\" field and try again.</qt>");
247 descriptionCombo->setFocus();
248 return;
249 }
250 QDialog::accept();
251}