Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

configuration.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the OPIE Project
00003                =.
00004              .=l.            Copyright (c)  2002 Dan Williams <drw@handhelds.org>
00005            .>+-=
00006  _;:,     .>    :=|.         This file is free software; you can
00007 .> <`_,   >  .   <=          redistribute it and/or modify it under
00008 :`=1 )Y*s>-.--   :           the terms of the GNU General Public
00009 .="- .-=="i,     .._         License as published by the Free Software
00010  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00011      ._= =}       :          or (at your option) any later version.
00012     .%`+i>       _;_.
00013     .i_,=:_.      -<s.       This file is distributed in the hope that
00014      +  .  -:.       =       it will be useful, but WITHOUT ANY WARRANTY;
00015     : ..    .:,     . . .    without even the implied warranty of
00016     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00017   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU General
00018 ..}^=.=       =       ;      Public License for more details.
00019 ++=   -.     .`     .:
00020  :     =  ...= . :.=-        You should have received a copy of the GNU
00021  -.   .:....=;==+<;          General Public License along with this file;
00022   -_. . .   )=.  =           see the file COPYING. If not, write to the
00023     --        :-=`           Free Software Foundation, Inc.,
00024                              59 Temple Place - Suite 330,
00025                              Boston, MA 02111-1307, USA.
00026 
00027 */
00028 
00029 #include "configuration.h"
00030 #include "listedit.h"
00031 
00032 #include <qcheckbox.h>
00033 #include <qlabel.h>
00034 #include <qlayout.h>
00035 #include <qlineedit.h>
00036 #include <qwhatsthis.h>
00037 #include <qlistview.h>
00038 #include <qtabwidget.h>
00039 
00040 Configuration::Configuration( QWidget *parent, Cfg &cfg )
00041         : QDialog( parent, 0, TRUE, WStyle_ContextHelp )
00042 {
00043         setCaption( tr( "Configure Checkbook" ) );
00044 
00045     // Setup layout to make everything pretty
00046         QVBoxLayout *layout = new QVBoxLayout( this );
00047         layout->setMargin( 2 );
00048         layout->setSpacing( 4 );
00049 
00050         // Setup tabs for all info
00051         _mainWidget = new QTabWidget( this );
00052         layout->addWidget( _mainWidget );
00053 
00054     // Settings tab
00055     _mainWidget->addTab( initSettings(cfg), tr( "&Settings" ) );
00056 
00057     // Account Types tab
00058     ColumnDef *d;
00059     _listEditTypes=new ListEdit(_mainWidget, "TYPES" );
00060     d=new ColumnDef( tr("Type"), (ColumnDef::ColumnType)(ColumnDef::typeString | ColumnDef::typeUnique), tr("New Account Type"));
00061     _listEditTypes->addColumnDef( d );
00062     _listEditTypes->addData( cfg.getAccountTypes() );
00063     _mainWidget->addTab( _listEditTypes, tr( "&Account Types" ) );
00064 
00065     // Categories tab
00066     _listEditCategories=new ListEdit(_mainWidget, "CATEGORIES" );
00067     _listEditCategories->addColumnDef( new ColumnDef( tr("Category"), (ColumnDef::ColumnType)(ColumnDef::typeString | ColumnDef::typeUnique), tr("New Category")) );
00068     d=new ColumnDef(  tr("Type"), ColumnDef::typeList, tr("Expense") );
00069     d->addColumnValue( tr("Expense") );
00070     d->addColumnValue( tr("Income") );
00071     _listEditCategories->addColumnDef( d );
00072     QStringList lst=cfg.getCategories();
00073     _listEditCategories->addData( lst );
00074     _mainWidget->addTab( _listEditCategories, tr( "&Categories" ) );
00075 
00076     // Payees tab
00077     _listEditPayees=new ListEdit(_mainWidget, "PAYEES");
00078     _listEditPayees->addColumnDef( new ColumnDef( tr("Payee"), (ColumnDef::ColumnType)(ColumnDef::typeString | ColumnDef::typeUnique), tr("New Payee")) );
00079     _listEditPayees->addData( cfg.getPayees() );
00080     _mainWidget->addTab( _listEditPayees, tr("&Payees") );
00081 }
00082 
00083 Configuration::~Configuration()
00084 {
00085 }
00086 
00087 // ---- initSettings ----------------------------------------------------------
00088 QWidget *Configuration::initSettings(Cfg &cfg)
00089 {
00090     QWidget *control = new QWidget( _mainWidget );
00091 
00092     QFontMetrics fm = fontMetrics();
00093         int fh = fm.height();
00094 
00095     QVBoxLayout *vb = new QVBoxLayout( control );
00096 
00097         QScrollView *sv = new QScrollView( control );
00098         vb->addWidget( sv, 0, 0 );
00099         sv->setResizePolicy( QScrollView::AutoOneFit );
00100         sv->setFrameStyle( QFrame::NoFrame );
00101 
00102         QWidget *container = new QWidget( sv->viewport() );
00103         sv->addChild( container );
00104 
00105         QGridLayout *layout = new QGridLayout( container );
00106         layout->setSpacing( 4 );
00107         layout->setMargin( 4 );
00108 
00109         QLabel *label = new QLabel( tr( "Enter currency symbol:" ), container );
00110         QWhatsThis::add( label, tr( "Enter your local currency symbol here." ) );
00111         label->setMaximumHeight( fh + 3 );
00112         layout->addWidget( label, 0, 0 );
00113 
00114         symbolEdit = new QLineEdit( cfg.getCurrencySymbol(), container );
00115         QWhatsThis::add( symbolEdit, tr( "Enter your local currency symbol here." ) );
00116         symbolEdit->setMaximumHeight( fh + 5 );
00117         symbolEdit->setFocus();
00118     layout->addWidget( symbolEdit, 0, 1 );
00119 
00120         lockCB = new QCheckBox( tr( "Show whether checkbook is password\nprotected" ), container );
00121         QWhatsThis::add( lockCB, tr( "Click here to select whether or not the main window will display that the checkbook is protected with a password." ) );
00122         lockCB->setChecked( cfg.getShowLocks() );
00123         layout->addMultiCellWidget( lockCB, 1, 1, 0, 1 );
00124 
00125         balCB = new QCheckBox( tr( "Show checkbook balances" ), container );
00126         QWhatsThis::add( balCB, tr( "Click here to select whether or not the main window will display the current balance for each checkbook." ) );
00127         balCB->setMaximumHeight( fh + 5 );
00128         balCB->setChecked( cfg.getShowBalances() );
00129         layout->addMultiCellWidget( balCB, 2, 2, 0, 1 );
00130 
00131     openLastBookCB = new QCheckBox( tr("Open last checkbook" ), container );
00132     QWhatsThis::add( openLastBookCB, tr("Click here to select whether the last open checkbook will be opened at startup.") );
00133     openLastBookCB->setMaximumHeight(fh+5);
00134     openLastBookCB->setChecked( cfg.isOpenLastBook() );
00135     layout->addMultiCellWidget( openLastBookCB, 3, 3, 0, 1 );
00136 
00137     lastTabCB = new QCheckBox( tr("Show last checkbook tab" ), container );
00138     QWhatsThis::add( lastTabCB, tr("Click here to select whether the last tab in a checkbook should be displayed.") );
00139     lastTabCB->setMaximumHeight(fh+5);
00140     lastTabCB->setChecked( cfg.isShowLastTab() );
00141     layout->addMultiCellWidget( lastTabCB, 4, 4, 0, 1 );
00142 
00143     savePayees = new QCheckBox( tr("Save new description as payee"), container );
00144     QWhatsThis::add( savePayees, tr("Click here to save new descriptions in the list of payess.") );
00145     savePayees->setMaximumHeight(fh+5);
00146     savePayees->setChecked( cfg.getSavePayees() );
00147     layout->addMultiCellWidget( savePayees, 5, 5, 0, 1 );
00148 
00149         smallFontCB = new QCheckBox( tr( "Use smaller font for list" ), container );
00150         QWhatsThis::add( smallFontCB, tr( "Click here to select smaller font for transactions." ) );
00151         smallFontCB->setChecked( cfg.getUseSmallFont() );
00152         layout->addMultiCellWidget( smallFontCB, 6, 6, 0, 1 );
00153 
00154     return(control);
00155 }
00156 
00157 // --- saveConfig -------------------------------------------------------------
00158 void Configuration::saveConfig(Cfg &cfg)
00159 {
00160     // Settings
00161     cfg.setCurrencySymbol( symbolEdit->text() );
00162     cfg.setUseSmallFont( smallFontCB->isChecked() );
00163     cfg.setShowLocks( lockCB->isChecked() );
00164     cfg.setShowBalances( balCB->isChecked() );
00165     cfg.setOpenLastBook( openLastBookCB->isChecked() );
00166     cfg.setShowLastTab( lastTabCB->isChecked() );
00167     cfg.setSavePayees( savePayees->isChecked() );
00168 
00169     // Typelist
00170     _listEditTypes->storeInList( cfg.getAccountTypes() );
00171 
00172     // Category list
00173     QStringList lst;
00174     _listEditCategories->storeInList( lst );
00175     cfg.setCategories( lst );
00176 
00177     // Payees
00178     _listEditPayees->storeInList( cfg.getPayees() );
00179 }

Generated on Sat Nov 5 16:16:47 2005 for OPIE by  doxygen 1.4.2