Fixed bug #5867.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 7 Jun 2010 13:14:24 +0000 (16:14 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 7 Jun 2010 13:14:24 +0000 (16:14 +0300)
Reviewed by: Henri Lampela.

src/gps/gpspositionprivateliblocation.cpp
src/map/friendgroupitem.cpp
src/map/friendgroupitem.h
src/map/friendlocationitem.cpp
src/map/friendlocationitem.h

index d328555..d888305 100644 (file)
@@ -122,7 +122,7 @@ void GPSPositionPrivate::requestLastPosition()
 
 void GPSPositionPrivate::positionUpdated(const GeoPositionInfo &positionInfo)
 {
-    qDebug() << __PRETTY_FUNCTION__ << positionInfo;
+    qDebug() << __PRETTY_FUNCTION__;
 
     if (positionInfo.coordinate().isValid()) {
         GeoCoordinate coordinate = positionInfo.coordinate();
index 69a5248..4611bca 100644 (file)
@@ -31,6 +31,7 @@
 #include "common.h"
 
 FriendGroupItem::FriendGroupItem(FriendLocationItem *item)
+    : m_clickEvent(false)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -105,19 +106,30 @@ void FriendGroupItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
                       Qt::AlignCenter, QString::number(m_friends.count()));
 }
 
+void FriendGroupItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if ((abs(m_mousePressPosition.y() - event->pos().toPoint().y()) > FRIEND_ITEM_PRESS_HEIGHT) ||
+        (abs(m_mousePressPosition.x() - event->pos().toPoint().x()) > FRIEND_ITEM_PRESS_WIDTH)) {
+
+        m_clickEvent = false;
+    }
+}
+
 void FriendGroupItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_mousePressPosition = event->screenPos();
+    m_mousePressPosition = event->pos().toPoint();
+    m_clickEvent = true;
 }
 
 void FriendGroupItem::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)) {
+    if (m_clickEvent) {
 
         QList<QString> userIDs;
 
index 9d3665c..9e3317f 100644 (file)
@@ -63,6 +63,16 @@ public:
 
 protected:
     /**
+    * @brief Mouse move event.
+    *
+    * Disables m_clickEvent flag if press and release where not
+    * in same area.
+    *
+    * @param event QGraphicsSceneMouseEvent.
+    */
+    void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
+
+    /**
     * @brief Mouse press event.
     *
     * Sets mouse press position.
@@ -136,6 +146,7 @@ signals:
 private:
     QList<FriendLocationItem *> m_friends; ///< List of joined FriendLocationItem items
     QPoint m_mousePressPosition;    ///< Mouse press position
+    bool m_clickEvent;              ///< Mouse click event flag
 };
 
 #endif // FRIENDGROUPITEM_H
index 2e5c04e..ffb8511 100644 (file)
@@ -30,7 +30,8 @@ FriendLocationItem::FriendLocationItem(const QString &userId,
     : BaseLocationItem(parent),
       m_partOfGroup(false),
       m_userId(userId),
-      m_mousePressPosition(QPoint(0, 0))
+      m_mousePressPosition(QPoint(0, 0)),
+      m_clickEvent(false)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -47,15 +48,28 @@ void FriendLocationItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_mousePressPosition = event->screenPos();
+    m_mousePressPosition = event->pos().toPoint();
+    m_clickEvent = true;
+}
+
+void FriendLocationItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if ((abs(m_mousePressPosition.y() - event->pos().toPoint().y()) > FRIEND_ITEM_PRESS_HEIGHT) ||
+        (abs(m_mousePressPosition.x() - event->pos().toPoint().x()) > FRIEND_ITEM_PRESS_WIDTH)) {
+
+        m_clickEvent = false;
+    }
 }
 
 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) {
         QList<QString> userIDs;
         userIDs.append(m_userId);
 
index 4cfbb9b..1e2526d 100644 (file)
@@ -99,6 +99,16 @@ public:
 
 protected:
     /**
+    * @brief method that detects when friend icon is moved
+    *
+    * Disables m_clickEvent flag if press and release where not
+    * in same area.
+    *
+    * @param event detects the mouse move (or touch in Maemo)
+    */
+    void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
+
+    /**
     * @brief method that detects when friend icon is clicked
     *
     * @param event detects the mouse click (or touch in Maemo)
@@ -131,6 +141,7 @@ private:
     const QString m_userId; ///< Friends user ID. Can't be changed afterwards
     QUrl m_profileImageUrl; ///< Friends Facebook profile image URL
     QPoint m_mousePressPosition; ///< Mouse press position
+    bool m_clickEvent;          ///< Flag to mark click event
 };
 
 #endif // FRIENDLOCATIONITEM_H