hovered_node_item.py
Go to the documentation of this file.
00001 """
00002 Copyright (c) 2011, Dirk Thomas, TU Darmstadt
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions
00007 are met:
00008 
00009   * Redistributions of source code must retain the above copyright
00010     notice, this list of conditions and the following disclaimer.
00011   * Redistributions in binary form must reproduce the above
00012     copyright notice, this list of conditions and the following
00013     disclaimer in the documentation and/or other materials provided
00014     with the distribution.
00015   * Neither the name of the TU Darmstadt nor the names of its
00016     contributors may be used to endorse or promote products derived
00017     from this software without specific prior written permission.
00018 
00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00022 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00023 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00024 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00025 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00027 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00028 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00029 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00030 POSSIBILITY OF SUCH DAMAGE.
00031 
00032 Note: This is modified version by CogniTeam
00033 """
00034 
00035 from python_qt_binding.QtCore import Qt
00036 from python_qt_binding.QtGui import QBrush, QGraphicsSimpleTextItem, QPen, QPainterPath, QColor
00037 from .node_item import NodeItem
00038 
00039 
00040 class HoveredNodeItem(NodeItem):
00041 
00042     HIGHLIGHT_LEVEL = 1
00043     HOVERED_COLOR = QColor(250, 0, 0)
00044 
00045     def __init__(self, bounding_box, shape, label, label_pos=None, url=None,
00046                  parent=None, **kwargs):
00047 
00048         super(HoveredNodeItem, self).__init__(bounding_box, shape, label, label_pos, url, parent, **kwargs)
00049 
00050         self._highlight_level = kwargs.get('highlight_level', self.HIGHLIGHT_LEVEL)
00051         self._hovered_color = kwargs.get('hovered_color', self.HOVERED_COLOR)
00052 
00053         self.hover_shape = None
00054         self.setAcceptHoverEvents(True)
00055 
00056     def set_hover_shape(self, shape):
00057         self.hover_shape = shape
00058 
00059     def shape(self):
00060         if self.hover_shape is not None:
00061             path = QPainterPath()
00062             path.addRect(self.hover_shape)
00063             return path
00064         else:
00065             return super(HoveredNodeItem, self).shape()
00066 
00067     def hoverEnterEvent(self, event):
00068         self.set_color(self.COLOR_RED)
00069         self._highlight_connections()
00070 
00071     def hoverLeaveEvent(self, event):
00072         self.set_color()
00073         self._highlight_connections(False)
00074 
00075     def _highlight_connections(self, highlighted=True):
00076         if highlighted:
00077             if self._highlight_level > 1:
00078                 cyclic_edges = self._incoming_edges.intersection(self._outgoing_edges)
00079                 # incoming edges in blue
00080                 incoming_nodes = set()
00081                 for incoming_edge in self._incoming_edges.difference(cyclic_edges):
00082                     incoming_edge.set_color(self.COLOR_BLUE)
00083                     if incoming_edge.from_node != self:
00084                         incoming_nodes.add(incoming_edge.from_node)
00085                 # outgoing edges in green
00086                 outgoing_nodes = set()
00087                 for outgoing_edge in self._outgoing_edges.difference(cyclic_edges):
00088                     outgoing_edge.set_color(self.COLOR_GREEN)
00089                     if outgoing_edge.to_node != self:
00090                         outgoing_nodes.add(outgoing_edge.to_node)
00091                 # incoming/outgoing edges in teal
00092                 for edge in cyclic_edges:
00093                     edge.set_color(self.COLOR_TEAL)
00094 
00095                 if self._highlight_level > 2:
00096                     cyclic_nodes = incoming_nodes.intersection(outgoing_nodes)
00097                     # incoming nodes in blue
00098                     for incoming_node in incoming_nodes.difference(cyclic_nodes):
00099                         incoming_node.set_color(self.COLOR_BLUE)
00100                     # outgoing nodes in green
00101                     for outgoing_node in outgoing_nodes.difference(cyclic_nodes):
00102                         outgoing_node.set_color(self.COLOR_GREEN)
00103                     # incoming/outgoing nodes in teal
00104                     for node in cyclic_nodes:
00105                         node.set_color(self.COLOR_TEAL)
00106             else:
00107                 if self._highlight_level > 1:
00108                     for incoming_edge in self._incoming_edges:
00109                         incoming_edge.set_color()
00110                         if self.highlight_level > 2 and incoming_edge.from_node != self:
00111                             incoming_edge.from_node.set_color()
00112                     for outgoing_edge in self._outgoing_edges:
00113                         outgoing_edge.set_color()
00114                         if self.highlight_level > 2 and outgoing_edge.to_node != self:
00115                             outgoing_edge.to_node.set_color()


rqt_decision_graph
Author(s):
autogenerated on Wed Aug 26 2015 11:16:47