2 * Qt OBS - A Qt based OBS client
4 * Copyright (C) 2010 Novell Inc, Klaas Freitag <freitag@suse.de>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) version 3.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Written by Klaas Freitag <freitag@suse.de>
24 #include "statusdelegate.h"
28 #include "statusdelegate.h"
30 StatusDelegate::StatusDelegate(QObject *parent)
31 : QStyledItemDelegate(parent)
37 void StatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
38 const QModelIndex &index) const
41 if (option.state & QStyle::State_Selected)
42 painter->fillRect(option.rect, option.palette.highlight());
44 int size = qMin(option.rect.width(), option.rect.height());
45 int brightness = index.model()->data( index, Qt::DisplayRole ).toInt();
46 double radius = (size/2.0) - (brightness/255.0 * size/2.0);
51 painter->setRenderHint(QPainter::Antialiasing, true);
52 painter->setPen(Qt::NoPen);
53 if (option.state & QStyle::State_Selected)
54 painter->setBrush(option.palette.highlightedText());
56 painter->setBrush(QBrush(Qt::black));
58 painter->drawEllipse(QRectF(option.rect.x() + option.rect.width()/2 - radius,
59 option.rect.y() + option.rect.height()/2 - radius,
62 QFontMetrics fmetrics = painter->fontMetrics();
63 painter->drawText(option.rect.x(), option.rect.y()+fmetrics.height(),
64 index.model()->data( index, Qt::DisplayRole ).toString() );
68 QSize StatusDelegate::sizeHint(const QStyleOptionViewItem& option,
69 const QModelIndex& index ) const
71 QString val = index.model()->data( index, Qt::DisplayRole ).toString();
72 QFontMetrics fm = option.fontMetrics;
74 return QSize( 1.2*fm.width( val ), 1.2*fm.height() );