示例#1
0
    def borderPath(self, rect):
        """
        Calculate the painter path for a styled or rounded border

        When the canvas has no styled background or rounded borders
        the painter path is empty.

        :param QRect rect: Bounding rectangle of the canvas
        :return: Painter path, that can be used for clipping
        """
        if self.testAttribute(Qt.WA_StyledBackground):
            recorder = QwtStyleSheetRecorder(rect.size())
            painter = QPainter(recorder)
            opt = QStyleOption()
            opt.initFrom(self)
            opt.rect = rect
            self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
            painter.end()
            if not recorder.background.path.isEmpty():
                return recorder.background.path
            if not recorder.border.rectList.isEmpty():
                return qwtCombinePathList(rect, recorder.border.pathlist)
        elif self.__data.borderRadius > 0.:
            fw2 = self.frameWidth()*.5
            r = QRectF(rect).adjusted(fw2, fw2, -fw2, -fw2)
            path = QPainterPath()
            path.addRoundedRect(r, self.__data.borderRadius,
                                self.__data.borderRadius)
            return path
        return QPainterPath()
示例#2
0
    def borderPath(self, rect):
        """
        Calculate the painter path for a styled or rounded border

        When the canvas has no styled background or rounded borders
        the painter path is empty.

        :param QRect rect: Bounding rectangle of the canvas
        :return: Painter path, that can be used for clipping
        """
        if self.testAttribute(Qt.WA_StyledBackground):
            recorder = QwtStyleSheetRecorder(rect.size())
            painter = QPainter(recorder)
            opt = QStyleOption()
            opt.initFrom(self)
            opt.rect = rect
            self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
            painter.end()
            if not recorder.background.path.isEmpty():
                return recorder.background.path
            if not recorder.border.rectList.isEmpty():
                return qwtCombinePathList(rect, recorder.border.pathlist)
        elif self.__data.borderRadius > 0.:
            fw2 = self.frameWidth() * .5
            r = QRectF(rect).adjusted(fw2, fw2, -fw2, -fw2)
            path = QPainterPath()
            path.addRoundedRect(r, self.__data.borderRadius,
                                self.__data.borderRadius)
            return path
        return QPainterPath()
示例#3
0
 def paintEvent(self, event):
     painter = QPainter(self)
     painter.setClipRegion(event.region())
     if self.testPaintAttribute(self.BackingStore) and\
        self.__data.backingStore is not None:
         bs = self.__data.backingStore
         if bs.size() != self.size():
             bs = QwtPainter.backingStore(self, self.size())
             if self.testAttribute(Qt.WA_StyledBackground):
                 p = QPainter(bs)
                 qwtFillBackground(p, self)
                 self.drawCanvas(p, True)
             else:
                 p = QPainter()
                 if self.__data.borderRadius <= 0.:
                     #                        print('**DEBUG: QwtPlotCanvas.paintEvent')
                     QwtPainter.fillPixmap(self, bs)
                     p.begin(bs)
                     self.drawCanvas(p, False)
                 else:
                     p.begin(bs)
                     qwtFillBackground(p, self)
                     self.drawCanvas(p, True)
                 if self.frameWidth() > 0:
                     self.drawBorder(p)
                 p.end()
         painter.drawPixmap(0, 0, self.__data.backingStore)
     else:
         if self.testAttribute(Qt.WA_StyledBackground):
             if self.testAttribute(Qt.WA_OpaquePaintEvent):
                 qwtFillBackground(painter, self)
                 self.drawCanvas(painter, True)
             else:
                 self.drawCanvas(painter, False)
         else:
             if self.testAttribute(Qt.WA_OpaquePaintEvent):
                 if self.autoFillBackground():
                     qwtFillBackground(painter, self)
                     qwtDrawBackground(painter, self)
             else:
                 if self.borderRadius() > 0.:
                     clipPath = QPainterPath()
                     clipPath.addRect(self.rect())
                     clipPath = clipPath.subtracted(
                         self.borderPath(self.rect()))
                     painter.save()
                     painter.setClipPath(clipPath, Qt.IntersectClip)
                     qwtFillBackground(painter, self)
                     qwtDrawBackground(painter, self)
                     painter.restore()
             self.drawCanvas(painter, False)
             if self.frameWidth() > 0:
                 self.drawBorder(painter)
     if self.hasFocus() and self.focusIndicator(
     ) == self.CanvasFocusIndicator:
         self.drawFocusIndicator(painter)
示例#4
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setClipRegion(event.region())
        if self.testPaintAttribute(self.BackingStore) and\
           self.__data.backingStore is not None:
            bs = self.__data.backingStore
            if bs.size() != self.size():
                bs = QwtPainter.backingStore(self, self.size())
                if self.testAttribute(Qt.WA_StyledBackground):
                    p = QPainter(bs)
                    qwtFillBackground(p, self)
                    self.drawCanvas(p, True)
                else:
                    p = QPainter()
                    if self.__data.borderRadius <= 0.:
#                        print('**DEBUG: QwtPlotCanvas.paintEvent')
                        QwtPainter.fillPixmap(self, bs)
                        p.begin(bs)
                        self.drawCanvas(p, False)
                    else:
                        p.begin(bs)
                        qwtFillBackground(p, self)
                        self.drawCanvas(p, True)
                    if self.frameWidth() > 0:
                        self.drawBorder(p)
                    p.end()
            painter.drawPixmap(0, 0, self.__data.backingStore)
        else:
            if self.testAttribute(Qt.WA_StyledBackground):
                if self.testAttribute(Qt.WA_OpaquePaintEvent):
                    qwtFillBackground(painter, self)
                    self.drawCanvas(painter, True)
                else:
                    self.drawCanvas(painter, False)
            else:
                if self.testAttribute(Qt.WA_OpaquePaintEvent):
                    if self.autoFillBackground():
                        qwtFillBackground(painter, self)
                        qwtDrawBackground(painter, self)
                else:
                    if self.borderRadius() > 0.:
                        clipPath = QPainterPath()
                        clipPath.addRect(self.rect())
                        clipPath = clipPath.subtracted(self.borderPath(self.rect()))
                        painter.save()
                        painter.setClipPath(clipPath, Qt.IntersectClip)
                        qwtFillBackground(painter, self)
                        qwtDrawBackground(painter, self)
                        painter.restore()
                self.drawCanvas(painter, False)
                if self.frameWidth() > 0:
                    self.drawBorder(painter)
        if self.hasFocus() and self.focusIndicator() == self.CanvasFocusIndicator:
            self.drawFocusIndicator(painter)
示例#5
0
 def copy(self, other):
     self.__type = other.__type
     if other.__type == self.Path:
         self.__path = QPainterPath(other.__path)
     elif other.__type == self.Pixmap:
         self.__pixmapData = PixmapData(other.__pixmapData)
     elif other.__type == self.Image:
         self.__imageData = ImageData(other.__imageData)
     elif other.__type == self.State:
         self.__stateData == StateData(other.__stateData)
示例#6
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
示例#7
0
 def borderPath(self, rect):
     if self.testAttribute(Qt.WA_StyledBackground):
         recorder = QwtStyleSheetRecorder(rect.size())
         painter = QPainter(recorder)
         opt = QStyleOption()
         opt.initFrom(self)
         opt.rect = rect
         self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
         painter.end()
         if not recorder.background.path.isEmpty():
             return recorder.background.path
         if not recorder.border.rectList.isEmpty():
             return qwtCombinePathList(rect, recorder.border.pathlist)
     elif self.__data.borderRadius > 0.:
         fw2 = self.frameWidth()*.5
         r = QRectF(rect).adjusted(fw2, fw2, -fw2, -fw2)
         path = QPainterPath()
         path.addRoundedRect(r, self.__data.borderRadius,
                             self.__data.borderRadius)
         return path
     return QPainterPath()
示例#8
0
 def borderPath(self, rect):
     if self.testAttribute(Qt.WA_StyledBackground):
         recorder = QwtStyleSheetRecorder(rect.size())
         painter = QPainter(recorder)
         opt = QStyleOption()
         opt.initFrom(self)
         opt.rect = rect
         self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
         painter.end()
         if not recorder.background.path.isEmpty():
             return recorder.background.path
         if not recorder.border.rectList.isEmpty():
             return qwtCombinePathList(rect, recorder.border.pathlist)
     elif self.__data.borderRadius > 0.:
         fw2 = self.frameWidth() * .5
         r = QRectF(rect).adjusted(fw2, fw2, -fw2, -fw2)
         path = QPainterPath()
         path.addRoundedRect(r, self.__data.borderRadius,
                             self.__data.borderRadius)
         return path
     return QPainterPath()
 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)
示例#10
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)
示例#11
0
 def __init__(self):
     self.hasBorder = False
     self.borderPath = QPainterPath()
     self.cornerRects = []
     self.background = StyleSheetBackground()
示例#12
0
 def __init__(self):
     self.path = QPainterPath()
     self.brush = QBrush()
     self.origin = QPointF()
示例#13
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
示例#14
0
    def renderCanvas(self, plot, painter, canvasRect, maps):
        """
        Render the canvas into a given rectangle.

        :param qwt.plot.QwtPlot plot: Plot widget
        :param QPainter painter: Painter
        :param qwt.scale_map.QwtScaleMap maps: mapping between plot and paint device coordinates
        :param QRectF rect: Bounding rectangle
        """
        canvas = plot.canvas()
        r = canvasRect.adjusted(0., 0., -1., 1.)
        if self.__data.layoutFlags & self.FrameWithScales:
            painter.save()
            r.adjust(-1., -1., 1., 1.)
            painter.setPen(QPen(Qt.black))
            if not (self.__data.discardFlags & self.DiscardCanvasBackground):
                bgBrush = canvas.palette().brush(plot.backgroundRole())
                painter.setBrush(bgBrush)
            QwtPainter.drawRect(painter, r)
            painter.restore()
            painter.save()
            painter.setClipRect(canvasRect)
            plot.drawItems(painter, canvasRect, maps)
            painter.restore()
        elif canvas.testAttribute(Qt.WA_StyledBackground):
            clipPath = QPainterPath()
            painter.save()
            if not self.__data.discardFlags & self.DiscardCanvasBackground:
                QwtPainter.drawBackground(painter, r, canvas)
                clipPath = qwtCanvasClip(canvas, canvasRect)
            painter.restore()
            painter.save()
            if clipPath.isEmpty():
                painter.setClipRect(canvasRect)
            else:
                painter.setClipPath(clipPath)
            plot.drawItems(painter, canvasRect, maps)
            painter.restore()
        else:
            clipPath = QPainterPath()
            frameWidth = 0
            if not self.__data.discardFlags & self.DiscardCanvasFrame:
                frameWidth = canvas.frameWidth()
                clipPath = qwtCanvasClip(canvas, canvasRect)
            innerRect = canvasRect.adjusted(frameWidth, frameWidth,
                                            -frameWidth, -frameWidth)
            painter.save()
            if clipPath.isEmpty():
                painter.setClipRect(innerRect)
            else:
                painter.setClipPath(clipPath)
            if not self.__data.discardFlags & self.DiscardCanvasBackground:
                QwtPainter.drawBackground(painter, innerRect, canvas)
            plot.drawItems(painter, innerRect, maps)
            painter.restore()
            if frameWidth > 0:
                painter.save()
                frameStyle = canvas.frameShadow() | canvas.frameShape()
                frameWidth = canvas.frameWidth()
                borderRadius = canvas.borderRadius()
                if borderRadius > 0.:
                    QwtPainter.drawRoundedFrame(painter, canvasRect, r, r,
                                                canvas.palette(), frameWidth,
                                                frameStyle)
                else:
                    midLineWidth = canvas.midLineWidth()
                    QwtPainter.drawFrame(painter, canvasRect, canvas.palette(),
                                         canvas.foregroundRole(), frameWidth,
                                         midLineWidth, frameStyle)
                painter.restore()
示例#15
0
    def renderCanvas(self, plot, painter, canvasRect, maps):
        """
        Render the canvas into a given rectangle.

        :param qwt.plot.QwtPlot plot: Plot widget
        :param QPainter painter: Painter
        :param qwt.scale_map.QwtScaleMap maps: mapping between plot and paint device coordinates
        :param QRectF rect: Bounding rectangle
        """
        canvas = plot.canvas()
        r = canvasRect.adjusted(0., 0., -1., 1.)
        if self.__data.layoutFlags & self.FrameWithScales:
            painter.save()
            r.adjust(-1., -1., 1., 1.)
            painter.setPen(QPen(Qt.black))
            if not (self.__data.discardFlags & self.DiscardCanvasBackground):
                bgBrush = canvas.palette().brush(plot.backgroundRole())
                painter.setBrush(bgBrush)
            painter.drawRect(r)
            painter.restore()
            painter.save()
            painter.setClipRect(canvasRect)
            plot.drawItems(painter, canvasRect, maps)
            painter.restore()
        elif canvas.testAttribute(Qt.WA_StyledBackground):
            clipPath = QPainterPath()
            painter.save()
            if not self.__data.discardFlags & self.DiscardCanvasBackground:
                QwtPainter.drawBackground(painter, r, canvas)
                clipPath = qwtCanvasClip(canvas, canvasRect)
            painter.restore()
            painter.save()
            if clipPath.isEmpty():
                painter.setClipRect(canvasRect)
            else:
                painter.setClipPath(clipPath)
            plot.drawItems(painter, canvasRect, maps)
            painter.restore()
        else:
            clipPath = QPainterPath()
            frameWidth = 0
            if not self.__data.discardFlags & self.DiscardCanvasFrame:
                frameWidth = canvas.frameWidth()
                clipPath = qwtCanvasClip(canvas, canvasRect)
            innerRect = canvasRect.adjusted(frameWidth, frameWidth,
                                            -frameWidth, -frameWidth)
            painter.save()
            if clipPath.isEmpty():
                painter.setClipRect(innerRect)
            else:
                painter.setClipPath(clipPath)
            if not self.__data.discardFlags & self.DiscardCanvasBackground:
                QwtPainter.drawBackground(painter, innerRect, canvas)
            plot.drawItems(painter, innerRect, maps)
            painter.restore()
            if frameWidth > 0:
                painter.save()
                frameStyle = canvas.frameShadow() | canvas.frameShape()
                frameWidth = canvas.frameWidth()
                borderRadius = canvas.borderRadius()
                if borderRadius > 0.:
                    QwtPainter.drawRoundedFrame(painter, canvasRect, r, r,
                                                canvas.palette(), frameWidth,
                                                frameStyle)
                else:
                    midLineWidth = canvas.midLineWidth()
                    QwtPainter.drawFrame(painter, canvasRect, canvas.palette(),
                                         canvas.foregroundRole(), frameWidth,
                                         midLineWidth, frameStyle)
                painter.restore()
示例#16
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()
示例#17
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()
示例#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()
示例#19
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()
示例#20
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()
示例#21
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()
示例#22
0
 def renderCanvas(self, plot, painter, canvasRect, maps):
     canvas = plot.canvas()
     r = canvasRect.adjusted(0., 0., -1., 1.)
     if self.__data.layoutFlags & self.FrameWithScales:
         painter.save()
         r.adjust(-1., -1., 1., 1.)
         painter.setPen(QPen(Qt.black))
         if not (self.__data.discardFlags & self.DiscardCanvasBackground):
             bgBrush = canvas.palette().brush(plot.backgroundRole())
             painter.setBrush(bgBrush)
         QwtPainter.drawRect(painter, r)
         painter.restore()
         painter.save()
         painter.setClipRect(canvasRect)
         plot.drawItems(painter, canvasRect, maps)
         painter.restore()
     elif canvas.testAttribute(Qt.WA_StyledBackground):
         clipPath = QPainterPath()
         painter.save()
         if not self.__data.discardFlags & self.DiscardCanvasBackground:
             QwtPainter.drawBackground(painter, r, canvas)
             clipPath = qwtCanvasClip(canvas, canvasRect)
         painter.restore()
         painter.save()
         if clipPath.isEmpty():
             painter.setClipRect(canvasRect)
         else:
             painter.setClipPath(clipPath)
         plot.drawItems(painter, canvasRect, maps)
         painter.restore()
     else:
         clipPath = QPainterPath()
         frameWidth = 0
         if not self.__data.discardFlags & self.DiscardCanvasFrame:
             frameWidth = canvas.frameWidth()
             clipPath = qwtCanvasClip(canvas, canvasRect)
         innerRect = canvasRect.adjusted(frameWidth, frameWidth,
                                         -frameWidth, -frameWidth)
         painter.save()
         if clipPath.isEmpty():
             painter.setClipRect(innerRect)
         else:
             painter.setClipPath(clipPath)
         if not self.__data.discardFlags & self.DiscardCanvasBackground:
             QwtPainter.drawBackground(painter, innerRect, canvas)
         plot.drawItems(painter, innerRect, maps)
         painter.restore()
         if frameWidth > 0:
             painter.save()
             frameStyle = canvas.frameShadow() | canvas.frameShape()
             frameWidth = canvas.frameWidth()
             borderRadius = canvas.borderRadius()
             if borderRadius > 0.:
                 QwtPainter.drawRoundedFrame(painter, canvasRect, r, r,
                                             canvas.palette(), frameWidth,
                                             frameStyle)
             else:
                 midLineWidth = canvas.midLineWidth()
                 QwtPainter.drawFrame(painter, canvasRect, canvas.palette(),
                                      canvas.foregroundRole(), frameWidth,
                                      midLineWidth, frameStyle)
             painter.restore()
示例#23
0
文件: painter.py 项目: gyenney/Tools
 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()
示例#24
0
 def __init__(self, *args):
     if len(args) == 0:
         self.__type = self.Invalid
     elif len(args) == 1:
         arg, = args
         if isinstance(arg, QPainterPath):
             path = arg
             self.__type = self.Path
             self.__path = QPainterPath(path)
         elif isinstance(arg, QwtPainterCommand):
             other = arg
             self.copy(other)
         else:
             state = arg
             self.__type = self.State
             self.__stateData = StateData()
             self.__stateData.flags = state.state()
             if self.__stateData.flags & QPaintEngine.DirtyPen:
                 self.__stateData.pen = state.pen()
             if self.__stateData.flags & QPaintEngine.DirtyBrush:
                 self.__stateData.brush = state.brush()
             if self.__stateData.flags & QPaintEngine.DirtyBrushOrigin:
                 self.__stateData.brushOrigin = state.brushOrigin()
             if self.__stateData.flags & QPaintEngine.DirtyFont:
                 self.__stateData.font = state.font()
             if self.__stateData.flags & QPaintEngine.DirtyBackground:
                 self.__stateData.backgroundMode = state.backgroundMode()
                 self.__stateData.backgroundBrush = state.backgroundBrush()
             if self.__stateData.flags & QPaintEngine.DirtyTransform:
                 self.__stateData.transform = state.transform()
             if self.__stateData.flags & QPaintEngine.DirtyClipEnabled:
                 self.__stateData.isClipEnabled = state.isClipEnabled()
             if self.__stateData.flags & QPaintEngine.DirtyClipRegion:
                 self.__stateData.clipRegion = state.clipRegion()
                 self.__stateData.clipOperation = state.clipOperation()
             if self.__stateData.flags & QPaintEngine.DirtyClipPath:
                 self.__stateData.clipPath = state.clipPath()
                 self.__stateData.clipOperation = state.clipOperation()
             if self.__stateData.flags & QPaintEngine.DirtyHints:
                 self.__stateData.renderHints = state.renderHints()
             if self.__stateData.flags & QPaintEngine.DirtyCompositionMode:
                 self.__stateData.compositionMode = state.compositionMode()
             if self.__stateData.flags & QPaintEngine.DirtyOpacity:
                 self.__stateData.opacity = state.opacity()
     elif len(args) == 3:
         rect, pixmap, subRect = args
         self.__type = self.Pixmap
         self.__pixmapData = PixmapData()
         self.__pixmapData.rect = rect
         self.__pixmapData.pixmap = pixmap
         self.__pixmapData.subRect = subRect
     elif len(args) == 4:
         rect, image, subRect, flags = args
         self.__type = self.Image
         self.__imageData = ImageData()
         self.__imageData.rect = rect
         self.__imageData.image = image
         self.__imageData.subRect = subRect
         self.__imageData.flags = flags
     else:
         raise TypeError("%s() takes 0, 1, 3 or 4 argument(s) (%s given)"\
                         % (self.__class__.__name__, len(args)))
示例#25
0
文件: symbol.py 项目: gyenney/Tools
 def __init__(self):
     self.path = QPainterPath()
     self.graphic = QwtGraphic()
示例#26
0
 def renderCanvas(self, plot, painter, canvasRect, maps):
     canvas = plot.canvas()
     r = canvasRect.adjusted(0., 0., -1., 1.)
     if self.__data.layoutFlags & self.FrameWithScales:
         painter.save()
         r.adjust(-1., -1., 1., 1.)
         painter.setPen(QPen(Qt.black))
         if not (self.__data.discardFlags & self.DiscardCanvasBackground):
             bgBrush = canvas.palette().brush(plot.backgroundRole())
             painter.setBrush(bgBrush)
         QwtPainter.drawRect(painter, r)
         painter.restore()
         painter.save()
         painter.setClipRect(canvasRect)
         plot.drawItems(painter, canvasRect, maps)
         painter.restore()
     elif canvas.testAttribute(Qt.WA_StyledBackground):
         clipPath = QPainterPath()
         painter.save()
         if not self.__data.discardFlags & self.DiscardCanvasBackground:
             QwtPainter.drawBackground(painter, r, canvas)
             clipPath = qwtCanvasClip(canvas, canvasRect)
         painter.restore()
         painter.save()
         if clipPath.isEmpty():
             painter.setClipRect(canvasRect)
         else:
             painter.setClipPath(clipPath)
         plot.drawItems(painter, canvasRect, maps)
         painter.restore()
     else:
         clipPath = QPainterPath()
         frameWidth = 0
         if not self.__data.discardFlags & self.DiscardCanvasFrame:
             frameWidth = canvas.frameWidth()
             clipPath = qwtCanvasClip(canvas, canvasRect)
         innerRect = canvasRect.adjusted(frameWidth, frameWidth,
                                         -frameWidth, -frameWidth)
         painter.save()
         if clipPath.isEmpty():
             painter.setClipRect(innerRect)
         else:
             painter.setClipPath(clipPath)
         if not self.__data.discardFlags & self.DiscardCanvasBackground:
             QwtPainter.drawBackground(painter, innerRect, canvas)
         plot.drawItems(painter, innerRect, maps)
         painter.restore()
         if frameWidth > 0:
             painter.save()
             frameStyle = canvas.frameShadow() | canvas.frameShape()
             frameWidth = canvas.frameWidth()
             borderRadius = canvas.borderRadius()
             if borderRadius > 0.:
                 QwtPainter.drawRoundedFrame(painter, canvasRect, r, r,
                                             canvas.palette(), frameWidth,
                                             frameStyle)
             else:
                 midLineWidth = canvas.midLineWidth()
                 QwtPainter.drawFrame(painter, canvasRect, canvas.palette(),
                                      canvas.foregroundRole(), frameWidth,
                                      midLineWidth, frameStyle)
             painter.restore()
示例#27
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()