#include <QtWidgets>
#include "controls.h"

Controls::Controls(QWidget *parent) : QWidget(parent)
{
	QVBoxLayout *mainLayout = new QVBoxLayout;

	QHBoxLayout *argsLayout = new QHBoxLayout;
	argsLayout->addWidget(arg1 = new QLineEdit);
	argsLayout->addWidget(arg2 = new QLineEdit);
	mainLayout->addLayout(argsLayout);

	mainLayout->addWidget(result = new QLineEdit);

	QHBoxLayout *opsLayout = new QHBoxLayout;
	opsLayout->addWidget(add = new QPushButton("+"));
	opsLayout->addWidget(sub = new QPushButton("-"));
	opsLayout->addWidget(mul = new QPushButton("*"));
	opsLayout->addWidget(div = new QPushButton("/"));
	mainLayout->addLayout(opsLayout);

	setLayout(mainLayout);

	connect(add, &QPushButton::clicked, this, &Controls::doAdd);
	connect(sub, &QPushButton::clicked, this, &Controls::doSub);
	connect(mul, &QPushButton::clicked, this, &Controls::doMul);
	connect(div, &QPushButton::clicked, this, &Controls::doDiv);
}

void Controls::doAdd()
{
	result->setText(QString::number(arg1->text().toDouble() + arg2->text().toDouble()));
}

void Controls::doSub()
{
	result->setText(QString::number(arg1->text().toDouble() - arg2->text().toDouble()));
}

void Controls::doMul()
{
	result->setText(QString::number(arg1->text().toDouble() * arg2->text().toDouble()));
}

void Controls::doDiv()
{
	result->setText(QString::number(arg1->text().toDouble() / arg2->text().toDouble()));
}
