00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00046 QVBoxLayout *layout = new QVBoxLayout( this );
00047 layout->setMargin( 2 );
00048 layout->setSpacing( 4 );
00049
00050
00051 _mainWidget = new QTabWidget( this );
00052 layout->addWidget( _mainWidget );
00053
00054
00055 _mainWidget->addTab( initSettings(cfg), tr( "&Settings" ) );
00056
00057
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
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
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
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
00158 void Configuration::saveConfig(Cfg &cfg)
00159 {
00160
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
00170 _listEditTypes->storeInList( cfg.getAccountTypes() );
00171
00172
00173 QStringList lst;
00174 _listEditCategories->storeInList( lst );
00175 cfg.setCategories( lst );
00176
00177
00178 _listEditPayees->storeInList( cfg.getPayees() );
00179 }