00001 #include "newaccount.h"
00002 #include "calculator.h"
00003 #include "datepicker.h"
00004 #include <qmultilineedit.h>
00005
00006 extern Preferences *preferences;
00007
00008 NewAccount::NewAccount ( QWidget *parent, const char *name, bool modal ) : QDialog ( parent, name, modal )
00009 {
00010 accountdescription = "";
00011 dateedited = FALSE;
00012 setCaption( tr( "Account" ) );
00013
00014 namelabel = new QLabel ( "Account Name", this );
00015
00016 accountbox = new QHBox ( this );
00017 accountname = new QLineEdit ( accountbox );
00018 descriptionbutton = new QPushButton ( accountbox );
00019 descriptionbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/info.png" ) );
00020
00021 datelabel = new QLabel ( "Date", this );
00022
00023 datebox = new QHBox ( this );
00024 startdate = new QLineEdit ( datebox );
00025 startdate->setDisabled ( TRUE );
00026 datebutton = new QPushButton ( datebox );
00027 datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) );
00028
00029 childcheckbox = new QCheckBox ( this );
00030 childcheckbox->setText( tr ( "Child Account" ) );
00031
00032 childlabel = new QLabel ( "Child of", this );
00033 childbox = new QComboBox ( FALSE, this );
00034 hideChildPulldownMenu ();
00035
00036 balancelabel = new QLabel ( "Balance", this );
00037
00038 balancebox = new QHBox ( this );
00039 accountbalance = new QLineEdit ( balancebox );
00040 accountbalance->setText ( "0.00" );
00041 balancecalculator = new QPushButton( balancebox );
00042 balancecalculator->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) );
00043
00044 creditlimitlabel = new QLabel ( "Credit Limit", this );
00045
00046 creditlimitbox = new QHBox ( this );
00047 creditlimit = new QLineEdit ( creditlimitbox );
00048 creditlimitbox->setEnabled ( FALSE );
00049 creditlimitcalculator = new QPushButton( creditlimitbox );
00050 creditlimitcalculator->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) );
00051
00052 currencybox = new Currency ( this );
00053
00054 typelabel = new QLabel ( "Type", this );
00055 accounttype = new QComboBox ( FALSE, this );
00056 accounttype->insertItem( tr( "Bank" ) );
00057 accounttype->insertItem( tr( "Cash" ) );
00058 accounttype->insertItem( tr( "Credit Card" ) );
00059 accounttype->insertItem( tr( "Equity" ) );
00060 accounttype->insertItem( tr( "Asset" ) );
00061 accounttype->insertItem( tr( "Liability" ) );
00062
00063 layout = new QGridLayout ( this, 7, 2, 4, 2 );
00064 layout->addWidget ( namelabel , 0, 0, Qt::AlignLeft );
00065 layout->addWidget ( accountbox, 1, 0, Qt::AlignLeft );
00066 layout->addWidget ( datelabel, 2, 0, Qt::AlignLeft );
00067 layout->addWidget ( datebox, 3, 0, Qt::AlignLeft );
00068 layout->addWidget ( childcheckbox, 4, 0, Qt::AlignLeft );
00069 layout->addWidget ( childlabel, 5, 0, Qt::AlignLeft );
00070 layout->addWidget ( childbox, 6, 0, Qt::AlignLeft );
00071 layout->addWidget ( balancelabel, 0, 1, Qt::AlignLeft );
00072 layout->addWidget ( balancebox, 1, 1, Qt::AlignLeft );
00073 layout->addWidget ( creditlimitlabel, 2, 1, Qt::AlignLeft );
00074 layout->addWidget ( creditlimitbox, 3, 1, Qt::AlignLeft );
00075 layout->addWidget ( currencybox, 4, 1, Qt::AlignLeft );
00076 layout->addWidget ( typelabel, 5, 1, Qt::AlignLeft );
00077 layout->addWidget ( accounttype, 6, 1, Qt::AlignLeft );
00078
00079 connect ( childcheckbox, SIGNAL ( clicked() ), this, SLOT ( showChildPulldownMenu() ) );
00080 connect ( balancecalculator, SIGNAL ( released() ), this, SLOT ( showCalculator() ) );
00081 connect ( creditlimitcalculator, SIGNAL ( released() ), this, SLOT ( showCreditLimitCalculator() ) );
00082 connect ( accounttype, SIGNAL ( activated(int) ), this, SLOT ( activateCreditLimit(int) ) );
00083 connect ( datebutton, SIGNAL ( released() ), this, SLOT ( showCalendar() ) );
00084 connect ( descriptionbutton, SIGNAL ( released() ), this, SLOT ( addAccountDescription() ) );
00085 }
00086
00087 NewAccount::~NewAccount ()
00088 {
00089 }
00090
00091 void NewAccount::showChildPulldownMenu ()
00092 {
00093 if ( childcheckbox->isChecked() == TRUE )
00094 {
00095 childlabel->setEnabled ( TRUE );
00096 childbox->setEnabled ( TRUE );
00097 }
00098 else
00099 hideChildPulldownMenu();
00100 }
00101
00102 void NewAccount::hideChildPulldownMenu ()
00103 {
00104 childlabel->setEnabled ( FALSE );
00105 childbox->setEnabled ( FALSE );
00106 }
00107
00108 void NewAccount::showCalculator ()
00109 {
00110 Calculator *calculator = new Calculator ( this );
00111 calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) );
00112 if ( calculator->exec () == QDialog::Accepted )
00113 accountbalance->setText ( calculator->display->text() );
00114 }
00115
00116 void NewAccount::showCreditLimitCalculator ()
00117 {
00118 Calculator *calculator = new Calculator ( this );
00119 calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) );
00120 if ( calculator->exec () == QDialog::Accepted )
00121 creditlimit->setText ( calculator->display->text() );
00122 }
00123
00124 void NewAccount::activateCreditLimit ( int index )
00125 {
00126 if ( index == 2 || index == 5 )
00127 creditlimitbox->setEnabled ( TRUE );
00128 else
00129 {
00130 creditlimit->clear ();
00131 creditlimitbox->setEnabled ( FALSE );
00132 }
00133 }
00134
00135 void NewAccount::showCalendar ()
00136 {
00137 QDate newDate = QDate::currentDate ();
00138 DatePicker *dp = new DatePicker ( newDate );
00139 dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) );
00140
00141 int response = dp->exec();
00142 if ( response == QDialog::Accepted )
00143 {
00144
00145 year = dp->getYear();
00146 month = dp->getMonth();
00147 day = dp->getDay();
00148
00149
00150
00151
00152 dateedited = TRUE;
00153
00154
00155 startdate->setText ( preferences->getDate ( year, month, day ) );
00156 }
00157 }
00158
00159 bool NewAccount::getDateEdited ()
00160 {
00161 return dateedited;
00162 }
00163
00164 int NewAccount::getDay ()
00165 {
00166 return day;
00167 }
00168
00169 int NewAccount::getMonth ()
00170 {
00171 return month;
00172 }
00173
00174 int NewAccount::getYear ()
00175 {
00176 return year;
00177 }
00178
00179 QString NewAccount::getDescription ()
00180 {
00181 return accountdescription;
00182 }
00183
00184 void NewAccount::setDescription ( QString description )
00185 {
00186 accountdescription = description;
00187 }
00188
00189 void NewAccount::addAccountDescription ()
00190 {
00191
00192 QDialog *description = new QDialog ( this, "description", TRUE );
00193 description->setCaption ( "Notes" );
00194 QMultiLineEdit *enter = new QMultiLineEdit ( description );
00195 enter->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) );
00196 enter->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) );
00197 enter->setWordWrap ( QMultiLineEdit::WidgetWidth );
00198 if ( accountdescription != "(NULL)" )
00199 enter->setText ( accountdescription );
00200 if ( description->exec () == QDialog::Accepted )
00201 accountdescription = enter->text ();
00202 }
00203
00204
00205
00206