#include "MainWindow.h"

#include <QResizeEvent>

#include "map/3D/MapView3D.h"
#include "map/2D/MapView2D.h"

#include "menu/MainMenu.h"
#include "debug/SensorDataWidget.h"
#include "debug/InfoWidget.h"
#include "UIHelper.h"

#include <QGridLayout>

MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {

	setMinimumHeight(500);
	setMinimumWidth(500);

	mapView3D = new MapView3D(this);
	mapView2D = new MapView2D(this);

	mainMenu = new MainMenu(this);
	infoWidget = new InfoWidget(this);
	sensorWidget = new SensorDataWidget(this);

	// ensure we are fullscreen
	showMaximized();

	sleep(1);
	emit resizeEvent(nullptr);

	// important! must be called AFTER window is visible
	// otherwise MapView3D's openGL context is uninitialized.
	sensorWidget->setVisible(false);
	mapView2D->setVisible(true);
	mapView3D->setVisible(false);

}

void MainWindow::resizeEvent(QResizeEvent* event) {

	const int w = this->width();
	const int h = this->height();

	const int menuH = UIHelper::getMainMenuHeight(this);
	const int infoH = UIHelper::getInfoHeight(this);

	int y = 0;

	mainMenu->setGeometry(0,y,w,menuH);			y += menuH;
	infoWidget->setGeometry(0,y,w,infoH);		y += infoH;

	mapView3D->setGeometry(0,y,w,h-y);
	mapView2D->setGeometry(0,y,w,h-y);

	sensorWidget->setGeometry(0,y,w,h-y);

	mainMenu->resizeEvent(event);
	mapView2D->resizeEvent(event);
//	infoWidget->resizeEvent(event);


}


