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,
22 #include <QVBoxLayout>
23 #include <QPushButton>
26 #include <QPaintEvent>
29 #include <QFormLayout>
30 #include <QSpacerItem>
32 #include "friendlistitem.h"
33 #include "../user/user.h"
35 FriendListItem::FriendListItem(QWidget *parent)
39 QVBoxLayout *layout = new QVBoxLayout(this);
40 this->setLayout(layout);
42 QHBoxLayout *topLayout = new QHBoxLayout();
43 topLayout->setMargin(0);
44 topLayout->setSpacing(0);
46 QHBoxLayout *bottomLayout = new QHBoxLayout();
47 bottomLayout->setMargin(0);
48 bottomLayout->setSpacing(0);
49 m_infoWidget = new QWidget(this);
51 QFormLayout *infoLayout = new QFormLayout();
52 infoLayout->setMargin(0);
53 infoLayout->setSpacing(0);
54 m_infoWidget->setLayout(infoLayout);
56 QLabel *clockLabel = new QLabel(this);
57 clockLabel->setPixmap(QPixmap(CLOCK_PATH));
58 clockLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
59 QLabel *envelopeLabel = new QLabel(this);
60 envelopeLabel->setPixmap(QPixmap(ENVELOPE_PATH));
61 envelopeLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
62 QLabel *compassLabel = new QLabel(this);
63 compassLabel->setPixmap(QPixmap(COMPASS_PATH));
64 compassLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
66 m_imageLabel = new QLabel(this);
67 m_imageLabel->setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT);
68 m_nameLabel = new QLabel("", this);
69 m_nameLabel->setFixedHeight(IMAGE_HEIGHT);
70 m_updatedLabel = new QLabel("", this);
71 m_updatedLabel->setWordWrap(true);
72 m_statusTextLabel = new QLabel("", this);
73 m_statusTextLabel->setWordWrap(true);
74 m_locationLabel = new QLabel("", this);
75 m_locationLabel->setWordWrap(true);
77 infoLayout->addRow(clockLabel, m_updatedLabel);
78 infoLayout->addRow(envelopeLabel, m_statusTextLabel);
79 infoLayout->addRow(compassLabel, m_locationLabel);
81 topLayout->addWidget(m_imageLabel);
82 topLayout->addWidget(m_nameLabel);
84 bottomLayout->addSpacerItem(new QSpacerItem(IMAGE_WIDTH, IMAGE_HEIGHT));
85 bottomLayout->addWidget(m_infoWidget, 1);
87 layout->addLayout(topLayout, 0);
88 layout->addLayout(bottomLayout, 1);
90 this->setObjectName("listItem");
91 m_infoWidget->setObjectName("infoWidget");
92 m_nameLabel->setObjectName("nameLabel");
94 this->setStyleSheet("#listItem { border-image: url(:/res/images/list_item.png) 20%; " \
95 "border-width: 20px 14px 16px 14px; } " \
96 "QLabel { font-size: 13pt; color: #989898; }" \
97 "#nameLabel { font-size: 18pt; color: #ffffff }");
99 this->setMinimumSize(ITEM_MIN_WIDTH, ITEM_MIN_HEIGHT);
100 this->setMaximumSize(ITEM_MAX_WIDTH, ITEM_MAX_HEIGHT);
103 void FriendListItem::setData(const User &user)
109 m_imageLabel->setPixmap(m_user.profileImage());
110 m_nameLabel->setText(m_shortenedName);
111 m_updatedLabel->setText(m_shortenedUpdated);
112 m_statusTextLabel->setText(m_shortenedStatusText);
113 m_locationLabel->setText(m_shortenedLocation);
117 void FriendListItem::shortenTexts()
119 if (m_user.name().length() > MAXIMUM_CHARS) {
120 m_shortenedName = m_user.name().left(MAXIMUM_CHARS-3).append("...");
123 m_shortenedName = m_user.name();
125 if (m_user.timestamp().length() > MAXIMUM_CHARS) {
126 m_shortenedUpdated = m_user.timestamp().left(MAXIMUM_CHARS-3).append("...");
129 m_shortenedUpdated = m_user.timestamp();
131 if (m_user.note().length() > MAXIMUM_CHARS) {
132 m_shortenedStatusText = m_user.note().left(MAXIMUM_CHARS-3).append("...");
135 m_shortenedStatusText = m_user.note();
137 if (m_user.address().length() > MAXIMUM_CHARS) {
138 m_shortenedLocation = m_user.address().left(MAXIMUM_CHARS-3).append("...");
141 m_shortenedLocation = m_user.address();
145 void FriendListItem::toggleHeight()
148 m_nameLabel->setText(m_shortenedName);
149 m_updatedLabel->setText(m_shortenedUpdated);
150 m_statusTextLabel->setText(m_shortenedStatusText);
151 m_locationLabel->setText(m_shortenedLocation);
156 m_nameLabel->setText(m_user.name());
157 m_updatedLabel->setText(m_user.timestamp());
158 m_statusTextLabel->setText(m_user.note());
159 m_locationLabel->setText(m_user.address());
164 void FriendListItem::mousePressEvent(QMouseEvent *event)
166 m_mousePosition = event->pos();
169 void FriendListItem::mouseReleaseEvent(QMouseEvent *event)
171 qDebug() << __PRETTY_FUNCTION__;
173 if (event->pos() == m_mousePosition)
177 void FriendListItem::paintEvent(QPaintEvent *)
182 QPainter painter(this);
183 style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);