/*******************************************************************************
*                                                                              *
* Société de Transports de Montréal.                                    	   *
* 2012                                                                         *
*                                                                              *
* Projet Zones Tests                                                           *
*                                                                              *
*                                                                              *
*                                                                              *
*******************************************************************************/
/*
    Description:
    Classe qui crée la scène ainsi que les instances des différents objets
    nécessaires à l'affichage.

*/

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

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

/* ************************************************************************** */
#include "MainPanel.h"
#include <QPushButton>
#include <QGraphicsProxyWidget>
#include <QPixmap>

#include <stdio.h>
#include <QtGui>
#include <QColor>
#include "Zonetest.h"

#include "ZTconfigmgr.h"


//#include <QtPlugin>
//#ifndef Q_OS_WIN32
//Q_IMPORT_PLUGIN(qjpeg)
//#endif

Panel::~Panel()
{
    //if(scene)
        //delete scene;
//	delete mWelcomePage;
//	delete mZTMainPage;

}

Panel::Panel()
{

    scene = 0;
	mProgramHandle = 0;

   //No Scrollbar
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);


    //Speed-up display
    setCacheMode(CacheBackground);
	setRenderHints(/*QPainter::Antialiasing | */QPainter::SmoothPixmapTransform/* | QPainter::TextAntialiasing*/);
    setViewportUpdateMode(QGraphicsView::SmartViewportUpdate/*QGraphicsView::FullViewportUpdate*/);

//	QPixmap background;
//    background.load("./Images/GuiBackground.jpg");
//    background = background.scaled(SCREEN_RES_WIDTH,SCREEN_RES_HEIGHT);


	QLinearGradient BackgroundGradient(QPointF(rect().width()/2,0),QPointF(rect().width()/2,rect().height()));
	BackgroundGradient.setColorAt(0.5,QColor(128,158,222));
	BackgroundGradient.setColorAt(1,Qt::white);
	QBrush BkBrush(BackgroundGradient);
    setBackgroundBrush(BkBrush);

   // QRectF bounds(0,0, QApplication::desktop()->geometry().width(),QApplication::desktop()->geometry().height());
    QRectF bounds(0,0, SCREEN_RES_WIDTH,SCREEN_RES_HEIGHT);
    scene = new QGraphicsScene(bounds, this);
    setScene(scene);

    //resize(QApplication::desktop()->geometry().width(),QApplication::desktop()->geometry().height());

    resize(SCREEN_RES_WIDTH,SCREEN_RES_HEIGHT);
    ////////////////////////

	setMouseTracking(true);

    mWelcomePage = new CWelcomePage();
	mZTMainPage = new CZTPage();
	mOptionsPage = new COptionsPage();
	mFunctionSelectPage = new CFunctionSelectionPage();
	mLogsListPage = new CLogsListPage();
	mLogViewPage = new CLogViewPage();
	mEngineeringPage = new CEngineeringPage();
    mMaintenancePage = new CMaintenancePage();
	mGeneralSettingsPage = new CGeneralSettingsPage();
	mZTLogViewerPage = new CZTLogViewerPage();
    mModbusSettingsPage = new CModbusSettingsPage();
    mSEISettingsPage = new CSEISettingsPage();
    mModbusDisplayPage = new CModbusDisplayPage();
    mHistorienDisplayPage = new CHistorienDisplayPage();

    scene->addItem(mWelcomePage);
	scene->addItem(mZTMainPage);
	scene->addItem(mOptionsPage);
	scene->addItem(mFunctionSelectPage);
	scene->addItem(mLogsListPage);
	scene->addItem(mLogViewPage);
	scene->addItem(mEngineeringPage);
    scene->addItem(mMaintenancePage);
	scene->addItem(mGeneralSettingsPage);
    scene->addItem(mModbusSettingsPage);
    scene->addItem(mSEISettingsPage);
	scene->addItem(mZTLogViewerPage);
    scene->addItem(mModbusDisplayPage);
    scene->addItem(mHistorienDisplayPage);

	mZTMainPage->setPos(0,0);
	mZTMainPage->hide();
	mZTMainPage->setZValue(0);
    scene->addItem(mZTMainPage->mExitPasswordPrompt);

	mWelcomePage->setPos(0,0);
    mWelcomePage->show();
	mWelcomePage->setZValue(1);

	mOptionsPage->setPos(312,100);
	mOptionsPage->hide();
	mOptionsPage->resize(400,400);
	mOptionsPage->setZValue(1);

	mFunctionSelectPage->setPos(212,184);
	mFunctionSelectPage->hide();
	mFunctionSelectPage->resize(600,400);
	mFunctionSelectPage->setZValue(1);

	mLogsListPage->setPos(62,84);
	mLogsListPage->hide();
	mLogsListPage->resize(900,600);
	mLogsListPage->setZValue(1);

    mLogViewPage->setPos(0,0);
    mLogViewPage->resize(1024,768);
	mLogViewPage->setZValue(1);
	mLogViewPage->hide();

	mEngineeringPage->setPos(10,10);
	mEngineeringPage->resize(SCREEN_RES_WIDTH-20,SCREEN_RES_HEIGHT-20);
	mEngineeringPage->setZValue(1);
	mEngineeringPage->hide();
	scene->addItem(mEngineeringPage->mPasswordPrompt);

    mMaintenancePage->setPos(112,84);
    mMaintenancePage->hide();
    mMaintenancePage->resize(800,600);
    mMaintenancePage->setZValue(1);

	mGeneralSettingsPage->setPos(112,84);
	mGeneralSettingsPage->hide();
	mGeneralSettingsPage->resize(800,600);
	mGeneralSettingsPage->setZValue(1);

    mModbusSettingsPage->setPos(112,84);
    mModbusSettingsPage->hide();
    mModbusSettingsPage->resize(800,600);
    mModbusSettingsPage->setZValue(1);

    mSEISettingsPage->setPos(112,84);
    mSEISettingsPage->hide();
    mSEISettingsPage->resize(800,600);
    mSEISettingsPage->setZValue(1);

	mZTLogViewerPage->setPos(112,84);
	mZTLogViewerPage->hide();
	mZTLogViewerPage->resize(800,600);
	mZTLogViewerPage->setZValue(1);

    mModbusDisplayPage->setPos(10,10);
    mModbusDisplayPage->resize(SCREEN_RES_WIDTH-20,SCREEN_RES_HEIGHT-20);
    mModbusDisplayPage->setZValue(1);
    mModbusDisplayPage->hide();

    mHistorienDisplayPage->setPos(10,10);
    mHistorienDisplayPage->resize(SCREEN_RES_WIDTH-20,SCREEN_RES_HEIGHT-20);
    mHistorienDisplayPage->setZValue(1);
    mHistorienDisplayPage->hide();



	installEventFilter(mLogViewPage);

}

void Panel::HideWelcomePage()
{
	mWelcomePage->hide();
}

void Panel::ShowMainPage()
{
	mZTMainPage->show();
}

void Panel::HideMainPAge()
{
	mZTMainPage->hide();
}

//void Panel::mousePressEvent(QGraphicsSceneMouseEvent *event)
//{
//}

void Panel::closeEvent(QCloseEvent *event)
{
	Q_UNUSED(event)
    mProgramHandle->ApplicationQuit(EXIT_REASON_USER_REQUEST);
}

