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
8 Henri Lampela - henri.lampela@ixonos.com
9 Ville Tiensuu - ville.tiensuu@ixonos.com
11 Situare is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 version 2 as published by the Free Software Foundation.
15 Situare is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with Situare; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
26 #include <QFormLayout>
28 #include <QMouseEvent>
31 #include <QVBoxLayout>
34 #include "imagebutton.h"
35 #include "tagsdialog.h"
36 #include "textmodifier.h"
37 #include "user/user.h"
41 const int BACKGROUND_BOTTOM_HEIGHT = 15;
42 const int BACKGROUND_TOP_HEIGHT = 20;
43 const int BACKGROUND_WIDTH = 368;
44 const int ICON_HEIGHT = 24;
45 const int ICON_WIDTH = 24;
47 const int LABEL_MAX_WIDTH = BACKGROUND_WIDTH - ICON_WIDTH - 5 * MARGIN;
49 UserInfo::UserInfo(QWidget *parent)
55 qDebug() << __PRETTY_FUNCTION__;
57 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
58 verticalLayout->setContentsMargins(MARGIN * 2, 0, MARGIN * 2, MARGIN * 2);
59 verticalLayout->setSpacing(0);
60 setLayout(verticalLayout);
62 QFormLayout *infoLayout = new QFormLayout();
63 infoLayout->setMargin(0);
64 infoLayout->setSpacing(0);
66 QLabel *envelopeLabel = new QLabel();
67 envelopeLabel->setPixmap(QPixmap(":/res/images/envelope.png"));
68 envelopeLabel->setContentsMargins(0, 0, MARGIN, 0);
69 envelopeLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
70 QLabel *compassLabel = new QLabel();
71 compassLabel->setPixmap(QPixmap(":/res/images/compass.png"));
72 compassLabel->setContentsMargins(0, 0, MARGIN, 0);
73 compassLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
74 QLabel *clockLabel = new QLabel();
75 clockLabel->setPixmap(QPixmap(":/res/images/clock.png"));
76 clockLabel->setContentsMargins(0, 0, MARGIN, 0);
77 clockLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
78 QLabel *tagsLabel = new QLabel();
79 tagsLabel->setPixmap(QPixmap(":/res/images/tag.png"));
80 tagsLabel->setContentsMargins(0, 0, MARGIN, 0);
81 tagsLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
83 m_avatar = new ImageButton();
85 m_nameLabel = new QLabel();
87 m_statusTextLabel = new QLabel();
88 m_statusTextLabel->setWordWrap(true);
89 m_statusTextLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
90 m_locationLabel = new QLabel();
91 m_locationLabel->setWordWrap(true);
92 m_locationLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
93 m_updatedLabel = new QLabel();
94 m_updatedLabel->setWordWrap(true);
95 m_updatedLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
96 m_tagsTextLabel = new QLabel();
97 m_tagsTextLabel->setWordWrap(true);
98 m_tagsTextLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
101 infoLayout->addRow(envelopeLabel, m_statusTextLabel);
102 infoLayout->addRow(compassLabel, m_locationLabel);
103 infoLayout->addRow(clockLabel, m_updatedLabel);
104 infoLayout->addRow(tagsLabel, m_tagsTextLabel);
106 verticalLayout->addWidget(m_avatar, 0, Qt::AlignHCenter);
107 verticalLayout->addWidget(m_nameLabel, 0, Qt::AlignHCenter);
108 verticalLayout->addLayout(infoLayout);
110 connect(m_avatar, SIGNAL(clicked()),
111 this, SLOT(findButtonClicked()));
113 setFixedWidth(BACKGROUND_WIDTH);
115 this->setFont(NOKIA_FONT_SMALL);
116 m_nameLabel->setFont(NOKIA_FONT_NORMAL);
117 QPalette itemPalette = palette();
118 itemPalette.setColor(QPalette::Foreground, COLOR_GRAY);
119 setPalette(itemPalette);
120 QPalette namePalette = m_nameLabel->palette();
121 namePalette.setColor(QPalette::Foreground, Qt::white);
122 m_nameLabel->setPalette(namePalette);
124 m_backgroundTopImage.load(":/res/images/list_item_top.png");
125 m_backgroundMiddleImage.load(":/res/images/list_item_middle.png");
126 m_backgroundBottomImage.load(":/res/images/list_item_bottom.png");
127 m_backgroundTopSelectedImage.load(":/res/images/list_item_top_selected.png");
128 m_backgroundMiddleSelectedImage.load(":/res/images/list_item_middle_selected.png");
129 m_backgroundBottomSelectedImage.load(":/res/images/list_item_bottom_selected.png");
131 restoreUnsendMessage();
134 UserInfo::~UserInfo()
136 qDebug() << __PRETTY_FUNCTION__;
138 QSettings settings(DIRECTORY_NAME, FILE_NAME);
140 if (!m_backupMessage.isEmpty()) {
141 settings.setValue(USER_UNSEND_MESSAGE, m_backupMessage.toAscii());
142 settings.setValue(USER_UNSEND_MESSAGE_PUBLISH, m_backupFacebookPublishPolicity);
144 settings.remove(USER_UNSEND_MESSAGE);
145 settings.remove(USER_UNSEND_MESSAGE_PUBLISH);
149 void UserInfo::backupUpdateLocationDialogData(const QString &status, bool publish)
151 qDebug() << __PRETTY_FUNCTION__;
153 m_backupMessage = status;
154 m_backupFacebookPublishPolicity = publish;
157 void UserInfo::clearUpdateLocationDialogData()
159 qDebug() << __PRETTY_FUNCTION__;
161 m_backupMessage.clear();
162 m_backupFacebookPublishPolicity = false;
165 void UserInfo::collapse()
167 qDebug() << __PRETTY_FUNCTION__;
172 void UserInfo::findButtonClicked()
174 qDebug() << __PRETTY_FUNCTION__;
176 emit findUser(m_coordinates);
179 void UserInfo::messageUpdate()
181 qDebug() << __PRETTY_FUNCTION__;
183 delete m_updateLocation;
184 m_updateLocation = new UpdateLocationDialog(m_backupMessage, m_backupFacebookPublishPolicity,
187 connect(this, SIGNAL(reverseGeoReady(QString)),
188 m_updateLocation, SLOT(setAddress(QString)));
190 connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
191 this, SIGNAL(statusUpdate(QString, bool)));
193 connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
194 this, SLOT(backupUpdateLocationDialogData(QString, bool)));
196 connect(m_updateLocation, SIGNAL(finished(int)),
197 this, SLOT(updateLocationDialogFinished(int)));
199 m_updateLocation->show();
201 emit requestReverseGeo();
204 void UserInfo::mousePressEvent(QMouseEvent *event)
206 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
208 m_mousePosition = event->pos();
211 void UserInfo::mouseReleaseEvent(QMouseEvent *event)
213 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
215 const int MOUSE_PRESS_AREA_HEIGHT = 20;
216 const int MOUSE_PRESS_AREA_WIDTH = 20;
218 if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH)
219 && (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
222 //m_expanded = false;
231 void UserInfo::paintEvent(QPaintEvent *event)
233 qDebug() << __PRETTY_FUNCTION__ << " " << event->rect();
235 QPainter painter(this);
237 QRect topRect = QRect(0, MARGIN, BACKGROUND_WIDTH, BACKGROUND_TOP_HEIGHT);
239 QRect middleRect = QRect(topRect.left(), topRect.bottom(), BACKGROUND_WIDTH,
240 height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
242 QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), BACKGROUND_WIDTH,
243 BACKGROUND_BOTTOM_HEIGHT);
246 painter.drawPixmap(topRect, m_backgroundTopSelectedImage);
247 painter.drawPixmap(middleRect, m_backgroundMiddleSelectedImage);
248 painter.drawPixmap(bottomRect, m_backgroundBottomSelectedImage);
250 painter.drawPixmap(topRect, m_backgroundTopImage);
251 painter.drawPixmap(middleRect, m_backgroundMiddleImage);
252 painter.drawPixmap(bottomRect, m_backgroundBottomImage);
256 void UserInfo::restoreUnsendMessage()
258 qDebug() << __PRETTY_FUNCTION__;
260 QSettings settings(DIRECTORY_NAME, FILE_NAME);
261 m_backupMessage = settings.value(USER_UNSEND_MESSAGE, EMPTY).toString();
262 m_backupFacebookPublishPolicity = settings.value(USER_UNSEND_MESSAGE_PUBLISH, false).toBool();
265 void UserInfo::setAddress(const QString &address)
267 qDebug() << __PRETTY_FUNCTION__;
269 m_locationLabel->setText(address);
272 void UserInfo::setCoordinates(const GeoCoordinate &coordinates)
274 qDebug() << __PRETTY_FUNCTION__;
276 m_coordinates = coordinates;
279 void UserInfo::setMessageText(const QString &text)
281 qDebug() << __PRETTY_FUNCTION__;
283 m_messageText = TextModifier::splitLongWords(m_statusTextLabel->fontMetrics(), text,
289 void UserInfo::setProfileImage(const QPixmap &image)
291 qDebug() << __PRETTY_FUNCTION__;
294 m_avatar->setButtonIcon(image);
297 void UserInfo::setExpanded(bool expanded)
299 qDebug() << __PRETTY_FUNCTION__;
301 m_expanded = expanded;
304 m_statusTextLabel->setText(m_messageText);
306 m_statusTextLabel->setText(TextModifier::shortenText(m_statusTextLabel->fontMetrics(),
307 m_messageText, LABEL_MAX_WIDTH));
311 emit itemSelectionChanged(expanded);
314 void UserInfo::setTags(const QHash<QString, QString> &tags)
316 qDebug() << __PRETTY_FUNCTION__;
322 QHashIterator<QString, QString> tagsIterator(tags);
323 while (tagsIterator.hasNext()) {
325 tagsText.append("[" + tagsIterator.value() + "] ");
328 m_tagsTextLabel->setText(tagsText);
331 m_tagsDialog->populateUserTags(m_userTags);
334 void UserInfo::setPopularTags(const QHash<QString, QString> &tags)
336 qDebug() << __PRETTY_FUNCTION__;
339 m_tagsDialog->populatePopularTags(tags);
342 void UserInfo::setTime(const QString &time)
344 qDebug() << __PRETTY_FUNCTION__;
346 m_updatedLabel->setText(time);
349 void UserInfo::setUserName(const QString &name)
351 qDebug() << __PRETTY_FUNCTION__;
355 m_nameLabel->setText(TextModifier::shortenText(m_nameLabel->fontMetrics(), m_userName,
359 void UserInfo::showTagsDialog()
361 qDebug() << __PRETTY_FUNCTION__;
363 m_tagsDialog = new TagsDialog(m_userTags, this);
364 connect(m_tagsDialog, SIGNAL(finished(int)),
365 this, SLOT(tagsDialogFinished(int)));
366 m_tagsDialog->show();
369 void UserInfo::tagsDialogFinished(int reason)
371 qDebug() << __PRETTY_FUNCTION__;
374 if (reason == QDialog::Accepted) {
375 QStringList removedTagsIds;
377 foreach (QString removedTag, m_tagsDialog->removedTags())
378 removedTagsIds.append(m_userTags.key(removedTag));
380 if (!removedTagsIds.isEmpty())
381 emit removeTags(removedTagsIds);
382 if (!m_tagsDialog->newTags().isEmpty())
383 emit addTags(m_tagsDialog->newTags());
386 m_tagsDialog->deleteLater();
391 void UserInfo::updateLocationDialogFinished(int reason)
393 qDebug() << __PRETTY_FUNCTION__;
397 if (m_updateLocation) {
398 disconnect(this, SIGNAL(reverseGeoReady(QString)),
399 m_updateLocation, SLOT(setAddress(QString)));
401 disconnect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
402 this, SIGNAL(statusUpdate(QString,bool)));
404 disconnect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
405 this, SLOT(backupUpdateLocationDialogData(QString,bool)));
407 disconnect(m_updateLocation, SIGNAL(finished(int)),
408 this, SLOT(updateLocationDialogFinished(int)));
410 m_updateLocation->deleteLater();
411 m_updateLocation = 0;