#include "districtAreaListDelegate.h"
#include <QtGui>

districtAreaListDelegate::districtAreaListDelegate(QObject *parent) :
    QItemDelegate(parent)
{

}

void districtAreaListDelegate::paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
          //if (index.column() == 0) return;
    QStyleOptionViewItemV3 opt = setOptions(index, option);


    // prepare
    painter->save();
    painter->setFont(QFont("MS Shell Dlg 2",5));


    // get the data and the rectangles
    const QPixmap& pixmap
            = qvariant_cast<QPixmap>(index.data(Qt::UserRole+1));

    QRect decorationRect = QRect(opt.rect.topLeft()+QPoint(5,10), pixmap.size());
    decorationRect.moveTo(decorationRect.left(), decorationRect.top());

    const QString& name = index.data(Qt::UserRole).toString();
    QFontMetrics fm(painter->font());
    QRect displayRect = QRect(opt.rect.topLeft()+QPoint(75,10),QSize(fm.width(name),fm.height()));

    const QString& nameEn = index.data(Qt::UserRole+3).toString();
    //QFontMetrics fm(painter->font());
    QRect displayRect2 = QRect(opt.rect.topLeft()+QPoint(75,40),QSize(240,60));

    const QString& pps = index.data(Qt::UserRole+4).toString();
    //QFontMetrics fm(painter->font());
    QRect displayRect3 = QRect(opt.rect.topLeft()+QPoint(180,10),QSize(fm.width(pps),fm.height()));





    const QPixmap& pixmapSmall
            = qvariant_cast<QPixmap>(index.data(Qt::UserRole+2));
    QRect smallIconRect = QRect(opt.rect.topLeft()+QPoint(310,25), pixmapSmall.size());

    const QString& percent = index.data(Qt::UserRole+5).toString();
    //QFontMetrics fm(painter->font());
    QRect displayRect4 = QRect(smallIconRect.topLeft()+QPoint(-40,-5),QSize(fm.width(percent),fm.height()));

    const QPixmap& arrow
            = qvariant_cast<QPixmap>(index.data(Qt::UserRole+6));
    QRect smallIconRect2 = QRect(displayRect4.topLeft()+QPoint(-20,3), arrow.size());




    drawBackground(painter, opt, index);
    painter->drawPixmap(decorationRect, pixmap);
    painter->drawText(displayRect, name);
    painter->drawText(displayRect2, nameEn);
    painter->drawText(displayRect3, pps);
    painter->drawPixmap(smallIconRect, pixmapSmall);
    painter->drawText(displayRect4, percent);
    painter->drawPixmap(smallIconRect2, arrow);


    drawFocus(painter, opt, smallIconRect);

    // done
    painter->restore();
}


QSize districtAreaListDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
    return QSize(300,90);
}
