File indexing completed on 2022-09-20 13:02:50

0001 /***************************************************************************
0002  *   Copyright (C) 2013 by Ian Simpson <ian.kdedev@yahoo.com>              *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  ***************************************************************************/
0009 
0010 #include "itemdelegate.h"
0011 
0012 itemDelegate::itemDelegate(int height, QObject *parent) :
0013     QItemDelegate(parent),
0014     m_height(height),
0015     m_grandTotalRow(19)
0016 {
0017     m_emptyRows << 9 << 18;
0018 }
0019 
0020 QSize itemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
0021 {
0022     if (index.row() == 0 || index.row() == m_grandTotalRow || m_emptyRows.contains(index.row()))
0023     {
0024         return QItemDelegate::sizeHint(option, index);
0025     }
0026     else
0027     {
0028         // Set the height to that of the font set at pointSize m_height
0029         QSize size;
0030         QFont font(index.data(Qt::FontRole).value<QFont>());
0031         font.setPointSize(m_height);
0032         QFontMetrics fm(font);
0033         size.setHeight(fm.height());
0034         size.setWidth(QItemDelegate::sizeHint(option, index).width());
0035         return size;
0036     }
0037 }
0038 
0039 void itemDelegate::setHeight(int height)
0040 {
0041     m_height = height;
0042 }