2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Jukka Saastamoinen - jukka.saastamoinen@ixonos.com
6 Jussi Laitinen - jussi.laitinen@ixonos.com
7 Katri Kaikkonen - katri.kaikkonen@ixonos.com
9 Situare is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 version 2 as published by the Free Software Foundation.
13 Situare is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Situare; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24 #include <QVBoxLayout>
25 #include <QPushButton>
28 #include <QPaintEvent>
31 #include <QFormLayout>
32 #include <QSpacerItem>
33 #include <QStylePainter>
36 #include "imagebutton.h"
37 #include "avatarimage.h"
38 #include "../user/user.h"
41 UserInfo::UserInfo(QWidget *parent)
45 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
46 verticalLayout->setContentsMargins(MARGIN, 0, MARGIN*2, MARGIN*2);
47 verticalLayout->setSpacing(0);
48 setLayout(verticalLayout);
50 QGridLayout *gridLayout = new QGridLayout(this);
51 gridLayout->setMargin(0);
52 gridLayout->setSpacing(0);
54 QHBoxLayout *topLayout = new QHBoxLayout(this);
55 topLayout->setMargin(0);
56 topLayout->setSpacing(0);
58 QFormLayout *infoLayout = new QFormLayout(this);
59 infoLayout->setMargin(0);
60 infoLayout->setSpacing(0);
62 QHBoxLayout *buttonLayout = new QHBoxLayout(this);
63 buttonLayout->setMargin(0);
64 buttonLayout->setSpacing(0);
66 QLabel *clockLabel = new QLabel();
67 clockLabel->setPixmap(QPixmap(":/res/images/clock.png"));
68 clockLabel->setContentsMargins(0, 0, MARGIN, 0);
69 clockLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
70 QLabel *envelopeLabel = new QLabel();
71 envelopeLabel->setPixmap(QPixmap(":/res/images/envelope.png"));
72 envelopeLabel->setContentsMargins(0, 0, MARGIN, 0);
73 envelopeLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
74 QLabel *compassLabel = new QLabel();
75 compassLabel->setPixmap(QPixmap(":/res/images/compass.png"));
76 compassLabel->setContentsMargins(0, 0, MARGIN, 0);
77 compassLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
79 m_imageLabel = new QLabel();
80 m_imageLabel->setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT);
81 m_imageLabel->setAlignment(Qt::AlignHCenter);
83 m_nameLabel = new QLabel();
84 m_nameLabel->setFixedHeight(IMAGE_HEIGHT);
85 m_nameLabel->setAlignment(Qt::AlignHCenter);
87 m_updatedLabel = new QLabel();
88 m_updatedLabel->setWordWrap(true);
89 m_statusTextLabel = new QLabel();
90 m_statusTextLabel->setWordWrap(true);
91 m_locationLabel = new QLabel();
92 m_locationLabel->setWordWrap(true);
94 ImageButton *updateFriendsButton = new ImageButton(this, ":/res/images/refresh.png",
95 ":/res/images/refresh_s.png");
96 ImageButton *updateStatusMessageButton = new ImageButton(this, ":/res/images/send_position.png",
97 ":/res/images/send_position_s.png");
99 buttonLayout->addWidget(updateFriendsButton);
100 buttonLayout->addWidget(updateStatusMessageButton);
103 infoLayout->addRow(compassLabel, m_locationLabel);
104 infoLayout->addRow(envelopeLabel, m_statusTextLabel);
105 infoLayout->addRow(clockLabel, m_updatedLabel);
107 topLayout->addWidget(m_nameLabel);
109 gridLayout->addWidget(m_imageLabel);
111 verticalLayout->addLayout(gridLayout, 0);
112 verticalLayout->addLayout(topLayout, 1);
113 verticalLayout->addLayout(infoLayout);
114 verticalLayout->addLayout(buttonLayout, 2 );
116 connect(updateStatusMessageButton,SIGNAL(clicked()),
117 this,SLOT(messageUpdate()));
118 connect(updateFriendsButton,SIGNAL(clicked()),
119 this, SIGNAL(refreshUserData()));
121 this->setFont(NOKIA_FONT_SMALL);
122 m_nameLabel->setFont(NOKIA_FONT_NORMAL);
123 QPalette itemPalette = palette();
124 itemPalette.setColor(QPalette::Foreground, COLOR_GRAY);
125 setPalette(itemPalette);
126 QPalette namePalette = m_nameLabel->palette();
127 namePalette.setColor(QPalette::Foreground, Qt::white);
128 m_nameLabel->setPalette(namePalette);
130 this->setMinimumHeight(300);
132 m_backgroundTopImage.load(":/res/images/list_item_top.png");
133 m_backgroundMiddleImage.load(":/res/images/list_item_middle.png");
134 m_backgroundBottomImage.load(":/res/images/list_item_bottom.png");
137 void UserInfo::setUserName(const QString &name)
139 qDebug() << __PRETTY_FUNCTION__;
142 // m_nameLabel->setText(name);
147 void UserInfo::setAvatar(const QPixmap &image)
150 // m_imageLabel->setPixmap(AvatarImage::create(m_avatar.profileImage()));
151 //m_imageLabel->setPixmap(AvatarImage::create(m_avatar.profileImage()));
152 m_imageLabel->setPixmap(m_avatar);
156 void UserInfo::setMessageText(const QString &text)
158 if(m_messageText == text)
160 m_messageText = text;
161 // m_statusTextLabel->setText(m_messageText);
165 void UserInfo::setAddress(const QString &addr)
167 qDebug() << __PRETTY_FUNCTION__;
169 // m_locationLabel->setText(addr);
173 void UserInfo::setTime(const QString &tim)
178 // m_updatedLabel->setText(m_time);
183 void UserInfo::shortenTexts()
185 qDebug() << __PRETTY_FUNCTION__;
187 QFontMetrics nameLabelMetrics = m_nameLabel->fontMetrics();
188 QFontMetrics otherLabelsMetrics = m_locationLabel->fontMetrics();
190 QString name = m_userName;
191 QString updated = m_time;
192 QString statusText = m_messageText;
193 QString location = m_address;
195 int nameIndex = name.indexOf('\n');
196 int updatedIndex = updated.indexOf('\n');
197 int statusTextIndex = statusText.indexOf('\n');
198 int locationIndex = location.indexOf('\n');
201 name.truncate(nameIndex);
204 if (updatedIndex > 0) {
205 updated.truncate(updatedIndex);
206 updated.append("...");
208 if (statusTextIndex > 0) {
209 statusText.truncate(statusTextIndex);
210 statusText.append("...");
212 if (locationIndex > 0) {
213 location.truncate(locationIndex);
214 location.append("...");
217 m_shortenedName = nameLabelMetrics.elidedText(name, Qt::ElideRight, LABEL_MAX_WIDTH + 30);
218 m_shortenedUpdated = otherLabelsMetrics.elidedText(updated, Qt::ElideRight, LABEL_MAX_WIDTH);
219 m_shortenedStatusText = otherLabelsMetrics.elidedText(statusText, Qt::ElideRight,
221 m_shortenedLocation = otherLabelsMetrics.elidedText(location, Qt::ElideRight, LABEL_MAX_WIDTH);
224 void UserInfo::setText(bool expanded)
226 qDebug() << __PRETTY_FUNCTION__;
229 m_nameLabel->setText(m_userName);
230 m_updatedLabel->setText(m_time);
231 m_statusTextLabel->setText(m_messageText);
232 m_locationLabel->setText(m_address);
235 m_nameLabel->setText(m_shortenedName);
236 m_updatedLabel->setText(m_shortenedUpdated);
237 m_statusTextLabel->setText(m_shortenedStatusText);
238 m_locationLabel->setText(m_shortenedLocation);
242 void UserInfo::mouseReleaseEvent(QMouseEvent *event)
244 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
246 if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH) &&
247 (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
250 // m_expanded = false;
254 // m_expanded = true;
258 void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
260 // Q_UNUSED(aPaintEvent);
262 // QStyleOption option;
263 // option.init(this);
264 // QStylePainter painter(this);
266 // // Temporary border
267 // painter.setPen(Qt::red);
268 // painter.drawRect(this->rect().x(), this->rect().y(), this->rect().width() - 1, this->rect().height() - 1);
270 // style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
272 qDebug() << __PRETTY_FUNCTION__ << " " << aPaintEvent->rect();
274 QPainter painter(this);
276 QRect topRect = QRect(0, 0, ITEM_MIN_WIDTH, BACKGROUND_TOP_HEIGHT);
277 QRect middleRect = QRect(0, topRect.bottom(), ITEM_MIN_WIDTH,
278 height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
279 QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), ITEM_MIN_WIDTH,
280 BACKGROUND_BOTTOM_HEIGHT);
282 painter.drawPixmap(topRect, m_backgroundTopImage);
283 painter.drawPixmap(middleRect, m_backgroundMiddleImage);
284 painter.drawPixmap(bottomRect, m_backgroundBottomImage);
288 void UserInfo::mousePressEvent(QMouseEvent *event)
290 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
292 m_mousePosition = event->pos();
295 void UserInfo::messageUpdate()
297 qDebug() << __PRETTY_FUNCTION__;
299 m_locationDialog = new UpdateLocationDialog(this);
300 emit requestReverseGeo();
302 connect(this, SIGNAL(reverseGeoReady(QString)),
303 m_locationDialog, SLOT(setAddress(QString)));
304 connect(m_locationDialog, SIGNAL(statusUpdate(QString, bool)),
305 this, SIGNAL(statusUpdate(QString, bool)));
307 m_locationDialog->show();
310 //void UserInfo::updateFriendsStatus()
312 // qDebug() << __PRETTY_FUNCTION__;
313 // //emit launchUpdateFriendsStatus();