/// Copyright (c) 2010 Ruben Penalva. All rights reserved.
/// Redistribution and use in source and binary forms, with or without modification, 
/// are permitted provided that the following conditions are met:
///    1. Redistributions of source code must retain the above copyright notice, this 
///    list of conditions and the following disclaimer.
///    2. Redistributions in binary form must reproduce the above copyright notice,
///    this list of conditions and the following disclaimer in the documentation and/or
///    other materials provided with the distribution.
///    3. The name of the author may not be used to endorse or promote products derived
///    from this software without specific prior written permission.
///
/// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
/// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
/// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 
/// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
/// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
/// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
/// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
/// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef _SETTINGS_TAB_H_
#define _SETTINGS_TAB_H_

#include "ITab.h"
#include "TestScene.h"

#include <QtGui\QPushButton>
#include <QtCore\QObject>
#include <QtGui\QSpinBox>
#include <QtGui\QSplitter>
#include <QtGui\QGridLayout>
#include <boost\shared_ptr.hpp>
#include "UserEventQueue.h"
#include "ICustomEvent.h"

namespace TaskBasedFlockSim
{


class SettingsTab :
	public QObject, public TestFrameWork::ITab
{
	Q_OBJECT

public:
	SettingsTab(TestFrameWork::UserEventQueue& eventQueue);

	~SettingsTab(void);

	QWidget* GetWidget(void) const;

	void LoadDefaultSceneParameters(const TestFrameWork::ScenePtr scene);

private:
	QWidget* m_widget;
	QGridLayout* m_gridLayout;
	QSpinBox* m_spinBox_flockSize;
	QDoubleSpinBox* m_doubleSpinBox_separationDistance;
	QDoubleSpinBox* m_doubleSpinBox_groupDistance;
	QDoubleSpinBox* m_doubleSpinBox_separationWeight;
	QDoubleSpinBox* m_doubleSpinBox_cohesionWeight;
	QDoubleSpinBox* m_doubleSpinBox_alignmentWeight;
	QDoubleSpinBox* m_doubleSpinBox_maxSpeed;
	QDoubleSpinBox* m_doubleSpinBox_trefoilKnotPathWeight;
	QDoubleSpinBox* m_doubleSpinBox_angleIncrement;
	QSpinBox* m_spinBox_tasksCount;

	TestFrameWork::UserEventQueue& m_eventQueue;

	void SetupWidget(void);

private slots:
	void TasksCountChanged(int i);

	void SizeChange(int val);

	void AngleIncrementChanged(double val);

	void SeparationWeightChanged(double val);

	void CohesionWeightChanged(double val);

	void AlignmentWeightChanged(double val);

	void TrefoildKnotPathWeightChanged(double val);

	void MaxSpeedChanged(double val);

	void SeparationDistanceChanged(double val);

	void GroupDistanceChanged(double val);
};

enum SettingsTabValueId
{
	TasksCount,
	FlockSize,
	AngleIncrement,
	SeparationWeight,
	CohesionWeight,
	AlignmentWeight,
	TrefoilKnotPathWeight,
	MaxSpeed,
	SeparationDistance,
	GroupDistance
};

class ValueChangedEvent :
	public TestFrameWork::ICustomEvent
{
public:
	ValueChangedEvent(float value, 
					  SettingsTabValueId settingsTabValueId)	:	m_value(value),
																	m_settingsTabValueId(settingsTabValueId)
	{
	}

	TestFrameWork::UserEventType GetUserEventType(void) const
	{
		return TestFrameWork::Custom;
	}

	TestFrameWork::CustomEventType GetCustomEventType(void) const
	{
		return TestFrameWork::CustomEventType(m_settingsTabValueId);
	}

	float m_value;
	SettingsTabValueId m_settingsTabValueId;
};

typedef boost::shared_ptr<ValueChangedEvent> ValueChangedEventPtr;
}

#endif