Ignore:
Timestamp:
11/14/12 15:33:53 (17 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Changed how hover events are handled in 'LinkItem'.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/canvas/items/linkitem.py

    r11182 r11184  
    1010) 
    1111 
    12 from PyQt4.QtCore import Qt, QPointF 
     12from PyQt4.QtCore import Qt, QPointF, QEvent 
    1313 
    1414from .nodeitem import SHADOW_COLOR 
     
    127127        self.sinkItem = None 
    128128        self.sinkAnchor = None 
     129 
    129130        self.curveItem = LinkCurveItem(self) 
     131 
    130132        self.sourceIndicator = LinkAnchorIndicator(self) 
    131133        self.sinkIndicator = LinkAnchorIndicator(self) 
     
    289291 
    290292    def __updateText(self): 
     293        self.prepareGeometryChange() 
     294 
    291295        if self.__sourceName or self.__sinkName: 
    292296            text = "{0} --> {1}".format(self.__sourceName, self.__sinkName) 
     
    318322    def setHoverState(self, state): 
    319323        if self.hover != state: 
     324            self.prepareGeometryChange() 
    320325            self.hover = state 
    321326            self.sinkIndicator.setHoverState(state) 
     
    324329 
    325330    def hoverEnterEvent(self, event): 
    326         self.setHoverState(True) 
     331        # Hover enter event happens when the mouse enters any child object 
     332        # but we only want to show the 'hovered' shadow when the mouse 
     333        # is over the 'curveItem', so we install self as an event filter 
     334        # on the item and listen to the hover events. 
     335        self.curveItem.installSceneEventFilter(self) 
    327336        return QGraphicsObject.hoverEnterEvent(self, event) 
    328337 
    329338    def hoverLeaveEvent(self, event): 
    330         self.setHoverState(False) 
     339        # Remove the event filter to prevent unnecessary work in 
     340        # scene event filter when not needed 
     341        self.curveItem.removeSceneEventFilter(self) 
    331342        return QGraphicsObject.hoverLeaveEvent(self, event) 
     343 
     344    def sceneEventFilter(self, obj, event): 
     345        if obj is self.curveItem: 
     346            if event.type() == QEvent.GraphicsSceneHoverEnter: 
     347                self.setHoverState(True) 
     348            elif event.type() == QEvent.GraphicsSceneHoverLeave: 
     349                self.setHoverState(False) 
     350 
     351        return QGraphicsObject.sceneEventFilter(self, obj, event) 
    332352 
    333353    def boundingRect(self): 
     
    358378 
    359379    def __updatePen(self): 
     380        self.prepareGeometryChange() 
    360381        if self.__dynamic: 
    361382            if self.__dynamicEnabled: 
Note: See TracChangeset for help on using the changeset viewer.