/*******************************************************************************
*                                                                              *
* Société de Transports de Montréal.                                    	   *
* 2012                                                                         *
*                                                                              *
* Projet Zones Tests                                                           *
*                                                                              *
*                                                                              *
*                                                                              *
*******************************************************************************/
/*
    Description:
	Page de sélection des options (sélection des fonctions de détection, ingénierie,
	mode entretien, etc.).

*/

/* ************************************************************************** */
/* Revision:
### 20131021 JFM
    Verision d'origine.

### YYYMMDD Description du besoin ou du bug
    Description du changement.
 */

/* ************************************************************************** */


#include "OptionsPage.h"
#include <QPainter>
#include "GlobalDefine.h"
#include <QDialog>
#include <QMainWindow>
#include "Zonetest.h"
#include <QDateTime>
#include <QFont>



COptionsPage::COptionsPage(QGraphicsWidget *Parent)
{
	Q_UNUSED(Parent)

	mProgramHandle = 0;
	mZTSimulatorPtr = 0;



	mBackgroundRect = new QGraphicsRectItem(boundingRect(), this);
	QBrush BackgroundBrush(QColor(245, 245, 255));
	mBackgroundRect->setBrush(BackgroundBrush);

	QGraphicsTextItem *Title = new QGraphicsTextItem("Choisissez une option",this);
	QFont font;
	font.setPointSize(18);
	Title->setFont(font);
	Title->setPos(40,10);

	mZTFunctionsButton = new CTextButtonWidget("Fonctions Détection");
	mZTFunctionsButton->setParentItem(this);
	mZTFunctionsButton->setPos(50,60);
	connect(mZTFunctionsButton,SIGNAL(TxtButtonClicked(CTextButtonWidget*)),this,SLOT(ButtonClicked(CTextButtonWidget*)));

	mZTMaintenanceModeButton = new CTextButtonWidget("Mode entretien");
	mZTMaintenanceModeButton->setParentItem(this);
	mZTMaintenanceModeButton->setPos(50,100);
	connect(mZTMaintenanceModeButton,SIGNAL(TxtButtonClicked(CTextButtonWidget*)),this,SLOT(ButtonClicked(CTextButtonWidget*)));

	mZTEngineeringButton = new CTextButtonWidget("Ingénierie");
	mZTEngineeringButton->setParentItem(this);
	mZTEngineeringButton->setPos(50,140);
	connect(mZTEngineeringButton,SIGNAL(TxtButtonClicked(CTextButtonWidget*)),this,SLOT(ButtonClicked(CTextButtonWidget*)));

	mZTGeneralSettingsButton = new CTextButtonWidget("Paramètres");
	mZTGeneralSettingsButton->setParentItem(this);
	mZTGeneralSettingsButton->setPos(50,180);
	connect(mZTGeneralSettingsButton,SIGNAL(TxtButtonClicked(CTextButtonWidget*)),this,SLOT(ButtonClicked(CTextButtonWidget*)));

    mModbusSettingsButton = new CTextButtonWidget("Modbus PCC");
    mModbusSettingsButton->setParentItem(this);
    mModbusSettingsButton->setPos(50,220);
    connect(mModbusSettingsButton,SIGNAL(TxtButtonClicked(CTextButtonWidget*)),this,SLOT(ButtonClicked(CTextButtonWidget*)));

    mSEIModbusSettingsButton = new CTextButtonWidget("SEI");
    mSEIModbusSettingsButton->setParentItem(this);
    mSEIModbusSettingsButton->setPos(50,260);
    connect(mSEIModbusSettingsButton,SIGNAL(TxtButtonClicked(CTextButtonWidget*)),this,SLOT(ButtonClicked(CTextButtonWidget*)));

	mZTLogViewButton = new CTextButtonWidget("Fichier LOG");
	mZTLogViewButton->setParentItem(this);
    mZTLogViewButton->setPos(50,300);
	connect(mZTLogViewButton,SIGNAL(TxtButtonClicked(CTextButtonWidget*)),this,SLOT(ButtonClicked(CTextButtonWidget*)));

    mCancelButton = new CTextButtonWidget("Fermer");
	mCancelButton->setParentItem(this);
    mCancelButton->setPos(300,340);
	connect(mCancelButton,SIGNAL(TxtButtonClicked(CTextButtonWidget*)),this,SLOT(ButtonClicked(CTextButtonWidget*)));

}

void COptionsPage::resizeEvent(QGraphicsSceneResizeEvent *event)
{
	Q_UNUSED(event)
	mBackgroundRect->setRect(boundingRect());
}

void COptionsPage::ButtonClicked(CTextButtonWidget *BtnPtr)
{
	if(BtnPtr == mZTFunctionsButton)
	{
		mProgramHandle->ZTFunctionsOptionSelected();

	}
	else if(BtnPtr == mZTMaintenanceModeButton)
	{
		mProgramHandle->ZTMaintenanceOptionSeleced();
	}
	else if(BtnPtr == mCancelButton)
	{
		hide();
	}
	else if(BtnPtr == mZTEngineeringButton)
	{
		mProgramHandle->OpenEngineeringPageRequest();
	}
	else if(BtnPtr == mZTGeneralSettingsButton)
	{
		mProgramHandle->OpenGeneralSettingsPage();
	}
    else if(BtnPtr == mModbusSettingsButton)
    {
        mProgramHandle->OpenModbusSettingsPage();
    }
    else if(BtnPtr == mSEIModbusSettingsButton)
    {
        mProgramHandle->OpenSEISettingsPage();
    }
    else if(BtnPtr == mZTLogViewButton)
	{
		mProgramHandle->ShowZTLogViewerPage();
	}
}

//Grab the mouse if the user clicks outside buttons
void COptionsPage::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
	Q_UNUSED(event)
}
void COptionsPage::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
	Q_UNUSED(event)
}
