#include "TrayListViewDelegate.h"

#include <QPainter>

void TrayListViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QStyleOptionViewItem opt = option;
    initStyleOption(&opt, index);

    QRect rect = option.rect;

    if (opt.state & QStyle::State_Selected) {
        painter->fillRect(rect, opt.palette.highlight());
    }

    QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
    int iconSize = 32;
    QRect iconRect(rect.x() + 5, rect.y() + (rect.height() - iconSize) / 2, iconSize, iconSize);
    icon.paint(painter, iconRect);

    QString text = index.data(Qt::DisplayRole).toString();
    QRect textRect(rect.x() + iconSize + 50, rect.y(), rect.width() - iconSize - 55, rect.height());
    painter->drawText(textRect, Qt::AlignVCenter, text);
}

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