#ifndef SECTION_NAME_WIDGET_H
#define SECTION_NAME_WIDGET_H

#include <QtGui>
#include "ui_sectionNameWidget.h"

class SectionNameWidget : public QWidget {
	Q_OBJECT

private:
	Ui::SectionNameWidget ui_;
	QString name_;
	bool isInChangedState_;
public:
	SectionNameWidget(QWidget * parent) : QWidget(parent) {
		ui_.setupUi(this);	

		isInChangedState_ = false;
	}

	void setName(const std::wstring & name) {
		name_ = QString::fromUtf16(name.c_str());
		
		refreshAppearance();
	}

	void setAsChanged() {
		this->isInChangedState_ = true;
		refreshAppearance();
	}

	void setAsNormal() {
		this->isInChangedState_ = false;
		refreshAppearance();
	}

	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_.sectionNameButton->setIcon(icon);
        ui_.sectionNameButton->setIconSize(QSize(width, height));
	}

	virtual void setGeometry(const QRect & rect) {
		setGeometry(rect.x(), rect.y(), rect.width(), rect.height());
	}

	virtual void setGeometry(int ax, int ay, int awidth, int aheight) {
		QWidget::setGeometry(ax, ay, awidth, aheight);

		ui_.sectionBorderFrame->setGeometry(0, 0, this->width(), this->height());
		ui_.sectionMainFrame->setGeometry(0, 0, this->width(), this->height());

		ui_.sectionNameButton->setGeometry(3, 3, ui_.sectionMainFrame->width() - 6, ui_.sectionMainFrame->height() - 6);
	}

private:
	void refreshAppearance() {
		if (isInChangedState_) {
			ui_.sectionNameButton->setText(name_ + QString::fromUtf16(L" (Změněno)"));
			ui_.sectionNameButton->setProperty("changed", true);
			ui_.sectionNameButton->setStyleSheet(ui_.sectionNameButton->styleSheet());
		}
		else {
			ui_.sectionNameButton->setText(name_);
			// Set property as invalid QVariant to unset it
			ui_.sectionNameButton->setProperty("changed", QVariant());
			ui_.sectionNameButton->setStyleSheet(ui_.sectionNameButton->styleSheet());
		}
	}
};

#endif