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 <QStateMachine>
30 #include <QAbstractTransition>
31 #include <QPropertyAnimation>
32 #include <QSignalTransition>
33 #include <QFontMetrics>
34 #include <QFormLayout>
35 #include <QSpacerItem>
37 #include "friendlistitem.h"
38 #include "user/user.h"
40 FriendListItem::FriendListItem(QWidget *parent)
44 QVBoxLayout *layout = new QVBoxLayout(this);
45 this->setLayout(layout);
47 QHBoxLayout *topLayout = new QHBoxLayout();
48 topLayout->setMargin(0);
49 topLayout->setSpacing(0);
51 QHBoxLayout *bottomLayout = new QHBoxLayout();
52 bottomLayout->setMargin(0);
53 bottomLayout->setSpacing(0);
54 m_infoWidget = new QWidget(this);
56 QFormLayout *infoLayout = new QFormLayout();
57 infoLayout->setMargin(0);
58 infoLayout->setSpacing(0);
59 m_infoWidget->setLayout(infoLayout);
61 QLabel *clockLabel = new QLabel(this);
62 clockLabel->setPixmap(QPixmap(CLOCK_PATH));
63 clockLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
64 QLabel *envelopeLabel = new QLabel(this);
65 envelopeLabel->setPixmap(QPixmap(ENVELOPE_PATH));
66 envelopeLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
67 QLabel *compassLabel = new QLabel(this);
68 compassLabel->setPixmap(QPixmap(COMPASS_PATH));
69 compassLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
71 m_imageLabel = new QLabel(this);
72 m_imageLabel->setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT);
73 m_nameLabel = new QLabel("", this);
74 m_nameLabel->setFixedHeight(IMAGE_HEIGHT);
75 m_updatedLabel = new QLabel("", this);
76 m_updatedLabel->setWordWrap(true);
77 m_statusTextLabel = new QLabel("", this);
78 m_statusTextLabel->setWordWrap(true);
79 m_locationLabel = new QLabel("", this);
80 m_locationLabel->setWordWrap(true);
82 infoLayout->addRow(clockLabel, m_updatedLabel);
83 infoLayout->addRow(envelopeLabel, m_statusTextLabel);
84 infoLayout->addRow(compassLabel, m_locationLabel);
86 topLayout->addWidget(m_imageLabel);
87 topLayout->addWidget(m_nameLabel);
89 bottomLayout->addSpacerItem(new QSpacerItem(IMAGE_WIDTH, IMAGE_HEIGHT));
90 bottomLayout->addWidget(m_infoWidget, 1);
92 layout->addLayout(topLayout, 0);
93 layout->addLayout(bottomLayout, 1);
95 this->setObjectName("listItem");
96 m_infoWidget->setObjectName("infoWidget");
97 m_nameLabel->setObjectName("nameLabel");
99 this->setStyleSheet("#listItem { border-image: url(:/res/images/list_item.png) 20%; " \
100 "border-width: 20px 14px 16px 14px; } " \
101 "QLabel { font-size: 13pt; color: #989898; }" \
102 "#nameLabel { font-size: 18pt; color: #ffffff }");
104 this->setMinimumSize(ITEM_MIN_WIDTH, ITEM_MIN_HEIGHT);
105 this->setMaximumSize(ITEM_MAX_WIDTH, ITEM_MAX_HEIGHT);
108 void FriendListItem::setData(const User &user)
114 m_imageLabel->setPixmap(m_user.profileImage());
115 m_nameLabel->setText(m_shortenedName);
116 m_updatedLabel->setText(m_shortenedUpdated);
117 m_statusTextLabel->setText(m_shortenedStatusText);
118 m_locationLabel->setText(m_shortenedLocation);
122 void FriendListItem::shortenTexts()
124 if (m_user.name().length() > MAXIMUM_CHARS) {
125 m_shortenedName = m_user.name().left(MAXIMUM_CHARS-3).append("...");
128 m_shortenedName = m_user.name();
130 if (m_user.timestamp().length() > MAXIMUM_CHARS) {
131 m_shortenedUpdated = m_user.timestamp().left(MAXIMUM_CHARS-3).append("...");
134 m_shortenedUpdated = m_user.timestamp();
136 if (m_user.note().length() > MAXIMUM_CHARS) {
137 m_shortenedStatusText = m_user.note().left(MAXIMUM_CHARS-3).append("...");
140 m_shortenedStatusText = m_user.note();
142 if (m_user.address().length() > MAXIMUM_CHARS) {
143 m_shortenedLocation = m_user.address().left(MAXIMUM_CHARS-3).append("...");
146 m_shortenedLocation = m_user.address();
150 void FriendListItem::toggleHeight()
153 m_nameLabel->setText(m_shortenedName);
154 m_updatedLabel->setText(m_shortenedUpdated);
155 m_statusTextLabel->setText(m_shortenedStatusText);
156 m_locationLabel->setText(m_shortenedLocation);
161 m_nameLabel->setText(m_user.name());
162 m_updatedLabel->setText(m_user.timestamp());
163 m_statusTextLabel->setText(m_user.note());
164 m_locationLabel->setText(m_user.address());
169 void FriendListItem::mousePressEvent(QMouseEvent *event)
171 m_mousePosition = event->pos();
174 void FriendListItem::mouseReleaseEvent(QMouseEvent *event)
176 qDebug() << __PRETTY_FUNCTION__;
178 if (event->pos() == m_mousePosition)
182 void FriendListItem::paintEvent(QPaintEvent *)
187 QPainter painter(this);
188 style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);