#include "mainWindow.h"
#include "./ui_mainWindow.h"

#include "functionNavigationBar.h"
#include "dvieMainWindow.h"
#include "tccMainWindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    , m_funNavigationBar(nullptr)
    , m_pDvieMainWindow(nullptr)
    , m_pTccMainWindow(nullptr)
{
    ui->setupUi(this);

    initialize();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::initialize()
{
    m_pDvieMainWindow = new DvieMainWindow(this);
    ui->hLayout_DVIE->addWidget(m_pDvieMainWindow);
    m_pTccMainWindow = new TccMainWindow(this);
    ui->hLayout_TCC->addWidget(m_pTccMainWindow);
    ui->stackedWidget->setCurrentIndex(0);

    /*m_funNavigationBar = new FunctionNavigationBar(this);
    connect(m_funNavigationBar, SIGNAL(sgl_funBtnClicke(QString)), this, SLOT(onSignal_funBtnClicked(QString)));
    // QPoint originPoint = mapToGlobal(QPoint(0, 0)); 只有dialog需要做此计算
    int nWidth = m_funNavigationBar->width();
    int nY = (this->height() - m_funNavigationBar->height()) * 0.5;
    m_funNavigationBar->setGeometry(0, nY, nWidth, m_funNavigationBar->height());
    m_funNavigationBar->raise();
    m_funNavigationBar->show();*/
}

bool MainWindow::event(QEvent* event)
{
    //qDebug() << event->type();
    if(event->type() == QEvent::Resize || event->type() == QEvent::Move)
    {
        if(m_funNavigationBar)
        {
            int nY = (this->height() - m_funNavigationBar->height()) * 0.5;
            m_funNavigationBar->setGeometry(0, nY, m_funNavigationBar->width(), m_funNavigationBar->height());
        }
    }

    return QMainWindow::event(event);
}

void MainWindow::onSignal_funBtnClicked(QString strFun)
{
    if(strFun == "DVIE")
        ui->stackedWidget->setCurrentIndex(0);
    else if(strFun == "TCC")
        ui->stackedWidget->setCurrentIndex(1);
}


