#ifndef HANGAR_ITEM_WIDGET_H
#define HANGAR_ITEM_WIDGET_H

#include <QtGui>
#include <list>
#include <cassert>
#include "ui_hangarItemWidget.h"
#include "softProj\clientServer\structs.h"

class HangarItemWidget : public QWidget {
	Q_OBJECT

private:
	Ui::HangarItemWidget ui_;
	id_t itemId_;

	QIcon hangarIcon;
signals:
	void clickedSignal(id_t itemId);
private slots:
	void installButtonClickedSlot(bool checked) {
		emit clickedSignal(itemId_);
	}
public:
	HangarItemWidget(QWidget * parent) : QWidget(parent) {
		ui_.setupUi(this);

		bool connected = true;
		connected = connected && connect(ui_.nameButton, SIGNAL(clicked(bool)), this, SLOT(installButtonClickedSlot(bool)));
		connected = connected && connect(ui_.imageButton, SIGNAL(clicked(bool)), this, SLOT(installButtonClickedSlot(bool)));
		assert(connected && "Signals not connected");

		hangarIcon.addFile(QString::fromUtf8(":/pictures/images/others/hangary.png"), QSize(), QIcon::Normal, QIcon::Off);

		itemId_ = 0;
	}

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

	void setItemName(const std::string & itemName) {
		ui_.nameButton->setText(QString::fromUtf8(itemName.c_str()));
	}

	void setItemId(id_t itemId) {
		this->itemId_ = itemId;
	}

	void setButtonIcon(const std::string & path, int width, int height) {
        QIcon icon;
		icon.addFile(QString::fromUtf8(path.c_str()), QSize(), QIcon::Normal, QIcon::Off);

		ui_.nameButton->setIcon(icon);
        ui_.nameButton->setIconSize(QSize(width, height));
	}

	void setAsBeingConstructed(bool constructed) {
		if (constructed) {
			ui_.imageButton->setIcon(hangarIcon);
			ui_.imageButton->setIconSize(QSize(20, 20));
		}
		else {
			ui_.imageButton->setIcon(QIcon());
		}
	}
};

#endif