#include "tableWidgetHoverDelegate.h"

QTableWidgetHoverDelegate::QTableWidgetHoverDelegate(QTableWidget *parent)
    : QStyledItemDelegate{parent}
{
    m_tableWiget = parent;
}

QTableWidgetHoverDelegate::~QTableWidgetHoverDelegate()
{}

void QTableWidgetHoverDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
    if(option.state.testFlag(QStyle::State_MouseOver))
    {
        QTableWidgetItem* hoveredItem = m_tableWiget->item(index.row(), index.column());
        if(hoveredItem)
        {
            int row = index.row();
            for(int column = 0; column < m_tableWiget->columnCount(); column++)
            {
                QTableWidgetItem* item = m_tableWiget->item(row, column);
                if(!item)
                    continue;

                QModelIndex index = m_tableWiget->model()->index(row, column);
                QStyleOptionViewItem itemOption = option;
                itemOption.rect = m_tableWiget->visualItemRect(item);
                QStyledItemDelegate::paint(painter, itemOption, index);
            }
        }
    }
    else
        QStyledItemDelegate::paint(painter, option, index);
}
