Added listcommon.h file.
[situare] / src / ui / friendlistitemdelegate.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Jussi Laitinen - jussi.laitinen@ixonos.com
6
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.
10
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.
15
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,
19    USA.
20 */
21
22 #include <QDebug>
23 #include <QPainter>
24
25 #include "friendlistitemdelegate.h"
26 #include "../common.h"
27 #include "listcommon.h"
28
29 FriendListItemDelegate::FriendListItemDelegate()
30 {
31     qDebug() << __PRETTY_FUNCTION__;
32
33     m_clockImage = QPixmap(":/res/images/clock.png");
34     m_envelopeImage = QPixmap(":/res/images/envelope.png");
35     m_compassImage = QPixmap(":/res/images/compass.png");
36 }
37
38 void FriendListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
39                                    const QModelIndex &index) const
40 {
41     qDebug() << __PRETTY_FUNCTION__;
42
43     ListItemDelegate::paint(painter, option, index);
44
45     painter->setPen(COLOR_GRAY);
46     painter->setFont(NOKIA_FONT_SMALL);
47
48     QString statusText = index.data(STATUS_TEXT_DISPLAY_INDEX).toString();
49     QString location = index.data(LOCATION_DISPLAY_INDEX).toString();
50     QString updated = index.data(UPDATED_DISPLAY_INDEX).toString();
51     QString distance = index.data(DISTANCE_TEXT_DISPLAY_INDEX).toString();
52     QPixmap distanceIcon = QPixmap(qvariant_cast<QPixmap>(index.data(DISTANCE_IMAGE_INDEX)));
53
54     QRect itemRect = option.rect;
55
56     QPoint distanceIconPoint = QPoint(ITEM_WIDTH - ICON_WIDTH - 3*MARGIN, itemRect.top() + MARGIN);
57     QRect distanceRect = index.data(DISTANCE_SIZE_HINT_INDEX).toRect();
58     distanceRect.translate(ITEM_WIDTH - distanceRect.width() - 2*MARGIN,
59                            itemRect.top() + ICON_HEIGHT + 2*MARGIN);
60
61     painter->drawPixmap(distanceIconPoint, distanceIcon);
62     painter->drawText(distanceRect, Qt::TextSingleLine, distance);
63
64     QRect envelopeRect = QRect(itemRect.left() + IMAGE_WIDTH + 3*MARGIN,
65                                itemRect.top() + IMAGE_HEIGHT - 2*MARGIN, ICON_WIDTH, ICON_HEIGHT);
66     QRect statusTextRect = index.data(STATUS_TEXT_SIZE_HINT_INDEX).toRect();
67     statusTextRect.translate(envelopeRect.right() + MARGIN, envelopeRect.top());
68
69     painter->drawPixmap(envelopeRect, m_envelopeImage);
70     painter->drawText(statusTextRect, Qt::TextWrapAnywhere, statusText);
71
72
73     QRect compassRect = QRect(envelopeRect.left(), statusTextRect.bottom() + ICON_MARGIN,
74                               ICON_WIDTH, ICON_HEIGHT);
75     QRect locationRect = index.data(LOCATION_SIZE_HINT_INDEX).toRect();
76     locationRect.translate(compassRect.right() + MARGIN, compassRect.top());
77
78     painter->drawPixmap(compassRect, m_compassImage);
79     painter->drawText(locationRect, Qt::TextWrapAnywhere, location);
80
81     QRect clockRect = QRect(envelopeRect.left(), locationRect.bottom() + ICON_MARGIN, ICON_WIDTH,
82                             ICON_HEIGHT);
83     QRect updatedRect = index.data(UPDATED_SIZE_HINT_INDEX).toRect();
84     updatedRect.translate(clockRect.right() + MARGIN, clockRect.top());
85
86     painter->drawPixmap(clockRect, m_clockImage);
87     painter->drawText(updatedRect, Qt::TextWrapAnywhere, updated);
88 }
89
90 QSize FriendListItemDelegate::sizeHint(const QStyleOptionViewItem &option,
91                                       const QModelIndex &index) const
92 {
93     qDebug() << __PRETTY_FUNCTION__;
94
95     return ListItemDelegate::sizeHint(option, index);
96 }