/***
   This file is part of fly-ocr.

   Copyright (C) 2021 LLC "RusBITech-Astra" (https://astralinux.ru)

   Foobar is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   Foobar 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 fly-ocr. If not, see <https://www.gnu.org/licenses/>.
***/

#include <QFontMetrics>
#include <QAbstractItemView>
#include <QToolButton>
#include <QEvent>
#include <QHBoxLayout>
#include "sourcedocumentmodel.h"
#include "pageitemdelegate.h"

PageItemDelegate::PageItemDelegate(QObject* parent)
    : QStyledItemDelegate(parent)
{}

void PageItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
    QStyleOptionViewItem newOption = option;

    if (static_cast<const SourceDocumentModel*>(index.model())->listMode()) {
        newOption.decorationPosition = QStyleOptionViewItem::Left;
        newOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
    } else {
        newOption.decorationPosition = QStyleOptionViewItem::Top;
        newOption.displayAlignment = Qt::AlignCenter;
    }
    QStyledItemDelegate::paint(painter, newOption, index);
}

QSize PageItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
    QFontMetrics fMetrics(option.font);
    QSize size = QStyledItemDelegate::sizeHint(option, index);
    return QSize(size.height(), size.height() + fMetrics.height());
}
