/*
    Stanley Designer
    Copyright (C) 2012  Ivan Pelipenko peri4ko@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef QGLVIEWWINDOW_H
#define QGLVIEWWINDOW_H

#include <QTranslator>
#include <QInputDialog>
#include <QFileDialog>
#include <QColorDialog>
#include <QCloseEvent>
#include <QClipboard>
#include <QRadioButton>
#include <QUrl>
#include <QThread>
#include <QTime>
#include <QSplitter>
#include "ui_qglview_window.h"
#include "loader_3ds.h"
#include "loader_ase.h"
#include "renderer_simple.h"
#include "renderer_deferred_shading.h"
//#include "renderer_rt.h"
#include "glparticles_system.h"
#include "water_system.h"
#include "rope_system.h"


class QGLViewWindow: public QMainWindow, public Ui::QGLViewWindow
{
	Q_OBJECT
public:
	QGLViewWindow(QWidget * parent = 0);
	~QGLViewWindow();

	void loadFile(const QString & path);

private:
	// Qt`s overloaded
	void changeEvent(QEvent * e);
	void timerEvent(QTimerEvent * );

	void importFile(const QString & path);
	void makeObjetTree(const GLObjectBase * o, QTreeWidgetItem * ti);

	QTranslator translator;
	QIcon icon_geo, icon_camera, icon_light;
	QString prev_path;
	GLObjectBase * sel_obj, * axis;
	Light * cam_light;
	GLPrimitiveCube * box;
	Material m;
	bool isChanged;

	GLParticlesSystem partsys;

private slots:
	void on_spinFOV_valueChanged(double val) {view->setFOV(val);}
	void on_spinDepthStart_valueChanged(double val) {view->setDepthStart(val);}
	void on_spinDepthEnd_valueChanged(double val) {view->setDepthEnd(val);}
	void on_comboRenderer_currentIndexChanged(int val);
	void on_comboViewRenderMode_currentIndexChanged(int val) {static int modes[] = {GL_POINT, GL_LINE, GL_FILL}; view->setRenderMode((GLObjectBase::RenderMode)modes[val]);}
	void on_groupHoverHalo_clicked(bool val) {view->setHoverHaloEnabled(val);}
	void on_groupSelectionHalo_clicked(bool val) {view->setSelectionHaloEnabled(val);}
	void on_spinHoverHaloFill_valueChanged(double val) {view->setHoverHaloFillAlpha(val);}
	void on_spinSelectionHaloFill_valueChanged(double val) {view->setSelectionHaloFillAlpha(val);}
	void on_colorHoverHalo_colorChanged(QColor color) {view->setHoverHaloColor(color);}
	void on_colorSelectionHalo_colorChanged(QColor color) {view->setSelectionHaloColor(color);}
	void on_checkFXAA_clicked(bool val) {view->setFeature(QGLView::qglFXAA, val);}
	void on_checkMSAA_clicked(bool val) {view->setFeature(QGLView::qglMSAA, val);}
	void on_colorBack_colorChanged(QColor color) {view->setBackColor(color);}
	void on_colorAmbient_colorChanged(QColor color) {view->setAmbientColor(color);}
	void on_checkCameraOrbit_clicked(bool val) {view->setCameraOrbit(val);}

	void on_groupShadows_clicked(bool val) {view->setFeature(QGLView::qglShadowsEnabled, val);}
	void on_groupEyeAccomodation_clicked(bool val) {view->setFeature(QGLView::qglEyeAccomodationEnabled, val);}
	void on_groupBloom_clicked(bool val) {view->setFeature(QGLView::qglBloomEnabled, val);}
	void on_groupMotionBlur_clicked(bool val) {view->setFeature(QGLView::qglMotionBlurEnabled, val);}
	void on_groupReflections_clicked(bool val) {view->setFeature(QGLView::qglReflectionsEnabled, val);}
	void on_checkSoftShadows_clicked(bool val) {view->setFeature(QGLView::qglShadowsSoftEnabled, val);}
	void on_groupSSAO_clicked(bool val) {view->setFeature(QGLView::qglSSAOEnabled, val);}
	void on_groupDOF_clicked(bool val) {view->setFeature(QGLView::qglDepthOfFieldEnabled, val);}
	void on_checkDOFAutoFocus_clicked(bool val) {view->setFeature(QGLView::qglDepthOfFieldAutoFocusEnabled, val);}
	void on_spinDOFFocus_valueChanged(double val) {view->setFeature(QGLView::qglDepthOfFieldFocus, val);}
	void on_spinDOFDiaphragm_valueChanged(double val) {view->setFeature(QGLView::qglDepthOfFieldDiaphragm, val);}
	void on_spinDOFSpeed_valueChanged(double val) {view->setFeature(QGLView::qglDepthOfFieldAutoFocusSpeed, val);}
	void on_spinAccom_valueChanged(double val) {view->setFeature(QGLView::qglEyeAccomodationTime, val);}
	void on_spinAccomMS_valueChanged(double val) {view->setFeature(QGLView::qglEyeAccomodationMaxSpeed, val);}
	void on_checkReflectionsBlur_clicked(bool val) {view->setFeature(QGLView::qglReflectionsBlur, val);}
	void on_spinShadowmapSize_valueChanged(double val) {view->setFeature(QGLView::qglShadowsMapSize, val);}
	void on_spinMotionBlurFactor_valueChanged(double val) {view->setFeature(QGLView::qglMotionBlurFactor, val);}
	void on_spinMotionBlurSteps_valueChanged(int val) {view->setFeature(QGLView::qglMotionBlurSteps, val);}
	void on_spinBloomFactor_valueChanged(double val) {view->setFeature(QGLView::qglBloomFactor, val);}
	void on_spinBloomRadius_valueChanged(int val) {view->setFeature(QGLView::qglBloomRadius, val);}
	void on_spinBloomThreshold_valueChanged(double val) {view->setFeature(QGLView::qglBloomThreshold, val);}
	void on_spinSSAORadius_valueChanged(int val) {view->setFeature(QGLView::qglSSAORadius, val);}

	void on_actionExit_triggered() {close();}
	void on_actionReset_triggered();
	void on_actionImport_triggered();
	void on_actionSave_triggered();
	void on_actionSaveSelected_triggered();
	void on_actionOpen_triggered();

	void on_view_glKeyPressEvent(QKeyEvent * e);
	void on_view_glInitializeDone();
	void on_view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m);

	void on_treeObjects_itemClicked(QTreeWidgetItem * ti, int col);

	void objectsTreeChanged();
	void materialChanged();
	void selectionChanged(GLObjectBase * cur, GLObjectBase * prev);

	void on_pushButton_clicked();
	void on_pushButton_2_clicked() {view->reloadShaders();}
	void on_pushButton_3_clicked();

public slots:

signals:

private:
	QMatrix4x4 cam_mat;

};

#endif // QGLVIEWWINDOW_H
