4 #include "friendlistitemdelegate.h"
7 const int BACKGROUND_BOTTOM_HEIGHT = 15;
8 const int BACKGROUND_TOP_HEIGHT = 20;
9 const int BACKGROUND_WIDTH = 368;
10 const int ICON_HEIGHT = 24; ///< Icon height
11 const int ICON_WIDTH = 24; ///< Icon width
12 const int IMAGE_HEIGHT = 64; ///< Friend image height
13 const int IMAGE_WIDTH = 64; ///< Friend image width
14 const int ITEM_MIN_HEIGHT = 141; ///< Minimum height for item
15 const int MARGIN = 5; ///< Icon margin
16 const int MOUSE_PRESS_AREA_WIDTH = 20; ///< Area width for item height toggling
17 const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height toggling
20 * @var NAME_LABEL_MAX_WIDTH
22 * @brief Name label's maximum width
24 const int NAME_LABEL_MAX_WIDTH = BACKGROUND_WIDTH - 3*MARGIN - IMAGE_WIDTH;
27 * @var LABEL_MAX_WIDTH
29 * @brief All label's maximum width
31 const int LABEL_MAX_WIDTH = BACKGROUND_WIDTH - 3 * MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH;
33 FriendListItemDelegate::FriendListItemDelegate()
35 qDebug() << __PRETTY_FUNCTION__;
37 m_clockImage = QPixmap(":/res/images/clock.png");
38 m_envelopeImage = QPixmap(":/res/images/envelope.png");
39 m_compassImage = QPixmap(":/res/images/compass.png");
42 void FriendListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
43 const QModelIndex &index) const
45 qDebug() << __PRETTY_FUNCTION__;
47 ListItemDelegate::paint(painter, option, index);
49 painter->setPen(COLOR_GRAY);
50 painter->setFont(NOKIA_FONT_SMALL);
52 QString statusText = index.data(Qt::UserRole).toString();
53 QString address = index.data(Qt::UserRole + 1).toString();
54 QString timestamp = index.data(Qt::UserRole + 2).toString();
55 QString distance = index.data(Qt::UserRole + 3).toString();
56 QPixmap distanceIcon = QPixmap(qvariant_cast<QPixmap>(index.data(Qt::UserRole + 4)));
58 QRect itemRect = option.rect;
60 QPoint distanceIconPoint = QPoint(BACKGROUND_WIDTH - ICON_WIDTH - 15, itemRect.top() + 5);
61 QRect distanceRect = index.data(Qt::SizeHintRole + 4).toRect();
62 distanceRect.translate(BACKGROUND_WIDTH - distanceRect.width(), itemRect.top() + ICON_HEIGHT);
63 qDebug() << __PRETTY_FUNCTION__ << distanceRect << distance;
64 painter->drawPixmap(distanceIconPoint, distanceIcon);
65 painter->drawText(distanceRect, Qt::TextWordWrap, distance);
67 QRect envelopeRect = QRect(itemRect.left() + IMAGE_WIDTH + 15, itemRect.top() + IMAGE_HEIGHT - 10,
68 ICON_WIDTH, ICON_HEIGHT);
69 QRect statusTextRect = index.data(Qt::SizeHintRole + 1).toRect();
70 statusTextRect.translate(envelopeRect.right() + 5, envelopeRect.top());
72 painter->drawPixmap(envelopeRect, m_envelopeImage);
73 painter->drawText(statusTextRect, Qt::TextWordWrap, statusText);
76 QRect compassRect = QRect(envelopeRect.left(), statusTextRect.bottom() + 2, ICON_WIDTH,
78 QRect locationRect = index.data(Qt::SizeHintRole + 2).toRect();
79 locationRect.translate(compassRect.right() + 5, compassRect.top());
81 painter->drawPixmap(compassRect, m_compassImage);
82 painter->drawText(locationRect, Qt::TextWordWrap, address);
85 QRect clockRect = QRect(envelopeRect.left(), locationRect.bottom() + 2, ICON_WIDTH, ICON_HEIGHT);
86 QRect timestampRect = index.data(Qt::SizeHintRole + 3).toRect();
87 timestampRect.translate(clockRect.right() + 5, clockRect.top());
89 painter->drawPixmap(clockRect, m_clockImage);
90 painter->drawText(timestampRect, Qt::TextWordWrap, timestamp);
93 QSize FriendListItemDelegate::sizeHint(const QStyleOptionViewItem &option,
94 const QModelIndex &index) const
96 qDebug() << __PRETTY_FUNCTION__;
98 return ListItemDelegate::sizeHint(option, index);