summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/checkbook.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp
index 7a6b7cc..5fe660c 100644
--- a/noncore/apps/checkbook/checkbook.cpp
+++ b/noncore/apps/checkbook/checkbook.cpp
@@ -1,658 +1,658 @@
1/* 1/*
2                This file is part of the OPIE Project 2                This file is part of the OPIE Project
3 =. 3 =.
4             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> 4             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org>
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can 6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public 8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License, 10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version. 11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that 13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details. 18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .: 19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU 20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file; 21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the 22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc., 23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330, 24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include "checkbook.h" 29#include "checkbook.h"
30#include "cbinfo.h" 30#include "cbinfo.h"
31#include "transaction.h" 31#include "transaction.h"
32#include "traninfo.h" 32#include "traninfo.h"
33#include "graph.h" 33#include "graph.h"
34#include "graphinfo.h" 34#include "graphinfo.h"
35#include "password.h" 35#include "password.h"
36 36
37#include <opie/otabwidget.h> 37#include <opie/otabwidget.h>
38#include <qpe/config.h> 38#include <qpe/config.h>
39#include <qpe/qpeapplication.h> 39#include <qpe/qpeapplication.h>
40#include <qpe/qpemessagebox.h> 40#include <qpe/qpemessagebox.h>
41#include <qpe/resource.h> 41#include <qpe/resource.h>
42 42
43#include <qcheckbox.h> 43#include <qcheckbox.h>
44#include <qcombobox.h> 44#include <qcombobox.h>
45#include <qfile.h> 45#include <qfile.h>
46#include <qfontmetrics.h> 46#include <qfontmetrics.h>
47#include <qlabel.h> 47#include <qlabel.h>
48#include <qlayout.h> 48#include <qlayout.h>
49#include <qlineedit.h> 49#include <qlineedit.h>
50#include <qmultilineedit.h> 50#include <qmultilineedit.h>
51#include <qpushbutton.h> 51#include <qpushbutton.h>
52#include <qwhatsthis.h> 52#include <qwhatsthis.h>
53#include <qwidget.h> 53#include <qwidget.h>
54 54
55Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol ) 55Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol )
56 : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) 56 : QDialog( parent, 0, TRUE, WStyle_ContextHelp )
57{ 57{
58 info = i; 58 info = i;
59 currencySymbol = symbol; 59 currencySymbol = symbol;
60 60
61 if ( info->name() != "" ) 61 if ( info->name() != "" )
62 { 62 {
63 QString tempstr = info->name(); 63 QString tempstr = info->name();
64 tempstr.append( " - " ); 64 tempstr.append( " - " );
65 tempstr.append( tr( "Checkbook" ) ); 65 tempstr.append( tr( "Checkbook" ) );
66 setCaption( tempstr ); 66 setCaption( tempstr );
67 } 67 }
68 else 68 else
69 { 69 {
70 setCaption( tr( "New checkbook" ) ); 70 setCaption( tr( "New checkbook" ) );
71 } 71 }
72 72
73 // Setup layout to make everything pretty 73 // Setup layout to make everything pretty
74 QVBoxLayout *layout = new QVBoxLayout( this ); 74 QVBoxLayout *layout = new QVBoxLayout( this );
75 layout->setMargin( 2 ); 75 layout->setMargin( 2 );
76 layout->setSpacing( 4 ); 76 layout->setSpacing( 4 );
77 77
78 // Setup tabs for all info 78 // Setup tabs for all info
79 mainWidget = new OTabWidget( this ); 79 mainWidget = new OTabWidget( this );
80 layout->addWidget( mainWidget ); 80 layout->addWidget( mainWidget );
81 81
82 mainWidget->addTab( initInfo(), "checkbook/infotab", tr( "Info" ) ); 82 mainWidget->addTab( initInfo(), "checkbook/infotab", tr( "Info" ) );
83 mainWidget->addTab( initTransactions(), "checkbook/trantab", tr( "Transactions" ) ); 83 mainWidget->addTab( initTransactions(), "checkbook/trantab", tr( "Transactions" ) );
84 mainWidget->addTab( initCharts(), "checkbook/charttab", tr( "Charts" ) ); 84 mainWidget->addTab( initCharts(), "checkbook/charttab", tr( "Charts" ) );
85 mainWidget->setCurrentTab( tr( "Info" ) ); 85 mainWidget->setCurrentTab( tr( "Info" ) );
86 86
87 // Load checkbook information 87 // Load checkbook information
88 loadCheckbook(); 88 loadCheckbook();
89} 89}
90 90
91Checkbook::~Checkbook() 91Checkbook::~Checkbook()
92{ 92{
93} 93}
94 94
95QWidget *Checkbook::initInfo() 95QWidget *Checkbook::initInfo()
96{ 96{
97 QWidget *control = new QWidget( mainWidget ); 97 QWidget *control = new QWidget( mainWidget );
98 98
99 QVBoxLayout *vb = new QVBoxLayout( control ); 99 QVBoxLayout *vb = new QVBoxLayout( control );
100 100
101 QScrollView *sv = new QScrollView( control ); 101 QScrollView *sv = new QScrollView( control );
102 vb->addWidget( sv, 0, 0 ); 102 vb->addWidget( sv, 0, 0 );
103 sv->setResizePolicy( QScrollView::AutoOneFit ); 103 sv->setResizePolicy( QScrollView::AutoOneFit );
104 sv->setFrameStyle( QFrame::NoFrame ); 104 sv->setFrameStyle( QFrame::NoFrame );
105 105
106 QWidget *container = new QWidget( sv->viewport() ); 106 QWidget *container = new QWidget( sv->viewport() );
107 sv->addChild( container ); 107 sv->addChild( container );
108 108
109 QGridLayout *layout = new QGridLayout( container ); 109 QGridLayout *layout = new QGridLayout( container );
110 layout->setSpacing( 2 ); 110 layout->setSpacing( 2 );
111 layout->setMargin( 4 ); 111 layout->setMargin( 4 );
112 112
113 // Password protection 113 // Password protection
114 passwordCB = new QCheckBox( tr( "Password protect" ), container ); 114 passwordCB = new QCheckBox( tr( "Password protect" ), container );
115 QWhatsThis::add( passwordCB, tr( "Click here to enable/disable password protection of this checkbook." ) ); 115 QWhatsThis::add( passwordCB, tr( "Click here to enable/disable password protection of this checkbook." ) );
116 connect( passwordCB, SIGNAL( clicked() ), this, SLOT( slotPasswordClicked() ) ); 116 connect( passwordCB, SIGNAL( clicked() ), this, SLOT( slotPasswordClicked() ) );
117 layout->addMultiCellWidget( passwordCB, 0, 0, 0, 1 ); 117 layout->addMultiCellWidget( passwordCB, 0, 0, 0, 1 );
118 118
119 // Account name 119 // Account name
120 QLabel *label = new QLabel( tr( "Name:" ), container ); 120 QLabel *label = new QLabel( tr( "Name:" ), container );
121 QWhatsThis::add( label, tr( "Enter name of checkbook here." ) ); 121 QWhatsThis::add( label, tr( "Enter name of checkbook here." ) );
122 layout->addWidget( label, 1, 0 ); 122 layout->addWidget( label, 1, 0 );
123 nameEdit = new QLineEdit( container ); 123 nameEdit = new QLineEdit( container );
124 QWhatsThis::add( nameEdit, tr( "Enter name of checkbook here." ) ); 124 QWhatsThis::add( nameEdit, tr( "Enter name of checkbook here." ) );
125 connect( nameEdit, SIGNAL( textChanged( const QString & ) ), 125 connect( nameEdit, SIGNAL( textChanged( const QString & ) ),
126 this, SLOT( slotNameChanged( const QString & ) ) ); 126 this, SLOT( slotNameChanged( const QString & ) ) );
127 layout->addWidget( nameEdit, 1, 1 ); 127 layout->addWidget( nameEdit, 1, 1 );
128 128
129 // Type of account 129 // Type of account
130 label = new QLabel( tr( "Type:" ), container ); 130 label = new QLabel( tr( "Type:" ), container );
131 QWhatsThis::add( label, tr( "Select type of checkbook here." ) ); 131 QWhatsThis::add( label, tr( "Select type of checkbook here." ) );
132 layout->addWidget( label, 2, 0 ); 132 layout->addWidget( label, 2, 0 );
133 typeList = new QComboBox( container ); 133 typeList = new QComboBox( container );
134 QWhatsThis::add( typeList, tr( "Select type of checkbook here." ) ); 134 QWhatsThis::add( typeList, tr( "Select type of checkbook here." ) );
135 typeList->insertItem( tr( "Savings" ) ); // 0 135 typeList->insertItem( tr( "Savings" ) ); // 0
136 typeList->insertItem( tr( "Checking" ) ); // 1 136 typeList->insertItem( tr( "Checking" ) ); // 1
137 typeList->insertItem( tr( "CD" ) ); // 2 137 typeList->insertItem( tr( "CD" ) ); // 2
138 typeList->insertItem( tr( "Money market" ) );// 3 138 typeList->insertItem( tr( "Money market" ) );// 3
139 typeList->insertItem( tr( "Mutual fund" ) );// 4 139 typeList->insertItem( tr( "Mutual fund" ) );// 4
140 typeList->insertItem( tr( "Other" ) ); // 5 140 typeList->insertItem( tr( "Other" ) ); // 5
141 layout->addWidget( typeList, 2, 1 ); 141 layout->addWidget( typeList, 2, 1 );
142 142
143 // Bank/institution name 143 // Bank/institution name
144 label = new QLabel( tr( "Bank:" ), container ); 144 label = new QLabel( tr( "Bank:" ), container );
145 QWhatsThis::add( label, tr( "Enter name of the bank for this checkbook here." ) ); 145 QWhatsThis::add( label, tr( "Enter name of the bank for this checkbook here." ) );
146 layout->addWidget( label, 3, 0 ); 146 layout->addWidget( label, 3, 0 );
147 bankEdit = new QLineEdit( container ); 147 bankEdit = new QLineEdit( container );
148 QWhatsThis::add( bankEdit, tr( "Enter name of the bank for this checkbook here." ) ); 148 QWhatsThis::add( bankEdit, tr( "Enter name of the bank for this checkbook here." ) );
149 layout->addWidget( bankEdit, 3, 1 ); 149 layout->addWidget( bankEdit, 3, 1 );
150 150
151 // Account number 151 // Account number
152 label = new QLabel( tr( "Account number:" ), container ); 152 label = new QLabel( tr( "Account number:" ), container );
153 QWhatsThis::add( label, tr( "Enter account number for this checkbook here." ) ); 153 QWhatsThis::add( label, tr( "Enter account number for this checkbook here." ) );
154 layout->addWidget( label, 4, 0 ); 154 layout->addWidget( label, 4, 0 );
155 acctNumEdit = new QLineEdit( container ); 155 acctNumEdit = new QLineEdit( container );
156 QWhatsThis::add( acctNumEdit, tr( "Enter account number for this checkbook here." ) ); 156 QWhatsThis::add( acctNumEdit, tr( "Enter account number for this checkbook here." ) );
157 layout->addWidget( acctNumEdit, 4, 1 ); 157 layout->addWidget( acctNumEdit, 4, 1 );
158 158
159 // PIN number 159 // PIN number
160 label = new QLabel( tr( "PIN number:" ), container ); 160 label = new QLabel( tr( "PIN number:" ), container );
161 QWhatsThis::add( label, tr( "Enter PIN number for this checkbook here." ) ); 161 QWhatsThis::add( label, tr( "Enter PIN number for this checkbook here." ) );
162 layout->addWidget( label, 5, 0 ); 162 layout->addWidget( label, 5, 0 );
163 pinNumEdit = new QLineEdit( container ); 163 pinNumEdit = new QLineEdit( container );
164 QWhatsThis::add( pinNumEdit, tr( "Enter PIN number for this checkbook here." ) ); 164 QWhatsThis::add( pinNumEdit, tr( "Enter PIN number for this checkbook here." ) );
165 layout->addWidget( pinNumEdit, 5, 1 ); 165 layout->addWidget( pinNumEdit, 5, 1 );
166 166
167 // Starting balance 167 // Starting balance
168 label = new QLabel( tr( "Starting balance:" ), container ); 168 label = new QLabel( tr( "Starting balance:" ), container );
169 QWhatsThis::add( label, tr( "Enter the initial balance for this checkbook here." ) ); 169 QWhatsThis::add( label, tr( "Enter the initial balance for this checkbook here." ) );
170 layout->addWidget( label, 6, 0 ); 170 layout->addWidget( label, 6, 0 );
171 balanceEdit = new QLineEdit( container ); 171 balanceEdit = new QLineEdit( container );
172 QWhatsThis::add( balanceEdit, tr( "Enter the initial balance for this checkbook here." ) ); 172 QWhatsThis::add( balanceEdit, tr( "Enter the initial balance for this checkbook here." ) );
173 connect( balanceEdit, SIGNAL( textChanged( const QString & ) ), 173 connect( balanceEdit, SIGNAL( textChanged( const QString & ) ),
174 this, SLOT( slotStartingBalanceChanged( const QString & ) ) ); 174 this, SLOT( slotStartingBalanceChanged( const QString & ) ) );
175 layout->addWidget( balanceEdit, 6, 1 ); 175 layout->addWidget( balanceEdit, 6, 1 );
176 176
177 // Notes 177 // Notes
178 label = new QLabel( tr( "Notes:" ), container ); 178 label = new QLabel( tr( "Notes:" ), container );
179 QWhatsThis::add( label, tr( "Enter any additional information for this checkbook here." ) ); 179 QWhatsThis::add( label, tr( "Enter any additional information for this checkbook here." ) );
180 layout->addWidget( label, 7, 0 ); 180 layout->addWidget( label, 7, 0 );
181 notesEdit = new QMultiLineEdit( container ); 181 notesEdit = new QMultiLineEdit( container );
182 QWhatsThis::add( notesEdit, tr( "Enter any additional information for this checkbook here." ) ); 182 QWhatsThis::add( notesEdit, tr( "Enter any additional information for this checkbook here." ) );
183 notesEdit->setMinimumHeight( 25 ); 183 notesEdit->setMinimumHeight( 25 );
184 notesEdit->setMaximumHeight( 65 ); 184 notesEdit->setMaximumHeight( 65 );
185 layout->addMultiCellWidget( notesEdit, 8, 8, 0, 1 ); 185 layout->addMultiCellWidget( notesEdit, 8, 8, 0, 1 );
186 186
187 return control; 187 return control;
188} 188}
189 189
190QWidget *Checkbook::initTransactions() 190QWidget *Checkbook::initTransactions()
191{ 191{
192 QWidget *control = new QWidget( mainWidget ); 192 QWidget *control = new QWidget( mainWidget );
193 193
194 QGridLayout *layout = new QGridLayout( control ); 194 QGridLayout *layout = new QGridLayout( control );
195 layout->setSpacing( 2 ); 195 layout->setSpacing( 2 );
196 layout->setMargin( 4 ); 196 layout->setMargin( 4 );
197 197
198 balanceLabel = new QLabel( tr( "Current balance: %10.00" ).arg( currencySymbol ), 198 balanceLabel = new QLabel( tr( "Current balance: %10.00" ).arg( currencySymbol ),
199 control ); 199 control );
200 QWhatsThis::add( balanceLabel, tr( "This area shows the current balance in this checkbook." ) ); 200 QWhatsThis::add( balanceLabel, tr( "This area shows the current balance in this checkbook." ) );
201 layout->addMultiCellWidget( balanceLabel, 0, 0, 0, 2 ); 201 layout->addMultiCellWidget( balanceLabel, 0, 0, 0, 2 );
202 202
203 tranTable = new QListView( control ); 203 tranTable = new QListView( control );
204 QWhatsThis::add( tranTable, tr( "This is a listing of all transactions entered for this checkbook.\n\nTo sort entries by a specific field, click on the column name." ) ); 204 QWhatsThis::add( tranTable, tr( "This is a listing of all transactions entered for this checkbook.\n\nTo sort entries by a specific field, click on the column name." ) );
205 tranTable->addColumn( tr( "Num" ) ); 205 tranTable->addColumn( tr( "Num" ) );
206 tranTable->addColumn( tr( "Date" ) ); 206 tranTable->addColumn( tr( "Date" ) );
207 //tranTable->addColumn( tr( "Cleared" ) ); 207 //tranTable->addColumn( tr( "Cleared" ) );
208 tranTable->addColumn( tr( "Description" ) ); 208 tranTable->addColumn( tr( "Description" ) );
209 int colnum = tranTable->addColumn( tr( "Amount" ) ); 209 int colnum = tranTable->addColumn( tr( "Amount" ) );
210 tranTable->setColumnAlignment( colnum, Qt::AlignRight ); 210 tranTable->setColumnAlignment( colnum, Qt::AlignRight );
211 tranTable->setAllColumnsShowFocus( TRUE ); 211 tranTable->setAllColumnsShowFocus( TRUE );
212 tranTable->setSorting( 1 ); 212 tranTable->setSorting( 1 );
213 layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 ); 213 layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 );
214 QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold ); 214 QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold );
215 connect( tranTable, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ), 215 connect( tranTable, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ),
216 this, SLOT( slotEditTran() ) ); 216 this, SLOT( slotEditTran() ) );
217 217
218 QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control ); 218 QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control );
219 QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) ); 219 QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) );
220 connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) ); 220 connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) );
221 layout->addWidget( btn, 2, 0 ); 221 layout->addWidget( btn, 2, 0 );
222 222
223 btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), control ); 223 btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), control );
224 QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) ); 224 QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) );
225 connect( btn, SIGNAL( clicked() ), this, SLOT( slotEditTran() ) ); 225 connect( btn, SIGNAL( clicked() ), this, SLOT( slotEditTran() ) );
226 layout->addWidget( btn, 2, 1 ); 226 layout->addWidget( btn, 2, 1 );
227 227
228 btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), control ); 228 btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), control );
229 QWhatsThis::add( btn, tr( "Select a checkbook and then click here to delete it." ) ); 229 QWhatsThis::add( btn, tr( "Select a checkbook and then click here to delete it." ) );
230 connect( btn, SIGNAL( clicked() ), this, SLOT( slotDeleteTran() ) ); 230 connect( btn, SIGNAL( clicked() ), this, SLOT( slotDeleteTran() ) );
231 layout->addWidget( btn, 2, 2 ); 231 layout->addWidget( btn, 2, 2 );
232 232
233 return( control ); 233 return( control );
234} 234}
235 235
236QWidget *Checkbook::initCharts() 236QWidget *Checkbook::initCharts()
237{ 237{
238 graphInfo = 0x0; 238 graphInfo = 0x0;
239 239
240 QWidget *control = new QWidget( mainWidget ); 240 QWidget *control = new QWidget( mainWidget );
241 241
242 QGridLayout *layout = new QGridLayout( control ); 242 QGridLayout *layout = new QGridLayout( control );
243 layout->setSpacing( 2 ); 243 layout->setSpacing( 2 );
244 layout->setMargin( 4 ); 244 layout->setMargin( 4 );
245 245
246 graphWidget = new Graph( control ); 246 graphWidget = new Graph( control );
247 QWhatsThis::add( graphWidget, tr( "Select the desired chart below and then click on the Draw button." ) ); 247 QWhatsThis::add( graphWidget, tr( "Select the desired chart below and then click on the Draw button." ) );
248 layout->addMultiCellWidget( graphWidget, 0, 0, 0, 2 ); 248 layout->addMultiCellWidget( graphWidget, 0, 0, 0, 2 );
249 249
250 graphList = new QComboBox( control ); 250 graphList = new QComboBox( control );
251 QWhatsThis::add( graphList, tr( "Click here to select the desired chart type." ) ); 251 QWhatsThis::add( graphList, tr( "Click here to select the desired chart type." ) );
252 graphList->insertItem( tr( "Account balance" ) ); 252 graphList->insertItem( tr( "Account balance" ) );
253 graphList->insertItem( tr( "Withdrawals by category" ) ); 253 graphList->insertItem( tr( "Withdrawals by category" ) );
254 graphList->insertItem( tr( "Deposits by category" ) ); 254 graphList->insertItem( tr( "Deposits by category" ) );
255 255
256 layout->addMultiCellWidget( graphList, 1, 1, 0, 1 ); 256 layout->addMultiCellWidget( graphList, 1, 1, 0, 1 );
257 257
258 QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control ); 258 QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control );
259 QWhatsThis::add( btn, tr( "Click here to draw the selected chart." ) ); 259 QWhatsThis::add( btn, tr( "Click here to draw the selected chart." ) );
260 connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) ); 260 connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) );
261 layout->addWidget( btn, 1, 2 ); 261 layout->addWidget( btn, 1, 2 );
262 262
263 return control; 263 return control;
264} 264}
265 265
266void Checkbook::loadCheckbook() 266void Checkbook::loadCheckbook()
267{ 267{
268 if ( !info ) 268 if ( !info )
269 { 269 {
270 return; 270 return;
271 } 271 }
272 272
273 tranList = info->transactions(); 273 tranList = info->transactions();
274 274
275 passwordCB->setChecked( !info->password().isNull() ); 275 passwordCB->setChecked( !info->password().isNull() );
276 nameEdit->setText( info->name() ); 276 nameEdit->setText( info->name() );
277 QString temptext = info->type(); 277 QString temptext = info->type();
278 int i = typeList->count(); 278 int i = typeList->count();
279 while ( i > 0 ) 279 while ( i > 0 )
280 { 280 {
281 i--; 281 i--;
282 typeList->setCurrentItem( i ); 282 typeList->setCurrentItem( i );
283 if ( typeList->currentText() == temptext ) 283 if ( typeList->currentText() == temptext )
284 { 284 {
285 break; 285 break;
286 } 286 }
287 } 287 }
288 bankEdit->setText( info->bank() ); 288 bankEdit->setText( info->bank() );
289 acctNumEdit->setText( info->account() ); 289 acctNumEdit->setText( info->account() );
290 pinNumEdit->setText( info->pin() ); 290 pinNumEdit->setText( info->pin() );
291 temptext.setNum( info->startingBalance(), 'f', 2 ); 291 temptext.setNum( info->startingBalance(), 'f', 2 );
292 balanceEdit->setText( temptext ); 292 balanceEdit->setText( temptext );
293 notesEdit->setText( info->notes() ); 293 notesEdit->setText( info->notes() );
294 294
295 // Load transactions 295 // Load transactions
296 float amount; 296 float amount;
297 QString stramount; 297 QString stramount;
298 298
299 for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) 299 for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() )
300 { 300 {
301 amount = tran->amount(); 301 amount = tran->amount();
302 if ( tran->withdrawal() ) 302 if ( tran->withdrawal() )
303 { 303 {
304 amount *= -1; 304 amount *= -1;
305 } 305 }
306 stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); 306 stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount );
307 ( void ) new CBListItem( tranTable, tran->number(), tran->datestr(), tran->desc(), stramount ); 307 ( void ) new CBListItem( tranTable, tran->number(), tran->datestr(), tran->desc(), stramount );
308 } 308 }
309 309
310 balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) ); 310 balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) );
311 311
312 highTranNum = tranList->count(); 312 highTranNum = tranList->count();
313} 313}
314 314
315void Checkbook::adjustBalance() 315void Checkbook::adjustBalance()
316{ 316{
317 balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) ); 317 balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) );
318} 318}
319 319
320TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, const QString &desc ) 320TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, const QString &desc )
321{ 321{
322 TranInfo *traninfo = tranList->first(); 322 TranInfo *traninfo = tranList->first();
323 while ( traninfo ) 323 while ( traninfo )
324 { 324 {
325 if ( traninfo->number() == checknum && traninfo->datestr() == date && 325 if ( traninfo->number() == checknum && traninfo->datestr() == date &&
326 traninfo->desc() == desc ) 326 traninfo->desc() == desc )
327 break; 327 break;
328 traninfo = tranList->next(); 328 traninfo = tranList->next();
329 } 329 }
330 return( traninfo ); 330 return( traninfo );
331} 331}
332 332
333void Checkbook::accept() 333void Checkbook::accept()
334{ 334{
335 info->setName( nameEdit->text() ); 335 info->setName( nameEdit->text() );
336 info->setType( typeList->currentText() ); 336 info->setType( typeList->currentText() );
337 info->setBank( bankEdit->text() ); 337 info->setBank( bankEdit->text() );
338 info->setAccount( acctNumEdit->text() ); 338 info->setAccount( acctNumEdit->text() );
339 info->setPin( pinNumEdit->text() ); 339 info->setPin( pinNumEdit->text() );
340 bool ok; 340 bool ok;
341 info->setStartingBalance( balanceEdit->text().toFloat( &ok ) ); 341 info->setStartingBalance( balanceEdit->text().toFloat( &ok ) );
342 info->setNotes( notesEdit->text() ); 342 info->setNotes( notesEdit->text() );
343 343
344 QDialog::accept(); 344 QDialog::accept();
345} 345}
346 346
347void Checkbook::slotPasswordClicked() 347void Checkbook::slotPasswordClicked()
348{ 348{
349 if ( info->password().isNull() && passwordCB->isChecked() ) 349 if ( info->password().isNull() && passwordCB->isChecked() )
350 { 350 {
351 Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); 351 Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) );
352 if ( pw->exec() != QDialog::Accepted ) 352 if ( pw->exec() != QDialog::Accepted )
353 { 353 {
354 passwordCB->setChecked( FALSE ); 354 passwordCB->setChecked( FALSE );
355 delete pw; 355 delete pw;
356 return; 356 return;
357 } 357 }
358 info->setPassword( pw->password ); 358 info->setPassword( pw->password );
359 delete pw; 359 delete pw;
360 360
361 pw = new Password( this, tr( "Confirm password" ), tr( "Please confirm your password:" ) ); 361 pw = new Password( this, tr( "Confirm password" ), tr( "Please confirm your password:" ) );
362 if ( pw->exec() != QDialog::Accepted || pw->password != info->password() ) 362 if ( pw->exec() != QDialog::Accepted || pw->password != info->password() )
363 { 363 {
364 passwordCB->setChecked( FALSE ); 364 passwordCB->setChecked( FALSE );
365 info->setPassword( QString::null ); 365 info->setPassword( QString::null );
366 } 366 }
367 367
368 delete pw; 368 delete pw;
369 } 369 }
370 else if ( !info->password().isNull() && !passwordCB->isChecked() ) 370 else if ( !info->password().isNull() && !passwordCB->isChecked() )
371 { 371 {
372 Password *pw = new Password( this, tr( "Enter password" ), 372 Password *pw = new Password( this, tr( "Enter password" ),
373 tr( "Please enter your password to confirm removal of password protection:" ) ); 373 tr( "Please enter your password to confirm removal of password protection:" ) );
374 if ( pw->exec() == QDialog::Accepted && pw->password == info->password() ) 374 if ( pw->exec() == QDialog::Accepted && pw->password == info->password() )
375 { 375 {
376 info->setPassword( QString::null ); 376 info->setPassword( QString::null );
377 delete pw; 377 delete pw;
378 return; 378 return;
379 } 379 }
380 else 380 else
381 { 381 {
382 passwordCB->setChecked( TRUE ); 382 passwordCB->setChecked( TRUE );
383 } 383 }
384 384
385 delete pw; 385 delete pw;
386 } 386 }
387} 387}
388 388
389void Checkbook::slotNameChanged( const QString &newname ) 389void Checkbook::slotNameChanged( const QString &newname )
390{ 390{
391 info->setName( newname ); 391 info->setName( newname );
392 392
393 // TODO - need filedir 393 // TODO - need filedir
394 //QString namestr = filedir; 394 //QString namestr = filedir;
395 //namestr.append( newname ); 395 //namestr.append( newname );
396 //namestr.append( ".qcb" ); 396 //namestr.append( ".qcb" );
397 //info->setFilename( namestr ); 397 //info->setFilename( namestr );
398 398
399 QString namestr = newname; 399 QString namestr = newname;
400 namestr.append( " - " ); 400 namestr.append( " - " );
401 namestr.append( tr( "Checkbook" ) ); 401 namestr.append( tr( "Checkbook" ) );
402 setCaption( namestr ); 402 setCaption( namestr );
403} 403}
404 404
405void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) 405void Checkbook::slotStartingBalanceChanged( const QString &newbalance )
406{ 406{
407 bool ok; 407 bool ok;
408 info->setStartingBalance( newbalance.toFloat( &ok ) ); 408 info->setStartingBalance( newbalance.toFloat( &ok ) );
409 adjustBalance(); 409 adjustBalance();
410} 410}
411 411
412void Checkbook::slotNewTran() 412void Checkbook::slotNewTran()
413{ 413{
414 highTranNum++; 414 highTranNum++;
415 TranInfo *traninfo = new TranInfo( highTranNum ); 415 TranInfo *traninfo = new TranInfo( highTranNum );
416 416
417 Transaction *currtran = new Transaction( this, info->name(), 417 Transaction *currtran = new Transaction( this, info->name(),
418 traninfo, 418 traninfo,
419 currencySymbol ); 419 currencySymbol );
420 currtran->showMaximized(); 420 currtran->showMaximized();
421 if ( currtran->exec() == QDialog::Accepted ) 421 if ( currtran->exec() == QDialog::Accepted )
422 { 422 {
423 // Add to transaction list 423 // Add to transaction list
424 info->addTransaction( traninfo ); 424 info->addTransaction( traninfo );
425 425
426 // Add to transaction table 426 // Add to transaction table
427 float amount; 427 float amount;
428 QString stramount; 428 QString stramount;
429 429
430 amount = traninfo->amount(); 430 amount = traninfo->amount();
431 if ( traninfo->withdrawal() ) 431 if ( traninfo->withdrawal() )
432 { 432 {
433 amount *= -1; 433 amount *= -1;
434 } 434 }
435 stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); 435 stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount );
436 436
437 ( void ) new CBListItem( tranTable, traninfo->number(), traninfo->datestr(), traninfo->desc(), 437 ( void ) new CBListItem( tranTable, traninfo->number(), traninfo->datestr(), traninfo->desc(),
438 stramount ); 438 stramount );
439 439
440 adjustBalance(); 440 adjustBalance();
441 } 441 }
442 else 442 else
443 { 443 {
444 highTranNum--; 444 highTranNum--;
445 delete traninfo; 445 delete traninfo;
446 } 446 }
447} 447}
448 448
449void Checkbook::slotEditTran() 449void Checkbook::slotEditTran()
450{ 450{
451 QListViewItem *curritem = tranTable->currentItem(); 451 QListViewItem *curritem = tranTable->currentItem();
452 if ( !curritem ) 452 if ( !curritem )
453 { 453 {
454 return; 454 return;
455 } 455 }
456 456
457 TranInfo *traninfo = info->findTransaction( curritem->text( 0 ), curritem->text( 1 ), 457 TranInfo *traninfo = info->findTransaction( curritem->text( 0 ), curritem->text( 1 ),
458 curritem->text( 2 ) ); 458 curritem->text( 2 ) );
459 459
460 Transaction *currtran = new Transaction( this, info->name(), 460 Transaction *currtran = new Transaction( this, info->name(),
461 traninfo, 461 traninfo,
462 currencySymbol ); 462 currencySymbol );
463 currtran->showMaximized(); 463 currtran->showMaximized();
464 if ( currtran->exec() == QDialog::Accepted ) 464 if ( currtran->exec() == QDialog::Accepted )
465 { 465 {
466 curritem->setText( 0, traninfo->number() ); 466 curritem->setText( 0, traninfo->number() );
467 curritem->setText( 1, traninfo->datestr() ); 467 curritem->setText( 1, traninfo->datestr() );
468 curritem->setText( 2, traninfo->desc() ); 468 curritem->setText( 2, traninfo->desc() );
469 469
470 float amount = traninfo->amount(); 470 float amount = traninfo->amount();
471 if ( traninfo->withdrawal() ) 471 if ( traninfo->withdrawal() )
472 { 472 {
473 amount *= -1; 473 amount *= -1;
474 } 474 }
475 QString stramount; 475 QString stramount;
476 stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); 476 stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount );
477 curritem->setText( 3, stramount ); 477 curritem->setText( 3, stramount );
478 478
479 adjustBalance(); 479 adjustBalance();
480 } 480 }
481 481
482 delete currtran; 482 delete currtran;
483} 483}
484 484
485void Checkbook::slotDeleteTran() 485void Checkbook::slotDeleteTran()
486{ 486{
487 QListViewItem *curritem = tranTable->currentItem(); 487 QListViewItem *curritem = tranTable->currentItem();
488 if ( !curritem ) 488 if ( !curritem )
489 { 489 {
490 return; 490 return;
491 } 491 }
492 492
493 TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) ); 493 TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) );
494 494
495 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) ) 495 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) )
496 { 496 {
497 info->removeTransaction( traninfo ); 497 info->removeTransaction( traninfo );
498 delete curritem; 498 delete curritem;
499 adjustBalance(); 499 adjustBalance();
500 } 500 }
501} 501}
502 502
503void Checkbook::slotDrawGraph() 503void Checkbook::slotDrawGraph()
504{ 504{
505 if ( graphInfo ) 505 if ( graphInfo )
506 { 506 {
507 delete graphInfo; 507 delete graphInfo;
508 } 508 }
509 509
510 switch ( graphList->currentItem() ) 510 switch ( graphList->currentItem() )
511 { 511 {
512 case 0 : drawBalanceChart(); 512 case 0 : drawBalanceChart();
513 break; 513 break;
514 case 1 : drawCategoryChart( TRUE ); 514 case 1 : drawCategoryChart( TRUE );
515 break; 515 break;
516 case 2 : drawCategoryChart( FALSE ); 516 case 2 : drawCategoryChart( FALSE );
517 break; 517 break;
518 }; 518 };
519 519
520 graphWidget->setGraphInfo( graphInfo ); 520 graphWidget->setGraphInfo( graphInfo );
521 graphWidget->drawGraph( TRUE ); 521 graphWidget->drawGraph( TRUE );
522} 522}
523 523
524void Checkbook::drawBalanceChart() 524void Checkbook::drawBalanceChart()
525{ 525{
526 DataPointList *list = new DataPointList(); 526 DataPointList *list = new DataPointList();
527 527
528 float balance = info->startingBalance(); 528 float balance = info->startingBalance();
529 float amount; 529 float amount;
530 QString label; 530 QString label;
531 int i = 0; 531 int i = 0;
532 int count = tranList->count(); 532 int count = tranList->count();
533 533
534 for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) 534 for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() )
535 { 535 {
536 i++; 536 i++;
537 balance -= tran->fee(); 537 balance -= tran->fee();
538 amount = tran->amount(); 538 amount = tran->amount();
539 if ( tran->withdrawal() ) 539 if ( tran->withdrawal() )
540 { 540 {
541 amount *= -1; 541 amount *= -1;
542 } 542 }
543 balance += amount; 543 balance += amount;
544 if ( i == 1 || i == count / 2 || i == count ) 544 if ( i == 1 || i == count / 2 || i == count )
545 { 545 {
546 label = tran->datestr(); 546 label = tran->datestr();
547 } 547 }
548 else 548 else
549 { 549 {
550 label = ""; 550 label = "";
551 } 551 }
552 list->append( new DataPointInfo( label, balance ) ); 552 list->append( new DataPointInfo( label, balance ) );
553 } 553 }
554 554
555 graphInfo = new GraphInfo( GraphInfo::BarChart, list ); 555 graphInfo = new GraphInfo( GraphInfo::BarChart, list );
556} 556}
557 557
558void Checkbook::drawCategoryChart( bool withdrawals ) 558void Checkbook::drawCategoryChart( bool withdrawals )
559{ 559{
560 DataPointList *list = new DataPointList(); 560 DataPointList *list = new DataPointList();
561 561
562 TranInfo *tran = tranList->first(); 562 TranInfo *tran = tranList->first();
563 if ( tran && tran->withdrawal() == withdrawals ) 563 if ( tran && tran->withdrawal() == withdrawals )
564 { 564 {
565 list->append( new DataPointInfo( tran->category(), tran->amount() ) ); 565 list->append( new DataPointInfo( tran->category(), tran->amount() ) );
566 } 566 }
567 tran = tranList->next(); 567 tran = tranList->next();
568 568
569 DataPointInfo *cat; 569 DataPointInfo *cat;
570 for ( ; tran; tran = tranList->next() ) 570 for ( ; tran; tran = tranList->next() )
571 { 571 {
572 if ( tran->withdrawal() == withdrawals ) 572 if ( tran->withdrawal() == withdrawals )
573 { 573 {
574 // Find category in list 574 // Find category in list
575 for ( cat = list->first(); cat; cat = list->next() ) 575 for ( cat = list->first(); cat; cat = list->next() )
576 { 576 {
577 if ( cat->label() == tran->category() ) 577 if ( cat->label() == tran->category() )
578 { 578 {
579 break; 579 break;
580 } 580 }
581 } 581 }
582 if ( cat && cat->label() == tran->category() ) 582 if ( cat && cat->label() == tran->category() )
583 { // Found category, add to transaction to category total 583 { // Found category, add to transaction to category total
584 cat->addToValue( tran->amount() ); 584 cat->addToValue( tran->amount() );
585 } 585 }
586 else 586 else
587 { // Didn't find category, add category to list 587 { // Didn't find category, add category to list
588 list->append( new DataPointInfo( tran->category(), tran->amount() ) ); 588 list->append( new DataPointInfo( tran->category(), tran->amount() ) );
589 } 589 }
590 } 590 }
591 } 591 }
592 592
593 graphInfo = new GraphInfo( GraphInfo::PieChart, list ); 593 graphInfo = new GraphInfo( GraphInfo::PieChart, list );
594} 594}
595 595
596CBListItem::CBListItem( QListView *parent, QString label1, QString label2, 596CBListItem::CBListItem( QListView *parent, QString label1, QString label2,
597 QString label3, QString label4, QString label5, QString label6, QString label7, 597 QString label3, QString label4, QString label5, QString label6, QString label7,
598 QString label8 ) 598 QString label8 )
599 : QListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 ) 599 : QListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 )
600{ 600{
601 m_known = FALSE; 601 m_known = FALSE;
602 owner = parent; 602 owner = parent;
603} 603}
604 604
605void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align ) 605void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align )
606{ 606{
607 QColorGroup _cg = cg; 607 QColorGroup _cg = cg;
608 const QPixmap *pm = listView()->viewport()->backgroundPixmap(); 608 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
609 if ( pm && !pm->isNull() ) 609 if ( pm && !pm->isNull() )
610 { 610 {
611 _cg.setBrush( QColorGroup::Base, QBrush( cg.base(), *pm ) ); 611 _cg.setBrush( QColorGroup::Base, QBrush( cg.base(), *pm ) );
612 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); 612 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
613 } 613 }
614 else if ( isAltBackground() ) 614 else if ( isAltBackground() )
615 _cg.setColor(QColorGroup::Base, QColor( 200, 255, 200 ) ); 615 _cg.setColor(QColorGroup::Base, cg.background() );
616 616
617 QListViewItem::paintCell(p, _cg, column, width, align); 617 QListViewItem::paintCell(p, _cg, column, width, align);
618} 618}
619 619
620bool CBListItem::isAltBackground() 620bool CBListItem::isAltBackground()
621{ 621{
622 QListView *lv = static_cast<QListView *>( listView() ); 622 QListView *lv = static_cast<QListView *>( listView() );
623 if ( lv ) 623 if ( lv )
624 { 624 {
625 CBListItem *above = 0; 625 CBListItem *above = 0;
626 above = (CBListItem *)( itemAbove() ); 626 above = (CBListItem *)( itemAbove() );
627 m_known = above ? above->m_known : true; 627 m_known = above ? above->m_known : true;
628 if ( m_known ) 628 if ( m_known )
629 { 629 {
630 m_odd = above ? !above->m_odd : false; 630 m_odd = above ? !above->m_odd : false;
631 } 631 }
632 else 632 else
633 { 633 {
634 CBListItem *item; 634 CBListItem *item;
635 bool previous = true; 635 bool previous = true;
636 if ( parent() ) 636 if ( parent() )
637 { 637 {
638 item = (CBListItem *)( parent() ); 638 item = (CBListItem *)( parent() );
639 if ( item ) 639 if ( item )
640 previous = item->m_odd; 640 previous = item->m_odd;
641 item = (CBListItem *)( parent()->firstChild() ); 641 item = (CBListItem *)( parent()->firstChild() );
642 } 642 }
643 else 643 else
644 { 644 {
645 item = (CBListItem *)( lv->firstChild() ); 645 item = (CBListItem *)( lv->firstChild() );
646 } 646 }
647 647
648 while(item) 648 while(item)
649 { 649 {
650 item->m_odd = previous = !previous; 650 item->m_odd = previous = !previous;
651 item->m_known = true; 651 item->m_known = true;
652 item = (CBListItem *)( item->nextSibling() ); 652 item = (CBListItem *)( item->nextSibling() );
653 } 653 }
654 } 654 }
655 return m_odd; 655 return m_odd;
656 } 656 }
657 return false; 657 return false;
658} 658}