2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Jussi Laitinen - jussi.laitinen@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare 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 Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 #include "../common.h"
26 #include "avatarimage.h"
27 #include "listcommon.h"
30 #include "listitemdelegate.h"
32 const int BACKGROUND_BOTTOM_HEIGHT = 15; ///< Background image bottom height
33 const int BACKGROUND_TOP_HEIGHT = 20; ///< Background image top height
34 const int NAME_TOP_MARGIN = 40; ///< Name text top margin
36 ListItemDelegate::ListItemDelegate(QWidget *parent) :
37 QStyledItemDelegate(parent)
39 qDebug() << __PRETTY_FUNCTION__;
41 m_backgroundTopImage.load(":/res/images/list_item_top.png");
42 m_backgroundMiddleImage.load(":/res/images/list_item_middle.png");
43 m_backgroundBottomImage.load(":/res/images/list_item_bottom.png");
44 m_backgroundTopSelectedImage.load(":/res/images/list_item_top_selected.png");
45 m_backgroundMiddleSelectedImage.load(":/res/images/list_item_middle_selected.png");
46 m_backgroundBottomSelectedImage.load(":/res/images/list_item_bottom_selected.png");
49 void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
50 const QModelIndex &index) const
52 qDebug() << __PRETTY_FUNCTION__;
54 QPixmap image = QPixmap(qvariant_cast<QPixmap>(index.data(AVATAR_IMAGE_INDEX)));
55 QString name = index.data(TITLE_DISPLAY_INDEX).toString();
56 QSize size = index.data(ITEM_SIZE_HINT_INDEX).toSize();
57 bool selected = index.data(ITEM_EXPANDED_INDEX).toBool();
59 QRect itemRect = option.rect;
61 QRect topRect = QRect(itemRect.left(), itemRect.top(), ITEM_WIDTH,
62 BACKGROUND_TOP_HEIGHT);
63 QRect middleRect = QRect(itemRect.left(), topRect.bottom(), ITEM_WIDTH,
64 size.height() - BACKGROUND_TOP_HEIGHT
65 - BACKGROUND_BOTTOM_HEIGHT);
66 QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), ITEM_WIDTH,
67 BACKGROUND_BOTTOM_HEIGHT);
70 painter->drawPixmap(topRect, m_backgroundTopSelectedImage);
71 painter->drawPixmap(middleRect, m_backgroundMiddleSelectedImage);
72 painter->drawPixmap(bottomRect, m_backgroundBottomSelectedImage);
74 painter->drawPixmap(topRect, m_backgroundTopImage);
75 painter->drawPixmap(middleRect, m_backgroundMiddleImage);
76 painter->drawPixmap(bottomRect, m_backgroundBottomImage);
79 painter->setPen(Qt::white);
80 painter->setFont(NOKIA_FONT_NORMAL);
82 //Image is set, draw image and text
83 if (!image.isNull()) {
84 painter->drawPixmap(itemRect.left() + MARGIN * 2, itemRect.top(), image);
85 painter->drawText(itemRect.topLeft() + QPoint(MARGIN * 2 + IMAGE_WIDTH + MARGIN,
86 NAME_TOP_MARGIN), name);
90 painter->drawText(itemRect.topLeft() + QPoint(MARGIN * 3, NAME_TOP_MARGIN), name);
94 QSize ListItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
96 qDebug() << __PRETTY_FUNCTION__;
100 return index.data(Qt::SizeHintRole).toSize();