#include "MainWindow.h"
#include <QWidget>
#include "OutilModbus.h"

MainWindow::MainWindow(QWidget *parent,COutilModbus* ProgramHandle)
    : QMainWindow(parent),
      mProgramHandle(ProgramHandle)
{
    resize(1024,768);

    mMainPage = new CMainPage(this);
    mMainPage->mProgramHandle = ProgramHandle;

    mSEIModbusPage = new CSEIModbusPage();
    mSEIModbusPage->mProgramHandle = ProgramHandle;

    mModbusPage = new CModbusPage();
    mModbusPage->mProgramHandle = ProgramHandle;

    mZTAlarmGeneratorPage = new CZTAlarmGeneratorPage();
    //mZTAlarmGeneratorPage->mProgramHandle = ProgramHandle;

    mHistorianPage = new CHistorianPage;


    mLazerSimPage = new CLazerProbeSimPage;

    setCentralWidget(mMainPage);


    mMainPage->RegisterPagesTabs(mModbusPage,mLazerSimPage, mSEIModbusPage, mZTAlarmGeneratorPage,mHistorianPage);

  //  setWindowFlags(Qt::WindowStaysOnTopHint);

//    QHBoxLayout *MainLayout = new QHBoxLayout;
//    QWidget *test = new QWidget();
//    mCCGridLayout = new QGridLayout();
//    mSEIGridLayout = new QGridLayout();
//    test->setLayout(MainLayout);
//    setCentralWidget(test);

//    test->resize(200,200);
//    MainLayout->addLayout(mCCGridLayout);
//    MainLayout->addLayout(mSEIGridLayout);




//    mConnectToSlaveBtn = new QPushButton("Connect to slave");
//    connect(mConnectToSlaveBtn,SIGNAL(clicked()),this,SLOT(ButtonPushed()));
//    mSendWriteMultipleHR = new QPushButton("Write Multiple HR");
//    connect(mSendWriteMultipleHR,SIGNAL(clicked()),this,SLOT(ButtonPushed()));
//    mSendReadHR = new QPushButton("Read HR");
//    connect(mSendReadHR,SIGNAL(clicked()),this,SLOT(ButtonPushed()));
//    mWriteSingleHR = new QPushButton("Write Single HR");
//    connect(mWriteSingleHR,SIGNAL(clicked()),this,SLOT(ButtonPushed()));

//    mAlarmePPIZT1 = new QLabel("Alarme PP Int. ZT1");
//    mAlarmePPEZT1 = new QLabel("Alarem PP Ext. ZT1");
//    mAlarmePG = new QLabel("Alarme PG ZT1");
//    mAlarmeFN = new QLabel("Alarme FN");
//    mAlarmePEQ1 = new QLabel("PEQ1");
//    mAlarmePEQ2 = new QLabel("PEQ2");
//    mAlarmePPIZT2 = new QLabel("Alarme PP Int. ZT2");
//    mAlarmePPEZT2 = new QLabel("Alarme PP Ext. ZT2");
//    mITI = new QLabel("Itinéraire: 10/12");
//    mRankPPZT1 = new QLabel("Rang PP ZT1: 0");
//    mRankPG = new QLabel("Rang PG ZT1: 0");
//    mRankPPZT2 = new QLabel("Rang PP ZT2: 0");

//    mCCEventsList = new QTextEdit;
//    mCCEventsList->setText("");
//    mCCGridLayout->addWidget(mCCEventsList,20,0,10,30);

//    mSEIEventsList = new QTextEdit;
//    mSEIEventsList->setText("TEST\nTest\nTEST\na;sdlfjkasl;fjasl;dkfjasl;dfjsdj\ntest");
//    mSEIEventsList->resize(200,60);
//    mSEIGridLayout->addWidget(mSEIEventsList,0,20,10,30);

//    mCCGridLayout->addWidget(mConnectToSlaveBtn,0,0);
//    mCCGridLayout->addWidget(mSendWriteMultipleHR,0,1);
//    mCCGridLayout->addWidget(mSendReadHR,0,2);
//    mCCGridLayout->addWidget(mWriteSingleHR,0,3);

//    mCCGridLayout->addWidget(mAlarmePPIZT1,5,0);
//    mCCGridLayout->addWidget(mAlarmePPEZT1,5,1);
//    mCCGridLayout->addWidget(mAlarmePG,5,2);
//    mCCGridLayout->addWidget(mAlarmeFN,5,3);
//    mCCGridLayout->addWidget(mAlarmePEQ1,6,0);
//    mCCGridLayout->addWidget(mAlarmePEQ2,6,1);
//    mCCGridLayout->addWidget(mAlarmePPIZT2,6,2);
//    mCCGridLayout->addWidget(mAlarmePPEZT2,6,3);
//    mCCGridLayout->addWidget(mITI,7,0);
//    mCCGridLayout->addWidget(mRankPPZT1,8,0);
//    mCCGridLayout->addWidget(mRankPG,9,0,1,1,Qt::AlignLeft);
//    mCCGridLayout->addWidget(mRankPPZT2,10,0,1,1,Qt::AlignLeft);


}

MainWindow::~MainWindow()
{
    delete mMainPage;
    delete mSEIModbusPage;
    delete mZTAlarmGeneratorPage;
    delete mLazerSimPage;
}

void MainWindow::ButtonPushed()
{


//    QObject *Btn = QObject::sender();

//    qDebug("Button clicked:");

//    if(Btn == mConnectToSlaveBtn)
//    {
//        qDebug("Button clicked: mConnectToSlaveBtn");
//    }
//    else if(Btn == mSendWriteMultipleHR)
//    {
//        qDebug("Button clicked: mSendWriteMultipleHR");
//    }
//    else if(Btn == mSendReadHR)
//    {
//        qDebug("Button clicked: mSendReadHR");
//    }
//    else if(Btn == mWriteSingleHR)
//    {
//        qDebug("Button clicked: mWriteSingleHR");
//    }


}
