-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetbudget.cpp
More file actions
102 lines (89 loc) · 2.97 KB
/
Copy pathsetbudget.cpp
File metadata and controls
102 lines (89 loc) · 2.97 KB
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
#include "setbudget.h"
#include "QIntValidator"
#include "ui_setbudget.h"
#include <qpushbutton.h>
SetBudget::SetBudget(QWidget *parent)
: QDialog(parent)
, ui(new Ui::SetBudget)
{
ui->setupUi(this);
ui->foodLabel->setVisible(false);
ui->foodLineEdit->setVisible(false);
ui->transportationLabel->setVisible(false);
ui->transportationLineEdit->setVisible(false);
ui->otherLabel->setVisible(false);
ui->otherLineEdit->setVisible(false);
QIntValidator *validator = new QIntValidator(0, 100, this);
ui->foodLineEdit->setValidator(validator);
ui->transportationLineEdit->setValidator(validator);
ui->otherLineEdit->setValidator(validator);
connect(ui->customSplitRadio, &QRadioButton::toggled, this, &SetBudget::customRadioToggled);
connect(ui->createSplitRadio, &QRadioButton::toggled, this, &SetBudget::defaultRadioToggled);
connect(ui->foodLineEdit, &QLineEdit::textChanged, this, &SetBudget::validatePercentages);
connect(ui->transportationLineEdit,
&QLineEdit::textChanged,
this,
&SetBudget::validatePercentages);
connect(ui->otherLineEdit, &QLineEdit::textChanged, this, &SetBudget::validatePercentages);
}
void SetBudget::validatePercentages()
{
int value1 = ui->foodLineEdit->text().toInt();
int value2 = ui->transportationLineEdit->text().toInt();
int value3 = ui->otherLineEdit->text().toInt();
if (value1 + value2 + value3 == 100) {
ui->buttonBox->setEnabled(true);
} else {
ui->buttonBox->setEnabled(false);
}
}
void SetBudget::defaultRadioToggled(bool checked)
{
if (checked) {
ui->buttonBox->setEnabled(true);
}
}
std::vector<QString> SetBudget::getPercentages(int mode)
{
if (mode == 2) {
return {ui->foodLineEdit->text(),
ui->transportationLineEdit->text(),
ui->otherLineEdit->text()};
} else {
return {"30", "25", "45"};
}
}
int SetBudget::getRadioMode()
{
if (ui->createSplitRadio->isChecked()) {
return 1;
} else {
return 2;
}
}
void SetBudget::customRadioToggled(bool checked)
{
if (!checked) {
this->resize(this->width(), 300);
ui->buttonBox->move(ui->buttonBox->x(), ui->buttonBox->y() - 100);
ui->foodLabel->setVisible(false);
ui->foodLineEdit->setVisible(false);
ui->transportationLabel->setVisible(false);
ui->transportationLineEdit->setVisible(false);
ui->otherLabel->setVisible(false);
ui->otherLineEdit->setVisible(false);
} else {
this->resize(this->width(), 400);
ui->foodLabel->setVisible(true);
ui->foodLineEdit->setVisible(true);
ui->transportationLabel->setVisible(true);
ui->transportationLineEdit->setVisible(true);
ui->otherLabel->setVisible(true);
ui->otherLineEdit->setVisible(true);
ui->buttonBox->move(ui->buttonBox->x(), ui->buttonBox->y() + 100);
}
}
SetBudget::~SetBudget()
{
delete ui;
}