Exemplo n.º 1
0
 def paintEvent(self, QPaintEvent):
     p = QPainter(self)
     r = self.rect()
     p.setPen(self.pen)
     if (self.sd.style == QGradient.LinearGradient):
         linearGradient = QLinearGradient(self.startPoint, self.endPoint)
         linearGradient.setColorAt(0.0, self.sd.startColor)
         linearGradient.setColorAt(1.0, self.sd.endColor)
         linearGradient.setSpread(self.sd.spread)
         p.setBrush(linearGradient)
     elif (self.sd.style == QGradient.RadialGradient):
         rr = math.sqrt(
             math.pow(self.endPoint.x() - self.startPoint.x(), 2) + math.pow(self.endPoint.y() - self.startPoint.y(),
                                                                             2))
         radialGradient = QRadialGradient(self.startPoint, rr, self.startPoint)
         radialGradient.setColorAt(0.0, self.sd.startColor)
         radialGradient.setColorAt(1.0, self.sd.endColor)
         radialGradient.setSpread(self.sd.spread)
         p.setBrush(radialGradient)
     elif (self.sd.style == QGradient.ConicalGradient):
         angle = math.atan2(self.endPoint.y() - self.startPoint.y(), self.endPoint.x() - self.startPoint.x())
         conicalGradient = QConicalGradient(self.startPoint, -(180 * angle) / math.pi)
         conicalGradient.setColorAt(0.0, self.sd.startColor)
         conicalGradient.setColorAt(1.0, self.sd.endColor)
         p.setBrush(conicalGradient)
         p.drawRect(r)
Exemplo n.º 2
0
    def paintEvent(self, event):

        background = QRadialGradient(QPointF(self.rect().topLeft()), 500,
                                     QPointF(self.rect().bottomRight()))
        background.setColorAt(0, self.backgroundColor1)
        background.setColorAt(1, self.backgroundColor2)

        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.fillRect(event.rect(), QBrush(background))

        painter.setPen(self.pen)

        for bubble in self.bubbles:

            if QRectF(bubble.position - QPointF(bubble.radius, bubble.radius),
                      QSizeF(2 * bubble.radius, 2 * bubble.radius)).intersects(
                          QRectF(event.rect())):
                bubble.drawBubble(painter)

        if self.newBubble:

            self.newBubble.drawBubble(painter)

        painter.end()
    def drawTarget(self):
        if self.target == None:
            return

        x = self.target.x
        y = self.target.y
        width = self.target.width
        height = self.target.height

        # prepare drawing
        painter = QPainter(self.targetPixmap)

        if self.target.visualForm == 'red_dot' or self.target.visualForm == 'dot+head':
            radialGrad = QRadialGradient(QPoint(x, y), max(width, height) / 2)
            radialGrad.setColorAt(0, self.target.color)
            radialGrad.setColorAt(1, Qt.white)

            targetBrush = QBrush(radialGrad)
            targetPen = QPen(Qt.transparent, 0, Qt.SolidLine)
            painter.setPen(targetPen)

            painter.setBrush(targetBrush)
            painter.drawEllipse(x - width / 2, y - height / 2, width, height)

        if self.target.visualForm == 'nao_head' or self.target.visualForm == 'dot+head':
            painter.drawPixmap(x - NAO_HEAD_SIZE / 2, y - NAO_HEAD_SIZE / 2,
                               self.naoPixmap)

        painter.end()

        self.viewport().update()
Exemplo n.º 4
0
    def __paintRound(self):
        """
        Private method to paint a round raised LED.
        """
        # Initialize coordinates, width and height of the LED
        width = self.__getBestRoundSize()

        # Calculate the gradient for the LED
        wh = width / 2
        color = self.__led_on and self.__led_color or self.__offcolor
        gradient = QRadialGradient(wh, wh, wh, 0.8 * wh, 0.8 * wh)
        gradient.setColorAt(0.0, color.lighter(200))
        gradient.setColorAt(0.6, color)
        if self.__framedLed:
            gradient.setColorAt(0.9, color.darker())
            gradient.setColorAt(1.0, self.palette().color(QPalette.Dark))
        else:
            gradient.setColorAt(1.0, color.darker())

        # now do the drawing
        paint = QPainter(self)
        paint.setRenderHint(QPainter.Antialiasing, True)
        paint.setBrush(QBrush(gradient))
        paint.setPen(Qt.NoPen)
        paint.drawEllipse(1, 1, width, width)
        paint.end()
    def paintEvent(self, evt):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setPen(QPen(Qt.black, 1))

        realSize = min(self.width(), self.height())  # 窗口的短边
        painter.translate(self.width() / 2.0, self.height() / 2.0)  # 原点平移到窗口中心
        painter.scale(realSize / self.scaledSize, realSize / self.scaledSize)  # 缩放,窗口的短边值映射为self.scaledSize
        gradient = QRadialGradient(QPointF(0, 0), self.scaledSize / 2.0, QPointF(0, 0))  # 辐射渐变

        # 画边框外圈和内圈
        for color, radius in [(self.colorBorderOut, self.radiusBorderOut),  # 边框外圈
                              (self.colorBorderIn, self.radiusBorderIn)]:  # 边框内圈
            gradient.setColorAt(1, color)
            painter.setBrush(QBrush(gradient))
            painter.drawEllipse(QPointF(0, 0), radius, radius)

        # 画内圆
        if self.state == 'off':
            gradient.setColorAt(0, self.colorOffBegin)
            gradient.setColorAt(1, self.colorOffEnd)
        else:
            gradient.setColorAt(0, self.colorOnBegin)
            gradient.setColorAt(1, self.colorOnEnd)

        painter.setBrush(QBrush(gradient))
        painter.drawEllipse(QPointF(0, 0), self.radiusCircle, self.radiusCircle)
Exemplo n.º 6
0
 def __paintRound(self):
     """
     Private method to paint a round raised LED.
     """
     # Initialize coordinates, width and height of the LED
     width = self.__getBestRoundSize()
     
     # Calculate the gradient for the LED
     wh = width / 2
     color = self.__led_on and self.__led_color or self.__offcolor
     gradient = QRadialGradient(wh, wh, wh, 0.8 * wh, 0.8 * wh)
     gradient.setColorAt(0.0, color.lighter(200))
     gradient.setColorAt(0.6, color)
     if self.__framedLed:
         gradient.setColorAt(0.9, color.darker())
         gradient.setColorAt(1.0, self.palette().color(QPalette.Dark))
     else:
         gradient.setColorAt(1.0, color.darker())
     
     # now do the drawing
     paint = QPainter(self)
     paint.setRenderHint(QPainter.Antialiasing, True)
     paint.setBrush(QBrush(gradient))
     paint.setPen(Qt.NoPen)
     paint.drawEllipse(1, 1, width, width)
     paint.end()
Exemplo n.º 7
0
    def slotBrush(self, value):
        color = self.brushColorFrame.palette().color(QPalette.Window)
        style = Qt.BrushStyle(
            self.brushStyleComboBox.itemData(value, Qt.UserRole))

        if (style == Qt.LinearGradientPattern):
            linearGradient = QLinearGradient(0, 0, 400, 400)
            linearGradient.setColorAt(0.0, Qt.white)
            linearGradient.setColorAt(0.2, color)
            linearGradient.setColorAt(1.0, Qt.black)
            self.area.setBrush(linearGradient)
        elif style == Qt.RadialGradientPattern:
            radialGradient = QRadialGradient(200, 200, 80, 70, 70)
            radialGradient.setColorAt(0.0, Qt.white)
            radialGradient.setColorAt(0.2, Qt.green)
            radialGradient.setColorAt(1.0, Qt.black)
            self.area.setBrush(radialGradient)
        elif (style == Qt.ConicalGradientPattern):
            conicalGradient = QConicalGradient(200, 200, 30)
            conicalGradient.setColorAt(0.0, Qt.white)
            conicalGradient.setColorAt(0.2, color)
            conicalGradient.setColorAt(1.0, Qt.black)
            self.area.setBrush(conicalGradient)
        elif (style == Qt.TexturePattern):
            self.area.setBrush(QBrush(QPixmap("images/brick.png")))
        else:
            self.area.setBrush(QBrush(color, style))
Exemplo n.º 8
0
    def paintEvent(self, event):

        background = QRadialGradient(QPointF(self.rect().topLeft()), 500,
                QPointF(self.rect().bottomRight()))
        background.setColorAt(0, self.backgroundColor1)
        background.setColorAt(1, self.backgroundColor2)

        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.fillRect(event.rect(), QBrush(background))

        painter.setPen(self.pen)

        for bubble in self.bubbles:

            if QRectF(bubble.position - QPointF(bubble.radius, bubble.radius),
                      QSizeF(2*bubble.radius, 2*bubble.radius)).intersects(QRectF(event.rect())):
                bubble.drawBubble(painter)

        if self.newBubble:

            self.newBubble.drawBubble(painter)

        painter.end()
Exemplo n.º 9
0
    def brushChanged(self):
        style = Qt.BrushStyle(self.brushStyleComboBox.itemData(
                self.brushStyleComboBox.currentIndex(), IdRole))

        if style == Qt.LinearGradientPattern:
            linearGradient = QLinearGradient(0, 0, 100, 100)
            linearGradient.setColorAt(0.0, Qt.white)
            linearGradient.setColorAt(0.2, Qt.green)
            linearGradient.setColorAt(1.0, Qt.black)
            self.renderArea.setBrush(QBrush(linearGradient))
        elif style == Qt.RadialGradientPattern:
            radialGradient = QRadialGradient(50, 50, 50, 70, 70)
            radialGradient.setColorAt(0.0, Qt.white)
            radialGradient.setColorAt(0.2, Qt.green)
            radialGradient.setColorAt(1.0, Qt.black)
            self.renderArea.setBrush(QBrush(radialGradient))
        elif style == Qt.ConicalGradientPattern:
            conicalGradient = QConicalGradient(50, 50, 150)
            conicalGradient.setColorAt(0.0, Qt.white)
            conicalGradient.setColorAt(0.2, Qt.green)
            conicalGradient.setColorAt(1.0, Qt.black)
            self.renderArea.setBrush(QBrush(conicalGradient))
        elif style == Qt.TexturePattern:
            self.renderArea.setBrush(QBrush(QPixmap(':/images/brick.png')))
        else:
            self.renderArea.setBrush(QBrush(Qt.green, style))
Exemplo n.º 10
0
    def brushChanged(self):
        style = Qt.BrushStyle(
            self.brushStyleComboBox.itemData(
                self.brushStyleComboBox.currentIndex(), IdRole))

        if style == Qt.LinearGradientPattern:
            linearGradient = QLinearGradient(0, 0, 100, 100)
            linearGradient.setColorAt(0.0, Qt.white)
            linearGradient.setColorAt(0.2, Qt.green)
            linearGradient.setColorAt(1.0, Qt.black)
            self.renderArea.setBrush(QBrush(linearGradient))
        elif style == Qt.RadialGradientPattern:
            radialGradient = QRadialGradient(50, 50, 50, 70, 70)
            radialGradient.setColorAt(0.0, Qt.white)
            radialGradient.setColorAt(0.2, Qt.green)
            radialGradient.setColorAt(1.0, Qt.black)
            self.renderArea.setBrush(QBrush(radialGradient))
        elif style == Qt.ConicalGradientPattern:
            conicalGradient = QConicalGradient(50, 50, 150)
            conicalGradient.setColorAt(0.0, Qt.white)
            conicalGradient.setColorAt(0.2, Qt.green)
            conicalGradient.setColorAt(1.0, Qt.black)
            self.renderArea.setBrush(QBrush(conicalGradient))
        elif style == Qt.TexturePattern:
            self.renderArea.setBrush(QBrush(QPixmap(":/images/brick.png")))
        else:
            self.renderArea.setBrush(QBrush(Qt.green, style))
Exemplo n.º 11
0
    def paintEvent(self, event):
        super().paintEvent(event)

        painter = QPainter(self)

        size = self.size()
        brush = QBrush()

        smallest_dim = size.width()
        if smallest_dim > size.height():
            smallest_dim = size.height()

        smallest_dim = smallest_dim / 2
        smallest_dim -= 2

        center_x = size.width() / 2
        center_y = size.height() / 2
        centerpoint = QPoint(center_x, center_y)

        radius = smallest_dim

        painter.setPen(QPen(QColor('lightgray'), 0))
        brush.setStyle(Qtc.SolidPattern)

        radial = QRadialGradient(center_x, center_y / 2, radius)
        radial.setColorAt(0, Qtc.white)
        radial.setColorAt(0.8, Qtc.darkGray)
        painter.setBrush(QBrush(radial))
        painter.drawEllipse(centerpoint, radius, radius)

        # Draw the colored center
        radial = QRadialGradient(center_x, center_y / 2, radius)
        radial.setColorAt(0, Qtc.white)

        if self.curState:
            radial.setColorAt(.7, self.on_color)
            brush.setColor(self.on_color)
            painter.setPen(QPen(self.on_color, 0))
        else:
            radial.setColorAt(.7, self.off_color)
            brush.setColor(self.off_color)
            painter.setPen(QPen(self.off_color, 0))

        brush.setStyle(Qtc.SolidPattern)
        painter.setBrush(QBrush(radial))
        if smallest_dim <= 30:
            radius = radius - 3
        elif smallest_dim <= 60:
            radius = radius - 4
        elif smallest_dim <= 100:
            radius = radius - 5
        elif smallest_dim <= 200:
            radius = radius - 6
        elif smallest_dim <= 300:
            radius = radius - 7
        else:
            radius = radius - 9
        painter.drawEllipse(centerpoint, radius, radius)
Exemplo n.º 12
0
    def setupParametricCurveDemo(self):
        self.demoName = "Parametric Curves Demo"

        # create empty curve objects. As they are not adopted by main QCustomPlot an explicit
        # reference must be kept
        self.fermatSpiral1 = QCustomPlot.QCPCurve(self.customPlot.xAxis,
                                                  self.customPlot.yAxis)
        self.fermatSpiral2 = QCustomPlot.QCPCurve(self.customPlot.xAxis,
                                                  self.customPlot.yAxis)
        self.deltoidRadial = QCustomPlot.QCPCurve(self.customPlot.xAxis,
                                                  self.customPlot.yAxis)
        # generate the curve data points:
        pointCount = 501
        dataSpiral1 = [[0.0] * pointCount, [0.0] * pointCount,
                       [0.0] * pointCount]
        dataSpiral2 = [[0.0] * pointCount, [0.0] * pointCount,
                       [0.0] * pointCount]
        dataDeltoid = [[0.0] * pointCount, [0.0] * pointCount,
                       [0.0] * pointCount]
        for i in range(0, pointCount):
            phi = i / (pointCount - 1) * 8 * math.pi
            theta = i / (pointCount - 1) * 2 * math.pi
            dataSpiral1[0][i] = float(i)
            dataSpiral1[1][i] = math.sqrt(phi) * math.cos(phi)
            dataSpiral1[2][i] = math.sqrt(phi) * math.sin(phi)
            dataSpiral2[0][i] = float(i)
            dataSpiral2[1][i] = -dataSpiral1[1][i]
            dataSpiral2[2][i] = -dataSpiral1[2][i]
            dataDeltoid[0][i] = float(i)
            dataDeltoid[1][i] = 2 * math.cos(2 * theta) + math.cos(
                1 * theta) + 2 * math.sin(theta)
            dataDeltoid[2][i] = 2 * math.sin(2 * theta) - math.sin(1 * theta)

        # pass the data to the curves; we know t (i in loop above) is ascending, so set alreadySorted=true (saves an extra internal sort):
        self.fermatSpiral1.setData(dataSpiral1[0], dataSpiral1[1],
                                   dataSpiral1[2], True)
        self.fermatSpiral2.setData(dataSpiral2[0], dataSpiral2[1],
                                   dataSpiral2[2], True)
        self.deltoidRadial.setData(dataDeltoid[0], dataDeltoid[1],
                                   dataDeltoid[2], True)
        # color the curves:
        self.fermatSpiral1.setPen(QPen(Qt.blue))
        self.fermatSpiral1.setBrush(QBrush(QColor(0, 0, 255, 20)))
        self.fermatSpiral2.setPen(QPen(QColor(255, 120, 0)))
        self.fermatSpiral2.setBrush(QBrush(QColor(255, 120, 0, 30)))
        radialGrad = QRadialGradient(QPointF(310, 180), 200)
        radialGrad.setColorAt(0, QColor(170, 20, 240, 100))
        radialGrad.setColorAt(0.5, QColor(20, 10, 255, 40))
        radialGrad.setColorAt(1, QColor(120, 20, 240, 10))
        self.deltoidRadial.setPen(QPen(QColor(170, 20, 240)))
        self.deltoidRadial.setBrush(QBrush(radialGrad))
        # set some basic customPlot config:
        self.customPlot.setInteractions(
            QCustomPlot.QCP.Interactions(QCustomPlot.QCP.iRangeDrag
                                         | QCustomPlot.QCP.iRangeZoom
                                         | QCustomPlot.QCP.iSelectPlottables))
        self.customPlot.axisRect().setupFullAxesBox()
        self.customPlot.rescaleAxes()
Exemplo n.º 13
0
 def point_obj(self):
     p = pg.QtGui.QPainter(self.picture)
     p.setRenderHint(QtGui.QPainter.Antialiasing, True)
     gradient = QRadialGradient(QtCore.QPointF(self.x, self.y), 5)
     gradient.setColorAt(0, QColor('#fc030b'))
     gradient.setColorAt(1, QColor('#9065e0'))
     p.setBrush(gradient)
     p.setPen(QtCore.Qt.NoPen)
     p.drawEllipse(QtCore.QPointF(self.x, self.y), 3, 3)
     p.end()
Exemplo n.º 14
0
 def paint(self, painter, option, widget):
     gradient = QRadialGradient(-3, -3, 10)
     if option.state & QStyle.State_Sunken:
         gradient.setCenter(3, 3)
         gradient.setFocalPoint(3, 3)
         gradient.setColorAt(0, QColor(Qt.yellow).light(120))
     else:
         gradient.setColorAt(0, QColor(Qt.yellow).light(120))
     painter.setBrush(gradient)
     painter.setPen(QPen(Qt.black, 0))
     painter.drawRoundedRect(self.boundingRect(), 3, 3)
Exemplo n.º 15
0
    def drawMagnifierOnVideo(width, height, maskPixmap, dragPos, zoomPixmap, surface, painter, offset):
        ''' Draw Magnifier on Video '''
        dim = min(width, height)
        MAX_MAGNIFIER = 229
        magnifierSize = min(MAX_MAGNIFIER, dim * 2 / 3)
        radius = magnifierSize / 2
        ring = radius - 15
        box = QSize(magnifierSize, magnifierSize)

        # reupdate our mask
        if maskPixmap.size() != box:
            maskPixmap = QPixmap(box)
            maskPixmap.fill(Qt.transparent)
            g = QRadialGradient()
            g.setCenter(radius, radius)
            g.setFocalPoint(radius, radius)
            g.setRadius(radius)
            g.setColorAt(1.0, QColor(64, 64, 64, 0))
            g.setColorAt(0.5, QColor(0, 0, 0, 255))
            mask = QPainter(maskPixmap)
            mask.setRenderHint(QPainter.HighQualityAntialiasing)
            mask.setCompositionMode(QPainter.CompositionMode_Source)
            mask.setBrush(g)
            mask.setPen(Qt.NoPen)
            mask.drawRect(maskPixmap.rect())
            mask.setBrush(QColor(Qt.transparent))
            mask.drawEllipse(g.center(), ring, ring)
            mask.end()

        center = dragPos - QPoint(0, radius)
        center += QPoint(0, radius / 2)
        corner = center - QPoint(radius, radius)
        xy = center * 2 - QPoint(radius, radius)
        # only set the dimension to the magnified portion
        if zoomPixmap.size() != box:
            zoomPixmap = QPixmap(box)
            zoomPixmap.fill(Qt.lightGray)

        if True:
            painter_p = QPainter(zoomPixmap)
            painter_p.translate(-xy)
            largePixmap = QPixmap.fromImage(surface.image)
            painter_p.drawPixmap(offset, largePixmap)
            painter_p.end()

        clipPath = QPainterPath()
        clipPath.addEllipse(QPointF(center), ring, ring)
        painter.setClipPath(clipPath)
        painter.drawPixmap(corner, zoomPixmap)
        painter.setClipping(False)
        painter.drawPixmap(corner, maskPixmap)
        painter.setPen(Qt.gray)
        painter.drawPath(clipPath)
        return
Exemplo n.º 16
0
 def paint(self, painter, option, widget):
     ellipse = self.boundingRect()
     gradient = QRadialGradient(0, 8, 20, 0, 8)
     gradient.setColorAt(0.0, Qt.white)
     gradient.setColorAt(0.8, self.color)
     painter.setBrush(gradient)
     painter.setPen(self.color)
     painter.drawEllipse(ellipse)
     painter.setFont(QFont("Verdana", 8))
     painter.setPen(QColor(Qt.white))
     painter.drawText(ellipse, Qt.AlignCenter, self.name)
Exemplo n.º 17
0
    def __init__(self, nx_node, pos):
        """
        Create node in the graph scene

        :param tuple nx_node: Node info
        :param x_y: Position of the node
        """
        super().__init__(nx_node, pos)

        # color around ellipse
        outline_color = QColor('grey')
        outline_style = Qt.SolidLine
        outline_width = 1
        if self.status_wallet:
            outline_color = QColor('black')
            outline_width = 2
        if not self.status_member:
            outline_color = QColor('red')
            outline_style = Qt.SolidLine
        self.setPen(QPen(outline_color, outline_width, outline_style))

        # text inside ellipse
        self.text_item = QGraphicsSimpleTextItem(self)
        self.text_item.setText(self.text)
        text_color = QColor('grey')
        if self.status_wallet == NodeStatus.HIGHLIGHTED:
            text_color = QColor('black')
        self.text_item.setBrush(QBrush(text_color))
        # center ellipse around text
        self.setRect(0, 0,
                     self.text_item.boundingRect().width() * 2,
                     self.text_item.boundingRect().height() * 2)

        #  set anchor to the center
        self.setTransform(QTransform().translate(
            -self.boundingRect().width() / 2.0,
            -self.boundingRect().height() / 2.0))
        # center text in ellipse
        self.text_item.setPos(self.boundingRect().width() / 4.0,
                              self.boundingRect().height() / 4.0)

        # create gradient inside the ellipse
        gradient = QRadialGradient(
            QPointF(0,
                    self.boundingRect().height() / 4),
            self.boundingRect().width())
        gradient.setColorAt(0, QColor('white'))
        gradient.setColorAt(1, QColor('darkgrey'))
        self.setBrush(QBrush(gradient))

        # cursor change on hover
        self.setAcceptHoverEvents(True)
        self.setZValue(1)
Exemplo n.º 18
0
 def draw_center(self, qp, event, w):
     w *= 0.2
     rect = QRect()
     rect.setSize(QSize(w, w))
     rect.moveCenter(event.rect().center())
     rad = rect.width() / 2
     cap = QRadialGradient(rect.center(), rad)
     cap.setColorAt(0, Qt.white)
     cap.setColorAt(1, Qt.gray)
     qp.setPen(QPen(Qt.black, 1))
     qp.setBrush(QBrush(cap))
     qp.drawEllipse(rect)
Exemplo n.º 19
0
    def draw_value(self, painter):

        self.initCoordinateSystem(painter)

        color = QColor(Qt.blue)
        if self.mPointer.value() >= self.mPointer.nominal():
            color = QColor(0, 200, 0)
        if self.mPointer.value() >= self.mPointer.critical():
            color = QColor(Qt.red)

        factor = (self.mPointer.value() - self.mPointer.minimal()) / (
            self.mPointer.maximal() - self.mPointer.minimal())

        painter.setFont(self.mValueFont)
        st = "{} ℃".format(self.mPointer.value())
        Size = painter.fontMetrics().size(Qt.TextSingleLine, st)
        painter.drawText(QPointF(Size.width() / -2, 307 - Size.height()), st)

        slug = QLinearGradient(0.0, 0.0, 5.0, 0.0)
        tank = QRadialGradient(0.0, 267.0, 10.0, -5.0, 262.0)

        slug.setSpread(QGradient.ReflectSpread)
        tank.setSpread(QGradient.ReflectSpread)

        color.setHsv(color.hue(), color.saturation(), color.value())
        slug.setColorAt(1.0, color)
        tank.setColorAt(1.0, color)

        color.setHsv(color.hue(), color.saturation() - 200, color.value())
        slug.setColorAt(0.0, color)
        tank.setColorAt(0.0, color)

        painter.setPen(Qt.NoPen)
        painter.setBrush(slug)

        offset = 10

        temp = 224 * factor

        height = temp + offset

        if 231 < temp:
            height = 231 + offset
        if offset - 5 >= height:
            height = offset - 5

        painter.drawRect(-5, 252 + offset - height, 10, height)

        painter.setBrush(tank)
        painter.drawEllipse(QRectF(-10.0, 257.5, 20.0, 20.0))

        painter.end()
Exemplo n.º 20
0
 def drawEndpointFade(self, rect, scale=None):
     rect = FlowBoardPainter._endpointRect(rect, scale)
     gradient = QRadialGradient(QRectF(rect).center(), rect.width() / 2)
     bg = QColor(QFlowPalette[0][1])
     bg.setAlphaF(0.2)
     gradient.setColorAt(0.6, bg)
     gradient.setColorAt(1.0, QFlowPalette[0][1])
     self.save()
     self.setRenderHint(QPainter.Antialiasing, True)
     self.setBrush(QBrush(gradient))
     self.setPen(QPen(QFlowPalette[0][1], 1))
     self.drawEllipse(rect)
     self.restore()
Exemplo n.º 21
0
    def drawGradients(self, painter: QPainter):
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)

        gr1 = QRadialGradient(20.0, 20.0, 110.0)
        painter.setBrush(gr1)
        painter.drawEllipse(20.0, 20.0, 100.0, 100.0)

        gr2 = QRadialGradient(190.0, 70.0, 50.0, 190.0, 70.0)
        gr2.setColorAt(0.2, Qt.yellow)
        gr2.setColorAt(0.7, Qt.black)
        painter.setBrush(gr2)
        painter.drawEllipse(140.0, 20.0, 100.0, 100.0)
Exemplo n.º 22
0
 def paintEvent(self, event):
     painter = QPainter(self)
     pen = QPen()
     pen.setStyle(Qt.NoPen)
     painter.setPen(pen)
     W = self.width()
     H = self.height()
     radialGrad = QRadialGradient(W / 2, H / 2, W / 8, W / 2, H / 2)
     radialGrad.setColorAt(0, Qt.yellow)
     radialGrad.setColorAt(1, Qt.blue)
     radialGrad.setSpread(QGradient.ReflectSpread)
     painter.setBrush(radialGrad)
     painter.drawRect(self.rect())
Exemplo n.º 23
0
 def paintEvent(self, event):
     painter = QPainter(self)
     pen = QPen()
     pen.setStyle(Qt.NoPen)
     painter.setPen(pen)
     W = self.width()
     H = self.height()
     radialGrad = QRadialGradient(W/2, H/2, W/3, 3*W/4, H/2)
     radialGrad.setColorAt(0, Qt.yellow)
     radialGrad.setColorAt(0.8, Qt.blue)
     painter.setBrush(radialGrad)
     rect = QRect(W/4, H/4, W/2, H/2)
     painter.drawRect(rect)
Exemplo n.º 24
0
    def __init__(self, nx_node, pos):
        """
        Create node in the graph scene

        :param tuple nx_node: Node info
        :param x_y: Position of the node
        """
        super().__init__(nx_node, pos)

        # color around ellipse
        outline_color = QColor('grey')
        outline_style = Qt.SolidLine
        outline_width = 1
        if self.status_wallet:
            outline_color = QColor('black')
            outline_width = 2
        if not self.status_member:
            outline_color = QColor('red')
            outline_style = Qt.SolidLine
        self.setPen(QPen(outline_color, outline_width, outline_style))

        # text inside ellipse
        self.text_item = QGraphicsSimpleTextItem(self)
        self.text_item.setText(self.text)
        text_color = QColor('grey')
        if self.status_wallet == NodeStatus.HIGHLIGHTED:
            text_color = QColor('black')
        self.text_item.setBrush(QBrush(text_color))
        # center ellipse around text
        self.setRect(
            0,
            0,
            self.text_item.boundingRect().width() * 2,
            self.text_item.boundingRect().height() * 2
        )

        #  set anchor to the center
        self.setTransform(
            QTransform().translate(-self.boundingRect().width() / 2.0, -self.boundingRect().height() / 2.0))
        # center text in ellipse
        self.text_item.setPos(self.boundingRect().width() / 4.0, self.boundingRect().height() / 4.0)

        # create gradient inside the ellipse
        gradient = QRadialGradient(QPointF(0, self.boundingRect().height() / 4), self.boundingRect().width())
        gradient.setColorAt(0, QColor('white'))
        gradient.setColorAt(1, QColor('darkgrey'))
        self.setBrush(QBrush(gradient))

        # cursor change on hover
        self.setAcceptHoverEvents(True)
        self.setZValue(1)
Exemplo n.º 25
0
 def paint(self, QPainter, QStyleOptionGraphicsItem, QWidget_widget=None):
     QPainter.setClipRect(self.rect)
     center = QPointF(self.rect.width() / 2, self.rect.height() / 2)
     focalPoint = center
     grad = QRadialGradient(center, float(self.rect.width() * 0.58929),
                            focalPoint)
     col = QColor(bConfig['checkColor'])
     grad.setColorAt(0, col)
     grad.setColorAt(1, self.brush.color())
     col = QColor(bConfig['checkColor'])
     col.setAlphaF(float(bConfig['effectsAlpha']))
     QPainter.setBrush(QBrush(col))
     QPainter.setPen(QPen(Qt.NoPen))
     QPainter.fillRect(self.rect,  grad)
Exemplo n.º 26
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setPen(QPen(Qt.black, 4, Qt.SolidLine))

        radialGradient = QRadialGradient(QPoint(100, 100), 10)

        # center point and radious

        radialGradient.setColorAt(0.4, Qt.white)
        radialGradient.setColorAt(0.8, Qt.green)
        radialGradient.setColorAt(1.0, Qt.black)
        painter.setBrush(QBrush(radialGradient))

        painter.drawRect(10, 10, 300, 300)
Exemplo n.º 27
0
    def paintEvent(self, e):
        painter = QPainter(self)

        painter.setPen(QPen(Qt.red, 4, Qt.SolidLine))

        radial = QRadialGradient(QPoint(100, 100), 100)

        radial.setColorAt(0.4, Qt.white)
        radial.setColorAt(0.8, Qt.green)
        radial.setColorAt(1.0, Qt.black)

        painter.setBrush(QBrush(radial))

        painter.drawRect(0, 0, 200, 200)
Exemplo n.º 28
0
 def drawEndpointGlow(self, rect, key, scale=None):
     color = QFlowPalette[key][0]
     rect = FlowBoardPainter._endpointRect(rect, scale)
     gradient = QRadialGradient(QRectF(rect).center(), rect.width() / 2)
     bg = QColor(color)
     bg.setAlphaF(0.3)
     gradient.setColorAt(0.5, bg)
     gradient.setColorAt(1.0, color)
     self.save()
     self.setRenderHint(QPainter.Antialiasing, True)
     self.setBrush(QBrush(gradient))
     self.setPen(QPen(color, 1))
     self.drawEllipse(rect)
     self.restore()
Exemplo n.º 29
0
 def draw_painter_paths(self, qp, event):
     w = min(event.rect().width(), event.rect().height())
     center = event.rect().center()
     fp = QPoint(int(center.x() - w / 4), int(center.y() - w / 4))
     bg = QRadialGradient(center, w / 2, fp)
     bg.setColorAt(0, QColor(180, 180, 180))
     bg.setColorAt(1, QColor(40, 40, 40))
     qp.setBrush(QBrush(bg))
     qp.setPen(QPen(QColor(Qt.black), 4))
     qp.drawPath(self.left_path)
     qp.drawPath(self.right_path)
     qp.drawPath(self.top_path)
     qp.drawPath(self.bottom_path)
     qp.drawPath(self.center_path)
Exemplo n.º 30
0
    def paint(self, painter, option, widget):

        if self.is_node1:
            color = Qt.green
            dark_color = Qt.darkGreen
        else:
            color = Qt.yellow
            dark_color = Qt.darkYellow

        gradient = QRadialGradient(-3, -3, 10)
        if option.state & QStyle.State_MouseOver:
            gradient.setCenter(3, 3)
            gradient.setFocalPoint(3, 3)
            gradient.setColorAt(1, QColor(color).lighter(120))
            gradient.setColorAt(0, QColor(dark_color).lighter(120))
        else:
            gradient.setColorAt(0, color)
            gradient.setColorAt(1, dark_color)

        painter.setBrush(QBrush(gradient))
        painter.setPen(QPen(Qt.black, 0))
        painter.drawEllipse(-10, -10, 20, 20)

        # node text
        painter.setPen(QPen(QColor(Qt.black), 0))
        painter.drawText(13, 4, "%s" % self.node_record.index)
Exemplo n.º 31
0
    def paint(self, painter, option, widget):
        painter.setPen(Qt.NoPen)
        painter.setBrush(Qt.darkGray)
        ball_size = 50
        painter.drawRect(-ball_size, -ball_size, ball_size, ball_size)
        painter.drawEllipse(-7, -7, ball_size, ball_size)

        gradient = QRadialGradient(-3, -3, 10)
        gradient.setColorAt(0, Qt.yellow)
        gradient.setColorAt(1, Qt.darkYellow)

        painter.setBrush(QBrush(gradient))
        painter.setPen(QPen(Qt.black, 0))
        painter.drawEllipse(-10, -10, ball_size, ball_size)
Exemplo n.º 32
0
 def draw_background(self, qp, event, w):
     w -= 6
     center = event.rect().center()
     rect = QRect()
     rect.setSize(QSize(w, w))
     rect.moveCenter(center)
     fp = QPoint(center.x() - w / 4, center.y() - w / 4)
     bg = QRadialGradient(center, w / 2, fp)
     bg.setColorAt(0, QColor(180, 180, 180))
     bg.setColorAt(1, QColor(40, 40, 40))
     qp.setPen(QPen(self._bezel_color, 6))
     qp.setBrush(QBrush(bg))
     qp.drawEllipse(rect)
     qp.drawArc(rect, 0, 360 * 16)
Exemplo n.º 33
0
    def draw_growing_circle(self, painter, x, y, width, height, time_diff_rate):
        self.draw_normal_circle(painter, x, y , width, height)
        # painter.setBrush(QBrush(QColor("#ffa8c5"), Qt.NoBrush))


        radialGradient = QRadialGradient(QPoint(x * width + int(width/2),y * height + int(height/2))
                                         ,int(height / 2) - 20,
                                         QPoint(x * width + int(width/2),y * height + int(height/2))) # center,radius,focalPoint
        radialGradient.setColorAt(0,QColor("#fccccc"))
        radialGradient.setColorAt(0.7,QColor("#eb9494"))
        radialGradient.setColorAt(1.0,QColor("#ff4d4d"))
        painter.setBrush(QBrush(radialGradient))
        painter.setPen(Qt.NoPen)
        painter.drawEllipse(QPoint(x * width + int(width/2), y * height + int(height/2))
                            ,(int(height / 2) - 20) * time_diff_rate, (int(height/2) - 40) * time_diff_rate)
        painter.setPen(QPen())
Exemplo n.º 34
0
    def _refresh_colors(self):
        """
        Refresh elements in the node
        """
        # color around ellipse
        outline_color = QColor('grey')
        outline_style = Qt.SolidLine
        outline_width = 1
        if self.status_wallet:
            outline_width = 2
        if not self.status_member:
            outline_color = QColor('red')

        if self.status_sentry:
            outline_color = QColor('black')
            outline_width = 3

        self.setPen(QPen(outline_color, outline_width, outline_style))

        if self.highlighted:
            text_color = QColor('grey')
        else:
            text_color = QColor('black')

        if self.status_wallet == NodeStatus.HIGHLIGHTED:
            text_color = QColor('grey')

        if self.text_item:
            self.text_item.setBrush(QBrush(text_color))

        # create gradient inside the ellipse
        gradient = QRadialGradient(
            QPointF(0,
                    self.boundingRect().height() / 4),
            self.boundingRect().width())
        color = QColor()
        color.setHsv(120 - 60 / self.steps_max * self.steps,
                     180 + 50 / self.steps_max * self.steps,
                     60 + 170 / self.steps_max * self.steps)
        if self.highlighted:
            color = color.darker(200)
        color = color.lighter(
            math.fabs(math.sin(self.loading_counter / 100 * math.pi) * 100) +
            100)
        gradient.setColorAt(0, color)
        gradient.setColorAt(1, color.darker(150))
        self.setBrush(QBrush(gradient))
Exemplo n.º 35
0
def radial_gradient(color, color_light=50):
    """
    radial_gradient(QColor, QColor)
    radial_gradient(QColor, int)

    Return a radial gradient. `color_light` can be a QColor or an int.
    In the later case the light color is derived from `color` using
    `saturated(color, color_light)`.

    """
    if not isinstance(color_light, QColor):
        color_light = saturated(color, color_light)
    gradient = QRadialGradient(0.5, 0.5, 0.5)
    gradient.setColorAt(0.0, color_light)
    gradient.setColorAt(0.5, color_light)
    gradient.setColorAt(1.0, color)
    gradient.setCoordinateMode(QRadialGradient.ObjectBoundingMode)
    return gradient
Exemplo n.º 36
0
 def __init__(self, parent=None, ast=None):
     ''' Create the INPUT symbol '''
     ast = ast or ogAST.Input()
     self.ast = ast
     self.branch_entrypoint = None
     if not ast.pos_y and parent:
         # Make sure the item is placed below its parent
         ast.pos_y = parent.y() + parent.boundingRect().height() + 10
     super(Input, self).__init__(parent, text=ast.inputString,
             x=ast.pos_x or 0, y=ast.pos_y or 0, hyperlink=ast.hyperlink)
     self.set_shape(ast.width, ast.height)
     gradient = QRadialGradient(50, 50, 50, 50, 50)
     gradient.setColorAt(0, QColor(255, 240, 170))
     gradient.setColorAt(1, Qt.white)
     self.setBrush(QBrush(gradient))
     self.terminal_symbol = False
     self.parser = ogParser
     if ast.comment:
         Comment(parent=self, ast=ast.comment)
Exemplo n.º 37
0
    def setupScene(self):
        self.m_scene.setSceneRect(-300, -200, 600, 460)

        linearGrad = QLinearGradient(QPointF(-100, -100), QPointF(100, 100))
        linearGrad.setColorAt(0, Qt.darkGreen)#QColor(255, 255, 255))
        linearGrad.setColorAt(1, Qt.green)#QQColor(192, 192, 255))
        self.setBackgroundBrush(linearGrad)

        radialGrad = QRadialGradient(30, 30, 30)
        radialGrad.setColorAt(0, Qt.yellow)
        radialGrad.setColorAt(0.2, Qt.yellow)
        radialGrad.setColorAt(1, Qt.transparent)

        pixmap = QPixmap(60, 60)
        pixmap.fill(Qt.transparent)

        painter = QPainter(pixmap)
        painter.setPen(Qt.NoPen)
        painter.setBrush(radialGrad)
        painter.drawEllipse(0, 0, 60, 60)
        painter.end()

        self.m_lightSource = self.m_scene.addPixmap(pixmap)
        self.m_lightSource.setZValue(2)

        self.proto = ProtoObj(0, 0, 50, 50, self)
        self.proto.initObj()

        #self.m_items.append(self.proto.getObj()[0])
        self.m_scene.addItem(self.proto.getObj()[0])
Exemplo n.º 38
0
    def updateBrush(self):
        gradient = QRadialGradient(QPointF(self.radius, self.radius),
                self.radius, QPointF(self.radius*0.5, self.radius*0.5))

        gradient.setColorAt(0, QColor(255, 255, 255, 255))
        gradient.setColorAt(0.25, self.innerColor)
        gradient.setColorAt(1, self.outerColor)
        self.brush = QBrush(gradient)
Exemplo n.º 39
0
    def _refresh_colors(self):
        """
        Refresh elements in the node
        """
        # color around ellipse
        outline_color = QColor('black')
        outline_style = Qt.SolidLine
        outline_width = 1
        if self.status_wallet:
            outline_color = QColor('grey')
            outline_width = 2
        if not self.status_member:
            outline_color = QColor('red')
            outline_style = Qt.SolidLine
        self.setPen(QPen(outline_color, outline_width, outline_style))

        if self.highlighted:
            text_color = QColor('grey')
        else:
            text_color = QColor('black')

        if self.status_wallet == NodeStatus.HIGHLIGHTED:
            text_color = QColor('grey')
        self.text_item.setBrush(QBrush(text_color))

        # create gradient inside the ellipse
        gradient = QRadialGradient(QPointF(0, self.boundingRect().height() / 4), self.boundingRect().width())
        color = QColor()
        color.setHsv(120 - 60 / self.steps_max * self.steps,
                     180 + 50 / self.steps_max * self.steps,
                     60 + 170 / self.steps_max * self.steps)
        if self.highlighted:
            color = color.darker(200)
        color = color.lighter(math.fabs(math.sin(self.loading_counter / 100 * math.pi) * 100) + 100)
        gradient.setColorAt(0, color)
        gradient.setColorAt(1, color.darker(150))
        self.setBrush(QBrush(gradient))
Exemplo n.º 40
0
    def paint(self, painter, option, widget):
        painter.setPen(Qt.NoPen)
        painter.setBrush(Qt.darkGray)
        painter.drawEllipse(-7, -7, 20, 20)

        gradient = QRadialGradient(-3, -3, 10)
        if option.state & QStyle.State_Sunken:
            gradient.setCenter(3, 3)
            gradient.setFocalPoint(3, 3)
            gradient.setColorAt(1, QColor(Qt.yellow).lighter(120))
            gradient.setColorAt(0, QColor(Qt.darkYellow).lighter(120))
        else:
            gradient.setColorAt(0, Qt.yellow)
            gradient.setColorAt(1, Qt.darkYellow)

        painter.setBrush(QBrush(gradient))
        painter.setPen(QPen(Qt.black, 0))
        painter.drawEllipse(-10, -10, 20, 20)
Exemplo n.º 41
0
class ControlButton(QWidget):
    def __init__(self, index, name, func, parent):
        super().__init__(parent)
        self.index = index
        self.name = name
        self.function = func
        self.resize(TILE_WIDTH << 2, TILE_HEIGHT << 2)
        self.show()
        self.opacity = None
        self.setMouseTracking(True)
        self.color = QColor(50 * self.index, 255, 255 - 10 * self.index)
        self.gradient = QRadialGradient(
            50 + 10 * self.index, 50 - 10 * self.index, 500 - 50 * self.index,
            50 + 10 * self.index, 100 - 10 * self.index)
        self.gradient.setColorAt(0, QColor(200, 200, 200))
        self.gradient.setColorAt(0.5, QColor(50 * self.index, 255, 255 - 10 * self.index))
        self.gradient.setColorAt(1, QColor(200, 200, 200))
        self.brush = QBrush(self.gradient)
        self.path = QPainterPath()
        rect = QRectF(TILE_WIDTH * 1.5, TILE_HEIGHT * 1.5, TILE_WIDTH * 1.5, TILE_HEIGHT * 1.5)
        total = self.parent().total - 1
        if total < 3:
            total = 3
        if self.index == 0:
            self.path.arcMoveTo(rect, 90)
            self.path.arcTo(rect, 90, 360)
        else:
            self.path.arcMoveTo(QRectF(self.rect()), 90 + self.index * 360 // total)
            self.path.arcTo(QRectF(self.rect()), 90 + self.index * 360 // total,  360 // total)
            self.path.arcTo(rect, 90 + self.index * 360 // total + 360 // total, -360 // total)
            self.path.arcTo(QRectF(self.rect()), 90 + self.index * 360 // total,  0)

    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setBrush(self.brush)
        if self.opacity is None or self.parent().vanishing:
            painter.setOpacity(self.parent().opacity / 255)
        else:
            painter.setOpacity(self.opacity / 255)
        pen = QPen(QColor(100, 100, 100, 150))
        pen.setWidth(10)
        painter.setPen(pen)
        painter.drawPath(self.path)
        painter.setPen(QColor(0, 0, 0))
        painter.drawText(self.path.controlPointRect(), Qt.AlignCenter, self.name)
Exemplo n.º 42
0
    def setupScene(self):
        self.m_scene.setSceneRect(-300, -200, 600, 460)

        linearGrad = QLinearGradient(QPointF(-100, -100), QPointF(100, 100))
        linearGrad.setColorAt(0, QColor(255, 255, 255))
        linearGrad.setColorAt(1, QColor(192, 192, 255))
        self.setBackgroundBrush(linearGrad)

        radialGrad = QRadialGradient(30, 30, 30)
        radialGrad.setColorAt(0, Qt.yellow)
        radialGrad.setColorAt(0.2, Qt.yellow)
        radialGrad.setColorAt(1, Qt.transparent)

        pixmap = QPixmap(60, 60)
        pixmap.fill(Qt.transparent)

        painter = QPainter(pixmap)
        painter.setPen(Qt.NoPen)
        painter.setBrush(radialGrad)
        painter.drawEllipse(0, 0, 60, 60)
        painter.end()

        self.m_lightSource = self.m_scene.addPixmap(pixmap)
        self.m_lightSource.setZValue(2)

        for i in range(-2, 3):
            for j in range(-2, 3):
                if (i + j) & 1:
                    item = QGraphicsEllipseItem(0, 0, 50, 50)
                else:
                    item = QGraphicsRectItem(0, 0, 50, 50)

                item.setPen(QPen(Qt.black, 1))
                item.setBrush(QBrush(Qt.white))

                effect = QGraphicsDropShadowEffect(self)
                effect.setBlurRadius(8)
                item.setGraphicsEffect(effect)
                item.setZValue(1)
                item.setPos(i * 80, j * 80)
                self.m_scene.addItem(item)
                self.m_items.append(item)
Exemplo n.º 43
0
    def paintEvent(self, event):
        painter = QPainter()
        x = 0
        y = 0
        if self._alignment & Qt.AlignLeft:
            x = 0
        elif self._alignment & Qt.AlignRight:
            x = self.width() - self._diameter
        elif self._alignment & Qt.AlignHCenter:
            x = (self.width() - self._diameter) / 2
        elif self._alignment & Qt.AlignJustify:
            x = 0

        if self._alignment & Qt.AlignTop:
            y = 0
        elif self._alignment & Qt.AlignBottom:
            y = self.height() - self._diameter
        elif self._alignment & Qt.AlignVCenter:
            y = (self.height() - self._diameter) / 2

        gradient = QRadialGradient(x + self._diameter / 2, y + self._diameter / 2,
                                   self._diameter * 0.4, self._diameter * 0.4, self._diameter * 0.4)
        gradient.setColorAt(0, Qt.white)

        if self._state:
            gradient.setColorAt(1, self._color)
        else:
            gradient.setColorAt(1, Qt.black)

        painter.begin(self)
        brush = QBrush(gradient)
        painter.setPen(self._color)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setBrush(brush)
        painter.drawEllipse(x, y, self._diameter - 1, self._diameter - 1)

        if self._flashRate > 0 and self._flashing:
            self._timer.start(self._flashRate)
        else:
            self._timer.stop()

        painter.end()
Exemplo n.º 44
0
class PolygonWidget(QWidget):
    """PolygonWidget(QWidget)
    
    Provides a custom widget to display a polygon with properties and slots
    that can be used to customize its appearance.
    """
    
    def __init__(self, parent=None):
    
        super(PolygonWidget, self).__init__(parent)
        
        self._sides = 5
        self._innerRadius = 20
        self._outerRadius = 50
        self._angle = 0
        
        self.createPath()
        
        self._innerColor = QColor(255, 255, 128)
        self._outerColor = QColor(255, 0, 128)
        
        self.createGradient()
    
    def paintEvent(self, event):
    
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setBrush(QBrush(QColor(192, 192, 255)))
        painter.drawRect(event.rect())
        
        painter.translate(self.width()/2.0, self.height()/2.0)
        painter.rotate(self._angle)
        painter.setBrush(QBrush(self.gradient))
        painter.drawPath(self.path)
        painter.end()
    
    def sizeHint(self):
    
        return QSize(2*self._outerRadius + 20, 2*self._outerRadius + 20)
    
    def createPath(self):
    
        self.path = QPainterPath()
        angle = 2*math.pi/self._sides
        self.path.moveTo(self._outerRadius, 0)
        for step in range(1, self._sides + 1):
            self.path.lineTo(
                self._innerRadius * math.cos((step - 0.5) * angle),
                self._innerRadius * math.sin((step - 0.5) * angle)
                )
            self.path.lineTo(
                self._outerRadius * math.cos(step * angle),
                self._outerRadius * math.sin(step * angle)
                )
        self.path.closeSubpath()
    
    def createGradient(self):
    
        center = QPointF(0, 0)
        self.gradient = QRadialGradient(center, self._outerRadius, center)
        self.gradient.setColorAt(0.5, QColor(self._innerColor))
        self.gradient.setColorAt(1.0, QColor(self._outerColor))
    
    # The angle property is implemented using the getAngle() and setAngle()
    # methods.
    
    def getAngle(self):
        return self._angle
    
    # The setAngle() setter method is also a slot.
    @pyqtSlot(int)
    def setAngle(self, angle):
        self._angle = min(max(0, angle), 360)
        self.update()
    
    angle = pyqtProperty(int, getAngle, setAngle)
    
    # The innerRadius property is implemented using the getInnerRadius() and
    # setInnerRadius() methods.
    
    def getInnerRadius(self):
        return self._innerRadius
    
    # The setInnerRadius() setter method is also a slot.
    @pyqtSlot(int)
    def setInnerRadius(self, radius):
        self._innerRadius = radius
        self.createPath()
        self.createGradient()
        self.update()
    
    innerRadius = pyqtProperty(int, getInnerRadius, setInnerRadius)
    
    # The outerRadius property is implemented using the getOuterRadius() and
    # setOuterRadius() methods.
    
    def getOuterRadius(self):
        return self._outerRadius
    
    # The setOuterRadius() setter method is also a slot.
    @pyqtSlot(int)
    def setOuterRadius(self, radius):
        self._outerRadius = radius
        self.createPath()
        self.createGradient()
        self.update()
    
    outerRadius = pyqtProperty(int, getOuterRadius, setOuterRadius)
    
    # The numberOfSides property is implemented using the getNumberOfSides()
    # and setNumberOfSides() methods.
    
    def getNumberOfSides(self):
        return self._sides
    
    # The setNumberOfSides() setter method is also a slot.
    @pyqtSlot(int)
    def setNumberOfSides(self, sides):
        self._sides = max(3, sides)
        self.createPath()
        self.update()
    
    numberOfSides = pyqtProperty(int, getNumberOfSides, setNumberOfSides)
    
    # The innerColor property is implemented using the getInnerColor() and
    # setInnerColor() methods.
    
    def getInnerColor(self):
        return self._innerColor
    
    def setInnerColor(self, color):
        self._innerColor = max(3, color)
        self.createGradient()
        self.update()
    
    innerColor = pyqtProperty(QColor, getInnerColor, setInnerColor)
    
    # The outerColor property is implemented using the getOuterColor() and
    # setOuterColor() methods.
    
    def getOuterColor(self):
        return self._outerColor
    
    def setOuterColor(self, color):
        self._outerColor = color
        self.createGradient()
        self.update()
    
    outerColor = pyqtProperty(QColor, getOuterColor, setOuterColor)
Exemplo n.º 45
0
    def __init__(self, metadata, x_y):
        """
        Create node in the graph scene

        :param dict metadata: Node metadata
        :param x_y: Position of the node
        """
        # unpack tuple
        x, y = x_y

        super(Node, self).__init__()

        self.metadata = metadata
        self.id = metadata['id']
        self.status_wallet = self.metadata['status'] & NODE_STATUS_HIGHLIGHTED
        self.status_member = not self.metadata['status'] & NODE_STATUS_OUT
        self.text = self.metadata['text']
        self.setToolTip(self.metadata['tooltip'])
        self.arcs = []
        self.menu = None
        self.action_sign = None
        self.action_transaction = None
        self.action_contact = None
        self.action_show_member = None

        # color around ellipse
        outline_color = QColor('grey')
        outline_style = Qt.SolidLine
        outline_width = 1
        if self.status_wallet:
            outline_color = QColor('black')
            outline_width = 2
        if not self.status_member:
            outline_color = QColor('red')
            outline_style = Qt.SolidLine
        self.setPen(QPen(outline_color, outline_width, outline_style))

        # text inside ellipse
        self.text_item = QGraphicsSimpleTextItem(self)
        self.text_item.setText(self.text)
        text_color = QColor('grey')
        if self.status_wallet == NODE_STATUS_HIGHLIGHTED:
            text_color = QColor('black')
        self.text_item.setBrush(QBrush(text_color))
        # center ellipse around text
        self.setRect(
            0,
            0,
            self.text_item.boundingRect().width() * 2,
            self.text_item.boundingRect().height() * 2
        )

        #  set anchor to the center
        self.setTransform(
            QTransform().translate(-self.boundingRect().width() / 2.0, -self.boundingRect().height() / 2.0))
        self.setPos(x, y)
        # center text in ellipse
        self.text_item.setPos(self.boundingRect().width() / 4.0, self.boundingRect().height() / 4.0)

        # create gradient inside the ellipse
        gradient = QRadialGradient(QPointF(0, self.boundingRect().height() / 4), self.boundingRect().width())
        gradient.setColorAt(0, QColor('white'))
        gradient.setColorAt(1, QColor('darkgrey'))
        self.setBrush(QBrush(gradient))

        # cursor change on hover
        self.setAcceptHoverEvents(True)
        self.setZValue(1)
Exemplo n.º 46
0
    def paintEvent(self, event):
        p = QPainter()
        p.begin(self)
        self._normalMap.render(p, event.rect())
        p.setPen(Qt.black)
        p.drawText(self.rect(), Qt.AlignBottom | Qt.TextWordWrap,
                   "Map data CCBYSA 2009 OpenStreetMap.org contributors")
        p.end()

        if self.zoomed:
            dim = min(self.width(), self.height())
            magnifierSize = min(MAX_MAGNIFIER, dim * 2 / 3)
            radius = magnifierSize / 2
            ring = radius - 15
            box = QSize(magnifierSize, magnifierSize)

            # reupdate our mask
            if self.maskPixmap.size() != box:
                self.maskPixmap = QPixmap(box)
                self.maskPixmap.fill(Qt.transparent)
                g = QRadialGradient()
                g.setCenter(radius, radius)
                g.setFocalPoint(radius, radius)
                g.setRadius(radius)
                g.setColorAt(1.0, QColor(255, 255, 255, 0))
                g.setColorAt(0.5, QColor(128, 128, 128, 255))
                mask = QPainter(self.maskPixmap)
                mask.setRenderHint(QPainter.Antialiasing)
                mask.setCompositionMode(QPainter.CompositionMode_Source)
                mask.setBrush(g)
                mask.setPen(Qt.NoPen)
                mask.drawRect(self.maskPixmap.rect())
                mask.setBrush(QColor(Qt.transparent))
                mask.drawEllipse(g.center(), ring, ring)
                mask.end()

            center = self.dragPos - QPoint(0, radius)
            center += QPoint(0, radius / 2)
            corner = center - QPoint(radius, radius)
            xy = center * 2 - QPoint(radius, radius)
            # only set the dimension to the magnified portion
            if self.zoomPixmap.size() != box:
                self.zoomPixmap = QPixmap(box)
                self.zoomPixmap.fill(Qt.lightGray)
    
            if True:
                p = QPainter(self.zoomPixmap)
                p.translate(-xy)
                self._largeMap.render(p, QRect(xy, box))
                p.end()

            clipPath = QPainterPath()
            clipPath.addEllipse(QPointF(center), ring, ring)
            p = QPainter(self)
            p.setRenderHint(QPainter.Antialiasing)
            p.setClipPath(clipPath)
            p.drawPixmap(corner, self.zoomPixmap)
            p.setClipping(False)
            p.drawPixmap(corner, self.maskPixmap)
            p.setPen(Qt.gray)
            p.drawPath(clipPath)

        if self.invert:
            p = QPainter(self)
            p.setCompositionMode(QPainter.CompositionMode_Difference)
            p.fillRect(event.rect(), Qt.white)
            p.end()
Exemplo n.º 47
0
    def showWedge(self, angle, color,
                  extended=False, rev_gradient=False, outline_only=False):
        """Summary

        Args:
            angle (TYPE): Description
            color (TYPE): Description
            extended (bool, optional): Description
            rev_gradient (bool, optional): Description
            outline_only (bool, optional): Description
        """
        # Hack to keep wedge in front
        # self.setRotation(self.pre_xover_item_group.rotation())

        self._last_params = (angle, color, extended, rev_gradient, outline_only)
        radius = self._radius
        span = self.pre_xover_item_group.partCrossoverSpanAngle() / 2
        radius_adjusted = radius + (_WEDGE_RECT_GAIN / 2)

        tip = QPointF(radius_adjusted, radius_adjusted)
        EXT = 1.35 if extended else 1.0

        # print("wtf", tip, pos)
        base_p2 = QPointF(1, 1)

        line0 = QLineF(tip, QPointF(base_p2))
        line1 = QLineF(tip, QPointF(base_p2))
        line2 = QLineF(tip, QPointF(base_p2))

        quad_scale = 1 + (.22*(span - 5) / 55)  # lo+(hi-lo)*(val-min)/(max-min)
        line0.setLength(radius_adjusted * EXT*quad_scale)  # for quadTo control point
        line1.setLength(radius_adjusted * EXT)
        line2.setLength(radius_adjusted * EXT)
        line0.setAngle(angle)
        line1.setAngle(angle - span)
        line2.setAngle(angle + span)

        path = QPainterPath()

        if outline_only:
            self.setPen(getPenObj(color, 0.5, alpha=128, capstyle=Qt.RoundCap))
            path.moveTo(line1.p2())
            path.quadTo(line0.p2(), line2.p2())
        else:
            gradient = QRadialGradient(tip, radius_adjusted * EXT)
            color1 = getColorObj(color, alpha=80)
            color2 = getColorObj(color, alpha=0)
            if rev_gradient:
                color1, color2 = color2, color1

            if extended:
                gradient.setColorAt(0, color1)
                gradient.setColorAt(radius_adjusted / (radius_adjusted * EXT), color1)
                gradient.setColorAt(radius_adjusted / (radius_adjusted * EXT) + 0.01, color2)
                gradient.setColorAt(1, color2)
            else:
                gradient.setColorAt(0, getColorObj(color, alpha=50))
            brush = QBrush(gradient)
            self.setBrush(brush)

            path.moveTo(line1.p1())
            path.lineTo(line1.p2())
            path.quadTo(line0.p2(), line2.p2())
            path.lineTo(line2.p1())

        self.setPath(path)
        self.show()
Exemplo n.º 48
0
    def paintEvent(self, _event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        width = self.width()
        height = self.height()

        if self.dynamic_resize:
            knob_radius = self.dynamic_knob_radius
        else:
            knob_radius = self.knob_radius

        # ensure that the center point is in the middle of a pixel to ensure
        # that exact vertial and horizantal ticks are drawn exactly 1px wide
        x = math.floor(width / 2.0) + 0.5
        y = math.floor(height / 2.0) + 0.5

        if DEBUG:
            painter.fillRect(0, 0, width, height, Qt.yellow)

        painter.translate(x, y)

        if self.knob_style == KnobWidget.STYLE_NEEDLE:
            r = min(x, y) - 1

            painter.setPen(Qt.white)
            painter.setBrush(Qt.white)
            painter.drawEllipse(QPoint(0, 0), r, r)

        angle = self.value_factor * self.total_angle - (self.total_angle / 2.0)

        # draw base knob or needle spike
        if self.knob_style == KnobWidget.STYLE_ROUND:
            painter.setPen(self.border_color)

            if self.pressed:
                gradient = QRadialGradient(0, 0, knob_radius)
                gradient.setColorAt(0, self.base_color_pressed)
                gradient.setColorAt(0.85, self.base_color)
                gradient.setColorAt(1, self.base_color)

                painter.setBrush(gradient)
            else:
                painter.setBrush(self.base_color)

            painter.drawEllipse(QPoint(0, 0), knob_radius, knob_radius)
        elif self.knob_style == KnobWidget.STYLE_NEEDLE:
            painter.save()
            painter.rotate(angle)
            painter.setPen(self.needle_color)
            painter.setBrush(self.needle_color)

            needle = QPolygonF()
            needle.append(QPointF(self.needle_base_radius * 0.6, 0))
            needle.append(QPointF(0, -knob_radius))
            needle.append(QPointF(-self.needle_base_radius * 0.6, 0))

            painter.drawPolygon(needle)
            painter.restore()

        # draw knob mark or needle base
        if self.knob_style == KnobWidget.STYLE_ROUND:
            painter.save()
            painter.rotate(angle)
            painter.setPen(QPen(self.mark_color, 2))
            painter.drawLine(0, -knob_radius * 0.4, 0, -knob_radius * 0.8)
            painter.restore()
        elif self.knob_style == KnobWidget.STYLE_NEEDLE:
            painter.setPen(self.border_color)
            painter.setBrush(self.base_color)
            painter.drawEllipse(QPoint(0, 0), self.needle_base_radius, self.needle_base_radius)

        if self.scale_visible:
            painter.setPen(Qt.black)

            # draw scale arc
            if self.scale_arc_visible:
                painter.drawArc(-knob_radius - self.knob_to_scale,
                                -knob_radius - self.knob_to_scale,
                                knob_radius * 2 + self.knob_to_scale * 2,
                                knob_radius * 2 + self.knob_to_scale * 2,
                                (90 + self.total_angle / 2) * 16, -self.total_angle * 16)

            # draw scale ticks
            def value_to_angle(value):
                return (float(value - self.minimum_value) / self.value_range) * self.total_angle - (self.total_angle / 2.0)

            value = self.minimum_value

            while value <= self.maximum_value:
                angle = value_to_angle(value)

                painter.save()
                painter.rotate(value_to_angle(value))
                painter.drawLine(0, -knob_radius - self.knob_to_scale,
                                 0, -knob_radius - self.knob_to_scale - self.tick_size_large)

                if self.scale_text_visible:
                    p = painter.worldTransform().map(QPoint(0, -knob_radius - \
                                                               self.knob_to_scale - \
                                                               self.tick_size_large - \
                                                               self.tick_to_text - \
                                                               self.text_radius))

                painter.restore()

                if self.scale_text_visible:
                    if DEBUG:
                        painter.save()
                        painter.setPen(QColor(255, 0, 0, 50))
                        painter.setBrush(QColor(255, 0, 0, 50))
                        painter.drawEllipse(QPoint(p.x() - x, p.y() - y),
                                            self.text_radius, self.text_radius)
                        painter.restore()

                    painter.drawText(p.x() - x - 30, p.y() - y - 30, 60, 60,
                                     Qt.TextDontClip | Qt.AlignHCenter | Qt.AlignVCenter,
                                     str(value))

                for i in range(1, self.scale_step_divisions):
                    sub_value = value + (float(self.scale_step_size) * i) / self.scale_step_divisions

                    if sub_value > self.maximum_value:
                        break

                    painter.save()
                    painter.rotate(value_to_angle(sub_value))
                    painter.drawLine(0, -knob_radius - self.knob_to_scale,
                                     0, -knob_radius - self.knob_to_scale - self.tick_size_small)
                    painter.restore()

                value += self.scale_step_size

        if self.title_text != None:
            painter.drawText(-knob_radius, knob_radius - 30,
                             knob_radius * 2, 60,
                             Qt.TextDontClip | Qt.AlignHCenter | Qt.AlignVCenter,
                             self.title_text)