/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
 * -*- coding: utf-8 -*-
 *
 * Copyright (C) 2025 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#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);
}
