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

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

}

void blogSearchListDelegate::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",6));


    // 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,15), pixmap.size());
    decorationRect.moveTo(decorationRect.left(), decorationRect.top());

    const QString& name = index.data(Qt::UserRole).toString();
    QFontMetrics fm(painter->font());
    QRect displayRect = QRect(decorationRect.topRight()+QPoint(20,30),QSize(fm.width(name),fm.height()));

    const QString& nameEn = index.data(Qt::UserRole+3).toString();
    //QFontMetrics fm(painter->font());
    QRect displayRect2 = QRect(decorationRect.topRight()+QPoint(20,0),QSize(fm.width(nameEn),fm.height()));

    const QString& address = index.data(Qt::UserRole+4).toString();

    QRect displayRect3 = QRect(decorationRect.topRight()+QPoint(20,55),QSize(210,60));

    const QString& count = index.data(Qt::UserRole+5).toString();
    QRect displayRect5 = QRect(decorationRect.topRight()+QPoint(20,100),QSize(fm.width(count),fm.height()));



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


    drawBackground(painter, opt, index);
    painter->drawPixmap(decorationRect, pixmap);
    painter->drawText(displayRect, name);
    painter->drawText(displayRect2, nameEn);
    painter->drawText(displayRect3, address);

    painter->drawText(displayRect5, count);

    painter->drawPixmap(smallIconRect, pixmapSmall);

    drawFocus(painter, opt, displayRect5);

    // done
    painter->restore();
}


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

