dmg_node_item.py
Go to the documentation of this file.
00001 """
00002 Copyright (c) 2013, Cogniteam
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 are met:
00007 
00008 *   Redistributions of source code must retain the above copyright
00009     notice, this list of conditions and the following disclaimer.
00010 
00011 *   Redistributions in binary form must reproduce the above copyright
00012     notice, this list of conditions and the following disclaimer in the
00013     documentation and/or other materials provided with the distribution.
00014 
00015 *   Neither the name of the Cogniteam nor the
00016     names of its contributors may be used to endorse or promote products
00017     derived from this software without specific prior written permission.
00018 
00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00020 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00023 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 """
00030 
00031 from python_qt_binding.QtCore import Qt
00032 from python_qt_binding.QtGui import QBrush, QGraphicsSimpleTextItem, QPen, QColor
00033 from .hovered_node_item import HoveredNodeItem
00034 
00035 
00036 class DmgNodeItem(HoveredNodeItem):
00037 
00038     HIGHLIGHTED_COLOR = QColor(100, 100, 100)
00039     HIGHLIGHTED_PEN_WIDTH = 2.0
00040     HIGHLIGHTED_LABEL_PEN_WIDTH = 1.0
00041 
00042     def __init__(self, bounding_box, shape, label, label_pos=None, url=None, parent=None, **kwargs):
00043         super(DmgNodeItem, self).__init__(bounding_box, shape, label, label_pos, url, parent, **kwargs)
00044 
00045         self._highlighted_color = kwargs.get('highlighted_color', self.HIGHLIGHTED_COLOR)
00046         self._highlighted_pen_width = kwargs.get('highlighted_pen_width', self.HIGHLIGHTED_PEN_WIDTH)
00047         self._highlighted_label_pen_width = kwargs.get('highlighted_label_pen_width', self.HIGHLIGHTED_LABEL_PEN_WIDTH)
00048 
00049         self._current_color = self._color
00050         self._previous_color = self._color
00051 
00052         self._current_pen_width = self._pen_width
00053         self._previous_pen_width = self._pen_width
00054 
00055     def set_color(self, color=None):
00056         if color is None:
00057             color = self._color
00058 
00059         self._previous_color = self._current_color
00060         self._current_color = color
00061 
00062         self._brush.setColor(color)
00063         self._graphics_item_pen.setColor(color)
00064         self._label_pen.setColor(color)
00065 
00066         self._graphics_item_pen.setColor(color)
00067         self._graphics_item.setPen(self._graphics_item_pen)
00068 
00069         if self._label is not None:
00070             self._label.setBrush(self._brush)
00071             self._label.setPen(self._label_pen)
00072 
00073     def hoverEnterEvent(self, event):
00074         self.set_color(self._highlighted_color)
00075         self._highlight_connections()
00076 
00077     def hoverLeaveEvent(self, event):
00078         self.set_color()
00079         self._highlight_connections(False)
00080 
00081     def highlight(self, highlighted=True):
00082         if highlighted:
00083             self._graphics_item_pen.setWidthF(self._highlighted_pen_width)
00084             self._label_pen.setWidthF(self._highlighted_label_pen_width)
00085         else:
00086             self._graphics_item_pen.setWidthF(self._pen_width)
00087             self._label_pen.setWidthF(self._label_pen_width)
00088 
00089         self._label.setPen(self._label_pen)
00090         self._graphics_item.setPen(self._graphics_item_pen)
00091 


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