#include "dpConfigurationDialog.h"
#include "ui_dpConfigurationDialog.h"
#include "dataPanel.h"

dpConfigurationDialog::dpConfigurationDialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::dpConfigurationDialog)
    , m_curActiveTab(nullptr)
    , m_pDataPanel(nullptr)
{
    ui->setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
    setAttribute(Qt::WA_TranslucentBackground);

    initialize();
}

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

void dpConfigurationDialog::initialize()
{
    ui->tabDataType->setProperty("index", 0);
    connect(ui->tabDataType, SIGNAL(clicked()), this, SLOT(onBtnClicked_tabBtn()));
    ui->tabDataSource->setProperty("index", 1);
    connect(ui->tabDataSource, SIGNAL(clicked()), this, SLOT(onBtnClicked_tabBtn()));
    ui->tabDisplaySetting->setProperty("index", 2);
    connect(ui->tabDisplaySetting, SIGNAL(clicked()), this, SLOT(onBtnClicked_tabBtn()));
    m_curActiveTab = ui->tabDataType;

    ui->stackedWidget->setCurrentIndex(0);

    connect(ui->btnConfirm, SIGNAL(clicked()), this, SLOT(onBtnClicked_confirm()));
    connect(ui->btnCancle, SIGNAL(clicked()), this, SLOT(onBtnClicked_cancle()));
}

void dpConfigurationDialog::setPanel(DataPanel* pPanel)
{
    m_pDataPanel = pPanel;
}

void dpConfigurationDialog::onBtnClicked_tabBtn()
{
    QPushButton* pTab = qobject_cast<QPushButton*>(sender());
    if(pTab == m_curActiveTab)
        return;

    if(m_curActiveTab)
    {
        m_curActiveTab->setStyleSheet("QPushButton\n"
                                      "{\n"
                                      "color: rgb(250, 250, 250);\n"
                                      "font: 700 12pt \"黑体\";\n"
                                      "border:0px;\n"
                                      "background-color:transparent;\n"
                                      "}\n"
                                      "QPushButton:hover\n"
                                      "{\n"
                                      "}\n"
                                      "QPushButton:pressed\n"
                                      "{\n"
                                      "}");
    }
    if(pTab)
    {
        pTab->setStyleSheet("QPushButton\n"
                                      "{\n"
                                      "color: rgb(250, 250, 250);\n"
                                      "font: 700 12pt \"黑体\";\n"
                                      "border:1px solid rgb(200,200,200);\n"
                                      "border-bottom:0px;\n"
                                      "background-color:rgba(36,43,50, 250);\n"
                                      "}\n"
                                      "QPushButton:hover\n"
                                      "{\n"
                                      "}\n"
                                      "QPushButton:pressed\n"
                                      "{\n"
                                      "}");

        int nIndex = pTab->property("index").toInt();
        ui->stackedWidget->setCurrentIndex(nIndex);
    }
    m_curActiveTab = pTab;

}

void dpConfigurationDialog::onBtnClicked_confirm()
{
    hide();
    emit sgl_hide();
}

void dpConfigurationDialog::onBtnClicked_cancle()
{
    hide();
    emit sgl_hide();
}
