#include "cameraparam.h"
#include "awidget.h"
#include "bwidget.h"
#include "cstackedwidget.h"
#include "ctextedit.h"

#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QToolButton>
#include <QStackedWidget>
#include <QFrame>
#include <QSplitter>


CameraParam::CameraParam(QWidget *parent)
    : QWidget(parent)
{
    initUI();
    createConnections();
}

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

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

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

void CameraParam::initUI()
{
    mMainVLayout = new QVBoxLayout;
    //    mMainVLayout->setSpacing(0);
    //    mMainVLayout->setMargin(0);
    mMainVLayout->setContentsMargins(0, 0, 0, 0);

    mTopWidget = new QWidget;
    mTopWidget->setObjectName("CameraDisplayTopWidget");
    mTopWidget->setFixedHeight(32);
    mTopHLayout = new QHBoxLayout;
    mTopHLayout->setContentsMargins(0, 0, 0, 0);
    mTopHLayout->setSpacing(0);
    //    mIndexLabel = new QLabel;
    //    mIndexLabel->setObjectName("CameraDisplayIndexLabel");
    //    mIndexLabel->setFixedSize(50, 40);
    //    mIndexLabel->setAlignment(Qt::AlignCenter);
    mIndexButton = new QToolButton;
    mIndexButton->setFixedSize(50, 32);
    mIndexButton->setObjectName("CameraDisplayIndexButton");

    mTitleLabel = new QLabel;    
    mTitleLabel->setObjectName("CameraDisplayTitleLabel");
    mTitleLabel->setAlignment(Qt::AlignCenter);
    mTitleLabel->setFixedSize(50, 32);
    mStateLabel = new QLabel;
    mStateLabel->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    mStateLabel->setObjectName("CameraDisplayStateLabel");
    mStateLabel->setAlignment(Qt::AlignCenter);
    mStateLabel->setFixedHeight(32);

    mExtendButton = new QToolButton;
    mExtendButton->setText("参数");
    mExtendButton->setObjectName("CameraParamExtendButton");
    mExtendButton->setFixedSize(50, 32);

    mTopHLayout->addWidget(mIndexButton);
    mTopHLayout->addWidget(mStateLabel);
    mTopHLayout->addWidget(mTitleLabel);
    mTopHLayout->addWidget(mExtendButton);
    mTopWidget->setLayout(mTopHLayout);

    mSplitter = new QSplitter;
    mSplitter->setOrientation(Qt::Vertical);


    mStackedWidget = new CStackedWidget;
    mAWidget = new AWidget;
    mBWidget = new BWidget;
    mStackedWidget->addWidget(mAWidget);
    mStackedWidget->addWidget(mBWidget);

    mLogTextEdit = new CTextEdit;
    mLogTextEdit->setObjectName("MainWindowLogTextEdit");
    QString logStr = "001 2023/03/21 10:53:31.478 十月的雨，总会让人不自觉地悲伤起来，正值秋天，本就是悲伤，\n"
                     "002 2023/03/21 10:53:45.142 更何况是下着毛毛细雨呢？我敬佩刘禹锡，他豁达乐观，即使在秋天，也能吟上一句“自古逢秋悲寂寥，\n"
                     "003 2023/03/21 10:53:49.342 我言秋日胜春朝。晴空一鹤排云上，便引诗情到碧霄”而我就只能在秋天独自忧愁，独自忧伤，独自怀念。\n"
                     "004 2023/03/21 10:53:52.254 人是群居动物，总会感到些许寂寞，即便是习惯了寂寞的人也是。我不怕寂寞，却也怕在人群中明明是笑着的，\n"
                     "005 2023/03/21 10:53:56.531 内心却还是寂寞，这种寂寞是最可怕的。\n";
    mLogTextEdit->append(logStr);

    mSplitter->addWidget(mStackedWidget);
    mSplitter->addWidget(mLogTextEdit);
    mSplitter->setStretchFactor(0, 6);
    mSplitter->setStretchFactor(1, 2);

    mMainVLayout->addWidget(mTopWidget);
//    mMainVLayout->addWidget(mStackedWidget);
    mMainVLayout->addWidget(mSplitter);


    this->setLayout(mMainVLayout);
}

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

    connect(mExtendButton, &QToolButton::clicked, mAWidget, &AWidget::showHideParam);
}



