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 "textmodifier.h"
36 #include "user/user.h"
40 const int BACKGROUND_BOTTOM_HEIGHT = 15;
41 const int BACKGROUND_TOP_HEIGHT = 20;
42 const int BACKGROUND_WIDTH = 368;
43 const int ICON_HEIGHT = 24;
44 const int ICON_WIDTH = 24;
46 const int LABEL_MAX_WIDTH = BACKGROUND_WIDTH - ICON_WIDTH - 5 * MARGIN;
48 UserInfo::UserInfo(QWidget *parent)
53 qDebug() << __PRETTY_FUNCTION__;
55 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
56 verticalLayout->setContentsMargins(MARGIN * 2, 0, MARGIN * 2, MARGIN * 2);
57 verticalLayout->setSpacing(0);
58 setLayout(verticalLayout);
60 QFormLayout *infoLayout = new QFormLayout();
61 infoLayout->setMargin(0);
62 infoLayout->setSpacing(0);
64 QLabel *envelopeLabel = new QLabel();
65 envelopeLabel->setPixmap(QPixmap(":/res/images/envelope.png"));
66 envelopeLabel->setContentsMargins(0, 0, MARGIN, 0);
67 envelopeLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
68 QLabel *compassLabel = new QLabel();
69 compassLabel->setPixmap(QPixmap(":/res/images/compass.png"));
70 compassLabel->setContentsMargins(0, 0, MARGIN, 0);
71 compassLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
72 QLabel *clockLabel = new QLabel();
73 clockLabel->setPixmap(QPixmap(":/res/images/clock.png"));
74 clockLabel->setContentsMargins(0, 0, MARGIN, 0);
75 clockLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
77 m_avatar = new ImageButton();
79 m_nameLabel = new QLabel();
81 m_statusTextLabel = new QLabel();
82 m_statusTextLabel->setWordWrap(true);
83 m_locationLabel = new QLabel();
84 m_locationLabel->setWordWrap(true);
85 m_updatedLabel = new QLabel();
86 m_updatedLabel->setWordWrap(true);
88 infoLayout->addRow(envelopeLabel, m_statusTextLabel);
89 infoLayout->addRow(compassLabel, m_locationLabel);
90 infoLayout->addRow(clockLabel, m_updatedLabel);
92 verticalLayout->addWidget(m_avatar, 0, Qt::AlignHCenter);
93 verticalLayout->addWidget(m_nameLabel, 0, Qt::AlignHCenter);
94 verticalLayout->addLayout(infoLayout);
96 connect(m_avatar, SIGNAL(clicked()),
97 this, SLOT(findButtonClicked()));
99 setFixedWidth(BACKGROUND_WIDTH);
101 this->setFont(NOKIA_FONT_SMALL);
102 m_nameLabel->setFont(NOKIA_FONT_NORMAL);
103 QPalette itemPalette = palette();
104 itemPalette.setColor(QPalette::Foreground, COLOR_GRAY);
105 setPalette(itemPalette);
106 QPalette namePalette = m_nameLabel->palette();
107 namePalette.setColor(QPalette::Foreground, Qt::white);
108 m_nameLabel->setPalette(namePalette);
110 m_backgroundTopImage.load(":/res/images/list_item_top.png");
111 m_backgroundMiddleImage.load(":/res/images/list_item_middle.png");
112 m_backgroundBottomImage.load(":/res/images/list_item_bottom.png");
114 restoreUnsendMessage();
117 UserInfo::~UserInfo()
119 qDebug() << __PRETTY_FUNCTION__;
121 QSettings settings(DIRECTORY_NAME, FILE_NAME);
123 if (!m_backupMessage.isEmpty()) {
124 settings.setValue(USER_UNSEND_MESSAGE, m_backupMessage.toAscii());
125 settings.setValue(USER_UNSEND_MESSAGE_PUBLISH, m_backupFacebookPublishPolicity);
127 settings.remove(USER_UNSEND_MESSAGE);
128 settings.remove(USER_UNSEND_MESSAGE_PUBLISH);
132 void UserInfo::backupUpdateLocationDialogData(const QString &status, bool publish)
134 qDebug() << __PRETTY_FUNCTION__;
136 m_backupMessage = status;
137 m_backupFacebookPublishPolicity = publish;
140 void UserInfo::clearUpdateLocationDialogData()
142 qDebug() << __PRETTY_FUNCTION__;
144 m_backupMessage.clear();
145 m_backupFacebookPublishPolicity = false;
148 void UserInfo::collapse()
150 qDebug() << __PRETTY_FUNCTION__;
155 void UserInfo::findButtonClicked()
157 qDebug() << __PRETTY_FUNCTION__;
159 emit findUser(m_coordinates);
162 void UserInfo::messageUpdate()
164 qDebug() << __PRETTY_FUNCTION__;
166 delete m_updateLocation;
167 m_updateLocation = new UpdateLocationDialog(m_backupMessage, m_backupFacebookPublishPolicity,
170 connect(this, SIGNAL(reverseGeoReady(QString)),
171 m_updateLocation, SLOT(setAddress(QString)));
173 connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
174 this, SIGNAL(statusUpdate(QString, bool)));
176 connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
177 this, SLOT(backupUpdateLocationDialogData(QString, bool)));
179 connect(m_updateLocation, SIGNAL(finished(int)),
180 this, SLOT(updateLocationDialogFinished(int)));
182 m_updateLocation->show();
184 emit requestReverseGeo();
187 void UserInfo::mousePressEvent(QMouseEvent *event)
189 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
191 m_mousePosition = event->pos();
194 void UserInfo::mouseReleaseEvent(QMouseEvent *event)
196 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
198 const int MOUSE_PRESS_AREA_HEIGHT = 20;
199 const int MOUSE_PRESS_AREA_WIDTH = 20;
201 if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH)
202 && (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
214 void UserInfo::paintEvent(QPaintEvent *event)
216 qDebug() << __PRETTY_FUNCTION__ << " " << event->rect();
218 QPainter painter(this);
220 QRect topRect = QRect(0, MARGIN, BACKGROUND_WIDTH, BACKGROUND_TOP_HEIGHT);
222 QRect middleRect = QRect(topRect.left(), topRect.bottom() + 1, BACKGROUND_WIDTH,
223 this->height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
225 QRect bottomRect = QRect(topRect.left(), middleRect.bottom() + 1, BACKGROUND_WIDTH,
226 BACKGROUND_BOTTOM_HEIGHT);
228 painter.drawPixmap(topRect, m_backgroundTopImage);
229 painter.drawPixmap(middleRect, m_backgroundMiddleImage);
230 painter.drawPixmap(bottomRect, m_backgroundBottomImage);
233 void UserInfo::restoreUnsendMessage()
235 qDebug() << __PRETTY_FUNCTION__;
237 QSettings settings(DIRECTORY_NAME, FILE_NAME);
238 m_backupMessage = settings.value(USER_UNSEND_MESSAGE, EMPTY).toString();
239 m_backupFacebookPublishPolicity = settings.value(USER_UNSEND_MESSAGE_PUBLISH, false).toBool();
242 void UserInfo::setAddress(const QString &address)
244 qDebug() << __PRETTY_FUNCTION__;
246 m_locationLabel->setText(address);
249 void UserInfo::setCoordinates(const GeoCoordinate &coordinates)
251 qDebug() << __PRETTY_FUNCTION__;
253 m_coordinates = coordinates;
256 void UserInfo::setMessageText(const QString &text)
258 qDebug() << __PRETTY_FUNCTION__;
260 m_messageText = TextModifier::splitLongWords(m_statusTextLabel->fontMetrics(), text,
266 void UserInfo::setProfileImage(const QPixmap &image)
268 qDebug() << __PRETTY_FUNCTION__;
271 m_avatar->setButtonIcon(image);
274 void UserInfo::setExpanded(bool expanded)
276 qDebug() << __PRETTY_FUNCTION__;
279 m_statusTextLabel->setText(m_messageText);
281 m_statusTextLabel->setText(TextModifier::shortenText(m_statusTextLabel->fontMetrics(),
282 m_messageText, LABEL_MAX_WIDTH));
286 void UserInfo::setTime(const QString &time)
288 qDebug() << __PRETTY_FUNCTION__;
290 m_updatedLabel->setText(time);
293 void UserInfo::setUserName(const QString &name)
295 qDebug() << __PRETTY_FUNCTION__;
299 m_nameLabel->setText(TextModifier::shortenText(m_nameLabel->fontMetrics(), m_userName,
303 void UserInfo::updateLocationDialogFinished(int reason)
305 qDebug() << __PRETTY_FUNCTION__;
309 if (m_updateLocation) {
310 disconnect(this, SIGNAL(reverseGeoReady(QString)),
311 m_updateLocation, SLOT(setAddress(QString)));
313 disconnect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
314 this, SIGNAL(statusUpdate(QString,bool)));
316 disconnect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
317 this, SLOT(backupUpdateLocationDialogData(QString,bool)));
319 disconnect(m_updateLocation, SIGNAL(finished(int)),
320 this, SLOT(updateLocationDialogFinished(int)));
322 m_updateLocation->deleteLater();
323 m_updateLocation = 0;