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
00037
00038 from .graph_item import GraphItem
00039 from .shape_factory import ShapeFactory
00040
00041
00042 class NodeItem(GraphItem):
00043
00044 def __init__(self, bounding_box, shape, label, label_pos=None, url=None, parent=None, **kwargs):
00045 super(NodeItem, self).__init__(parent, **kwargs)
00046
00047 self.url = url
00048 self._incoming_edges = set()
00049 self._outgoing_edges = set()
00050 self._brush = QBrush(self._color)
00051
00052 self._label_pen = QPen()
00053 self._label_pen.setColor(self._color)
00054 self._label_pen.setJoinStyle(Qt.RoundJoin)
00055 self._label_pen.setWidthF(self._label_pen_width)
00056
00057 if self._pen_width == 0.0:
00058 self._graphics_item_pen = QPen(Qt.NoPen)
00059 else:
00060 self._graphics_item_pen = QPen(self._label_pen)
00061 self._graphics_item_pen.setWidthF(self._pen_width)
00062
00063 self._graphics_item = ShapeFactory.create(shape, bounding_box)
00064 if ShapeFactory.message is not None:
00065 print ShapeFactory.message
00066
00067 self.addToGroup(self._graphics_item)
00068
00069 if not shape == 'point':
00070 self._label = QGraphicsSimpleTextItem(label)
00071
00072 label_rectangle = self._label.boundingRect()
00073 if label_pos is None:
00074 label_rectangle.moveCenter(bounding_box.center())
00075 else:
00076 label_rectangle.moveCenter(label_pos)
00077 self._label.setPos(label_rectangle.x(), label_rectangle.y())
00078
00079 self.addToGroup(self._label)
00080 else:
00081 self._graphics_item.setBrush(self._color)
00082 self._label = None
00083
00084 self._brush.setColor(self._color)
00085 self._graphics_item_pen.setColor(self._color)
00086 self._label_pen.setColor(self._color)
00087
00088 self._graphics_item.setPen(self._graphics_item_pen)
00089
00090 if self._label is not None:
00091 self._label.setBrush(self._brush)
00092 self._label.setPen(self._label_pen)
00093
00094 def add_incoming_edge(self, edge):
00095 self._incoming_edges.add(edge)
00096
00097 def add_outgoing_edge(self, edge):
00098 self._outgoing_edges.add(edge)
00099
00100 def set_color(self, color=None):
00101 if color is None:
00102 color = self._color
00103
00104 self._brush.setColor(color)
00105 self._graphics_item_pen.setColor(color)
00106 self._label_pen.setColor(color)
00107
00108 self._graphics_item.setPen(self._graphics_item_pen)
00109
00110 if self._label is not None:
00111 self._label.setBrush(self._brush)
00112 self._label.setPen(self._label_pen)