USA.
*/
-#include <QVBoxLayout>
-#include <QPushButton>
#include <QPainter>
#include <QDebug>
-#include <QPaintEvent>
-#include <QLabel>
#include <QPixmap>
-#include <QStateMachine>
-#include <QAbstractTransition>
-#include <QPropertyAnimation>
-#include <QSignalTransition>
-#include <QFontMetrics>
-#include <QFormLayout>
-#include <QSpacerItem>
+
+#include "../user/user.h"
+#include "../common.h"
+#include "listcommon.h"
#include "friendlistitem.h"
-#include "user/user.h"
-FriendListItem::FriendListItem(QWidget *parent)
- : QWidget(parent)
- , m_expanded(false)
+FriendListItem::FriendListItem()
{
- QVBoxLayout *layout = new QVBoxLayout(this);
- this->setLayout(layout);
-
- QHBoxLayout *topLayout = new QHBoxLayout();
- topLayout->setMargin(0);
- topLayout->setSpacing(0);
-
- QHBoxLayout *bottomLayout = new QHBoxLayout();
- bottomLayout->setMargin(0);
- bottomLayout->setSpacing(0);
- m_infoWidget = new QWidget(this);
-
- QFormLayout *infoLayout = new QFormLayout();
- infoLayout->setMargin(0);
- infoLayout->setSpacing(0);
- m_infoWidget->setLayout(infoLayout);
-
- QLabel *clockLabel = new QLabel(this);
- clockLabel->setPixmap(QPixmap(CLOCK_PATH));
- clockLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
- QLabel *envelopeLabel = new QLabel(this);
- envelopeLabel->setPixmap(QPixmap(ENVELOPE_PATH));
- envelopeLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
- QLabel *compassLabel = new QLabel(this);
- compassLabel->setPixmap(QPixmap(COMPASS_PATH));
- compassLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
-
- m_imageLabel = new QLabel(this);
- m_imageLabel->setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT);
- m_nameLabel = new QLabel("", this);
- m_nameLabel->setFixedHeight(IMAGE_HEIGHT);
- m_updatedLabel = new QLabel("", this);
- m_updatedLabel->setWordWrap(true);
- m_statusTextLabel = new QLabel("", this);
- m_statusTextLabel->setWordWrap(true);
- m_locationLabel = new QLabel("", this);
- m_locationLabel->setWordWrap(true);
-
- infoLayout->addRow(clockLabel, m_updatedLabel);
- infoLayout->addRow(envelopeLabel, m_statusTextLabel);
- infoLayout->addRow(compassLabel, m_locationLabel);
-
- topLayout->addWidget(m_imageLabel);
- topLayout->addWidget(m_nameLabel);
-
- bottomLayout->addSpacerItem(new QSpacerItem(IMAGE_WIDTH, IMAGE_HEIGHT));
- bottomLayout->addWidget(m_infoWidget, 1);
-
- layout->addLayout(topLayout, 0);
- layout->addLayout(bottomLayout, 1);
-
- this->setObjectName("listItem");
- m_infoWidget->setObjectName("infoWidget");
- m_nameLabel->setObjectName("nameLabel");
-
- this->setStyleSheet("#listItem { border-image: url(:/res/images/list_item.png) 20%; " \
- "border-width: 20px 14px 16px 14px; } " \
- "QLabel { font-size: 13pt; color: #989898; }" \
- "#nameLabel { font-size: 18pt; color: #ffffff }");
-
- this->setMinimumSize(ITEM_MIN_WIDTH, ITEM_MIN_HEIGHT);
- this->setMaximumSize(ITEM_MAX_WIDTH, ITEM_MAX_HEIGHT);
+ qDebug() << __PRETTY_FUNCTION__;
+
+ setSubitemTextWidth(SUBITEM_TEXT_MAX_WIDTH);
}
-void FriendListItem::setData(const User &user)
+FriendListItem::~FriendListItem()
{
- m_user = user;
-
- shortenTexts();
+ qDebug() << __PRETTY_FUNCTION__;
+}
- m_imageLabel->setPixmap(m_user.profileImage());
- m_nameLabel->setText(m_shortenedName);
- m_updatedLabel->setText(m_shortenedUpdated);
- m_statusTextLabel->setText(m_shortenedStatusText);
- m_locationLabel->setText(m_shortenedLocation);
+GeoCoordinate FriendListItem::coordinates() const
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ return m_coordinates;
}
-void FriendListItem::shortenTexts()
+QString FriendListItem::facebookId() const
{
- if (m_user.name().length() > MAXIMUM_CHARS) {
- m_shortenedName = m_user.name().left(MAXIMUM_CHARS-3).append("...");
- }
- else {
- m_shortenedName = m_user.name();
- }
- if (m_user.timestamp().length() > MAXIMUM_CHARS) {
- m_shortenedUpdated = m_user.timestamp().left(MAXIMUM_CHARS-3).append("...");
- }
- else {
- m_shortenedUpdated = m_user.timestamp();
- }
- if (m_user.note().length() > MAXIMUM_CHARS) {
- m_shortenedStatusText = m_user.note().left(MAXIMUM_CHARS-3).append("...");
- }
- else {
- m_shortenedStatusText = m_user.note();
- }
- if (m_user.address().length() > MAXIMUM_CHARS) {
- m_shortenedLocation = m_user.address().left(MAXIMUM_CHARS-3).append("...");
- }
- else {
- m_shortenedLocation = m_user.address();
- }
+ return m_facebookId;
}
-void FriendListItem::toggleHeight()
+void FriendListItem::setAvatarImage(const QPixmap &image)
{
- if (m_expanded) {
- m_nameLabel->setText(m_shortenedName);
- m_updatedLabel->setText(m_shortenedUpdated);
- m_statusTextLabel->setText(m_shortenedStatusText);
- m_locationLabel->setText(m_shortenedLocation);
- m_expanded = false;
-
- }
- else {
- m_nameLabel->setText(m_user.name());
- m_updatedLabel->setText(m_user.timestamp());
- m_statusTextLabel->setText(m_user.note());
- m_locationLabel->setText(m_user.address());
- m_expanded = true;
- }
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if(!image.isNull())
+ setImage(image);
}
-void FriendListItem::mousePressEvent(QMouseEvent *event)
+void FriendListItem::setCoordinates(const GeoCoordinate &coordinates)
{
- m_mousePosition = event->pos();
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_coordinates = coordinates;
}
-void FriendListItem::mouseReleaseEvent(QMouseEvent *event)
+void FriendListItem::setDistanceIcon(double value, const QString &unit)
{
qDebug() << __PRETTY_FUNCTION__;
- if (event->pos() == m_mousePosition)
- toggleHeight();
+ const int AEROPLANE_DISTANCE = 5000;///< Aeroplane distance limit for distance icon
+ const int CAR_DISTANCE = 500; ///< Car distance limit for distance icon
+ const int WALK_DISTANCE = 5; ///< Walk distance limit for distance icon
+
+ QPixmap distanceImage;
+
+ if ((unit == "m") || (value < WALK_DISTANCE))
+ distanceImage.load(":/res/images/walk_icon_gray.png");
+ else if (value < CAR_DISTANCE)
+ distanceImage.load(":/res/images/car_icon_gray.png");
+ else if (value < AEROPLANE_DISTANCE)
+ distanceImage.load(":/res/images/aeroplane_icon_gray.png");
+ else
+ distanceImage.load(":/res/images/rocket_icon_gray.png");
+
+ setData(DISTANCE_IMAGE_INDEX, distanceImage);
}
-void FriendListItem::paintEvent(QPaintEvent *)
+
+void FriendListItem::setFacebookId(const QString &facebookId)
{
- QStyleOption option;
- option.init(this);
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_facebookId = facebookId;
+}
+void FriendListItem::setUserData(User *user)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QString unit;
+ double value;
+ user->distance(value, unit);
+ QString distanceText = QString::number(value) + " " + unit;
+ setData(DISTANCE_TEXT_DISPLAY_INDEX, distanceText);
+ setDistanceIcon(value, unit);
+
+ setFacebookId(user->userId());
+
+ //Dummy value to get painter font metrics.
+ QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
+ QPainter painter(&p);
+ painter.setFont(NOKIA_FONT_SMALL);
+ QFontMetrics distanceTextFontMetrics = painter.fontMetrics();
+ QRect distanceRect = distanceTextFontMetrics.boundingRect(distanceText);
+
+ setData(DISTANCE_SIZE_HINT_INDEX, distanceRect);
+ setTitle(shortenText(user->name(), NAME_TEXT_MAX_WIDTH - distanceRect.width() - MARGIN * 2,
+ ListItem::TEXT_SIZE_NORMAL));
+ setCoordinates(user->coordinates());
+
+ if (!user->profileImage().isNull())
+ setImage(user->profileImage());
+
+ clearSubItems();
- QPainter painter(this);
- style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
+ addSubItem(user->note(), QPixmap(":/res/images/envelope.png"));
+ addSubItem(user->address(), QPixmap(":/res/images/compass.png"));
+ addSubItem(user->timestamp(), QPixmap(":/res/images/clock.png"));
}