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.QtGui import QColor 00032 from python_qt_binding.QtCore import QRectF 00033 from .dmg_node_item import DmgNodeItem 00034 from .dmg_html_node_item import DmgHtmlNodeItem 00035 from .dmg_edge_item import DmgEdgeItem 00036 from .hovered_item_factory import HoveredGraphItemFactory 00037 00038 00039 class DmgItemFactory(HoveredGraphItemFactory): 00040 def __init__(self): 00041 super(DmgItemFactory, self).__init__() 00042 self._highlighted_pen_width = 3.0 00043 self._highlighted_label_pen_width = 1.0 00044 self._highlighted_color = QColor(0, 150, 0) 00045 00046 def set_highlighted_pen_width(self, highlighted_pen_width): 00047 self._highlighted_pen_width = highlighted_pen_width 00048 00049 def highlighted_pen_width(self): 00050 return self._highlighted_pen_width 00051 00052 def set_highlighted_label_pen_width(self, highlighted_label_pen_width): 00053 self._highlighted_label_pen_width = highlighted_label_pen_width 00054 00055 def highlighted_label_pen_width(self): 00056 return self._highlighted_label_pen_width 00057 00058 def set_highlighted_color(self, highlighted_color): 00059 self._highlighted_color = highlighted_color 00060 00061 def highlighted_color(self): 00062 return self._highlighted_color 00063 00064 def set_highlighted_color(self, highlighted_color): 00065 self._highlighted_color = highlighted_color 00066 00067 def highlighted_color(self): 00068 return self._highlighted_color 00069 00070 def create_edge(self, spline, label, label_center, from_node, to_node, parent=None, **kwargs): 00071 self._check_constraints(kwargs, False) 00072 return DmgEdgeItem(spline, label, label_center, from_node, to_node, parent, **kwargs) 00073 00074 def create_node(self, bounding_box, shape, label, label_pos=None, url=None, parent=None, cluster=False, **kwargs): 00075 self._check_constraints(kwargs) 00076 00077 if label.startswith('<') and label.endswith('>'): 00078 node_item = DmgHtmlNodeItem(bounding_box, shape, label[1:-1], label_pos, url, parent, **kwargs) 00079 else: 00080 node_item = DmgNodeItem(bounding_box, shape, label, label_pos, url, parent, **kwargs) 00081 00082 if cluster: 00083 bounding_box = QRectF(bounding_box) 00084 bounding_box.setHeight(30) 00085 node_item.set_hover_shape(bounding_box) 00086 00087 return node_item 00088 00089 def _check_constraints(self, dictionary, node=True): 00090 super(DmgItemFactory, self)._check_constraints(dictionary, node) 00091 00092 if 'highlighted_color' not in dictionary: 00093 dictionary['highlighted_color'] = self._highlighted_color 00094 00095 if 'highlighted_pen_width' not in dictionary: 00096 dictionary['highlighted_pen_width'] = self._highlighted_pen_width 00097 00098 if 'highlighted_label_pen_width' not in dictionary: 00099 dictionary['highlighted_label_pen_width'] = self._highlighted_label_pen_width