/*
Copyright 2010-2012 Grégory Soutadé
This file is part of KissCount.
KissCount 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.
KissCount 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 KissCount. If not, see .
*/
#ifndef TABLEVIEWDELEGATE_H
#define TABLEVIEWDELEGATE_H
#include
#include "GridAccount.hpp"
class TableViewDelegate : public QStyledItemDelegate
{
protected:
GridAccount* _grid;
public:
// "Nomme" les rôles utilisés par ce delegate
// pour récupèrer les nouvelles propriétés d'un item
enum Roles {
BorderWidthRole = Qt::UserRole,
BorderColorRole,
};
TableViewDelegate(QObject *parent = 0) : QStyledItemDelegate(parent), _grid(qobject_cast(parent))
{
}
void paint (QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index ) const
{
QStyledItemDelegate::paint(painter, option, index);
if (!_grid) return;
QPen pen(Qt::black);
int row = index.row();
painter->setPen(pen);
// Always paint column
painter->drawLine(option.rect.topLeft(), option.rect.bottomLeft());
if (row == 0)
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
else if (_grid->_canAddOperation)
{
if (row == _grid->_fixCosts ||
row == _grid->_week1 ||
row == _grid->_week2 ||
row == _grid->_week3 ||
row == _grid->_week4 ||
row == _grid->_week5)
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
}
}
};
#endif