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

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

}

void tradeListDelegate::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 QString& address = index.data(Qt::UserRole+1).toString();
    QFontMetrics fm(painter->font());
    QRect decorationRect = QRect(opt.rect.topLeft()+QPoint(0,10), QSize(250,60));
    decorationRect.moveTo(decorationRect.left(), decorationRect.top());

    const QString& date = index.data(Qt::UserRole).toString();

    QRect displayRect = QRect(opt.rect.topLeft()+QPoint(0,60),QSize(fm.width(date),fm.height()));

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

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

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

    const QString& pps = index.data(Qt::UserRole+5).toString();
    //QFontMetrics fm(painter->font());
    QRect displayRect5 = QRect(displayRect4.topRight()+QPoint(-(fm.width(isCent)) ,30),QSize(fm.width(pps),fm.height()));


    drawBackground(painter, opt, index);
    painter->drawText(decorationRect, address);
    painter->drawText(displayRect, date);
    painter->drawText(displayRect2, size);
    painter->drawText(displayRect3, price);
    painter->drawText(displayRect4, isCent);
    painter->drawText(displayRect5, pps);


    drawFocus(painter, opt, displayRect5);

    // done
    painter->restore();
}


QSize tradeListDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
    return QSize(360,120);
}
