Copyright (C) 2010 Ixonos Plc. Authors:
Ville Tiensuu - ville.tiensuu@ixonos.com
+ Sami Rämö - sami.ramo@ixonos.com
Situare is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
*/
#include <QDebug>
+#include <QGraphicsSceneMouseEvent>
+#include <QIcon>
#include "friendlocationitem.h"
-#include "mapengine.h"
#include "mapcommon.h"
-FriendLocationItem::FriendLocationItem(const QPixmap &icon,
- const QPointF &friendsLocation,
+FriendLocationItem::FriendLocationItem(const QString &userId,
QObject *parent)
+ : BaseLocationItem(parent),
+ m_partOfGroup(false),
+ m_userId(userId),
+ m_mousePressPosition(QPoint(0, 0)),
+ m_clickEvent(false)
{
- Q_UNUSED(parent);
qDebug() << __PRETTY_FUNCTION__;
- setPixmap(icon);
- setPosition(QPointF( friendsLocation.x(), friendsLocation.y() ));
+ setPos(UNDEFINED, UNDEFINED);
setZValue(FRIEND_LOCATION_ICON_Z_LEVEL);
- setOffset(-icon.width()/2, -icon.height()/2);
- setFlag(QGraphicsItem::ItemIgnoresTransformations);
- m_name = new QString;
+}
+
+bool FriendLocationItem::isPartOfGroup() const
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ return m_partOfGroup;
}
void FriendLocationItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
+
+ m_mousePressPosition = event->pos();
+ m_clickEvent = true;
+ update();
+}
+
+void FriendLocationItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (m_clickEvent) {
+ if ((event->pos() - m_mousePressPosition).manhattanLength() > PRESS_MANHATTAN_LENGTH) {
+ m_clickEvent = false;
+ update();
+ }
+ }
+}
+
+void FriendLocationItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
Q_UNUSED(event);
- qDebug() << "Friends Location is " << position().x() << " " << position().y();
- qDebug() << "Name of the friend is " << m_name->toAscii();
- emit iconClicked(*m_name);
+
+ if (m_clickEvent) {
+ m_clickEvent = false;
+ QList<QString> userIDs;
+ userIDs.append(m_userId);
+
+ emit locationItemClicked(userIDs);
+ }
+
+ update();
+}
+
+void FriendLocationItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (m_clickEvent) {
+ QIcon icon;
+ icon.addPixmap(pixmap());
+ painter->drawPixmap(offset(), icon.pixmap(pixmap().size(), QIcon::Selected,
+ QIcon::On));
+ } else {
+ BaseLocationItem::paint(painter, option, widget);
+ }
+}
+
+void FriendLocationItem::setPartOfGroup(bool value)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_partOfGroup = value;
+
+ if (value)
+ hide();
+ else
+ show();
}
-QString FriendLocationItem::name() const
+QString FriendLocationItem::userId() const
{
- return *m_name;
+ qDebug() << __PRETTY_FUNCTION__;
+
+ return m_userId;
+}
+
+void FriendLocationItem::setProfileImage(const QPixmap image, const QUrl &url)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ setPixmap(image);
+ setOffset(-image.width()/2, -image.height()/2);
+ m_profileImageUrl = url;
}
-void FriendLocationItem::setName(const QString &name)
+QUrl FriendLocationItem::profileImageUrl() const
{
- *m_name = name;
+ qDebug() << __PRETTY_FUNCTION__;
+
+ return m_profileImageUrl;
}
+