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