#include "blankpage.h"
#include "global/utils/global_data.h"
/* 适配 kySDK  */
#include <gsettingmonitor.h>

BlankPage::BlankPage(QWidget *parent) : QWidget(parent)
{
    init();
    initGsetting();
}

BlankPage::~BlankPage() {}

void BlankPage::init()
{
    this->setMinimumSize(QSize(350, 506));
    this->setAttribute(Qt::WA_StyledBackground, true);
//    this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    //    this->setStyleSheet("background-color:#FFFFFF");
    m_blankLabel = new QLabel();
    QIcon blankIcon = QIcon(":/res/kylin-ipmsg.svg");
    m_blankLabel->setPixmap(blankIcon.pixmap(blankIcon.actualSize(QSize(96, 96))));
    m_blankTextLabel = new QLabel();
    m_blankTextLabel->setText(tr("No Information"));

    // 空白页面布局
    m_hBlankLayout = new QHBoxLayout();
    m_vBlankLayout = new QVBoxLayout();

    m_hBlankLayout->addStretch();
    m_hBlankLayout->addWidget(m_blankLabel);
    m_hBlankLayout->addStretch();

    m_vBlankLayout->addSpacing(160);
    m_vBlankLayout->addLayout(m_hBlankLayout);
    m_vBlankLayout->setSpacing(8);
    m_vBlankLayout->addWidget(m_blankTextLabel);
    m_blankTextLabel->setAlignment(Qt::AlignHCenter);
    m_vBlankLayout->addStretch();

    this->setLayout(m_vBlankLayout);
}

void BlankPage::initGsetting()
{
    // 主题颜色
    this->connect(kdk::GsettingMonitor::getInstance(), &kdk::GsettingMonitor::systemThemeChange, this, [=]() {
        GlobalData::getInstance()->getSystemTheme();
        changeTheme();
    });
}

void BlankPage::changeTheme()
{
    if (GlobalSizeData::THEME_COLOR == GlobalSizeData::UKUILight) {
        this->setStyleSheet("background-color:#FFFFFF");
        m_blankTextLabel->setStyleSheet("font-size: 14px; color:#8C8C8C; opacity: 1;");
    } else {
        this->setStyleSheet("background-color:#1d1d1d");
        m_blankTextLabel->setStyleSheet("font-size: 14px; color:#8F9399; opacity: 1;");
        }
    if (searchblank == 1) {
        if (GlobalSizeData::THEME_COLOR == GlobalSizeData::UKUILight) {
            QIcon SearchIcon1 = QIcon(":/res/Search-web-light.svg");
            m_blankLabel->setPixmap(SearchIcon1.pixmap(SearchIcon1.actualSize(QSize(96, 96))));
        } else {
            QIcon SearchIcon2 = QIcon(":/res/Search-web-dark.svg");
            m_blankLabel->setPixmap(SearchIcon2.pixmap(SearchIcon2.actualSize(QSize(96, 96))));
        }
    }
}

void BlankPage::changeSearchText()
{
    m_blankTextLabel->setText(tr("No Relevant Contacts"));
    searchblank = 1;
    if (GlobalSizeData::THEME_COLOR == GlobalSizeData::UKUILight) {
        QIcon SearchIcon1 = QIcon(":/res/Search-web-light.svg");
        m_blankLabel->setPixmap(SearchIcon1.pixmap(SearchIcon1.actualSize(QSize(96, 96))));
    } else {
        QIcon SearchIcon2 = QIcon(":/res/Search-web-dark.svg");
        m_blankLabel->setPixmap(SearchIcon2.pixmap(SearchIcon2.actualSize(QSize(96, 96))));
    }
}

void BlankPage::changeBlankText()
{
    m_blankTextLabel->setText(tr("No Information"));
    QIcon blankIcon = QIcon(":/res/kylin-ipmsg.svg");
    m_blankLabel->setPixmap(blankIcon.pixmap(blankIcon.actualSize(QSize(96, 96))));
    searchblank = 0;
}


