#include "resourceWidget.h"
#include "softProj\settings.h"
#include "softProj\helpers.h"

ResourceWidget::ResourceWidget(QWidget * parent) : QWidget(parent) {
	ui_.setupUi(this);
}

void ResourceWidget::setName(const std::wstring & name) {
	ui_.nameButton->setText(QString::fromUtf16(name.c_str()));
}

void ResourceWidget::setIcon(const std::string & path) {
	QIcon icon;
	icon.addFile(QString::fromUtf8(path.c_str()));
	ui_.nameButton->setIcon(icon);
}

void ResourceWidget::setValue(unsigned long long value) {
	ui_.weightValue->setText(Settings::instance().formatNumber(value) + countUnit_);
}

void ResourceWidget::setValueUnit(const std::wstring & countUnit) {
	this->countUnit_ = " " + QString::fromUtf16(countUnit.c_str());
}

void ResourceWidget::setCapacityUnit(const std::wstring & unit) {
	this->capacityUnit_ = " " + QString::fromUtf16(unit.c_str());
}

void ResourceWidget::setSize(unsigned long long value) {
	ui_.capacityValue->setText(Settings::instance().formatNumber(value) + capacityUnit_);
}

void ResourceWidget::setFreeCapacity(unsigned long long value) {
	ui_.freeCapacityValue->setText(Settings::instance().formatNumber(value) + countUnit_);
}

void ResourceWidget::setFreeCapacity(const std::wstring & value) {
	ui_.freeCapacityValue->setText(QString::fromUtf16(value.c_str()));
}

void ResourceWidget::setSize(const std::wstring & value) {
	ui_.capacityValue->setText(QString::fromUtf16(value.c_str()));
}

void ResourceWidget::setGradient(signed long long value) {
	QString sign = QString("+ ");

	if (value >= 0) {
		sign = QString("+ ");
	}
	else {
		sign = QString::null;
	}

	ui_.gradientValue->setText(sign + Settings::instance().formatNumber(value) + " " + countUnit_ + " / hs");
}

void ResourceWidget::setValueLabel(const std::wstring & value) {
	ui_.weightLabel->setText(QString::fromUtf16(value.c_str()));
}