summaryrefslogtreecommitdiff
path: root/noncore/apps/qashmoney/qashmoney.cpp
Unidiff
Diffstat (limited to 'noncore/apps/qashmoney/qashmoney.cpp') (more/less context) (ignore whitespace changes)
-rwxr-xr-xnoncore/apps/qashmoney/qashmoney.cpp356
1 files changed, 356 insertions, 0 deletions
diff --git a/noncore/apps/qashmoney/qashmoney.cpp b/noncore/apps/qashmoney/qashmoney.cpp
new file mode 100755
index 0000000..1ea358c
--- a/dev/null
+++ b/noncore/apps/qashmoney/qashmoney.cpp
@@ -0,0 +1,356 @@
1#include "qashmoney.h"
2#include "preferencedialogs.h"
3#include "memorydialog.h"
4
5#include <qheader.h>
6#include <iostream.h>
7
8Budget *budget = new Budget ();
9Preferences *preferences = new Preferences ();
10Account *account = new Account ();
11Transaction *transaction = new Transaction ();
12Transfer *transfer = new Transfer ();
13Memory *memory = new Memory ();
14
15QashMoney::QashMoney () : QWidget ()
16 {
17 preferences->addPreferences();
18 preferences->initializeColumnPreferences ();
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 QPEMenuBar ( 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
78QashMoney::~QashMoney ()
79 {
80 delete budget;
81 delete preferences;
82 delete account;
83 delete transaction;
84 delete transfer;
85 delete memory;
86 }
87
88void 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 // display transactions
147 transactiondisplay->listview->clear();
148 QString displaytext = "%";
149 displaytext.prepend ( transactiondisplay->limitbox->text() );
150 if ( transaction->getNumberOfTransactions() > 0 )
151 transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext );
152
153 // display transfers
154 transfer->displayTransfers ( transactiondisplay->listview, accountid, children );
155
156 // open a new preferences object and resize the transaction display columns
157 // each column will have a different size based on whether we are looking at a child
158 // account or children through a parent
159 if ( parentaccountid != -1 || accountdisplay->listview->selectedItem()->childCount() == 0 ) // a parent with no children or a child - three columns
160 {
161 transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 3 ) ); // normal transaction date width
162 transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual );
163 transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 4 ) ); // normal transaction name width
164 transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual );
165 transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 5 ) ); // normal transaction amount width
166 transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual );
167 }
168 else
169 {
170 transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 6 ) ); // extended transaction date width
171 transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual );
172 transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 7 ) ); // extended transaction name width
173 transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual );
174 transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 8 ) ); // extended transaction amount width
175 transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual );
176 transactiondisplay->listview->setColumnWidth ( 4, preferences->getColumnPreference ( 9 ) ); // transaction account width
177 transactiondisplay->listview->setColumnWidthMode ( 4, QListView::Manual );
178 }
179
180 // show the window
181 transactiondisplay->show();
182 // hide the account display and define accountid
183 accountdisplay->hide();
184 // hide the budget display
185 budgetdisplay->hide();
186 }
187 else if ( maintabs->currentPageIndex() == 0 )
188 {
189 disableOneTouchViewing();
190
191 // clear the account display selection
192 accountdisplay->listview->clearSelection();
193
194 // resize the account display columns
195 accountdisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) );
196 accountdisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) );
197
198 // display the accounts
199 if ( account->getNumberOfAccounts() != 0 )
200 account->displayAccounts ( accountdisplay->listview );
201 maintabs->setTabEnabled ( tab_2, FALSE );
202
203 // set the toggle button
204 accountdisplay->setToggleButton ();
205
206 // show the account display
207 accountdisplay->show();
208
209 // hide the transaction display
210 transactiondisplay->hide();
211
212 // hide the budget display
213 budgetdisplay->hide();
214
215
216 enableOneTouchViewing ();
217 }
218 else
219 {
220 budgetdisplay->displayLineItems();
221 budgetdisplay->show();
222 transactiondisplay->hide();
223 accountdisplay->hide();
224 }
225 }
226
227void QashMoney::setTransactionTab ()
228 {
229 if ( accountdisplay->listview->selectedItem() == 0 )
230 maintabs->setTabEnabled ( tab_2, FALSE );
231 else
232 maintabs->setTabEnabled ( tab_2, TRUE );
233 }
234
235void QashMoney::displayDatePreferencesDialog ()
236 {
237 // this shows a dialog to set preferences for formatting the date
238 DatePreferences *pd = new DatePreferences ( this );
239 pd->exec ();
240 if ( transactiondisplay->isVisible() )
241 {
242 // set the account id
243 int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt();
244
245 // set children so we can let displayTransfers know if there are children for the selected account
246 bool children;
247 if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 )
248 children = TRUE;
249 else
250 children = FALSE;
251
252 // redisplay transactions if they are visible incorporating
253 // any changes to the date format
254 transactiondisplay->listview->clear();
255 QString displaytext = "%";
256 displaytext.prepend ( transactiondisplay->limitbox->text() );
257 if ( transaction->getNumberOfTransactions() > 0 )
258 transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext );
259
260 if ( transfer->getNumberOfTransfers() != 0 )
261 transfer->displayTransfers ( transactiondisplay->listview, accountid, children );
262 }
263 else if ( accountdisplay->isVisible() )
264 {
265 accountdisplay->listview->clearSelection();
266 maintabs->setTabEnabled ( tab_2, FALSE );
267 }
268 else
269 budgetdisplay->updateBudgetInformation();
270 }
271
272void QashMoney::displayTransactionPreferencesDialog ()
273 {
274 // display a dialog for setting preferences for transactions
275 TransactionPreferences *td = new TransactionPreferences ( this );
276 td->exec ();
277 if ( transactiondisplay->isVisible() )
278 {
279 // set the account id
280 int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt();
281
282 // set children so we can let displayTransfers know if there are children for the selected account
283 bool children;
284 if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 )
285 children = TRUE;
286 else
287 children = FALSE;
288
289 // redisplay transactions incorporating any transaction preference changes
290 transactiondisplay->listview->clear();
291 QString displaytext = "%";
292 displaytext.prepend ( transactiondisplay->limitbox->text() );
293 if ( transaction->getNumberOfTransactions() > 0 )
294 transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext );
295
296 if ( transfer->getNumberOfTransfers() != 0 )
297 transfer->displayTransfers ( transactiondisplay->listview, accountid, children );
298 }
299 else
300 {
301 accountdisplay->listview->clearSelection();
302 maintabs->setTabEnabled ( tab_2, FALSE );
303 }
304 }
305
306void QashMoney::displayAccountPreferencesDialog ()
307 {
308 // display a dialog for setting preferences for accounts
309 AccountPreferences *ap = new AccountPreferences ( this );
310 ap->exec ();
311
312 if ( accountdisplay->isVisible() && account->getNumberOfAccounts() != 0 )
313 {
314 accountdisplay->listview->clear();
315 account->displayAccounts ( accountdisplay->listview );
316 accountdisplay->listview->clearSelection();
317 maintabs->setTabEnabled ( tab_2, FALSE );
318 }
319 changeTabDisplay();
320 }
321
322void QashMoney::displayMemoryDialog ()
323 {
324 // opens a dialog to add, edit and delete memory items
325 MemoryDialog *md = new MemoryDialog ();
326 md->exec();
327 }
328
329void QashMoney::showTransactions ()
330 {
331 maintabs->setCurrentPage ( 1 );
332 }
333
334void QashMoney::enableOneTouchViewing ()
335 {
336 if ( preferences->getPreference ( 5 ) == 1 )
337 connect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) );
338 else
339 disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) );
340 }
341
342void QashMoney::disableOneTouchViewing ()
343 {
344 disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) );
345 }
346
347void QashMoney::toggleOneTouchViewing ( bool state )
348 {
349 if ( state == TRUE )
350 disableOneTouchViewing();
351 else
352 enableOneTouchViewing();
353 }
354
355
356