/*
    QGL SceneTree
    Ivan Pelipenko peri4ko@yandex.ru

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser 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 Lesser General Public License for more details.

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

#ifndef SCENE_TREE_H
#define SCENE_TREE_H

#include "glscene.h"

#include <QIcon>
#include <QWidget>

class QTreeWidgetItem;

namespace Ui {
class SceneTree;
}

class SceneTree: public QWidget {
	Q_OBJECT

public:
	SceneTree(QWidget * parent = 0);
	~SceneTree();

	void assignQGLView(QGLView * v);
	QList<QAction *> actionsAdd();
	QList<QAction *> actionsSelection();
	void expandItems();

private:
	void changeEvent(QEvent * e);
	void rememberExpanded(QTreeWidgetItem * ti);
	void restoreExpanded(QTreeWidgetItem * ti);
	void makeObjetTree(ObjectBase * o, QTreeWidgetItem * ti);
	ObjectBase * itemObject(QTreeWidgetItem * item) const;
	ObjectBase * insertTarget() const;
	int itemType(QTreeWidgetItem * item) const;
	bool filterTree(QTreeWidgetItem * ti, const QString & filter, int types);
	void checkActions();

	Ui::SceneTree * ui;
	bool block_tree;
	int hidden_by_filter, obj_count;
	QIcon icon_empty, icon_geo, icon_camera, icon_light, icon_vis[2];
	QSet<ObjectBase *> expanded_;
	QList<QTreeWidgetItem *> geo_items, cam_items;
	QGLView * view;

private slots:
	void treeObjects_selectionCnahged();
	void on_treeObjects_itemChanged(QTreeWidgetItem * item, int column);
	void on_treeObjects_itemMoved(QTreeWidgetItem * item, QTreeWidgetItem * new_parent);

	void on_actionAdd_node_triggered();
	void on_actionAdd_light_triggered();
	void on_actionAdd_camera_triggered();

	void on_actionFocus_triggered() { focusObjects(); }
	void on_actionRemove_triggered() { removeObjects(); }
	void on_actionClone_triggered();
	void on_actionGroup_triggered();
	void on_actionTransfer_transform_to_children_triggered();
	void on_actionMove_to_parent_triggered();

	void on_actionActive_camera_triggered();
	void on_actionDefault_camera_triggered();

	void on_actionSelect_parent_triggered();
	void on_actionSelect_by_mesh_triggered();
	void on_actionSelect_by_material_triggered();

	void removeObjects();
	void focusObjects();
	void objectsTreeChanged();
	void selectionChanged();
	void materialsChanged();
	void cameraChanged();
	void filter();
	void __objectDeleted(ObjectBase * o);

public slots:

signals:

private:
};

#endif // SCENE_TREE_H
