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
10 Situare is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 version 2 as published by the Free Software Foundation.
14 Situare is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Situare; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
26 #include "imagebutton.h"
27 #include "../user/user.h"
30 const int BACKGROUND_WIDTH = 240; ///< Width for item
31 const int BACKGROUND_TOP_HEIGHT = 16; ///< Height for item top
32 const int BACKGROUND_BOTTOM_HEIGHT = 15; ///< Height for item bottom
33 //const QColor COLOR_GRAY = QColor(152, 152, 152); ///< Gray color
34 //const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal); ///< Normal font
35 //const QFont NOKIA_FONT_SMALL = QFont("Nokia Sans", 13, QFont::Normal); ///< Small font
36 const int ICON_HEIGHT = 24; ///< Icon height
37 const int ICON_WIDTH = 24; ///< Icon width
38 //const int IMAGE_HEIGHT = 60; ///< Profile image height
39 //const int IMAGE_WIDTH = 60; ///< Profile image width
40 const int MARGIN = 5; ///< Icon margin
41 const int MOUSE_PRESS_AREA_WIDTH = 20; ///< Area width for item height toggling
42 const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height toggling
43 const QString USER_UNSEND_MESSAGE = "User_unsend_message_content";
44 const QString USER_UNSEND_MESSAGE_PUBLISH_POLICITY = "User_unsend_message_publish";
47 * @var LABEL_MAX_WIDTH
49 * @brief All label's maximum width
51 const int LABEL_MAX_WIDTH = BACKGROUND_WIDTH - 3 * MARGIN - ICON_WIDTH + 130;
53 UserInfo::UserInfo(QWidget *parent)
57 qDebug() << __PRETTY_FUNCTION__;
59 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
60 verticalLayout->setContentsMargins(MARGIN * 2, 0, MARGIN * 2, MARGIN * 2);
61 verticalLayout->setSpacing(0);
62 setLayout(verticalLayout);
64 QFormLayout *infoLayout = new QFormLayout();
65 infoLayout->setMargin(0);
66 infoLayout->setSpacing(0);
68 QHBoxLayout *buttonLayout = new QHBoxLayout();
69 buttonLayout->setMargin(0);
70 buttonLayout->setSpacing(0);
72 QLabel *envelopeLabel = new QLabel();
73 envelopeLabel->setPixmap(QPixmap(":/res/images/envelope.png"));
74 envelopeLabel->setContentsMargins(0, 0, MARGIN, 0);
75 envelopeLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
76 QLabel *compassLabel = new QLabel();
77 compassLabel->setPixmap(QPixmap(":/res/images/compass.png"));
78 compassLabel->setContentsMargins(0, 0, MARGIN, 0);
79 compassLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
80 QLabel *clockLabel = new QLabel();
81 clockLabel->setPixmap(QPixmap(":/res/images/clock.png"));
82 clockLabel->setContentsMargins(0, 0, MARGIN, 0);
83 clockLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
85 m_findButton = new ImageButton();
87 m_nameLabel = new QLabel();
88 m_nameLabel->setWordWrap(true);
90 m_statusTextLabel = new QLabel();
91 m_statusTextLabel->setWordWrap(true);
92 m_locationLabel = new QLabel();
93 m_locationLabel->setWordWrap(true);
94 m_updatedLabel = new QLabel();
95 m_updatedLabel->setWordWrap(true);
97 m_messageDialog = new UpdateLocationDialog(this);
98 m_messageDialog->hide();
99 m_messageDialog->setWindowModality(Qt::NonModal);
101 ImageButton *updateFriendsButton = new ImageButton(this, ":/res/images/refresh.png",
102 ":/res/images/refresh_s.png");
103 ImageButton *updateStatusMessageButton = new ImageButton(this, ":/res/images/send_position.png",
104 ":/res/images/send_position_s.png");
106 buttonLayout->addWidget(updateFriendsButton);
107 buttonLayout->addWidget(updateStatusMessageButton);
109 infoLayout->addRow(envelopeLabel, m_statusTextLabel);
110 infoLayout->addRow(compassLabel, m_locationLabel);
111 infoLayout->addRow(clockLabel, m_updatedLabel);
113 verticalLayout->addWidget(m_findButton, 0, Qt::AlignHCenter);
114 verticalLayout->addWidget(m_nameLabel, 0, Qt::AlignHCenter);
115 verticalLayout->addLayout(infoLayout);
116 verticalLayout->addLayout(buttonLayout);
118 connect(updateStatusMessageButton,SIGNAL(clicked()),
119 this,SLOT(messageUpdate()));
121 connect(updateFriendsButton,SIGNAL(clicked()),
122 this, SIGNAL(refreshUserData()));
124 connect(m_findButton, SIGNAL(clicked()),
125 this, SLOT(findButtonClicked()));
127 connect(this, SIGNAL(reverseGeoReady(QString)),
128 m_messageDialog, SLOT(setAddress(QString)));
130 connect(m_messageDialog, SIGNAL(statusUpdate(QString,bool)),
131 this, SIGNAL(statusUpdate(QString,bool)));
133 connect(m_messageDialog, SIGNAL(statusUpdate(QString,bool)),
134 this, SLOT(backupUpdateLocationDialogData(QString,bool)));
136 connect(this, SIGNAL(messageUpdatedToSituare()),
137 this, SLOT(clearUpdateLocationDialogData()));
139 setFixedWidth(BACKGROUND_WIDTH);
141 this->setFont(NOKIA_FONT_SMALL);
142 m_nameLabel->setFont(NOKIA_FONT_NORMAL);
143 QPalette itemPalette = palette();
144 itemPalette.setColor(QPalette::Foreground, COLOR_GRAY);
145 setPalette(itemPalette);
146 QPalette namePalette = m_nameLabel->palette();
147 namePalette.setColor(QPalette::Foreground, Qt::white);
148 m_nameLabel->setPalette(namePalette);
150 m_backgroundTopImage.load(":/res/images/user_info_item_top.png");
151 m_backgroundMiddleImage.load(":/res/images/user_info_item_middle.png");
152 m_backgroundBottomImage.load(":/res/images/user_info_item_bottom.png");
154 restoreUnsendMessage();
157 UserInfo::~UserInfo()
159 qDebug() << __PRETTY_FUNCTION__;
161 if (!m_backupMessage.isEmpty()) {
162 QSettings settings(DIRECTORY_NAME, FILE_NAME);
163 settings.setValue(USER_UNSEND_MESSAGE, m_backupMessage.toAscii());
164 settings.setValue(USER_UNSEND_MESSAGE_PUBLISH_POLICITY, m_backupFacebookPublishPolicity);
169 void UserInfo::backupUpdateLocationDialogData(const QString &status, const bool &publish)
171 qDebug() << __PRETTY_FUNCTION__;
173 m_backupMessage = status;
174 m_backupFacebookPublishPolicity = publish;
176 m_messageUpdateVerified = false;
179 void UserInfo::clearUpdateLocationDialogData()
181 qDebug() << __PRETTY_FUNCTION__;
183 qDebug() << "Message Before Clearing: " << m_backupMessage;
184 m_backupMessage.clear();
185 qDebug() << "Message After Clearing: " << m_backupMessage;
186 m_backupFacebookPublishPolicity = false;
189 void UserInfo::restoreUnsendMessage()
191 QSettings settings(DIRECTORY_NAME, FILE_NAME);
192 m_backupMessage = settings.value(USER_UNSEND_MESSAGE, "").toString();
193 m_backupFacebookPublishPolicity =
194 settings.value(USER_UNSEND_MESSAGE_PUBLISH_POLICITY, false).toBool();
198 void UserInfo::setAddress(const QString &address)
200 qDebug() << __PRETTY_FUNCTION__;
202 m_locationLabel->setText(address);
205 void UserInfo::setCoordinates(const QPointF &coordinates)
207 qDebug() << __PRETTY_FUNCTION__;
209 m_coordinates = coordinates;
212 void UserInfo::setMessageText(const QString &text)
214 qDebug() << __PRETTY_FUNCTION__;
216 m_messageText = text;
220 void UserInfo::setProfileImage(const QPixmap &image)
222 qDebug() << __PRETTY_FUNCTION__;
224 m_findButton->setButtonIcon(image);
227 void UserInfo::setTime(const QString &time)
229 qDebug() << __PRETTY_FUNCTION__;
231 m_updatedLabel->setText(time);
234 void UserInfo::setUserName(const QString &name)
236 qDebug() << __PRETTY_FUNCTION__;
242 QString UserInfo::shortenText(const QLabel *label, const QString &text, int textMaxWidth)
244 qDebug() << __PRETTY_FUNCTION__;
246 QFontMetrics labelMetrics = label->fontMetrics();
248 QString textParam = text;
249 int index = textParam.indexOf('\n');
252 textParam.truncate(index);
253 textParam.append("...");
256 return labelMetrics.elidedText(textParam, Qt::ElideRight, textMaxWidth);
259 void UserInfo::setText(bool expanded)
261 qDebug() << __PRETTY_FUNCTION__;
264 m_nameLabel->setText(m_userName);
265 m_statusTextLabel->setText(m_messageText);
268 m_nameLabel->setText(shortenText(m_nameLabel, m_userName, LABEL_MAX_WIDTH));
269 m_statusTextLabel->setText(shortenText(m_statusTextLabel, m_messageText,
274 void UserInfo::verifyMessageUpdateToServer(QString errorMessage)
276 qDebug() << __PRETTY_FUNCTION__;
278 Q_UNUSED(errorMessage);
280 if (!m_messageUpdateVerified) {
281 QString message = QObject::tr("Status update failed\n\nYour message is saved to textbox "
282 "until sending will succeed");
284 qDebug() << "m_messageText: " << m_messageText;
285 qDebug() << "m_backupMessage: " << m_backupMessage;
287 if (m_messageText != m_backupMessage && !m_backupMessage.isEmpty())
288 emit notificateUpdateFailing(message);
291 m_messageUpdateVerified = true;
294 void UserInfo::mouseReleaseEvent(QMouseEvent *event)
296 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
298 if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH) &&
299 (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
311 void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
313 qDebug() << __PRETTY_FUNCTION__ << " " << aPaintEvent->rect();
315 QPainter painter(this);
317 QRect topRect = QRect(0, MARGIN, BACKGROUND_WIDTH, BACKGROUND_TOP_HEIGHT);
318 QRect middleRect = QRect(0, topRect.bottom(), BACKGROUND_WIDTH,
319 height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
320 QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), BACKGROUND_WIDTH,
321 BACKGROUND_BOTTOM_HEIGHT);
323 painter.drawPixmap(topRect, m_backgroundTopImage);
324 painter.drawPixmap(middleRect, m_backgroundMiddleImage);
325 painter.drawPixmap(bottomRect, m_backgroundBottomImage);
328 void UserInfo::mousePressEvent(QMouseEvent *event)
330 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
332 m_mousePosition = event->pos();
335 void UserInfo::findButtonClicked()
337 qDebug() << __PRETTY_FUNCTION__;
339 emit findUser(m_coordinates);
342 void UserInfo::messageUpdate()
344 qDebug() << __PRETTY_FUNCTION__;
346 emit requestReverseGeo();
348 m_messageDialog->show();
349 m_messageDialog->m_textEdit->setPlainText(m_backupMessage);
350 m_messageDialog->m_checkBox->setCheckState(Qt::Unchecked);
352 if (m_backupFacebookPublishPolicity == true)
353 m_messageDialog->m_checkBox->setCheckState(Qt::Checked);
355 m_messageDialog->exec();