Diffstat (limited to 'noncore/unsupported/qashmoney/qashmoney.cpp') (more/less context) (ignore whitespace changes)
-rwxr-xr-x | noncore/unsupported/qashmoney/qashmoney.cpp | 402 |
1 files changed, 402 insertions, 0 deletions
diff --git a/noncore/unsupported/qashmoney/qashmoney.cpp b/noncore/unsupported/qashmoney/qashmoney.cpp new file mode 100755 index 0000000..1455eb0 --- a/dev/null +++ b/noncore/unsupported/qashmoney/qashmoney.cpp | |||
@@ -0,0 +1,402 @@ | |||
1 | #include "qashmoney.h" | ||
2 | #include "preferencedialogs.h" | ||
3 | #include "memorydialog.h" | ||
4 | |||
5 | #include <qheader.h> | ||
6 | |||
7 | Budget *budget = new Budget (); | ||
8 | Preferences *preferences = new Preferences (); | ||
9 | Account *account = new Account (); | ||
10 | Transaction *transaction = new Transaction (); | ||
11 | Transfer *transfer = new Transfer (); | ||
12 | Memory *memory = new Memory (); | ||
13 | |||
14 | QashMoney::QashMoney () : QWidget () | ||
15 | { | ||
16 | preferences->addPreferences (); | ||
17 | preferences->initializeColumnPreferences (); | ||
18 | preferences->initializeSortingPreferences (); | ||
19 | |||
20 | // set the text in the upper part of the frame | ||
21 | setCaption ( tr ( "QashMoney" ) ); | ||
22 | |||
23 | // Create new menubar for our mainwindow | ||
24 | // and add menu items | ||
25 | mainmenu = new QMenuBar ( this ); | ||
26 | mainmenu->setFrameStyle ( QFrame::PopupPanel | QFrame::Raised ); | ||
27 | preferencesmenu = new QPopupMenu ( this ); | ||
28 | utilitiesmenu = new QPopupMenu ( this ); | ||
29 | mainmenu->insertItem ( "Preferences", preferencesmenu ); | ||
30 | mainmenu->insertItem ( "Utilities", utilitiesmenu ); | ||
31 | preferencesmenu->insertItem ( "Date", this, SLOT ( displayDatePreferencesDialog() ) ); | ||
32 | preferencesmenu->insertItem ( "Account", this, SLOT ( displayAccountPreferencesDialog() ) ); | ||
33 | preferencesmenu->insertItem ( "Transaction", this, SLOT ( displayTransactionPreferencesDialog() ) ); | ||
34 | utilitiesmenu->insertItem ( "Memory", this, SLOT ( displayMemoryDialog() ) ); | ||
35 | |||
36 | // create the main tabwidget for displaying accounts and transactions | ||
37 | maintabs = new QTabWidget ( this ); | ||
38 | tab = new QWidget ( this ); | ||
39 | tab_2 = new QWidget ( this ); | ||
40 | tab_3 = new QWidget ( this ); | ||
41 | maintabs->addTab ( tab, "Accounts" ); | ||
42 | maintabs->addTab ( tab_2, "Transactions" ); | ||
43 | maintabs->addTab ( tab_3, "Budgets" ); | ||
44 | tabheight = tab->height(); | ||
45 | maintabs->setTabEnabled ( tab_2, FALSE ); | ||
46 | |||
47 | // create a new account display object | ||
48 | accountdisplay = new AccountDisplay ( maintabs ); | ||
49 | accountdisplay->setTabs ( tab_2, maintabs ); | ||
50 | connect ( accountdisplay->listview, SIGNAL ( selectionChanged() ), this, SLOT ( setTransactionTab() ) ); | ||
51 | |||
52 | // set the connection to disable the one touch account viewing if we are transfering money | ||
53 | connect ( accountdisplay->transferbutton, SIGNAL ( toggled(bool) ), this, SLOT ( toggleOneTouchViewing(bool) ) ); | ||
54 | |||
55 | // create a new transactiondisplay object | ||
56 | transactiondisplay = new TransactionDisplay ( maintabs ); | ||
57 | transactiondisplay->hide(); | ||
58 | |||
59 | // create new budgetdisplay object | ||
60 | budgetdisplay = new BudgetDisplay ( maintabs ); | ||
61 | budgetdisplay->hide(); | ||
62 | |||
63 | tabslayout = new QVBoxLayout ( maintabs, 4, 2 ); | ||
64 | tabslayout->addSpacing ( tabheight ); | ||
65 | tabslayout->addWidget ( accountdisplay ); | ||
66 | tabslayout->addWidget ( transactiondisplay ); | ||
67 | tabslayout->addWidget ( budgetdisplay ); | ||
68 | |||
69 | // connect a change in the maintabs with changing the tab display | ||
70 | connect ( maintabs, SIGNAL ( currentChanged(QWidget*) ), this, SLOT ( changeTabDisplay() ) ); | ||
71 | |||
72 | // create layout that will contain the menubar and the maintabs | ||
73 | layout = new QVBoxLayout ( this, 2, 2 ); | ||
74 | layout->setMenuBar ( mainmenu ); | ||
75 | layout->addWidget ( maintabs ); | ||
76 | } | ||
77 | |||
78 | QashMoney::~QashMoney () | ||
79 | { | ||
80 | delete budget; | ||
81 | delete preferences; | ||
82 | delete account; | ||
83 | delete transaction; | ||
84 | delete transfer; | ||
85 | delete memory; | ||
86 | } | ||
87 | |||
88 | void QashMoney::changeTabDisplay () | ||
89 | { | ||
90 | // if the user pressed the transactions tab, hide the account display | ||
91 | // object and create a new transaction display | ||
92 | if ( maintabs->currentPageIndex() == 1 ) | ||
93 | { | ||
94 | // initialize variables | ||
95 | bool children = FALSE; | ||
96 | |||
97 | // hide the account display and define accountid | ||
98 | int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt(); | ||
99 | |||
100 | //remove all the columns from the transactiondisplay | ||
101 | int columns = transactiondisplay->listview->columns(); | ||
102 | int counter; | ||
103 | for ( counter = 0; counter <= columns; counter++ ) | ||
104 | transactiondisplay->listview->removeColumn ( 0 ); | ||
105 | |||
106 | // set the account name and account balance | ||
107 | QString name = account->getAccountName ( accountid ); | ||
108 | QString balance = account->getAccountBalance ( accountid ); | ||
109 | transactiondisplay->name->setText ( name ); | ||
110 | transactiondisplay->balance->setText ( balance ); | ||
111 | |||
112 | // clear the limitbox | ||
113 | transactiondisplay->limitbox->clear(); | ||
114 | |||
115 | // get parent account id | ||
116 | int parentaccountid = account->getParentAccountID ( accountid ); | ||
117 | |||
118 | // add columns based on which account is selected | ||
119 | // this first if determines if we selected a parent with no children or a child | ||
120 | // in these cases, we add standard three columns for date, transaction, amount | ||
121 | transactiondisplay->listview->addColumn ( "Date", 0 ); | ||
122 | transactiondisplay->listview->addColumn ( "Transaction", 0 ); | ||
123 | transactiondisplay->listview->addColumn ( "Amt", 0); | ||
124 | transactiondisplay->listview->setColumnAlignment ( 2, Qt::AlignRight ); | ||
125 | transactiondisplay->listview->addColumn ( "", 0 ); | ||
126 | |||
127 | if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) // we selected a parent with children | ||
128 | { | ||
129 | // add an extra column for the account name for eac child transaction | ||
130 | transactiondisplay->listview->addColumn ( "Acct", 0 ); | ||
131 | children = TRUE; | ||
132 | |||
133 | // hide the new transaction button | ||
134 | transactiondisplay->newtransaction->setEnabled ( FALSE ); | ||
135 | } | ||
136 | else //we selected a parent without children or a child | ||
137 | transactiondisplay->newtransaction->setEnabled ( TRUE ); | ||
138 | |||
139 | // disable the transactionid column so it can't be red | ||
140 | transactiondisplay->listview->header()->setResizeEnabled ( FALSE, 3 ); | ||
141 | |||
142 | // set the accountid and children variables | ||
143 | transactiondisplay->setChildren ( children ); | ||
144 | transactiondisplay->setAccountID ( accountid ); | ||
145 | |||
146 | setTransactionDisplayDate (); | ||
147 | |||
148 | // display transactions | ||
149 | transactiondisplay->listview->clear(); | ||
150 | QString displaytext = "%"; | ||
151 | displaytext.prepend ( transactiondisplay->limitbox->text() ); | ||
152 | if ( transaction->getNumberOfTransactions() > 0 ) | ||
153 | transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate ); | ||
154 | |||
155 | // display transfers | ||
156 | transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate ); | ||
157 | |||
158 | // open a new preferences object and resize the transaction display columns | ||
159 | // each column will have a different size based on whether we are looking at a child | ||
160 | // account or children through a parent | ||
161 | if ( parentaccountid != -1 || accountdisplay->listview->selectedItem()->childCount() == 0 ) // a parent with no children or a child - three columns | ||
162 | { | ||
163 | transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 3 ) ); // normal transaction date width | ||
164 | transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual ); | ||
165 | transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 4 ) ); // normal transaction name width | ||
166 | transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual ); | ||
167 | transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 5 ) ); // normal transaction amount width | ||
168 | transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual ); | ||
169 | } | ||
170 | else | ||
171 | { | ||
172 | transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 6 ) ); // extended transaction date width | ||
173 | transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual ); | ||
174 | transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 7 ) ); // extended transaction name width | ||
175 | transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual ); | ||
176 | transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 8 ) ); // extended transaction amount width | ||
177 | transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual ); | ||
178 | transactiondisplay->listview->setColumnWidth ( 4, preferences->getColumnPreference ( 9 ) ); // transaction account width | ||
179 | transactiondisplay->listview->setColumnWidthMode ( 4, QListView::Manual ); | ||
180 | } | ||
181 | |||
182 | // pull the column sorting preference from the preferences table, and configure the listview accordingly | ||
183 | int column = 0; | ||
184 | int direction = 0; | ||
185 | preferences->getSortingPreference ( 2, &column, &direction ); | ||
186 | transactiondisplay->listview->setSorting ( column, direction ); | ||
187 | |||
188 | // show the window | ||
189 | transactiondisplay->show(); | ||
190 | // hide the account display and define accountid | ||
191 | accountdisplay->hide(); | ||
192 | // hide the budget display | ||
193 | budgetdisplay->hide(); | ||
194 | } | ||
195 | else if ( maintabs->currentPageIndex() == 0 ) | ||
196 | { | ||
197 | disableOneTouchViewing(); | ||
198 | |||
199 | // clear the account display selection | ||
200 | accountdisplay->listview->clearSelection(); | ||
201 | |||
202 | // resize the account display columns | ||
203 | accountdisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) ); | ||
204 | accountdisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) ); | ||
205 | |||
206 | // set sorting preference on account display columns | ||
207 | int column = 0; | ||
208 | int direction = 0; | ||
209 | preferences->getSortingPreference ( 1, &column, &direction ); | ||
210 | accountdisplay->listview->setSorting ( column, direction ); | ||
211 | |||
212 | // display the accounts | ||
213 | if ( account->getNumberOfAccounts() != 0 ) | ||
214 | account->displayAccounts ( accountdisplay->listview ); | ||
215 | maintabs->setTabEnabled ( tab_2, FALSE ); | ||
216 | |||
217 | // set the toggle button | ||
218 | accountdisplay->setToggleButton (); | ||
219 | |||
220 | // show the account display | ||
221 | accountdisplay->show(); | ||
222 | |||
223 | // hide the transaction display | ||
224 | transactiondisplay->hide(); | ||
225 | |||
226 | // hide the budget display | ||
227 | budgetdisplay->hide(); | ||
228 | |||
229 | |||
230 | enableOneTouchViewing (); | ||
231 | } | ||
232 | else | ||
233 | { | ||
234 | budgetdisplay->displayLineItems(); | ||
235 | budgetdisplay->show(); | ||
236 | transactiondisplay->hide(); | ||
237 | accountdisplay->hide(); | ||
238 | } | ||
239 | } | ||
240 | |||
241 | void QashMoney::setTransactionTab () | ||
242 | { | ||
243 | if ( accountdisplay->listview->selectedItem() == 0 ) | ||
244 | maintabs->setTabEnabled ( tab_2, FALSE ); | ||
245 | else | ||
246 | maintabs->setTabEnabled ( tab_2, TRUE ); | ||
247 | } | ||
248 | |||
249 | void QashMoney::displayDatePreferencesDialog () | ||
250 | { | ||
251 | // this shows a dialog to set preferences for formatting the date | ||
252 | DatePreferences *pd = new DatePreferences ( this ); | ||
253 | pd->exec (); | ||
254 | if ( transactiondisplay->isVisible() ) | ||
255 | { | ||
256 | // set the account id | ||
257 | int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt(); | ||
258 | |||
259 | // set children so we can let displayTransfers know if there are children for the selected account | ||
260 | bool children; | ||
261 | if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) | ||
262 | children = TRUE; | ||
263 | else | ||
264 | children = FALSE; | ||
265 | |||
266 | // redisplay transactions if they are visible incorporating | ||
267 | // any changes to the date format | ||
268 | transactiondisplay->listview->clear(); | ||
269 | QString displaytext = "%"; | ||
270 | displaytext.prepend ( transactiondisplay->limitbox->text() ); | ||
271 | |||
272 | setTransactionDisplayDate(); | ||
273 | if ( transaction->getNumberOfTransactions() > 0 ) | ||
274 | transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate ); | ||
275 | |||
276 | if ( transfer->getNumberOfTransfers() != 0 ) | ||
277 | transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate ); | ||
278 | } | ||
279 | else if ( accountdisplay->isVisible() ) | ||
280 | { | ||
281 | accountdisplay->listview->clearSelection(); | ||
282 | maintabs->setTabEnabled ( tab_2, FALSE ); | ||
283 | } | ||
284 | else | ||
285 | budgetdisplay->updateBudgetInformation(); | ||
286 | } | ||
287 | |||
288 | void QashMoney::displayTransactionPreferencesDialog () | ||
289 | { | ||
290 | // display a dialog for setting preferences for transactions | ||
291 | TransactionPreferences *td = new TransactionPreferences ( this ); | ||
292 | td->exec (); | ||
293 | if ( transactiondisplay->isVisible() ) | ||
294 | { | ||
295 | // set the account id | ||
296 | int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt(); | ||
297 | |||
298 | // set children so we can let displayTransfers know if there are children for the selected account | ||
299 | bool children; | ||
300 | if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) | ||
301 | children = TRUE; | ||
302 | else | ||
303 | children = FALSE; | ||
304 | |||
305 | // redisplay transactions incorporating any transaction preference changes | ||
306 | transactiondisplay->listview->clear(); | ||
307 | QString displaytext = "%"; | ||
308 | displaytext.prepend ( transactiondisplay->limitbox->text() ); | ||
309 | |||
310 | setTransactionDisplayDate(); | ||
311 | if ( transaction->getNumberOfTransactions() > 0 ) | ||
312 | transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate ); | ||
313 | |||
314 | if ( transfer->getNumberOfTransfers() != 0 ) | ||
315 | transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate ); | ||
316 | } | ||
317 | else | ||
318 | { | ||
319 | accountdisplay->listview->clearSelection(); | ||
320 | maintabs->setTabEnabled ( tab_2, FALSE ); | ||
321 | } | ||
322 | } | ||
323 | |||
324 | void QashMoney::displayAccountPreferencesDialog () | ||
325 | { | ||
326 | // display a dialog for setting preferences for accounts | ||
327 | AccountPreferences *ap = new AccountPreferences ( this ); | ||
328 | ap->exec (); | ||
329 | |||
330 | if ( accountdisplay->isVisible() && account->getNumberOfAccounts() != 0 ) | ||
331 | { | ||
332 | accountdisplay->listview->clear(); | ||
333 | account->displayAccounts ( accountdisplay->listview ); | ||
334 | accountdisplay->listview->clearSelection(); | ||
335 | maintabs->setTabEnabled ( tab_2, FALSE ); | ||
336 | } | ||
337 | changeTabDisplay(); | ||
338 | } | ||
339 | |||
340 | void QashMoney::displayMemoryDialog () | ||
341 | { | ||
342 | // opens a dialog to add, edit and delete memory items | ||
343 | MemoryDialog *md = new MemoryDialog (); | ||
344 | md->exec(); | ||
345 | } | ||
346 | |||
347 | void QashMoney::showTransactions () | ||
348 | { | ||
349 | maintabs->setCurrentPage ( 1 ); | ||
350 | } | ||
351 | |||
352 | void QashMoney::enableOneTouchViewing () | ||
353 | { | ||
354 | if ( preferences->getPreference ( 5 ) == 1 ) | ||
355 | connect ( accountdisplay->listview, SIGNAL ( selectionChanged() ), this, SLOT ( showTransactions() ) ); | ||
356 | else | ||
357 | disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged() ), this, SLOT ( showTransactions() ) ); | ||
358 | } | ||
359 | |||
360 | void QashMoney::disableOneTouchViewing () | ||
361 | { | ||
362 | disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged() ), this, SLOT ( showTransactions() ) ); | ||
363 | } | ||
364 | |||
365 | void QashMoney::toggleOneTouchViewing ( bool state ) | ||
366 | { | ||
367 | if ( state == TRUE ) | ||
368 | disableOneTouchViewing(); | ||
369 | else | ||
370 | enableOneTouchViewing(); | ||
371 | } | ||
372 | |||
373 | void QashMoney::setTransactionDisplayDate () | ||
374 | { | ||
375 | // determine how many days of transactions to show | ||
376 | int limittype = preferences->getPreference ( 7 ); | ||
377 | if ( limittype != 5 ) // set today's date if we are not showing all transactions | ||
378 | { | ||
379 | QDate today = QDate::currentDate (); | ||
380 | switch ( limittype ) // if we are not showing all transactions | ||
381 | { | ||
382 | case 0: // viewing two weeks | ||
383 | newdate = today.addDays ( -14 ); | ||
384 | break; | ||
385 | case 1: // viewing one month | ||
386 | newdate = today.addDays ( -30 ); | ||
387 | break; | ||
388 | case 2: // three months | ||
389 | newdate = today.addDays ( -90 ); | ||
390 | break; | ||
391 | case 3: // six months | ||
392 | newdate = today.addDays ( -180 ); | ||
393 | break; | ||
394 | case 4: // one year | ||
395 | newdate = today.addDays ( -365 ); | ||
396 | break; | ||
397 | } | ||
398 | } | ||
399 | else | ||
400 | newdate = QDate ( 1900, 1, 1 ); | ||
401 | } | ||
402 | |||