Properly handle hover events in ChatView
authorManuel Nickschas <sputnick@quassel-irc.org>
Wed, 24 Feb 2010 17:58:54 +0000 (18:58 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 24 Feb 2010 18:00:00 +0000 (19:00 +0100)
Fixes link underlines and hover previews sticking around sometimes.

src/qtui/chatline.cpp
src/qtui/chatline.h

index 6032cbe..2af3269 100644 (file)
@@ -49,7 +49,8 @@ ChatLine::ChatLine(int row, QAbstractItemModel *model,
     _width(width),
     _height(_contentsItem.height()),
     _selection(0),
-    _mouseGrabberItem(0)
+    _mouseGrabberItem(0),
+    _hoverItem(0)
 {
   Q_ASSERT(model);
   QModelIndex index = model->index(row, ChatLineModel::ContentsColumn);
@@ -247,14 +248,17 @@ void ChatLine::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
 
 void ChatLine::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
   ChatItem *item = mouseEventTargetItem(event->pos());
-  if(item)
+  if(item) {
+    Q_ASSERT(!_hoverItem);
+    _hoverItem = item;
     item->hoverEnterEvent(event);
+  }
 }
 
 void ChatLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
-  ChatItem *item = mouseEventTargetItem(event->pos());
-  if(item)
-    item->hoverLeaveEvent(event);
+  Q_ASSERT(_hoverItem);
+  _hoverItem->hoverLeaveEvent(event);
+  _hoverItem = 0;
 }
 
 void ChatLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
index 24947d0..824d50e 100644 (file)
@@ -101,6 +101,7 @@ private:
   quint8 _selection;  // save space, so we put both the col and the flags into one byte
 
   ChatItem *_mouseGrabberItem;
+  ChatItem *_hoverItem;
 };
 
 #endif