#include "slistwidgetsetting.h"
#include <QScrollBar>

#include "mainwindow.h"


SListWidgetSetting::SListWidgetSetting(QWidget *parent) : QListWidget(parent)
{
    verticalScrollBar()->hide();

}

SListWidgetSetting::~SListWidgetSetting()
{

}

void SListWidgetSetting::valueChangedScrollBarHorizontal(int nValue)
{
    int nMax = verticalScrollBar()->maximum();

    float fRatio = (float)nValue / 299.0f;
    int nPos = fRatio * nMax + 0.5f;

    if(nPos>nMax)
    {
        nPos = nMax;
    }

    if(nPos<0)
    {
        nPos = 0;
    }

    verticalScrollBar()->setValue(nPos);

}

void SListWidgetSetting::SetData(STableHeader* pTableHeader)
{
    int i=0;
    CommonData* pCommonData = MainWindow::GetCommonData();

    for(i=0 ; i<count() ; i++)
    {
        QListWidgetItem* pItem = item(i);
        SAFE_DELETE(pItem);
    }
    clear();

    vector<TableHeader*>* pListHeader = NULL;

    if(m_bActivate==true)
    {
        pListHeader = pTableHeader->GetListActive();
    }
    else
    {
        pListHeader = pTableHeader->GetListInactive();
    }

    int nDisplayType = MainWindow::GetCommonData()->GetDisplayType();

    int nFontSize = 24;
    int nCellHeight = 80;
    if(nDisplayType==SDISPLAY_1280X1024)
    {
        nCellHeight = 64;
    }
    else if(nDisplayType==SDISPLAY_1920X1080)
    {
        nCellHeight = 74;
    }


    for(i=0 ; i<pListHeader->size() ; i++)
    {
        QListWidgetItem* pItem = NULL;
        pItem = new QListWidgetItem(this);
        pItem->setTextAlignment(Qt::AlignCenter);
        //pItem->setSizeHint(QSize(pItem->sizeHint().width(), nCellHeight));
        pItem->setSizeHint(QSize(size().width(), nCellHeight));
        addItem(pItem);

        FormItemSelection* pItemWidget = new FormItemSelection(this);
        setItemWidget(pItem, pItemWidget);

        TableHeader* pHeader = (*pListHeader)[i];

        QString strText = pHeader->m_strText;
        //pItemWidget->SetText(strText);
        pItemWidget->SetTableHeader(pHeader);
    }
}

void SListWidgetSetting::SetActivate(bool bActivate)
{
    m_bActivate = bActivate;
}

bool SListWidgetSetting::IsActivate()
{
    return m_bActivate;
}

void SListWidgetSetting::SetListType(int nType)
{
    m_nListType = nType;
}
