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
9 Situare is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 version 2 as published by the Free Software Foundation.
13 Situare is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Situare; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24 #include <QVBoxLayout>
25 #include <QPushButton>
28 #include <QPaintEvent>
31 #include <QFormLayout>
32 #include <QSpacerItem>
33 #include <QStylePainter>
36 #include "imagebutton.h"
37 #include "avatarimage.h"
38 #include "../user/user.h"
41 UserInfo::UserInfo(QWidget *parent)
45 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
46 verticalLayout->setContentsMargins(MARGIN, 0, MARGIN*2, MARGIN*2);
47 verticalLayout->setSpacing(0);
48 setLayout(verticalLayout);
50 QGridLayout *gridLayout = new QGridLayout(this);
51 gridLayout->setMargin(0);
52 gridLayout->setSpacing(0);
54 QHBoxLayout *topLayout = new QHBoxLayout(this);
55 topLayout->setMargin(0);
56 topLayout->setSpacing(0);
58 QFormLayout *infoLayout = new QFormLayout(this);
59 infoLayout->setMargin(0);
60 infoLayout->setSpacing(0);
62 QHBoxLayout *buttonLayout = new QHBoxLayout(this);
63 buttonLayout->setMargin(0);
64 buttonLayout->setSpacing(0);
66 QLabel *clockLabel = new QLabel();
67 clockLabel->setPixmap(QPixmap(":/res/images/clock.png"));
68 clockLabel->setContentsMargins(0, 0, MARGIN, 0);
69 clockLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
70 QLabel *envelopeLabel = new QLabel();
71 envelopeLabel->setPixmap(QPixmap(":/res/images/envelope.png"));
72 envelopeLabel->setContentsMargins(0, 0, MARGIN, 0);
73 envelopeLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
74 QLabel *compassLabel = new QLabel();
75 compassLabel->setPixmap(QPixmap(":/res/images/compass.png"));
76 compassLabel->setContentsMargins(0, 0, MARGIN, 0);
77 compassLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
79 m_imageLabel = new QLabel();
80 m_imageLabel->setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT);
81 m_imageLabel->setAlignment(Qt::AlignHCenter);
83 m_nameLabel = new QLabel();
84 m_nameLabel->setFixedHeight(IMAGE_HEIGHT);
86 m_updatedLabel = new QLabel();
87 m_updatedLabel->setWordWrap(true);
88 m_statusTextLabel = new QLabel();
89 m_statusTextLabel->setWordWrap(true);
90 m_locationLabel = new QLabel();
91 m_locationLabel->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);
102 infoLayout->addRow(compassLabel, m_locationLabel);
103 infoLayout->addRow(envelopeLabel, m_statusTextLabel);
104 infoLayout->addRow(clockLabel, m_updatedLabel);
106 topLayout->addWidget(m_nameLabel);
108 gridLayout->addWidget(m_imageLabel);
110 verticalLayout->addLayout(gridLayout, 0);
111 verticalLayout->addLayout(topLayout, 1);
112 verticalLayout->addLayout(infoLayout);
113 verticalLayout->addLayout(buttonLayout, 2 );
115 connect(updateStatusMessageButton,SIGNAL(clicked()),
116 this,SLOT(messageUpdate()));
117 connect(updateFriendsButton,SIGNAL(clicked()),
118 this,SLOT(updateFriendsStatus()));
120 setFont(NOKIA_FONT_SMALL);
121 m_nameLabel->setFont(NOKIA_FONT_NORMAL);
122 QPalette itemPalette = palette();
123 itemPalette.setColor(QPalette::Foreground, COLOR_GRAY);
124 setPalette(itemPalette);
125 QPalette namePalette = m_nameLabel->palette();
126 namePalette.setColor(QPalette::Foreground, Qt::white);
127 m_nameLabel->setPalette(namePalette);
129 m_nameLabel->setText("");
131 this->setMaximumHeight(300);
133 m_backgroundTopImage.load(":/res/images/list_item_top.png");
134 m_backgroundMiddleImage.load(":/res/images/list_item_middle.png");
135 m_backgroundBottomImage.load(":/res/images/list_item_bottom.png");
140 void UserInfo::setUserName(const QString &name)
142 qDebug() << __PRETTY_FUNCTION__;
145 m_nameLabel->setText(name);
150 void UserInfo::setAvatar(const QPixmap &image)
153 // m_imageLabel->setPixmap(AvatarImage::create(m_avatar.profileImage()));
154 //m_imageLabel->setPixmap(AvatarImage::create(m_avatar.profileImage()));
155 m_imageLabel->setPixmap(m_avatar);
159 void UserInfo::setMessageText(const QString &text)
161 if(m_messageText == text)
163 m_messageText = text;
164 m_statusTextLabel->setText(m_messageText);
168 void UserInfo::setAddress(const QString &addr)
170 qDebug() << __PRETTY_FUNCTION__;
172 m_locationLabel->setText(addr);
176 void UserInfo::setTime(const QString &tim)
181 m_updatedLabel->setText(m_time);
185 void UserInfo::shortenTexts()
187 qDebug() << __PRETTY_FUNCTION__;
189 QFontMetrics nameLabelMetrics = m_nameLabel->fontMetrics();
190 QFontMetrics otherLabelsMetrics = m_locationLabel->fontMetrics();
192 QString name = m_userName;
193 QString updated = m_time;
194 QString statusText = m_messageText;
195 QString location = m_address;
197 int nameIndex = name.indexOf('\n');
198 int updatedIndex = updated.indexOf('\n');
199 int statusTextIndex = statusText.indexOf('\n');
200 int locationIndex = location.indexOf('\n');
203 name.truncate(nameIndex);
206 if (updatedIndex > 0) {
207 updated.truncate(updatedIndex);
208 updated.append("...");
210 if (statusTextIndex > 0) {
211 statusText.truncate(statusTextIndex);
212 statusText.append("...");
214 if (locationIndex > 0) {
215 location.truncate(locationIndex);
216 location.append("...");
219 m_shortenedName = nameLabelMetrics.elidedText(name, Qt::ElideRight, LABEL_MAX_WIDTH + 30);
220 m_shortenedUpdated = otherLabelsMetrics.elidedText(updated, Qt::ElideRight, LABEL_MAX_WIDTH);
221 m_shortenedStatusText = otherLabelsMetrics.elidedText(statusText, Qt::ElideRight,
223 m_shortenedLocation = otherLabelsMetrics.elidedText(location, Qt::ElideRight, LABEL_MAX_WIDTH);
226 void UserInfo::setText(bool expanded)
228 qDebug() << __PRETTY_FUNCTION__;
231 m_nameLabel->setText(m_userName);
232 m_updatedLabel->setText(m_time);
233 m_statusTextLabel->setText(m_messageText);
234 m_locationLabel->setText(m_address);
237 m_nameLabel->setText(m_shortenedName);
238 m_updatedLabel->setText(m_shortenedUpdated);
239 m_statusTextLabel->setText(m_shortenedStatusText);
240 m_locationLabel->setText(m_shortenedLocation);
244 void UserInfo::mouseReleaseEvent(QMouseEvent *event)
246 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
248 if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH) &&
249 (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
260 void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
262 // Q_UNUSED(aPaintEvent);
264 // QStyleOption option;
265 // option.init(this);
266 // QStylePainter painter(this);
268 // // Temporary border
269 // painter.setPen(Qt::red);
270 // painter.drawRect(this->rect().x(), this->rect().y(), this->rect().width() - 1, this->rect().height() - 1);
272 // style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
274 qDebug() << __PRETTY_FUNCTION__ << " " << aPaintEvent->rect();
276 QPainter painter(this);
277 QRect topRect = QRect(0, 0, ITEM_MIN_WIDTH, BACKGROUND_TOP_HEIGHT);
278 QRect middleRect = QRect(0, topRect.bottom(), ITEM_MIN_WIDTH,
279 height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
280 QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), ITEM_MIN_WIDTH,
281 BACKGROUND_BOTTOM_HEIGHT);
283 painter.drawPixmap(topRect, m_backgroundTopImage);
284 painter.drawPixmap(middleRect, m_backgroundMiddleImage);
285 painter.drawPixmap(bottomRect, m_backgroundBottomImage);
289 void UserInfo::mousePressEvent(QMouseEvent *event)
291 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
293 m_mousePosition = event->pos();
296 void UserInfo::messageUpdate()
298 qDebug() << __PRETTY_FUNCTION__;
299 m_locationDialog = new UpdateLocationDialog(this);
300 m_locationDialog->show();
303 void UserInfo::updateFriendsStatus()
305 qDebug() << __PRETTY_FUNCTION__;
306 //emit launchUpdateFriendsStatus();