#ifndef QT_COMPOSITE_WIDGET
#define QT_COMPOSITE_WIDGET

#include <qwidget.h>
#include <qobject.h>
#include <qframe.h>
#include <exception>
#include <map>
#include <vector>

#include "ScienceNode.h"
#include "ui_ScienceTreeWidget.h"

/** Widget for viewing details of one leaf, ie its parameters */
class ListDetailsViewWidget : public QWidget
{
	Q_OBJECT
signals:
	void settingsChangedSignal();
public:
	/** One row of details view with name, percents and points of parameter */
	class CompositeItemsRow
	{
	public:
		/** Label for name of parameter */
		QLabel nameLabel;		

		/** Spinbox for assigned percents to parameter */
		QSpinBox percentsBox;

		/** Label for created points for parameter */
		QLabel pointsLabel;

		/** Assigned parameter */
		CompositeItem * item_;

		/** Constructor 
		* @param style Stylesheet for row components
		*/
		CompositeItemsRow(QString & style);

		/** Hides row with all its components */
		void hide();

		/** Checks if row is visible */
		bool isVisible();

		/** Shows rows with all its components */
		void show();

		/** Sets maximum of spinbox component calculated from given free percents
		* @param freePercents Free percents of parent leaf used for calculation 
		*/
		void adjustMaximum(int freePercents);

		/** Sets widget components with given item and free percents of parent leaf 
		* @param item Composite item, that this row represents
		* @param freePercents Free percents of parent leaf
		*/
		void setup(CompositeItem * item, int freePercents);

		/** Clears row and its components, removes reference to item and disconnect signals */
		void setupBack();
	private:
		/** If row is visible */
		bool m_isVisible;
	};

	/** Constructor 
	* @param layout Layout for displaing this widget
	* @param maxRows Max count of rows with items in widget
	*/
	ListDetailsViewWidget(QGridLayout * layout, int maxRows);

	/** Destructor */
	~ListDetailsViewWidget();

	/** Setup one row with given item 
	* @param item Composite item, that setted row will represent
	* @param index Index of row to set, starting from 0
	*/
	void setupRow(CompositeItem * item, int index);

	/** Clears row and its components, removes reference to item and disconnect signals 
	* @param index Index of row to clear, starting from 0 
	*/
	void setupRowBack(int index);

	/** Hides all rows with index higher than given index
	* @index Starting startIndex of first row to hide
	*/
	void hideAllRowsFrom(int startIndex);

	/** Hides entire widget */
	virtual void hide();

	/** Shows content of widget */
	virtual void showContent();

	/** Sets value representing free percents of parent leaf */
	void setFreePercents(int value);
private:
	int freePercents_;
	int itemsRowsCount_;
	QGridLayout * layout_;
	CompositeItemsRow ** itemsRows_;	
};

#endif