summaryrefslogtreecommitdiff
path: root/noncore/unsupported/qashmoney/newaccount.cpp
blob: 5932182d66e67be7b0cd18a6f19bd41ed2294930 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#include "newaccount.h"
#include "calculator.h"
#include "datepicker.h"
#include <qmultilineedit.h>

extern Preferences *preferences;

NewAccount::NewAccount ( QWidget *parent, const char *name, bool modal ) : QDialog ( parent, name, modal )
  {
    accountdescription = "";
    dateedited = FALSE;
    setCaption( tr( "Account" ) );

    namelabel = new QLabel ( "Account Name", this );

    accountbox = new QHBox ( this );
    accountname = new QLineEdit ( accountbox );
    descriptionbutton = new QPushButton ( accountbox );
    descriptionbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/info.png" ) );

    datelabel = new QLabel ( "Date", this );

    datebox = new QHBox ( this );
    startdate = new QLineEdit ( datebox );
    startdate->setDisabled ( TRUE );
    datebutton = new QPushButton ( datebox );
    datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) );

    childcheckbox = new QCheckBox ( this );
    childcheckbox->setText( tr ( "Child Account" ) );

    childlabel = new QLabel ( "Child of", this );
    childbox = new QComboBox ( FALSE, this );
    hideChildPulldownMenu ();

    balancelabel = new QLabel ( "Balance", this );

    balancebox = new QHBox ( this );
    accountbalance = new QLineEdit ( balancebox );
    accountbalance->setText ( "0.00" );
    balancecalculator = new QPushButton( balancebox );
    balancecalculator->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) );

    creditlimitlabel = new QLabel ( "Credit Limit", this );

    creditlimitbox = new QHBox ( this );
    creditlimit = new QLineEdit ( creditlimitbox );
    creditlimitbox->setEnabled ( FALSE );
    creditlimitcalculator = new QPushButton( creditlimitbox );
    creditlimitcalculator->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) );

    currencybox = new Currency ( this );

    typelabel = new QLabel ( "Type", this );
    accounttype = new QComboBox ( FALSE, this );
    accounttype->insertItem( tr( "Bank" ) );
    accounttype->insertItem( tr( "Cash" ) );
    accounttype->insertItem( tr( "Credit Card" ) );
    accounttype->insertItem( tr( "Equity" ) );
    accounttype->insertItem( tr( "Asset" ) );
    accounttype->insertItem( tr( "Liability" ) );

    layout = new QGridLayout ( this, 7, 2, 4, 2 );
    layout->addWidget ( namelabel , 0, 0, Qt::AlignLeft );
    layout->addWidget ( accountbox, 1, 0, Qt::AlignLeft );
    layout->addWidget ( datelabel, 2, 0, Qt::AlignLeft );
    layout->addWidget ( datebox, 3, 0, Qt::AlignLeft );
    layout->addWidget ( childcheckbox, 4, 0, Qt::AlignLeft );
    layout->addWidget ( childlabel, 5, 0, Qt::AlignLeft );
    layout->addWidget ( childbox, 6, 0, Qt::AlignLeft );
    layout->addWidget ( balancelabel, 0, 1, Qt::AlignLeft );
    layout->addWidget ( balancebox, 1, 1, Qt::AlignLeft );
    layout->addWidget ( creditlimitlabel, 2, 1, Qt::AlignLeft );
    layout->addWidget ( creditlimitbox, 3, 1, Qt::AlignLeft );
    layout->addWidget ( currencybox, 4, 1, Qt::AlignLeft );
    layout->addWidget ( typelabel, 5, 1, Qt::AlignLeft );
    layout->addWidget ( accounttype, 6, 1, Qt::AlignLeft );

    connect ( childcheckbox, SIGNAL ( clicked() ), this, SLOT ( showChildPulldownMenu() ) );
    connect ( balancecalculator, SIGNAL ( released() ), this, SLOT ( showCalculator() ) );
    connect ( creditlimitcalculator, SIGNAL ( released() ), this, SLOT ( showCreditLimitCalculator() ) );
    connect ( accounttype, SIGNAL ( activated(int) ), this, SLOT ( activateCreditLimit(int) ) );
    connect ( datebutton, SIGNAL ( released() ), this, SLOT ( showCalendar() ) );
    connect ( descriptionbutton, SIGNAL ( released() ), this, SLOT ( addAccountDescription() ) );
}

NewAccount::~NewAccount ()
  {
  }

void NewAccount::showChildPulldownMenu ()
  {
    if ( childcheckbox->isChecked() == TRUE )
      {
        childlabel->setEnabled ( TRUE );
        childbox->setEnabled ( TRUE );
      }
    else
      hideChildPulldownMenu();
  }

void NewAccount::hideChildPulldownMenu ()
  {
    childlabel->setEnabled ( FALSE );
    childbox->setEnabled ( FALSE );
  }

void NewAccount::showCalculator ()
  {
    Calculator *calculator = new Calculator ( this );
    calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) );
    if ( calculator->exec () == QDialog::Accepted )
      accountbalance->setText ( calculator->display->text() );
  }

void NewAccount::showCreditLimitCalculator ()
  {
    Calculator *calculator = new Calculator ( this );
    calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) );
    if ( calculator->exec () == QDialog::Accepted )
      creditlimit->setText ( calculator->display->text() );
  }

void NewAccount::activateCreditLimit ( int index )
  {
    if ( index == 2 || index == 5 )
      creditlimitbox->setEnabled ( TRUE );
    else
     {
       creditlimit->clear ();
       creditlimitbox->setEnabled ( FALSE );
     }
  }

void NewAccount::showCalendar ()
  {
    QDate newDate = QDate::currentDate ();
    DatePicker *dp = new DatePicker ( newDate );
    dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) );

    int response = dp->exec();
    if ( response == QDialog::Accepted )
      {
	// Set date integers
	year = dp->getYear();
	month = dp->getMonth();
	day = dp->getDay();

	// Set dateedited to TRUE
	// This tells the accountdisplay object that the user edited an account
	// and did change the date
	dateedited = TRUE;

	// Display date with our selected format
	startdate->setText ( preferences->getDate ( year, month, day ) );
      }
  }

bool NewAccount::getDateEdited ()
  {
    return dateedited;
  }

int NewAccount::getDay ()
  {
    return day;
  }

int NewAccount::getMonth ()
  {
    return month;
  }

int NewAccount::getYear ()
  {
    return year;
  }

QString NewAccount::getDescription ()
  {
    return accountdescription;
  }

void NewAccount::setDescription ( QString description )
  {
    accountdescription = description;
  }

void NewAccount::addAccountDescription ()
  {
    // Function for adding or editing an account description.
    QDialog *description = new QDialog ( this, "description", TRUE );
    description->setCaption ( "Notes" );
    QMultiLineEdit *enter = new QMultiLineEdit ( description );
    enter->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) );
    enter->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) );
    enter->setWordWrap ( QMultiLineEdit::WidgetWidth );
    if ( accountdescription != "(NULL)" )
      enter->setText ( accountdescription );
    if ( description->exec () == QDialog::Accepted )
      accountdescription = enter->text ();
  }