#ifndef SCIENCE_TREE_WIDGET
#define SCIENCE_TREE_WIDGET

#include <QtGui>

#include "ScienceNode.h"
#include "ScienceTree.h"
#include "protocol.h"
#include "softProj\clientServer\structs.h"

/// Widget is used for developing game technologies.
/** Main widget with science tree that encapsulates all science tree funcionality */ 
class ScienceTreeWidget : public QWidget
{
	Q_OBJECT
public:
	/**
	* Constructor
	* @param parent Parent widget
	*/
	ScienceTreeWidget(QWidget * parent);

	/** Destructor */
	~ScienceTreeWidget();

	/** Gets state of the tree, that means composition of points in a tree 
	* @return State of the tree
	*/
	sciencetree_raw_data getState();

	/** Sets state of the tree, that means composition of points in a tree 
	* @param data State of the tree
	*/
	void setState(ScienceTreeRawUpdateData & data);

	/** Creates and then appends composite item to leaf with given index
	* @param parentName Logical name of parent node of composite
	* @param compositeName Logical name of appended composite
	* @param graphicalName Graphical Name of new composite item 
	*/
	void appendComposite(const std::string & parentName, const std::string & compositeName, QString graphicalName);

	/** Sets multiplicators for corresponding levels of a tree 
	* @param values Multiplicators for all levels 
	* @param count Size of array with multiplicators 
	*/
	void setTokenMultiplicators(double * values, int count);

	/** Sets option of showing tokens in nodes 
	* @param option Showing option 
	*/
	void setShowTokens(EShowingOptions option);

	/** Sets option of showing points in nodes 
	* @param option Showing option 
	*/
	void setShowPoints(EShowingOptions option);

public slots:
	/** Slot for clicking submit button 
	* @param checked If button is checked
	*/
	void confirmationButtonClicked(bool checked);

	/** Slot for clicking cancel button 
	* @param checked If button is checked
	*/
	void cancelButtonClicked(bool checked);

	/** Informs science tree widget that user settings was changed in a tree */
	void settingsChangedSlot();
signals:
	/** Signal for signaling that state of the tree has changed and should be send to server 
	* @param state State of the science tree
	*/
	void changeScienceTreeStateSignal(sciencetree_raw_data & state);

	/** Signal for signaling request for update of state of science tree */
	void updateScienceTreeStateSignal();
private:
	ScienceTree * tree_;
	Ui_treeWidget * mainWidget_;

	void connectNode(ScienceTree * tree_, NodeWidget * node)
	{
		QObject::connect(
			node,
			SIGNAL(mousePressSignal(NodeWidget*)),
			tree_,
			SLOT(scienceNodeMousePressed(NodeWidget*))
			);
	}

	void connectNodes();
	void buildTree();

	bool isLockedForUpdate_;
	void lockForUpdate(bool lock);
};

#endif