Exemple #1
0
    def resize_scene(self):
        center_x = self.mapToScene(
            QtCore.QPoint(self.viewport().width() / 2,
                          self.viewport().height() / 2)).x()
        center_y = self.mapToScene(
            QtCore.QPoint(self.viewport().width() / 2,
                          self.viewport().height() / 2)).y()
        w = self.viewport().width() / self.current_zoom * 2 + 25000
        h = self.viewport().height() / self.current_zoom * 2 + 25000

        self.scene().setSceneRect(
            QtCore.QRectF(center_x - w / 2, center_y - h / 2, w, h))

        show_detail = True if self.current_zoom >= 0.5 else False
        point1 = self.mapToScene(QtCore.QPoint(0, 0))
        point2 = self.mapToScene(
            QtCore.QPoint(self.viewport().width(),
                          self.viewport().height()))
        rect = QtCore.QRectF(point1, point2)
        for version_node in self.nodes():
            if hasattr(version_node, 'version_widget'):
                version_node.version_widget.setVisible(show_detail)
            else:
                if rect.contains(version_node.pos()) and show_detail:
                    # version_node.start_show_version_widget()
                    version_node.show_version_widget()
                    QtCore.QCoreApplication.processEvents()
            for knob in version_node.knobs():
                knob.setVisible(show_detail)
            for tag in version_node.tags():
                if tag.auto_hide:
                    tag.setVisible(show_detail)
Exemple #2
0
    def __init__(self, combine_version=False, parent=None):
        super(GraphicsSceneWidget, self).__init__(parent=parent)

        self.scene = GraphicsScene(combine_version=combine_version,
                                   parent=self)
        # orientation: 0-h 1-v
        self.view = GraphicsView()
        self.view.setScene(self.scene)
        self.setGeometry(100, 100, 800, 600)

        self.view.setRenderHint(QtGui.QPainter.Antialiasing)
        self.view.setViewportUpdateMode(
            QtWidgets.QGraphicsView.FullViewportUpdate)

        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(self.view)
        self.setLayout(layout)

        self.scene.setSceneRect(
            QtCore.QRectF(
                -(self.view.viewport().width() / self.view.current_zoom * 2 +
                  25000) / 2,
                -(self.view.viewport().height() / self.view.current_zoom * 2 +
                  25000) / 2,
                self.view.viewport().width() / self.view.current_zoom * 2 +
                25000,
                self.view.viewport().height() / self.view.current_zoom * 2 +
                25000))

        # self.itemPopulate.connect(self.test, QtCore.Qt.QueuedConnection)
        self.showWidgetSignal.connect(self.show_version_widget,
                                      QtCore.Qt.QueuedConnection)
Exemple #3
0
    def boundingRect(self):
        """Return the bounding box of the Node.

        :return:
        """
        rect = QtCore.QRectF(self.x, self.y, self.w, self.h)

        return rect
Exemple #4
0
    def __init__(self, combine_version=False, **kwargs):
        super(GraphicsScene, self).__init__(**kwargs)

        self.combine_version = combine_version

        self.depth = 0

        self.max_y_depth = 0

        self.node_dict = {"depth": 2, "nodes": {}}

        self.setSceneRect(QtCore.QRectF(-25000 / 2, -25000 / 2, 25000, 25000))
Exemple #5
0
    def paint(self, painter, option, widget):
        """Draw the Tag's shape and label."""
        bbox = self.boundingRect()

        if self.shape is not None:
            painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))
            painter.setBrush(QtGui.QBrush(self.fillColor))

            # Draw a filled rectangle.
            if self.shape == 1:
                roundness = 3
                painter.drawRoundedRect(bbox, roundness, roundness)

            # Ellipse
            if self.shape == 2:
                painter.drawEllipse(bbox)

            # Triangle0
            if self.shape == 3:
                points, rects = get_shapes_of_triangle(self.w,
                                                       roundness=2,
                                                       direction=0)
                painter.drawPolygon(QtGui.QPolygonF(points))
                for rect in rects:
                    painter.drawEllipse(rect)

            # Triangle2
            if self.shape == 4:
                points, rects = get_shapes_of_triangle(self.w,
                                                       roundness=2,
                                                       direction=2)
                painter.drawPolygon(QtGui.QPolygonF(points))
                for rect in rects:
                    painter.drawEllipse(rect)

        if self.text is not None:
            painter.setPen(QtGui.QPen(self.textColor))
            font = painter.font()
            fm = QtGui.QFontMetrics(font)
            w = fm.boundingRect(self.text).width() + 10
            h = fm.boundingRect(self.text).height()
            rect = QtCore.QRectF(0 - (w - bbox.width()) / 2.0,
                                 0 - (h - bbox.height()) / 2.0, w, h)
            painter.drawText(rect, QtCore.Qt.AlignCenter, self.text)
Exemple #6
0
    def mouseMoveEvent(self, event):
        if self.panning:
            mouse_move = event.pos() - self.prevPos
            newCenter = QtCore.QPointF(
                self.prev_center.x() - mouse_move.x() / self.current_zoom,
                self.prev_center.y() - mouse_move.y() / self.current_zoom)
            self.centerOn(newCenter)

            show_detail = True if self.current_zoom >= 0.5 else False
            if show_detail:
                point1 = self.mapToScene(QtCore.QPoint(0, 0))
                point2 = self.mapToScene(
                    QtCore.QPoint(self.viewport().width(),
                                  self.viewport().height()))
                rect = QtCore.QRectF(point1, point2)
                for version_node in self.nodes():
                    if rect.contains(version_node.pos()) and not hasattr(
                            version_node, 'version_widget'):
                        version_node.start_show_version_widget()
                        # print version_node.pos(), point1, point2

            return
        super(GraphicsView, self).mouseMoveEvent(event)
Exemple #7
0
def get_rect_of_ellipse(center_x, center_y, radius):
    x = center_x - radius
    y = center_y - radius
    w = 2.0 * radius
    h = 2.0 * radius
    return QtCore.QRectF(x, y, w, h)