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_statusTextLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
84 m_locationLabel = new QLabel();
85 m_locationLabel->setWordWrap(true);
86 m_locationLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
87 m_updatedLabel = new QLabel();
88 m_updatedLabel->setWordWrap(true);
89 m_updatedLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
91 infoLayout->addRow(envelopeLabel, m_statusTextLabel);
92 infoLayout->addRow(compassLabel, m_locationLabel);
93 infoLayout->addRow(clockLabel, m_updatedLabel);
95 verticalLayout->addWidget(m_avatar, 0, Qt::AlignHCenter);
96 verticalLayout->addWidget(m_nameLabel, 0, Qt::AlignHCenter);
97 verticalLayout->addLayout(infoLayout);
99 connect(m_avatar, SIGNAL(clicked()),
100 this, SLOT(findButtonClicked()));
102 setFixedWidth(BACKGROUND_WIDTH);
104 this->setFont(NOKIA_FONT_SMALL);
105 m_nameLabel->setFont(NOKIA_FONT_NORMAL);
106 QPalette itemPalette = palette();
107 itemPalette.setColor(QPalette::Foreground, COLOR_GRAY);
108 setPalette(itemPalette);
109 QPalette namePalette = m_nameLabel->palette();
110 namePalette.setColor(QPalette::Foreground, Qt::white);
111 m_nameLabel->setPalette(namePalette);
113 m_backgroundTopImage.load(":/res/images/list_item_top.png");
114 m_backgroundMiddleImage.load(":/res/images/list_item_middle.png");
115 m_backgroundBottomImage.load(":/res/images/list_item_bottom.png");
117 restoreUnsendMessage();
120 UserInfo::~UserInfo()
122 qDebug() << __PRETTY_FUNCTION__;
124 QSettings settings(DIRECTORY_NAME, FILE_NAME);
126 if (!m_backupMessage.isEmpty()) {
127 settings.setValue(USER_UNSEND_MESSAGE, m_backupMessage.toAscii());
128 settings.setValue(USER_UNSEND_MESSAGE_PUBLISH, m_backupFacebookPublishPolicity);
130 settings.remove(USER_UNSEND_MESSAGE);
131 settings.remove(USER_UNSEND_MESSAGE_PUBLISH);
135 void UserInfo::backupUpdateLocationDialogData(const QString &status, bool publish)
137 qDebug() << __PRETTY_FUNCTION__;
139 m_backupMessage = status;
140 m_backupFacebookPublishPolicity = publish;
143 void UserInfo::clearUpdateLocationDialogData()
145 qDebug() << __PRETTY_FUNCTION__;
147 m_backupMessage.clear();
148 m_backupFacebookPublishPolicity = false;
151 void UserInfo::collapse()
153 qDebug() << __PRETTY_FUNCTION__;
158 void UserInfo::findButtonClicked()
160 qDebug() << __PRETTY_FUNCTION__;
162 emit findUser(m_coordinates);
165 void UserInfo::messageUpdate()
167 qDebug() << __PRETTY_FUNCTION__;
169 delete m_updateLocation;
170 m_updateLocation = new UpdateLocationDialog(m_backupMessage, m_backupFacebookPublishPolicity,
173 connect(this, SIGNAL(reverseGeoReady(QString)),
174 m_updateLocation, SLOT(setAddress(QString)));
176 connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
177 this, SIGNAL(statusUpdate(QString, bool)));
179 connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
180 this, SLOT(backupUpdateLocationDialogData(QString, bool)));
182 connect(m_updateLocation, SIGNAL(finished(int)),
183 this, SLOT(updateLocationDialogFinished(int)));
185 m_updateLocation->show();
187 emit requestReverseGeo();
190 void UserInfo::mousePressEvent(QMouseEvent *event)
192 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
194 m_mousePosition = event->pos();
197 void UserInfo::mouseReleaseEvent(QMouseEvent *event)
199 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
201 const int MOUSE_PRESS_AREA_HEIGHT = 20;
202 const int MOUSE_PRESS_AREA_WIDTH = 20;
204 if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH)
205 && (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
217 void UserInfo::paintEvent(QPaintEvent *event)
219 qDebug() << __PRETTY_FUNCTION__ << " " << event->rect();
221 QPainter painter(this);
223 QRect topRect = QRect(0, MARGIN, BACKGROUND_WIDTH, BACKGROUND_TOP_HEIGHT);
225 QRect middleRect = QRect(topRect.left(), topRect.bottom() + 1, BACKGROUND_WIDTH,
226 this->height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
228 QRect bottomRect = QRect(topRect.left(), middleRect.bottom() + 1, BACKGROUND_WIDTH,
229 BACKGROUND_BOTTOM_HEIGHT);
231 painter.drawPixmap(topRect, m_backgroundTopImage);
232 painter.drawPixmap(middleRect, m_backgroundMiddleImage);
233 painter.drawPixmap(bottomRect, m_backgroundBottomImage);
236 void UserInfo::restoreUnsendMessage()
238 qDebug() << __PRETTY_FUNCTION__;
240 QSettings settings(DIRECTORY_NAME, FILE_NAME);
241 m_backupMessage = settings.value(USER_UNSEND_MESSAGE, EMPTY).toString();
242 m_backupFacebookPublishPolicity = settings.value(USER_UNSEND_MESSAGE_PUBLISH, false).toBool();
245 void UserInfo::setAddress(const QString &address)
247 qDebug() << __PRETTY_FUNCTION__;
249 m_locationLabel->setText(address);
252 void UserInfo::setCoordinates(const GeoCoordinate &coordinates)
254 qDebug() << __PRETTY_FUNCTION__;
256 m_coordinates = coordinates;
259 void UserInfo::setMessageText(const QString &text)
261 qDebug() << __PRETTY_FUNCTION__;
263 m_messageText = TextModifier::splitLongWords(m_statusTextLabel->fontMetrics(), text,
269 void UserInfo::setProfileImage(const QPixmap &image)
271 qDebug() << __PRETTY_FUNCTION__;
274 m_avatar->setButtonIcon(image);
277 void UserInfo::setExpanded(bool expanded)
279 qDebug() << __PRETTY_FUNCTION__;
282 m_statusTextLabel->setText(m_messageText);
284 m_statusTextLabel->setText(TextModifier::shortenText(m_statusTextLabel->fontMetrics(),
285 m_messageText, LABEL_MAX_WIDTH));
289 void UserInfo::setTime(const QString &time)
291 qDebug() << __PRETTY_FUNCTION__;
293 m_updatedLabel->setText(time);
296 void UserInfo::setUserName(const QString &name)
298 qDebug() << __PRETTY_FUNCTION__;
302 m_nameLabel->setText(TextModifier::shortenText(m_nameLabel->fontMetrics(), m_userName,
306 void UserInfo::updateLocationDialogFinished(int reason)
308 qDebug() << __PRETTY_FUNCTION__;
312 if (m_updateLocation) {
313 disconnect(this, SIGNAL(reverseGeoReady(QString)),
314 m_updateLocation, SLOT(setAddress(QString)));
316 disconnect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
317 this, SIGNAL(statusUpdate(QString,bool)));
319 disconnect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
320 this, SLOT(backupUpdateLocationDialogData(QString,bool)));
322 disconnect(m_updateLocation, SIGNAL(finished(int)),
323 this, SLOT(updateLocationDialogFinished(int)));
325 m_updateLocation->deleteLater();
326 m_updateLocation = 0;