-
Notifications
You must be signed in to change notification settings - Fork 0
/
calcdiv.cpp
88 lines (67 loc) · 2.32 KB
/
calcdiv.cpp
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
#include "calcdiv.h"
#include <QLineEdit>
#include <QLabel>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>
CalcDiv::CalcDiv(QWidget *parent)
: QWidget(parent)
{
QLabel *firstLabel = new QLabel("&First number:");
QLabel *secondLabel = new QLabel("&Second number:");
QLabel *resultLabel = new QLabel("&Result:");
QLineEdit *firstNumber = new QLineEdit;
QLineEdit *secondNumber = new QLineEdit;
QLineEdit *result = new QLineEdit;
QPushButton *divButton = new QPushButton("/");
firstNumber->setFixedWidth(40);
firstNumber->setMaxLength(5);
secondNumber->setFixedWidth(40);
secondNumber->setMaxLength(5);
result->setFixedWidth(40);
result->setMaxLength(5);
result->setReadOnly(true);
firstLabel->setBuddy(firstNumber);
secondLabel->setBuddy(secondNumber);
resultLabel->setBuddy(result);
connect(firstNumber, SIGNAL(textChanged(QString)), this, SLOT(setFirstNumb(QString)));
connect(secondNumber, SIGNAL(textChanged(QString)), this, SLOT(setSecondNumb(QString)));
connect(divButton, SIGNAL(clicked()), this, SLOT(setResult()));
connect(this, SIGNAL(getResult(QString)), result, SLOT(setText(QString)));
QHBoxLayout *firstNumbLayout = new QHBoxLayout;
QHBoxLayout *secondNumbLayout = new QHBoxLayout;
QHBoxLayout *resultLayout = new QHBoxLayout;
firstNumbLayout->addWidget(firstLabel);
firstNumbLayout->addWidget(firstNumber);
secondNumbLayout->addWidget(secondLabel);
secondNumbLayout->addWidget(secondNumber);
resultLayout->addWidget(resultLabel);
resultLayout->addWidget(result);
QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addLayout(firstNumbLayout);
leftLayout->addLayout(secondNumbLayout);
leftLayout->addLayout(resultLayout);
QHBoxLayout *layout = new QHBoxLayout;
layout->addLayout(leftLayout);
layout->addWidget(divButton);
setLayout(layout);
}
CalcDiv::~CalcDiv()
{
}
void CalcDiv::setFirstNumb(QString str)
{
int firstNumb = str.toInt();
this->firstNumb = firstNumb;
}
void CalcDiv::setSecondNumb(QString str)
{
int secondNumb = str.toInt();
this->secondNumb = secondNumb;
}
void CalcDiv::setResult()
{
this->result = (float)this->firstNumb / (float)this->secondNumb;
emit getResult(QString::number(this->result));
}