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,
25 #include "imagebutton.h"
26 #include "../user/user.h"
29 const int BACKGROUND_WIDTH = 240; ///< Width for item
30 const int BACKGROUND_TOP_HEIGHT = 16;
31 const int BACKGROUND_BOTTOM_HEIGHT = 15;
32 const QColor COLOR_GRAY = QColor(152, 152, 152); ///< Gray color
33 const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal); ///< Normal font
34 const QFont NOKIA_FONT_SMALL = QFont("Nokia Sans", 13, QFont::Normal); ///< Small font
35 const int ICON_HEIGHT = 24; ///< Icon height
36 const int ICON_WIDTH = 24; ///< Icon width
37 const int IMAGE_HEIGHT = 60; ///< Profile image height
38 const int IMAGE_WIDTH = 60; ///< Profile image width
39 const int MARGIN = 5; ///< Icon margin
40 const int MOUSE_PRESS_AREA_WIDTH = 20; ///< Area width for item height toggling
41 const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height toggling
44 * @var LABEL_MAX_WIDTH
46 * @brief All label's maximum width
48 const int LABEL_MAX_WIDTH = BACKGROUND_WIDTH - 3 * MARGIN - ICON_WIDTH + 130;
51 * @brief Name label's maximum width
53 * @var NAME_LABEL_MAX_WIDTH
55 const int NAME_LABEL_MAX_WIDTH = LABEL_MAX_WIDTH + 70;
57 UserInfo::UserInfo(QWidget *parent)
61 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
62 verticalLayout->setContentsMargins(MARGIN * 2, 0, MARGIN * 2, MARGIN * 2);
63 verticalLayout->setSpacing(0);
64 this->setLayout(verticalLayout);
66 QFormLayout *infoLayout = new QFormLayout();
67 infoLayout->setMargin(0);
68 infoLayout->setSpacing(0);
70 QHBoxLayout *buttonLayout = new QHBoxLayout();
71 buttonLayout->setMargin(0);
72 buttonLayout->setSpacing(0);
74 QLabel *envelopeLabel = new QLabel(this);
75 envelopeLabel->setPixmap(QPixmap(":/res/images/envelope.png"));
76 envelopeLabel->setContentsMargins(0, 0, MARGIN, 0);
77 envelopeLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
78 QLabel *compassLabel = new QLabel(this);
79 compassLabel->setPixmap(QPixmap(":/res/images/compass.png"));
80 compassLabel->setContentsMargins(0, 0, MARGIN, 0);
81 compassLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
82 QLabel *clockLabel = new QLabel(this);
83 clockLabel->setPixmap(QPixmap(":/res/images/clock.png"));
84 clockLabel->setContentsMargins(0, 0, MARGIN, 0);
85 clockLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
87 m_imageLabel = new QLabel(this);
88 m_imageLabel->setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT);
90 m_nameLabel = new QLabel(this);
91 m_nameLabel->setWordWrap(true);
92 m_nameLabel->setFixedHeight(IMAGE_HEIGHT);
94 m_statusTextLabel = new QLabel(this);
95 m_statusTextLabel->setWordWrap(true);
96 m_locationLabel = new QLabel(this);
97 m_locationLabel->setWordWrap(true);
98 m_updatedLabel = new QLabel(this);
99 m_updatedLabel->setWordWrap(true);
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_imageLabel, 0, Qt::AlignHCenter);
114 verticalLayout->addWidget(m_nameLabel, 0, Qt::AlignHCenter);
115 verticalLayout->addLayout(infoLayout, 1);
116 verticalLayout->addLayout(buttonLayout);
118 connect(updateStatusMessageButton,SIGNAL(clicked()),
119 this,SLOT(messageUpdate()));
120 connect(updateFriendsButton,SIGNAL(clicked()),
121 this, SIGNAL(refreshUserData()));
123 this->setFixedWidth(BACKGROUND_WIDTH);
125 this->setFont(NOKIA_FONT_SMALL);
126 m_nameLabel->setFont(NOKIA_FONT_NORMAL);
127 QPalette itemPalette = palette();
128 itemPalette.setColor(QPalette::Foreground, COLOR_GRAY);
129 setPalette(itemPalette);
130 QPalette namePalette = m_nameLabel->palette();
131 namePalette.setColor(QPalette::Foreground, Qt::white);
132 m_nameLabel->setPalette(namePalette);
134 this->m_backgroundTopImage.load(":/res/images/user_info_item_top.png");
135 this->m_backgroundMiddleImage.load(":/res/images/user_info_item_middle.png");
136 this->m_backgroundBottomImage.load(":/res/images/user_info_item_bottom.png");
139 void UserInfo::setUserName(const QString &name)
141 qDebug() << __PRETTY_FUNCTION__;
147 void UserInfo::setProfileImage(const QPixmap &image)
149 qDebug() << __PRETTY_FUNCTION__;
151 m_imageLabel->setPixmap(image);
154 void UserInfo::setMessageText(const QString &text)
156 qDebug() << __PRETTY_FUNCTION__;
158 m_messageText = text;
162 void UserInfo::setAddress(const QString &address)
164 qDebug() << __PRETTY_FUNCTION__;
166 m_locationLabel->setText(address);
169 void UserInfo::setTime(const QString &time)
171 qDebug() << __PRETTY_FUNCTION__;
173 m_updatedLabel->setText(time);
176 QString UserInfo::shortenText(const QLabel *label, const QString &text, int textMaxWidth)
178 qDebug() << __PRETTY_FUNCTION__;
180 QFontMetrics labelMetrics = label->fontMetrics();
182 QString textParam = text;
183 int index = textParam.indexOf('\n');
186 textParam.truncate(index);
187 textParam.append("...");
190 return labelMetrics.elidedText(textParam, Qt::ElideRight, textMaxWidth);
193 void UserInfo::setText(bool expanded)
195 qDebug() << __PRETTY_FUNCTION__;
198 m_nameLabel->setText(m_userName);
199 m_statusTextLabel->setText(m_messageText);
202 m_nameLabel->setText(shortenText(m_nameLabel, m_userName, LABEL_MAX_WIDTH));
203 m_statusTextLabel->setText(shortenText(m_statusTextLabel, m_messageText,
208 void UserInfo::mouseReleaseEvent(QMouseEvent *event)
210 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
212 if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH) &&
213 (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
224 void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
226 qDebug() << __PRETTY_FUNCTION__ << " " << aPaintEvent->rect();
228 QPainter painter(this);
230 QRect topRect = QRect(0, MARGIN, BACKGROUND_WIDTH, BACKGROUND_TOP_HEIGHT);
231 QRect middleRect = QRect(0, topRect.bottom(), BACKGROUND_WIDTH,
232 height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
233 QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), BACKGROUND_WIDTH,
234 BACKGROUND_BOTTOM_HEIGHT);
236 painter.drawPixmap(topRect, m_backgroundTopImage);
237 painter.drawPixmap(middleRect, m_backgroundMiddleImage);
238 painter.drawPixmap(bottomRect, m_backgroundBottomImage);
241 void UserInfo::mousePressEvent(QMouseEvent *event)
243 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
245 m_mousePosition = event->pos();
248 void UserInfo::messageUpdate()
250 qDebug() << __PRETTY_FUNCTION__;
252 UpdateLocationDialog updateLocationDialog(this);
254 emit requestReverseGeo();
256 connect(this, SIGNAL(reverseGeoReady(QString)),
257 &updateLocationDialog, SLOT(setAddress(QString)));
258 connect(&updateLocationDialog, SIGNAL(statusUpdate(QString, bool)),
259 this, SIGNAL(statusUpdate(QString, bool)));
261 updateLocationDialog.exec();