Ejemplo n.º 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)
Ejemplo n.º 2
0
 def paintEvent(self, event):
     super(AttachmentLabel, self).paintEvent(event)
     if self.text() != '':
         painter = QtGui.QPainter(self)
         painter.drawLine(QtCore.QPoint(0,
                                        self.height() - 1),
                          QtCore.QPoint(self.width(),
                                        self.height() - 1))
Ejemplo n.º 3
0
    def drawBackground(self, painter, rect):
        painter.setBrush(QtGui.QBrush(self.fillColor))
        painter.setPen(QtGui.QPen(self.lineColor))

        painter.drawRect(rect)
        lines = []
        scale = max(int(1 / self.current_zoom / 2), 1)
        line_w = 200 * scale
        line_h = 80 * scale

        point1 = self.mapToScene(QtCore.QPoint(0, 0))
        point2 = self.mapToScene(
            QtCore.QPoint(self.viewport().width(),
                          self.viewport().height()))

        # for i in range(int(point1.y() / line_h), int(self.scene().height() / line_h)):
        for i in range(int(point1.y() / line_h), int(point2.y() / line_h)):
            lines.append(
                QtCore.QLineF(
                    QtCore.QPoint(rect.x(), i * line_h),
                    QtCore.QPoint(rect.x() + rect.width(), i * line_h)))
        # for i in range(int(self.scene().sceneRect().x()), int(self.scene().width() / line_w)):
        for i in range(int(point1.x() / line_w), int(point2.x() / line_w)):
            lines.append(
                QtCore.QLineF(
                    QtCore.QPoint(i * line_w, rect.y()),
                    QtCore.QPoint(i * line_w,
                                  rect.y() + rect.height())))
        painter.drawLines(lines)

        painter.setPen(QtGui.QPen(QtGui.QColor(80, 80, 60, 50)))
        painter.drawLine(
            QtCore.QLineF(QtCore.QPoint(rect.x(), 0),
                          QtCore.QPoint(rect.x() + rect.width(), 0)))
        painter.drawLine(
            QtCore.QLineF(QtCore.QPoint(0, rect.y()),
                          QtCore.QPoint(0,
                                        rect.y() + rect.height())))
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
 def mousePressEvent(self, event):
     """Initiate custom panning using middle mouse button."""
     selected_items = self.scene().selectedItems()
     if event.button() == QtCore.Qt.MiddleButton:
         self.setDragMode(QtWidgets.QGraphicsView.NoDrag)
         self.panning = True
         self.prevPos = event.pos()
         self.prev_center = self.mapToScene(
             QtCore.QPoint(self.viewport().width() / 2,
                           self.viewport().height() / 2))
         self.setCursor(QtCore.Qt.SizeAllCursor)
     elif event.button() == QtCore.Qt.LeftButton:
         self.setDragMode(QtWidgets.QGraphicsView.RubberBandDrag)
     super(GraphicsView, self).mousePressEvent(event)
     if event.button() == QtCore.Qt.MiddleButton:
         for item in selected_items:
             item.setSelected(True)
     self.highlight_connection()