author | drw <drw> | 2005-06-03 18:31:12 (UTC) |
---|---|---|
committer | drw <drw> | 2005-06-03 18:31:12 (UTC) |
commit | 77736831bd44d6ca60ee573133cd72551d312dbc (patch) (side-by-side diff) | |
tree | 7bd56feaf8283e813d2064e7bef1177666897b5d | |
parent | d0f6a0721d7ab67a115d08990143944ee71d54ba (diff) | |
download | opie-77736831bd44d6ca60ee573133cd72551d312dbc.zip opie-77736831bd44d6ca60ee573133cd72551d312dbc.tar.gz opie-77736831bd44d6ca60ee573133cd72551d312dbc.tar.bz2 |
Add config option to use smaller font for checkbook transaction tab - patch courtesy of hrw
-rw-r--r-- | noncore/apps/checkbook/cfg.cpp | 3 | ||||
-rw-r--r-- | noncore/apps/checkbook/cfg.h | 45 | ||||
-rw-r--r-- | noncore/apps/checkbook/checkbook.cpp | 3 | ||||
-rw-r--r-- | noncore/apps/checkbook/configuration.cpp | 6 | ||||
-rw-r--r-- | noncore/apps/checkbook/configuration.h | 1 |
5 files changed, 37 insertions, 21 deletions
diff --git a/noncore/apps/checkbook/cfg.cpp b/noncore/apps/checkbook/cfg.cpp index 24fa4cb..4f70593 100644 --- a/noncore/apps/checkbook/cfg.cpp +++ b/noncore/apps/checkbook/cfg.cpp @@ -1,221 +1,224 @@ /* This file is part of the OPIE Project =. .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <stdio.h> #include <qwidget.h> #include <qpe/config.h> #include "cfg.h" // --- Cfg -------------------------------------------------------------------- Cfg::Cfg() { _currencySymbol="$"; + _useSmallFont=TRUE; _showLocks=FALSE; _showBalances=FALSE; _pCategories=new CategoryList(); _bDirty=false; } // --- readStringList --------------------------------------------------------- // Reads the entries for the control from a configuration file and returns // them in a StringList. Later this list can be used to create the control. It // is assumed, that the group is already set. Key is used to enumerate the // entries. void Cfg::readStringList(Config &cfg, const char *sKey, QStringList &lst) { QString sEntry; int iCount; // read count of elements sEntry.sprintf("%s_Count", sKey); iCount=cfg.readNumEntry(sEntry, 0); // read entries for(int i=1; i<=iCount; i++) { sEntry.sprintf("%s%d", sKey, i); QString sType=cfg.readEntry(sEntry); if( sType!=NULL ) lst.append(sType); } } // --- readConfig ------------------------------------------------------------- // Reads the member data from the given config file. It will also set the group // "Config" void Cfg::readConfig(Config &config) { // set group config.setGroup( "Config" ); // read scalars _currencySymbol = config.readEntry( "CurrencySymbol", "$" ); + _useSmallFont = config.readBoolEntry( "UseSmallFont", TRUE ); _showLocks = config.readBoolEntry( "ShowLocks", FALSE ); _showBalances = config.readBoolEntry( "ShowBalances", FALSE ); _openLastBook = config.readBoolEntry( "OpenLastBook", FALSE ); _sLastBook = config.readEntry("LastBook", ""); _showLastTab = config.readBoolEntry( "ShowLastTab", FALSE ); _bSavePayees = config.readBoolEntry( "SavePayees", FALSE ); // Account types readStringList(config, "AccType", _AccountTypes); if( _AccountTypes.isEmpty() ) { _AccountTypes+= (const char *)QWidget::tr("Savings"); _AccountTypes+= (const char *)QWidget::tr("Checking"); _AccountTypes+= (const char *)QWidget::tr("CD"); _AccountTypes+= (const char *)QWidget::tr("Money market"); _AccountTypes+= (const char *)QWidget::tr("Mutual fund"); _AccountTypes+= (const char *)QWidget::tr("Other"); writeStringList(config, "AccType", _AccountTypes); config.write(); } // Payees readStringList(config, "Payee", _Payees); // Read Categories QStringList lst; readStringList(config, "Category", lst); if( lst.isEmpty() ) { QString type=QWidget::tr("Expense"); lst += QWidget::tr( "Automobile" )+";"+type; lst += QWidget::tr( "Bills" )+";"+type; lst += QWidget::tr( "CDs" )+";"+type; lst += QWidget::tr( "Clothing" )+";"+type; lst += QWidget::tr( "Computer" )+";"+type; lst += QWidget::tr( "DVDs" )+";"+type; lst += QWidget::tr( "Electronics" )+";"+type; lst += QWidget::tr( "Entertainment" )+";"+type; lst += QWidget::tr( "Food" )+";"+type; lst += QWidget::tr( "Gasoline" )+";"+type; lst += QWidget::tr( "Misc" )+";"+type; lst += QWidget::tr( "Movies" )+";"+type; lst += QWidget::tr( "Rent" )+";"+type; lst += QWidget::tr( "Travel" )+";"+type; type=QWidget::tr( "Income" ); lst += QWidget::tr( "Work" )+";"+type; lst += QWidget::tr( "Family Member" )+";"+type; lst += QWidget::tr( "Misc. Credit" )+";"+type; setCategories(lst); writeStringList(config, "Category", lst); config.write(); } else { setCategories(lst); } // not dirty _bDirty=false; } // --- writeStringList -------------------------------------------------------- // Writes the entries in the control in a configuration file. It is assumed, // that the group is already set. Key is used to enumerate the entries void Cfg::writeStringList(Config &cfg, const char *sKey, QStringList &lst) { QString sEntry; int iCount=0; QStringList::Iterator itr; for(itr=lst.begin(); itr!=lst.end(); itr++) { sEntry.sprintf("%s%d", sKey, ++iCount); cfg.writeEntry(sEntry, *itr ); } sEntry.sprintf("%s_Count", sKey); cfg.writeEntry(sEntry, iCount); } // --- writeConfig ----------------------------------------------------------- // Writes all config data back to the config file. The group will be set to // "Config" and the write be commited void Cfg::writeConfig(Config &config) { // set the group config.setGroup( "Config" ); // write scalars config.writeEntry( "CurrencySymbol", _currencySymbol ); + config.writeEntry( "UseSmallFont", _useSmallFont ); config.writeEntry( "ShowLocks", _showLocks ); config.writeEntry( "ShowBalances", _showBalances ); config.writeEntry( "OpenLastBook", _openLastBook ); config.writeEntry( "LastBook", _sLastBook ); config.writeEntry( "ShowLastTab", _showLastTab ); config.writeEntry( "SavePayees", _bSavePayees ); // write account types writeStringList(config, "AccType", _AccountTypes); // write payees writeStringList(config, "Payee", _Payees); // write categories QStringList lst=getCategories(); writeStringList(config, "Category", lst ); // commit write config.write(); _bDirty=false; } // --- getCategories ---------------------------------------------------------- QStringList Cfg::getCategories() { QStringList ret; for(Category *itr=_pCategories->first(); itr; itr=_pCategories->next() ) { QString sEntry; sEntry.sprintf("%s;%s", (const char *)itr->getName(), (const char *)(itr->isIncome() ? QWidget::tr("Income") : QWidget::tr("Expense")) ); ret.append(sEntry); } return(ret); } // --- setCategories ---------------------------------------------------------- void Cfg::setCategories(QStringList &lst) { _pCategories->clear(); QStringList::Iterator itr; for(itr=lst.begin(); itr!=lst.end(); itr++) { QStringList split=QStringList::split(";", *itr, true); if( split.count()<2 ) continue; bool bIncome= (split[1]==QWidget::tr("Income")); _pCategories->append( new Category(split[0], bIncome) ); } } // --- CategoryList ------------------------------------------------------------ CategoryList::CategoryList() : QList<Category>() { setAutoDelete(true); } diff --git a/noncore/apps/checkbook/cfg.h b/noncore/apps/checkbook/cfg.h index 20692b4..418bd93 100644 --- a/noncore/apps/checkbook/cfg.h +++ b/noncore/apps/checkbook/cfg.h @@ -1,132 +1,135 @@ /* - This file is part of the OPIE Project + This file is part of the OPIE Project =. - .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> - .>+-= - _;:, .> :=|. This file is free software; you can -.> <`_, > . <= redistribute it and/or modify it under -:`=1 )Y*s>-.-- : the terms of the GNU General Public -.="- .-=="i, .._ License as published by the Free Software - - . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. - .%`+i> _;_. - .i_,=:_. -<s. This file is distributed in the hope that - + . -:. = it will be useful, but WITHOUT ANY WARRANTY; - : .. .:, . . . without even the implied warranty of - =_ + =;=|` MERCHANTABILITY or FITNESS FOR A - _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General -..}^=.= = ; Public License for more details. -++= -. .` .: - : = ...= . :.=- You should have received a copy of the GNU - -. .:....=;==+<; General Public License along with this file; - -_. . . )=. = see the file COPYING. If not, write to the - -- :-=` Free Software Foundation, Inc., + .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> + .>+-= +_;:, .> :=|. This file is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU General Public +.="- .-=="i, .._ License as published by the Free Software +- . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This file is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General +..}^=.= = ; Public License for more details. +++= -. .` .: +: = ...= . :.=- You should have received a copy of the GNU +-. .:....=;==+<; General Public License along with this file; + -_. . . )=. = see the file COPYING. If not, write to the + -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef CFG_H #define CFG_H #include <qstring.h> #include <qlist.h> #include <qstringlist.h> class Config; // --- Category --------------------------------------------------------------- class Category { public: // --- Constructor: Category(QString &sName, bool bIncome=false) { _sName=sName; _bIncome=bIncome; } // members QString &getName() { return(_sName); } bool isIncome() { return(_bIncome); } void setName(QString &sName) { _sName=sName; } void setIncome(bool bIncome) { _bIncome=bIncome; } private: QString _sName; bool _bIncome; }; class CategoryList : public QList<Category> { public: // --- Constructor CategoryList(); }; // --- Cfg -------------------------------------------------------------------- class Cfg { public: // --- Constructor Cfg(); // --- members + bool getUseSmallFont() { return(_useSmallFont); } + void setUseSmallFont(bool n) { _useSmallFont=n; } bool getShowLocks() { return(_showLocks); } void setShowLocks(bool n) { _showLocks=n; } bool getShowBalances() { return(_showBalances); } void setShowBalances(bool n) { _showBalances=n; } QString &getCurrencySymbol() { return(_currencySymbol); } void setCurrencySymbol(QString n) {_currencySymbol= n; } void setCurrencySymbol(const char *n) { _currencySymbol=n; } QStringList &getAccountTypes() { return(_AccountTypes); } // --- Payees QStringList &getPayees() { return(_Payees); } bool getSavePayees() { return(_bSavePayees); } void setSavePayees(bool bSave) { _bSavePayees=bSave; } // --- Categories QStringList getCategories(); void setCategories(QStringList &lst); CategoryList *getCategoryList() { return(_pCategories); } // --- last book void setOpenLastBook(bool openLastBook) { _openLastBook=openLastBook; } bool isOpenLastBook() { return(_openLastBook); } void setLastBook(const QString &lastBook) { _sLastBook=lastBook; } QString &getLastBook() { return(_sLastBook); } // --- last tab void setShowLastTab(bool showLastTab) { _showLastTab=showLastTab; } bool isShowLastTab() { return(_showLastTab); } // --- reads data from config file void readConfig(Config &cfg); // --- writes data to config file void writeConfig(Config &cfg); // --- dirty flag bool isDirty() { return(_bDirty); } void setDirty(bool bDirty) { _bDirty=bDirty; } protected: // --- reads list from config file static void readStringList(Config &cfg, const char *sKey, QStringList &lst); // --- writes list in configuration file static void writeStringList(Config &cfg, const char *sKey, QStringList &lst); private: QString _currencySymbol; + bool _useSmallFont; bool _showLocks; bool _showBalances; bool _openLastBook; bool _showLastTab; bool _bDirty; bool _bSavePayees; QString _sLastBook; QStringList _AccountTypes; CategoryList *_pCategories; QStringList _Payees; }; #endif diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp index b325f45..1231f42 100644 --- a/noncore/apps/checkbook/checkbook.cpp +++ b/noncore/apps/checkbook/checkbook.cpp @@ -1,804 +1,807 @@ /* This file is part of the OPIE Project =. .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "checkbook.h" #include "cbinfo.h" #include "transaction.h" #include "traninfo.h" #include "graph.h" #include "graphinfo.h" #include "password.h" #include "cfg.h" #include <opie2/oresource.h> #include <qpe/applnk.h> #include <qpe/qpeapplication.h> #include <qpe/qpemessagebox.h> #include <qcheckbox.h> #include <qcombobox.h> #include <qlabel.h> #include <qlayout.h> #include <qlineedit.h> #include <qmultilineedit.h> #include <qpushbutton.h> #include <qwhatsthis.h> #include <qpopupmenu.h> #define COL_ID 0 #define COL_SORTDATE 1 #define COL_NUM 2 #define COL_DATE 3 #define COL_DESC 4 #define COL_AMOUNT 5 #define COL_BAL 6 // --- Checkbook -------------------------------------------------------------- using namespace Opie::Ui; Checkbook::Checkbook( QWidget *parent, CBInfo *i, Cfg *cfg ) : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) { info = i; _pCfg=cfg; // Title bar if ( info->name() != "" ) { QString tempstr = info->name(); tempstr.append( " - " ); tempstr.append( tr( "Checkbook" ) ); setCaption( tempstr ); } else { setCaption( tr( "New checkbook" ) ); } // Setup layout to make everything pretty QVBoxLayout *layout = new QVBoxLayout( this ); layout->setMargin( 2 ); layout->setSpacing( 4 ); // Setup tabs for all info mainWidget = new OTabWidget( this ); layout->addWidget( mainWidget ); mainWidget->addTab( initInfo(), "checkbook/infotab", tr( "Info" ) ); mainWidget->addTab( initTransactions(), "checkbook/trantab", tr( "Transactions" ) ); mainWidget->addTab( initCharts(), "checkbook/charttab", tr( "Charts" ) ); if( _pCfg->isShowLastTab() ) mainWidget->setCurrentTab( info->getLastTab() ); else mainWidget->setCurrentTab( tr( "Info" ) ); connect( mainWidget, SIGNAL( currentChanged(QWidget*) ), this, SLOT( slotTab(QWidget*) ) ); // Load checkbook information loadCheckbook(); } Checkbook::~Checkbook() { } // --- initInfo --------------------------------------------------------------- QWidget *Checkbook::initInfo() { QWidget *control = new QWidget( mainWidget, tr("Info") ); QVBoxLayout *vb = new QVBoxLayout( control ); QScrollView *sv = new QScrollView( control ); vb->addWidget( sv, 0, 0 ); sv->setResizePolicy( QScrollView::AutoOneFit ); sv->setFrameStyle( QFrame::NoFrame ); QWidget *container = new QWidget( sv->viewport() ); sv->addChild( container ); QGridLayout *layout = new QGridLayout( container ); layout->setSpacing( 2 ); layout->setMargin( 4 ); // Password protection passwordCB = new QCheckBox( tr( "Password protect" ), container ); QWhatsThis::add( passwordCB, tr( "Click here to enable/disable password protection of this checkbook." ) ); connect( passwordCB, SIGNAL( clicked() ), this, SLOT( slotPasswordClicked() ) ); layout->addMultiCellWidget( passwordCB, 0, 0, 0, 1 ); // Account name QLabel *label = new QLabel( tr( "Name:" ), container ); QWhatsThis::add( label, tr( "Enter name of checkbook here." ) ); layout->addWidget( label, 1, 0 ); nameEdit = new QLineEdit( container ); QWhatsThis::add( nameEdit, tr( "Enter name of checkbook here." ) ); connect( nameEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( slotNameChanged(const QString&) ) ); layout->addWidget( nameEdit, 1, 1 ); // Type of account label = new QLabel( tr( "Type:" ), container ); QWhatsThis::add( label, tr( "Select type of checkbook here." ) ); layout->addWidget( label, 2, 0 ); typeList = new QComboBox( container ); QWhatsThis::add( typeList, tr( "Select type of checkbook here." ) ); typeList->insertStringList( _pCfg->getAccountTypes() ); layout->addWidget( typeList, 2, 1 ); // Bank/institution name label = new QLabel( tr( "Bank:" ), container ); QWhatsThis::add( label, tr( "Enter name of the bank for this checkbook here." ) ); layout->addWidget( label, 3, 0 ); bankEdit = new QLineEdit( container ); QWhatsThis::add( bankEdit, tr( "Enter name of the bank for this checkbook here." ) ); layout->addWidget( bankEdit, 3, 1 ); // Account number label = new QLabel( tr( "Account number:" ), container ); QWhatsThis::add( label, tr( "Enter account number for this checkbook here." ) ); layout->addWidget( label, 4, 0 ); acctNumEdit = new QLineEdit( container ); QWhatsThis::add( acctNumEdit, tr( "Enter account number for this checkbook here." ) ); layout->addWidget( acctNumEdit, 4, 1 ); // PIN number label = new QLabel( tr( "PIN number:" ), container ); QWhatsThis::add( label, tr( "Enter PIN number for this checkbook here." ) ); layout->addWidget( label, 5, 0 ); pinNumEdit = new QLineEdit( container ); QWhatsThis::add( pinNumEdit, tr( "Enter PIN number for this checkbook here." ) ); layout->addWidget( pinNumEdit, 5, 1 ); // Starting balance label = new QLabel( tr( "Starting balance:" ), container ); QWhatsThis::add( label, tr( "Enter the initial balance for this checkbook here." ) ); layout->addWidget( label, 6, 0 ); balanceEdit = new QLineEdit( container ); QWhatsThis::add( balanceEdit, tr( "Enter the initial balance for this checkbook here." ) ); connect( balanceEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( slotStartingBalanceChanged(const QString&) ) ); layout->addWidget( balanceEdit, 6, 1 ); // Notes label = new QLabel( tr( "Notes:" ), container ); QWhatsThis::add( label, tr( "Enter any additional information for this checkbook here." ) ); layout->addWidget( label, 7, 0 ); notesEdit = new QMultiLineEdit( container ); QWhatsThis::add( notesEdit, tr( "Enter any additional information for this checkbook here." ) ); notesEdit->setMinimumHeight( 25 ); notesEdit->setMaximumHeight( 65 ); layout->addMultiCellWidget( notesEdit, 8, 8, 0, 1 ); return control; } // --- initTransactions ------------------------------------------------------- QWidget *Checkbook::initTransactions() { QWidget *control = new QWidget( mainWidget, tr("Transactions") ); QGridLayout *layout = new QGridLayout( control ); layout->setSpacing( 2 ); layout->setMargin( 4 ); // Sort selector QLabel *label = new QLabel( tr( "Sort by:" ), control ); QWhatsThis::add( label, tr( "Select checkbook sorting here." ) ); layout->addMultiCellWidget( label, 0, 0, 0, 1 ); _cbSortType=new QComboBox( control ); _cbSortType->insertItem( tr("Entry Order") ); _cbSortType->insertItem( tr("Date") ); _cbSortType->insertItem( tr("Number") ); layout->addMultiCellWidget( _cbSortType, 0, 0, 1, 2 ); connect( _cbSortType, SIGNAL( activated(const QString&) ), this, SLOT( slotSortChanged(const QString&) ) ); // Table tranTable = new QListView( control ); QFont fnt(QPEApplication::font()); + if( _pCfg->getUseSmallFont() ) + { fnt.setPointSize( fnt.pointSize()-1 ); + } tranTable->setFont( fnt ); QWhatsThis::add( tranTable, tr( "This is a listing of all transactions entered for this checkbook.\n\nTo sort entries by a specific field, click on the column name." ) ); tranTable->addColumn( tr( "Id" ) ); tranTable->setColumnWidthMode( COL_ID, QListView::Manual ); tranTable->setColumnWidth( COL_ID, 0); tranTable->addColumn( tr( "SortDate" ) ); tranTable->setColumnWidthMode( COL_SORTDATE, QListView::Manual ); tranTable->setColumnWidth( COL_SORTDATE, 0); tranTable->addColumn( tr( "Num" ) ); tranTable->addColumn( tr( "Date" ) ); //tranTable->addColumn( tr( "Cleared" ) ); tranTable->addColumn( tr( "Description" ) ); int column = tranTable->addColumn( tr( "Amount" ) ); tranTable->setColumnAlignment( column, Qt::AlignRight ); column=tranTable->addColumn( tr("Balance") ); tranTable->setColumnAlignment( column, Qt::AlignRight ); tranTable->setAllColumnsShowFocus( TRUE ); tranTable->setSorting( -1 ); layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 ); QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold ); connect( tranTable, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ), this, SLOT( slotMenuTran(QListViewItem*,const QPoint&) ) ); connect( tranTable, SIGNAL( doubleClicked(QListViewItem*) ), this, SLOT( slotEditTran() ) ); _sortCol=COL_ID; // Buttons QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), tr( "New" ), control ); btn->setFixedHeight( AppLnk::smallIconSize()+4 ); QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) ); layout->addWidget( btn, 2, 0 ); btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Edit" ), control ); btn->setFixedHeight( AppLnk::smallIconSize()+4 ); QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotEditTran() ) ); layout->addWidget( btn, 2, 1 ); btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), control ); btn->setFixedHeight( AppLnk::smallIconSize()+4 ); QWhatsThis::add( btn, tr( "Select a checkbook and then click here to delete it." ) ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotDeleteTran() ) ); layout->addWidget( btn, 2, 2 ); return( control ); } // --- initCharts ------------------------------------------------------------- QWidget *Checkbook::initCharts() { graphInfo = 0x0; QWidget *control = new QWidget( mainWidget, tr("Charts") ); QGridLayout *layout = new QGridLayout( control ); layout->setSpacing( 2 ); layout->setMargin( 4 ); graphWidget = new Graph( control ); QWhatsThis::add( graphWidget, tr( "Select the desired chart below and then click on the Draw button." ) ); layout->addMultiCellWidget( graphWidget, 0, 0, 0, 2 ); graphList = new QComboBox( control ); QWhatsThis::add( graphList, tr( "Click here to select the desired chart type." ) ); graphList->insertItem( tr( "Account balance" ) ); graphList->insertItem( tr( "Withdrawals by category" ) ); graphList->insertItem( tr( "Deposits by category" ) ); layout->addMultiCellWidget( graphList, 1, 1, 0, 1 ); QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "checkbook/drawbtn", Opie::Core::OResource::SmallIcon ), tr( "Draw" ), control ); btn->setFixedHeight( AppLnk::smallIconSize()+4 ); QWhatsThis::add( btn, tr( "Click here to draw the selected chart." ) ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) ); layout->addWidget( btn, 1, 2 ); return control; } // --- loadCheckbook ---------------------------------------------------------- void Checkbook::loadCheckbook() { if ( !info ) { return; } tranList = info->transactions(); passwordCB->setChecked( !info->password().isNull() ); nameEdit->setText( info->name() ); QString temptext = info->type(); int i = typeList->count(); while ( i > 0 ) { i--; typeList->setCurrentItem( i ); if ( typeList->currentText() == temptext ) { break; } } if( i<=0 ) { typeList->insertItem( temptext, 0 ); typeList->setCurrentItem(0); } bankEdit->setText( info->bank() ); acctNumEdit->setText( info->account() ); pinNumEdit->setText( info->pin() ); temptext.setNum( info->startingBalance(), 'f', 2 ); balanceEdit->setText( temptext ); notesEdit->setText( info->notes() ); // Load transactions float amount; QString stramount; QString symbol = _pCfg->getCurrencySymbol(); for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) { amount = tran->amount(); if ( tran->withdrawal() ) { amount *= -1; } stramount.sprintf( "%.2f", amount ); stramount.prepend( symbol ); ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->datestr(false), tran->number(), tran->datestr(true), tran->desc(), stramount ); } // set sort order bool bOk=false; for(int i=0; i<_cbSortType->count(); i++) { if( _cbSortType->text(i)==info->getSortOrder() ) { _cbSortType->setCurrentItem(i); slotSortChanged( info->getSortOrder() ); bOk=true; break; } } if( !bOk ) { _cbSortType->setCurrentItem(0); slotSortChanged( _cbSortType->currentText() ); } // calc running balance adjustBalance(); } // --- adjustBalance ---------------------------------------------------------- void Checkbook::adjustBalance() { // update running balance in register QString sRunning; QString symbol = _pCfg->getCurrencySymbol(); float bal=info->startingBalance(); for(CBListItem *item=(CBListItem *)tranTable->firstChild(); item; item=(CBListItem *)item->nextSibling() ) { TranInfo *tran=item->getTranInfo(); bal=bal + (tran->withdrawal() ? -1 : 1)*tran->amount() - tran->fee(); sRunning.sprintf( "%.2f", bal ); sRunning.prepend(symbol); item->setText( COL_BAL, sRunning); } } // --- resort ----------------------------------------------------------------- void Checkbook::resort() { tranTable->setSorting(_sortCol); tranTable->sort(); tranTable->setSorting(-1); } // --- accept ----------------------------------------------------------------- void Checkbook::accept() { info->setName( nameEdit->text() ); info->setType( typeList->currentText() ); info->setBank( bankEdit->text() ); info->setAccount( acctNumEdit->text() ); info->setPin( pinNumEdit->text() ); bool ok; info->setStartingBalance( balanceEdit->text().toFloat( &ok ) ); info->setNotes( notesEdit->text() ); QDialog::accept(); } // --- slotPasswordClicked ---------------------------------------------------- void Checkbook::slotPasswordClicked() { if ( info->password().isNull() && passwordCB->isChecked() ) { Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); if ( pw->exec() != QDialog::Accepted ) { passwordCB->setChecked( FALSE ); delete pw; return; } info->setPassword( pw->password ); delete pw; pw = new Password( this, tr( "Confirm password" ), tr( "Please confirm your password:" ) ); if ( pw->exec() != QDialog::Accepted || pw->password != info->password() ) { passwordCB->setChecked( FALSE ); info->setPassword( QString::null ); } delete pw; } else if ( !info->password().isNull() && !passwordCB->isChecked() ) { Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password to confirm removal of password protection:" ) ); if ( pw->exec() == QDialog::Accepted && pw->password == info->password() ) { info->setPassword( QString::null ); delete pw; return; } else { passwordCB->setChecked( TRUE ); } delete pw; } } void Checkbook::slotNameChanged( const QString &newname ) { info->setName( newname ); // TODO - need filedir // QString namestr = filedir; // namestr.append( newname ); // namestr.append( ".qcb" ); // info->setFilename( namestr ); QString namestr = newname; namestr.append( " - " ); namestr.append( tr( "Checkbook" ) ); setCaption( namestr ); } // ---slotStartingBalanceChanged ---------------------------------------------- void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) { bool ok; info->setStartingBalance( newbalance.toFloat( &ok ) ); adjustBalance(); } // --- slotNewTran ------------------------------------------------------------ void Checkbook::slotNewTran() { TranInfo *traninfo = new TranInfo( info->getNextNumber() ); if( !_dLastNew.isNull() ) traninfo->setDate(_dLastNew); Transaction *currtran = new Transaction( this, true, info->name(), traninfo, _pCfg ); QString symbol = _pCfg->getCurrencySymbol(); if ( QPEApplication::execDialog( currtran ) == QDialog::Accepted ) { // Add to transaction list info->addTransaction( traninfo ); // Add to transaction table float amount; QString stramount; amount = (traninfo->withdrawal() ? -1 : 1)*traninfo->amount(); stramount.sprintf( "%.2f", amount ); stramount.prepend(symbol); ( void ) new CBListItem( traninfo, tranTable, traninfo->getIdStr(), traninfo->datestr(false), traninfo->number(), traninfo->datestr(true), traninfo->desc(), stramount ); resort(); adjustBalance(); // save last date _dLastNew = traninfo->date(); // save description in list of payees, if not in there QStringList *pLst=&_pCfg->getPayees(); if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) { pLst->append( traninfo->desc() ); pLst->sort(); _pCfg->setDirty(true); } } else { delete traninfo; } } // --- slotEditTran ----------------------------------------------------------- void Checkbook::slotEditTran() { QListViewItem *curritem = tranTable->currentItem(); if ( !curritem ) return; TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) ); Transaction *currtran = new Transaction( this, false, info->name(), traninfo, _pCfg ); if ( QPEApplication::execDialog( currtran ) == QDialog::Accepted ) { curritem->setText( COL_NUM, traninfo->number() ); curritem->setText( COL_SORTDATE, traninfo->datestr(false) ); curritem->setText( COL_DATE, traninfo->datestr(true) ); curritem->setText( COL_DESC, traninfo->desc() ); float amount = traninfo->amount(); if ( traninfo->withdrawal() ) { amount *= -1; } QString stramount; stramount.sprintf( "%.2f", amount ); stramount.prepend( _pCfg->getCurrencySymbol() ); curritem->setText( COL_AMOUNT, stramount ); resort(); adjustBalance(); // save description in list of payees, if not in there QStringList *pLst=&_pCfg->getPayees(); if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) { pLst->append( traninfo->desc() ); pLst->sort(); _pCfg->setDirty(true); } } delete currtran; } // --- slotMenuTran ----------------------------------------------------------- void Checkbook::slotMenuTran(QListViewItem *item, const QPoint &pnt) { // active item? if( !item ) return; // Display menu QPopupMenu m; m.insertItem( QWidget::tr( "Edit" ), 1 ); m.insertItem( QWidget::tr( "New" ), 2 ); m.insertItem( QWidget::tr( "Delete" ), 3 ); int r = m.exec( pnt ); switch(r) { case 1: slotEditTran(); break; case 2: slotNewTran(); break; case 3: slotDeleteTran(); break; } } // --- slotDeleteTran --------------------------------------------------------- void Checkbook::slotDeleteTran() { QListViewItem *curritem = tranTable->currentItem(); if ( !curritem ) return; TranInfo *traninfo = info->findTransaction( curritem->text(COL_ID) ); if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) ) { info->removeTransaction( traninfo ); delete curritem; adjustBalance(); } } void Checkbook::slotDrawGraph() { if ( graphInfo ) { delete graphInfo; } switch ( graphList->currentItem() ) { case 0 : drawBalanceChart(); break; case 1 : drawCategoryChart( TRUE ); break; case 2 : drawCategoryChart( FALSE ); break; }; graphWidget->setGraphInfo( graphInfo ); graphWidget->drawGraph( TRUE ); } void Checkbook::drawBalanceChart() { DataPointList *list = new DataPointList(); float balance = info->startingBalance(); float amount; QString label; int i = 0; int count = tranList->count(); for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) { i++; balance -= tran->fee(); amount = tran->amount(); if ( tran->withdrawal() ) { amount *= -1; } balance += amount; if ( i == 1 || i == count / 2 || i == count ) { label = tran->datestr(true); } else { label = ""; } list->append( new DataPointInfo( label, balance ) ); } graphInfo = new GraphInfo( GraphInfo::BarChart, list ); } void Checkbook::drawCategoryChart( bool withdrawals ) { DataPointList *list = new DataPointList(); TranInfo *tran = tranList->first(); if ( tran && tran->withdrawal() == withdrawals ) { list->append( new DataPointInfo( tran->category(), tran->amount() ) ); } tran = tranList->next(); DataPointInfo *cat; for ( ; tran; tran = tranList->next() ) { if ( tran->withdrawal() == withdrawals ) { // Find category in list for ( cat = list->first(); cat; cat = list->next() ) { if ( cat->label() == tran->category() ) { break; } } if ( cat && cat->label() == tran->category() ) { // Found category, add to transaction to category total cat->addToValue( tran->amount() ); } else { // Didn't find category, add category to list list->append( new DataPointInfo( tran->category(), tran->amount() ) ); } } } graphInfo = new GraphInfo( GraphInfo::PieChart, list ); } CBListItem::CBListItem( TranInfo *pTran, QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5, QString label6, QString label7, QString label8 ) : QListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 ) { _pTran=pTran; m_known = FALSE; owner = parent; } void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align ) { QColorGroup _cg = cg; const QPixmap *pm = listView()->viewport()->backgroundPixmap(); if ( pm && !pm->isNull() ) { _cg.setBrush( QColorGroup::Base, QBrush( cg.base(), *pm ) ); p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); } else if ( isAltBackground() ) _cg.setColor(QColorGroup::Base, cg.background() ); QListViewItem::paintCell(p, _cg, column, width, align); } // --- CBListItem::isAltBackground -------------------------------------------- bool CBListItem::isAltBackground() { QListView *lv = static_cast<QListView *>( listView() ); if ( lv ) { CBListItem *above = 0; above = (CBListItem *)( itemAbove() ); m_known = above ? above->m_known : true; if ( m_known ) { m_odd = above ? !above->m_odd : false; } else { CBListItem *item; bool previous = true; if ( parent() ) { item = (CBListItem *)( parent() ); if ( item ) previous = item->m_odd; item = (CBListItem *)( parent()->firstChild() ); } else { item = (CBListItem *)( lv->firstChild() ); } while(item) { item->m_odd = previous = !previous; item->m_known = true; item = (CBListItem *)( item->nextSibling() ); } } return m_odd; } return false; } // --- slotTab ---------------------------------------------------------------- void Checkbook::slotTab(QWidget *tab) { if( !tab || !info ) return; info->setLastTab( tab->name() ); } // --- slotSortChanged --------------------------------------------------------- void Checkbook::slotSortChanged( const QString &selc ) { if( selc==tr("Entry Order") ) { _sortCol=COL_ID; } else if( selc==tr("Number") ) { _sortCol=COL_NUM; } else if( selc==tr("Date") ) { _sortCol=COL_SORTDATE; } info->setSortOrder( selc ); resort(); } diff --git a/noncore/apps/checkbook/configuration.cpp b/noncore/apps/checkbook/configuration.cpp index 872d9b2..929c7c0 100644 --- a/noncore/apps/checkbook/configuration.cpp +++ b/noncore/apps/checkbook/configuration.cpp @@ -1,173 +1,179 @@ /* This file is part of the OPIE Project =. .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "configuration.h" #include "listedit.h" #include <qcheckbox.h> #include <qlabel.h> #include <qlayout.h> #include <qlineedit.h> #include <qwhatsthis.h> #include <qlistview.h> #include <qtabwidget.h> Configuration::Configuration( QWidget *parent, Cfg &cfg ) : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) { setCaption( tr( "Configure Checkbook" ) ); // Setup layout to make everything pretty QVBoxLayout *layout = new QVBoxLayout( this ); layout->setMargin( 2 ); layout->setSpacing( 4 ); // Setup tabs for all info _mainWidget = new QTabWidget( this ); layout->addWidget( _mainWidget ); // Settings tab _mainWidget->addTab( initSettings(cfg), tr( "&Settings" ) ); // Account Types tab ColumnDef *d; _listEditTypes=new ListEdit(_mainWidget, "TYPES" ); d=new ColumnDef( tr("Type"), (ColumnDef::ColumnType)(ColumnDef::typeString | ColumnDef::typeUnique), tr("New Account Type")); _listEditTypes->addColumnDef( d ); _listEditTypes->addData( cfg.getAccountTypes() ); _mainWidget->addTab( _listEditTypes, tr( "&Account Types" ) ); // Categories tab _listEditCategories=new ListEdit(_mainWidget, "CATEGORIES" ); _listEditCategories->addColumnDef( new ColumnDef( tr("Category"), (ColumnDef::ColumnType)(ColumnDef::typeString | ColumnDef::typeUnique), tr("New Category")) ); d=new ColumnDef( tr("Type"), ColumnDef::typeList, tr("Expense") ); d->addColumnValue( tr("Expense") ); d->addColumnValue( tr("Income") ); _listEditCategories->addColumnDef( d ); QStringList lst=cfg.getCategories(); _listEditCategories->addData( lst ); _mainWidget->addTab( _listEditCategories, tr( "&Categories" ) ); // Payees tab _listEditPayees=new ListEdit(_mainWidget, "PAYEES"); _listEditPayees->addColumnDef( new ColumnDef( tr("Payee"), (ColumnDef::ColumnType)(ColumnDef::typeString | ColumnDef::typeUnique), tr("New Payee")) ); _listEditPayees->addData( cfg.getPayees() ); _mainWidget->addTab( _listEditPayees, tr("&Payees") ); } Configuration::~Configuration() { } // ---- initSettings ---------------------------------------------------------- QWidget *Configuration::initSettings(Cfg &cfg) { QWidget *control = new QWidget( _mainWidget ); QFontMetrics fm = fontMetrics(); int fh = fm.height(); QVBoxLayout *vb = new QVBoxLayout( control ); QScrollView *sv = new QScrollView( control ); vb->addWidget( sv, 0, 0 ); sv->setResizePolicy( QScrollView::AutoOneFit ); sv->setFrameStyle( QFrame::NoFrame ); QWidget *container = new QWidget( sv->viewport() ); sv->addChild( container ); QGridLayout *layout = new QGridLayout( container ); layout->setSpacing( 4 ); layout->setMargin( 4 ); QLabel *label = new QLabel( tr( "Enter currency symbol:" ), container ); QWhatsThis::add( label, tr( "Enter your local currency symbol here." ) ); label->setMaximumHeight( fh + 3 ); layout->addWidget( label, 0, 0 ); symbolEdit = new QLineEdit( cfg.getCurrencySymbol(), container ); QWhatsThis::add( symbolEdit, tr( "Enter your local currency symbol here." ) ); symbolEdit->setMaximumHeight( fh + 5 ); symbolEdit->setFocus(); layout->addWidget( symbolEdit, 0, 1 ); lockCB = new QCheckBox( tr( "Show whether checkbook is password\nprotected" ), container ); QWhatsThis::add( lockCB, tr( "Click here to select whether or not the main window will display that the checkbook is protected with a password." ) ); lockCB->setChecked( cfg.getShowLocks() ); layout->addMultiCellWidget( lockCB, 1, 1, 0, 1 ); balCB = new QCheckBox( tr( "Show checkbook balances" ), container ); QWhatsThis::add( balCB, tr( "Click here to select whether or not the main window will display the current balance for each checkbook." ) ); balCB->setMaximumHeight( fh + 5 ); balCB->setChecked( cfg.getShowBalances() ); layout->addMultiCellWidget( balCB, 2, 2, 0, 1 ); openLastBookCB = new QCheckBox( tr("Open last checkbook" ), container ); QWhatsThis::add( openLastBookCB, tr("Click here to select whether the last open checkbook will be opened at startup.") ); openLastBookCB->setMaximumHeight(fh+5); openLastBookCB->setChecked( cfg.isOpenLastBook() ); layout->addMultiCellWidget( openLastBookCB, 3, 3, 0, 1 ); lastTabCB = new QCheckBox( tr("Show last checkbook tab" ), container ); QWhatsThis::add( lastTabCB, tr("Click here to select whether the last tab in a checkbook should be displayed.") ); lastTabCB->setMaximumHeight(fh+5); lastTabCB->setChecked( cfg.isShowLastTab() ); layout->addMultiCellWidget( lastTabCB, 4, 4, 0, 1 ); savePayees = new QCheckBox( tr("Save new description as payee"), container ); QWhatsThis::add( savePayees, tr("Click here to save new descriptions in the list of payess.") ); savePayees->setMaximumHeight(fh+5); savePayees->setChecked( cfg.getSavePayees() ); layout->addMultiCellWidget( savePayees, 5, 5, 0, 1 ); + smallFontCB = new QCheckBox( tr( "Use smaller font for list" ), container ); + QWhatsThis::add( smallFontCB, tr( "Click here to select smaller font for transactions." ) ); + smallFontCB->setChecked( cfg.getUseSmallFont() ); + layout->addMultiCellWidget( smallFontCB, 6, 6, 0, 1 ); + return(control); } // --- saveConfig ------------------------------------------------------------- void Configuration::saveConfig(Cfg &cfg) { // Settings cfg.setCurrencySymbol( symbolEdit->text() ); + cfg.setUseSmallFont( smallFontCB->isChecked() ); cfg.setShowLocks( lockCB->isChecked() ); cfg.setShowBalances( balCB->isChecked() ); cfg.setOpenLastBook( openLastBookCB->isChecked() ); cfg.setShowLastTab( lastTabCB->isChecked() ); cfg.setSavePayees( savePayees->isChecked() ); // Typelist _listEditTypes->storeInList( cfg.getAccountTypes() ); // Category list QStringList lst; _listEditCategories->storeInList( lst ); cfg.setCategories( lst ); // Payees _listEditPayees->storeInList( cfg.getPayees() ); } diff --git a/noncore/apps/checkbook/configuration.h b/noncore/apps/checkbook/configuration.h index 663514d..44c9717 100644 --- a/noncore/apps/checkbook/configuration.h +++ b/noncore/apps/checkbook/configuration.h @@ -1,69 +1,70 @@ /* This file is part of the OPIE Project =. .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef CONFIGURATION_H #define CONFIGURATION_H #include <qdialog.h> #include "cfg.h" class QCheckBox; class QLineEdit; class QString; class QTabWidget; class ListEdit; class Configuration : public QDialog { Q_OBJECT public: // Constructor Configuration( QWidget *, Cfg &cfg); ~Configuration(); QLineEdit *symbolEdit; + QCheckBox *smallFontCB; QCheckBox *lockCB; QCheckBox *balCB; QCheckBox *openLastBookCB; QCheckBox *lastTabCB; QCheckBox *savePayees; QTabWidget *_mainWidget; ListEdit *_listEditTypes; ListEdit *_listEditCategories; ListEdit *_listEditPayees; // saves settings in config struct void saveConfig(Cfg &cfg); protected: // creates settings tap from configuration QWidget *initSettings(Cfg &cfg); }; #endif |