예제 #1
0
    def get_header_rect(self):
        header_height = 1.4 * self.title_label.boundingRect().height()  # 35 * (self.parent_node.title.count('\n')+1)

        header_rect = QRectF()
        header_rect.setTopLeft(QPointF(-self.width/2, -self.height/2))
        header_rect.setWidth(self.width)
        header_rect.setHeight(header_height)
        return header_rect
예제 #2
0
    def get_header_rect(self):
        header_height = 35 * (self.parent_node.title.count('\n') + 1)

        header_rect = QRectF()
        header_rect.setTopLeft(QPointF(-self.width / 2, -self.height / 2))
        header_rect.setRight(self.width / 2)
        header_rect.setBottom(-self.height / 2 + header_height)
        return header_rect
예제 #3
0
    def get_header_rect(w, h, title_rect):
        """
        :param w: width
        :param h: height
        """

        header_height = 1.4 * title_rect.height(
        )  # 35 * (self.parent_node.title.count('\n')+1)

        header_rect = QRectF()
        header_rect.setTopLeft(QPointF(-w / 2, -h / 2))
        header_rect.setWidth(w)
        header_rect.setHeight(header_height)
        return header_rect
예제 #4
0
    def on_target_viewport_visible_scene_rect_changed(self, visible: QRectF):
        scene = self._target_view.scene()
        if scene is None:
            return

        x = (visible.x() - scene.sceneRect().x()) * self._scale
        y = (visible.y() - scene.sceneRect().y()) * self._scale
        width = visible.width() * self._scale
        height = visible.height() * self._scale
        mm_scene_w = self.sceneRect().width()
        mm_scene_h = self.sceneRect().height()

        minimap_vp_rect = QRectF()
        minimap_vp_rect.setTopLeft(
            QPoint(int(clamp(x, 0, mm_scene_w)), int(clamp(y, 0, mm_scene_h))))
        minimap_vp_rect.setBottomRight(
            QPoint(int(clamp(x + width, 0, mm_scene_w)),
                   int(clamp(y + height, 0, mm_scene_h))))

        self._minimap_target_viewport_box.set_viewport_rect(minimap_vp_rect)
        self._minimap_target_viewport_box.update()
예제 #5
0
    def eventFilter(self, obj, event):
        if event.type() == QEvent.GraphicsSceneMousePress:
            if event.button() == Qt.MouseButton.LeftButton:
                self.mouse_pressed = True

                self.mouse_pressed_x, self.mouse_pressed_y = event.pos().x(
                ), event.pos().y()

                if self.draw_ellipse:
                    ellipsis = QGraphicsEllipseItem(self.chart)

                    ellipsis.setZValue(12)
                    ellipsis.setBrush(QBrush(QColor(244, 67, 54, 50)))
                    ellipsis.setPen(QPen(Qt.transparent))

                    self.ellipses.append(ellipsis)
                elif self.write_text:
                    for t in self.texts:
                        r = QRectF()
                        r.setTopLeft(t.pos())
                        r.setWidth(t.boundingRect().width())
                        r.setHeight(t.boundingRect().height())

                        if r.contains(self.mouse_pressed_x,
                                      self.mouse_pressed_y):
                            return True
                    """
                        The user clicked over an area where there is no text. So we create one.
                    """

                    text = QGraphicsTextItem(self.chart)

                    text.setZValue(12)
                    text.setPos(
                        QPointF(self.mouse_pressed_x, self.mouse_pressed_y))
                    text.setPlainText("label")
                    text.setAcceptHoverEvents(True)
                    text.setTabChangesFocus(True)
                    text.setFlags(QGraphicsTextItem.ItemIsMovable)
                    text.installEventFilter(self.text_event_filter)

                    self.texts.append(text)

                return True
            elif event.button() == Qt.MouseButton.RightButton:
                x, y = event.pos().x(), event.pos().y()

                for e in self.ellipses:
                    if e.rect().contains(x, y):
                        e.hide()

                        self.ellipses.remove(e)

                for t in self.texts:
                    r = QRectF()
                    r.setTopLeft(t.pos())
                    r.setWidth(t.boundingRect().width())
                    r.setHeight(t.boundingRect().height())

                    if r.contains(x, y):
                        t.hide()

                        self.texts.remove(t)

                return True

            return QObject.eventFilter(self, obj, event)

        elif event.type() == QEvent.GraphicsSceneMouseRelease:
            self.mouse_pressed = False

            return True

        elif event.type() == QEvent.GraphicsSceneMouseMove:
            if self.mouse_pressed:
                if self.draw_ellipse:
                    x, y = event.pos().x(), event.pos().y()

                    width = x - self.mouse_pressed_x
                    height = y - self.mouse_pressed_y

                    self.ellipses[-1].setRect(self.mouse_pressed_x,
                                              self.mouse_pressed_y, width,
                                              height)

                    return True

            return QObject.eventFilter(self, obj, event)

        return QObject.eventFilter(self, obj, event)