Esempio n. 1
0
    def drawBackbone(self, painter):
        """
        Draws the baseline of the scale

        :param QPainter painter: Painter

        .. seealso::

            :py:meth:`drawTick()`, :py:meth:`drawLabel()`
        """
        pos = self.__data.pos
        len_ = self.__data.len
        off = 0.5 * self.penWidth()
        if self.alignment() == self.LeftScale:
            x = pos.x() - off
            painter.drawLine(QLineF(x, pos.y(), x, pos.y() + len_))
        elif self.alignment() == self.RightScale:
            x = pos.x() + off
            painter.drawLine(QLineF(x, pos.y(), x, pos.y() + len_))
        elif self.alignment() == self.TopScale:
            y = pos.y() - off
            painter.drawLine(QLineF(pos.x(), y, pos.x() + len_, y))
        elif self.alignment() == self.BottomScale:
            y = pos.y() + off
            painter.drawLine(QLineF(pos.x(), y, pos.x() + len_, y))
Esempio n. 2
0
    def drawTick(self, painter, value, len_):
        """
        Draw a tick

        :param QPainter painter: Painter
        :param float value: Value of the tick
        :param float len: Length of the tick

        .. seealso::

            :py:meth:`drawBackbone()`, :py:meth:`drawLabel()`
        """
        if len_ <= 0:
            return
        pos = self.__data.pos
        tval = self.scaleMap().transform(value)
        pw = self.penWidth()
        a = 0
        if self.alignment() == self.LeftScale:
            x1 = pos.x() + a
            x2 = pos.x() + a - pw - len_
            painter.drawLine(QLineF(x1, tval, x2, tval))
        elif self.alignment() == self.RightScale:
            x1 = pos.x()
            x2 = pos.x() + pw + len_
            painter.drawLine(QLineF(x1, tval, x2, tval))
        elif self.alignment() == self.BottomScale:
            y1 = pos.y()
            y2 = pos.y() + pw + len_
            painter.drawLine(QLineF(tval, y1, tval, y2))
        elif self.alignment() == self.TopScale:
            y1 = pos.y() + a
            y2 = pos.y() - pw - len_ + a
            painter.drawLine(QLineF(tval, y1, tval, y2))
Esempio n. 3
0
    def draw_arrow(self, QPainter, point_1: QPointF,
                   point_2: QPointF) -> 'QPolygonF':
        """
        绘制箭头。
        :param QPainter:
        :param point_1:
        :param point_2:
        :return:
        """

        line = QLineF(point_1, point_2)

        v = line.unitVector()

        v.setLength(20)  # 改变单位向量的大小,实际就是改变箭头长度
        v.translate(QPointF(int(line.dx() / 2), int(line.dy() / 2)))

        n = v.normalVector()  # 法向量
        n.setLength(n.length() * 0.2)  # 这里设定箭头的宽度
        n2 = n.normalVector().normalVector()  # 两次法向量运算以后,就得到一个反向的法向量
        p1 = v.p2()
        p2 = n.p2()
        p3 = n2.p2()
        if PYSIDE2:
            QPainter.drawPolygon([p1, p2, p3])
        else:
            QPainter.drawPolygon(p1, p2, p3)
        return QPolygonF([p1, p2, p3, p1])
Esempio n. 4
0
    def drawSticks(self, painter, xMap, yMap, canvasRect, from_, to):
        """
        Draw sticks

        :param QPainter painter: Painter
        :param qwt.scale_map.QwtScaleMap xMap: Maps x-values into pixel coordinates.
        :param qwt.scale_map.QwtScaleMap yMap: Maps y-values into pixel coordinates.
        :param QRectF canvasRect: Contents rectangle of the canvas
        :param int from_: Index of the first point to be painted
        :param int to: Index of the last point to be painted. If to < 0 the curve will be painted to its last point.

        .. seealso::

            :py:meth:`draw()`, :py:meth:`drawDots()`,
            :py:meth:`drawSteps()`, :py:meth:`drawLines()`
        """
        painter.save()
        painter.setRenderHint(QPainter.Antialiasing, False)
        x0 = xMap.transform(self.__data.baseline)
        y0 = yMap.transform(self.__data.baseline)
        o = self.orientation()
        series = self.data()
        for i in range(from_, to + 1):
            sample = series.sample(i)
            xi = xMap.transform(sample.x())
            yi = yMap.transform(sample.y())
            if o == Qt.Horizontal:
                painter.drawLine(QLineF(xi, y0, xi, yi))
            else:
                painter.drawLine(QLineF(x0, yi, xi, yi))
        painter.restore()
Esempio n. 5
0
        def draw_grid(grid_step):
            window_rect = self.rect()
            tl = self.mapToScene(window_rect.topLeft())
            br = self.mapToScene(window_rect.bottomRight())
            left = math.floor(tl.x() / grid_step - 0.5)
            right = math.floor(br.x() / grid_step + 1.0)
            bottom = math.floor(tl.y() / grid_step - 0.5)
            top = math.floor(br.y() / grid_step + 1.0)

            # vertical lines
            lines = [
                QLineF(xi * grid_step, bottom * grid_step, xi * grid_step,
                       top * grid_step)
                for xi in range(int(left),
                                int(right) + 1)
            ]

            # horizontal lines
            lines.extend([
                QLineF(left * grid_step, yi * grid_step, right * grid_step,
                       yi * grid_step) for yi in range(int(bottom),
                                                       int(top) + 1)
            ])

            painter.drawLines(lines)
Esempio n. 6
0
def qwtDrawPanel(painter, rect, pal, lw):
    if lw > 0.0:
        if rect.width() == 0.0:
            painter.setPen(pal.window().color())
            painter.drawLine(QLineF(rect.topLeft(), rect.bottomLeft()))
            return
        if rect.height() == 0.0:
            painter.setPen(pal.window().color())
            painter.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)
        innerRect = outerRect.adjusted(lw, lw, -lw, -lw)
        lines = [QPolygonF(), QPolygonF()]
        lines[0] += outerRect.bottomLeft()
        lines[0] += outerRect.topLeft()
        lines[0] += outerRect.topRight()
        lines[0] += innerRect.topRight()
        lines[0] += innerRect.topLeft()
        lines[0] += innerRect.bottomLeft()
        lines[1] += outerRect.topRight()
        lines[1] += outerRect.bottomRight()
        lines[1] += outerRect.bottomLeft()
        lines[1] += innerRect.bottomLeft()
        lines[1] += innerRect.bottomRight()
        lines[1] += innerRect.topRight()
        painter.setPen(Qt.NoPen)
        painter.setBrush(pal.light())
        painter.drawPolygon(lines[0])
        painter.setBrush(pal.dark())
        painter.drawPolygon(lines[1])
    painter.fillRect(rect.adjusted(lw, lw, -lw + 1, -lw + 1), pal.window())
Esempio n. 7
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))
Esempio n. 8
0
    def paint(self, p=QPainter(), o=QStyleOptionGraphicsItem(), widget=None):
        p.setRenderHint(QPainter.Antialiasing)
        p.setPen(self.pen)
        p.setBrush(self.brush)
        p.drawPath(self._path)

        p.setBrush(Qt.transparent)
        p.drawLine(QLineF(-0.5, 0, 0.5, 0))
        p.drawLine(QLineF(0, -0.5, 0, 0.5))
        p.drawEllipse(QPointF(0, 0), 0.25, 0.25)
Esempio n. 9
0
 def draw_icon(self, painter):
     painter.drawEllipse(QPointF(0.5, 0.5), 0.5, 0.5)
     pen = painter.pen()
     pen.setWidthF(pen.width() * 2)
     pen.setCapStyle(Qt.FlatCap)
     painter.setPen(pen)
     r = 0.5
     x1 = r + r * math.cos(math.radians(45))
     y1 = r + r * math.sin(math.radians(45))
     x2 = r + r * math.cos(math.radians(225))
     y2 = r + r * math.sin(math.radians(225))
     painter.drawLine(QLineF(x1, y1, x2, y2))
     painter.drawLine(QLineF(x2, y1, x1, y2))
Esempio n. 10
0
 def drawLines(self, painter, canvasRect, orientation, scaleMap, values):
     x1 = canvasRect.left()
     x2 = canvasRect.right() - 1.0
     y1 = canvasRect.top()
     y2 = canvasRect.bottom() - 1.0
     for val in values:
         value = scaleMap.transform(val)
         if orientation == Qt.Horizontal:
             if qwtFuzzyGreaterOrEqual(value, y1) and qwtFuzzyLessOrEqual(
                     value, y2):
                 painter.drawLine(QLineF(x1, value, x2, value))
         else:
             if qwtFuzzyGreaterOrEqual(value, x1) and qwtFuzzyLessOrEqual(
                     value, x2):
                 painter.drawLine(QLineF(value, y1, value, y2))
Esempio n. 11
0
    def paint(self,
              q_painter: 'QPainter',
              style_option_graphics_item: 'QStyleOptionGraphicsItem',
              widget: 'QWidget' = None):

        pen = QPen()
        pen.setColor(self.color)
        pen.setWidth(3)
        pen.setJoinStyle(Qt.MiterJoin)  # 让箭头变尖
        q_painter.setPen(pen)

        path = QPainterPath()

        point1 = self.start_port
        path.moveTo(self.start_port.center_pos)
        # for i in self.line_items:
        #     i.setPen(QColor(255, 0, 0))
        #     i.update()
        for p in self.center_points + [self.end_port]:
            pen.setWidth(3)
            q_painter.setPen(pen)
            path.lineTo(p.center_pos)
            q_painter.drawLine(QLineF(point1.center_pos, p.center_pos))
            arrow = self.draw_arrow(q_painter, point1.center_pos, p.center_pos)
            path.addPolygon(arrow)  # 将箭头添加到连线上
            point1 = p
Esempio n. 12
0
    def refresh_line_items(self):
        """
        刷新背后的直线段。
        :return:
        """
        last_pos = self.start_port.center_pos
        if len(self.line_items) == 0:
            return
        for i, p in enumerate(self.center_points):
            pos = p.center_pos
            line = QLineF(last_pos, pos)
            self.line_items[i].setLine(line)
            last_pos = pos

        line = QLineF(last_pos, self.end_port.center_pos)
        self.line_items[-1].setLine(line)
Esempio n. 13
0
    def add_mid_point(self, line_item: 'PMGGraphicsLineItem', pos: QPointF):
        """
        增加中间节点
        :param line_item:
        :param pos:
        :return:
        """
        index = self.line_items.index(line_item)
        new_center_point = CustomMidPoint(pos, line=self)
        self.canvas.addItem(new_center_point)
        self.center_points.insert(index, new_center_point)
        self.connect_midpoint_signals(new_center_point)
        if index == 0:
            last_pos = self.start_port.center_pos
        else:
            last_pos = self.center_points[index].center_pos
        next_pos = new_center_point.center_pos
        new_line_item = PMGGraphicsLineItem(QLineF(last_pos, next_pos))

        # pen = QPen()
        # pen.setColor(self.color)
        # pen.setWidth(3)
        # new_line_item.setPen(pen)
        self.canvas.addItem(new_line_item)
        self.line_items.insert(index, new_line_item)
        self.bind_line_item_signals(new_line_item)  # 绑定中间节点的信号。
        print(len(self.line_items))
        self.refresh_line_items()
        self.update()
        self.canvas.update_viewport()
Esempio n. 14
0
    def paintEvent(self, event: QtGui.QPaintEvent):
        border_distance = 5
        rect = self.rect()
        mid = rect.y() + rect.height() / 2
        line_begin = QPointF(rect.height() + 10 + self.text_size.width(), mid)
        line_end = QPointF(rect.width() + rect.x() - 5, mid)
        triangle = QPolygonF()
        side_length = rect.height() - 2 * border_distance
        triangle_height = side_length * sqrt(3) / 2
        start_point = QPointF(rect.x() + border_distance, rect.y() + border_distance)

        if self.isChecked():
            triangle.append(start_point)
            triangle.append(start_point + QPointF(0, side_length))
            triangle.append(start_point + QPointF(triangle_height, side_length / 2))
        else:
            triangle.append(start_point)
            triangle.append(start_point + QPointF(side_length, 0))
            triangle.append(start_point + QPointF(side_length / 2, triangle_height))
        painter = QPainter(self)

        painter.setBrush(Qt.black)
        top = rect.height() - (self.text_size.height() / 2)
        painter.drawText(rect.height() + 5, top, self.info_text)
        painter.drawPolygon(triangle, Qt.WindingFill)
        painter.drawLine(QLineF(line_begin, line_end))
Esempio n. 15
0
    def drawColorBar(self, painter, colorMap, interval, scaleMap, orientation,
                     rect):
        """
        Draw a color bar into a rectangle

        :param QPainter painter: Painter
        :param qwt.color_map.QwtColorMap colorMap: Color map
        :param qwt.interval.QwtInterval interval: Value range
        :param qwt.scalemap.QwtScaleMap scaleMap: Scale map
        :param Qt.Orientation orientation: Orientation
        :param QRectF rect: Target rectangle
        """
        colorTable = []
        if colorMap.format() == QwtColorMap.Indexed:
            colorTable = colorMap.colorTable(interval)
        c = QColor()
        devRect = rect.toAlignedRect()
        pixmap = QPixmap(devRect.size())
        pixmap.fill(Qt.transparent)
        pmPainter = QPainter(pixmap)
        pmPainter.translate(-devRect.x(), -devRect.y())
        if orientation == Qt.Horizontal:
            sMap = QwtScaleMap(scaleMap)
            sMap.setPaintInterval(rect.left(), rect.right())
            for x in range(devRect.left(), devRect.right() + 1):
                value = sMap.invTransform(x)
                if colorMap.format() == QwtColorMap.RGB:
                    c.setRgba(colorMap.rgb(interval, value))
                else:
                    c = colorTable[colorMap.colorIndex(interval, value)]
                pmPainter.setPen(c)
                pmPainter.drawLine(
                    QLineF(x, devRect.top(), x, devRect.bottom()))
        else:
            sMap = QwtScaleMap(scaleMap)
            sMap.setPaintInterval(rect.bottom(), rect.top())
            for y in range(devRect.top(), devRect.bottom() + 1):
                value = sMap.invTransform(y)
                if colorMap.format() == QwtColorMap.RGB:
                    c.setRgba(colorMap.rgb(interval, value))
                else:
                    c = colorTable[colorMap.colorIndex(interval, value)]
                pmPainter.setPen(c)
                pmPainter.drawLine(
                    QLineF(devRect.left(), y, devRect.right(), y))
        pmPainter.end()
        self.drawPixmap(painter, rect, pixmap)
Esempio n. 16
0
 def paint(self, p=QPainter(), o=QStyleOptionGraphicsItem(), widget=None):
     # p.setRenderHint(QPainter.N)
     p.setPen(self._pen)
     p.setBrush(self._brush)
     p.drawLine(
         QLineF(QPointF(self.b_rect.left(), 0),
                QPointF(self.b_rect.right(), 0)))
     super(HLine, self).paint(p, o, widget)
Esempio n. 17
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])
Esempio n. 18
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))
Esempio n. 19
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)
Esempio n. 20
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))
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)
Esempio n. 22
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()))
Esempio n. 23
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)
        ])
Esempio n. 24
0
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())
Esempio n. 25
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)
Esempio n. 26
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)
Esempio n. 27
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
Esempio n. 28
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)
Esempio n. 29
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
Esempio n. 30
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