/*******************************************************************************
*                                                                              *
* 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 <QtPlugin>
//#ifndef Q_OS_WIN32
//Q_IMPORT_PLUGIN(qjpeg)
//#endif

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

}

Panel::Panel()
{

    scene = 0;
//    setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
//   //     setParent(0); // Create TopLevel-Widget
//        setAttribute(Qt::WA_NoSystemBackground, true);
//        setAttribute(Qt::WA_TranslucentBackground, true);
//        setAttribute(Qt::WA_PaintOnScreen); // not needed in Qt 5.2 and up

   //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);

    const static int LogViewPageWidth(950);

    mMainPage = new CMainPage();
    mDatabaseModeLogViewPage = new CLogViewPage(LogViewPageWidth);
    mDatabaseModeLogListPage = new CLogsListPage();
    mOptionsPage = new COptionsPage();
    mNetworkZTListPage = new CNetworkZTListPage();
    mNetworkCtrlPage = new CNetworkCtrlPage();
    mRemoteZTPage = new CRemoteZTPage();
    mZTLogViewerPage = new CZTLogViewerPage(0,false);
    mNetworkModeLogListPage = new CLogsListPage();
    mNetworkModeLogViewPage = new CLogViewPage(LogViewPageWidth);
    mProgressBarPage = new CProgressBarPage();
    mRemoteZTCtrlPage = new CRemoteZTCtrlPage();
    mDatabaseMgrPage = new CDatabaseMgrPage();
    mZTLogsListPage = new CZTLogsListPage();
    mZTLogFileViewerPage = new CZTLogViewerPage(0,true);


    scene->addItem(mMainPage);
    scene->addItem(mDatabaseModeLogViewPage);
    scene->addItem(mDatabaseModeLogListPage);
    scene->addItem(mOptionsPage);
    scene->addItem(mNetworkZTListPage);
    scene->addItem(mNetworkCtrlPage);
    scene->addItem(mRemoteZTPage);
    scene->addItem(mZTLogViewerPage);
    scene->addItem(mNetworkModeLogListPage);
    scene->addItem(mNetworkModeLogViewPage);
    scene->addItem(mProgressBarPage);
    scene->addItem(mRemoteZTCtrlPage);
    scene->addItem(mDatabaseMgrPage);
    scene->addItem(mZTLogsListPage);
    scene->addItem(mZTLogFileViewerPage);


    mMainPage->setPos(0,0);
    mMainPage->show();
    mMainPage->setZValue(0);
    mMainPage->resize(10,SCREEN_RES_HEIGHT);


    mDatabaseModeLogViewPage->setPos(SCREEN_RES_WIDTH-LogViewPageWidth,0);
    mDatabaseModeLogViewPage->resize(LogViewPageWidth/*980*/,SCREEN_RES_HEIGHT);
    mDatabaseModeLogViewPage->setZValue(0);
    mDatabaseModeLogViewPage->DisableCloseButton();
    mDatabaseModeLogViewPage->show();

    mDatabaseModeLogListPage->setPos(45,0);
    mDatabaseModeLogListPage->resize(400,SCREEN_RES_HEIGHT-100);
    mDatabaseModeLogListPage->setZValue(1);
    mDatabaseModeLogListPage->show();

    mZTLogsListPage->setPos(100,0);
    mZTLogsListPage->resize(SCREEN_RES_WIDTH,SCREEN_RES_HEIGHT);
    mZTLogsListPage->setZValue(0);
    mZTLogsListPage->hide();

    mZTLogFileViewerPage->resize(980,700);
    mZTLogFileViewerPage->setPos(600,10);
    mZTLogFileViewerPage->hide();
    mZTLogFileViewerPage->setZValue(0);

    mOptionsPage->setPos(412,100);
    mOptionsPage->hide();
    mOptionsPage->resize(600,600);
    mOptionsPage->setZValue(1);

    mDatabaseMgrPage->setPos(412,100);
    mDatabaseMgrPage->hide();
    mDatabaseMgrPage->resize(800,400);
    mDatabaseMgrPage->setZValue(1);

    mNetworkZTListPage->setPos(100,0);
    mNetworkZTListPage->setZValue(0);
    mNetworkZTListPage->hide();

    mNetworkCtrlPage->setPos(100,325);
    mNetworkCtrlPage->resize(150,150);
    mNetworkCtrlPage->setZValue(0);
    mNetworkCtrlPage->hide();

    mRemoteZTPage->setPos(450,0);
    mRemoteZTPage->resize(SCREEN_RES_WIDTH-450,SCREEN_RES_HEIGHT);
    mRemoteZTPage->setZValue(0);
    mRemoteZTPage->hide();

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

    mNetworkModeLogListPage->setPos(1000,0);
    mNetworkModeLogListPage->resize(400,SCREEN_RES_HEIGHT-100);
    mNetworkModeLogListPage->setZValue(1);
    mNetworkModeLogListPage->show();

    mNetworkModeLogViewPage->setPos(SCREEN_RES_WIDTH-980,0);
    mNetworkModeLogViewPage->resize(980,SCREEN_RES_HEIGHT);
    mNetworkModeLogViewPage->setZValue(1);
    mNetworkModeLogViewPage->EnableCloseButton();
    mNetworkModeLogViewPage->hide();

    mRemoteZTCtrlPage->setPos(1000,0);
    mRemoteZTCtrlPage->resize(400,SCREEN_RES_HEIGHT-100);
    mRemoteZTCtrlPage->hide();
    mRemoteZTCtrlPage->setZValue(0);





    mProgressBarPage->setPos(500,300);
//    mProgressBarPage->resize(400,300);
    mProgressBarPage->setZValue(2);
    mProgressBarPage->hide();

    installEventFilter(mDatabaseModeLogViewPage);
}

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

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

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


