hovered_edge_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, QPointF
00036 from python_qt_binding.QtGui import QBrush, QGraphicsSimpleTextItem, QPen, QColor, QPainterPath, QGraphicsPolygonItem, \
00037                                     QPolygonF, QPainterPath, QGraphicsPathItem
00038 from .edge_item import EdgeItem
00039 
00040 
00041 class HoveredEdgeItem(EdgeItem):
00042 
00043     HIGHLIGHT_LEVEL = 1
00044     HOVERED_COLOR = QColor(250, 0, 0)
00045 
00046     def __init__(self, spline, label, label_center, from_node, to_node,
00047                  parent=None, **kwargs):
00048         super(HoveredEdgeItem, self).__init__(spline, label, label_center, from_node, to_node, 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         if self._label is not None:
00054             self._label.hoverEnterEvent = self.hoverEnterEvent
00055             self._label.hoverLeaveEvent = self.hoverLeaveEvent
00056             self._label.setAcceptHoverEvents(True)
00057 
00058         if self._arrow is not None:
00059             self._arrow.hoverEnterEvent = self.hoverEnterEvent
00060             self._arrow.hoverLeaveEvent = self.hoverLeaveEvent
00061             self._arrow.setAcceptHoverEvents(True)
00062 
00063     def hoverEnterEvent(self, event):
00064          # hovered edge item in red
00065         self.set_color(self._hovered_color)
00066         self._highlight_connections()
00067 
00068     def hoverLeaveEvent(self, event):
00069         self.set_color()
00070         self._highlight_connections(False)
00071 
00072     def _highlight_connections(self, highlighted=True):
00073         if highlighted:
00074             if self._highlight_level > 1:
00075                 if self.from_node != self.to_node:
00076                     # from-node in blue
00077                     self.from_node.set_color(self.COLOR_BLUE)
00078                     # to-node in green
00079                     self.to_node.set_color(self.COLOR_GREEN)
00080                 else:
00081                     # from-node/in-node in teal
00082                     self.from_node.set_color(self.COLOR_TEAL)
00083                     self.to_node.set_color(self.COLOR_TEAL)
00084             if self._highlight_level > 2:
00085                 # sibling edges in orange
00086                 for sibling_edge in self._sibling_edges:
00087                     sibling_edge.set_color(self.COLOR_ORANGE)
00088         else:
00089             if self._highlight_level > 1:
00090                 self.from_node.set_color()
00091                 self.to_node.set_color()
00092             if self._highlight_level > 2:
00093                 for sibling_edge in self._sibling_edges:
00094                     sibling_edge.set_color()


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