#include "cameraparam.h"
#include "ui_cameraparam.h"
#include "global.h"

CameraParam::CameraParam(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::CameraParam)
{
    ui->setupUi(this);

    initUI();
    createConnections();
}

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

void CameraParam::setIndex(const QString &index)
{
    ui->mIndexButton->setText(index);
}

void CameraParam::setTitle(const QString &title)
{
    ui->mTitleLabel->setText(title);
}

void CameraParam::setState(const QString &state)
{
    ui->mStateLabel->setText(state);
}

void CameraParam::initUI()
{
    ui->horizontalLayout_3->setSpacing(0);
    ui->horizontalLayout_3->setMargin(0);
    ui->horizontalLayout_3->setContentsMargins(0, 0, 0, 0);

    ui->horizontalLayout_2->setSpacing(0);
    ui->horizontalLayout_2->setMargin(0);
    ui->horizontalLayout_2->setContentsMargins(0, 0, 0, 0);

    ui->mMainVLayout = new QVBoxLayout;
    ui->mMainVLayout->setSpacing(0);
    ui->mMainVLayout->setMargin(0);
    ui->mMainVLayout->setContentsMargins(0, 0, 0, 0);

    ui->mTopWidget->setObjectName("CameraDisplayTopWidget");
    ui->mTopWidget->setFixedHeight(32);

    ui->mTopHLayout->setContentsMargins(0, 0, 0, 0);
    ui->mTopHLayout->setSpacing(0);

    ui->mIndexButton->setFixedSize(50, 32);
    ui->mIndexButton->setObjectName("CameraDisplayIndexButton");

    ui->mTitleLabel->setObjectName("CameraDisplayTitleLabel");
    ui->mTitleLabel->setAlignment(Qt::AlignCenter);
    ui->mTitleLabel->setFixedSize(50, 32);

    ui->mStateLabel->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    ui->mStateLabel->setObjectName("CameraDisplayStateLabel");
    ui->mStateLabel->setAlignment(Qt::AlignCenter);
    ui->mStateLabel->setFixedHeight(32);

    ui->mExtendButton->setText("参数");
    ui->mExtendButton->setObjectName("CameraParamExtendButton");
    ui->mExtendButton->setFixedSize(50, 32);
}

void CameraParam::createConnections()
{
    connect(ui->mIndexButton, &QToolButton::clicked, this, [=](){
        if(ui->mStackedWidget->currentIndex() == 0)
        {
            ui->mStackedWidget->setCurrentIndex(1);
        }
        else
        {
            ui->mStackedWidget->setCurrentIndex(0);
        }
        emit Global::Instance()->refresh();
    });

    connect(ui->mExtendButton, &QToolButton::clicked, ui->mAWidget, &AWidget::showHideParam);
    connect(ui->mExtendButton, &QToolButton::clicked, Global::Instance(), &Global::refresh);
}
