Beispiel #1
0
def qwtDrawXCrossSymbols(painter, points, numPoints, symbol):
    size = symbol.size()
    pen = QPen(symbol.pen())
    if pen.width() > 1:
        pen.setCapStyle(Qt.FlatCap)
    painter.setPen(pen)
    sw = size.width()
    sh = size.height()
    sw2 = 0.5 * size.width()
    sh2 = 0.5 * size.height()
    for pos in points:
        x1 = pos.x() - sw2
        x2 = x1 + sw
        y1 = pos.y() - sh2
        y2 = y1 + sh
        painter.drawLine(QLineF(x1, y1, x2, y2))
        painter.drawLine(QLineF(x2, y1, x1, y2))
Beispiel #2
0
    def updatePosition(self, scene):
        pos0 = scene.posFromLonLat(self._lon0, self._lat0)
        pos1 = scene.posFromLonLat(self._lon1, self._lat1)
        deltaPos = QPointF(pos1[0] - pos0[0], pos1[1] - pos0[1])

        self.prepareGeometryChange()
        self.setLine(QLineF(QPointF(0.0, 0.0), deltaPos))
        self.setPos(pos0[0], pos0[1])
Beispiel #3
0
    def paint(self, p=QPainter(), o=QStyleOptionGraphicsItem(), widget=None):
        # p.setRenderHint(QPainter.Antialiasing)
        p.setPen(self._pen)
        p.setBrush(self._brush)

        p.drawLine(
            QLineF(QPointF(0, self.b_rect.bottom()),
                   QPointF(0, self.b_rect.top())))

        super(VLine, self).paint(p, o, widget)
def debug_drawing(painter, connection):
    geom = connection.geometry
    source, sink = geom.source, geom.sink
    c1, c2 = geom.points_c1_c2()

    painter.setPen(Qt.red)
    painter.setBrush(Qt.red)

    painter.drawLine(QLineF(source, c1))
    painter.drawLine(QLineF(c1, c2))
    painter.drawLine(QLineF(c2, sink))
    painter.drawEllipse(c1, 3, 3)
    painter.drawEllipse(c2, 3, 3)

    painter.setBrush(Qt.NoBrush)

    painter.drawPath(cubic_path(geom))
    painter.setPen(Qt.yellow)

    painter.drawRect(geom.bounding_rect)
Beispiel #5
0
def qwtDrawLineSymbols(painter, orientations, points, numPoints, symbol):
    size = symbol.size()
    pen = QPen(symbol.pen())
    if pen.width() > 1:
        pen.setCapStyle(Qt.FlatCap)
    painter.setPen(pen)
    painter.setRenderHint(QPainter.Antialiasing, False)
    sw = size.width()
    sh = size.height()
    sw2 = 0.5 * size.width()
    sh2 = 0.5 * size.height()
    for pos in points:
        if orientations & Qt.Horizontal:
            x = round(pos.x()) - sw2
            y = round(pos.y())
            painter.drawLine(QLineF(x, y, x + sw, y))
        if orientations & Qt.Vertical:
            x = round(pos.x())
            y = round(pos.y()) - sh2
            painter.drawLine(QLineF(x, y, x, y + sh))
Beispiel #6
0
def qwtDrawStar1Symbols(painter, points, numPoints, symbol):
    size = symbol.size()
    painter.setPen(symbol.pen())
    sqrt1_2 = math.sqrt(0.5)
    r = QRectF(0, 0, size.width(), size.height())
    for pos in points:
        r.moveCenter(pos.toPoint())
        c = QPointF(r.center())
        d1 = r.width() / 2.0 * (1.0 - sqrt1_2)
        painter.drawLine(
            QLineF(r.left() + d1,
                   r.top() + d1,
                   r.right() - d1,
                   r.bottom() - d1))
        painter.drawLine(
            QLineF(r.left() + d1,
                   r.bottom() - d1,
                   r.right() - d1,
                   r.top() + d1))
        painter.drawLine(QLineF(c.x(), r.top(), c.x(), r.bottom()))
        painter.drawLine(QLineF(r.left(), c.y(), r.right(), c.y()))
Beispiel #7
0
    def draw_icon(self, painter):
        path = QPainterPath(QPointF(0, 0.3))
        path.lineTo(0, 0.9)
        path.lineTo(1, 0.3)
        path.lineTo(1, 0.9)
        path.closeSubpath()
        painter.drawPath(path)
        painter.drawLine(QPointF(0.5, 0.6), QPointF(0.5, 0.15))

        painter.setBrush(self._interlock_brush)
        painter.drawRect(QRectF(0.35, 0, 0.3, 0.3))

        # Draw the arrow end-caps
        painter.setBrush(QBrush(QColor(0, 0, 0)))

        top_arrow_point = QPointF(0.65, 0.42)
        arrow = QPolygonF([
            QPointF(-0.07, 0.0),
            QPointF(-0.005, 0.0),
            QPointF(-0.005, 0.8),
            QPointF(0.005, 0.8),
            QPointF(0.005, 0.0),
            QPointF(0.07, 0.0),
            QPointF(0.00, -0.25)
        ])

        t = QTransform()
        t.rotate(40)
        top_arrow_r = t.map(arrow)
        arrow_l = top_arrow_r.translated(top_arrow_point)
        painter.drawPolygon(arrow_l)

        t_x = 0.4
        t_y = 0.05
        painter.drawLines([
            QLineF(0.0 + t_x, 0.0 + t_y, 0.0 + t_x, 0.2 + t_y),
            QLineF(0.0 + t_x, 0.0 + t_y, 0.1 + t_x, 0.2 + t_y),
            QLineF(0.1 + t_x, 0.2 + t_y, 0.2 + t_x, 0.0 + t_y),
            QLineF(0.2 + t_x, 0.0 + t_y, 0.2 + t_x, 0.2 + t_y)
        ])
def qwtDrawBox(p, rect, pal, lw):
    if lw > 0.0:
        if rect.width() == 0.0:
            p.setPen(pal.dark().color())
            p.drawLine(QLineF(rect.topLeft(), rect.bottomLeft()))
            return
        if rect.height() == 0.0:
            p.setPen(pal.dark().color())
            p.drawLine(QLineF(rect.topLeft(), rect.topRight()))
            return
        lw = min([lw, rect.height() / 2.0 - 1.0])
        lw = min([lw, rect.width() / 2.0 - 1.0])
        outerRect = rect.adjusted(0, 0, 1, 1)
        polygon = QPolygonF(outerRect)
        if outerRect.width() > 2 * lw and outerRect.height() > 2 * lw:
            innerRect = outerRect.adjusted(lw, lw, -lw, -lw)
            polygon = polygon.subtracted(innerRect)
        p.setPen(Qt.NoPen)
        p.setBrush(pal.dark())
        p.drawPolygon(polygon)
    windowRect = rect.adjusted(lw, lw, -lw + 1, -lw + 1)
    if windowRect.isValid():
        p.fillRect(windowRect, pal.window())
Beispiel #9
0
    def paint(self, p=QPainter(), o=QStyleOptionGraphicsItem(), widget=None):
        # p.setRenderHint(QPainter.Antialiasing)
        p.setPen(self._pen)
        p.setBrush(self._brush)

        p.drawLine(
            QLineF(QPointF(0, self.b_rect.bottom()), QPointF(0, self.b_rect.top()))
        )

        p.setPen(Qt.transparent)
        p.drawRect(self.b_rect)

        if CONFIG.debug:
            p.setPen(Qt.yellow)
            p.drawRect(self.b_rect)
Beispiel #10
0
    def init_line_items(self):
        """
        初始化线段
        :return:
        """
        last_pos = self.start_port.center_pos
        for p in self.center_points:
            pos = p.center_pos
            line_item = PMGGraphicsLineItem(QLineF(last_pos, pos))
            self.bind_line_item_signals(line_item)

            pen = QPen()
            pen.setColor(self.color)
            pen.setWidth(5)
            line_item.setPen(pen)
            self.canvas.addItem(line_item)
            last_pos = pos
            self.line_items.append(line_item)
        line_item = PMGGraphicsLineItem(
            QLineF(last_pos, self.end_port.center_pos))
        self.bind_line_item_signals(line_item)

        self.canvas.addItem(line_item)
        self.line_items.append(line_item)
Beispiel #11
0
 def draw_icon(self, painter):
     pen = painter.pen()
     pen.setWidthF(pen.width() * 2)
     pen.setCapStyle(Qt.FlatCap)
     painter.setPen(pen)
     # Circle parameters
     radius = 0.3
     center = (0.5, 1 - radius)
     # Draw circle
     painter.drawEllipse(QPointF(*center), radius, radius)
     # X pattern
     quad = math.cos(math.radians(45)) * radius
     painter.drawLine(
         QLineF(center[0] + quad, center[1] + quad, center[0] - quad,
                center[1] - quad))
     painter.drawLine(
         QLineF(center[0] + quad, center[1] - quad, center[0] - quad,
                center[1] + quad))
     # Interlock Icon
     square_dims = (0.4, 0.2)
     painter.drawLine(QPointF(center[0], center[1] - radius),
                      QPointF(center[0], square_dims[1]))
     painter.setBrush(self._interlock_brush)
     painter.drawRect(QRectF((1 - square_dims[0]) / 2., 0, *square_dims))
Beispiel #12
0
    def legendIcon(self, index, size):
        """
        :param int index: Index of the legend entry (ignored as there is only one)
        :param QSizeF size: Icon size
        :return: Icon representing the curve on the legend

        .. seealso::

            :py:meth:`qwt.plot.QwtPlotItem.setLegendIconSize()`,
            :py:meth:`qwt.plot.QwtPlotItem.legendData()`
        """
        if size.isEmpty():
            return QwtGraphic()
        graphic = QwtGraphic()
        graphic.setDefaultSize(size)
        graphic.setRenderHint(QwtGraphic.RenderPensUnscaled, True)
        painter = QPainter(graphic)
        painter.setRenderHint(
            QPainter.Antialiasing,
            self.testRenderHint(QwtPlotItem.RenderAntialiased))
        if self.__data.legendAttributes == 0 or (
                self.__data.legendAttributes & QwtPlotCurve.LegendShowBrush):
            brush = self.__data.brush
            if brush.style(
            ) == Qt.NoBrush and self.__data.legendAttributes == 0:
                if self.style() != QwtPlotCurve.NoCurve:
                    brush = QBrush(self.pen().color())
                elif (self.__data.symbol
                      and self.__data.symbol.style() != QwtSymbol.NoSymbol):
                    brush = QBrush(self.__data.symbol.pen().color())
            if brush.style() != Qt.NoBrush:
                r = QRectF(0, 0, size.width(), size.height())
                painter.fillRect(r, brush)
        if self.__data.legendAttributes & QwtPlotCurve.LegendShowLine:
            if self.pen() != Qt.NoPen:
                painter.setPen(self.pen())
                y = size.height() // 2
                painter.drawLine(QLineF(0, y, size.width(), y))
        if self.__data.legendAttributes & QwtPlotCurve.LegendShowSymbol:
            if self.__data.symbol:
                r = QRectF(0, 0, size.width(), size.height())
                self.__data.symbol.drawSymbol(painter, r)
        return graphic
Beispiel #13
0
    def paint(self, p=QPainter(), o=QStyleOptionGraphicsItem(), widget=None):
        pen = QPen(Qt.red)
        p.setPen(pen)

        p.drawLine(QLineF(0, 0, 2, 0))
        p.drawLine(QLineF(2, 0, 1.5, 0.5))
        p.drawLine(QLineF(2, 0, 1.5, -0.5))

        pen = QPen(Qt.blue)
        p.setPen(pen)
        p.drawLine(QLineF(0, 0, 0, 2))
        p.drawLine(QLineF(0, 2, 0.5, 1.5))
        p.drawLine(QLineF(0, 2, -0.5, 1.5))

        pen = QPen(Qt.yellow)
        p.setPen(pen)
        p.drawRect(-9, -9, 18, 18)
Beispiel #14
0
    def draw(self, painter, xMap, yMap, canvasRect):
        items = self.get_legend_items()
        TW, TH, _width, height = self.get_legend_size(items)

        x, y = self.get_top_left(xMap, yMap, canvasRect)
        self.draw_frame(painter, x, y, TW, TH)

        y0 = y + LEGEND_SPACEV
        x0 = x + LEGEND_SPACEH
        for text, ipen, ibrush, isymbol in items:
            isymbol.drawSymbols(
                painter, [QPointF(x0 + LEGEND_WIDTH / 2, y0 + height / 2)]
            )
            painter.save()
            painter.setPen(ipen)
            painter.setBrush(ibrush)
            painter.drawLine(
                QLineF(x0, y0 + height / 2, x0 + LEGEND_WIDTH, y0 + height / 2)
            )
            x1 = x0 + LEGEND_SPACEH + LEGEND_WIDTH
            painter.translate(x1, y0)
            text.drawContents(painter)
            painter.restore()
            y0 += height + LEGEND_SPACEV
Beispiel #15
0
    def __draw_point(self, i: int, vpoint: VPoint) -> None:
        """Draw a point."""
        connected = len(vpoint.links) - 1
        if vpoint.type in {VJoint.P, VJoint.RP}:
            pen = QPen(QColor(*vpoint.color))
            pen.setWidth(2)
            # Draw slot point and pin point
            for j, (cx, cy) in enumerate(vpoint.c):
                if not vpoint.links:
                    grounded = False
                else:
                    grounded = vpoint.links[j] == VLink.FRAME
                # Slot point
                if j == 0 or vpoint.type == VJoint.P:
                    if self.monochrome:
                        color = Qt.black
                    else:
                        color = QColor(*vpoint.color)
                    pen.setColor(color)
                    self.painter.setPen(pen)
                    cp = QPointF(cx, -cy) * self.zoom
                    jr = self.joint_size * (2 if j == 0 else 1)
                    rp = QPointF(jr, -jr)
                    self.painter.drawRect(QRectF(cp + rp, cp - rp))
                    if self.show_point_mark:
                        pen.setColor(Qt.darkGray)
                        self.painter.setPen(pen)
                        text = f"[Point{i}]"
                        if self.show_dimension:
                            text += f":({cx:.02f}, {cy:.02f})"
                        self.painter.drawText(cp + rp, text)
                else:
                    self.draw_point(i, cx, cy, grounded, vpoint.color,
                                    connected)
            # Slider line
            pen.setColor(QColor(*vpoint.color).darker())
            self.painter.setPen(pen)
            qline_m = QLineF(
                QPointF(vpoint.c[1][0], -vpoint.c[1][1]) * self.zoom,
                QPointF(vpoint.c[0][0], -vpoint.c[0][1]) * self.zoom)
            nv = qline_m.normalVector()
            nv.setLength(self.joint_size)
            nv.setPoints(nv.p2(), nv.p1())
            qline_1 = nv.normalVector()
            qline_1.setLength(qline_m.length())
            self.painter.drawLine(qline_1)
            nv.setLength(nv.length() * 2)
            nv.setPoints(nv.p2(), nv.p1())
            qline_2 = nv.normalVector()
            qline_2.setLength(qline_m.length())
            qline_2.setAngle(qline_2.angle() + 180)
            self.painter.drawLine(qline_2)
        else:
            self.draw_point(i, vpoint.cx, vpoint.cy, vpoint.grounded(),
                            vpoint.color, connected)

        # For selects function
        if self.select_mode == SelectMode.JOINT and (i in self.selections):
            pen = QPen(QColor(161, 16, 239))
            pen.setWidth(3)
            self.painter.setPen(pen)
            self.painter.drawRect(vpoint.cx * self.zoom - 12,
                                  vpoint.cy * -self.zoom - 12, 24, 24)
Beispiel #16
0
    def drawSeries(self, painter, xMap, yMap, canvasRect, first, last=-1):
        """Draw an interval of the curve, including the error bars

        painter is the QPainter used to draw the curve

        xMap is the QwtDiMap used to map x-values to pixels

        yMap is the QwtDiMap used to map y-values to pixels

        first is the index of the first data point to draw

        last is the index of the last data point to draw. If last < 0, last
        is transformed to index the last data point
        """

        if last < 0:
            last = self.dataSize() - 1

        if self.errorOnTop:
            QwtPlotCurve.drawSeries(self, painter, xMap, yMap, canvasRect, first, last)

        # draw the error bars
        painter.save()
        painter.setPen(self.errorPen)

        # draw the error bars with caps in the x direction
        if self.__dx is not None:
            # draw the bars
            if len(self.__dx.shape) in [0, 1]:
                xmin = self.__x - self.__dx
                xmax = self.__x + self.__dx
            else:
                xmin = self.__x - self.__dx[0]
                xmax = self.__x + self.__dx[1]
            y = self.__y
            n, i = len(y), 0
            lines = []
            while i < n:
                yi = yMap.transform(y[i])
                lines.append(
                    QLineF(xMap.transform(xmin[i]), yi, xMap.transform(xmax[i]), yi)
                )
                i += 1
            painter.drawLines(lines)
            if self.errorCap > 0:
                # draw the caps
                cap = self.errorCap / 2
                n, i, = (
                    len(y),
                    0,
                )
                lines = []
                while i < n:
                    yi = yMap.transform(y[i])
                    lines.append(
                        QLineF(
                            xMap.transform(xmin[i]),
                            yi - cap,
                            xMap.transform(xmin[i]),
                            yi + cap,
                        )
                    )
                    lines.append(
                        QLineF(
                            xMap.transform(xmax[i]),
                            yi - cap,
                            xMap.transform(xmax[i]),
                            yi + cap,
                        )
                    )
                    i += 1
            painter.drawLines(lines)

        # draw the error bars with caps in the y direction
        if self.__dy is not None:
            # draw the bars
            if len(self.__dy.shape) in [0, 1]:
                ymin = self.__y - self.__dy
                ymax = self.__y + self.__dy
            else:
                ymin = self.__y - self.__dy[0]
                ymax = self.__y + self.__dy[1]
            x = self.__x
            n, i, = (
                len(x),
                0,
            )
            lines = []
            while i < n:
                xi = xMap.transform(x[i])
                lines.append(
                    QLineF(xi, yMap.transform(ymin[i]), xi, yMap.transform(ymax[i]))
                )
                i += 1
            painter.drawLines(lines)
            # draw the caps
            if self.errorCap > 0:
                cap = self.errorCap / 2
                n, i, j = len(x), 0, 0
                lines = []
                while i < n:
                    xi = xMap.transform(x[i])
                    lines.append(
                        QLineF(
                            xi - cap,
                            yMap.transform(ymin[i]),
                            xi + cap,
                            yMap.transform(ymin[i]),
                        )
                    )
                    lines.append(
                        QLineF(
                            xi - cap,
                            yMap.transform(ymax[i]),
                            xi + cap,
                            yMap.transform(ymax[i]),
                        )
                    )
                    i += 1
            painter.drawLines(lines)

        painter.restore()

        if not self.errorOnTop:
            QwtPlotCurve.drawSeries(self, painter, xMap, yMap, canvasRect, first, last)
Beispiel #17
0
    def create_high_dpi_drop_indicator_pixmap(
            self, size: QSizeF, area: DockWidgetArea,
            mode: OverlayMode) -> QPixmap:
        '''
        Create high dpi drop indicator pixmap

        Parameters
        ----------
        size : QSizeF
        area : DockWidgetArea
        mode : OverlayMode

        Returns
        -------
        value : QPixmap
        '''
        border_color = self.icon_color(IconColor.frame_color)
        background_color = self.icon_color(IconColor.window_background_color)

        window = self.public.window()

        # QT version compatibility (TODO necessary for qtpy?)
        device_pixel_ratio = (window.devicePixelRatioF()
                              if hasattr(window, 'devicePixelRatioF')
                              else window.devicePixelRatio())

        pixmap_size = QSizeF(size * device_pixel_ratio)
        pm = QPixmap(pixmap_size.toSize())
        pm.fill(QColor(0, 0, 0, 0))
        p = QPainter(pm)
        pen = p.pen()
        shadow_rect = QRectF(pm.rect())

        base_rect = QRectF()
        base_rect.setSize(shadow_rect.size() * 0.7)
        base_rect.moveCenter(shadow_rect.center())

        # Fill
        shadow_color = self.icon_color(IconColor.shadow_color)
        if shadow_color.alpha() == 255:
            shadow_color.setAlpha(64)

        p.fillRect(shadow_rect, shadow_color)

        # Drop area rect.
        p.save()
        area_rect = QRectF()
        area_line = QLineF()
        non_area_rect = QRectF()

        if area == DockWidgetArea.top:
            area_rect = QRectF(base_rect.x(), base_rect.y(), base_rect.width(),
                               base_rect.height()*.5)
            non_area_rect = QRectF(base_rect.x(), shadow_rect.height()*.5,
                                   base_rect.width(), base_rect.height()*.5)
            area_line = QLineF(area_rect.bottomLeft(), area_rect.bottomRight())
        elif area == DockWidgetArea.right:
            area_rect = QRectF(shadow_rect.width()*.5, base_rect.y(),
                               base_rect.width()*.5, base_rect.height())
            non_area_rect = QRectF(base_rect.x(), base_rect.y(),
                                   base_rect.width()*.5, base_rect.height())
            area_line = QLineF(area_rect.topLeft(), area_rect.bottomLeft())
        elif area == DockWidgetArea.bottom:
            area_rect = QRectF(base_rect.x(), shadow_rect.height()*.5,
                               base_rect.width(), base_rect.height()*.5)
            non_area_rect = QRectF(base_rect.x(), base_rect.y(),
                                   base_rect.width(), base_rect.height()*.5)
            area_line = QLineF(area_rect.topLeft(), area_rect.topRight())
        elif area == DockWidgetArea.left:
            area_rect = QRectF(base_rect.x(), base_rect.y(),
                               base_rect.width()*.5, base_rect.height())
            non_area_rect = QRectF(shadow_rect.width()*.5, base_rect.y(),
                                   base_rect.width()*.5, base_rect.height())
            area_line = QLineF(area_rect.topRight(), area_rect.bottomRight())

        baseSize = base_rect.size()
        if (OverlayMode.container == mode
                and area != DockWidgetArea.center):
            base_rect = area_rect

        p.fillRect(base_rect, background_color)
        if area_rect.isValid():
            pen = p.pen()
            pen.setColor(border_color)
            Color = self.icon_color(IconColor.overlay_color)
            if Color.alpha() == 255:
                Color.setAlpha(64)

            p.setBrush(Color)
            p.setPen(Qt.NoPen)
            p.drawRect(area_rect)
            pen = p.pen()
            pen.setWidth(1)
            pen.setColor(border_color)
            pen.setStyle(Qt.DashLine)
            p.setPen(pen)
            p.drawLine(area_line)

        p.restore()
        p.save()

        # Draw outer border
        pen = p.pen()
        pen.setColor(border_color)
        pen.setWidth(1)
        p.setBrush(Qt.NoBrush)
        p.setPen(pen)
        p.drawRect(base_rect)

        # draw window title bar
        p.setBrush(border_color)
        frame_rect = QRectF(base_rect.topLeft(),
                            QSizeF(base_rect.width(), baseSize.height()/10))
        p.drawRect(frame_rect)
        p.restore()

        # Draw arrow for outer container drop indicators
        if (OverlayMode.container == mode and
                area != DockWidgetArea.center):
            arrow_rect = QRectF()
            arrow_rect.setSize(baseSize)
            arrow_rect.setWidth(arrow_rect.width()/4.6)
            arrow_rect.setHeight(arrow_rect.height()/2)
            arrow_rect.moveCenter(QPointF(0, 0))

            arrow = QPolygonF()
            arrow.append(arrow_rect.topLeft())
            arrow.append(QPointF(arrow_rect.right(), arrow_rect.center().y()))
            arrow.append(arrow_rect.bottomLeft())

            p.setPen(Qt.NoPen)
            p.setBrush(self.icon_color(IconColor.arrow_color))
            p.setRenderHint(QPainter.Antialiasing, True)
            p.translate(non_area_rect.center().x(), non_area_rect.center().y())
            if area == DockWidgetArea.top:
                p.rotate(-90)
            elif area == DockWidgetArea.right:
                ...
            elif area == DockWidgetArea.bottom:
                p.rotate(90)
            elif area == DockWidgetArea.left:
                p.rotate(180)

            p.drawPolygon(arrow)

        pm.setDevicePixelRatio(device_pixel_ratio)
        return pm