Ejemplo n.º 1
0
 def drawRoundFrame(self, painter, rect, palette, lineWidth, frameStyle):
     """
     Draw a round frame
     
     :param QPainter painter: Painter
     :param QRectF rect: Target rectangle
     :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`
     """
     Plain, Sunken, Raised = list(range(3))
     style = Plain
     if (frameStyle & QFrame.Sunken) == QFrame.Sunken:
         style = Sunken
     elif (frameStyle & QFrame.Raised) == QFrame.Raised:
         style = Raised
     lw2 = .5*lineWidth
     r = rect.adjusted(lw2, lw2, -lw2, -lw2)
     if style != Plain:
         c1 = palette.color(QPalette.Light)
         c2 = palette.color(QPalette.Dark)
         if style == Sunken:
             c1, c2 = c2, c1
         gradient = QLinearGradient(r.topLeft(), r.bottomRight())
         gradient.setColorAt(0., c1)
         gradient.setColorAt(1., c2)
         brush = QBrush(gradient)
     else:
         brush = palette.brush(QPalette.WindowText)
     painter.save()
     painter.setPen(QPen(brush, lineWidth))
     painter.drawEllipse(r)
     painter.restore()
Ejemplo n.º 2
0
 def drawRoundFrame(self, painter, rect, palette, lineWidth, frameStyle):
     """
     Draw a round frame
     
     :param QPainter painter: Painter
     :param QRectF rect: Target rectangle
     :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`
     """
     Plain, Sunken, Raised = list(range(3))
     style = Plain
     if (frameStyle & QFrame.Sunken) == QFrame.Sunken:
         style = Sunken
     elif (frameStyle & QFrame.Raised) == QFrame.Raised:
         style = Raised
     lw2 = .5 * lineWidth
     r = rect.adjusted(lw2, lw2, -lw2, -lw2)
     if style != Plain:
         c1 = palette.color(QPalette.Light)
         c2 = palette.color(QPalette.Dark)
         if style == Sunken:
             c1, c2 = c2, c1
         gradient = QLinearGradient(r.topLeft(), r.bottomRight())
         gradient.setColorAt(0., c1)
         gradient.setColorAt(1., c2)
         brush = QBrush(gradient)
     else:
         brush = palette.brush(QPalette.WindowText)
     painter.save()
     painter.setPen(QPen(brush, lineWidth))
     painter.drawEllipse(r)
     painter.restore()
Ejemplo n.º 3
0
 def drawRoundFrame(self, painter, rect, palette, lineWidth, frameStyle):
     Plain, Sunken, Raised = list(range(3))
     style = Plain
     if (frameStyle & QFrame.Sunken) == QFrame.Sunken:
         style = Sunken
     elif (frameStyle & QFrame.Raised) == QFrame.Raised:
         style = Raised
     lw2 = .5*lineWidth
     r = rect.adjusted(lw2, lw2, -lw2, -lw2)
     if style != Plain:
         c1 = palette.color(QPalette.Light)
         c2 = palette.color(QPalette.Dark)
         if style == Sunken:
             c1, c2 = c2, c1
         gradient = QLinearGradient(r.topLeft(), r.bottomRight())
         gradient.setColorAt(0., c1)
         gradient.setColorAt(1., c2)
         brush = QBrush(gradient)
     else:
         brush = palette.brush(QPalette.WindowText)
     painter.save()
     painter.setPen(QPen(brush, lineWidth))
     painter.drawEllipse(r)
     painter.restore()
Ejemplo n.º 4
0
 def drawRoundFrame(self, painter, rect, palette, lineWidth, frameStyle):
     Plain, Sunken, Raised = list(range(3))
     style = Plain
     if (frameStyle & QFrame.Sunken) == QFrame.Sunken:
         style = Sunken
     elif (frameStyle & QFrame.Raised) == QFrame.Raised:
         style = Raised
     lw2 = .5 * lineWidth
     r = rect.adjusted(lw2, lw2, -lw2, -lw2)
     if style != Plain:
         c1 = palette.color(QPalette.Light)
         c2 = palette.color(QPalette.Dark)
         if style == Sunken:
             c1, c2 = c2, c1
         gradient = QLinearGradient(r.topLeft(), r.bottomRight())
         gradient.setColorAt(0., c1)
         gradient.setColorAt(1., c2)
         brush = QBrush(gradient)
     else:
         brush = palette.brush(QPalette.WindowText)
     painter.save()
     painter.setPen(QPen(brush, lineWidth))
     painter.drawEllipse(r)
     painter.restore()
Ejemplo n.º 5
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()
Ejemplo n.º 6
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()
Ejemplo n.º 7
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()
Ejemplo n.º 8
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()