示例#1
0
def qwtDrawStar2Symbols(painter, points, numPoints, symbol):
    pen = QPen(symbol.pen())
    if pen.width() > 1:
        pen.setCapStyle(Qt.FlatCap)
    pen.setJoinStyle(Qt.MiterJoin)
    painter.setPen(pen)
    painter.setBrush(symbol.brush())
    cos30 = np.cos(30*np.pi/180.)
    dy = .25*symbol.size().height()
    dx = .5*symbol.size().width()*cos30/3.
    for pos in points:
        x = pos.x()
        y = pos.y()
        x1 = x-3*dx
        y1 = y-2*dy
        x2 = x1+1*dx
        x3 = x1+2*dx
        x4 = x1+3*dx
        x5 = x1+4*dx
        x6 = x1+5*dx
        x7 = x1+6*dx
        y2 = y1+1*dy
        y3 = y1+2*dy
        y4 = y1+3*dy
        y5 = y1+4*dy
        star = [QPointF(x4, y1), QPointF(x5, y2), QPointF(x7, y2),
                QPointF(x6, y3), QPointF(x7, y4), QPointF(x5, y4),
                QPointF(x4, y5), QPointF(x3, y4), QPointF(x1, y4),
                QPointF(x2, y3), QPointF(x1, y2), QPointF(x3, y2)]
        painter.drawPolygon(QPolygonF(star))
示例#2
0
文件: symbol.py 项目: gyenney/Tools
def qwtDrawXCrossSymbols(painter, points, numPoints, symbol):
    size =symbol.size()
    off = 0
    pen = QPen(symbol.pen())
    if pen.width() > 1:
        pen.setCapStyle(Qt.FlatCap)
        off = 1
    painter.setPen(pen)
    if QwtPainter.roundingAlignment(painter):
        sw = np.floor(size.width())
        sh = np.floor(size.height())
        sw2 = size.width()//2
        sh2 = size.height()//2
        for pos in points:
            x = round(pos.x())
            y = round(pos.y())
            x1 = x-sw2
            x2 = x1+sw+off
            y1 = y-sh2
            y2 = y1+sh+off
            QwtPainter.drawLine(painter, x1, y1, x2, y2)
            QwtPainter.drawLine(painter, x2, y1, x1, y2)
    else:
        sw = size.width()
        sh = size.height()
        sw2 = .5*size.width()
        sh2 = .5*size.height()
        for pos in points:
            x1 = pos.x()-sw2
            x2 = x1+sw
            y1 = pos.y()-sh2
            y2 = y1+sh
            QwtPainter.drawLine(painter, x1, y1, x2, y2)
            QwtPainter.drawLine(painter, x2, y1, x1, y2)
示例#3
0
文件: symbol.py 项目: gyenney/Tools
def qwtDrawXCrossSymbols(painter, points, numPoints, symbol):
    size = symbol.size()
    off = 0
    pen = QPen(symbol.pen())
    if pen.width() > 1:
        pen.setCapStyle(Qt.FlatCap)
        off = 1
    painter.setPen(pen)
    if QwtPainter.roundingAlignment(painter):
        sw = np.floor(size.width())
        sh = np.floor(size.height())
        sw2 = size.width() // 2
        sh2 = size.height() // 2
        for pos in points:
            x = round(pos.x())
            y = round(pos.y())
            x1 = x - sw2
            x2 = x1 + sw + off
            y1 = y - sh2
            y2 = y1 + sh + off
            QwtPainter.drawLine(painter, x1, y1, x2, y2)
            QwtPainter.drawLine(painter, x2, y1, x1, y2)
    else:
        sw = size.width()
        sh = size.height()
        sw2 = .5 * size.width()
        sh2 = .5 * size.height()
        for pos in points:
            x1 = pos.x() - sw2
            x2 = x1 + sw
            y1 = pos.y() - sh2
            y2 = y1 + sh
            QwtPainter.drawLine(painter, x1, y1, x2, y2)
            QwtPainter.drawLine(painter, x2, y1, x1, y2)
示例#4
0
文件: symbol.py 项目: gyenney/Tools
def qwtDrawStar2Symbols(painter, points, numPoints, symbol):
    pen = QPen(symbol.pen())
    if pen.width() > 1:
        pen.setCapStyle(Qt.FlatCap)
    pen.setJoinStyle(Qt.MiterJoin)
    painter.setPen(pen)
    painter.setBrush(symbol.brush())
    cos30 = np.cos(30 * np.pi / 180.)
    dy = .25 * symbol.size().height()
    dx = .5 * symbol.size().width() * cos30 / 3.
    doAlign = QwtPainter.roundingAlignment(painter)
    for pos in points:
        if doAlign:
            x = round(pos.x())
            y = round(pos.y())
            x1 = round(x - 3 * dx)
            y1 = round(y - 2 * dy)
        else:
            x = pos.x()
            y = pos.y()
            x1 = x - 3 * dx
            y1 = y - 2 * dy
        x2 = x1 + 1 * dx
        x3 = x1 + 2 * dx
        x4 = x1 + 3 * dx
        x5 = x1 + 4 * dx
        x6 = x1 + 5 * dx
        x7 = x1 + 6 * dx
        y2 = y1 + 1 * dy
        y3 = y1 + 2 * dy
        y4 = y1 + 3 * dy
        y5 = y1 + 4 * dy
        star = [
            QPointF(x4, y1),
            QPointF(x5, y2),
            QPointF(x7, y2),
            QPointF(x6, y3),
            QPointF(x7, y4),
            QPointF(x5, y4),
            QPointF(x4, y5),
            QPointF(x3, y4),
            QPointF(x1, y4),
            QPointF(x2, y3),
            QPointF(x1, y2),
            QPointF(x3, y2)
        ]
        QwtPainter.drawPolygon(painter, QPolygonF(star))
示例#5
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 = .5 * size.width()
    sh2 = .5 * size.height()
    for pos in points:
        x1 = pos.x() - sw2
        x2 = x1 + sw
        y1 = pos.y() - sh2
        y2 = y1 + sh
        painter.drawLine(x1, y1, x2, y2)
        painter.drawLine(x2, y1, x1, y2)
示例#6
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 = .5*size.width()
    sh2 = .5*size.height()
    for pos in points:
        x1 = pos.x()-sw2
        x2 = x1+sw
        y1 = pos.y()-sh2
        y2 = y1+sh
        painter.drawLine(x1, y1, x2, y2)
        painter.drawLine(x2, y1, x1, y2)
示例#7
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 = .5 * size.width()
    sh2 = .5 * size.height()
    for pos in points:
        if orientations & Qt.Horizontal:
            x = round(pos.x()) - sw2
            y = round(pos.y())
            painter.drawLine(x, y, x + sw, y)
        if orientations & Qt.Vertical:
            x = round(pos.x())
            y = round(pos.y()) - sh2
            painter.drawLine(x, y, x, y + sh)
示例#8
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 = .5*size.width()
    sh2 = .5*size.height()
    for pos in points:
        if orientations & Qt.Horizontal:
            x = round(pos.x())-sw2
            y = round(pos.y())
            painter.drawLine(x, y, x+sw, y)
        if orientations & Qt.Vertical:
            x = round(pos.x())
            y = round(pos.y())-sh2
            painter.drawLine(x, y, x, y+sh)
示例#9
0
 def draw(self, painter, xMap, yMap, canvasRect):
     minorPen = QPen(self.__data.minorPen)
     minorPen.setCapStyle(Qt.FlatCap)
     painter.setPen(minorPen)
     if self.__data.xEnabled and self.__data.xMinEnabled:
         self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                        self.__data.xScaleDiv.ticks(QwtScaleDiv.MinorTick))
         self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                        self.__data.xScaleDiv.ticks(QwtScaleDiv.MediumTick))
     if self.__data.yEnabled and self.__data.yMinEnabled:
         self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                        self.__data.yScaleDiv.ticks(QwtScaleDiv.MinorTick))
         self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                        self.__data.yScaleDiv.ticks(QwtScaleDiv.MediumTick))
     majorPen = QPen(self.__data.majorPen)
     majorPen.setCapStyle(Qt.FlatCap)
     painter.setPen(majorPen)
     if self.__data.xEnabled:
         self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                        self.__data.xScaleDiv.ticks(QwtScaleDiv.MajorTick))
     if self.__data.yEnabled:
         self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                        self.__data.yScaleDiv.ticks(QwtScaleDiv.MajorTick))
示例#10
0
 def draw(self, painter, xMap, yMap, canvasRect):
     minorPen = QPen(self.__data.minorPen)
     minorPen.setCapStyle(Qt.FlatCap)
     painter.setPen(minorPen)
     if self.__data.xEnabled and self.__data.xMinEnabled:
         self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                        self.__data.xScaleDiv.ticks(QwtScaleDiv.MinorTick))
         self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                        self.__data.xScaleDiv.ticks(QwtScaleDiv.MediumTick))
     if self.__data.yEnabled and self.__data.yMinEnabled:
         self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                        self.__data.yScaleDiv.ticks(QwtScaleDiv.MinorTick))
         self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                        self.__data.yScaleDiv.ticks(QwtScaleDiv.MediumTick))
     majorPen = QPen(self.__data.majorPen)
     majorPen.setCapStyle(Qt.FlatCap)
     painter.setPen(majorPen)
     if self.__data.xEnabled:
         self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                        self.__data.xScaleDiv.ticks(QwtScaleDiv.MajorTick))
     if self.__data.yEnabled:
         self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                        self.__data.yScaleDiv.ticks(QwtScaleDiv.MajorTick))
示例#11
0
文件: symbol.py 项目: gyenney/Tools
def qwtDrawLineSymbols(painter, orientations, points, numPoints, symbol):
    size =symbol.size()
    off = 0
    pen = QPen(symbol.pen())
    if pen.width() > 1:
        pen.setCapStyle(Qt.FlatCap)
        off = 1
    painter.setPen(pen)
    painter.setRenderHint(QPainter.Antialiasing, False)
    if QwtPainter.roundingAlignment(painter):
        sw = np.floor(size.width())
        sh = np.floor(size.height())
        sw2 = size.width()//2
        sh2 = size.height()//2
        for pos in points:
            if orientations & Qt.Horizontal:
                x = round(pos.x())-sw2
                y = round(pos.y())
                QwtPainter.drawLine(painter, x, y, x+sw+off, y)
            if orientations & Qt.Vertical:
                x = round(pos.x())
                y = round(pos.y())-sh2
                QwtPainter.drawLine(painter, x, y, x, y+sh+off)
    else:
        sw = size.width()
        sh = size.height()
        sw2 = .5*size.width()
        sh2 = .5*size.height()
        for pos in points:
            if orientations & Qt.Horizontal:
                x = round(pos.x())-sw2
                y = round(pos.y())
                QwtPainter.drawLine(painter, x, y, x+sw, y)
            if orientations & Qt.Vertical:
                x = round(pos.x())
                y = round(pos.y())-sh2
                QwtPainter.drawLine(painter, x, y, x, y+sh)
示例#12
0
文件: symbol.py 项目: gyenney/Tools
def qwtDrawLineSymbols(painter, orientations, points, numPoints, symbol):
    size = symbol.size()
    off = 0
    pen = QPen(symbol.pen())
    if pen.width() > 1:
        pen.setCapStyle(Qt.FlatCap)
        off = 1
    painter.setPen(pen)
    painter.setRenderHint(QPainter.Antialiasing, False)
    if QwtPainter.roundingAlignment(painter):
        sw = np.floor(size.width())
        sh = np.floor(size.height())
        sw2 = size.width() // 2
        sh2 = size.height() // 2
        for pos in points:
            if orientations & Qt.Horizontal:
                x = round(pos.x()) - sw2
                y = round(pos.y())
                QwtPainter.drawLine(painter, x, y, x + sw + off, y)
            if orientations & Qt.Vertical:
                x = round(pos.x())
                y = round(pos.y()) - sh2
                QwtPainter.drawLine(painter, x, y, x, y + sh + off)
    else:
        sw = size.width()
        sh = size.height()
        sw2 = .5 * size.width()
        sh2 = .5 * size.height()
        for pos in points:
            if orientations & Qt.Horizontal:
                x = round(pos.x()) - sw2
                y = round(pos.y())
                QwtPainter.drawLine(painter, x, y, x + sw, y)
            if orientations & Qt.Vertical:
                x = round(pos.x())
                y = round(pos.y()) - sh2
                QwtPainter.drawLine(painter, x, y, x, y + sh)
示例#13
0
    def draw(self, painter, xMap, yMap, canvasRect):
        """
        Draw the grid

        The grid is drawn into the bounding rectangle such that
        grid lines begin and end at the rectangle's borders. The X and Y
        maps are used to map the scale divisions into the drawing region
        screen.

        :param QPainter painter: Painter
        :param qwt.scale_map.QwtScaleMap xMap: X axis map
        :param qwt.scale_map.QwtScaleMap yMap: Y axis
        :param QRectF canvasRect: Contents rectangle of the plot canvas
        """
        minorPen = QPen(self.__data.minorPen)
        minorPen.setCapStyle(Qt.FlatCap)
        painter.setPen(minorPen)
        if self.__data.xEnabled and self.__data.xMinEnabled:
            self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                           self.__data.xScaleDiv.ticks(QwtScaleDiv.MinorTick))
            self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                           self.__data.xScaleDiv.ticks(QwtScaleDiv.MediumTick))
        if self.__data.yEnabled and self.__data.yMinEnabled:
            self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                           self.__data.yScaleDiv.ticks(QwtScaleDiv.MinorTick))
            self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                           self.__data.yScaleDiv.ticks(QwtScaleDiv.MediumTick))
        majorPen = QPen(self.__data.majorPen)
        majorPen.setCapStyle(Qt.FlatCap)
        painter.setPen(majorPen)
        if self.__data.xEnabled:
            self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                           self.__data.xScaleDiv.ticks(QwtScaleDiv.MajorTick))
        if self.__data.yEnabled:
            self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                           self.__data.yScaleDiv.ticks(QwtScaleDiv.MajorTick))
示例#14
0
    def draw(self, painter, xMap, yMap, canvasRect):
        """
        Draw the grid

        The grid is drawn into the bounding rectangle such that
        grid lines begin and end at the rectangle's borders. The X and Y
        maps are used to map the scale divisions into the drawing region
        screen.

        :param QPainter painter: Painter
        :param qwt.scale_map.QwtScaleMap xMap: X axis map
        :param qwt.scale_map.QwtScaleMap yMap: Y axis
        :param QRectF canvasRect: Contents rectangle of the plot canvas
        """
        minorPen = QPen(self.__data.minorPen)
        minorPen.setCapStyle(Qt.FlatCap)
        painter.setPen(minorPen)
        if self.__data.xEnabled and self.__data.xMinEnabled:
            self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                           self.__data.xScaleDiv.ticks(QwtScaleDiv.MinorTick))
            self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                           self.__data.xScaleDiv.ticks(QwtScaleDiv.MediumTick))
        if self.__data.yEnabled and self.__data.yMinEnabled:
            self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                           self.__data.yScaleDiv.ticks(QwtScaleDiv.MinorTick))
            self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                           self.__data.yScaleDiv.ticks(QwtScaleDiv.MediumTick))
        majorPen = QPen(self.__data.majorPen)
        majorPen.setCapStyle(Qt.FlatCap)
        painter.setPen(majorPen)
        if self.__data.xEnabled:
            self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                           self.__data.xScaleDiv.ticks(QwtScaleDiv.MajorTick))
        if self.__data.yEnabled:
            self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                           self.__data.yScaleDiv.ticks(QwtScaleDiv.MajorTick))
示例#15
0
 def drawRoundedFrame(self, painter, rect, xRadius, yRadius,
                      palette, lineWidth, frameStyle):
     painter.save()
     painter.setRenderHint(QPainter.Antialiasing, True)
     painter.setBrush(Qt.NoBrush)
     lw2 = lineWidth*.5
     r = rect.adjusted(lw2, lw2, -lw2, -lw2)
     path = QPainterPath()
     path.addRoundedRect(r, xRadius, yRadius)
     Plain, Sunken, Raised = list(range(3))
     style = Plain
     if (frameStyle & QFrame.Sunken) == QFrame.Sunken:
         style = Sunken
     if (frameStyle & QFrame.Raised) == QFrame.Raised:
         style = Raised
     if style != Plain and path.elementCount() == 17:
         pathList = [QPainterPath() for _i in range(8)]
         for i in range(4):
             j = i*4+1
             pathList[2*i].moveTo(path.elementAt(j-1).x,
                                  path.elementAt(j-1).y)
             pathList[2*i].cubicTo(
                     path.elementAt(j+0).x, path.elementAt(j+0).y,
                     path.elementAt(j+1).x, path.elementAt(j+1).y,
                     path.elementAt(j+2).x, path.elementAt(j+2).y)
             pathList[2*i+1].moveTo(path.elementAt(j+2).x,
                                    path.elementAt(j+2).y)
             pathList[2*i+1].lineTo(path.elementAt(j+3).x,
                                    path.elementAt(j+3).y)
         c1 = QColor(palette.color(QPalette.Dark))
         c2 = QColor(palette.color(QPalette.Light))
         if style == Raised:
             c1, c2 = c2, c1
         for i in range(5):
             r = pathList[2*i].controlPointRect()
             arcPen = QPen()
             arcPen.setCapStyle(Qt.FlatCap)
             arcPen.setWidth(lineWidth)
             linePen = QPen()
             linePen.setCapStyle(Qt.FlatCap)
             linePen.setWidth(lineWidth)
             if i == 0:
                 arcPen.setColor(c1)
                 linePen.setColor(c1)
             elif i == 1:
                 gradient = QLinearGradient()
                 gradient.setStart(r.topLeft())
                 gradient.setFinalStop(r.bottomRight())
                 gradient.setColorAt(0., c1)
                 gradient.setColorAt(1., c2)
                 arcPen.setBrush(gradient)
                 linePen.setColor(c2)
             elif i == 2:
                 arcPen.setColor(c2)
                 linePen.setColor(c2)
             elif i == 3:
                 gradient = QLinearGradient()
                 gradient.setStart(r.bottomRight())
                 gradient.setFinalStop(r.topLeft())
                 gradient.setColorAt(0., c2)
                 gradient.setColorAt(1., c1)
                 arcPen.setBrush(gradient)
                 linePen.setColor(c1)
             painter.setPen(arcPen)
             painter.drawPath(pathList[2*i])
             painter.setPen(linePen)
             painter.drawPath(pathList[2*i+1])
     else:
         pen = QPen(palette.color(QPalette.WindowText), lineWidth)
         painter.setPen(pen)
         painter.drawPath(path)
     painter.restore()
示例#16
0
文件: painter.py 项目: gyenney/Tools
 def drawRoundedFrame(self, painter, rect, xRadius, yRadius,
                      palette, lineWidth, frameStyle):
     """
     Draw a rectangular frame with rounded borders
     
     :param QPainter painter: Painter
     :param QRectF rect: Frame rectangle
     :param float xRadius: x-radius of the ellipses defining the corners
     :param float yRadius: y-radius of the ellipses defining the corners
     :param QPalette palette: `QPalette.WindowText` is used for plain borders, `QPalette.Dark` and `QPalette.Light` for raised or sunken borders
     :param int lineWidth: Line width
     :param int frameStyle: bitwise OR´ed value of `QFrame.Shape` and `QFrame.Shadow`
     """
     painter.save()
     painter.setRenderHint(QPainter.Antialiasing, True)
     painter.setBrush(Qt.NoBrush)
     lw2 = lineWidth*.5
     r = rect.adjusted(lw2, lw2, -lw2, -lw2)
     path = QPainterPath()
     path.addRoundedRect(r, xRadius, yRadius)
     Plain, Sunken, Raised = list(range(3))
     style = Plain
     if (frameStyle & QFrame.Sunken) == QFrame.Sunken:
         style = Sunken
     if (frameStyle & QFrame.Raised) == QFrame.Raised:
         style = Raised
     if style != Plain and path.elementCount() == 17:
         pathList = [QPainterPath() for _i in range(8)]
         for i in range(4):
             j = i*4+1
             pathList[2*i].moveTo(path.elementAt(j-1).x,
                                  path.elementAt(j-1).y)
             pathList[2*i].cubicTo(
                     path.elementAt(j+0).x, path.elementAt(j+0).y,
                     path.elementAt(j+1).x, path.elementAt(j+1).y,
                     path.elementAt(j+2).x, path.elementAt(j+2).y)
             pathList[2*i+1].moveTo(path.elementAt(j+2).x,
                                    path.elementAt(j+2).y)
             pathList[2*i+1].lineTo(path.elementAt(j+3).x,
                                    path.elementAt(j+3).y)
         c1 = QColor(palette.color(QPalette.Dark))
         c2 = QColor(palette.color(QPalette.Light))
         if style == Raised:
             c1, c2 = c2, c1
         for i in range(5):
             r = pathList[2*i].controlPointRect()
             arcPen = QPen()
             arcPen.setCapStyle(Qt.FlatCap)
             arcPen.setWidth(lineWidth)
             linePen = QPen()
             linePen.setCapStyle(Qt.FlatCap)
             linePen.setWidth(lineWidth)
             if i == 0:
                 arcPen.setColor(c1)
                 linePen.setColor(c1)
             elif i == 1:
                 gradient = QLinearGradient()
                 gradient.setStart(r.topLeft())
                 gradient.setFinalStop(r.bottomRight())
                 gradient.setColorAt(0., c1)
                 gradient.setColorAt(1., c2)
                 arcPen.setBrush(gradient)
                 linePen.setColor(c2)
             elif i == 2:
                 arcPen.setColor(c2)
                 linePen.setColor(c2)
             elif i == 3:
                 gradient = QLinearGradient()
                 gradient.setStart(r.bottomRight())
                 gradient.setFinalStop(r.topLeft())
                 gradient.setColorAt(0., c2)
                 gradient.setColorAt(1., c1)
                 arcPen.setBrush(gradient)
                 linePen.setColor(c1)
             painter.setPen(arcPen)
             painter.drawPath(pathList[2*i])
             painter.setPen(linePen)
             painter.drawPath(pathList[2*i+1])
     else:
         pen = QPen(palette.color(QPalette.WindowText), lineWidth)
         painter.setPen(pen)
         painter.drawPath(path)
     painter.restore()
示例#17
0
 def drawRoundedFrame(self, painter, rect, xRadius, yRadius, palette,
                      lineWidth, frameStyle):
     painter.save()
     painter.setRenderHint(QPainter.Antialiasing, True)
     painter.setBrush(Qt.NoBrush)
     lw2 = lineWidth * .5
     r = rect.adjusted(lw2, lw2, -lw2, -lw2)
     path = QPainterPath()
     path.addRoundedRect(r, xRadius, yRadius)
     Plain, Sunken, Raised = list(range(3))
     style = Plain
     if (frameStyle & QFrame.Sunken) == QFrame.Sunken:
         style = Sunken
     if (frameStyle & QFrame.Raised) == QFrame.Raised:
         style = Raised
     if style != Plain and path.elementCount() == 17:
         pathList = [QPainterPath() for _i in range(8)]
         for i in range(4):
             j = i * 4 + 1
             pathList[2 * i].moveTo(
                 path.elementAt(j - 1).x,
                 path.elementAt(j - 1).y)
             pathList[2 * i].cubicTo(
                 path.elementAt(j + 0).x,
                 path.elementAt(j + 0).y,
                 path.elementAt(j + 1).x,
                 path.elementAt(j + 1).y,
                 path.elementAt(j + 2).x,
                 path.elementAt(j + 2).y)
             pathList[2 * i + 1].moveTo(
                 path.elementAt(j + 2).x,
                 path.elementAt(j + 2).y)
             pathList[2 * i + 1].lineTo(
                 path.elementAt(j + 3).x,
                 path.elementAt(j + 3).y)
         c1 = QColor(palette.color(QPalette.Dark))
         c2 = QColor(palette.color(QPalette.Light))
         if style == Raised:
             c1, c2 = c2, c1
         for i in range(5):
             r = pathList[2 * i].controlPointRect()
             arcPen = QPen()
             arcPen.setCapStyle(Qt.FlatCap)
             arcPen.setWidth(lineWidth)
             linePen = QPen()
             linePen.setCapStyle(Qt.FlatCap)
             linePen.setWidth(lineWidth)
             if i == 0:
                 arcPen.setColor(c1)
                 linePen.setColor(c1)
             elif i == 1:
                 gradient = QLinearGradient()
                 gradient.setStart(r.topLeft())
                 gradient.setFinalStop(r.bottomRight())
                 gradient.setColorAt(0., c1)
                 gradient.setColorAt(1., c2)
                 arcPen.setBrush(gradient)
                 linePen.setColor(c2)
             elif i == 2:
                 arcPen.setColor(c2)
                 linePen.setColor(c2)
             elif i == 3:
                 gradient = QLinearGradient()
                 gradient.setStart(r.bottomRight())
                 gradient.setFinalStop(r.topLeft())
                 gradient.setColorAt(0., c2)
                 gradient.setColorAt(1., c1)
                 arcPen.setBrush(gradient)
                 linePen.setColor(c1)
             painter.setPen(arcPen)
             painter.drawPath(pathList[2 * i])
             painter.setPen(linePen)
             painter.drawPath(pathList[2 * i + 1])
     else:
         pen = QPen(palette.color(QPalette.WindowText), lineWidth)
         painter.setPen(pen)
         painter.drawPath(path)
     painter.restore()
示例#18
0
 def drawRoundedFrame(self, painter, rect, xRadius, yRadius, palette,
                      lineWidth, frameStyle):
     """
     Draw a rectangular frame with rounded borders
     
     :param QPainter painter: Painter
     :param QRectF rect: Frame rectangle
     :param float xRadius: x-radius of the ellipses defining the corners
     :param float yRadius: y-radius of the ellipses defining the corners
     :param QPalette palette: `QPalette.WindowText` is used for plain borders, `QPalette.Dark` and `QPalette.Light` for raised or sunken borders
     :param int lineWidth: Line width
     :param int frameStyle: bitwise OR´ed value of `QFrame.Shape` and `QFrame.Shadow`
     """
     painter.save()
     painter.setRenderHint(QPainter.Antialiasing, True)
     painter.setBrush(Qt.NoBrush)
     lw2 = lineWidth * .5
     r = rect.adjusted(lw2, lw2, -lw2, -lw2)
     path = QPainterPath()
     path.addRoundedRect(r, xRadius, yRadius)
     Plain, Sunken, Raised = list(range(3))
     style = Plain
     if (frameStyle & QFrame.Sunken) == QFrame.Sunken:
         style = Sunken
     if (frameStyle & QFrame.Raised) == QFrame.Raised:
         style = Raised
     if style != Plain and path.elementCount() == 17:
         pathList = [QPainterPath() for _i in range(8)]
         for i in range(4):
             j = i * 4 + 1
             pathList[2 * i].moveTo(
                 path.elementAt(j - 1).x,
                 path.elementAt(j - 1).y)
             pathList[2 * i].cubicTo(
                 path.elementAt(j + 0).x,
                 path.elementAt(j + 0).y,
                 path.elementAt(j + 1).x,
                 path.elementAt(j + 1).y,
                 path.elementAt(j + 2).x,
                 path.elementAt(j + 2).y)
             pathList[2 * i + 1].moveTo(
                 path.elementAt(j + 2).x,
                 path.elementAt(j + 2).y)
             pathList[2 * i + 1].lineTo(
                 path.elementAt(j + 3).x,
                 path.elementAt(j + 3).y)
         c1 = QColor(palette.color(QPalette.Dark))
         c2 = QColor(palette.color(QPalette.Light))
         if style == Raised:
             c1, c2 = c2, c1
         for i in range(5):
             r = pathList[2 * i].controlPointRect()
             arcPen = QPen()
             arcPen.setCapStyle(Qt.FlatCap)
             arcPen.setWidth(lineWidth)
             linePen = QPen()
             linePen.setCapStyle(Qt.FlatCap)
             linePen.setWidth(lineWidth)
             if i == 0:
                 arcPen.setColor(c1)
                 linePen.setColor(c1)
             elif i == 1:
                 gradient = QLinearGradient()
                 gradient.setStart(r.topLeft())
                 gradient.setFinalStop(r.bottomRight())
                 gradient.setColorAt(0., c1)
                 gradient.setColorAt(1., c2)
                 arcPen.setBrush(gradient)
                 linePen.setColor(c2)
             elif i == 2:
                 arcPen.setColor(c2)
                 linePen.setColor(c2)
             elif i == 3:
                 gradient = QLinearGradient()
                 gradient.setStart(r.bottomRight())
                 gradient.setFinalStop(r.topLeft())
                 gradient.setColorAt(0., c2)
                 gradient.setColorAt(1., c1)
                 arcPen.setBrush(gradient)
                 linePen.setColor(c1)
             painter.setPen(arcPen)
             painter.drawPath(pathList[2 * i])
             painter.setPen(linePen)
             painter.drawPath(pathList[2 * i + 1])
     else:
         pen = QPen(palette.color(QPalette.WindowText), lineWidth)
         painter.setPen(pen)
         painter.drawPath(path)
     painter.restore()