#include <QDebug>
#include <QGraphicsSceneMouseEvent>
+#include <QIcon>
#include "friendlocationitem.h"
#include "mapcommon.h"
: BaseLocationItem(parent),
m_partOfGroup(false),
m_userId(userId),
- m_mousePressPosition(QPoint(0, 0))
+ m_mousePressPosition(QPoint(0, 0)),
+ m_clickEvent(false)
{
qDebug() << __PRETTY_FUNCTION__;
bool FriendLocationItem::isPartOfGroup() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return m_partOfGroup;
}
{
qDebug() << __PRETTY_FUNCTION__;
- m_mousePressPosition = event->screenPos();
+ 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__;
- if ((abs(m_mousePressPosition.y() - event->screenPos().y()) <= FRIEND_ITEM_PRESS_HEIGHT) &&
- (abs(m_mousePressPosition.x() - event->screenPos().x()) <= FRIEND_ITEM_PRESS_WIDTH)) {
+ Q_UNUSED(event);
+
+ 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)
QString FriendLocationItem::userId() const
{
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;
QUrl FriendLocationItem::profileImageUrl() const
{
qDebug() << __PRETTY_FUNCTION__;
+
return m_profileImageUrl;
}