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)
52 qDebug() << __PRETTY_FUNCTION__;
54 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
55 verticalLayout->setContentsMargins(MARGIN * 2, 0, MARGIN * 2, MARGIN * 2);
56 verticalLayout->setSpacing(0);
57 setLayout(verticalLayout);
59 QFormLayout *infoLayout = new QFormLayout();
60 infoLayout->setMargin(0);
61 infoLayout->setSpacing(0);
63 QLabel *envelopeLabel = new QLabel();
64 envelopeLabel->setPixmap(QPixmap(":/res/images/envelope.png"));
65 envelopeLabel->setContentsMargins(0, 0, MARGIN, 0);
66 envelopeLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
67 QLabel *compassLabel = new QLabel();
68 compassLabel->setPixmap(QPixmap(":/res/images/compass.png"));
69 compassLabel->setContentsMargins(0, 0, MARGIN, 0);
70 compassLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
71 QLabel *clockLabel = new QLabel();
72 clockLabel->setPixmap(QPixmap(":/res/images/clock.png"));
73 clockLabel->setContentsMargins(0, 0, MARGIN, 0);
74 clockLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
76 m_avatar = new ImageButton();
78 m_nameLabel = new QLabel();
80 m_statusTextLabel = new QLabel();
81 m_statusTextLabel->setWordWrap(true);
82 m_statusTextLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
83 m_locationLabel = new QLabel();
84 m_locationLabel->setWordWrap(true);
85 m_locationLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
86 m_updatedLabel = new QLabel();
87 m_updatedLabel->setWordWrap(true);
88 m_updatedLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
90 infoLayout->addRow(envelopeLabel, m_statusTextLabel);
91 infoLayout->addRow(compassLabel, m_locationLabel);
92 infoLayout->addRow(clockLabel, m_updatedLabel);
94 verticalLayout->addWidget(m_avatar, 0, Qt::AlignHCenter);
95 verticalLayout->addWidget(m_nameLabel, 0, Qt::AlignHCenter);
96 verticalLayout->addLayout(infoLayout);
98 connect(m_avatar, SIGNAL(clicked()),
99 this, SLOT(findButtonClicked()));
101 setFixedWidth(BACKGROUND_WIDTH);
103 this->setFont(NOKIA_FONT_SMALL);
104 m_nameLabel->setFont(NOKIA_FONT_NORMAL);
105 QPalette itemPalette = palette();
106 itemPalette.setColor(QPalette::Foreground, COLOR_GRAY);
107 setPalette(itemPalette);
108 QPalette namePalette = m_nameLabel->palette();
109 namePalette.setColor(QPalette::Foreground, Qt::white);
110 m_nameLabel->setPalette(namePalette);
112 m_backgroundTopImage.load(":/res/images/list_item_top.png");
113 m_backgroundMiddleImage.load(":/res/images/list_item_middle.png");
114 m_backgroundBottomImage.load(":/res/images/list_item_bottom.png");
117 UserInfo::~UserInfo()
119 qDebug() << __PRETTY_FUNCTION__;
122 void UserInfo::collapse()
124 qDebug() << __PRETTY_FUNCTION__;
129 void UserInfo::findButtonClicked()
131 qDebug() << __PRETTY_FUNCTION__;
133 emit findUser(m_coordinates);
136 void UserInfo::mousePressEvent(QMouseEvent *event)
138 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
140 m_mousePosition = event->pos();
143 void UserInfo::mouseReleaseEvent(QMouseEvent *event)
145 qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
147 const int MOUSE_PRESS_AREA_HEIGHT = 20;
148 const int MOUSE_PRESS_AREA_WIDTH = 20;
150 if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH)
151 && (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
163 void UserInfo::paintEvent(QPaintEvent *event)
165 qDebug() << __PRETTY_FUNCTION__ << " " << event->rect();
167 QPainter painter(this);
169 QRect topRect = QRect(0, MARGIN, BACKGROUND_WIDTH, BACKGROUND_TOP_HEIGHT);
171 QRect middleRect = QRect(topRect.left(), topRect.bottom() + 1, BACKGROUND_WIDTH,
172 this->height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
174 QRect bottomRect = QRect(topRect.left(), middleRect.bottom() + 1, BACKGROUND_WIDTH,
175 BACKGROUND_BOTTOM_HEIGHT);
177 painter.drawPixmap(topRect, m_backgroundTopImage);
178 painter.drawPixmap(middleRect, m_backgroundMiddleImage);
179 painter.drawPixmap(bottomRect, m_backgroundBottomImage);
182 void UserInfo::setAddress(const QString &address)
184 qDebug() << __PRETTY_FUNCTION__;
186 m_locationLabel->setText(address);
189 void UserInfo::setCoordinates(const GeoCoordinate &coordinates)
191 qDebug() << __PRETTY_FUNCTION__;
193 m_coordinates = coordinates;
196 void UserInfo::setMessageText(const QString &text)
198 qDebug() << __PRETTY_FUNCTION__;
200 m_messageText = TextModifier::splitLongWords(m_statusTextLabel->fontMetrics(), text,
206 void UserInfo::setProfileImage(const QPixmap &image)
208 qDebug() << __PRETTY_FUNCTION__;
211 m_avatar->setButtonIcon(image);
214 void UserInfo::setExpanded(bool expanded)
216 qDebug() << __PRETTY_FUNCTION__;
219 m_statusTextLabel->setText(m_messageText);
221 m_statusTextLabel->setText(TextModifier::shortenText(m_statusTextLabel->fontMetrics(),
222 m_messageText, LABEL_MAX_WIDTH));
226 void UserInfo::setTime(const QString &time)
228 qDebug() << __PRETTY_FUNCTION__;
230 m_updatedLabel->setText(time);
233 void UserInfo::setUserName(const QString &name)
235 qDebug() << __PRETTY_FUNCTION__;
239 m_nameLabel->setText(TextModifier::shortenText(m_nameLabel->fontMetrics(), m_userName,