コード例 #1
0
 def parse_shape(self, shape, bounding_box):
     if shape in ('box', 'rect', 'rectangle'):
         self._graphics_item = QGraphicsRectItem(bounding_box)
     elif shape in ('ellipse', 'oval', 'circle'):
         self._graphics_item = QGraphicsEllipseItem(bounding_box)
     elif shape in ('box3d', ):
         self._graphics_item = QGraphicsBox3dItem(bounding_box)
     else:
         print("Invalid shape '%s', defaulting to ellipse" % shape, file=sys.stderr)
         self._graphics_item = QGraphicsEllipseItem(bounding_box)
コード例 #2
0
ファイル: node_item.py プロジェクト: codenotes/androidlibs2
    def __init__(self,
                 highlight_level,
                 bounding_box,
                 label,
                 shape,
                 color=None,
                 parent=None,
                 label_pos=None):
        super(NodeItem, self).__init__(highlight_level, parent)

        self._default_color = self._COLOR_BLACK if color is None else color
        self._brush = QBrush(self._default_color)
        self._label_pen = QPen()
        self._label_pen.setColor(self._default_color)
        self._label_pen.setJoinStyle(Qt.RoundJoin)
        self._ellipse_pen = QPen(self._label_pen)
        self._ellipse_pen.setWidth(1)

        self._incoming_edges = set()
        self._outgoing_edges = set()

        if shape == 'box':
            self._graphics_item = QGraphicsRectItem(bounding_box)
        else:
            self._graphics_item = QGraphicsEllipseItem(bounding_box)
        self.addToGroup(self._graphics_item)

        self._label = QGraphicsSimpleTextItem(label)
        label_rect = self._label.boundingRect()
        if label_pos is None:
            label_rect.moveCenter(bounding_box.center())
        else:
            label_rect.moveCenter(label_pos)
        self._label.setPos(label_rect.x(), label_rect.y())
        self.addToGroup(self._label)

        self.set_node_color()

        self.setAcceptHoverEvents(True)

        self.hovershape = None
コード例 #3
0
    def __init__(self, highlight_level, bounding_box, label, shape, color=None, parent=None, label_pos=None, tooltip=None):
        super(NodeItem, self).__init__(highlight_level, parent)

        self._default_color = self._COLOR_BLACK if color is None else color
        self._brush = QBrush(self._default_color)
        self._label_pen = QPen()
        self._label_pen.setColor(self._default_color)
        self._label_pen.setJoinStyle(Qt.RoundJoin)
        self._ellipse_pen = QPen(self._label_pen)
        self._ellipse_pen.setWidth(1)

        self._incoming_edges = set()
        self._outgoing_edges = set()

        if shape == 'box':
            self._graphics_item = QGraphicsRectItem(bounding_box)

        # Since we don't have unique GraphicsItems other than Ellipse and Rect,
        # Using Polygon to draw the following using bounding_box

        elif shape == 'octagon':
            rect = bounding_box.getRect()
            octagon_polygon = QPolygonF([QPointF(rect[0], rect[1] + 3 * rect[3] / 10),
                                         QPointF(rect[0], rect[1] + 7 * rect[3] / 10),
                                         QPointF(rect[0] + 3 * rect[2] / 10, rect[1] + rect[3]),
                                         QPointF(rect[0] + 7 * rect[2] / 10, rect[1] + rect[3]),
                                         QPointF(rect[0] + rect[2], rect[1] + 7 * rect[3] / 10),
                                         QPointF(rect[0] + rect[2], rect[1] + 3 * rect[3] / 10),
                                         QPointF(rect[0] + 7 * rect[2] / 10, rect[1]),
                                         QPointF(rect[0] + 3 * rect[2] / 10, rect[1])])
            self._graphics_item = QGraphicsPolygonItem(octagon_polygon)

        elif shape == 'doubleoctagon':
            rect = bounding_box.getRect()
            inner_fold = 3.0

            octagon_polygon = QPolygonF([QPointF(rect[0], rect[1] + 3 * rect[3] / 10),
                                         QPointF(rect[0], rect[1] + 7 * rect[3] / 10),
                                         QPointF(rect[0] + 3 * rect[2] / 10, rect[1] + rect[3]),
                                         QPointF(rect[0] + 7 * rect[2] / 10, rect[1] + rect[3]),
                                         QPointF(rect[0] + rect[2], rect[1] + 7 * rect[3] / 10),
                                         QPointF(rect[0] + rect[2], rect[1] + 3 * rect[3] / 10),
                                         QPointF(rect[0] + 7 * rect[2] / 10, rect[1]),
                                         QPointF(rect[0] + 3 * rect[2] / 10, rect[1]),
                                         # inner
                                         QPointF(rect[0], rect[1] + 3 * rect[3] / 10),
                                         QPointF(rect[0] + inner_fold, rect[1] + 3 * rect[3] / 10 + inner_fold / 2),
                                         QPointF(rect[0] + inner_fold, rect[1] + 7 * rect[3] / 10 - inner_fold / 2),
                                         QPointF(rect[0] + 3 * rect[2] / 10, rect[1] + rect[3] - inner_fold),
                                         QPointF(rect[0] + 7 * rect[2] / 10, rect[1] + rect[3] - inner_fold),
                                         QPointF(rect[0] + rect[2] - inner_fold, rect[1] + 7 * rect[3] / 10 - inner_fold / 2),
                                         QPointF(rect[0] + rect[2] - inner_fold, rect[1] + 3 * rect[3] / 10 + inner_fold / 2),
                                         QPointF(rect[0] + 7 * rect[2] / 10, rect[1] + inner_fold),
                                         QPointF(rect[0] + 3 * rect[2] / 10, rect[1] + inner_fold),
                                         QPointF(rect[0] + inner_fold, rect[1] + 3 * rect[3] / 10 + inner_fold / 2)
                                         ])

            self._graphics_item = QGraphicsPolygonItem(octagon_polygon)

        elif shape == 'note':
            rect = bounding_box.getRect()
            note_polygon = QPolygonF([QPointF(rect[0] + 9 * rect[2] / 10, rect[1]),
                                      QPointF(rect[0], rect[1]),
                                      QPointF(rect[0], rect[1] + rect[3]),
                                      QPointF(rect[0] + rect[2], rect[1] + rect[3]),
                                      QPointF(rect[0] + rect[2], rect[1] + rect[3] / 5),
                                      QPointF(rect[0] + 9 * rect[2] / 10, rect[1] + rect[3] / 5),
                                      QPointF(rect[0] + 9 * rect[2] / 10, rect[1]),
                                      QPointF(rect[0] + rect[2], rect[1] + rect[3] / 5),
                                      QPointF(rect[0] + rect[2], rect[1] + rect[3] / 5)])
            self._graphics_item = QGraphicsPolygonItem(note_polygon)

        else:
            self._graphics_item = QGraphicsEllipseItem(bounding_box)
        self.addToGroup(self._graphics_item)

        self._label = QGraphicsSimpleTextItem(label)
        label_rect = self._label.boundingRect()
        if label_pos is None:
            label_rect.moveCenter(bounding_box.center())
        else:
            label_rect.moveCenter(label_pos)
        self._label.setPos(label_rect.x(), label_rect.y())
        self.addToGroup(self._label)
        if tooltip is not None:
            self.setToolTip(tooltip)

        self.set_node_color()

        self.setAcceptHoverEvents(True)

        self.hovershape = None
コード例 #4
0
ファイル: shape_factory.py プロジェクト: iosp/robil2
    def create(shape, bounding_box):
        ShapeFactory.message = None
        graphics_item = None

        if shape in ('box', 'rect', 'rectangle'):
            graphics_item = QGraphicsRoundRectItem(bounding_box)
        elif shape in ('ellipse', 'point'):
            graphics_item = QGraphicsEllipseItem(bounding_box)
        elif shape == 'diamond':
            points = QPolygonF([
                QPointF(bounding_box.x(),
                        bounding_box.y() + bounding_box.height() / 2),
                QPointF(bounding_box.x() + bounding_box.width() / 2,
                        bounding_box.y() + bounding_box.height()),
                QPointF(bounding_box.x() + bounding_box.width(),
                        bounding_box.y() + bounding_box.height() / 2),
                QPointF(bounding_box.x() + bounding_box.width() / 2,
                        bounding_box.y())
            ])
            graphics_item = QGraphicsPolygonItem(points)
        elif shape == 'parallelogram':
            points = QPolygonF([
                QPointF(bounding_box.x() + bounding_box.width() * 1 / 6,
                        bounding_box.y()),
                QPointF(bounding_box.x() + bounding_box.width(),
                        bounding_box.y()),
                QPointF(bounding_box.x() + bounding_box.width() * 5 / 6,
                        bounding_box.y() + bounding_box.height()),
                QPointF(bounding_box.x(),
                        bounding_box.y() + bounding_box.height())
            ])
            graphics_item = QGraphicsPolygonItem(points)
        elif shape == 'cds':
            points = QPolygonF([
                QPointF(bounding_box.x(), bounding_box.y()),
                QPointF(bounding_box.x() + bounding_box.width() * 5 / 6,
                        bounding_box.y()),
                QPointF(bounding_box.x() + bounding_box.width(),
                        bounding_box.y() + bounding_box.height() / 2),
                QPointF(bounding_box.x() + bounding_box.width() * 5 / 6,
                        bounding_box.y() + bounding_box.height()),
                QPointF(bounding_box.x(),
                        bounding_box.y() + bounding_box.height())
            ])
            graphics_item = QGraphicsPolygonItem(points)
        elif shape == 'rarrow':
            points = QPolygonF([
                QPointF(bounding_box.x(), bounding_box.y()),
                QPointF(bounding_box.x() + bounding_box.width() * 4 / 6,
                        bounding_box.y()),
                QPointF(bounding_box.x() + bounding_box.width() * 4 / 6,
                        bounding_box.y() - bounding_box.height() * 2 / 6),
                QPointF(bounding_box.x() + bounding_box.width(),
                        bounding_box.y() + bounding_box.height() / 2),
                QPointF(bounding_box.x() + bounding_box.width() * 4 / 6,
                        bounding_box.y() + bounding_box.height() * 8 / 6),
                QPointF(bounding_box.x() + bounding_box.width() * 4 / 6,
                        bounding_box.y() + bounding_box.height()),
                QPointF(bounding_box.x(),
                        bounding_box.y() + bounding_box.height())
            ])
            graphics_item = QGraphicsPolygonItem(points)
        elif shape == 'larrow':
            points = QPolygonF([
                QPointF(bounding_box.x() + bounding_box.width() * 2 / 6,
                        bounding_box.y()),
                QPointF(bounding_box.x() + bounding_box.width() * 2 / 6,
                        bounding_box.y() - bounding_box.height() * 2 / 6),
                QPointF(bounding_box.x(),
                        bounding_box.y() + bounding_box.height() / 2),
                QPointF(bounding_box.x() + bounding_box.width() * 2 / 6,
                        bounding_box.y() + bounding_box.height() * 8 / 6),
                QPointF(bounding_box.x() + bounding_box.width() * 2 / 6,
                        bounding_box.y() + bounding_box.height()),
                QPointF(bounding_box.x() + bounding_box.width(),
                        bounding_box.y() + bounding_box.height()),
                QPointF(bounding_box.x() + bounding_box.width(),
                        bounding_box.y())
            ])
            graphics_item = QGraphicsPolygonItem(points)
        elif shape == 'record':
            graphics_item = QGraphicsRectItem(bounding_box)
        elif shape == 'hexagon':
            points = QPolygonF([
                QPointF(bounding_box.x() + bounding_box.width() * 1 / 5,
                        bounding_box.y()),
                QPointF(bounding_box.x() + bounding_box.width() * 4 / 5,
                        bounding_box.y()),
                QPointF(bounding_box.x() + bounding_box.width(),
                        bounding_box.y() + bounding_box.height() / 2),
                QPointF(bounding_box.x() + bounding_box.width() * 4 / 5,
                        bounding_box.y() + bounding_box.height()),
                QPointF(bounding_box.x() + bounding_box.width() * 1 / 5,
                        bounding_box.y() + bounding_box.height()),
                QPointF(bounding_box.x(),
                        bounding_box.y() + bounding_box.height() / 2)
            ])
            graphics_item = QGraphicsPolygonItem(points)
        elif shape == 'triangle':
            points = QPolygonF([
                QPointF(bounding_box.x() + bounding_box.width() / 2,
                        bounding_box.y()),
                QPointF(bounding_box.x() + bounding_box.width(),
                        bounding_box.y() + bounding_box.height() * 3 / 4),
                QPointF(bounding_box.x(),
                        bounding_box.y() + bounding_box.height() * 3 / 4)
            ])
            graphics_item = QGraphicsPolygonItem(points)
        elif shape == 'circle':
            diameter = min(bounding_box.width(), bounding_box.height())
            graphics_item = QGraphicsEllipseItem(bounding_box.x(),
                                                 bounding_box.y(), diameter,
                                                 diameter)
        else:
            graphics_item = QGraphicsRectItem(bounding_box)
            ShapeFactory.message = "WARNING: %s is unknown shape, box used instead" % shape

        return graphics_item