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,
27 #include "imagebutton.h"
28 #include "../user/user.h"
31 const int BACKGROUND_WIDTH = 240; ///< Width for item
32 const int BACKGROUND_TOP_HEIGHT = 16; ///< Height for item top
33 const int BACKGROUND_BOTTOM_HEIGHT = 15; ///< Height for item bottom
34 const int ICON_HEIGHT = 24; ///< Icon height
35 const int ICON_WIDTH = 24; ///< Icon width
36 const int MARGIN = 5; ///< Icon margin
37 const int MOUSE_PRESS_AREA_WIDTH = 20; ///< Area width for item height toggling
38 const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height toggling
39 const QString USER_UNSEND_MESSAGE = "User_unsend_message_content";
40 const QString USER_UNSEND_MESSAGE_PUBLISH_POLICITY = "User_unsend_message_publish";
43 * @var LABEL_MAX_WIDTH
45 * @brief All label's maximum width
47 const int LABEL_MAX_WIDTH = BACKGROUND_WIDTH - 3 * MARGIN - ICON_WIDTH + 130;
49 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 QHBoxLayout *buttonLayout = new QHBoxLayout();
65 buttonLayout->setMargin(0);
66 buttonLayout->setSpacing(0);
68 QLabel *envelopeLabel = new QLabel();
69 envelopeLabel->setPixmap(QPixmap(":/res/images/envelope.png"));
70 envelopeLabel->setContentsMargins(0, 0, MARGIN, 0);
71 envelopeLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
72 QLabel *compassLabel = new QLabel();
73 compassLabel->setPixmap(QPixmap(":/res/images/compass.png"));
74 compassLabel->setContentsMargins(0, 0, MARGIN, 0);
75 compassLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
76 QLabel *clockLabel = new QLabel();
77 clockLabel->setPixmap(QPixmap(":/res/images/clock.png"));
78 clockLabel->setContentsMargins(0, 0, MARGIN, 0);
79 clockLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
81 m_findButton = new ImageButton();
83 m_nameLabel = new QLabel();
84 m_nameLabel->setWordWrap(true);
86 m_statusTextLabel = new QLabel();
87 m_statusTextLabel->setWordWrap(true);
88 m_locationLabel = new QLabel();
89 m_locationLabel->setWordWrap(true);
90 m_updatedLabel = new QLabel();
91 m_updatedLabel->setWordWrap(true);
93 ImageButton *updateFriendsButton = new ImageButton(this, ":/res/images/refresh.png",
94 ":/res/images/refresh_s.png");
95 ImageButton *updateStatusMessageButton = new ImageButton(this, ":/res/images/send_position.png",
96 ":/res/images/send_position_s.png");
98 buttonLayout->addWidget(updateFriendsButton);
99 buttonLayout->addWidget(updateStatusMessageButton);
101 infoLayout->addRow(envelopeLabel, m_statusTextLabel);
102 infoLayout->addRow(compassLabel, m_locationLabel);
103 infoLayout->addRow(clockLabel, m_updatedLabel);
105 verticalLayout->addWidget(m_findButton, 0, Qt::AlignHCenter);
106 verticalLayout->addWidget(m_nameLabel, 0, Qt::AlignHCenter);
107 verticalLayout->addLayout(infoLayout);
108 verticalLayout->addLayout(buttonLayout);
110 connect(updateStatusMessageButton,SIGNAL(clicked()),
111 this,SLOT(messageUpdate()));
113 connect(updateFriendsButton,SIGNAL(clicked()),
114 this, SIGNAL(refreshUserData()));
116 connect(m_findButton, SIGNAL(clicked()),
117 this, SLOT(findButtonClicked()));
119 setFixedWidth(BACKGROUND_WIDTH);
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 m_backgroundTopImage.load(":/res/images/user_info_item_top.png");
131 m_backgroundMiddleImage.load(":/res/images/user_info_item_middle.png");
132 m_backgroundBottomImage.load(":/res/images/user_info_item_bottom.png");
134 restoreUnsendMessage();
137 UserInfo::~UserInfo()
139 qDebug() << __PRETTY_FUNCTION__;
141 QSettings settings(DIRECTORY_NAME, FILE_NAME);
143 if (!m_backupMessage.isEmpty()) {
144 settings.setValue(USER_UNSEND_MESSAGE, m_backupMessage.toAscii());
145 settings.setValue(USER_UNSEND_MESSAGE_PUBLISH_POLICITY, m_backupFacebookPublishPolicity);
147 settings.remove(USER_UNSEND_MESSAGE);
148 settings.remove(USER_UNSEND_MESSAGE_PUBLISH_POLICITY);
152 void UserInfo::setAddress(const QString &address)
154 qDebug() << __PRETTY_FUNCTION__;
156 m_locationLabel->setText(address);
159 void UserInfo::setCoordinates(const QPointF &coordinates)
161 qDebug() << __PRETTY_FUNCTION__;
163 m_coordinates = coordinates;
166 void UserInfo::setMessageText(const QString &text)
168 qDebug() << __PRETTY_FUNCTION__;
170 m_messageText = text;
174 void UserInfo::setProfileImage(const QPixmap &image)
176 qDebug() << __PRETTY_FUNCTION__;
178 m_findButton->setButtonIcon(image);
181 void UserInfo::setTime(const QString &time)
183 qDebug() << __PRETTY_FUNCTION__;
185 m_updatedLabel->setText(time);
188 void UserInfo::setUserName(const QString &name)
190 qDebug() << __PRETTY_FUNCTION__;
196 void UserInfo::setText(bool expanded)
198 qDebug() << __PRETTY_FUNCTION__;
201 m_nameLabel->setText(m_userName);
202 m_statusTextLabel->setText(m_messageText);
205 m_nameLabel->setText(shortenText(m_nameLabel, m_userName, LABEL_MAX_WIDTH));
206 m_statusTextLabel->setText(shortenText(m_statusTextLabel, m_messageText,
211 void UserInfo::backupUpdateLocationDialogData(const QString &status, bool publish)
213 qDebug() << __PRETTY_FUNCTION__;
215 m_backupMessage = status;
216 m_backupFacebookPublishPolicity = publish;
218 m_messageUpdateVerified = false;
221 void UserInfo::clearUpdateLocationDialogData()
223 qDebug() << __PRETTY_FUNCTION__;
225 m_backupMessage.clear();
226 m_backupFacebookPublishPolicity = false;
229 void UserInfo::findButtonClicked()
231 qDebug() << __PRETTY_FUNCTION__;
233 emit findUser(m_coordinates);
236 void UserInfo::mouseReleaseEvent(QMouseEvent *event)
238 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
240 if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH) &&
241 (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
253 void UserInfo::mousePressEvent(QMouseEvent *event)
255 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
257 m_mousePosition = event->pos();
260 void UserInfo::messageUpdate()
262 qDebug() << __PRETTY_FUNCTION__;
264 emit requestReverseGeo();
266 UpdateLocationDialog updateLocation(m_backupMessage, m_backupFacebookPublishPolicity, this);
268 connect(this, SIGNAL(reverseGeoReady(QString)),
269 &updateLocation, SLOT(setAddress(QString)));
271 connect(&updateLocation, SIGNAL(statusUpdate(QString,bool)),
272 this, SIGNAL(statusUpdate(QString,bool)));
274 connect(&updateLocation, SIGNAL(statusUpdate(QString,bool)),
275 this, SLOT(backupUpdateLocationDialogData(QString,bool)));
277 updateLocation.exec();
279 disconnect(this, SIGNAL(reverseGeoReady(QString)),
280 &updateLocation, SLOT(setAddress(QString)));
282 disconnect(&updateLocation, SIGNAL(statusUpdate(QString,bool)),
283 this, SIGNAL(statusUpdate(QString,bool)));
285 disconnect(&updateLocation, SIGNAL(statusUpdate(QString,bool)),
286 this, SLOT(backupUpdateLocationDialogData(QString,bool)));
289 void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
291 qDebug() << __PRETTY_FUNCTION__ << " " << aPaintEvent->rect();
293 QPainter painter(this);
295 QRect topRect = QRect(0, MARGIN, BACKGROUND_WIDTH, BACKGROUND_TOP_HEIGHT);
296 QRect middleRect = QRect(0, topRect.bottom(), BACKGROUND_WIDTH,
297 height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
298 QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), BACKGROUND_WIDTH,
299 BACKGROUND_BOTTOM_HEIGHT);
301 painter.drawPixmap(topRect, m_backgroundTopImage);
302 painter.drawPixmap(middleRect, m_backgroundMiddleImage);
303 painter.drawPixmap(bottomRect, m_backgroundBottomImage);
306 void UserInfo::restoreUnsendMessage()
308 qDebug() << __PRETTY_FUNCTION__;
310 QSettings settings(DIRECTORY_NAME, FILE_NAME);
311 m_backupMessage = settings.value(USER_UNSEND_MESSAGE, "").toString();
312 m_backupFacebookPublishPolicity =
313 settings.value(USER_UNSEND_MESSAGE_PUBLISH_POLICITY, false).toBool();
316 QString UserInfo::shortenText(const QLabel *label, const QString &text, int textMaxWidth)
318 qDebug() << __PRETTY_FUNCTION__;
320 QFontMetrics labelMetrics = label->fontMetrics();
322 QString textParam = text;
323 int index = textParam.indexOf('\n');
326 textParam.truncate(index);
327 textParam.append("...");
330 return labelMetrics.elidedText(textParam, Qt::ElideRight, textMaxWidth);
333 void UserInfo::verifyMessageUpdateFailure(const QString &errorMessage)
335 qDebug() << __PRETTY_FUNCTION__;
337 Q_UNUSED(errorMessage);
339 if (!m_messageUpdateVerified) {
341 if (m_messageText != m_backupMessage && !m_backupMessage.isEmpty())
342 emit notificateUpdateFailing(tr("Location update failed\n\nYour message is saved to "
343 "textbox until sending will succeed"));
346 m_messageUpdateVerified = true;