#include "envResult.h"
#include "ui_envResult.h"

#include "CAppInfo.h"
#include "EnvResultItem.h"

#include <QScrollBar>


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

    setStyleSheet(g_appInfoPtr->m_sQssStr);

    initUI();

    ui->list_result->setVerticalScrollMode(QListWidget::ScrollPerPixel);
    ui->list_result->verticalScrollBar()->setSingleStep(g_appInfoPtr->m_fRate*5);
}

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

void envResult::initUI()
{
    setGeometry(0, 0, g_appInfoPtr->m_fRate*(600 - 24), g_appInfoPtr->m_fRate*340);
    ui->label_platformIcon->setGeometry(g_appInfoPtr->m_fRate*60, g_appInfoPtr->m_fRate*40, g_appInfoPtr->m_fRate*32, g_appInfoPtr->m_fRate*32);
    ui->label_platformTitle->adjustSize();
    ui->label_platformTitle->setGeometry(ui->label_platformIcon->x() + ui->label_platformIcon->width() + g_appInfoPtr->m_fRate*10,
                                         ui->label_platformIcon->y() + (ui->label_platformIcon->height() - ui->label_platformTitle->height())/2,
                                         ui->label_platformTitle->width(), ui->label_platformTitle->height());
    ui->label_unpassHint->adjustSize();
    ui->label_unpassHint->setGeometry(g_appInfoPtr->m_fRate*60, g_appInfoPtr->m_fRate*125, ui->label_unpassHint->width(), ui->label_unpassHint->height());
    ui->list_result->setGeometry(ui->label_unpassHint->x(), ui->label_unpassHint->y() + ui->label_unpassHint->height() + g_appInfoPtr->m_fRate*12,
                                 width() - g_appInfoPtr->m_fRate*60*2, g_appInfoPtr->m_fRate*95);
    if(!g_appInfoPtr->m_sVersionCode.isEmpty())
    {
        ui->label_version->setText(QString("V%1").arg(g_appInfoPtr->m_sVersionCode));
    }
    ui->label_version->adjustSize();
    ui->label_version->setGeometry(ui->label_unpassHint->x(), g_appInfoPtr->m_fRate*270, g_appInfoPtr->m_fRate*300, ui->label_version->height());
    ui->label_complay->adjustSize();
    ui->label_complay->setGeometry(ui->label_version->x(), ui->label_version->y() + ui->label_version->height(),
                                   ui->label_complay->width(), ui->label_complay->height());

}

void envResult::addItem(QString sStr)
{
    QListWidgetItem *item = new QListWidgetItem;
    ui->list_result->addItem(item);
    envResultItem *ei = new envResultItem;
    ei->setText(sStr);
    int nHeight = ei->setUI(ui->list_result->width() - 8);
    QSize size = item->sizeHint();
    size.setHeight(nHeight);
    item->setSizeHint(size);
    ui->list_result->setItemWidget(item, ei);
}

