#include "CheckHeaderView.h"
#include "CAppInfo.h"

CheckHeaderView::CheckHeaderView(int checkColumnIndex,
        Qt::Orientation orientation,
        QWidget * parent ) :
        QHeaderView(orientation, parent)
{
    // 创建checkbox;
	QString sCheckStyle = QString(R"(QCheckBox
                                  {
                                      outline: none;
                                      height:%1px;

                                      font-size:%2px;
                                      font-family:"Microsoft YaHei";
                                      font-weight:400;
                                      color:rgba(102,102,102,1);
                                  }

                                  QCheckBox::indicator
                                  {
                                      width:%3px;
                                      height:%4px;
                                  }

                                  QCheckBox::indicator:unchecked
                                  {
                                      border: %5px solid rgba(228,229,235,1);
                                      border-radius:%6px;
                                      background:rgba(239,240,245,1);
                                  }

                                  QCheckBox::indicator:checked
                                  {
                                      border-image: url(:/images/icon-checkbox-checked.png);
                                  })").arg((int)(g_appInfoPtr->m_fRate * 26))
		.arg((int)(g_appInfoPtr->m_fRate * 14))
		.arg((int)(g_appInfoPtr->m_fRate * 14))
		.arg((int)(g_appInfoPtr->m_fRate * 14))
		.arg((int)(g_appInfoPtr->m_fRate * 1))
		.arg((int)(g_appInfoPtr->m_fRate * 3));
    m_CheckIdex = checkColumnIndex;
    m_checkBox = new QCheckBox(this);
	m_checkBox->setStyleSheet(sCheckStyle);
    QObject::connect(m_checkBox, SIGNAL(stateChanged(int)), this, SLOT(stateChanged(int)));
}

void CheckHeaderView::stateChanged(int state)
{
    emit checkboxStateChanged(state);
}

void CheckHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
{

    painter->save();
    QHeaderView::paintSection(painter, rect, logicalIndex);
    painter->restore();


    if (logicalIndex == m_CheckIdex)
    {

        m_checkBox->setGeometry(rect);
    }

}