summaryrefslogtreecommitdiff
path: root/noncore
authorharlekin <harlekin>2002-07-05 13:00:41 (UTC)
committer harlekin <harlekin>2002-07-05 13:00:41 (UTC)
commit60238d4e9781ad18475a3b45bceaad1d30ea1b8b (patch) (unidiff)
treef4aac0b3daab54d8cb004879a91c51fd1f619a55 /noncore
parenta332e5e111b0c9ef8eb0836876a4ff386c660514 (diff)
downloadopie-60238d4e9781ad18475a3b45bceaad1d30ea1b8b.zip
opie-60238d4e9781ad18475a3b45bceaad1d30ea1b8b.tar.gz
opie-60238d4e9781ad18475a3b45bceaad1d30ea1b8b.tar.bz2
spendings tracking app by Nick Betcher (who quit qte development .-( )
Diffstat (limited to 'noncore') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/checkbook/TODO5
-rw-r--r--noncore/apps/checkbook/config.cpp560
-rw-r--r--noncore/apps/checkbook/config.h99
-rw-r--r--noncore/apps/checkbook/main.cpp11
-rw-r--r--noncore/apps/checkbook/qcheckbook.cpp149
-rw-r--r--noncore/apps/checkbook/qcheckbook.h37
-rw-r--r--noncore/apps/checkbook/qcheckbook.pro33
-rw-r--r--noncore/apps/checkbook/qcheckdetails.cpp119
-rw-r--r--noncore/apps/checkbook/qcheckdetails.h27
-rw-r--r--noncore/apps/checkbook/qcheckdetailsbase.ui62
-rw-r--r--noncore/apps/checkbook/qcheckentry.cpp251
-rw-r--r--noncore/apps/checkbook/qcheckentry.h31
-rw-r--r--noncore/apps/checkbook/qcheckentrybase.ui603
-rw-r--r--noncore/apps/checkbook/qcheckgraph.cpp258
-rw-r--r--noncore/apps/checkbook/qcheckgraph.h25
-rw-r--r--noncore/apps/checkbook/qcheckgraphbase.ui62
-rw-r--r--noncore/apps/checkbook/qcheckmainmenu.cpp74
-rw-r--r--noncore/apps/checkbook/qcheckmainmenu.h27
-rw-r--r--noncore/apps/checkbook/qcheckmmbase.ui80
-rw-r--r--noncore/apps/checkbook/qcheckname.cpp36
-rw-r--r--noncore/apps/checkbook/qcheckname.h15
-rw-r--r--noncore/apps/checkbook/qchecknamebase.ui136
-rw-r--r--noncore/apps/checkbook/qcheckview.cpp458
-rw-r--r--noncore/apps/checkbook/qcheckview.h33
-rw-r--r--noncore/apps/checkbook/qcheckviewbase.ui122
-rw-r--r--noncore/apps/checkbook/qrestrictedcombo.cpp78
-rw-r--r--noncore/apps/checkbook/qrestrictedcombo.h96
-rw-r--r--noncore/apps/checkbook/qrestrictedline.cpp78
-rw-r--r--noncore/apps/checkbook/qrestrictedline.h96
29 files changed, 3661 insertions, 0 deletions
diff --git a/noncore/apps/checkbook/TODO b/noncore/apps/checkbook/TODO
new file mode 100644
index 0000000..adc9665
--- a/dev/null
+++ b/noncore/apps/checkbook/TODO
@@ -0,0 +1,5 @@
1TODO:
2 * Date widget
3 * Various bug fixes
4 * Fix "the" crash
5 * Fix graph's legend not showing up \ No newline at end of file
diff --git a/noncore/apps/checkbook/config.cpp b/noncore/apps/checkbook/config.cpp
new file mode 100644
index 0000000..e6c6dcc
--- a/dev/null
+++ b/noncore/apps/checkbook/config.cpp
@@ -0,0 +1,560 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qdir.h>
22#include <qfile.h>
23#include <qfileinfo.h>
24#include <qmessagebox.h>
25#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
26#include <qtextcodec.h>
27#endif
28#include <qtextstream.h>
29
30#include <sys/stat.h>
31#include <sys/types.h>
32#include <fcntl.h>
33#include <stdlib.h>
34#include <unistd.h>
35
36#include "config.h"
37
38
39/*!
40 \internal
41*/
42QString Config::configFilename(const QString& name, Domain d)
43{
44 switch (d) {
45 case File:
46 return name;
47 case User: {
48 QDir dir = (QString(getenv("HOME")) + "/Settings");
49 if ( !dir.exists() )
50 mkdir(dir.path().local8Bit(),0700);
51 return dir.path() + "/" + name + ".conf";
52 }
53 }
54 return name;
55}
56
57/*!
58 \class Config config.h
59 \brief The Config class provides for saving application cofniguration state.
60
61 You should keep a Config in existence only while you do not want others
62 to be able to change the state. There is no locking currently, but there
63 may be in the future.
64*/
65
66/*!
67 \enum Config::ConfigGroup
68 \internal
69*/
70
71/*!
72 \enum Config::Domain
73
74 \value File
75 \value User
76
77 See Config for details.
78*/
79
80/*!
81 Constructs a config that will load or create a configuration with the
82 given \a name in the given \a domain.
83
84 You must call setGroup() before doing much else with the Config.
85
86 In the default Domain, \e User,
87 the configuration is user-specific. \a name should not contain "/" in
88 this case, and in general should be the name of the C++ class that is
89 primarily responsible for maintaining the configuration.
90
91 In the File Domain, \a name is an absolute filename.
92*/
93Config::Config( const QString &name, Domain domain )
94 : filename( configFilename(name,domain) )
95{
96 git = groups.end();
97 read();
98
99 lang = getenv("LANG");
100 int i = lang.find(".");
101 if ( i > 0 )
102 lang = lang.left( i );
103 i = lang.find( "_" );
104 if ( i > 0 )
105 glang = lang.left(i);
106}
107
108/*!
109 Writes any changes to disk and destroys the in-memory object.
110*/
111Config::~Config()
112{
113 if ( changed )
114 write();
115}
116
117/*!
118 Returns whether the current group has an entry called \a key.
119*/
120bool Config::hasKey( const QString &key ) const
121{
122 if ( groups.end() == git )
123 return FALSE;
124 ConfigGroup::ConstIterator it = ( *git ).find( key );
125 return it != ( *git ).end();
126}
127
128/*!
129 Sets the current group for subsequent reading and writing of
130 entries to \a gname. Grouping allows the application to partition the namespace.
131
132 This function must be called prior to any reading or writing
133 of entries.
134
135 The \a gname must not be empty.
136*/
137void Config::setGroup( const QString &gname )
138{
139 QMap< QString, ConfigGroup>::Iterator it = groups.find( gname );
140 if ( it == groups.end() ) {
141 git = groups.insert( gname, ConfigGroup() );
142 changed = TRUE;
143 return;
144 }
145 git = it;
146}
147
148/*!
149 Writes a (\a key, \a value) entry to the current group.
150
151 \sa readEntry()
152*/
153void Config::writeEntry( const QString &key, const char* value )
154{
155 writeEntry(key,QString(value));
156}
157
158/*!
159 Writes a (\a key, \a value) entry to the current group.
160
161 \sa readEntry()
162*/
163void Config::writeEntry( const QString &key, const QString &value )
164{
165 if ( git == groups.end() ) {
166 qWarning( "no group set" );
167 return;
168 }
169 if ( (*git)[key] != value ) {
170 ( *git ).insert( key, value );
171 changed = TRUE;
172 }
173}
174
175/*
176 Note that the degree of protection offered by the encryption here is
177 only sufficient to avoid the most casual observation of the configuration
178 files. People with access to the files can write down the contents and
179 decrypt it using this source code.
180
181 Conceivably, and at some burden to the user, this encryption could
182 be improved.
183*/
184static QString encipher(const QString& plain)
185{
186 // mainly, we make it long
187 QString cipher;
188 int mix=28730492;
189 for (int i=0; i<(int)plain.length(); i++) {
190 int u = plain[i].unicode();
191 int c = u ^ mix;
192 QString x = QString::number(c,36);
193 cipher.append(QChar('a'+x.length()));
194 cipher.append(x);
195 mix *= u;
196 }
197 return cipher;
198}
199
200static QString decipher(const QString& cipher)
201{
202 QString plain;
203 int mix=28730492;
204 for (int i=0; i<(int)cipher.length();) {
205 int l = cipher[i].unicode()-'a';
206 QString x = cipher.mid(i+1,l); i+=l+1;
207 int u = x.toInt(0,36) ^ mix;
208 plain.append(QChar(u));
209 mix *= u;
210 }
211 return plain;
212}
213
214/*!
215 Writes an encrypted (\a key, \a value) entry to the current group.
216
217 Note that the degree of protection offered by the encryption is
218 only sufficient to avoid the most casual observation of the configuration
219 files.
220
221 \sa readEntry()
222*/
223void Config::writeEntryCrypt( const QString &key, const QString &value )
224{
225 if ( git == groups.end() ) {
226 qWarning( "no group set" );
227 return;
228 }
229 QString evalue = encipher(value);
230 if ( (*git)[key] != evalue ) {
231 ( *git ).insert( key, evalue );
232 changed = TRUE;
233 }
234}
235
236/*!
237 Writes a (\a key, \a num) entry to the current group.
238
239 \sa readNumEntry()
240*/
241void Config::writeEntry( const QString &key, int num )
242{
243 QString s;
244 s.setNum( num );
245 writeEntry( key, s );
246}
247
248#ifdef Q_HAS_BOOL_TYPE
249/*!
250 Writes a (\a key, \a b) entry to the current group. This is equivalent
251 to writing a 0 or 1 as an integer entry.
252
253 \sa readBoolEntry()
254*/
255void Config::writeEntry( const QString &key, bool b )
256{
257 QString s;
258 s.setNum( ( int )b );
259 writeEntry( key, s );
260}
261#endif
262
263/*!
264 Writes a (\a key, \a lst) entry to the current group. The list
265 is separated by \a sep, so the strings must not contain that character.
266
267 \sa readListEntry()
268*/
269void Config::writeEntry( const QString &key, const QStringList &lst, const QChar &sep )
270{
271 QString s;
272 QStringList::ConstIterator it = lst.begin();
273 for ( ; it != lst.end(); ++it )
274 s += *it + sep;
275 writeEntry( key, s );
276}
277
278/*!
279 Removes the \a key entry from the current group. Does nothing if
280 there is no such entry.
281*/
282
283void Config::removeEntry( const QString &key )
284{
285 if ( git == groups.end() ) {
286 qWarning( "no group set" );
287 return;
288 }
289 ( *git ).remove( key );
290 changed = TRUE;
291}
292
293/*!
294 \fn bool Config::operator == ( const Config & other ) const
295
296 Tests for equality with \a other. Config objects are equal if they refer to the same filename.
297*/
298
299/*!
300 \fn bool Config::operator != ( const Config & other ) const
301
302 Tests for inequality with \a other. Config objects are equal if they refer to the same filename.
303*/
304
305/*!
306 \fn QString Config::readEntry( const QString &key, const QString &deflt ) const
307
308 Reads a string entry stored with \a key, defaulting to \a deflt if there is no entry.
309*/
310
311/*!
312 \internal
313 For compatibility, non-const version.
314*/
315QString Config::readEntry( const QString &key, const QString &deflt )
316{
317 QString res = readEntryDirect( key+"["+lang+"]" );
318 if ( !res.isNull() )
319 return res;
320 if ( !glang.isEmpty() ) {
321 res = readEntryDirect( key+"["+glang+"]" );
322 if ( !res.isNull() )
323 return res;
324 }
325 return readEntryDirect( key, deflt );
326}
327
328/*!
329 \fn QString Config::readEntryCrypt( const QString &key, const QString &deflt ) const
330
331 Reads an encrypted string entry stored with \a key, defaulting to \a deflt if there is no entry.
332*/
333
334/*!
335 \internal
336 For compatibility, non-const version.
337*/
338QString Config::readEntryCrypt( const QString &key, const QString &deflt )
339{
340 QString res = readEntryDirect( key+"["+lang+"]" );
341 if ( res.isNull() && glang.isEmpty() )
342 res = readEntryDirect( key+"["+glang+"]" );
343 if ( res.isNull() )
344 res = readEntryDirect( key, QString::null );
345 if ( res.isNull() )
346 return deflt;
347 return decipher(res);
348}
349
350/*!
351 \fn QString Config::readEntryDirect( const QString &key, const QString &deflt ) const
352 \internal
353*/
354
355/*!
356 \internal
357 For compatibility, non-const version.
358*/
359QString Config::readEntryDirect( const QString &key, const QString &deflt )
360{
361 if ( git == groups.end() ) {
362 //qWarning( "no group set" );
363 return deflt;
364 }
365 ConfigGroup::ConstIterator it = ( *git ).find( key );
366 if ( it != ( *git ).end() )
367 return *it;
368 else
369 return deflt;
370}
371
372/*!
373 \fn int Config::readNumEntry( const QString &key, int deflt ) const
374 Reads a numeric entry stored with \a key, defaulting to \a deflt if there is no entry.
375*/
376
377/*!
378 \internal
379 For compatibility, non-const version.
380*/
381int Config::readNumEntry( const QString &key, int deflt )
382{
383 QString s = readEntry( key );
384 if ( s.isEmpty() )
385 return deflt;
386 else
387 return s.toInt();
388}
389
390/*!
391 \fn bool Config::readBoolEntry( const QString &key, bool deflt ) const
392 Reads a bool entry stored with \a key, defaulting to \a deflt if there is no entry.
393*/
394
395/*!
396 \internal
397 For compatibility, non-const version.
398*/
399bool Config::readBoolEntry( const QString &key, bool deflt )
400{
401 QString s = readEntry( key );
402 if ( s.isEmpty() )
403 return deflt;
404 else
405 return (bool)s.toInt();
406}
407
408/*!
409 \fn QStringList Config::readListEntry( const QString &key, const QChar &sep ) const
410 Reads a string list entry stored with \a key, and with \a sep as the separator.
411*/
412
413/*!
414 \internal
415 For compatibility, non-const version.
416*/
417
418/*!
419 Removes all entries from the current group.
420*/
421void Config::clearGroup()
422{
423 if ( git == groups.end() ) {
424 qWarning( "no group set" );
425 return;
426 }
427 if ( !(*git).isEmpty() ) {
428 ( *git ).clear();
429 changed = TRUE;
430 }
431}
432
433void Config::removeGroup()
434{
435 if ( git == groups.end() ) {
436 qWarning( "no group set" );
437 return;
438 }
439
440 groups.remove(git);
441 changed = TRUE;
442}
443
444/*!
445 \internal
446*/
447void Config::write( const QString &fn )
448{
449 QString strNewFile;
450 if ( !fn.isEmpty() )
451 filename = fn;
452 strNewFile = filename + ".new";
453
454 QFile f( strNewFile );
455 if ( !f.open( IO_WriteOnly|IO_Raw ) ) {
456 qWarning( "could not open for writing `%s'", strNewFile.latin1() );
457 git = groups.end();
458 return;
459 }
460
461 QString str;
462 QCString cstr;
463 QMap< QString, ConfigGroup >::Iterator g_it = groups.begin();
464
465 for ( ; g_it != groups.end(); ++g_it ) {
466 str += "[" + g_it.key() + "]\n";
467 ConfigGroup::Iterator e_it = ( *g_it ).begin();
468 for ( ; e_it != ( *g_it ).end(); ++e_it )
469 str += e_it.key() + " = " + *e_it + "\n";
470 }
471 cstr = str.utf8();
472
473 int total_length;
474 total_length = f.writeBlock( cstr.data(), cstr.length() );
475 if ( total_length != int(cstr.length()) ) {
476 QMessageBox::critical( 0, QObject::tr("Out of Space"),
477 QObject::tr("There was a problem creating\nConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") );
478 f.close();
479 QFile::remove( strNewFile );
480 return;
481 }
482
483 f.close();
484 // now rename the file...
485 if ( rename( strNewFile, filename ) < 0 ) {
486 qWarning( "problem renaming the file %s to %s", strNewFile.latin1(),
487 filename.latin1() );
488 QFile::remove( strNewFile );
489 }
490}
491
492/*!
493 Returns whether the Config is in a valid state.
494*/
495bool Config::isValid() const
496{
497 return groups.end() != git;
498}
499
500/*!
501 \internal
502*/
503void Config::read()
504{
505 changed = FALSE;
506
507 if ( !QFileInfo( filename ).exists() ) {
508 git = groups.end();
509 return;
510 }
511
512 QFile f( filename );
513 if ( !f.open( IO_ReadOnly ) ) {
514 git = groups.end();
515 return;
516 }
517
518 QTextStream s( &f );
519#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
520 // The below should work, but doesn't in Qt 2.3.0
521 s.setCodec( QTextCodec::codecForMib( 106 ) );
522#else
523 s.setEncoding( QTextStream::UnicodeUTF8 );
524#endif
525
526 QStringList list = QStringList::split('\n', s.read() );
527 f.close();
528
529 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
530 if ( !parse( *it ) ) {
531 git = groups.end();
532 return;
533 }
534 }
535}
536
537/*!
538 \internal
539*/
540bool Config::parse( const QString &l )
541{
542 QString line = l.stripWhiteSpace();
543 if ( line[ 0 ] == QChar( '[' ) ) {
544 QString gname = line;
545 gname = gname.remove( 0, 1 );
546 if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) )
547 gname = gname.remove( gname.length() - 1, 1 );
548 git = groups.insert( gname, ConfigGroup() );
549 } else if ( !line.isEmpty() ) {
550 if ( git == groups.end() )
551 return FALSE;
552 int eq = line.find( '=' );
553 if ( eq == -1 )
554 return FALSE;
555 QString key = line.left(eq).stripWhiteSpace();
556 QString value = line.mid(eq+1).stripWhiteSpace();
557 ( *git ).insert( key, value );
558 }
559 return TRUE;
560}
diff --git a/noncore/apps/checkbook/config.h b/noncore/apps/checkbook/config.h
new file mode 100644
index 0000000..b3a8561
--- a/dev/null
+++ b/noncore/apps/checkbook/config.h
@@ -0,0 +1,99 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef CONFIG_H
22#define CONFIG_H
23
24// ##### could use QSettings with Qt 3.0
25
26#include <qmap.h>
27#include <qstringlist.h>
28
29class ConfigPrivate;
30class Config
31{
32public:
33 typedef QMap< QString, QString > ConfigGroup;
34
35 enum Domain { File, User };
36 Config( const QString &name, Domain domain=User );
37 ~Config();
38
39 bool operator == ( const Config & other ) const { return (filename == other.filename); }
40 bool operator != ( const Config & other ) const { return (filename != other.filename); }
41
42 bool isValid() const;
43 bool hasKey( const QString &key ) const;
44
45 void setGroup( const QString &gname );
46 void writeEntry( const QString &key, const char* value );
47 void writeEntry( const QString &key, const QString &value );
48 void writeEntryCrypt( const QString &key, const QString &value );
49 void writeEntry( const QString &key, int num );
50#ifdef Q_HAS_BOOL_TYPE
51 void writeEntry( const QString &key, bool b );
52#endif
53 void writeEntry( const QString &key, const QStringList &lst, const QChar &sep );
54 void removeEntry( const QString &key );
55
56 QString readEntry( const QString &key, const QString &deflt = QString::null ) const;
57 QString readEntryCrypt( const QString &key, const QString &deflt = QString::null ) const;
58 QString readEntryDirect( const QString &key, const QString &deflt = QString::null ) const;
59 int readNumEntry( const QString &key, int deflt = -1 ) const;
60 bool readBoolEntry( const QString &key, bool deflt = FALSE ) const;
61
62 // For compatibility, non-const versions.
63 QString readEntry( const QString &key, const QString &deflt );
64 QString readEntryCrypt( const QString &key, const QString &deflt );
65 QString readEntryDirect( const QString &key, const QString &deflt );
66 int readNumEntry( const QString &key, int deflt );
67 bool readBoolEntry( const QString &key, bool deflt );
68
69 void clearGroup();
70 void removeGroup();
71
72 void write( const QString &fn = QString::null );
73
74protected:
75 void read();
76 bool parse( const QString &line );
77
78 QMap< QString, ConfigGroup > groups;
79 QMap< QString, ConfigGroup >::Iterator git;
80 QString filename;
81 QString lang;
82 QString glang;
83 bool changed;
84 ConfigPrivate *d;
85 static QString configFilename(const QString& name, Domain);
86};
87
88inline QString Config::readEntry( const QString &key, const QString &deflt ) const
89{ return ((Config*)this)->readEntry(key,deflt); }
90inline QString Config::readEntryCrypt( const QString &key, const QString &deflt ) const
91{ return ((Config*)this)->readEntryCrypt(key,deflt); }
92inline QString Config::readEntryDirect( const QString &key, const QString &deflt ) const
93{ return ((Config*)this)->readEntryDirect(key,deflt); }
94inline int Config::readNumEntry( const QString &key, int deflt ) const
95{ return ((Config*)this)->readNumEntry(key,deflt); }
96inline bool Config::readBoolEntry( const QString &key, bool deflt ) const
97{ return ((Config*)this)->readBoolEntry(key,deflt); }
98
99#endif
diff --git a/noncore/apps/checkbook/main.cpp b/noncore/apps/checkbook/main.cpp
new file mode 100644
index 0000000..68f00e6
--- a/dev/null
+++ b/noncore/apps/checkbook/main.cpp
@@ -0,0 +1,11 @@
1#include <qpe/qpeapplication.h>
2#include "qcheckbook.h"
3
4int main(int argc, char **argv)
5{
6 QPEApplication app(argc, argv);
7 QCheckBook *qcb = new QCheckBook();
8 app.setMainWidget(qcb);
9 qcb->showMaximized();
10 return app.exec();
11}
diff --git a/noncore/apps/checkbook/qcheckbook.cpp b/noncore/apps/checkbook/qcheckbook.cpp
new file mode 100644
index 0000000..797127e
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckbook.cpp
@@ -0,0 +1,149 @@
1#include "qcheckbook.h"
2
3#include <qmenubar.h>
4#include <qstatusbar.h>
5#include <qpopupmenu.h>
6#include <qapplication.h>
7#include <qfile.h>
8#include <qdir.h>
9
10QCheckBook::QCheckBook()
11 : QMainWindow(),
12 m_view(),
13 m_view2(),
14 m_view3()
15{
16 initCheck = false;
17 initMM = false;
18 setCaption("Checking");
19 statusBar()->hide();
20 menuBar()->hide();
21
22 bar = new QToolBar(this);
23 bar->setHorizontalStretchable( TRUE );
24
25 addToolBar(bar);
26
27 Config config("qcheckbook");
28 config.setGroup("Global");
29 QString lastCheck = config.readEntry("LastCheckBook", QString(""));
30
31 QString checkdirname = QDir::homeDirPath();
32 checkdirname.append("/.checkbooks/");
33 checkdirname.append(lastCheck);
34 QFile f(checkdirname);
35
36
37 if (lastCheck.isEmpty() == false && lastCheck != "" && f.exists() == true)
38 {
39 newCheck(lastCheck);
40 } else {
41 initMainMenus();
42 }
43
44 setToolBarsMovable( FALSE );
45}
46
47void QCheckBook::newCheck(const QString &filename)
48{
49 if (filename.isEmpty() == false)
50 {
51 initCheck = true;
52 if (m_view != 0)
53 {
54 delete m_view;
55 }
56 m_view = new QCheckView(this, filename);
57 m_view->hide();
58 connect(m_view, SIGNAL(reload(const QString &)), this, SLOT(newCheck(const QString &)));
59
60 if (initMM == true)
61 {
62 delete nb1;
63 }
64
65 bar->clear();
66
67 mbar = new QMenuBar(bar);
68 mbar->setMargin(0);
69
70 QPixmap newIcon = Resource::loadPixmap( "new" );
71 nb2 = new QToolButton( newIcon, "New", QString::null, m_view, SLOT(newClicked()), bar, "new item" );
72 QPixmap pixmap = Resource::loadPixmap( "pixmap" );
73 m_filename = filename;
74 nb3 = new QToolButton( pixmap, "Graph", QString::null, this, SLOT(newGraph()), bar, "new graph" );
75
76 QPixmap closeIcon = Resource::loadPixmap( "close" );
77 nb4 = new QToolButton( closeIcon, "Close", QString::null, this, SLOT(initMainMenus()), bar, "close graph" );
78
79 popup = new QPopupMenu(m_view);
80 popup->insertItem("&New Entry", m_view, SLOT(newClicked()));
81 popup->insertItem("&Graph Checkbook", this, SLOT(newGraph()));
82 popup->insertItem("&Close Checkbook", this, SLOT(initMainMenus()));
83 popup->insertItem("&Exit", this, SLOT(close()));
84 mbar->insertItem("&File", popup);
85
86 setCentralWidget(m_view);
87 m_view->show();
88
89 Config config("qcheckbook");
90 config.setGroup("Global");
91 config.writeEntry("LastCheckBook", filename);
92 initMM = false;
93 }
94}
95
96void QCheckBook::close()
97{
98 QApplication::exit();
99}
100
101void QCheckBook::newGraph()
102{
103 if (m_filename.isEmpty() == false)
104 {
105 m_view2 = new QCheckGraph(m_filename);
106 m_view2->showMaximized();
107 }
108}
109
110void QCheckBook::initMainMenus()
111{
112 Config config("qcheckbook");
113 config.setGroup("Global");
114 config.writeEntry("LastCheckBook", QString(""));
115 initMM = true;
116 m_filename = "";
117 if (m_view3 != 0)
118 {
119 delete m_view3;
120 }
121 m_view3 = new QCheckMainMenu(this);
122 m_view3->hide();
123
124 if (initCheck == true)
125 {
126 delete nb2;
127 delete nb3;
128 delete nb4;
129 }
130
131 bar->clear();
132
133 mbar = new QMenuBar(bar);
134 mbar->setMargin(0);
135
136 QPixmap newIcon = Resource::loadPixmap( "new" );
137 nb1 = new QToolButton( newIcon, "New", QString::null, m_view3, SLOT(newClicked()), bar, "new book" );
138
139 popup = new QPopupMenu();
140 popup->insertItem("&New", m_view3, SLOT(newClicked()));
141 popup->insertItem("&Exit", this, SLOT(close()));
142 mbar->insertItem("&File", popup);
143
144 setCentralWidget(m_view3);
145 m_view3->show();
146
147 connect(m_view3, SIGNAL(itemSelected(const QString &)), this, SLOT(newCheck(const QString &)));
148 initCheck = false;
149}
diff --git a/noncore/apps/checkbook/qcheckbook.h b/noncore/apps/checkbook/qcheckbook.h
new file mode 100644
index 0000000..52c0d40
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckbook.h
@@ -0,0 +1,37 @@
1#include "qcheckview.h"
2#include "qcheckgraph.h"
3#include "qcheckmainmenu.h"
4
5#include <qpe/resource.h>
6#include <qmainwindow.h>
7#include <qtoolbar.h>
8#include <qstring.h>
9#include "config.h"
10#include <qpopupmenu.h>
11
12class QCheckBook : public QMainWindow
13{
14 Q_OBJECT
15 public:
16 QCheckBook();
17 private slots:
18 void newCheck(const QString &filename);
19 void newGraph();
20 void close();
21 void initMainMenus();
22 private:
23 QCheckView *m_view;
24 QCheckGraph *m_view2;
25 QCheckMainMenu *m_view3;
26 QToolBar *bar;
27 QMenuBar *mbar;
28 int filemenuid;
29 QString m_filename;
30 QToolButton *nb1;
31 QToolButton *nb2;
32 QToolButton *nb3;
33 QToolButton *nb4;
34 bool initCheck;
35 bool initMM;
36 QPopupMenu *popup;
37};
diff --git a/noncore/apps/checkbook/qcheckbook.pro b/noncore/apps/checkbook/qcheckbook.pro
new file mode 100644
index 0000000..f601f6d
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckbook.pro
@@ -0,0 +1,33 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 HEADERS = config.h \
4 qcheckbook.h \
5 qcheckdetails.h \
6 qcheckentry.h \
7 qcheckgraph.h \
8 qcheckmainmenu.h \
9 qcheckname.h \
10 qcheckview.h \
11 qrestrictedcombo.h \
12 qrestrictedline.h
13 SOURCES = config.cpp \
14 main.cpp \
15 qcheckbook.cpp \
16 qcheckdetails.cpp \
17 qcheckentry.cpp \
18 qcheckgraph.cpp \
19 qcheckmainmenu.cpp \
20 qcheckname.cpp \
21 qcheckview.cpp \
22 qrestrictedcombo.cpp \
23 qrestrictedline.cpp
24 INTERFACES= qcheckdetailsbase.ui \
25 qcheckentrybase.ui \
26 qcheckgraphbase.ui \
27 qcheckmmbase.ui \
28 qchecknamebase.ui \
29 qcheckviewbase.ui
30INCLUDEPATH += $(OPIEDIR)/include
31DEPENDPATH += $(OPIEDIR)/include
32 LIBS += -lqpe
33 TARGET = $(OPIEDIR)/bin/checkbook \ No newline at end of file
diff --git a/noncore/apps/checkbook/qcheckdetails.cpp b/noncore/apps/checkbook/qcheckdetails.cpp
new file mode 100644
index 0000000..19a5e82
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckdetails.cpp
@@ -0,0 +1,119 @@
1#include "qcheckdetails.h"
2
3QCheckDetails::QCheckDetails(int row, int col, const QStringList item)
4 : QMainWindow(),
5 m_view()
6{
7 m_view = new QCheckDetailsBase(this);
8 setCentralWidget(m_view);
9
10 m_row = row;
11 m_col = col;
12
13 QToolBar *bar = new QToolBar(this);
14 bar->setHorizontalStretchable( TRUE );
15
16 QPixmap newIcon = Resource::loadPixmap( "edit" );
17 QPixmap trashIcon = Resource::loadPixmap( "trash" );
18 QToolButton *nb1 = new QToolButton( newIcon, "Edit", QString::null, this, SLOT(editCheck()), bar, "edit transaction" );
19 QToolButton *nb2 = new QToolButton( trashIcon, "Delete", QString::null, this, SLOT(deleteCheck()), bar, "delete transaction" );
20 addToolBar(bar);
21
22 QString text = "";
23 if (item[0] == "true")
24 {
25 text.append("<b>Payment</b> to <b>");
26 text.append(item[1]);
27 }
28 if (item[0] == "false")
29 {
30 text.append("<b>Deposit</b> from <b>");
31 text.append(item[1]);
32 }
33 text.append("</b> on <b>");
34 text.append(item[7]);
35 text.append("</b> for <b>");
36 text.append(QString("$" + item[5]));
37
38 text.append("</b>, to make your balance <b>$");
39 text.append(item[9]);
40 text.append("</b>.");
41
42 text.append("<br><br>");
43 text.append("<b>Category: </b>");
44 text.append(item[2]);
45 text.append("<br>");
46 text.append("<b>Type: </b>");
47
48 QString type = "No Type";
49 if (item[0] == "true")
50 {
51 if(item[3] == "0")
52 {
53 type = "Debit Charge";
54 }
55 if(item[3] == "1")
56 {
57 type = "Written Check";
58 }
59 if(item[3] == "2")
60 {
61 type = "Transfer";
62 }
63 if(item[3] == "3")
64 {
65 type = "Credit Card";
66 }
67 }
68
69 if (item[0] == "false")
70 {
71 if(item[3] == "0")
72 {
73 type = "Written Check";
74 }
75 if(item[3] == "1")
76 {
77 type = "Automatic Payment";
78 }
79 if(item[3] == "2")
80 {
81 type = "Transfer";
82 }
83 if(item[3] == "3")
84 {
85 type = "Cash";
86 }
87 }
88
89 text.append(type);
90 text.append("<br>");
91 if (item[4] != "0")
92 {
93 text.append("<b>Check Number: </b>");
94 text.append(item[4]);
95 text.append("<br>");
96 }
97 if (item[6] != ".00")
98 {
99 text.append("<b>Extra Fee: </b>");
100 text.append(QString("$" + item[6]));
101 m_view->checkDetails->setText(text);
102 }
103 if (item[8] != "")
104 {
105 text.append("<br><b>Additional Comments: </b>");
106 text.append(item[8]);
107 }
108 m_view->checkDetails->setText(text);
109}
110
111void QCheckDetails::editCheck()
112{
113 emit editClicked(m_row, m_col);
114}
115
116void QCheckDetails::deleteCheck()
117{
118 emit deleteClicked(m_row, m_col);
119}
diff --git a/noncore/apps/checkbook/qcheckdetails.h b/noncore/apps/checkbook/qcheckdetails.h
new file mode 100644
index 0000000..fe5fe1a
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckdetails.h
@@ -0,0 +1,27 @@
1#include "qcheckdetailsbase.h"
2#include <qstring.h>
3#include <qtextview.h>
4#include <qtoolbar.h>
5#include <qpe/resource.h>
6#include <qpixmap.h>
7#include <qdialog.h>
8#include <qmainwindow.h>
9#include <qtoolbutton.h>
10#include <qwidget.h>
11
12class QCheckDetails : public QMainWindow
13{
14 Q_OBJECT
15 public:
16 QCheckDetails(int row, int col, const QStringList item);
17 signals:
18 void editClicked(int, int);
19 void deleteClicked(int, int);
20 public slots:
21 void editCheck();
22 void deleteCheck();
23 private:
24 int m_row;
25 int m_col;
26 QCheckDetailsBase *m_view;
27};
diff --git a/noncore/apps/checkbook/qcheckdetailsbase.ui b/noncore/apps/checkbook/qcheckdetailsbase.ui
new file mode 100644
index 0000000..d94ba5e
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckdetailsbase.ui
@@ -0,0 +1,62 @@
1<!DOCTYPE UI><UI>
2<class>QCheckDetailsBase</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>QCheckDetailsBase</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>240</width>
15 <height>265</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Transaction Details</string>
21 </property>
22 <grid>
23 <property stdset="1">
24 <name>margin</name>
25 <number>4</number>
26 </property>
27 <property stdset="1">
28 <name>spacing</name>
29 <number>0</number>
30 </property>
31 <widget row="0" column="0" >
32 <class>QTextView</class>
33 <property stdset="1">
34 <name>name</name>
35 <cstring>checkDetails</cstring>
36 </property>
37 </widget>
38 </grid>
39</widget>
40<customwidgets>
41 <customwidget>
42 <class>QWidget</class>
43 <header location="global">qwidget.h</header>
44 <sizehint>
45 <width>-1</width>
46 <height>-1</height>
47 </sizehint>
48 <container>0</container>
49 <sizepolicy>
50 <hordata>5</hordata>
51 <verdata>5</verdata>
52 </sizepolicy>
53 <pixmap>image0</pixmap>
54 </customwidget>
55</customwidgets>
56<images>
57 <image>
58 <name>image0</name>
59 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1ddec44f503c0ae2a154410f53d0ed20e2bf6bdb656dd6861dd23d9a66591b0587fd1654235ebded6f0edcd53e419d87ae7b1f4f9b8f906d0bfe012317426a70b07bdc2f3ec77f8ed6b89559061a0343d06a124cc105596482585094bc0ae599b04646c9018926491b2205e140c485cace25755c175d0a967b622ff900b8cc9c7d29af594ea722d589167f813aa852ba07d94b9dce296e883fe7bb163f23896753</data>
60 </image>
61</images>
62</UI>
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}
diff --git a/noncore/apps/checkbook/qcheckentry.h b/noncore/apps/checkbook/qcheckentry.h
new file mode 100644
index 0000000..f361bbf
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckentry.h
@@ -0,0 +1,31 @@
1#include <qstring.h>
2#include <qcombobox.h>
3#include "qrestrictedline.h"
4#include <qcombobox.h>
5#include <qstringlist.h>
6#include <qlabel.h>
7#include <qmultilineedit.h>
8#include "qcheckentrybase.h"
9#include <qdialog.h>
10#include <qregexp.h>
11#include <qmessagebox.h>
12#include <qwidget.h>
13#include <qevent.h>
14#include <qdatetime.h>
15#include <qradiobutton.h>
16#include "config.h"
17
18class QCheckEntry : public QCheckEntryBase
19{
20 Q_OBJECT
21 public:
22 QCheckEntry();
23 static QStringList popupEntry(const QStringList &originaldata);
24 private slots:
25 void amountChanged(const QString &);
26 void transFeeChanged(const QString &);
27 void paymentClicked();
28 void depositClicked();
29 protected slots:
30 virtual void accept();
31};
diff --git a/noncore/apps/checkbook/qcheckentrybase.ui b/noncore/apps/checkbook/qcheckentrybase.ui
new file mode 100644
index 0000000..a57d761
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckentrybase.ui
@@ -0,0 +1,603 @@
1<!DOCTYPE UI><UI>
2<class>QCheckEntryBase</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>QCheckEntryBase</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>228</width>
15 <height>291</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Account Transaction</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <property>
26 <name>layoutSpacing</name>
27 </property>
28 <grid>
29 <property stdset="1">
30 <name>margin</name>
31 <number>5</number>
32 </property>
33 <property stdset="1">
34 <name>spacing</name>
35 <number>2</number>
36 </property>
37 <spacer row="7" column="8" rowspan="1" colspan="4" >
38 <property>
39 <name>name</name>
40 <cstring>Spacer3</cstring>
41 </property>
42 <property stdset="1">
43 <name>orientation</name>
44 <enum>Horizontal</enum>
45 </property>
46 <property stdset="1">
47 <name>sizeType</name>
48 <enum>Expanding</enum>
49 </property>
50 <property>
51 <name>sizeHint</name>
52 <size>
53 <width>20</width>
54 <height>20</height>
55 </size>
56 </property>
57 </spacer>
58 <spacer row="3" column="1" rowspan="1" colspan="4" >
59 <property>
60 <name>name</name>
61 <cstring>Spacer5</cstring>
62 </property>
63 <property stdset="1">
64 <name>orientation</name>
65 <enum>Horizontal</enum>
66 </property>
67 <property stdset="1">
68 <name>sizeType</name>
69 <enum>Expanding</enum>
70 </property>
71 <property>
72 <name>sizeHint</name>
73 <size>
74 <width>20</width>
75 <height>20</height>
76 </size>
77 </property>
78 </spacer>
79 <widget row="5" column="5" >
80 <class>QLabel</class>
81 <property stdset="1">
82 <name>name</name>
83 <cstring>TextLabel6</cstring>
84 </property>
85 <property stdset="1">
86 <name>font</name>
87 <font>
88 <family>adobe-helvetica</family>
89 <bold>1</bold>
90 </font>
91 </property>
92 <property stdset="1">
93 <name>text</name>
94 <string>$</string>
95 </property>
96 </widget>
97 <spacer row="4" column="6" >
98 <property>
99 <name>name</name>
100 <cstring>Spacer8</cstring>
101 </property>
102 <property stdset="1">
103 <name>orientation</name>
104 <enum>Horizontal</enum>
105 </property>
106 <property stdset="1">
107 <name>sizeType</name>
108 <enum>Expanding</enum>
109 </property>
110 <property>
111 <name>sizeHint</name>
112 <size>
113 <width>20</width>
114 <height>20</height>
115 </size>
116 </property>
117 </spacer>
118 <widget row="2" column="0" rowspan="1" colspan="3" >
119 <class>QLabel</class>
120 <property stdset="1">
121 <name>name</name>
122 <cstring>TextLabel2</cstring>
123 </property>
124 <property stdset="1">
125 <name>text</name>
126 <string>Category:</string>
127 </property>
128 </widget>
129 <spacer row="5" column="2" rowspan="1" colspan="3" >
130 <property>
131 <name>name</name>
132 <cstring>Spacer7</cstring>
133 </property>
134 <property stdset="1">
135 <name>orientation</name>
136 <enum>Horizontal</enum>
137 </property>
138 <property stdset="1">
139 <name>sizeType</name>
140 <enum>Expanding</enum>
141 </property>
142 <property>
143 <name>sizeHint</name>
144 <size>
145 <width>20</width>
146 <height>20</height>
147 </size>
148 </property>
149 </spacer>
150 <spacer row="5" column="11" >
151 <property>
152 <name>name</name>
153 <cstring>Spacer4</cstring>
154 </property>
155 <property stdset="1">
156 <name>orientation</name>
157 <enum>Horizontal</enum>
158 </property>
159 <property stdset="1">
160 <name>sizeType</name>
161 <enum>Expanding</enum>
162 </property>
163 <property>
164 <name>sizeHint</name>
165 <size>
166 <width>20</width>
167 <height>20</height>
168 </size>
169 </property>
170 </spacer>
171 <spacer row="2" column="3" rowspan="1" colspan="2" >
172 <property>
173 <name>name</name>
174 <cstring>Spacer6</cstring>
175 </property>
176 <property stdset="1">
177 <name>orientation</name>
178 <enum>Horizontal</enum>
179 </property>
180 <property stdset="1">
181 <name>sizeType</name>
182 <enum>Expanding</enum>
183 </property>
184 <property>
185 <name>sizeHint</name>
186 <size>
187 <width>20</width>
188 <height>20</height>
189 </size>
190 </property>
191 </spacer>
192 <widget row="5" column="6" rowspan="1" colspan="5" >
193 <class>QRestrictedLine</class>
194 <property stdset="1">
195 <name>name</name>
196 <cstring>transAmount</cstring>
197 </property>
198 </widget>
199 <widget row="1" column="0" rowspan="1" colspan="5" >
200 <class>QLabel</class>
201 <property stdset="1">
202 <name>name</name>
203 <cstring>TextLabel1</cstring>
204 </property>
205 <property stdset="1">
206 <name>text</name>
207 <string>Description:</string>
208 </property>
209 </widget>
210 <widget row="3" column="0" >
211 <class>QLabel</class>
212 <property stdset="1">
213 <name>name</name>
214 <cstring>TextLabel3</cstring>
215 </property>
216 <property stdset="1">
217 <name>text</name>
218 <string>Type:</string>
219 </property>
220 </widget>
221 <widget row="5" column="0" rowspan="1" colspan="2" >
222 <class>QLabel</class>
223 <property stdset="1">
224 <name>name</name>
225 <cstring>TextLabel5</cstring>
226 </property>
227 <property stdset="1">
228 <name>text</name>
229 <string>Amount:</string>
230 </property>
231 </widget>
232 <widget row="2" column="5" rowspan="1" colspan="7" >
233 <class>QComboBox</class>
234 <item>
235 <property>
236 <name>text</name>
237 <string>Automobile</string>
238 </property>
239 </item>
240 <item>
241 <property>
242 <name>text</name>
243 <string>Bills</string>
244 </property>
245 </item>
246 <item>
247 <property>
248 <name>text</name>
249 <string>CDs</string>
250 </property>
251 </item>
252 <item>
253 <property>
254 <name>text</name>
255 <string>Clothing</string>
256 </property>
257 </item>
258 <item>
259 <property>
260 <name>text</name>
261 <string>Computer</string>
262 </property>
263 </item>
264 <item>
265 <property>
266 <name>text</name>
267 <string>DVDs</string>
268 </property>
269 </item>
270 <item>
271 <property>
272 <name>text</name>
273 <string>Eletronics</string>
274 </property>
275 </item>
276 <item>
277 <property>
278 <name>text</name>
279 <string>Entertainment</string>
280 </property>
281 </item>
282 <item>
283 <property>
284 <name>text</name>
285 <string>Food</string>
286 </property>
287 </item>
288 <item>
289 <property>
290 <name>text</name>
291 <string>Gasoline</string>
292 </property>
293 </item>
294 <item>
295 <property>
296 <name>text</name>
297 <string>Misc</string>
298 </property>
299 </item>
300 <item>
301 <property>
302 <name>text</name>
303 <string>Movies</string>
304 </property>
305 </item>
306 <item>
307 <property>
308 <name>text</name>
309 <string>Rent</string>
310 </property>
311 </item>
312 <item>
313 <property>
314 <name>text</name>
315 <string>Travel</string>
316 </property>
317 </item>
318 <property stdset="1">
319 <name>name</name>
320 <cstring>cmbCategory</cstring>
321 </property>
322 <property stdset="1">
323 <name>editable</name>
324 <bool>true</bool>
325 </property>
326 <property stdset="1">
327 <name>currentItem</name>
328 <number>0</number>
329 </property>
330 <property stdset="1">
331 <name>autoCompletion</name>
332 <bool>true</bool>
333 </property>
334 <property stdset="1">
335 <name>duplicatesEnabled</name>
336 <bool>false</bool>
337 </property>
338 </widget>
339 <widget row="4" column="0" rowspan="1" colspan="6" >
340 <class>QLabel</class>
341 <property stdset="1">
342 <name>name</name>
343 <cstring>TextLabel4</cstring>
344 </property>
345 <property stdset="1">
346 <name>text</name>
347 <string>Check Number:</string>
348 </property>
349 </widget>
350 <widget row="6" column="4" >
351 <class>QLabel</class>
352 <property stdset="1">
353 <name>name</name>
354 <cstring>TextLabel6_2</cstring>
355 </property>
356 <property stdset="1">
357 <name>font</name>
358 <font>
359 <family>adobe-helvetica</family>
360 <bold>1</bold>
361 </font>
362 </property>
363 <property stdset="1">
364 <name>text</name>
365 <string>$</string>
366 </property>
367 </widget>
368 <widget row="6" column="5" rowspan="1" colspan="4" >
369 <class>QRestrictedLine</class>
370 <property stdset="1">
371 <name>name</name>
372 <cstring>transFee</cstring>
373 </property>
374 </widget>
375 <widget row="6" column="0" rowspan="1" colspan="4" >
376 <class>QLabel</class>
377 <property stdset="1">
378 <name>name</name>
379 <cstring>TextLabel7</cstring>
380 </property>
381 <property stdset="1">
382 <name>text</name>
383 <string>Extra Fee:</string>
384 </property>
385 </widget>
386 <widget row="7" column="0" rowspan="1" colspan="8" >
387 <class>QLabel</class>
388 <property stdset="1">
389 <name>name</name>
390 <cstring>TextLabel8</cstring>
391 </property>
392 <property stdset="1">
393 <name>text</name>
394 <string>Additional Notes:</string>
395 </property>
396 </widget>
397 <widget row="1" column="5" rowspan="1" colspan="7" >
398 <class>QComboBox</class>
399 <property stdset="1">
400 <name>name</name>
401 <cstring>descriptionCombo</cstring>
402 </property>
403 <property stdset="1">
404 <name>editable</name>
405 <bool>true</bool>
406 </property>
407 <property stdset="1">
408 <name>maxCount</name>
409 <number>10</number>
410 </property>
411 <property stdset="1">
412 <name>insertionPolicy</name>
413 <enum>BeforeCurrent</enum>
414 </property>
415 <property stdset="1">
416 <name>autoCompletion</name>
417 <bool>true</bool>
418 </property>
419 <property stdset="1">
420 <name>duplicatesEnabled</name>
421 <bool>false</bool>
422 </property>
423 </widget>
424 <widget row="6" column="9" >
425 <class>QLabel</class>
426 <property stdset="1">
427 <name>name</name>
428 <cstring>TextLabel9</cstring>
429 </property>
430 <property stdset="1">
431 <name>minimumSize</name>
432 <size>
433 <width>0</width>
434 <height>0</height>
435 </size>
436 </property>
437 <property stdset="1">
438 <name>maximumSize</name>
439 <size>
440 <width>32767</width>
441 <height>32767</height>
442 </size>
443 </property>
444 <property stdset="1">
445 <name>caption</name>
446 <string></string>
447 </property>
448 <property stdset="1">
449 <name>text</name>
450 <string>Date:</string>
451 </property>
452 </widget>
453 <widget row="6" column="10" rowspan="1" colspan="2" >
454 <class>QRestrictedLine</class>
455 <property stdset="1">
456 <name>name</name>
457 <cstring>dateEdit</cstring>
458 </property>
459 </widget>
460 <widget row="4" column="7" rowspan="1" colspan="5" >
461 <class>QRestrictedLine</class>
462 <property stdset="1">
463 <name>name</name>
464 <cstring>checkNumber</cstring>
465 </property>
466 </widget>
467 <widget row="3" column="5" rowspan="1" colspan="7" >
468 <class>QComboBox</class>
469 <item>
470 <property>
471 <name>text</name>
472 <string>Debit Charge</string>
473 </property>
474 </item>
475 <item>
476 <property>
477 <name>text</name>
478 <string>Written Check</string>
479 </property>
480 </item>
481 <item>
482 <property>
483 <name>text</name>
484 <string>Transfer</string>
485 </property>
486 </item>
487 <item>
488 <property>
489 <name>text</name>
490 <string>Credit Card</string>
491 </property>
492 </item>
493 <property stdset="1">
494 <name>name</name>
495 <cstring>transType</cstring>
496 </property>
497 </widget>
498 <widget row="8" column="0" rowspan="1" colspan="12" >
499 <class>QMultiLineEdit</class>
500 <property stdset="1">
501 <name>name</name>
502 <cstring>additionalNotes</cstring>
503 </property>
504 </widget>
505 <widget row="0" column="0" rowspan="1" colspan="12" >
506 <class>QButtonGroup</class>
507 <property stdset="1">
508 <name>name</name>
509 <cstring>ButtonGroup3</cstring>
510 </property>
511 <property stdset="1">
512 <name>sizePolicy</name>
513 <sizepolicy>
514 <hsizetype>7</hsizetype>
515 <vsizetype>7</vsizetype>
516 </sizepolicy>
517 </property>
518 <property stdset="1">
519 <name>title</name>
520 <string></string>
521 </property>
522 <property>
523 <name>layoutMargin</name>
524 </property>
525 <property>
526 <name>layoutSpacing</name>
527 </property>
528 <grid>
529 <property stdset="1">
530 <name>margin</name>
531 <number>4</number>
532 </property>
533 <property stdset="1">
534 <name>spacing</name>
535 <number>0</number>
536 </property>
537 <widget row="0" column="1" >
538 <class>QRadioButton</class>
539 <property stdset="1">
540 <name>name</name>
541 <cstring>deposit</cstring>
542 </property>
543 <property stdset="1">
544 <name>sizePolicy</name>
545 <sizepolicy>
546 <hsizetype>1</hsizetype>
547 <vsizetype>1</vsizetype>
548 </sizepolicy>
549 </property>
550 <property stdset="1">
551 <name>text</name>
552 <string>Deposit</string>
553 </property>
554 </widget>
555 <widget row="0" column="0" >
556 <class>QRadioButton</class>
557 <property stdset="1">
558 <name>name</name>
559 <cstring>payment</cstring>
560 </property>
561 <property stdset="1">
562 <name>sizePolicy</name>
563 <sizepolicy>
564 <hsizetype>1</hsizetype>
565 <vsizetype>1</vsizetype>
566 </sizepolicy>
567 </property>
568 <property stdset="1">
569 <name>text</name>
570 <string>Payment</string>
571 </property>
572 <property stdset="1">
573 <name>checked</name>
574 <bool>true</bool>
575 </property>
576 </widget>
577 </grid>
578 </widget>
579 </grid>
580</widget>
581<customwidgets>
582 <customwidget>
583 <class>QRestrictedLine</class>
584 <header location="local">qrestrictedline.h</header>
585 <sizehint>
586 <width>-1</width>
587 <height>-1</height>
588 </sizehint>
589 <container>0</container>
590 <sizepolicy>
591 <hordata>5</hordata>
592 <verdata>5</verdata>
593 </sizepolicy>
594 <pixmap>image0</pixmap>
595 </customwidget>
596</customwidgets>
597<images>
598 <image>
599 <name>image0</name>
600 <data format="XPM.GZ" length="649">789c6dd23b0ec2300c00d03da7b0e22d42e9476c88232031222186c80c3074813220c4dd214dddd84dac0e759fe2386e1a07a7e3015c639e6318ef04740b0f70d7d730bccf97fdc7d8be87f8406737c62210606869dbb531f531a57f4a299d03a7e06c11cca1055508412c2889acc2ef425423b34840a645f28244936860d2c265d7923bae8b2f05cb35a91739002d2b5727d535cbe954a43ad1e22f700755caf7407cf4799fe286c47dbe3bf303014167a2</data>
601 </image>
602</images>
603</UI>
diff --git a/noncore/apps/checkbook/qcheckgraph.cpp b/noncore/apps/checkbook/qcheckgraph.cpp
new file mode 100644
index 0000000..5b21ad8
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckgraph.cpp
@@ -0,0 +1,258 @@
1#include "qcheckgraph.h"
2
3#include <qpainter.h>
4#include <qmessagebox.h>
5#include <qfontmetrics.h>
6#include <qdir.h>
7#include <qfile.h>
8#include <qstringlist.h>
9#include <qdatetime.h>
10#include <qmenubar.h>
11#include <qpopupmenu.h>
12
13QCheckGraph::QCheckGraph(const QString filename)
14 : QCheckGraphBase()
15{
16 QMenuBar *bar = new QMenuBar(this);
17 bar->setMargin(0);
18 QPopupMenu *popup = new QPopupMenu;
19 popup->insertItem("&Save Graph...", this, SLOT(saveGraphAsPicture()));
20 bar->insertItem("&File", popup);
21
22 pixmapready = false;
23 config = new Config(filename, Config::File);
24 QString forresult = "";
25 QString forresult2 = "";
26 int i = 1;
27 for (; forresult != "Not Found"; i++)
28 {
29 config->setGroup(QString::number(i));
30 forresult = config->readEntry("Description", QString("Not Found"));
31 forresult2 = config->readEntry("Category", QString("Not Found"));
32 if (forresult != "Not Found")
33 {
34 if (list.contains(forresult2) == 0)
35 {
36 config->setGroup("Totals");
37 QString larger = config->readEntry("Spent", QString("no"));
38 QString smaller = config->readEntry(forresult2, QString("no"));
39 if (larger != "no" && smaller != "no")
40 {
41 list << forresult2;
42 QString percentage = calculator(smaller, larger, true);
43
44 // Here we calculate how many pixels tall it will be by multiplying it by 200.
45 QString pixels = calculator(percentage, QString("200"), false);
46
47 // This is done because it really doesn't need to have a decimal... just an int, and
48 // QString rounds doubles up to the nearest whole number in order to convert
49 // to an int (which is correct).
50 pixels = pixels.remove(pixels.find('.'), pixels.length());
51
52 if (pixels.toInt() <= 5)
53 {
54 pixels = "6";
55 }
56
57 list2 << pixels;
58 }
59 }
60 } else {
61 continue;
62 }
63 // We want to break this loop on the 7th (remember, starts at 0->6 == 7) item.
64 if (list.count() == 6)
65 {
66 break;
67 }
68 }
69 for (QStringList::Iterator it = list.begin(); it != list.end(); it++)
70 {
71 if ((*it).length() > 11)
72 {
73 (*it).truncate(8);
74 (*it).append("...");
75 }
76 }
77 graphPixmap();
78}
79
80void QCheckGraph::graphPixmap()
81{
82 pixmapready = false;
83 graph = QPixmap(240,250);
84 QPainter p;
85 p.begin(&graph);
86 p.fillRect(0, 0, 240, 300, QColor(255,255,255));
87 // Draw the graph lines
88
89 // Y
90 p.drawLine( 40, 50, 40, 252 );
91
92 // X
93 p.drawLine( 40, 252, 203, 252 );
94
95 // Y stepup lines
96 p.drawLine( 40, 50, 37, 50);
97 p.drawLine( 40, 70, 37, 70);
98 p.drawLine( 40, 90, 37, 90);
99 p.drawLine( 40, 110, 37, 110);
100 p.drawLine( 40, 130, 37, 130);
101 p.drawLine( 40, 150, 37, 150);
102 p.drawLine( 40, 170, 37, 170);
103 p.drawLine( 40, 190, 37, 190);
104 p.drawLine( 40, 210, 37, 210);
105 p.drawLine( 40, 230, 37, 230);
106 p.drawLine( 40, 245, 37, 245);
107
108
109 // Y stepup values
110 p.drawText((35 - p.fontMetrics().width("100")), (50 + (p.fontMetrics().height() / 2)), "100");
111 p.drawText((35 - p.fontMetrics().width("90")), (70 + (p.fontMetrics().height() / 2)), "90");
112 p.drawText((35 - p.fontMetrics().width("80")), (90 + (p.fontMetrics().height() / 2)), "80");
113 p.drawText((35 - p.fontMetrics().width("70")), (110 + (p.fontMetrics().height() / 2)), "70");
114 p.drawText((35 - p.fontMetrics().width("60")), (130 + (p.fontMetrics().height() / 2)), "60");
115 p.drawText((35 - p.fontMetrics().width("50")), (150 + (p.fontMetrics().height() / 2)), "50");
116 p.drawText((35 - p.fontMetrics().width("40")), (170 + (p.fontMetrics().height() / 2)), "40");
117 p.drawText((35 - p.fontMetrics().width("30")), (190 + (p.fontMetrics().height() / 2)), "30");
118 p.drawText((35 - p.fontMetrics().width("20")), (210 + (p.fontMetrics().height() / 2)), "20");
119 p.drawText((35 - p.fontMetrics().width("10")), (230 + (p.fontMetrics().height() / 2)), "10");
120 p.drawText((35 - p.fontMetrics().width("<10")), (245 + (p.fontMetrics().height() / 2)), "<10");
121
122 // Draw the axis[sic?] labels
123 QString ylabel = "Percentage";
124 int pixel = 100;
125 for (unsigned int i = 0; i != ylabel.length(); i++)
126 {
127 p.setBrush(QColor(0,0,0));
128 p.drawText(5,pixel, QString(ylabel[i]));
129 pixel = pixel + p.fontMetrics().height();
130 }
131 p.drawText(95, 265, "Category");
132
133 int i = 0;
134 // Hack: Using if()'s... switch was acting all wierd :{
135 QStringList::Iterator it2 = list2.begin();
136 for (QStringList::Iterator it = list.begin(); it != list.end(); it++)
137 {
138 qWarning(QString::number(i));
139 if (i ==0)
140 {
141 // For the color code:
142 p.setBrush(QColor(255,0,0));
143 p.drawRect(8,12, 8, 8);
144
145 // Now the text:
146 p.setBrush(QColor(0,0,0));
147 p.drawText(18,20, (*it));
148
149 // Last, but not least, we have the actual bar graph height.
150 p.setBrush(QColor(255,0,0));
151 p.drawRect(47, ((202 - (*it2).toInt()) + 50), 15, (*it2).toInt());
152 }
153 if (i ==1)
154 {
155 p.setBrush(QColor(255,255,0));
156 p.drawRect(78,12, 8, 8);
157
158 p.setBrush(QColor(0,0,0));
159 p.drawText(88,20, (*it));
160
161 p.setBrush(QColor(255,255,0));
162 p.drawRect(70, ((202 - (*it2).toInt()) + 50), 15, (*it2).toInt());
163 }
164 if (i==2)
165 {
166 p.setBrush(QColor(0,255,0));
167 p.drawRect(153,12, 8, 8);
168 p.setBrush(QColor(0,0,0));
169 p.drawText(163,20, (*it));
170
171 p.setBrush(QColor(0,255,0));
172 p.drawRect(98, ((202 - (*it2).toInt()) + 50), 15, (*it2).toInt());
173 }
174 if (i==3)
175 {
176 p.setBrush(QColor(89,12,54));
177 p.drawRect(8,27, 8, 8);
178 p.setBrush(QColor(0,0,0));
179 p.drawText(18,35, (*it));
180
181 p.setBrush(QColor(89,12,54));
182 p.drawRect(126, ((202 - (*it2).toInt()) + 50), 15, (*it2).toInt());
183 }
184 if (i==4)
185 {
186 p.setBrush(QColor(0,0,255));
187 p.drawRect(78,27, 8, 8);
188 p.setBrush(QColor(0,0,0));
189 p.drawText(88,35, (*it));
190 p.setBrush(QColor(0,0,255));
191 p.drawRect(154, ((202 - (*it2).toInt()) + 50), 15, (*it2).toInt());
192 }
193 if (i==5)
194 {
195 p.setBrush(QColor(100,40,0));
196 p.drawRect(153,27, 8, 8);
197 p.setBrush(QColor(0,0,0));
198 p.drawText(163,35, (*it));
199 p.setBrush(QColor(100,40,0));
200 p.drawRect(182, ((202 - (*it2).toInt()) + 50), 15, (*it2).toInt());
201 }
202 i++;
203 it2++;
204 }
205
206 p.end();
207 pixmapready = true;
208 graphWidget->setBackgroundPixmap(graph);
209}
210
211QString QCheckGraph::calculator(QString largervalue, QString smallervalue, bool divide)
212{
213 //largervalue = largervalue.remove(largervalue.find(".", 0, false), 1);
214 //smallervalue = smallervalue.remove(smallervalue.find(".", 0, false), 1);
215
216 double largercents = largervalue.toDouble();
217 double smallercents = smallervalue.toDouble();
218
219 double finalammount = 0;
220
221 if (divide == true)
222 {
223 finalammount = (largercents / smallercents);
224 } else {
225 finalammount = (largercents * smallercents);
226 }
227
228 qWarning(QString::number(finalammount));
229
230 return QString::number(finalammount);
231}
232
233/*void QCheckGraph::paintEvent(QPaintEvent *e)
234{
235 if (pixmapready == true)
236 {
237 bitBlt((QPaintDevice *)(graphWidget), 0, 0, graph, 0,0);
238 QWidget::paintEvent(e);
239 }
240}
241*/
242void QCheckGraph::saveGraphAsPicture()
243{
244 QString homedir = QDir::homeDirPath();
245 QDate current = QDate::currentDate();
246 QString datestring = QString::number(current.month());
247 datestring.append(QString::number(current.day()));
248 datestring.append(QString::number(current.year()));
249 QString filename = homedir;
250 filename.append("/Documents/graph");
251 filename.append(datestring);
252 filename.append(".png");
253 graph.save(filename, "PNG", 85);
254 QString graphmessage = "<qt>The graph was saved as graph";
255 graphmessage.append(datestring);
256 graphmessage.append(".png. You may access it by returning to your home screen and clicking on the \"Documents\" tab in the upper right hand screen</qt>");
257 QMessageBox::information(0, "File Saved", graphmessage);
258}
diff --git a/noncore/apps/checkbook/qcheckgraph.h b/noncore/apps/checkbook/qcheckgraph.h
new file mode 100644
index 0000000..1cafef8
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckgraph.h
@@ -0,0 +1,25 @@
1#include <qstring.h>
2#include <qmainwindow.h>
3#include <qwidget.h>
4#include <qstringlist.h>
5#include <qpixmap.h>
6#include "config.h"
7
8#include "qcheckgraphbase.h"
9
10class QCheckGraph : public QCheckGraphBase
11{
12 Q_OBJECT
13 public:
14 QCheckGraph(const QString);
15 private:
16 QStringList list;
17 QStringList list2;
18 QString calculator(QString larger, QString smaller, bool divide);
19 QPixmap graph;
20 void graphPixmap();
21 bool pixmapready;
22 Config *config;
23 private slots:
24 void saveGraphAsPicture();
25};
diff --git a/noncore/apps/checkbook/qcheckgraphbase.ui b/noncore/apps/checkbook/qcheckgraphbase.ui
new file mode 100644
index 0000000..2763839
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckgraphbase.ui
@@ -0,0 +1,62 @@
1<!DOCTYPE UI><UI>
2<class>QCheckGraphBase</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>QCheckGraphBase</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>236</width>
15 <height>285</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Account Graph</string>
21 </property>
22 <grid>
23 <property stdset="1">
24 <name>margin</name>
25 <number>0</number>
26 </property>
27 <property stdset="1">
28 <name>spacing</name>
29 <number>0</number>
30 </property>
31 <widget row="0" column="0" >
32 <class>QWidget</class>
33 <property stdset="1">
34 <name>name</name>
35 <cstring>graphWidget</cstring>
36 </property>
37 </widget>
38 </grid>
39</widget>
40<customwidgets>
41 <customwidget>
42 <class>QWidget</class>
43 <header location="global">qwidget.h</header>
44 <sizehint>
45 <width>-1</width>
46 <height>-1</height>
47 </sizehint>
48 <container>0</container>
49 <sizepolicy>
50 <hordata>5</hordata>
51 <verdata>5</verdata>
52 </sizepolicy>
53 <pixmap>image0</pixmap>
54 </customwidget>
55</customwidgets>
56<images>
57 <image>
58 <name>image0</name>
59 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1ddec44f503c0ae2a154410f53d0ed20e2bf6bdb656dd6861dd23d9a66591b0587fd1654235ebded6f0edcd53e419d87ae7b1f4f9b8f906d0bfe012317426a70b07bdc2f3ec77f8ed6b89559061a0343d06a124cc105596482585094bc0ae599b04646c9018926491b2205e140c485cace25755c175d0a967b622ff900b8cc9c7d29af594ea722d589167f813aa852ba07d94b9dce296e883fe7bb163f23896753</data>
60 </image>
61</images>
62</UI>
diff --git a/noncore/apps/checkbook/qcheckmainmenu.cpp b/noncore/apps/checkbook/qcheckmainmenu.cpp
new file mode 100644
index 0000000..2382513
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckmainmenu.cpp
@@ -0,0 +1,74 @@
1#include "qcheckmainmenu.h"
2#include "qcheckname.h"
3
4QCheckMainMenu::QCheckMainMenu(QWidget *parent)
5 : QCheckMMBase(parent)
6{
7 init();
8}
9
10void QCheckMainMenu::init()
11{
12 lstCheckBooks->clear();
13 QString checkdirname = QDir::homeDirPath();
14 checkdirname.append("/.checkbooks");
15 QDir checkdir(checkdirname);
16 if (checkdir.exists() == true)
17 {
18 QStringList checkbooks = checkdir.entryList("*.qcb", QDir::Files|QDir::Readable|QDir::Writable, QDir::Time);
19 for (QStringList::Iterator it = checkbooks.begin(); it != checkbooks.end(); it++)
20 {
21 (*it) = (*it).remove((*it).find('.'), (*it).length());
22 }
23 lstCheckBooks->insertStringList(checkbooks);
24 }
25 lstCheckBooks->clearSelection();
26 connect(lstCheckBooks, SIGNAL(clicked(QListBoxItem *)), this, SLOT(slotSelected(QListBoxItem *)));
27 lstCheckBooks->clearSelection();
28}
29
30void QCheckMainMenu::slotSelected(QListBoxItem *item)
31{
32 if (item != 0)
33 {
34 QString text = item->text();
35 if (text.isEmpty() == false)
36 {
37 text.append(".qcb");
38 QString checkdirname = QDir::homeDirPath();
39 checkdirname.append("/.checkbooks/");
40 text.prepend(checkdirname);
41 emit itemSelected(text);
42 }
43 }
44}
45
46void QCheckMainMenu::newClicked()
47{
48 QString checkname = QCheckName::getName();
49 if (checkname.isEmpty() == false)
50 {
51 QString checkdirname = QDir::homeDirPath();
52 checkdirname.append("/.checkbooks");
53 QDir checkdir(checkdirname);
54 if (checkdir.exists() == false)
55 {
56 checkdir.mkdir(checkdirname);
57 }
58 checkdirname.append("/");
59 checkdirname.append(checkname);
60 checkdirname.append(".qcb");
61 QFile file(checkdirname);
62 if (file.exists() == false)
63 {
64 file.open(IO_WriteOnly);
65 QTextStream os(&file);
66 os << "";
67 file.close();
68 }
69 QFileInfo fi(file);
70 QString noextension = fi.fileName();
71 noextension = noextension.remove(noextension.find('.'), noextension.length());
72 lstCheckBooks->insertItem(noextension);
73 }
74}
diff --git a/noncore/apps/checkbook/qcheckmainmenu.h b/noncore/apps/checkbook/qcheckmainmenu.h
new file mode 100644
index 0000000..456d3df
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckmainmenu.h
@@ -0,0 +1,27 @@
1#include <qwidget.h>
2#include <qtoolbutton.h>
3#include <qpopupmenu.h>
4#include <qfile.h>
5#include <qdir.h>
6#include <qtextstream.h>
7#include <qstring.h>
8#include <qlistbox.h>
9#include <qmessagebox.h>
10
11#include "qcheckmmbase.h"
12
13class QCheckMainMenu : public QCheckMMBase
14{
15 Q_OBJECT
16 public:
17 QCheckMainMenu(QWidget *);
18 signals:
19 void itemSelected(const QString &);
20 private:
21 void init();
22 private slots:
23 void slotSelected(QListBoxItem *);
24 public slots:
25 void newClicked();
26};
27
diff --git a/noncore/apps/checkbook/qcheckmmbase.ui b/noncore/apps/checkbook/qcheckmmbase.ui
new file mode 100644
index 0000000..efde990
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckmmbase.ui
@@ -0,0 +1,80 @@
1<!DOCTYPE UI><UI>
2<class>QCheckMMBase</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>QCheckMMBase</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>256</width>
15 <height>311</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Main Menu</string>
21 </property>
22 <grid>
23 <property stdset="1">
24 <name>margin</name>
25 <number>7</number>
26 </property>
27 <property stdset="1">
28 <name>spacing</name>
29 <number>3</number>
30 </property>
31 <widget row="0" column="0" >
32 <class>QLabel</class>
33 <property stdset="1">
34 <name>name</name>
35 <cstring>TextLabel2</cstring>
36 </property>
37 <property stdset="1">
38 <name>text</name>
39 <string>Select from the check books below or click the "New" icon in the toolbar.</string>
40 </property>
41 <property stdset="1">
42 <name>alignment</name>
43 <set>WordBreak|AlignVCenter|AlignLeft</set>
44 </property>
45 <property>
46 <name>wordwrap</name>
47 </property>
48 </widget>
49 <widget row="1" column="0" >
50 <class>QListBox</class>
51 <property stdset="1">
52 <name>name</name>
53 <cstring>lstCheckBooks</cstring>
54 </property>
55 </widget>
56 </grid>
57</widget>
58<customwidgets>
59 <customwidget>
60 <class>QWidget</class>
61 <header location="global">qwidget.h</header>
62 <sizehint>
63 <width>-1</width>
64 <height>-1</height>
65 </sizehint>
66 <container>0</container>
67 <sizepolicy>
68 <hordata>5</hordata>
69 <verdata>5</verdata>
70 </sizepolicy>
71 <pixmap>image0</pixmap>
72 </customwidget>
73</customwidgets>
74<images>
75 <image>
76 <name>image0</name>
77 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1ddec44f503c0ae2a154410f53d0ed20e2bf6bdb656dd6861dd23d9a66591b0587fd1654235ebded6f0edcd53e419d87ae7b1f4f9b8f906d0bfe012317426a70b07bdc2f3ec77f8ed6b89559061a0343d06a124cc105596482585094bc0ae599b04646c9018926491b2205e140c485cace25755c175d0a967b622ff900b8cc9c7d29af594ea722d589167f813aa852ba07d94b9dce296e883fe7bb163f23896753</data>
78 </image>
79</images>
80</UI>
diff --git a/noncore/apps/checkbook/qcheckname.cpp b/noncore/apps/checkbook/qcheckname.cpp
new file mode 100644
index 0000000..0e4d71c
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckname.cpp
@@ -0,0 +1,36 @@
1#include "qcheckname.h"
2#include <qmessagebox.h>
3#include <qdialog.h>
4#include <qpushbutton.h>
5#include <qlineedit.h>
6#include "qrestrictedline.h"
7
8QCheckName::QCheckName()
9 : QCheckNameBase()
10{
11 connect(cmdDone, SIGNAL(clicked()), this, SLOT(clicked()));
12}
13
14QString QCheckName::getName()
15{
16 QCheckName qcn;
17 qcn.setWFlags(Qt::WType_Modal);
18 qcn.leText->setValidChars("abcdefghijklmnopqrstuvwxyz0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ");
19 if (qcn.exec() == QDialog::Accepted)
20 {
21 return qcn.leText->text();
22 } else {
23 return QString("");
24 }
25}
26
27void QCheckName::clicked()
28{
29 if (leText->text().isEmpty() == false)
30 {
31 hide();
32 accept();
33 } else {
34 QMessageBox::critical(this, "Missing Information", "<qt>Please enter the name of your Check Book and try again.</qt>");
35 }
36}
diff --git a/noncore/apps/checkbook/qcheckname.h b/noncore/apps/checkbook/qcheckname.h
new file mode 100644
index 0000000..c47c4f9
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckname.h
@@ -0,0 +1,15 @@
1#include "qchecknamebase.h"
2#include <qstring.h>
3#include <qwidget.h>
4
5class QCheckName : public QCheckNameBase
6{
7 Q_OBJECT
8 public:
9 QCheckName();
10 static QString getName();
11 private:
12 QWidget *m_parent;
13 private slots:
14 void clicked();
15};
diff --git a/noncore/apps/checkbook/qchecknamebase.ui b/noncore/apps/checkbook/qchecknamebase.ui
new file mode 100644
index 0000000..b9bda19
--- a/dev/null
+++ b/noncore/apps/checkbook/qchecknamebase.ui
@@ -0,0 +1,136 @@
1<!DOCTYPE UI><UI>
2<class>QCheckNameBase</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>QCheckNameBase</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>228</width>
15 <height>108</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Check Book Name</string>
21 </property>
22 <widget>
23 <class>QLabel</class>
24 <property stdset="1">
25 <name>name</name>
26 <cstring>TextLabel3</cstring>
27 </property>
28 <property stdset="1">
29 <name>geometry</name>
30 <rect>
31 <x>10</x>
32 <y>5</y>
33 <width>70</width>
34 <height>16</height>
35 </rect>
36 </property>
37 <property stdset="1">
38 <name>font</name>
39 <font>
40 <family>BDF-helvetica</family>
41 <pointsize>19</pointsize>
42 <bold>1</bold>
43 </font>
44 </property>
45 <property stdset="1">
46 <name>text</name>
47 <string>Name...</string>
48 </property>
49 </widget>
50 <widget>
51 <class>QLabel</class>
52 <property stdset="1">
53 <name>name</name>
54 <cstring>TextLabel4</cstring>
55 </property>
56 <property stdset="1">
57 <name>geometry</name>
58 <rect>
59 <x>10</x>
60 <y>25</y>
61 <width>210</width>
62 <height>25</height>
63 </rect>
64 </property>
65 <property stdset="1">
66 <name>text</name>
67 <string>Please name your check book (limit: 15 characters):</string>
68 </property>
69 <property stdset="1">
70 <name>alignment</name>
71 <set>WordBreak|AlignVCenter|AlignLeft</set>
72 </property>
73 <property>
74 <name>wordwrap</name>
75 </property>
76 </widget>
77 <widget>
78 <class>QPushButton</class>
79 <property stdset="1">
80 <name>name</name>
81 <cstring>cmdDone</cstring>
82 </property>
83 <property stdset="1">
84 <name>geometry</name>
85 <rect>
86 <x>75</x>
87 <y>80</y>
88 <width>75</width>
89 <height>25</height>
90 </rect>
91 </property>
92 <property stdset="1">
93 <name>text</name>
94 <string>&amp;Done</string>
95 </property>
96 </widget>
97 <widget>
98 <class>QRestrictedLine</class>
99 <property stdset="1">
100 <name>name</name>
101 <cstring>leText</cstring>
102 </property>
103 <property stdset="1">
104 <name>geometry</name>
105 <rect>
106 <x>5</x>
107 <y>51</y>
108 <width>216</width>
109 <height>25</height>
110 </rect>
111 </property>
112 </widget>
113</widget>
114<customwidgets>
115 <customwidget>
116 <class>QRestrictedLine</class>
117 <header location="local">qrestrictedline.h</header>
118 <sizehint>
119 <width>-1</width>
120 <height>-1</height>
121 </sizehint>
122 <container>0</container>
123 <sizepolicy>
124 <hordata>5</hordata>
125 <verdata>5</verdata>
126 </sizepolicy>
127 <pixmap>image0</pixmap>
128 </customwidget>
129</customwidgets>
130<images>
131 <image>
132 <name>image0</name>
133 <data format="XPM.GZ" length="649">789c6dd23b0ec2300c00d03da7b0e22d42e9476c88232031222186c80c3074813220c4dd214dddd84dac0e759fe2386e1a07a7e3015c639e6318ef04740b0f70d7d730bccf97fdc7d8be87f8406737c62210606869dbb531f531a57f4a299d03a7e06c11cca1055508412c2889acc2ef425423b34840a645f28244936860d2c265d7923bae8b2f05cb35a91739002d2b5727d535cbe954a43ad1e22f700755caf7407cf4799fe286c47dbe3bf303014167a2</data>
134 </image>
135</images>
136</UI>
diff --git a/noncore/apps/checkbook/qcheckview.cpp b/noncore/apps/checkbook/qcheckview.cpp
new file mode 100644
index 0000000..6f103e2
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckview.cpp
@@ -0,0 +1,458 @@
1#include "qcheckview.h"
2
3#include <qpe/resource.h>
4#include <qregexp.h>
5#include <qlineedit.h>
6#include <qradiobutton.h>
7#include <qcombobox.h>
8#include <qapplication.h>
9#include <qpushbutton.h>
10#include <qdir.h>
11#include <qlabel.h>
12#include <qdatetime.h>
13#include <qmessagebox.h>
14#include <qcheckbox.h>
15#include <qfile.h>
16#include <qtextstream.h>
17#include <qbuttongroup.h>
18#include <qradiobutton.h>
19#include <qheader.h>
20
21QCheckView::QCheckView(QWidget *parent, QString filename)
22 : QCheckViewBase(parent)
23{
24 tblTransactions->setHScrollBarMode( QTable::AlwaysOff );
25 tblTransactions->setNumRows( 0 );
26 tblTransactions->setNumCols( 4 );
27 tblTransactions->setShowGrid( FALSE );
28 tblTransactions->horizontalHeader()->setLabel(0, "Num", 29);
29 tblTransactions->horizontalHeader()->setLabel(1, "Description", 81);
30 tblTransactions->horizontalHeader()->setLabel(2, "Date", 57);
31 tblTransactions->horizontalHeader()->setLabel(3, "Amount", 59);
32 tblTransactions->verticalHeader()->hide();
33 tblTransactions->setLeftMargin( 0 );
34 tblTransactions->setSelectionMode(QTable::NoSelection);
35
36 m_filename = filename;
37 load(filename);
38}
39
40void QCheckView::deleteClicked(int row, int col)
41{
42 QStringList existing;
43 QString rowText = tblTransactions->text(row, 0);
44 config->setGroup(rowText);
45 QString originalamount = config->readEntry("Amount", "0.00");
46
47 config->setGroup("Data");
48 int lastCheck = config->readNumEntry("LastCheck", 0);
49
50 qWarning(rowText);
51 config->setGroup(rowText);
52 QString payment = config->readEntry("Payment", "true");
53 if ( payment == QString("true") && rowText.toInt() <= lastCheck)
54 {
55 for(int i = row; i != (lastCheck); i++)
56 {
57 config->setGroup(tblTransactions->text(i, 0));
58 QString ibalance = config->readEntry("Balance", "0.00");
59 // this adds the old amount on to the transaction and then takes the new amount away
60 QString newbalance = calculator(ibalance, originalamount, false);
61 config->writeEntry("Balance", newbalance);
62
63 if (i == (lastCheck - 1))
64 {
65 config->setGroup("Totals");
66 config->writeEntry("Balance", newbalance);
67 break;
68 }
69 }
70 QString category = config->readEntry("Category", "Error");
71 if (category != QString("Error"))
72 {
73 config->setGroup("Totals");
74 config->writeEntry("Spent", calculator(config->readEntry("Spent", QString("0")), originalamount, true));
75 QString categorytotal = config->readEntry(category, QString("0"));
76 categorytotal = calculator(categorytotal, originalamount, true);
77 config->writeEntry(category, categorytotal);
78 }
79 }
80 if ( payment == QString("false") && rowText.toInt() <= lastCheck)
81 {
82 for(int i = row; i != (lastCheck); i++)
83 {
84 config->setGroup(tblTransactions->text(i, 0));
85 QString ibalance = config->readEntry("Balance", "0.00");
86 // this subtracts the old amount on to the transaction and then adds the new amount on
87 QString newbalance = calculator(ibalance, originalamount, true);
88 config->writeEntry("Balance", newbalance);
89
90 if (i == lastCheck - 1)
91 {
92 config->setGroup("Totals");
93 config->writeEntry("Balance", newbalance);
94 break;
95 }
96 }
97 config->setGroup("Totals");
98 config->writeEntry("Deposited", calculator(config->readEntry("Deposited", QString("0")), originalamount, true));
99 }
100 for (int i = rowText.toInt(); i != lastCheck; i++)
101 {
102 qWarning(QString::number(i +1));
103 config->setGroup(QString::number(i +1));
104 QString origamount = config->readEntry("Amount", "0");
105 qWarning(origamount);
106 QString origbalance = config->readEntry("Balance", "0");
107 QString origchecknumber = config->readEntry("CheckNumber", "0");
108 QString origcomments = config->readEntry("Comments", "");
109 QString origdate = config->readEntry("Date", "01/01/2000");
110 QString origdescription = config->readEntry("Description", "No Description");
111 QString origpayment = config->readEntry("Payment", "true");
112 QString origtransactionfee = config->readEntry("TransactionFee", "0");
113 QString origtype = config->readEntry("Type", "0");
114
115 if (config->hasKey("Category"))
116 {
117 QString origcategory = config->readEntry("Category", "No Category");
118 config->removeGroup();
119 config->setGroup(QString::number(i));
120 config->clearGroup();
121 config->writeEntry("Category", origcategory);
122 } else {
123 config->removeGroup();
124 config->setGroup(QString::number(i));
125 config->clearGroup();
126 }
127 config->writeEntry("Amount", origamount);
128 config->writeEntry("Balance", origbalance);
129 config->writeEntry("CheckNumber", origchecknumber);
130 config->writeEntry("Comments", origcomments);
131 config->writeEntry("Date", origdate);
132 config->writeEntry("Description", origdescription);
133 config->writeEntry("Payment", origpayment);
134 config->writeEntry("TransactionFee", origtransactionfee);
135 config->writeEntry("Type", origtype);
136 }
137 tblTransactions->clearCell(row, col);
138 labelBalance->setText(QString("$" + config->readEntry("Balance", QString("0.00"))));
139 config->setGroup("Data");
140 config->writeEntry("LastCheck", QString::number(QString(config->readEntry("LastCheck", 0)).toInt() -1));
141 config->write();
142 delete qcd;
143 emit reload(m_filename);
144
145}
146
147void QCheckView::load(const QString filename)
148{
149 config = new Config(filename, Config::File);
150
151 connect(tblTransactions, SIGNAL(clicked(int, int, int, const QPoint &)), this, SLOT(tableClicked(int, int, int, const QPoint &)));
152
153 config->setGroup("Totals");
154 labelBalance->setText(QString("$" + config->readEntry("Balance", QString("0.00"))));
155
156 config->setGroup("Data");
157 int lastCheck = config->readNumEntry("LastCheck", 1);
158 for (int i = 1; i != (lastCheck + 1); i++)
159 {
160 config->setGroup(QString::number(i));
161 QString item = config->readEntry("Description", QString("Not Found"));
162 if (item != "Not Found")
163 {
164 QTableItem *qti = new QTableItem(tblTransactions, QTableItem::Never, QString::number(i));
165 QTableItem *qti1 = new QTableItem(tblTransactions, QTableItem::Never, config->readEntry("Description", QString("None")));
166 QTableItem *qti2 = new QTableItem(tblTransactions, QTableItem::Never, config->readEntry("Date", QString("None")));
167 QTableItem *qti3 = new QTableItem(tblTransactions, QTableItem::Never, QString("$" + config->readEntry("Amount", QString("0.00"))));
168 int row = tblTransactions->numRows();
169 tblTransactions->setNumRows(row + 1);
170 tblTransactions->setItem(row,0, qti);
171 tblTransactions->setItem(row,1, qti1);
172 tblTransactions->setItem(row,2, qti2);
173 tblTransactions->setItem(row,3, qti3);
174 tblTransactions->updateCell(row, 0);
175 tblTransactions->updateCell(row, 1);
176 tblTransactions->updateCell(row, 2);
177 tblTransactions->updateCell(row, 3);
178 }
179 }
180}
181
182void QCheckView::editClicked(int row, int col)
183{
184 delete qcd;
185 QStringList existing;
186 QString rowText = tblTransactions->text(row, 0);
187 config->setGroup("Data");
188 QString recent = config->readEntry("Recent", "");
189
190 config->setGroup(rowText);
191 //We need the original amount to add or subtract to check's blanaces written after this edited check
192 QString originalamount = config->readEntry("Amount", "0.00");
193 QString originalcategory = config->readEntry("Category", "None");
194
195 existing << config->readEntry("Payment", "true") << config->readEntry("Description", "No Description Found") << config->readEntry("Category", "Misc.") << config->readEntry("Type", "0") << config->readEntry("CheckNumber", "0") << originalamount << config->readEntry("TransactionFee", "") << config->readEntry("Date", "01/01/2001") << config->readEntry("Comments", "") << recent;
196 QStringList result = QCheckEntry::popupEntry(existing);
197 if (result.isEmpty() == false)
198 {
199 config->setGroup("Data");
200 int lastCheck = config->readNumEntry("LastCheck", 0);
201 config->writeEntry("Recent", result[9]);
202
203 config->setGroup(rowText);
204
205 tblTransactions->setText(row, 1, result[1]);
206 tblTransactions->updateCell(row, 1);
207
208 tblTransactions->setText(row, 2, result[7]);
209 tblTransactions->updateCell(row, 2);
210
211 tblTransactions->setText(row, 3, QString("$" + result[5]));
212 tblTransactions->updateCell(row, 3);
213
214 // This is how the list looks:
215 // 0: true or false, true == payment, false == deposit
216 // 1: description of the transaction
217 // 2: category name
218 // 3: transaction type (stores the integer value of the index of the combobox)
219 // 4: check number of the transaction (if any)
220 // 5: transaction amount
221 // 6: transaction fee (e.g. service charge, or ATM charge).
222 // 7: date of the transaction
223 // 8: additional comments
224 config->writeEntry("Payment", result[0]);
225 config->writeEntry("Description", result[1]);
226 if (result[0] == QString("true"))
227 {
228 config->writeEntry("Category", result[2]);
229 }
230 config->writeEntry("Type", result[3]);
231 config->writeEntry("CheckNumber", result[4]);
232 config->writeEntry("Amount", result[5]);
233 config->writeEntry("TransactionFee", result[6]);
234 config->writeEntry("Date", result[7]);
235 config->writeEntry("Comments", result[8]);
236 if (result[0] == QString("true"))
237 {
238 if (rowText.toInt() <= lastCheck)
239 {
240 for(int i = (rowText.toInt() - 1); i != (lastCheck); i++)
241 {
242 config->setGroup(tblTransactions->text(i, 0));
243 QString ibalance = config->readEntry("Balance", "0.00");
244
245 // this adds the old amount on to the transaction and then takes the new amount away
246 QString newbalance = calculator(calculator(ibalance, originalamount, false), result[5], true);
247 config->writeEntry("Balance", newbalance);
248 if (i == (lastCheck - 1))
249 {
250 config->setGroup("Totals");
251 config->writeEntry("Balance", newbalance);
252 break;
253 }
254 }
255 }
256 config->setGroup("Totals");
257 config->writeEntry("Spent", calculator(config->readEntry("Spent", QString("0")), originalamount, true));
258 config->writeEntry("Spent", calculator(config->readEntry("Spent", QString("0")), result[5], false));
259
260 if (result[2] == originalcategory)
261 {
262 QString categorytotal = config->readEntry(result[2], QString("0"));
263 categorytotal = calculator(categorytotal, originalamount, true);
264 categorytotal = calculator(categorytotal, result[5], false);
265 config->writeEntry(result[2], categorytotal);
266 } else {
267 QString origtotal = config->readEntry(originalcategory, QString("0"));
268 QString origfinal = calculator(origtotal, result[5], true);
269 if (origfinal == "0" || origfinal == "0.00")
270 {
271 config->removeEntry(originalcategory);
272 } else {
273 config->writeEntry(originalcategory, origfinal);
274 }
275 QString categorytotal = config->readEntry(result[2], QString("0"));
276 categorytotal = calculator(categorytotal, originalamount, false);
277 config->writeEntry(result[2],categorytotal);
278 }
279 }
280 if (result[0] == QString("false"))
281 {
282 if (rowText.toInt() <= lastCheck)
283 {
284 for(int i = (rowText.toInt() - 1 ); i != (lastCheck); i++)
285 {
286 config->setGroup(tblTransactions->text(i, 0));
287 QString ibalance = config->readEntry("Balance", "0.00");
288
289 // this subtracts the old amount on to the transaction and then adds the new amount on
290 QString newbalance = calculator(calculator(ibalance, originalamount, true), result[5], false);
291 config->writeEntry("Balance", newbalance);
292 if (i == lastCheck - 1)
293 {
294 config->setGroup("Totals");
295 config->writeEntry("Balance", newbalance);
296 break;
297 }
298 }
299 }
300 config->setGroup("Totals");
301 config->writeEntry("Deposited", calculator(config->readEntry("Deposited", QString("0")), originalamount, true));
302 config->writeEntry("Deposited", calculator(config->readEntry("Deposited", QString("0")), result[5], false));
303 }
304 labelBalance->setText(QString("$" + config->readEntry("Balance", QString("0.00"))));
305 config->write();
306 }
307}
308void QCheckView::tableClicked(int row, int col, int mouseButton, const QPoint &mousePos)
309{
310 if (tblTransactions->text(row, col).isEmpty() == false)
311 {
312 QStringList existing;
313 config->setGroup(tblTransactions->text(row, 0));
314 existing << config->readEntry("Payment", "true") << config->readEntry("Description", "No Description Found") << config->readEntry("Category", "Misc.") << config->readEntry("Type", "0") << config->readEntry("CheckNumber", "0") << config->readEntry("Amount", "0.00") << config->readEntry("TransactionFee", "0.00") << config->readEntry("Date", "01/01/2001") << config->readEntry("Comments", "") << config->readEntry("Balance", "0.00");
315 qcd = new QCheckDetails(row, col, existing);
316 qcd->showMaximized();
317 connect(qcd, SIGNAL(editClicked(int, int)), this, SLOT(editClicked(int, int)));
318 connect(qcd, SIGNAL(deleteClicked(int, int)), this, SLOT(deleteClicked(int, int)));
319 }
320}
321
322void QCheckView::newClicked()
323{
324 config->setGroup("Data");
325 QString recent = config->readEntry("Recent", "");
326 QStringList kindablank;
327 kindablank << recent;
328 QStringList result = QCheckEntry::popupEntry(kindablank);
329 if (result.count() > 1)
330 {
331 QTableItem *qti = new QTableItem(tblTransactions, QTableItem::Never, result[1]);
332 int row = tblTransactions->numRows();
333 tblTransactions->setNumRows(row + 1);
334 tblTransactions->setItem(row,1, qti);
335 tblTransactions->updateCell(row, 1);
336 config->setGroup("Data");
337 config->writeEntry("Recent", result[9]);
338 int lastCheck = config->readNumEntry("LastCheck", 0);
339 if (lastCheck == 0)
340 {
341 config->writeEntry("LastCheck", 1);
342 } else {
343 config->writeEntry("LastCheck", (lastCheck + 1));
344 }
345 QString number = QString::number(lastCheck + 1);
346 config->setGroup(number);
347
348 QTableItem *qti1 = new QTableItem(tblTransactions, QTableItem::Never, number);
349 tblTransactions->setItem(row, 0, qti1);
350 tblTransactions->updateCell(row, 0);
351
352 QTableItem *qti2 = new QTableItem(tblTransactions, QTableItem::Never, result[7]);
353 tblTransactions->setItem(row, 2, qti2);
354 tblTransactions->updateCell(row, 2);
355
356 QTableItem *qti3 = new QTableItem(tblTransactions, QTableItem::Never, QString("$" + result[5]));
357 tblTransactions->setItem(row, 3, qti3);
358 tblTransactions->updateCell(row, 3);
359
360 // This is how the list looks:
361 // 0: true or false, true == payment, false == deposit
362 // 1: description of the transaction
363 // 2: category name
364 // 3: transaction type (stores the integer value of the index of the combobox)
365 // 4: check number of the transaction (if any)
366 // 5: transaction amount
367 // 6: transaction fee (e.g. service charge, or ATM charge).
368 // 7: date of the transaction
369 config->writeEntry("Payment", result[0]);
370 config->writeEntry("Description", result[1]);
371 if (result[0] == QString("true"))
372 {
373 config->writeEntry("Category", result[2]);
374 }
375 config->writeEntry("Type", result[3]);
376 config->writeEntry("CheckNumber", result[4]);
377 config->writeEntry("Amount", result[5]);
378 config->writeEntry("TransactionFee", result[6]);
379 config->writeEntry("Date", result[7]);
380 config->writeEntry("Comments", result[8]);
381 config->setGroup("Totals");
382 if (result[0] == QString("true"))
383 {
384 QString totalspent = config->readEntry("Spent", QString("0"));
385 totalspent = calculator(totalspent, result[5], false);
386 config->writeEntry("Spent", totalspent);
387 QString balance = config->readEntry("Balance", QString("0"));
388 balance = calculator(balance, result[5], true);
389
390 // Make sure to add the fee on, if any
391 balance = calculator(balance, result[6], true);
392
393 config->writeEntry("Balance", balance);
394
395 config->setGroup(number);
396 config->writeEntry("Balance", balance);
397
398 config->setGroup("Totals");
399 QString categorytotal = config->readEntry(result[2], QString("0"));
400 categorytotal = calculator(categorytotal, result[5], false);
401 config->writeEntry(result[2], categorytotal);
402 }
403 if (result[0] == QString("false"))
404 {
405 QString totaldeposited = config->readEntry("Deposited", QString("0"));
406 totaldeposited = calculator(totaldeposited, result[5], false);
407 config->writeEntry("Deposited", totaldeposited);
408 QString balance = config->readEntry("Balance", QString("0"));
409 balance = calculator(balance, result[5], false);
410
411 // Make sure to add the fee on, if any
412 balance = calculator(balance, result[6], true);
413
414 config->writeEntry("Balance", balance);
415
416 config->setGroup(number);
417 config->writeEntry("Balance", balance);
418 }
419 }
420 config->setGroup("Totals");
421 labelBalance->setText(QString("$" + config->readEntry("Balance", QString("0.00"))));
422 config->write();
423}
424
425QString QCheckView::calculator(QString largervalue, QString smallervalue, bool subtract)
426{
427 // This class provides a way to eliminate the ARM processor problem of not being able to handle
428 // decimals. I just take the two QString'ed numbers and find the decimal point, then I remove the decimal
429 // point seperating the number into two. Then I convert it to cents (times it times 100) and add/
430 // substract the two together. Put the decimals back in, and return.
431
432 largervalue = largervalue.remove(largervalue.find(".", 0, false), 1);
433 smallervalue = smallervalue.remove(smallervalue.find(".", 0, false), 1);
434
435 int largercents = largervalue.toInt();
436 int smallercents = smallervalue.toInt();
437
438 int finalammount = 0;
439
440 if (subtract == true)
441 {
442 finalammount = largercents - smallercents;
443 } else {
444 finalammount = largercents + smallercents;
445 }
446
447 QString returnvalue = QString::number(finalammount);
448 if (returnvalue.length() >= 2)
449 {
450 returnvalue.insert((returnvalue.length() - 2), ".");
451 } else {
452 if (returnvalue.length() == 1)
453 {
454 returnvalue.prepend("0.0");
455 }
456 }
457 return returnvalue;
458}
diff --git a/noncore/apps/checkbook/qcheckview.h b/noncore/apps/checkbook/qcheckview.h
new file mode 100644
index 0000000..840dc8b
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckview.h
@@ -0,0 +1,33 @@
1#include "qcheckviewbase.h"
2#include "qrestrictedline.h"
3#include "qcheckentry.h"
4#include "qcheckdetails.h"
5
6#include <qstring.h>
7#include "config.h"
8#include <qtable.h>
9#include <qpoint.h>
10#include <qlayout.h>
11
12class QCheckView : public QCheckViewBase
13{
14 Q_OBJECT
15 public:
16 QCheckView(QWidget *, QString filename);
17 void load(const QString filename);
18 private:
19 Config *config;
20 QString calculator(QString largervalue, QString smallervalue, bool subtract);
21 int lastSortCol;
22 bool ascend;
23 QCheckDetails *qcd;
24 QString m_filename;
25 private slots:
26 // void entryActivated(int);
27 void newClicked();
28 void tableClicked(int, int, int, const QPoint &mousePos);
29 void editClicked(int, int);
30 void deleteClicked(int, int);
31 signals:
32 void reload(const QString &filename);
33};
diff --git a/noncore/apps/checkbook/qcheckviewbase.ui b/noncore/apps/checkbook/qcheckviewbase.ui
new file mode 100644
index 0000000..00ed7dd
--- a/dev/null
+++ b/noncore/apps/checkbook/qcheckviewbase.ui
@@ -0,0 +1,122 @@
1<!DOCTYPE UI><UI>
2<class>QCheckViewBase</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>QCheckViewBase</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>242</width>
15 <height>312</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Account Transactions</string>
21 </property>
22 <grid>
23 <property stdset="1">
24 <name>margin</name>
25 <number>5</number>
26 </property>
27 <property stdset="1">
28 <name>spacing</name>
29 <number>1</number>
30 </property>
31 <widget row="0" column="1" >
32 <class>QLabel</class>
33 <property stdset="1">
34 <name>name</name>
35 <cstring>labelBalance</cstring>
36 </property>
37 <property stdset="1">
38 <name>frameShape</name>
39 <enum>MShape</enum>
40 </property>
41 <property stdset="1">
42 <name>frameShadow</name>
43 <enum>MShadow</enum>
44 </property>
45 <property stdset="1">
46 <name>text</name>
47 <string>$0.00</string>
48 </property>
49 <property stdset="1">
50 <name>alignment</name>
51 <set>AlignCenter</set>
52 </property>
53 <property>
54 <name>hAlign</name>
55 </property>
56 </widget>
57 <widget row="1" column="0" rowspan="1" colspan="2" >
58 <class>QTable</class>
59 <property stdset="1">
60 <name>name</name>
61 <cstring>tblTransactions</cstring>
62 </property>
63 <property stdset="1">
64 <name>hScrollBarMode</name>
65 <enum>AlwaysOff</enum>
66 </property>
67 <property stdset="1">
68 <name>numRows</name>
69 <number>0</number>
70 </property>
71 <property stdset="1">
72 <name>numCols</name>
73 <number>4</number>
74 </property>
75 <property stdset="1">
76 <name>showGrid</name>
77 <bool>false</bool>
78 </property>
79 </widget>
80 <widget row="0" column="0" >
81 <class>QLabel</class>
82 <property stdset="1">
83 <name>name</name>
84 <cstring>TextLabel3</cstring>
85 </property>
86 <property stdset="1">
87 <name>text</name>
88 <string>Balance:</string>
89 </property>
90 <property stdset="1">
91 <name>alignment</name>
92 <set>AlignVCenter|AlignRight</set>
93 </property>
94 <property>
95 <name>hAlign</name>
96 </property>
97 </widget>
98 </grid>
99</widget>
100<customwidgets>
101 <customwidget>
102 <class>QWidget</class>
103 <header location="global">qwidget.h</header>
104 <sizehint>
105 <width>-1</width>
106 <height>-1</height>
107 </sizehint>
108 <container>0</container>
109 <sizepolicy>
110 <hordata>5</hordata>
111 <verdata>5</verdata>
112 </sizepolicy>
113 <pixmap>image0</pixmap>
114 </customwidget>
115</customwidgets>
116<images>
117 <image>
118 <name>image0</name>
119 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1ddec44f503c0ae2a154410f53d0ed20e2bf6bdb656dd6861dd23d9a66591b0587fd1654235ebded6f0edcd53e419d87ae7b1f4f9b8f906d0bfe012317426a70b07bdc2f3ec77f8ed6b89559061a0343d06a124cc105596482585094bc0ae599b04646c9018926491b2205e140c485cace25755c175d0a967b622ff900b8cc9c7d29af594ea722d589167f813aa852ba07d94b9dce296e883fe7bb163f23896753</data>
120 </image>
121</images>
122</UI>
diff --git a/noncore/apps/checkbook/qrestrictedcombo.cpp b/noncore/apps/checkbook/qrestrictedcombo.cpp
new file mode 100644
index 0000000..e1533f6
--- a/dev/null
+++ b/noncore/apps/checkbook/qrestrictedcombo.cpp
@@ -0,0 +1,78 @@
1/*
2 *
3 * $Id$
4 *
5 * Implementation of QRestrictedCombo
6 *
7 * Copyright (C) 1997 Michael Wiedmann, <mw@miwie.in-berlin.de>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <qkeycode.h>
26
27#include "qrestrictedcombo.h"
28
29QRestrictedCombo::QRestrictedCombo( QWidget *parent,
30 const char *name,
31 const QString& valid )
32 : QComboBox( parent, name )
33{
34 qsValidChars = valid;
35}
36
37QRestrictedCombo::~QRestrictedCombo()
38{
39 ;
40}
41
42
43void QRestrictedCombo::keyPressEvent( QKeyEvent *e )
44{
45 // let QLineEdit process "special" keys and return/enter
46 // so that we still can use the default key binding
47 if (e->key() == Key_Enter || e->key() == Key_Return || e->key() == Key_Delete || e->ascii() < 32)
48 {
49 QComboBox::keyPressEvent(e);
50 return;
51 }
52
53 // do we have a list of valid chars &&
54 // is the pressed key in the list of valid chars?
55 if (!qsValidChars.isEmpty() && !qsValidChars.contains(e->ascii()))
56 {
57 // invalid char, emit signal and return
58 emit (invalidChar(e->key()));
59 return;
60 }
61 else
62 // valid char: let QLineEdit process this key as usual
63 QComboBox::keyPressEvent(e);
64
65 return;
66}
67
68
69void QRestrictedCombo::setValidChars( const QString& valid)
70{
71 qsValidChars = valid;
72}
73
74QString QRestrictedCombo::validChars() const
75{
76 return qsValidChars;
77}
78
diff --git a/noncore/apps/checkbook/qrestrictedcombo.h b/noncore/apps/checkbook/qrestrictedcombo.h
new file mode 100644
index 0000000..50ea59f
--- a/dev/null
+++ b/noncore/apps/checkbook/qrestrictedcombo.h
@@ -0,0 +1,96 @@
1/*
2 *
3 * Definition of QRestrictedCombo
4 *
5 * Copyright (C) 1997 Michael Wiedmann, <mw@miwie.in-berlin.de>
6 *
7 * Edited 2001 by Nick Betcher <nbetcher@usinternet.com> to work
8 * with Qt-only. Changed class name from LRestrictedLine to
9 * QRestrictedCombo in order to accomidate Combo Boxes.
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
20 *
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the Free
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27#ifndef QRESTRICTEDCOMBO_H
28#define QRESTRICTEDCOMBO_H
29
30#include <qcombobox.h>
31
32/**
33 * The QRestrictedCombo widget is a variant of @ref QComboBox which
34 * accepts only a restricted set of characters as input.
35 * All other characters will be discarded and the signal @ref #invalidChar()
36 * will be emitted for each of them.
37 *
38 * Valid characters can be passed as a QString to the constructor
39 * or set afterwards via @ref #setValidChars().
40 * The default key bindings of @ref QComboBox are still in effect.
41 *
42 * @short A line editor for restricted character sets.
43 * @author Michael Wiedmann <mw@miwie.in-berlin.de>
44 * @version 0.0.1
45 */
46class QRestrictedCombo : public QComboBox
47{
48 Q_OBJECT
49 Q_PROPERTY( QString validChars READ validChars WRITE setValidChars )
50
51public:
52
53 /**
54 * Constructor: This contructor takes three - optional - arguments.
55 * The first two parameters are simply passed on to @ref QLineEdit.
56 * @param parent pointer to the parent widget
57 * @param name pointer to the name of this widget
58 * @param valid pointer to set of valid characters
59 */
60 QRestrictedCombo( QWidget *parent=0, const char *name=0,
61 const QString& valid = QString::null);
62
63 /**
64 * Destructs the restricted line editor.
65 */
66 ~QRestrictedCombo();
67
68 /**
69 * All characters in the string valid are treated as
70 * acceptable characters.
71 */
72 void setValidChars(const QString& valid);
73 /**
74 * @return the string of acceptable characters.
75 */
76 QString validChars() const;
77
78signals:
79
80 /**
81 * Emitted when an invalid character was typed.
82 */
83 voidinvalidChar(int);
84
85protected:
86 /**
87 * @reimplemented
88 */
89 voidkeyPressEvent( QKeyEvent *e );
90
91private:
92 /// QString of valid characters for this line
93 QStringqsValidChars;
94};
95
96#endif // QRESTRICTEDCOMBO_H
diff --git a/noncore/apps/checkbook/qrestrictedline.cpp b/noncore/apps/checkbook/qrestrictedline.cpp
new file mode 100644
index 0000000..8508c33
--- a/dev/null
+++ b/noncore/apps/checkbook/qrestrictedline.cpp
@@ -0,0 +1,78 @@
1/*
2 *
3 * $Id$
4 *
5 * Implementation of QRestrictedLine
6 *
7 * Copyright (C) 1997 Michael Wiedmann, <mw@miwie.in-berlin.de>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <qkeycode.h>
26
27#include "qrestrictedline.h"
28
29QRestrictedLine::QRestrictedLine( QWidget *parent,
30 const char *name,
31 const QString& valid )
32 : QLineEdit( parent, name )
33{
34 qsValidChars = valid;
35}
36
37QRestrictedLine::~QRestrictedLine()
38{
39 ;
40}
41
42
43void QRestrictedLine::keyPressEvent( QKeyEvent *e )
44{
45 // let QLineEdit process "special" keys and return/enter
46 // so that we still can use the default key binding
47 if (e->key() == Key_Enter || e->key() == Key_Return || e->key() == Key_Delete || e->ascii() < 32)
48 {
49 QLineEdit::keyPressEvent(e);
50 return;
51 }
52
53 // do we have a list of valid chars &&
54 // is the pressed key in the list of valid chars?
55 if (!qsValidChars.isEmpty() && !qsValidChars.contains(e->ascii()))
56 {
57 // invalid char, emit signal and return
58 emit (invalidChar(e->key()));
59 return;
60 }
61 else
62 // valid char: let QLineEdit process this key as usual
63 QLineEdit::keyPressEvent(e);
64
65 return;
66}
67
68
69void QRestrictedLine::setValidChars( const QString& valid)
70{
71 qsValidChars = valid;
72}
73
74QString QRestrictedLine::validChars() const
75{
76 return qsValidChars;
77}
78
diff --git a/noncore/apps/checkbook/qrestrictedline.h b/noncore/apps/checkbook/qrestrictedline.h
new file mode 100644
index 0000000..7e41cd9
--- a/dev/null
+++ b/noncore/apps/checkbook/qrestrictedline.h
@@ -0,0 +1,96 @@
1/*
2 *
3 * Definition of QRestrictedLine
4 *
5 * Copyright (C) 1997 Michael Wiedmann, <mw@miwie.in-berlin.de>
6 *
7 * Edited 2001 by Nick Betcher <nbetcher@usinternet.com> to work
8 * with Qt-only. Changed class name from QRestrictedLine to
9 * QRestrictedLine.
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
20 *
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the Free
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27#ifndef QRESTRICTEDLINE_H
28#define QRESTRICTEDLINE_H
29
30#include <qlineedit.h>
31
32/**
33 * The QRestrictedLine widget is a variant of @ref QLineEdit which
34 * accepts only a restricted set of characters as input.
35 * All other characters will be discarded and the signal @ref #invalidChar()
36 * will be emitted for each of them.
37 *
38 * Valid characters can be passed as a QString to the constructor
39 * or set afterwards via @ref #setValidChars().
40 * The default key bindings of @ref QLineEdit are still in effect.
41 *
42 * @short A line editor for restricted character sets.
43 * @author Michael Wiedmann <mw@miwie.in-berlin.de>
44 * @version 0.0.1
45 */
46class QRestrictedLine : public QLineEdit
47{
48 Q_OBJECT
49 Q_PROPERTY( QString validChars READ validChars WRITE setValidChars )
50
51public:
52
53 /**
54 * Constructor: This contructor takes three - optional - arguments.
55 * The first two parameters are simply passed on to @ref QLineEdit.
56 * @param parent pointer to the parent widget
57 * @param name pointer to the name of this widget
58 * @param valid pointer to set of valid characters
59 */
60 QRestrictedLine( QWidget *parent=0, const char *name=0,
61 const QString& valid = QString::null);
62
63 /**
64 * Destructs the restricted line editor.
65 */
66 ~QRestrictedLine();
67
68 /**
69 * All characters in the string valid are treated as
70 * acceptable characters.
71 */
72 void setValidChars(const QString& valid);
73 /**
74 * @return the string of acceptable characters.
75 */
76 QString validChars() const;
77
78signals:
79
80 /**
81 * Emitted when an invalid character was typed.
82 */
83 voidinvalidChar(int);
84
85protected:
86 /**
87 * @reimplemented
88 */
89 voidkeyPressEvent( QKeyEvent *e );
90
91private:
92 /// QString of valid characters for this line
93 QStringqsValidChars;
94};
95
96#endif // QRESTRICTEDLINE_H