Added highlight mode to FriendGroupItem and FriendLocationItem.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Thu, 10 Jun 2010 08:30:26 +0000 (11:30 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Thu, 10 Jun 2010 08:30:26 +0000 (11:30 +0300)
src/map/friendgroupitem.cpp
src/map/friendgroupitem.h
src/map/friendlocationitem.cpp
src/map/friendlocationitem.h

index e7acab4..4217c10 100644 (file)
@@ -24,6 +24,7 @@
 #include <QPainter>
 #include <QRect>
 #include <QGraphicsSceneMouseEvent>
+#include <QIcon>
 
 #include "friendlocationitem.h"
 #include "mapcommon.h"
@@ -35,10 +36,13 @@ FriendGroupItem::FriendGroupItem(FriendLocationItem *item)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QPixmap pixmap(":/res/images/friend_group.png");
-    setPixmap(pixmap);
+    m_image = QPixmap(":/res/images/friend_group.png");
+    QIcon icon;
+    icon.addPixmap(m_image);
+    m_highlightImage = icon.pixmap(m_image.size(), QIcon::Selected, QIcon::On);
+    setPixmap(m_image);
 
-    setOffset(-pixmap.width()/2, -pixmap.height()/2);
+    setOffset(-m_image.width()/2, -m_image.height()/2);
     setZValue(FRIEND_LOCATION_ICON_Z_LEVEL);
 
     joinFriend(item);
@@ -110,10 +114,14 @@ 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)) {
+    if (m_clickEvent) {
+        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;
+            setPixmap(m_image);
+            m_clickEvent = false;
+        }
     }
 }
 
@@ -123,6 +131,7 @@ void FriendGroupItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
 
     m_mousePressPosition = event->pos().toPoint();
     m_clickEvent = true;
+    setPixmap(m_highlightImage);
 }
 
 void FriendGroupItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
@@ -132,7 +141,7 @@ void FriendGroupItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
     qDebug() << __PRETTY_FUNCTION__;
 
     if (m_clickEvent) {
-
+        setPixmap(m_image);
         QList<QString> userIDs;
 
         foreach (FriendLocationItem *item, m_friends)
index 9e3317f..9fb5d57 100644 (file)
@@ -147,6 +147,8 @@ private:
     QList<FriendLocationItem *> m_friends; ///< List of joined FriendLocationItem items
     QPoint m_mousePressPosition;    ///< Mouse press position
     bool m_clickEvent;              ///< Mouse click event flag
+    QPixmap m_image;            ///< Normal item image
+    QPixmap m_highlightImage;   ///< Highlighted item image
 };
 
 #endif // FRIENDGROUPITEM_H
index ffb8511..7335ca2 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <QDebug>
 #include <QGraphicsSceneMouseEvent>
+#include <QIcon>
 #include "friendlocationitem.h"
 #include "mapcommon.h"
 
@@ -50,16 +51,21 @@ void FriendLocationItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
 
     m_mousePressPosition = event->pos().toPoint();
     m_clickEvent = true;
+    setPixmap(m_highlightImage);
 }
 
 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)) {
+    if (m_clickEvent) {
+        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;
+            setPixmap(m_image);
+            m_clickEvent = false;
+        }
     }
 }
 
@@ -70,6 +76,7 @@ void FriendLocationItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
     Q_UNUSED(event);
 
     if (m_clickEvent) {
+        setPixmap(m_image);
         QList<QString> userIDs;
         userIDs.append(m_userId);
 
@@ -96,8 +103,12 @@ QString FriendLocationItem::userId() const
 void FriendLocationItem::setProfileImage(const QPixmap image, const QUrl &url)
 {
     qDebug() << __PRETTY_FUNCTION__;
-    setPixmap(image);
-    setOffset(-image.width()/2, -image.height()/2);
+    m_image = image;
+    QIcon icon;
+    icon.addPixmap(image);
+    m_highlightImage = icon.pixmap(image.size(), QIcon::Selected, QIcon::On);
+    setPixmap(m_image);
+    setOffset(-m_image.width()/2, -m_image.height()/2);
     m_profileImageUrl = url;
 }
 
index 1e2526d..3a5b1df 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <QObject>
 #include <QUrl>
+#include <QPixmap>
 
 #include "baselocationitem.h"
 
@@ -142,6 +143,8 @@ private:
     QUrl m_profileImageUrl; ///< Friends Facebook profile image URL
     QPoint m_mousePressPosition; ///< Mouse press position
     bool m_clickEvent;          ///< Flag to mark click event
+    QPixmap m_image;            ///< Normal item image
+    QPixmap m_highlightImage;   ///< Highlighted item image
 };
 
 #endif // FRIENDLOCATIONITEM_H