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)
54 qDebug() << __PRETTY_FUNCTION__;
56 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
57 verticalLayout->setContentsMargins(MARGIN * 2, 0, MARGIN * 2, MARGIN * 2);
58 verticalLayout->setSpacing(0);
59 setLayout(verticalLayout);
61 QFormLayout *infoLayout = new QFormLayout();
62 infoLayout->setMargin(0);
63 infoLayout->setSpacing(0);
65 QLabel *envelopeLabel = new QLabel();
66 envelopeLabel->setPixmap(QPixmap(":/res/images/envelope.png"));
67 envelopeLabel->setContentsMargins(0, 0, MARGIN, 0);
68 envelopeLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
69 QLabel *compassLabel = new QLabel();
70 compassLabel->setPixmap(QPixmap(":/res/images/compass.png"));
71 compassLabel->setContentsMargins(0, 0, MARGIN, 0);
72 compassLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
73 QLabel *clockLabel = new QLabel();
74 clockLabel->setPixmap(QPixmap(":/res/images/clock.png"));
75 clockLabel->setContentsMargins(0, 0, MARGIN, 0);
76 clockLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
77 QLabel *tagsLabel = new QLabel();
78 tagsLabel->setPixmap(QPixmap(":/res/images/tag.png"));
79 tagsLabel->setContentsMargins(0, 0, MARGIN, 0);
80 tagsLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
82 m_avatar = new ImageButton();
84 m_nameLabel = new QLabel();
86 m_statusTextLabel = new QLabel();
87 m_statusTextLabel->setWordWrap(true);
88 m_statusTextLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
89 m_locationLabel = new QLabel();
90 m_locationLabel->setWordWrap(true);
91 m_locationLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
92 m_updatedLabel = new QLabel();
93 m_updatedLabel->setWordWrap(true);
94 m_updatedLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
95 m_tagsTextLabel = new QLabel();
96 m_tagsTextLabel->setWordWrap(true);
97 m_tagsTextLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
100 infoLayout->addRow(envelopeLabel, m_statusTextLabel);
101 infoLayout->addRow(compassLabel, m_locationLabel);
102 infoLayout->addRow(clockLabel, m_updatedLabel);
103 infoLayout->addRow(tagsLabel, m_tagsTextLabel);
105 verticalLayout->addWidget(m_avatar, 0, Qt::AlignHCenter);
106 verticalLayout->addWidget(m_nameLabel, 0, Qt::AlignHCenter);
107 verticalLayout->addLayout(infoLayout);
109 connect(m_avatar, SIGNAL(clicked()),
110 this, SLOT(findButtonClicked()));
112 setFixedWidth(BACKGROUND_WIDTH);
114 this->setFont(NOKIA_FONT_SMALL);
115 m_nameLabel->setFont(NOKIA_FONT_NORMAL);
116 QPalette itemPalette = palette();
117 itemPalette.setColor(QPalette::Foreground, COLOR_GRAY);
118 setPalette(itemPalette);
119 QPalette namePalette = m_nameLabel->palette();
120 namePalette.setColor(QPalette::Foreground, Qt::white);
121 m_nameLabel->setPalette(namePalette);
123 m_backgroundTopImage.load(":/res/images/list_item_top.png");
124 m_backgroundMiddleImage.load(":/res/images/list_item_middle.png");
125 m_backgroundBottomImage.load(":/res/images/list_item_bottom.png");
126 m_backgroundTopSelectedImage.load(":/res/images/list_item_top_selected.png");
127 m_backgroundMiddleSelectedImage.load(":/res/images/list_item_middle_selected.png");
128 m_backgroundBottomSelectedImage.load(":/res/images/list_item_bottom_selected.png");
130 restoreUnsendMessage();
133 UserInfo::~UserInfo()
135 qDebug() << __PRETTY_FUNCTION__;
137 QSettings settings(DIRECTORY_NAME, FILE_NAME);
139 if (!m_backupMessage.isEmpty()) {
140 settings.setValue(USER_UNSEND_MESSAGE, m_backupMessage.toAscii());
141 settings.setValue(USER_UNSEND_MESSAGE_PUBLISH, m_backupFacebookPublishPolicity);
143 settings.remove(USER_UNSEND_MESSAGE);
144 settings.remove(USER_UNSEND_MESSAGE_PUBLISH);
148 void UserInfo::backupUpdateLocationDialogData(const QString &status, bool publish)
150 qDebug() << __PRETTY_FUNCTION__;
152 m_backupMessage = status;
153 m_backupFacebookPublishPolicity = publish;
156 void UserInfo::clearUpdateLocationDialogData()
158 qDebug() << __PRETTY_FUNCTION__;
160 m_backupMessage.clear();
161 m_backupFacebookPublishPolicity = false;
164 void UserInfo::collapse()
166 qDebug() << __PRETTY_FUNCTION__;
171 void UserInfo::findButtonClicked()
173 qDebug() << __PRETTY_FUNCTION__;
175 emit findUser(m_coordinates);
178 void UserInfo::messageUpdate()
180 qDebug() << __PRETTY_FUNCTION__;
182 delete m_updateLocation;
183 m_updateLocation = new UpdateLocationDialog(m_backupMessage, m_backupFacebookPublishPolicity,
186 connect(this, SIGNAL(reverseGeoReady(QString)),
187 m_updateLocation, SLOT(setAddress(QString)));
189 connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
190 this, SIGNAL(statusUpdate(QString, bool)));
192 connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
193 this, SLOT(backupUpdateLocationDialogData(QString, bool)));
195 connect(m_updateLocation, SIGNAL(finished(int)),
196 this, SLOT(updateLocationDialogFinished(int)));
198 m_updateLocation->show();
200 emit requestReverseGeo();
203 void UserInfo::mousePressEvent(QMouseEvent *event)
205 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
207 m_mousePosition = event->pos();
210 void UserInfo::mouseReleaseEvent(QMouseEvent *event)
212 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
214 const int MOUSE_PRESS_AREA_HEIGHT = 20;
215 const int MOUSE_PRESS_AREA_WIDTH = 20;
217 if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH)
218 && (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
221 //m_expanded = false;
230 void UserInfo::paintEvent(QPaintEvent *event)
232 qDebug() << __PRETTY_FUNCTION__ << " " << event->rect();
234 QPainter painter(this);
236 QRect topRect = QRect(0, MARGIN, BACKGROUND_WIDTH, BACKGROUND_TOP_HEIGHT);
238 QRect middleRect = QRect(topRect.left(), topRect.bottom(), BACKGROUND_WIDTH,
239 height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
241 QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), BACKGROUND_WIDTH,
242 BACKGROUND_BOTTOM_HEIGHT);
245 painter.drawPixmap(topRect, m_backgroundTopSelectedImage);
246 painter.drawPixmap(middleRect, m_backgroundMiddleSelectedImage);
247 painter.drawPixmap(bottomRect, m_backgroundBottomSelectedImage);
249 painter.drawPixmap(topRect, m_backgroundTopImage);
250 painter.drawPixmap(middleRect, m_backgroundMiddleImage);
251 painter.drawPixmap(bottomRect, m_backgroundBottomImage);
255 void UserInfo::restoreUnsendMessage()
257 qDebug() << __PRETTY_FUNCTION__;
259 QSettings settings(DIRECTORY_NAME, FILE_NAME);
260 m_backupMessage = settings.value(USER_UNSEND_MESSAGE, EMPTY).toString();
261 m_backupFacebookPublishPolicity = settings.value(USER_UNSEND_MESSAGE_PUBLISH, false).toBool();
264 void UserInfo::setAddress(const QString &address)
266 qDebug() << __PRETTY_FUNCTION__;
268 m_locationLabel->setText(address);
271 void UserInfo::setCoordinates(const GeoCoordinate &coordinates)
273 qDebug() << __PRETTY_FUNCTION__;
275 m_coordinates = coordinates;
278 void UserInfo::setMessageText(const QString &text)
280 qDebug() << __PRETTY_FUNCTION__;
282 m_messageText = TextModifier::splitLongWords(m_statusTextLabel->fontMetrics(), text,
288 void UserInfo::setProfileImage(const QPixmap &image)
290 qDebug() << __PRETTY_FUNCTION__;
293 m_avatar->setButtonIcon(image);
296 void UserInfo::setExpanded(bool expanded)
298 qDebug() << __PRETTY_FUNCTION__;
300 m_expanded = expanded;
303 m_statusTextLabel->setText(m_messageText);
305 m_statusTextLabel->setText(TextModifier::shortenText(m_statusTextLabel->fontMetrics(),
306 m_messageText, LABEL_MAX_WIDTH));
310 emit itemSelectionChanged(expanded);
313 void UserInfo::setTags(const QHash<QString, QString> &tags)
315 qDebug() << __PRETTY_FUNCTION__;
321 QHashIterator<QString, QString> tagsIterator(tags);
322 while (tagsIterator.hasNext()) {
324 tagsText.append("[" + tagsIterator.value() + "] ");
327 m_tagsTextLabel->setText(tagsText);
330 m_tagsDialog->populateUserTags(m_userTags);
333 void UserInfo::setTime(const QString &time)
335 qDebug() << __PRETTY_FUNCTION__;
337 m_updatedLabel->setText(time);
340 void UserInfo::setUserName(const QString &name)
342 qDebug() << __PRETTY_FUNCTION__;
346 m_nameLabel->setText(TextModifier::shortenText(m_nameLabel->fontMetrics(), m_userName,
350 void UserInfo::showTagsDialog()
352 qDebug() << __PRETTY_FUNCTION__;
354 m_tagsDialog = new TagsDialog(m_userTags, this);
355 connect(m_tagsDialog, SIGNAL(finished(int)),
356 this, SLOT(tagsDialogFinished(int)));
357 m_tagsDialog->show();
360 void UserInfo::tagsDialogFinished(int reason)
362 qDebug() << __PRETTY_FUNCTION__;
365 if (reason == QDialog::Accepted) {
366 QStringList removedTagsIds;
368 foreach (QString removedTag, m_tagsDialog->removedTags())
369 removedTagsIds.append(m_userTags.key(removedTag));
371 if (!removedTagsIds.isEmpty())
372 emit removeTags(removedTagsIds);
373 if (!m_tagsDialog->newTags().isEmpty())
374 emit addTags(m_tagsDialog->newTags());
377 m_tagsDialog->deleteLater();
382 void UserInfo::updateLocationDialogFinished(int reason)
384 qDebug() << __PRETTY_FUNCTION__;
388 if (m_updateLocation) {
389 disconnect(this, SIGNAL(reverseGeoReady(QString)),
390 m_updateLocation, SLOT(setAddress(QString)));
392 disconnect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
393 this, SIGNAL(statusUpdate(QString,bool)));
395 disconnect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
396 this, SLOT(backupUpdateLocationDialogData(QString,bool)));
398 disconnect(m_updateLocation, SIGNAL(finished(int)),
399 this, SLOT(updateLocationDialogFinished(int)));
401 m_updateLocation->deleteLater();
402 m_updateLocation = 0;