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 const QString BACKGROUND_PATH = ":/res/images/list_item.png"; ///< Background image path
36 const QString CLOCK_PATH = ":/res/images/clock.png"; ///< Clock image path
37 const QString COMPASS_PATH = ":/res/images/compass.png"; ///< Compass image path
38 const QString ENVELOPE_PATH = ":/res/images/envelope.png"; ///< Envelope image path
40 const int ICON_MARGIN = 5; ///< Icon margin
41 const int IMAGE_HEIGHT = 60; ///< Friend image height
42 const int IMAGE_WIDTH = 60; ///< Friend image width
44 const int ITEM_MAX_HEIGHT = 240; ///< Maximum height for item
45 const int ITEM_MAX_WIDTH = 368; ///< Maximum width for item
46 const int ITEM_MIN_HEIGHT = 141; ///< Minimum height for item
47 const int ITEM_MIN_WIDTH = 368; ///< Minimum width for item
48 const int LABEL_MAX_WIDTH = 350; ///< Label maximum width
50 FriendListItem::FriendListItem(QWidget *parent)
55 qDebug() << __PRETTY_FUNCTION__;
57 QVBoxLayout *layout = new QVBoxLayout(this);
58 this->setLayout(layout);
60 QHBoxLayout *topLayout = new QHBoxLayout();
61 topLayout->setMargin(0);
62 topLayout->setSpacing(0);
64 QHBoxLayout *bottomLayout = new QHBoxLayout();
65 bottomLayout->setMargin(0);
66 bottomLayout->setSpacing(0);
68 QFormLayout *infoLayout = new QFormLayout();
69 infoLayout->setMargin(0);
70 infoLayout->setSpacing(0);
72 QLabel *clockLabel = new QLabel();
73 clockLabel->setPixmap(QPixmap(CLOCK_PATH));
74 clockLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
75 QLabel *envelopeLabel = new QLabel();
76 envelopeLabel->setPixmap(QPixmap(ENVELOPE_PATH));
77 envelopeLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
78 QLabel *compassLabel = new QLabel();
79 compassLabel->setPixmap(QPixmap(COMPASS_PATH));
80 compassLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
82 m_imageLabel = new QLabel();
83 m_imageLabel->setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT);
84 m_nameLabel = new QLabel();
85 m_nameLabel->setFixedHeight(IMAGE_HEIGHT);
86 m_updatedLabel = new QLabel();
87 m_updatedLabel->setWordWrap(true);
88 m_statusTextLabel = new QLabel();
89 m_statusTextLabel->setWordWrap(true);
90 m_locationLabel = new QLabel();
91 m_locationLabel->setWordWrap(true);
93 infoLayout->addRow(clockLabel, m_updatedLabel);
94 infoLayout->addRow(envelopeLabel, m_statusTextLabel);
95 infoLayout->addRow(compassLabel, m_locationLabel);
97 topLayout->addWidget(m_imageLabel);
98 topLayout->addWidget(m_nameLabel);
100 bottomLayout->addSpacing(IMAGE_WIDTH);
101 bottomLayout->addLayout(infoLayout, 1);
103 layout->addLayout(topLayout, 0);
104 layout->addLayout(bottomLayout, 1);
106 setObjectName("listItem");
107 m_nameLabel->setObjectName("nameLabel");
109 setStyleSheet("#listItem { border-image: url(:/res/images/list_item.png) 20%; " \
110 "border-width: 20px 14px 16px 14px; } " \
111 "QLabel { font-size: 13pt; color: #989898; }" \
112 "#nameLabel { font-size: 18pt; color: #ffffff }");
114 setMinimumSize(ITEM_MIN_WIDTH, ITEM_MIN_HEIGHT);
115 setMaximumSize(ITEM_MAX_WIDTH, ITEM_MAX_HEIGHT);
118 void FriendListItem::setData(User *user)
120 qDebug() << __PRETTY_FUNCTION__;
126 m_imageLabel->setPixmap(m_user->profileImage());
131 void FriendListItem::shortenTexts()
133 qDebug() << __PRETTY_FUNCTION__ << m_user->address().length();
135 m_shortenedName = m_nameLabel->fontMetrics()
136 .elidedText(m_user->name(), Qt::ElideRight, LABEL_MAX_WIDTH);
137 m_shortenedUpdated = m_updatedLabel->fontMetrics()
138 .elidedText(m_user->timestamp(), Qt::ElideRight, LABEL_MAX_WIDTH);
139 m_shortenedStatusText = m_statusTextLabel->fontMetrics()
140 .elidedText(m_user->note(), Qt::ElideRight, LABEL_MAX_WIDTH);
141 m_shortenedLocation = m_locationLabel->fontMetrics()
142 .elidedText(m_user->address(), Qt::ElideRight, LABEL_MAX_WIDTH);
145 void FriendListItem::setText(bool expanded)
147 qDebug() << __PRETTY_FUNCTION__;
150 m_nameLabel->setText(m_user->name());
151 m_updatedLabel->setText(m_user->timestamp());
152 m_statusTextLabel->setText(m_user->note());
153 m_locationLabel->setText(m_user->address());
156 m_nameLabel->setText(m_shortenedName);
157 m_updatedLabel->setText(m_shortenedUpdated);
158 m_statusTextLabel->setText(m_shortenedStatusText);
159 m_locationLabel->setText(m_shortenedLocation);
163 void FriendListItem::mousePressEvent(QMouseEvent *event)
165 qDebug() << __PRETTY_FUNCTION__;
167 m_mousePosition = event->pos();
170 void FriendListItem::mouseReleaseEvent(QMouseEvent *event)
172 qDebug() << __PRETTY_FUNCTION__;
174 if (event->pos() == m_mousePosition) {
186 void FriendListItem::paintEvent(QPaintEvent *)
188 qDebug() << __PRETTY_FUNCTION__;
193 QPainter painter(this);
194 style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);