Exemplo n.º 1
0
    def paintEvent(self, event):

        painter = QPainter(self)
        painter.setRenderHints(QPainter.Antialiasing)

        side = min(self.width(), self.height())
        painter.scale(side / 32.0, side / 32.0)

        painter.setPen(Qt.NoPen)

        if not self.is_pressed:
            painter.setBrush(self.back_color)
        else:
            painter.setBrush(
                QColor(self.back_color.red() + 30,
                       self.back_color.green() + 30,
                       self.back_color.blue() + 30))

        painter.drawRoundedRect(QRect(0, 0, 32, 32), 8, 8)

        if self.is_checked:

            check_path = QPainterPath()
            check_path.moveTo(self.x1)
            check_path.lineTo(self.x2)
            check_path.lineTo(self.x3)

            pen = QPen(self.check_color, self.check_thick, Qt.SolidLine)
            painter.setPen(pen)

            painter.drawPath(check_path)
Exemplo n.º 2
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
Exemplo n.º 3
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)

        prev_brush = painter.brush()
        prev_pen = painter.pen()

        painter.setPen(Qt.NoPen)
        painter.setBrush(self._arrow_brush)
        arrow = QPolygonF([
            QPointF(0.2, 0),
            QPointF(0.2, 0.20),
            QPointF(0.5, 0.40),
            QPointF(0.8, 0.20),
            QPointF(0.8, 0)
        ])
        painter.drawPolygon(arrow)

        painter.setPen(prev_pen)
        painter.setBrush(prev_brush)
        painter.drawLine(QPointF(0.2, 0), QPointF(0.5, 0.20))
        painter.drawLine(QPointF(0.2, 0.20), QPointF(0.5, 0.40))
        painter.drawLine(QPointF(0.5, 0.20), QPointF(0.8, 0))
        painter.drawLine(QPointF(0.5, 0.40), QPointF(0.8, 0.20))

        painter.drawLine(QPointF(0.5, 0.6), QPointF(0.5, 0.0))
Exemplo n.º 4
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))

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

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

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

        painter.setBrush(self._interlock_brush)
        painter.drawRect(QRectF(0.3, 0, 0.4, 0.15))
Exemplo n.º 5
0
    def paint(self, p, opt, widget):

        # Enforce constraints on handles
        r2 = Point(np.cos(np.radians(self.thetacenter)),
                   np.sin(np.radians(self.thetacenter)))  # chi center direction vector
        # constrain innerhandle to be parallel to outerhandle, and shorter than outerhandle
        self.innerhandle.setPos(r2 * self.innerradius)
        # constrain widthhandle to be counter-clockwise from innerhandle
        widthangle = np.radians(self.thetawidth / 2 + self.thetacenter)
        widthv = Point(np.cos(widthangle), np.sin(widthangle)) if self.thetawidth > 0 else r2
        # constrain widthhandle to half way between inner and outerhandles
        self.widthhandle.setPos(widthv * (self.innerradius + self.outerradius) / 2)
        # constrain handles to base values
        self.outerhandle.setPos(r2 * self.outerradius)


        pen = self.currentPen
        pen.setColor(QColor(0, 255, 255))

        p.setPen(pen)

        r = self.boundingRect()
        # p.drawRect(r)
        p.setRenderHint(QPainter.Antialiasing)

        p.scale(r.width(), r.height())  # workaround for GL bug

        centerangle = self.innerhandle.pos().angle(Point(1, 0))
        startangle = centerangle - self.thetawidth / 2
        endangle = centerangle + self.thetawidth / 2

        r = QCircRectF(radius=0.5)
        if self.innerradius < self.outerradius and self.thetawidth > 0:
            p.drawArc(r, -startangle * 16, -self.thetawidth * 16)

        radius = self.innerradius / self.outerradius / 2
        r = QCircRectF()
        r.radius = radius

        if self.innerradius < self.outerradius and self.thetawidth > 0:
            p.drawArc(r, -startangle * 16, -self.thetawidth * 16)

        pen.setStyle(Qt.DashLine)
        p.setPen(pen)

        p.drawLine(QPointF(0., 0.), self.widthhandle.pos().norm() / 2)
        r1v = self.innerhandle.pos().norm()
        p.drawLine(QPointF(0., 0.),
                   (-1. * self.widthhandle.pos() + 2 * self.widthhandle.pos().dot(r1v) * r1v).norm() / 2)
        pen.setStyle(Qt.SolidLine)

        if self.innerradius < self.outerradius and self.thetawidth > 0:
            path = QPainterPath()
            path.moveTo((-1. * self.widthhandle.pos() + 2 * self.widthhandle.pos().dot(r1v) * r1v).norm() / 2)
            path.arcTo(r, -startangle, -self.thetawidth)  # inside
            path.lineTo(self.widthhandle.pos().norm() / 2)  # ? side
            path.arcTo(QCircRectF(radius=0.5), -endangle, self.thetawidth)  # outside
            path.lineTo((-1. * self.widthhandle.pos() + 2 * self.widthhandle.pos().dot(r1v) * r1v).norm() / 2)
            self.path = path
            p.fillPath(path, QBrush(QColor(0, 255, 255, 20)))
Exemplo n.º 6
0
    def paintEvent(self, event):

        painter = QPainter(self)
        painter.setRenderHints(QPainter.Antialiasing)
        if self.label_width <= 0:
            return

        painter.setPen(Qt.NoPen)
        if self.hover:
            painter.setBrush(
                QColor(self.back_color.red() + 30,
                       self.back_color.green() + 30,
                       self.back_color.blue() + 30))
        else:
            painter.setBrush(self.back_color)

        painter.drawRoundedRect(QRect(0, 0, self.width(), self.height()),
                                self.border_radius, self.border_radius)

        x1 = QPointF(self.label_width + float(self.height() / 3),
                     float(self.height() * 0.45))
        x2 = QPointF(
            self.label_width + float(self.height() * (0.66 + self.rate) / 2),
            float(self.height() * 0.55))
        x3 = QPointF(self.width() - float(self.height() / 3),
                     float(self.height() * 0.45))

        check_path = QPainterPath()
        check_path.moveTo(x1)
        check_path.lineTo(x2)
        check_path.lineTo(x3)

        pen = QPen(self.text_color, self.drop_thick, Qt.SolidLine)
        painter.setPen(pen)
        painter.drawPath(check_path)
Exemplo n.º 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)
 def drawValue(self, p: QPainter, baseRect: QRectF, value: float, delta: float):
     if value == self.m_min:
         return
     if self.m_barStyle == self.BarStyle.EXPAND:
         p.setBrush(self.palette().highlight())
         p.setPen(QPen(self.palette().shadow().color(), self.m_dataPenWidth))
         radius = (baseRect.height() / 2) / delta
         p.drawEllipse(baseRect.center(), radius, radius)
         return
     if self.m_barStyle == self.BarStyle.LINE:
         p.setPen(QPen(self.palette().highlight().color(), self.m_dataPenWidth))
         p.setBrush(Qt.NoBrush)
         if value == self.m_max:
             p.drawEllipse(baseRect.adjusted(self.m_outlinePenWidth / 2, self.m_outlinePenWidth / 2,
                                             -self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2))
         else:
             arcLength = 360 / delta
             p.drawArc(baseRect.adjusted(self.m_outlinePenWidth / 2, self.m_outlinePenWidth / 2,
                                         -self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2),
                       int(self.m_nullPosition * 16),
                       int(-arcLength * 16))
         return
     dataPath = QPainterPath()
     dataPath.setFillRule(Qt.WindingFill)
     if value == self.m_max:
         dataPath.addEllipse(baseRect)
     else:
         arcLength = 360 / delta
         dataPath.moveTo(baseRect.center())
         dataPath.arcTo(baseRect, self.m_nullPosition, -arcLength)
         dataPath.lineTo(baseRect.center())
     p.setBrush(self.palette().highlight())
     p.setPen(QPen(self.palette().shadow().color(), self.m_dataPenWidth))
     p.drawPath(dataPath)
Exemplo n.º 9
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.3))
     painter.setBrush(self._interlock_brush)
     painter.drawRect(QRectF(0.2, 0, 0.6, 0.3))
Exemplo n.º 10
0
def painterPathForTriangle():
    bottomLeft = QPointF(-1.0, -1.0)
    top = QPointF(0.0, 1.0)
    bottomRight = QPointF(1.0, -1.0)

    path = QPainterPath(bottomLeft)
    path.lineTo(top)
    path.lineTo(bottomRight)
    path.closeSubpath()
    return path
Exemplo n.º 11
0
    def drawStar(self, qp):
        """Draw a star in the preview pane.

        Parameters
        ----------
        qp: QPainter object
        """
        width = self.rect().width()
        height = self.rect().height()
        col = QColor(135, 206, 235)
        pen = QPen(col, self._value)
        pen.setJoinStyle(Qt.PenJoinStyle.MiterJoin)
        qp.setPen(pen)

        path = QPainterPath()

        # draw pentagram
        star_center_x = width / 2
        star_center_y = height / 2
        # make sure the star equal no matter the size of the qframe
        if width < height:
            # not taking it all the way to the edge so the star has room to grow
            radius_outer = width * 0.35
        else:
            radius_outer = height * 0.35

        # start at the top point of the star and move counter clockwise to draw the path.
        # every other point is the shorter radius (1/(1+golden_ratio)) of the larger radius
        golden_ratio = (1 + np.sqrt(5)) / 2
        radius_inner = radius_outer / (1 + golden_ratio)
        theta_start = np.pi / 2
        theta_inc = (2 * np.pi) / 10
        for n in range(11):
            theta = theta_start + (n * theta_inc)
            theta = np.mod(theta, 2 * np.pi)
            if np.mod(n, 2) == 0:
                # use radius_outer
                x = radius_outer * np.cos(theta)
                y = radius_outer * np.sin(theta)

            else:
                # use radius_inner
                x = radius_inner * np.cos(theta)
                y = radius_inner * np.sin(theta)

            x_adj = star_center_x - x
            y_adj = star_center_y - y + 3
            if n == 0:

                path.moveTo(x_adj, y_adj)
            else:
                path.lineTo(x_adj, y_adj)

        qp.drawPath(path)
Exemplo n.º 12
0
    def updatePosition(self, scene):
        path = QPainterPath()

        self.prepareGeometryChange()

        count = len(self._longitudes)
        if count > 0:
            x, y = scene.posFromLonLat(self._longitudes, self._latitudes)
            path.moveTo(x[0], y[0])
            for i in iterRange(1, count):
                path.lineTo(x[i], y[i])

        self.setPath(path)
Exemplo n.º 13
0
    def updatePosition(self, scene):
        path = QPainterPath()

        self.prepareGeometryChange()

        count = len(self._longitudes)
        if count > 0:
            x, y = scene.posFromLonLat(self._longitudes, self._latitudes)
            path.moveTo(x[0], y[0])
            for i in iterRange(1, count):
                path.lineTo(x[i], y[i])

        self.setPath(path)
Exemplo n.º 14
0
 def get_line_path(points, shape_type):
     line_path = QPainterPath()
     if shape_type == 'rectangle' and len(points) == 2:
         rectangle = Shape.getRectFromLine(*points)
         line_path.addRect(rectangle)
     elif shape_type == 'circle' and len(points) == 2:
         rectangle = Shape.getCircleRectFromLine(points)
         line_path.addEllipse(rectangle)
     elif shape_type == 'linestrip' and points:
         line_path.moveTo(points[0])
         for p in points:
             line_path.lineTo(p)
     elif shape_type in ['curve', 'freeform'] and points:
         # Paint Bezier curve across given points.
         refined_points = BezierB(points).smooth()
         line_path.moveTo(refined_points[0])
         for p in refined_points:
             line_path.lineTo(p)
     elif points:
         line_path.moveTo(points[0])
         for p in points:
             line_path.lineTo(p)
         if shape_type == 'polygon':
             line_path.lineTo(points[0])
     return line_path
Exemplo n.º 15
0
def qwtCombinePathList(rect, pathList):
    if not pathList:
        return QPainterPath()

    ordered = [None] * 8
    for subPath in pathList:
        index = -1
        br = subPath.controlPointRect()
        if br.center().x() < rect.center().x():
            if br.center().y() < rect.center().y():
                if abs(br.top() - rect.top()) < abs(br.left() - rect.left()):
                    index = 1
                else:
                    index = 0
            else:
                if abs(br.bottom() - rect.bottom) < abs(br.left() -
                                                        rect.left()):
                    index = 6
                else:
                    index = 7
            if subPath.currentPosition().y() > br.center().y():
                qwtRevertPath(subPath)
        else:
            if br.center().y() < rect.center().y():
                if abs(br.top() - rect.top()) < abs(br.right() - rect.right()):
                    index = 2
                else:
                    index = 3
            else:
                if abs(br.bottom() - rect.bottom()) < abs(br.right() -
                                                          rect.right()):
                    index = 5
                else:
                    index = 4
            if subPath.currentPosition().y() < br.center().y():
                qwtRevertPath(subPath)
        ordered[index] = subPath
    for i in range(4):
        if ordered[2 * i].isEmpty() != ordered[2 * i + 1].isEmpty():
            return QPainterPath()
    corners = QPolygonF(rect)
    path = QPainterPath()
    for i in range(4):
        if ordered[2 * i].isEmpty():
            path.lineTo(corners[i])
        else:
            path.connectPath(ordered[2 * i])
            path.connectPath(ordered[2 * i + 1])
    path.closeSubpath()
    return path
Exemplo n.º 16
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.4, 0), QPointF(0.5, 0.15))
        painter.drawLine(QPointF(0.4, 0.10), QPointF(0.5, 0.25))
        painter.drawLine(QPointF(0.5, 0.15), QPointF(0.6, 0))
        painter.drawLine(QPointF(0.5, 0.25), QPointF(0.6, 0.10))

        painter.drawLine(QPointF(0.5, 0.6), QPointF(0.5, 0.0))
Exemplo n.º 17
0
    def shape(self):
        if self._shape is None:
            radius = self.getState()['size'][1]
            p = QPainterPath()
            p.moveTo(Point(0, -radius))
            p.lineTo(Point(0, radius))
            p.moveTo(Point(-radius, 0))
            p.lineTo(Point(radius, 0))
            p = self.mapToDevice(p)
            stroker = QPainterPathStroker()
            stroker.setWidth(10)
            outline = stroker.createStroke(p)
            self._shape = self.mapFromDevice(outline)

        return self._shape
Exemplo n.º 18
0
    def shape(self):
        # (used for hitbox for menu)

        centerangle = self.innerhandle.pos().angle(Point(1, 0))
        startangle = centerangle - self.thetawidth / 2
        endangle = centerangle + self.thetawidth / 2
        r1v = self.innerhandle.pos().norm()

        # Draw out the path in external space
        path = QPainterPath()
        path.moveTo(-1.0 * self.widthhandle.pos() + 2 * self.widthhandle.pos().dot(r1v) * r1v)
        path.arcTo(QCircRectF(radius=self.innerradius), -startangle, -self.thetawidth)  # inside
        path.lineTo(self.widthhandle.pos())  # ? side
        path.arcTo(QCircRectF(radius=self.outerradius), -endangle, self.thetawidth)  # outside
        path.lineTo(-1.0 * self.widthhandle.pos() + 2 * self.widthhandle.pos().dot(r1v) * r1v)
        return path
Exemplo n.º 19
0
    def paintEvent(self, event) -> None:
        super(ToolTip, self).paintEvent(event)

        x = self.rect().x() + self._anchor_width
        y = self.rect().y() + self._anchor_width
        w = self.rect().width() - self._anchor_width * 2
        h = self.rect().height() - self._anchor_width * 2

        # 背景
        painter = QPainter(self)
        path = QPainterPath()
        path.addRoundedRect(QRectF(x, y, w, h), 4, 4)
        # 画锚
        if self._direction == ToolTip.TOP:
            x1 = x + w / 2 - self._anchor_width
            y1 = y + h
            x2 = x + w / 2 + self._anchor_width
            y2 = y + h
            x3 = x + w / 2
            y3 = y + h + self._anchor_width
            path.moveTo(x1, y1)
            path.lineTo(x2, y2)
            path.lineTo(x3, y3)
        elif self._direction == ToolTip.BOTTOM:
            x1 = x + w / 2 - self._anchor_width
            y1 = y
            x2 = x + w / 2 + self._anchor_width
            y2 = y
            x3 = x + w / 2
            y3 = y - self._anchor_width
            path.moveTo(x1, y1)
            path.lineTo(x2, y2)
            path.lineTo(x3, y3)
        elif self._direction == ToolTip.RIGHT:
            x1 = x
            y1 = y + h / 2 - self._anchor_width
            x2 = x
            y2 = y + h / 2 + self._anchor_width
            x3 = x - self._anchor_width
            y3 = y + h / 2
            path.moveTo(x1, y1)
            path.lineTo(x2, y2)
            path.lineTo(x3, y3)
        elif self._direction == ToolTip.LEFT:
            x1 = x + w
            y1 = y + h / 2 - self._anchor_width
            x2 = x + w
            y2 = y + h / 2 + self._anchor_width
            x3 = x + w + self._anchor_width
            y3 = y + h / 2
            path.moveTo(x1, y1)
            path.lineTo(x2, y2)
            path.lineTo(x3, y3)

        painter.fillPath(path, ResourceLoader().qt_color_separator_dark)
Exemplo n.º 20
0
    def paint(self, painter, fill=False, canvas=None):
        from ..application import Application

        mainwindow = Application.get_main_window()
        line_pen, last_line_pen, fill_color = self._get_pens_and_colors(
            canvas, mainwindow.lineColor, mainwindow.fillColor)
        scale = self.get_scale(canvas)
        # Draw all vertices
        self.paint_vertices(painter, self.points, scale, self._highlightIndex,
                            self._highlightMode)
        line_path1, line_path2 = QPainterPath(), QPainterPath()
        fill_path = line_path1
        # Get path for committed and uncommitted parts
        # respectively and draw with different colors
        if self.shape_type == 'curve' and self.points:
            # Bezier curve needs to be fitted as a whole,
            # so reimplementing this part here.
            refined_points = BezierB(self.points).smooth()
            sep_idx = refined_points.index(self.points[-1])
            line_path1.moveTo(refined_points[0])
            for p in refined_points[:sep_idx]:
                line_path1.lineTo(p)
            line_path2.moveTo(refined_points[sep_idx])
            for p in refined_points[sep_idx:]:
                line_path2.lineTo(p)
        elif self.shape_type in ['circle', 'rectangle']:
            painter.setPen(line_pen)
            line_path2 = self.get_line_path(self.points, self.shape_type)
            painter.setPen(last_line_pen)
            painter.drawPath(line_path2)
            fill_path = line_path2
        elif len(self.points) >= 2:
            # Otherwise, just get 2 different line paths,
            # painting with different colors.
            # Use type == 'line' even with polygon to prevent connecting back.
            line_path1 = self.get_line_path(self.points[:-1], 'line')
            line_path2 = self.get_line_path(self.points[-2:], 'line')
        painter.setPen(line_pen)
        painter.drawPath(line_path1)
        painter.setPen(last_line_pen)
        painter.drawPath(line_path2)
        if fill:
            painter.fillPath(fill_path, fill_color)
Exemplo n.º 21
0
    def drawLine(self, qp, value: int):
        """Draw line on triangle indicating value.

        Parameters
        ----------
        qp: QPainter object
        value: int
            Value of highlight thickness.
        """
        col = QColor('white')
        qp.setPen(QPen(col, 2))
        qp.setBrush(col)
        path = QPainterPath()
        path.moveTo(value, 15)

        path.lineTo(value, 0)
        path.closeSubpath()

        qp.drawPath(path)
        self.valueChanged.emit(self._value)
    def showTracks(self):
        # clear self.pathitems
        self.clearTracks()

        frame = self.window.imageview.currentIndex
        if frame<len(self.tracks_by_frame):
            tracks = self.tracks_by_frame[frame]
            pen = QPen(Qt.green, .4)
            pen.setCosmetic(True)
            pen.setWidth(2)
            for track_idx in tracks:
                pathitem = QGraphicsPathItem(self.window.imageview.view)
                pathitem.setPen(pen)
                self.window.imageview.view.addItem(pathitem)
                self.pathitems.append(pathitem)
                pts = self.txy_pts[self.tracks[track_idx]]
                x = pts[:, 1]+.5; y = pts[:,2]+.5
                path = QPainterPath(QPointF(x[0],y[0]))
                for i in np.arange(1, len(pts)):
                    path.lineTo(QPointF(x[i],y[i]))
                pathitem.setPath(path)
Exemplo n.º 23
0
 def draw_target_path(self) -> None:
     """Draw solving path."""
     pen = QPen()
     pen.setWidth(self.path_width)
     for i, n in enumerate(sorted(self.target_path)):
         path = self.target_path[n]
         if self.monochrome:
             line, dot = target_path_style(0)
         else:
             line, dot = target_path_style(i + 1)
         pen.setColor(line)
         self.painter.setPen(pen)
         if len(path) == 1:
             x, y = path[0]
             p = QPointF(x, -y) * self.zoom
             self.painter.drawText(p + QPointF(6, -6), f"P{n}")
             pen.setColor(dot)
             self.painter.setPen(pen)
             self.draw_circle(p, self.joint_size)
         else:
             painter_path = QPainterPath()
             for j, (x, y) in enumerate(path):
                 p = QPointF(x, -y) * self.zoom
                 self.draw_circle(p, self.joint_size)
                 if j == 0:
                     self.painter.drawText(p + QPointF(6, -6), f"P{n}")
                     painter_path.moveTo(p)
                 else:
                     x2, y2 = path[j - 1]
                     self.__draw_arrow(x, -y, x2, -y2, zoom=True)
                     painter_path.lineTo(p)
             pen.setColor(line)
             self.painter.setPen(pen)
             self.painter.drawPath(painter_path)
             for x, y in path:
                 pen.setColor(dot)
                 self.painter.setPen(pen)
                 self.draw_circle(
                     QPointF(x, -y) * self.zoom, self.joint_size)
     self.painter.setBrush(Qt.NoBrush)
Exemplo n.º 24
0
 def drawPolygon(self, *args):
     if len(args) == 3:
         points, pointCount, mode = args
     elif len(args) == 2:
         points, mode = args
         pointCount = len(points)
     else:
         raise TypeError("Unexpected arguments")
     device = self.nullDevice()
     if device is None:
         return
     if device.mode() == QwtNullPaintDevice.PathMode:
         path = QPainterPath()
         if pointCount > 0:
             path.moveTo(points[0])
             for i in range(1, pointCount):
                 path.lineTo(points[i])
             if mode != QPaintEngine.PolylineMode:
                 path.closeSubpath()
         device.drawPath(path)
         return
     device.drawPolygon(points, pointCount, mode)
Exemplo n.º 25
0
 def draw_curve(self, path: Sequence[_Coord]) -> None:
     """Draw path as curve."""
     if len(set(path)) < 2:
         return
     painter_path = QPainterPath()
     error = False
     for i, (x, y) in enumerate(path):
         if isnan(x):
             error = True
             self.painter.drawPath(painter_path)
             painter_path = QPainterPath()
         else:
             p = QPointF(x, -y) * self.zoom
             if i == 0:
                 painter_path.moveTo(p)
                 self.draw_circle(p, 2)
                 continue
             if error:
                 painter_path.moveTo(p)
                 error = False
             else:
                 painter_path.lineTo(p)
     self.painter.drawPath(painter_path)
Exemplo n.º 26
0
 def draw_icon(self, painter):
     path = QPainterPath(QPointF(0, 0))
     path.lineTo(1, 1)
     path.lineTo(0.005, 1)
     path.lineTo(0.5, 0.5)
     path.lineTo(0, 0.9)
     path.closeSubpath()
     painter.drawPath(path)
     painter.drawEllipse(QPointF(0.5, 0.5), 0.05, 0.05)
Exemplo n.º 27
0
    def get_painter_stroke(geom: ConnectionGeometry) -> QPainterPath:
        """
        Get painter stroke

        Parameters
        ----------
        geom : ConnectionGeometry

        Returns
        -------
        value : QPainterPath
        """
        cubic = cubic_path(geom)
        source = geom.source
        result = QPainterPath(source)
        segments = 20

        for i in range(segments):
            ratio = float(i + 1) / segments
            result.lineTo(cubic.pointAtPercent(ratio))

        stroker = QPainterPathStroker()
        stroker.setWidth(10.0)
        return stroker.createStroke(result)
Exemplo n.º 28
0
    def drawTriangle(self, qp):
        """Draw triangle.

        Parameters
        ----------
        qp: QPainter object
        """
        width = self.rect().width()
        height = self.rect().height()

        col = QColor(135, 206, 235)
        qp.setPen(QPen(col, 1))
        qp.setBrush(col)
        path = QPainterPath()

        height = 10
        path.moveTo(0, height)

        path.lineTo(width, height)

        path.lineTo(width, 0)
        path.closeSubpath()

        qp.drawPath(path)
Exemplo n.º 29
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.3))
        painter.setBrush(self._interlock_brush)
        painter.drawRect(QRectF(0.2, 0, 0.6, 0.3))
        # Draw the N
        n_path = QPainterPath(QPointF(0.25, 0.25))
        n_path.lineTo(0.25, 0.05)
        n_path.lineTo(0.45, 0.25)
        n_path.lineTo(0.45, 0.05)
        painter.drawPath(n_path)

        # Draw the O
        painter.drawEllipse(QPointF(0.65, 0.15), 0.1, 0.1)
Exemplo n.º 30
0
class FadingTipBox(FadingDialog):
    """ """
    def __init__(self,
                 parent,
                 opacity,
                 duration,
                 easing_curve,
                 tour=None,
                 color_top=None,
                 color_back=None,
                 combobox_background=None):
        super(FadingTipBox, self).__init__(parent, opacity, duration,
                                           easing_curve)
        self.holder = self.anim  # needed for qt to work
        self.parent = parent
        self.tour = tour

        self.frames = None
        self.offset_shadow = 0
        self.fixed_width = 300

        self.key_pressed = None

        self.setAttribute(Qt.WA_TranslucentBackground)
        self.setWindowFlags(Qt.Dialog | Qt.FramelessWindowHint
                            | Qt.WindowStaysOnTopHint)
        self.setModal(False)

        # Widgets
        def toolbutton(icon):
            bt = QToolButton()
            bt.setAutoRaise(True)
            bt.setIcon(icon)
            return bt

        self.button_close = toolbutton(ima.icon("tour.close"))
        self.button_home = toolbutton(ima.icon("tour.home"))
        self.button_previous = toolbutton(ima.icon("tour.previous"))
        self.button_end = toolbutton(ima.icon("tour.end"))
        self.button_next = toolbutton(ima.icon("tour.next"))
        self.button_run = QPushButton(_('Run code'))
        self.button_disable = None
        self.button_current = QToolButton()
        self.label_image = QLabel()

        self.label_title = QLabel()
        self.combo_title = QComboBox()
        self.label_current = QLabel()
        self.label_content = QLabel()

        self.label_content.setMinimumWidth(self.fixed_width)
        self.label_content.setMaximumWidth(self.fixed_width)

        self.label_current.setAlignment(Qt.AlignCenter)

        self.label_content.setWordWrap(True)

        self.widgets = [
            self.label_content, self.label_title, self.label_current,
            self.combo_title, self.button_close, self.button_run,
            self.button_next, self.button_previous, self.button_end,
            self.button_home, self.button_current
        ]

        arrow = get_image_path('hide.png')

        self.color_top = color_top
        self.color_back = color_back
        self.combobox_background = combobox_background
        self.stylesheet = '''QComboBox {{
                             padding-left: 5px;
                             background-color: {}
                             border-width: 0px;
                             border-radius: 0px;
                             min-height:20px;
                             max-height:20px;
                             }}

                             QComboBox::drop-down  {{
                             subcontrol-origin: padding;
                             subcontrol-position: top left;
                             border-width: 0px;
                             }}

                             QComboBox::down-arrow {{
                             image: url({});
                             }}

                             '''.format(self.combobox_background.name(), arrow)
        # Windows fix, slashes should be always in unix-style
        self.stylesheet = self.stylesheet.replace('\\', '/')

        self.setFocusPolicy(Qt.StrongFocus)
        for widget in self.widgets:
            widget.setFocusPolicy(Qt.NoFocus)
            widget.setStyleSheet(self.stylesheet)

        layout_top = QHBoxLayout()
        layout_top.addWidget(self.combo_title)
        layout_top.addStretch()
        layout_top.addWidget(self.button_close)
        layout_top.addSpacerItem(
            QSpacerItem(self.offset_shadow, self.offset_shadow))

        layout_content = QHBoxLayout()
        layout_content.addWidget(self.label_content)
        layout_content.addWidget(self.label_image)
        layout_content.addSpacerItem(QSpacerItem(5, 5))

        layout_run = QHBoxLayout()
        layout_run.addStretch()
        layout_run.addWidget(self.button_run)
        layout_run.addStretch()
        layout_run.addSpacerItem(
            QSpacerItem(self.offset_shadow, self.offset_shadow))

        layout_navigation = QHBoxLayout()
        layout_navigation.addWidget(self.button_home)
        layout_navigation.addWidget(self.button_previous)
        layout_navigation.addStretch()
        layout_navigation.addWidget(self.label_current)
        layout_navigation.addStretch()
        layout_navigation.addWidget(self.button_next)
        layout_navigation.addWidget(self.button_end)
        layout_navigation.addSpacerItem(
            QSpacerItem(self.offset_shadow, self.offset_shadow))

        layout = QVBoxLayout()
        layout.addLayout(layout_top)
        layout.addStretch()
        layout.addSpacerItem(QSpacerItem(15, 15))
        layout.addLayout(layout_content)
        layout.addLayout(layout_run)
        layout.addStretch()
        layout.addSpacerItem(QSpacerItem(15, 15))
        layout.addLayout(layout_navigation)
        layout.addSpacerItem(
            QSpacerItem(self.offset_shadow, self.offset_shadow))

        layout.setSizeConstraint(QLayout.SetFixedSize)

        self.setLayout(layout)

        self.set_funcs_before_fade_in([self._disable_widgets])
        self.set_funcs_after_fade_in([self._enable_widgets, self.setFocus])
        self.set_funcs_before_fade_out([self._disable_widgets])

        self.setContextMenuPolicy(Qt.CustomContextMenu)

        # signals and slots
        # These are defined every time by the AnimatedTour Class

    def _disable_widgets(self):
        """ """
        for widget in self.widgets:
            widget.setDisabled(True)

    def _enable_widgets(self):
        """ """
        self.setWindowFlags(Qt.Dialog | Qt.FramelessWindowHint
                            | Qt.WindowStaysOnTopHint)
        for widget in self.widgets:
            widget.setDisabled(False)

        if self.button_disable == 'previous':
            self.button_previous.setDisabled(True)
            self.button_home.setDisabled(True)
        elif self.button_disable == 'next':
            self.button_next.setDisabled(True)
            self.button_end.setDisabled(True)

    def set_data(self,
                 title,
                 content,
                 current,
                 image,
                 run,
                 frames=None,
                 step=None):
        """ """
        self.label_title.setText(title)
        self.combo_title.clear()
        self.combo_title.addItems(frames)
        self.combo_title.setCurrentIndex(step)
        #        min_content_len = max([len(f) for f in frames])
        #        self.combo_title.setMinimumContentsLength(min_content_len)

        # Fix and try to see how it looks with a combo box
        self.label_current.setText(current)
        self.button_current.setText(current)
        self.label_content.setText(content)
        self.image = image

        if image is None:
            self.label_image.setFixedHeight(1)
            self.label_image.setFixedWidth(1)
        else:
            extension = image.split('.')[-1]
            self.image = QPixmap(get_image_path(image), extension)
            self.label_image.setPixmap(self.image)
            self.label_image.setFixedSize(self.image.size())

        if run is None:
            self.button_run.setVisible(False)
        else:
            self.button_run.setDisabled(False)
            self.button_run.setVisible(True)

        # Refresh layout
        self.layout().activate()

    def set_pos(self, x, y):
        """ """
        self.x = ceil(x)
        self.y = ceil(y)
        self.move(QPoint(self.x, self.y))

    def build_paths(self):
        """ """
        geo = self.geometry()
        radius = 0
        shadow = self.offset_shadow
        x0, y0 = geo.x(), geo.y()
        width, height = geo.width() - shadow, geo.height() - shadow

        left, top = 0, 0
        right, bottom = width, height

        self.round_rect_path = QPainterPath()
        self.round_rect_path.moveTo(right, top + radius)
        self.round_rect_path.arcTo(right - radius, top, radius, radius, 0.0,
                                   90.0)
        self.round_rect_path.lineTo(left + radius, top)
        self.round_rect_path.arcTo(left, top, radius, radius, 90.0, 90.0)
        self.round_rect_path.lineTo(left, bottom - radius)
        self.round_rect_path.arcTo(left, bottom - radius, radius, radius,
                                   180.0, 90.0)
        self.round_rect_path.lineTo(right - radius, bottom)
        self.round_rect_path.arcTo(right - radius, bottom - radius, radius,
                                   radius, 270.0, 90.0)
        self.round_rect_path.closeSubpath()

        # Top path
        header = 36
        offset = 2
        left, top = offset, offset
        right = width - (offset)
        self.top_rect_path = QPainterPath()
        self.top_rect_path.lineTo(right, top + radius)
        self.top_rect_path.moveTo(right, top + radius)
        self.top_rect_path.arcTo(right - radius, top, radius, radius, 0.0,
                                 90.0)
        self.top_rect_path.lineTo(left + radius, top)
        self.top_rect_path.arcTo(left, top, radius, radius, 90.0, 90.0)
        self.top_rect_path.lineTo(left, top + header)
        self.top_rect_path.lineTo(right, top + header)

    def paintEvent(self, event):
        """ """
        self.build_paths()

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)

        painter.fillPath(self.round_rect_path, self.color_back)
        painter.fillPath(self.top_rect_path, self.color_top)
        painter.strokePath(self.round_rect_path, QPen(Qt.gray, 1))

        # TODO: Build the pointing arrow?

    def keyReleaseEvent(self, event):
        """ """
        key = event.key()
        self.key_pressed = key

        keys = [
            Qt.Key_Right, Qt.Key_Left, Qt.Key_Down, Qt.Key_Up, Qt.Key_Escape,
            Qt.Key_PageUp, Qt.Key_PageDown, Qt.Key_Home, Qt.Key_End,
            Qt.Key_Menu
        ]

        if key in keys:
            if not self.is_fade_running():
                self.sig_key_pressed.emit()

    def mousePressEvent(self, event):
        """override Qt method"""
        # Raise the main application window on click
        self.parent.raise_()
        self.raise_()

        if event.button() == Qt.RightButton:
            pass


#            clicked_widget = self.childAt(event.x(), event.y())
#            if clicked_widget == self.label_current:
#            self.context_menu_requested(event)

    def focusOutEvent(self, event):
        """Override Qt method."""
        # To be used so tips do not appear outside spyder
        self.tour.lost_focus()

    def context_menu_requested(self, event):
        """ """
        pos = QPoint(event.x(), event.y())
        menu = QMenu(self)

        actions = []
        action_title = create_action(self, _('Go to step: '), icon=QIcon())
        action_title.setDisabled(True)
        actions.append(action_title)
        #        actions.append(create_action(self, _(': '), icon=QIcon()))

        add_actions(menu, actions)

        menu.popup(self.mapToGlobal(pos))

    def reject(self):
        """Qt method to handle escape key event"""
        if not self.is_fade_running():
            key = Qt.Key_Escape
            self.key_pressed = key
            self.sig_key_pressed.emit()
Exemplo n.º 31
0
class FadingTipBox(FadingDialog):
    """ """
    def __init__(self, parent, opacity, duration, easing_curve, tour=None):
        super(FadingTipBox, self).__init__(parent, opacity, duration,
                                           easing_curve)
        self.holder = self.anim  # needed for qt to work
        self.parent = parent
        self.tour = tour

        self.frames = None
        self.color_top = QColor.fromRgb(230, 230, 230)
        self.color_back = QColor.fromRgb(255, 255, 255)
        self.offset_shadow = 0
        self.fixed_width = 300

        self.key_pressed = None

        self.setAttribute(Qt.WA_TranslucentBackground)
        self.setWindowFlags(Qt.Dialog | Qt.FramelessWindowHint |
                            Qt.WindowStaysOnTopHint)
        self.setModal(False)

        # Widgets
        def toolbutton(icon):
            bt = QToolButton()
            bt.setAutoRaise(True)
            bt.setIcon(icon)
            return bt

        self.button_close = toolbutton(ima.icon("tour.close"))
        self.button_home = toolbutton(ima.icon("tour.home"))
        self.button_previous = toolbutton(ima.icon("tour.previous"))
        self.button_end = toolbutton(ima.icon("tour.end"))
        self.button_next = toolbutton(ima.icon("tour.next"))
        self.button_run = QPushButton(_('Run code'))
        self.button_disable = None
        self.button_current = QToolButton()
        self.label_image = QLabel()

        self.label_title = QLabel()
        self.combo_title = QComboBox()
        self.label_current = QLabel()
        self.label_content = QLabel()

        self.label_content.setMinimumWidth(self.fixed_width)
        self.label_content.setMaximumWidth(self.fixed_width)

        self.label_current.setAlignment(Qt.AlignCenter)

        self.label_content.setWordWrap(True)

        self.widgets = [self.label_content, self.label_title,
                        self.label_current, self.combo_title,
                        self.button_close, self.button_run, self.button_next,
                        self.button_previous, self.button_end,
                        self.button_home, self.button_current]

        arrow = get_image_path('hide.png')

        self.stylesheet = '''QComboBox {
                             padding-left: 5px;
                             background-color: rgbs(230,230,230,100%);
                             border-width: 0px;
                             border-radius: 0px;
                             min-height:20px;
                             max-height:20px;
                             }

                             QComboBox::drop-down  {
                             subcontrol-origin: padding;
                             subcontrol-position: top left;
                             border-width: 0px;
                             }
                             
                             QComboBox::down-arrow {
                             image: url(''' + arrow + ''');
                             }
                             
                             '''
        # Windows fix, slashes should be always in unix-style
        self.stylesheet = self.stylesheet.replace('\\', '/')

        self.setFocusPolicy(Qt.StrongFocus)
        for widget in self.widgets:
            widget.setFocusPolicy(Qt.NoFocus)
            widget.setStyleSheet(self.stylesheet)

        layout_top = QHBoxLayout()
        layout_top.addWidget(self.combo_title)
        layout_top.addStretch()
        layout_top.addWidget(self.button_close)
        layout_top.addSpacerItem(QSpacerItem(self.offset_shadow,
                                             self.offset_shadow))

        layout_content = QHBoxLayout()
        layout_content.addWidget(self.label_content)
        layout_content.addWidget(self.label_image)
        layout_content.addSpacerItem(QSpacerItem(5, 5))

        layout_run = QHBoxLayout()
        layout_run.addStretch()
        layout_run.addWidget(self.button_run)
        layout_run.addStretch()
        layout_run.addSpacerItem(QSpacerItem(self.offset_shadow,
                                             self.offset_shadow))

        layout_navigation = QHBoxLayout()
        layout_navigation.addWidget(self.button_home)
        layout_navigation.addWidget(self.button_previous)
        layout_navigation.addStretch()
        layout_navigation.addWidget(self.label_current)
        layout_navigation.addStretch()
        layout_navigation.addWidget(self.button_next)
        layout_navigation.addWidget(self.button_end)
        layout_navigation.addSpacerItem(QSpacerItem(self.offset_shadow,
                                                    self.offset_shadow))

        layout = QVBoxLayout()
        layout.addLayout(layout_top)
        layout.addStretch()
        layout.addSpacerItem(QSpacerItem(15, 15))
        layout.addLayout(layout_content)
        layout.addLayout(layout_run)
        layout.addStretch()
        layout.addSpacerItem(QSpacerItem(15, 15))
        layout.addLayout(layout_navigation)
        layout.addSpacerItem(QSpacerItem(self.offset_shadow,
                                         self.offset_shadow))

        layout.setSizeConstraint(QLayout.SetFixedSize)

        self.setLayout(layout)

        self.set_funcs_before_fade_in([self._disable_widgets])
        self.set_funcs_after_fade_in([self._enable_widgets, self.setFocus])
        self.set_funcs_before_fade_out([self._disable_widgets])

        self.setContextMenuPolicy(Qt.CustomContextMenu)

        # signals and slots
        # These are defined every time by the AnimatedTour Class

    def _disable_widgets(self):
        """ """
        for widget in self.widgets:
            widget.setDisabled(True)

    def _enable_widgets(self):
        """ """
        self.setWindowFlags(Qt.Dialog | Qt.FramelessWindowHint |
                            Qt.WindowStaysOnTopHint)
        for widget in self.widgets:
            widget.setDisabled(False)

        if self.button_disable == 'previous':
            self.button_previous.setDisabled(True)
            self.button_home.setDisabled(True)
        elif self.button_disable == 'next':
            self.button_next.setDisabled(True)
            self.button_end.setDisabled(True)

    def set_data(self, title, content, current, image, run, frames=None,
                 step=None):
        """ """
        self.label_title.setText(title)
        self.combo_title.clear()
        self.combo_title.addItems(frames)
        self.combo_title.setCurrentIndex(step)
#        min_content_len = max([len(f) for f in frames])
#        self.combo_title.setMinimumContentsLength(min_content_len)

        # Fix and try to see how it looks with a combo box
        self.label_current.setText(current)
        self.button_current.setText(current)
        self.label_content.setText(content)
        self.image = image

        if image is None:
            self.label_image.setFixedHeight(1)
            self.label_image.setFixedWidth(1)
        else:
            extension = image.split('.')[-1]
            self.image = QPixmap(get_image_path(image), extension)
            self.label_image.setPixmap(self.image)
            self.label_image.setFixedSize(self.image.size())

        if run is None:
            self.button_run.setVisible(False)
        else:
            self.button_run.setDisabled(False)
            self.button_run.setVisible(True)

        # Refresh layout
        self.layout().activate()

    def set_pos(self, x, y):
        """ """
        self.x = x
        self.y = y
        self.move(QPoint(x, y))

    def build_paths(self):
        """ """
        geo = self.geometry()
        radius = 0
        shadow = self.offset_shadow
        x0, y0 = geo.x(), geo.y()
        width, height = geo.width() - shadow, geo.height() - shadow

        left, top = 0, 0
        right, bottom = width, height

        self.round_rect_path = QPainterPath()
        self.round_rect_path.moveTo(right, top + radius)
        self.round_rect_path.arcTo(right-radius, top, radius, radius, 0.0,
                                   90.0)
        self.round_rect_path.lineTo(left+radius, top)
        self.round_rect_path.arcTo(left, top, radius, radius, 90.0, 90.0)
        self.round_rect_path.lineTo(left, bottom-radius)
        self.round_rect_path.arcTo(left, bottom-radius, radius, radius, 180.0,
                                   90.0)
        self.round_rect_path.lineTo(right-radius, bottom)
        self.round_rect_path.arcTo(right-radius, bottom-radius, radius, radius,
                                   270.0, 90.0)
        self.round_rect_path.closeSubpath()

        # Top path
        header = 36
        offset = 2
        left, top = offset, offset
        right = width - (offset)
        self.top_rect_path = QPainterPath()
        self.top_rect_path.lineTo(right, top + radius)
        self.top_rect_path.moveTo(right, top + radius)
        self.top_rect_path.arcTo(right-radius, top, radius, radius, 0.0, 90.0)
        self.top_rect_path.lineTo(left+radius, top)
        self.top_rect_path.arcTo(left, top, radius, radius, 90.0, 90.0)
        self.top_rect_path.lineTo(left, top + header)
        self.top_rect_path.lineTo(right, top + header)

    def paintEvent(self, event):
        """ """
        self.build_paths()

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)

        painter.fillPath(self.round_rect_path, self.color_back)
        painter.fillPath(self.top_rect_path, self.color_top)
        painter.strokePath(self.round_rect_path, QPen(Qt.gray, 1))

        # TODO: Build the pointing arrow?

    def keyReleaseEvent(self, event):
        """ """
        key = event.key()
        self.key_pressed = key

        keys = [Qt.Key_Right, Qt.Key_Left, Qt.Key_Down, Qt.Key_Up,
                Qt.Key_Escape, Qt.Key_PageUp, Qt.Key_PageDown,
                Qt.Key_Home, Qt.Key_End, Qt.Key_Menu]

        if key in keys:
            if not self.is_fade_running():
                self.sig_key_pressed.emit()

    def mousePressEvent(self, event):
        """override Qt method"""
        # Raise the main application window on click
        self.parent.raise_()
        self.raise_()

        if event.button() == Qt.RightButton:
            pass
#            clicked_widget = self.childAt(event.x(), event.y())
#            if clicked_widget == self.label_current:
#            self.context_menu_requested(event)

    def focusOutEvent(self, event):
        """Override Qt method."""
        # To be used so tips do not appear outside spyder
        self.tour.lost_focus()

    def context_menu_requested(self, event):
        """ """
        pos = QPoint(event.x(), event.y())
        menu = QMenu(self)

        actions = []
        action_title = create_action(self, _('Go to step: '), icon=QIcon())
        action_title.setDisabled(True)
        actions.append(action_title)
#        actions.append(create_action(self, _(': '), icon=QIcon()))

        add_actions(menu, actions)

        menu.popup(self.mapToGlobal(pos))

    def reject(self):
        """Qt method to handle escape key event"""
        if not self.is_fade_running():
            key = Qt.Key_Escape
            self.key_pressed = key
            self.sig_key_pressed.emit()
Exemplo n.º 32
0
 def drawFrame(
     self,
     painter,
     rect,
     palette,
     foregroundRole,
     frameWidth,
     midLineWidth,
     frameStyle,
 ):
     """
     Draw a rectangular frame
     
     :param QPainter painter: Painter
     :param QRectF rect: Frame rectangle
     :param QPalette palette: Palette
     :param QPalette.ColorRole foregroundRole: Palette
     :param int frameWidth: Frame width
     :param int midLineWidth: Used for `QFrame.Box`
     :param int frameStyle: bitwise OR´ed value of `QFrame.Shape` and `QFrame.Shadow`
     """
     if frameWidth <= 0 or rect.isEmpty():
         return
     shadow = frameStyle & QFrame.Shadow_Mask
     painter.save()
     if shadow == QFrame.Plain:
         outerRect = rect.adjusted(0.0, 0.0, -1.0, -1.0)
         innerRect = outerRect.adjusted(frameWidth, frameWidth, -frameWidth,
                                        -frameWidth)
         path = QPainterPath()
         path.addRect(outerRect)
         path.addRect(innerRect)
         painter.setPen(Qt.NoPen)
         painter.setBrush(palette.color(foregroundRole))
         painter.drawPath(path)
     else:
         shape = frameStyle & QFrame.Shape_Mask
         if shape == QFrame.Box:
             outerRect = rect.adjusted(0.0, 0.0, -1.0, -1.0)
             midRect1 = outerRect.adjusted(frameWidth, frameWidth,
                                           -frameWidth, -frameWidth)
             midRect2 = midRect1.adjusted(midLineWidth, midLineWidth,
                                          -midLineWidth, -midLineWidth)
             innerRect = midRect2.adjusted(frameWidth, frameWidth,
                                           -frameWidth, -frameWidth)
             path1 = QPainterPath()
             path1.moveTo(outerRect.bottomLeft())
             path1.lineTo(outerRect.topLeft())
             path1.lineTo(outerRect.topRight())
             path1.lineTo(midRect1.topRight())
             path1.lineTo(midRect1.topLeft())
             path1.lineTo(midRect1.bottomLeft())
             path2 = QPainterPath()
             path2.moveTo(outerRect.bottomLeft())
             path2.lineTo(outerRect.bottomRight())
             path2.lineTo(outerRect.topRight())
             path2.lineTo(midRect1.topRight())
             path2.lineTo(midRect1.bottomRight())
             path2.lineTo(midRect1.bottomLeft())
             path3 = QPainterPath()
             path3.moveTo(midRect2.bottomLeft())
             path3.lineTo(midRect2.topLeft())
             path3.lineTo(midRect2.topRight())
             path3.lineTo(innerRect.topRight())
             path3.lineTo(innerRect.topLeft())
             path3.lineTo(innerRect.bottomLeft())
             path4 = QPainterPath()
             path4.moveTo(midRect2.bottomLeft())
             path4.lineTo(midRect2.bottomRight())
             path4.lineTo(midRect2.topRight())
             path4.lineTo(innerRect.topRight())
             path4.lineTo(innerRect.bottomRight())
             path4.lineTo(innerRect.bottomLeft())
             path5 = QPainterPath()
             path5.addRect(midRect1)
             path5.addRect(midRect2)
             painter.setPen(Qt.NoPen)
             brush1 = palette.dark().color()
             brush2 = palette.light().color()
             if shadow == QFrame.Raised:
                 brush1, brush2 = brush2, brush1
             painter.setBrush(brush1)
             painter.drawPath(path1)
             painter.drawPath(path4)
             painter.setBrush(brush2)
             painter.drawPath(path2)
             painter.drawPath(path3)
             painter.setBrush(palette.mid())
             painter.drawPath(path5)
         else:
             outerRect = rect.adjusted(0.0, 0.0, -1.0, -1.0)
             innerRect = outerRect.adjusted(
                 frameWidth - 1.0,
                 frameWidth - 1.0,
                 -(frameWidth - 1.0),
                 -(frameWidth - 1.0),
             )
             path1 = QPainterPath()
             path1.moveTo(outerRect.bottomLeft())
             path1.lineTo(outerRect.topLeft())
             path1.lineTo(outerRect.topRight())
             path1.lineTo(innerRect.topRight())
             path1.lineTo(innerRect.topLeft())
             path1.lineTo(innerRect.bottomLeft())
             path2 = QPainterPath()
             path2.moveTo(outerRect.bottomLeft())
             path2.lineTo(outerRect.bottomRight())
             path2.lineTo(outerRect.topRight())
             path2.lineTo(innerRect.topRight())
             path2.lineTo(innerRect.bottomRight())
             path2.lineTo(innerRect.bottomLeft())
             painter.setPen(Qt.NoPen)
             brush1 = palette.dark().color()
             brush2 = palette.light().color()
             if shadow == QFrame.Raised:
                 brush1, brush2 = brush2, brush1
             painter.setBrush(brush1)
             painter.drawPath(path1)
             painter.setBrush(brush2)
             painter.drawPath(path2)
     painter.restore()