#include "cameradisplay.h"
#include "ui_cameradisplay.h"

#include <QStyleOption>
#include <QPainter>

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

    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->setDirection(QBoxLayout::TopToBottom);
    ui->mMainVLayout->setSpacing(0);
    ui->mMainVLayout->setMargin(0);
    ui->mMainVLayout->setContentsMargins(0, 0, 0, 0);

    ui->mTopWidget = new QWidget;
    ui->mTopWidget->setObjectName("CameraDisplayTopWidget");
    ui->mTopWidget->setFixedHeight(32);
    ui->mTopWidget->setStyleSheet("border: 10px solid red;");

    ui->mTopHLayout->setContentsMargins(0, 0, 0, 0);
    ui->mTopHLayout->setMargin(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->setObjectName("CameraDisplayStateLabel");
    ui->mStateLabel->setAlignment(Qt::AlignCenter);
    ui->mStateLabel->setFixedHeight(32);

    ui->mMainVLayout->setStretch(0, 1);
    ui->mMainVLayout->setStretch(1, 100);

    ui->mMainVLayout->addStretch();

    ui->axWidget->setControl("148BD520-A2AB-11CE-B11F-00AA00530503");
}

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

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

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

void CameraDisplay::setState(CameraState state)
{
    if(state == CameraState::NG)
    {
        ui->mStateLabel->setText("NG");
    }
    else if(state == CameraState::OK)
    {
        ui->mStateLabel->setText("OK");
    }
    else
    {
        ui->mStateLabel->setText("UNKNOW");
    }

}

void CameraDisplay::setContent(const QString &content)
{

}

void CameraDisplay::paintEvent(QPaintEvent *e)
{
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
