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 const int IMAGE_WIDTH = 60;
41 const int IMAGE_HEIGHT = 60;
43 const int ITEM_MIN_WIDTH = 368;
44 const int ITEM_MAX_WIDTH = 368;
45 const int ITEM_MIN_HEIGHT = 141;
46 const int ITEM_MAX_HEIGHT = 240;
47 const int ICON_MARGIN = 5;
49 const QString BACKGROUND_PATH = QString(":/res/images/list_item.png");
50 const QString CLOCK_PATH = QString(":/res/images/clock.png");
51 const QString ENVELOPE_PATH = QString(":/res/images/envelope.png");
52 const QString COMPASS_PATH = QString(":/res/images/compass.png");
54 const int MAXIMUM_CHARS = 32;
56 FriendListItem::FriendListItem(QWidget *parent)
60 QVBoxLayout *layout = new QVBoxLayout(this);
61 this->setLayout(layout);
63 QHBoxLayout *topLayout = new QHBoxLayout();
64 topLayout->setMargin(0);
65 topLayout->setSpacing(0);
67 QHBoxLayout *bottomLayout = new QHBoxLayout();
68 bottomLayout->setMargin(0);
69 bottomLayout->setSpacing(0);
70 m_infoWidget = new QWidget(this);
72 QFormLayout *infoLayout = new QFormLayout();
73 infoLayout->setMargin(0);
74 infoLayout->setSpacing(0);
75 m_infoWidget->setLayout(infoLayout);
77 QLabel *clockLabel = new QLabel(this);
78 clockLabel->setPixmap(QPixmap(CLOCK_PATH));
79 clockLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
80 QLabel *envelopeLabel = new QLabel(this);
81 envelopeLabel->setPixmap(QPixmap(ENVELOPE_PATH));
82 envelopeLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
83 QLabel *compassLabel = new QLabel(this);
84 compassLabel->setPixmap(QPixmap(COMPASS_PATH));
85 compassLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
87 m_imageLabel = new QLabel(this);
88 m_imageLabel->setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT);
89 m_nameLabel = new QLabel("", this);
90 m_nameLabel->setFixedHeight(IMAGE_HEIGHT);
91 m_updatedLabel = new QLabel("", this);
92 m_updatedLabel->setWordWrap(true);
93 m_statusTextLabel = new QLabel("", this);
94 m_statusTextLabel->setWordWrap(true);
95 m_locationLabel = new QLabel("", this);
96 m_locationLabel->setWordWrap(true);
98 infoLayout->addRow(clockLabel, m_updatedLabel);
99 infoLayout->addRow(envelopeLabel, m_statusTextLabel);
100 infoLayout->addRow(compassLabel, m_locationLabel);
102 topLayout->addWidget(m_imageLabel);
103 topLayout->addWidget(m_nameLabel);
105 QLabel *tmp = new QLabel(this);
106 bottomLayout->addSpacerItem(new QSpacerItem(IMAGE_WIDTH, IMAGE_HEIGHT));
107 bottomLayout->addWidget(m_infoWidget, 1);
109 layout->addLayout(topLayout, 0);
110 layout->addLayout(bottomLayout, 1);
112 this->setObjectName("listItem");
113 m_infoWidget->setObjectName("infoWidget");
114 m_nameLabel->setObjectName("nameLabel");
116 this->setStyleSheet("#listItem { border-image: url(:/res/images/list_item.png) 20%; " \
117 "border-width: 20px 14px 16px 14px; } " \
118 "QLabel { font-size: 13pt; color: #989898; }" \
119 "#nameLabel { font-size: 18pt; color: #ffffff }");
121 this->setMinimumSize(ITEM_MIN_WIDTH, ITEM_MIN_HEIGHT);
122 this->setMaximumSize(ITEM_MAX_WIDTH, ITEM_MAX_HEIGHT);
125 void FriendListItem::setData(const User &user)
131 m_imageLabel->setPixmap(m_user.profileImage());
132 m_nameLabel->setText(m_shortenedName);
133 m_updatedLabel->setText(m_shortenedUpdated);
134 m_statusTextLabel->setText(m_shortenedStatusText);
135 m_locationLabel->setText(m_shortenedLocation);
136 m_image = user.profileImageUrl().toString();
140 void FriendListItem::shortenTexts()
142 if (m_user.name().length() > MAXIMUM_CHARS) {
143 m_shortenedName = m_user.name().left(MAXIMUM_CHARS-3).append("...");
146 m_shortenedName = m_user.name();
148 if (m_user.timestamp().length() > MAXIMUM_CHARS) {
149 m_shortenedUpdated = m_user.timestamp().left(MAXIMUM_CHARS-3).append("...");
152 m_shortenedUpdated = m_user.timestamp();
154 if (m_user.note().length() > MAXIMUM_CHARS) {
155 m_shortenedStatusText = m_user.note().left(MAXIMUM_CHARS-3).append("...");
158 m_shortenedStatusText = m_user.note();
160 if (m_user.address().length() > MAXIMUM_CHARS) {
161 m_shortenedLocation = m_user.address().left(MAXIMUM_CHARS-3).append("...");
164 m_shortenedLocation = m_user.address();
168 void FriendListItem::toggleHeight()
171 m_nameLabel->setText(m_shortenedName);
172 m_updatedLabel->setText(m_shortenedUpdated);
173 m_statusTextLabel->setText(m_shortenedStatusText);
174 m_locationLabel->setText(m_shortenedLocation);
179 m_nameLabel->setText(m_user.name());
180 m_updatedLabel->setText(m_user.timestamp());
181 m_statusTextLabel->setText(m_user.note());
182 m_locationLabel->setText(m_user.address());
187 void FriendListItem::mousePressEvent(QMouseEvent *event)
189 m_mousePosition = event->pos();
192 void FriendListItem::mouseReleaseEvent(QMouseEvent *event)
194 qDebug() << __PRETTY_FUNCTION__;
196 if (event->pos() == m_mousePosition)
200 void FriendListItem::paintEvent(QPaintEvent *)
205 QPainter painter(this);
206 style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);