 
#include "MainMenu.h"
#include "../Icons.h"

#include <QPushButton>
#include <QGridLayout>
#include <QLabel>

#include <Indoor/Assertions.h>
#include "../UIHelper.h"

MainMenu::MainMenu(QWidget* parent) : QWidget(parent) {


	QGridLayout* lay = new QGridLayout(this);
	int row = 0;
	int col = 0;

	btnLoadMap = getButton("load");
	Assert::isTrue(connect(btnLoadMap, &QPushButton::clicked, this, &MainMenu::onLoadButton), "connect() failed");
	lay->addWidget(btnLoadMap, row, col, 1,1,Qt::AlignTop);		++col;

	btnDebug = getButton("bug");
	Assert::isTrue(connect(btnDebug, &QPushButton::clicked, this, &MainMenu::onDebugButton), "connect() failed");
	lay->addWidget(btnDebug, row, col, 1,1,Qt::AlignTop);		++col;

	btnCamera = getButton("camera");
	Assert::isTrue(connect(btnCamera, &QPushButton::clicked, this, &MainMenu::onCameraButton), "connect() failed");
	lay->addWidget(btnCamera, row, col, 1,1,Qt::AlignTop);		++col;

	btnTransparent = getButton("wall");
	Assert::isTrue(connect(btnTransparent, &QPushButton::clicked, this, &MainMenu::onTransparentButton), "connect() failed");
	lay->addWidget(btnTransparent, row, col, 1,1,Qt::AlignTop);	++col;

	btn3D = getButton("cube");
	Assert::isTrue(connect(btn3D, &QPushButton::clicked, this, &MainMenu::on3DButton), "connect() failed");
	lay->addWidget(btn3D, row, col, 1,1,Qt::AlignTop);	++col;


	btnStart = getButton("run");
	Assert::isTrue(connect(btnStart, &QPushButton::clicked, this, &MainMenu::onStartButton), "connect() failed");
	lay->addWidget(btnStart, row, col, 1,1,Qt::AlignTop);		++col;

}

static inline void setButtonSize(QPushButton* btn, int size) {
	const int border = 4;
	btn->setMinimumHeight(size+border);
	btn->setMaximumHeight(size+border);
	btn->setMinimumWidth(size+border);
	btn->setMaximumWidth(size+border);
}

void MainMenu::resizeEvent(QEvent* evt) {

	const int s = UIHelper::getButtonSize(this->parent());
	setButtonSize(btnLoadMap, s);
	setButtonSize(btnDebug, s);
	setButtonSize(btnCamera, s);
	setButtonSize(btnTransparent, s);
	setButtonSize(btnStart, s);
	setButtonSize(btn3D, s);


}

QPushButton* MainMenu::getButton(const std::string& icon) {

	const int size = UIHelper::getButtonSize(this->parent());


	QPushButton* btn = new QPushButton(Icons::getIcon(icon, size), "");
	btn->setIconSize(QSize(size,size));
	setButtonSize(btn, size);

	return btn;

}
