#include "right_widget.h"
#include "size_para.h"

RightWidget::RightWidget(QWidget *parent)
    : QWidget(parent)
    , m_mainWin(parent)
{
    if(parent == nullptr)
    {
        return;
    }
    initExhbitionSectorQSS(parent);

    this->setLayout(m_VLayoutExhbition);
}

void RightWidget::initPropertySectorQSS()
{
    m_deviceExhbitionMyWidget = new MainWinPropertyWidget(m_mainWin,this);
    m_deviceExhbitionMyWidget->setObjectName("deviceExhbitionWidget");
    m_deviceExhbitionMyWidget->setFixedSize(DEVICE_PROPERTY_SECTION);

    m_emptyWidget = new EmptyWidget(this);
    m_emptyWidget->setObjectName("emptyWidget");
    m_emptyWidget->setFixedSize(DEVICE_PROPERTY_SECTION);

    m_HLayoutProperty->setMargin(0);
    m_HLayoutProperty->setSpacing(0);
    m_HLayoutProperty->addStretch();
    m_HLayoutProperty->addWidget(m_deviceExhbitionMyWidget);
    m_HLayoutProperty->addWidget(m_emptyWidget);
    m_HLayoutProperty->addStretch();
}

void RightWidget::initExhbitionSectorQSS(QWidget *parent)
{
    if(parent == nullptr)
    {
        return;
    }
    //总体垂直布局
    m_VLayoutExhbition = new QVBoxLayout(this);
    //四联按钮水平
    m_HLayoutQuadsBtn = new QuadBtnsTitleBar(parent);
    m_HLayoutQuadsBtn->setShowBtnsMode(QuadBtnsShowMode::NO_MAX_BTN,parent);
    //属性展示区布局
    m_HLayoutProperty = new QHBoxLayout();

    initPropertySectorQSS();

    m_VLayoutExhbition->setSpacing(0);
    m_VLayoutExhbition->setMargin(0);
    m_VLayoutExhbition->addSpacing(0);
    m_VLayoutExhbition->addWidget(m_HLayoutQuadsBtn);
    m_VLayoutExhbition->addSpacing(4);
    m_VLayoutExhbition->addLayout(m_HLayoutProperty);
    m_VLayoutExhbition->addStretch();


}

void RightWidget::updateExhbitionSector(const UkuiUsbPrinter& printer)
{
    m_deviceExhbitionMyWidget->updateText(printer);
    m_deviceExhbitionMyWidget->show();
    m_emptyWidget->hide();
}

void RightWidget::hideExhbitionSector()
{
    m_emptyWidget->show();
    m_deviceExhbitionMyWidget->hide();
//    this->update();
}

void RightWidget::setQSSFontSize(QFont curFont)
{
    m_deviceExhbitionMyWidget->setQSSFontSize(curFont);
    m_emptyWidget->setQSSFontSize(curFont);
    m_HLayoutQuadsBtn->setQSSFontSize(curFont);
}

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

EmptyWidget::EmptyWidget(QWidget *parent)
{
    QFont ft;
    ft.setPixelSize(14);

    m_first = new QLabel(this);
    // m_first->setText(tr("No Valid Printer,"));
    m_first->setAlignment(Qt::AlignHCenter);
    m_second = new QLabel(this);
    m_second->setText(tr("Please click \"+\" button to add a printer."));
    m_second->setAlignment(Qt::AlignHCenter);
    m_VLayoutExhbition = new QVBoxLayout(this);

    m_VLayoutExhbition->setSpacing(0);
    m_VLayoutExhbition->setMargin(0);
    m_VLayoutExhbition->addSpacing(224);
    m_VLayoutExhbition->addWidget(m_first);
    m_VLayoutExhbition->addSpacing(10);
    m_VLayoutExhbition->addWidget(m_second);
    m_VLayoutExhbition->addStretch();

    this->setLayout(m_VLayoutExhbition);
    this->setBackgroundRole(QPalette::Button);
}
void EmptyWidget::setQSSFontSize(QFont curFont)
{
    //带QSS的控件设置字体ui->xx->setFont(font);
    double tittleFontSize = curFont.pointSizeF()/12*14;
    QFont titleFont = curFont;
    titleFont.setPointSizeF(tittleFontSize);

    m_first->setFont(titleFont);
    m_second->setFont(titleFont);
}

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