Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
 def drawFrame(self, painter, rect, palette, foregroundRole,
               frameWidth, midLineWidth, frameStyle):
     if frameWidth <= 0 or rect.isEmpty():
         return
     shadow = frameStyle & QFrame.Shadow_Mask
     painter.save()
     if shadow == QFrame.Plain:
         outerRect = rect.adjusted(0., 0., -1., -1.)
         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., -1., -1.)
             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., -1., -1.)
             innerRect = outerRect.adjusted(frameWidth-1., frameWidth-1.,
                                        -(frameWidth-1.), -(frameWidth-1.))
             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()
Ejemplo n.º 6
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., -1., -1.)
         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., -1., -1.)
             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., -1., -1.)
             innerRect = outerRect.adjusted(frameWidth-1., frameWidth-1.,
                                        -(frameWidth-1.), -(frameWidth-1.))
             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()
Ejemplo n.º 7
0
 def drawFrame(self, painter, rect, palette, foregroundRole, frameWidth,
               midLineWidth, frameStyle):
     if frameWidth <= 0 or rect.isEmpty():
         return
     shadow = frameStyle & QFrame.Shadow_Mask
     painter.save()
     if shadow == QFrame.Plain:
         outerRect = rect.adjusted(0., 0., -1., -1.)
         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., -1., -1.)
             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., -1., -1.)
             innerRect = outerRect.adjusted(frameWidth - 1.,
                                            frameWidth - 1.,
                                            -(frameWidth - 1.),
                                            -(frameWidth - 1.))
             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()
Ejemplo n.º 8
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., -1., -1.)
         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., -1., -1.)
             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., -1., -1.)
             innerRect = outerRect.adjusted(frameWidth - 1.,
                                            frameWidth - 1.,
                                            -(frameWidth - 1.),
                                            -(frameWidth - 1.))
             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()