1 | /************************************************************************************* |
2 | * Copyright (C) 2010-2012 by Alejandro Fiestas Olivares <afiestas@kde.org> * |
3 | * * |
4 | * This program is free software; you can redistribute it and/or * |
5 | * modify it under the terms of the GNU General Public License * |
6 | * as published by the Free Software Foundation; either version 2 * |
7 | * of the License, or (at your option) any later version. * |
8 | * * |
9 | * This program is distributed in the hope that it will be useful, * |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * GNU General Public License for more details. * |
13 | * * |
14 | * You should have received a copy of the GNU General Public License * |
15 | * along with this program; if not, write to the Free Software * |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * |
17 | *************************************************************************************/ |
18 | |
19 | #include "playgrounddelegate.h" |
20 | #include <QPainter> |
21 | |
22 | PlaygroundDelegate::PlaygroundDelegate(QObject *parent): QAbstractItemDelegate(parent) |
23 | { } |
24 | |
25 | QSize PlaygroundDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const |
26 | { |
27 | Q_UNUSED(option); |
28 | Q_UNUSED(index); |
29 | return QSize(200,100); |
30 | } |
31 | |
32 | void PlaygroundDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const |
33 | { |
34 | QString title = index.model()->data(index, Qt::DisplayRole).toString(); |
35 | QPixmap pixmap = index.model()->data(index,Qt::UserRole).value<QPixmap>(); |
36 | |
37 | //Paint background with highlight |
38 | painter->save(); |
39 | if (option.state & QStyle::State_Selected) { |
40 | painter->setBrush(option.palette.color(QPalette::Highlight)); |
41 | } else { |
42 | painter->setBrush(Qt::gray); |
43 | } |
44 | painter->drawRect(option.rect); |
45 | painter->restore(); |
46 | |
47 | //Any way of do this more beatifuly? |
48 | painter->drawPixmap(option.rect.x()+4,option.rect.y()+4,option.rect.width()-8,option.rect.height()-8,pixmap); |
49 | QFont font = painter->font(); |
50 | font.setWeight(QFont::Bold); |
51 | |
52 | painter->setFont(font); |
53 | painter->drawText(option.rect, Qt::AlignCenter | Qt::TextWordWrap, title); |
54 | painter->save(); |
55 | painter->restore(); |
56 | } |
57 | |