#include "ultravioletrays.h"
#include <QVBoxLayout>
#include <QGraphicsOpacityEffect>
#define UKUI_STYLE "org.ukui.style"
#define UKUI_FONT_SIZE "systemFontSize"
ultravioletrays::ultravioletrays(QWidget *parent) : QWidget(parent)
{
    m_uvLayout = new QVBoxLayout(this);

    m_uvIcon = new QLabel(this);
    m_str = new QLabel(this);
    m_degree = new QLabel(this);

    QPixmap uvpixmap(":/res/contorl_icons/index_uv.png");
    m_uvIcon->setPixmap(uvpixmap);
    m_uvIcon->setAlignment(Qt::AlignCenter);
    m_str->setText(tr("UV"));
    m_str->setAlignment(Qt::AlignCenter);
    m_degree->setText("N/A");
    m_degree->setAlignment(Qt::AlignCenter);
    initLayout();
    //    initQss();
}

void ultravioletrays::setItemContent(QString text)
{
    m_degree->setText(text);
}

void ultravioletrays::isFullScreen(int m_isFullScreen)
{
    m_judgeFullScreen = m_isFullScreen;
    initQss(14.0);
}

void ultravioletrays::initLayout()
{
    m_uvLayout->addWidget(m_uvIcon);
    m_uvLayout->addWidget(m_str);
    m_uvLayout->addWidget(m_degree);
}

void ultravioletrays::lable2SetFontSizeSlot(int size)
{
    //默认大小12px,换算成pt为9
    double lable2BaseFontSize = 11;                              //魔鬼数字，自行处理
    double nowFontSize = lable2BaseFontSize * double(size) / 11; // 11为系统默认大小，魔鬼数字，自行处理
    //    QFont font;
    //    font.setPointSizeF(nowFontSize);
    //    ui->label2->setFont(font);
    initQss(nowFontSize);
}
void ultravioletrays::initQss(double nowFontSize)
{
    m_uvIcon->setAlignment(Qt::AlignCenter);

    m_uvIcon->resize(30, 30);
    QPixmap uvpixmap(uvpath);
    m_uvIcon->setPixmap(uvpixmap);

    //    m_str->setStyleSheet("font:14px;color:white;");
    QFont m_font;
    //        m_font.setPointSizeF(nowFontSize);
    m_str->setFont(m_font);
    m_str->setAlignment(Qt::AlignCenter);
    QPalette uvStrPalette = m_str->palette();
    uvStrPalette.setColor(QPalette::WindowText, Qt::white);
    m_str->setPalette(uvStrPalette);
    //    设置字体透明度
    QGraphicsOpacityEffect *uvOpacityEffect = new QGraphicsOpacityEffect;
    uvOpacityEffect->setOpacity(0.7);
    m_str->setGraphicsEffect(uvOpacityEffect);
    //    m_degree->setStyleSheet("font:14px;color:white;");
    m_degree->setAlignment(Qt::AlignCenter);
    QPalette uvDegreePalette = m_degree->palette();
    uvDegreePalette.setColor(QPalette::WindowText, Qt::white);
    m_degree->setPalette(uvDegreePalette);
    m_degree->setFont(m_font);
}
