#include "main_window.h"
#include "mesh_processor.h"

#include <QApplication>
#include <QFileDialog>


MainWindow::MainWindow(QWidget *parent)
	:QMainWindow(parent),
	 toolbar(this),
	 mesh_viewer(this) {
	connect(&mesh_viewer, &MeshViewer::initialized, [&]() {
		open_action->setEnabled(true);
	});
	setCentralWidget(&mesh_viewer);
	addToolBar(Qt::RightToolBarArea, &toolbar);
	open_action = toolbar.addAction("Ouvrir…", [&](){
		emit open(QFileDialog::getOpenFileName(this, "Ouvrir un maillage"));
	});
	// toolbar_actions.append(toolbar.addAction("Fractionner", [&](){
	// 	QVector<QPair<MyMesh::Point, MyMesh>> fragments = shatter(mesh);
	// 	mesh_viewer.removeOpenGLMesh(glm);
	// 	for (auto &[pos, fragment] : fragments) {
	// 		fragment.triangulate();
	// 		QMatrix4x4 mat;
	// 		float scale = 1.2;
	// 		mat.translate(pos[0] * scale, pos[1] * scale, pos[2] * scale);
	// 		mesh_viewer.addOpenGLMeshFromOpenMesh(&fragment, mat);
	// 	}
	// }));
	open_action->setEnabled(false);
	for (QAction *a : toolbar_actions) {
		a->setEnabled(false);
	}
}
