#ifndef POINTS_2_SURFACE_H
#define POINTS_2_SURFACE_H

#include <QMainWindow>

#include "ui_main_window.h"
#include "../geometry/geometry_types.h"
#include "../geometry/point_set.h"
#include <QtGui/QKeyEvent>


class QLabel;
class PaintCanvas;
class SceneGraph;
class DlgDownSampling;
class DlgRotatePointCloud;


class MainWindow : public QMainWindow, public Ui::PcdViewerClass
{
	Q_OBJECT

public:
	MainWindow(QWidget *parent = 0, Qt::WindowFlags flags = 0);
	~MainWindow();
	
	static std::string title() { return "[MainWindow]: "; }

	void showCoordinateUnderMouse(const Point3f& p, bool found);
	void showPixelPositionUnderMouse(const QPoint& p);

	PaintCanvas* canvas() { return mainCanvas_; }
	SceneGraph* output(const std::string& msg) ;

	void updateStatusBar();
	void updateAnnotationTable();

public slots:
	bool importPointCloud();
	bool exportPointCloud();

	bool snapshot();
	void recordCameraState();
	void restoreCameraState();

	void openRecentFile();

	void setFullScreen(bool b);

	void about();
	void aboutQt();

	void treeItemDataChanged(QTreeWidgetItem* item, int col);

	void downSampling();
	void rotatePointCloud();

	void operationModeChanged(QAction* act);

private:
	void createMenus();
	void createActions(); 
	void createStatusBar();

	void createActionsForFileMenu();
	void createActionsForViewMenu();
	void createActionsForSelectMenu();
	void createActionsForEditMenu();

	void readSettings();
	void writeSettings();

	void closeEvent(QCloseEvent *event);

	bool okToContinue();

	bool loadPointCloud(const QString &fileName);
	bool savePointCloud(const QString &fileName);
	
	void setCurrentPointCloudFile(const QString &fileName);
	
	void updateRecentFileActions();
	QString strippedName(const QString &fullFileName);

	void showStatusMessage(const QString &text, int timeout = 0);

private:
	PaintCanvas*  mainCanvas_;
	
	QMenu*		  contextMenu_;

	QStringList recentFiles_;
	QString     curMeshFileName_;
	QString     curPointCloudFileName_;
	QString     curDataDirectory_;

	QLabel *statusLabel,
		*spacerLabel,
		*coordinateUnderMouseLabel,
		*numVerticesLabel,
		*numVertexGroupsLabel;

	enum { MaxRecentFiles = 5 };
	QAction *actionsRecentFile[MaxRecentFiles],
		*actionSeparator;

	DlgDownSampling*			dlgDownSampling_;
	DlgRotatePointCloud*		dlgRotatePointCloud_;
};

#endif // TESTQGLVIEWER_H
