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 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.º 3
0
def base_brush():
    bottom = QColor(20, 20, 40)
    top = QColor(70, 70, 80)
    gradient = QLinearGradient(0, 0, 0, 200)
    gradient.setColorAt(0, top)
    gradient.setColorAt(1, bottom)
    return gradient
    def drawBackground(self, painter, rect):
        # Shadow.
        sceneRect = self.sceneRect()
        rightShadow = QRectF(sceneRect.right(), sceneRect.top() + 5, 5,
                                    sceneRect.height())
        bottomShadow = QRectF(sceneRect.left() + 5, sceneRect.bottom(),
                                     sceneRect.width(), 5)
        if rightShadow.intersects(rect) or rightShadow.contains(rect):
            painter.fillRect(rightShadow, Qt.darkGray)
        if bottomShadow.intersects(rect) or bottomShadow.contains(rect):
            painter.fillRect(bottomShadow, Qt.darkGray)

        # Fill.
        gradient = QLinearGradient(sceneRect.topLeft(),
                                         sceneRect.bottomRight())
        gradient.setColorAt(0, Qt.white)
        gradient.setColorAt(1, Qt.lightGray)
        # painter.fillRect(rect.intersect(sceneRect), QBrush(gradient))
        painter.setBrush(Qt.NoBrush)
        painter.drawRect(sceneRect)

        # Text.
        textRect = QRectF(sceneRect.left() + 4, sceneRect.top() + 4,
                                 sceneRect.width() - 4, sceneRect.height() - 4)
        message = "Click and drag the nodes around, and zoom with the " \
                  "mouse wheel or the '+' and '-' keys"

        font = painter.font()
        font.setBold(True)
        font.setPointSize(14)
        painter.setFont(font)
        painter.setPen(Qt.lightGray)
        painter.drawText(textRect.translated(2, 2), message)
        painter.setPen(Qt.black)
        painter.drawText(textRect, message)
Exemplo n.º 5
0
    def drawTanks(self, qp):

        for tankKey in self.plan.tankList.keys():
            qp.setPen(Qt.black)
            tank = self.plan.tankList[tankKey]
            if tank.use == False:
                continue
            x1 = tank.useFromTime / self.totalTime *self.plot_width
            x2 = tank.useUntilTime / self.totalTime *self.plot_width
            yTxt = tank.changeDepth / self.depthMax * self.plot_height
            bgPath = QPainterPath()
            bgPath.moveTo(x1, self.plot_height+10)
            bgPath.lineTo(x1, self.plot_height+20)
            bgPath.lineTo(x2, self.plot_height+20)
            bgPath.lineTo(x2, self.plot_height+10)
            bgPath.closeSubpath()
            gradient = QLinearGradient(0, 0, 0, 100)
            gradient.setColorAt(0.0, tank.color)
            gradient.setColorAt(1.0, tank.color)
            qp.setBrush(QBrush(gradient))
            qp.drawPath(bgPath)
            text = '{} ({}/{})'.format(tank.name, tank.o2, tank.he)
            text2 = '{:.0f} m {:.0f} min'.format(tank.changeDepth, tank.useFromTime/60.0)
            qp.drawText(x1+3, self.plot_height+20, text)
            qp.drawText(x1+3, yTxt + 10, text)
            qp.drawText(x1+3, yTxt + 20, text2)

            qp.setPen(QPen(Qt.black, 1, Qt.DotLine))
            if x1 != 0 :
                qp.drawLine(x1, self.plot_height, x1, yTxt)
                qp.drawLine(x1, yTxt, self.plot_width, yTxt)
Exemplo n.º 6
0
    def paintEvent(self, e):
        painter = QPainter(self)

        if self.instrument == 'Color':
            if self.col1 is None:
                col = QColor('white')
            else:
                col = self.col1

            painter.fillRect(20, 50, 200, 200, col)

            self.color = FillFigure(self.col1)

        else:
            if self.col1 is None:
                col1 = QColor('white')
            else:
                col1 = self.col1
            if self.col2 is None:
                col2 = QColor('white')
            else:
                col2 = self.col2

            if self.first is None:
                self.first = [20, 50]
            if self.second is None:
                self.second = [21, 100]

            grad = QLinearGradient(self.first[0], self.first[1], self.second[0], self.second[1])
            grad.setColorAt(0, col1)
            grad.setColorAt(1, col2)
            painter.fillRect(20, 50, 200, 200, grad)

            self.color = FillFigure(self.col1, self.col2, self.first[0], self.first[1], self.second[0], self.second[1])
 def paintEvent(self, event):
     super(CoverLabel, self).paintEvent(event)
     if hasattr(self, "cover_title") and self.cover_title != "":
         # 底部绘制文字
         painter = QPainter(self)
         rect = self.rect()
         # 粗略字体高度
         painter.save()
         fheight = self.fontMetrics().height()
         # 底部矩形框背景渐变颜色
         bottomRectColor = QLinearGradient(
             rect.width() / 2, rect.height() - 24 - fheight,
             rect.width() / 2, rect.height())
         bottomRectColor.setSpread(QGradient.PadSpread)
         bottomRectColor.setColorAt(0, QColor(255, 255, 255, 70))
         bottomRectColor.setColorAt(1, QColor(0, 0, 0, 50))
         # 画半透明渐变矩形框
         painter.setPen(Qt.NoPen)
         painter.setBrush(QBrush(bottomRectColor))
         painter.drawRect(rect.x(), rect.height() - 24 -
                          fheight, rect.width(), 24 + fheight)
         painter.restore()
         # 距离底部一定高度画文字
         font = self.font() or QFont()
         font.setPointSize(8)
         painter.setFont(font)
         painter.setPen(Qt.white)
         rect.setHeight(rect.height() - 12)  # 底部减去一定高度
         painter.drawText(rect, Qt.AlignHCenter |
                          Qt.AlignBottom, self.cover_title)
Exemplo n.º 8
0
    def paintEvent(self, event):
        # pylint: disable = unused-argument
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        width = painter.device().width()
        height = painter.device().height()

        # Gradient draw pass
        gradient = QLinearGradient(0, 0, width, 0)
        for stop, color in self.gradient.items():
            gradient.setColorAt(stop, QColor(*color))
        painter.fillRect(0, 0, width, height, gradient)

        # Handles draw pass
        pen = QPen()
        pen.setWidth(3)
        pen.setColor(QColor(255, 255, 255, 191))
        painter.setPen(pen)

        y = height / 2
        for pos in self.gradient.keys():
            x = pos * width
            painter.drawLine(
                QPoint(x, y - 12),
                QPoint(x, y + 12)
            )
            painter.drawEllipse(QPoint(x, y), 6, 6)

        painter.end()
 def set_palette(self):
     palette = QPalette()
     gradient = QLinearGradient(0, 0, 0, 100)
     gradient.setColorAt(1.0, Colors.light_sandstone)
     gradient.setColorAt(0.0, Colors.stone)
     palette.setBrush(QPalette.Window, QBrush(gradient))
     self.setPalette(palette)
Exemplo n.º 10
0
def gradient_darker(grad, factor):
    """Return a copy of the QGradient darkened by factor.

    .. note:: Only QLinearGradeint and QRadialGradient are supported.

    """
    if type(grad) is QGradient:
        if grad.type() == QGradient.LinearGradient:
            grad = sip.cast(grad, QLinearGradient)
        elif grad.type() == QGradient.RadialGradient:
            grad = sip.cast(grad, QRadialGradient)

    if isinstance(grad, QLinearGradient):
        new_grad = QLinearGradient(grad.start(), grad.finalStop())
    elif isinstance(grad, QRadialGradient):
        new_grad = QRadialGradient(grad.center(), grad.radius(),
                                   grad.focalPoint())
    else:
        raise TypeError

    new_grad.setCoordinateMode(grad.coordinateMode())

    for pos, color in grad.stops():
        new_grad.setColorAt(pos, color.darker(factor))

    return new_grad
Exemplo n.º 11
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.monitorWin = parent
        if self.monitorWin:
            self.monitorWin.sigTaskUpdating.connect(self.slotTaskUpdate)

        self.scene = QGraphicsScene(self)
        self.scene.setSceneRect(0, 0, self.SIZE[0], self.SIZE[1])
        self.setScene(self.scene)

        self._speedsPen = QPen(Qt.white)

        gradient = QLinearGradient(0, 0, self.SIZE[0], self.SIZE[1])
        gradient.setColorAt(0.0, Qt.darkGreen)
        gradient.setColorAt(1.0, Qt.yellow)
        self._speedsBrush = QBrush(gradient)

        # add elements to the scene
        self._speedsPolygon = self.scene.addPolygon(QPolygonF(),
                                                    self._speedsPen,
                                                    self._speedsBrush)
        self._progressText = self.scene.addText("")
        self._progressText.setPos(10, 0)

        self.setupDropSupport()
Exemplo n.º 12
0
    def drawGUI(self):
        # Draw everything to an image first so we can have a local copy
        # available for pixel RGBA access.
        qimage = QImage(QSize(512, 512), QImage.Format_ARGB32)
        qp = QPainter(qimage)
        qp.setRenderHint(QPainter.Antialiasing)
        qp.setPen(Qt.NoPen)

        # Draw the texture.
        qp.drawImage(0, 0, self.texture)

        # Draw the graydient bar
        myQRect = QRect(497, 1, 14, 510)
        gradient = QLinearGradient(0, 0, 0, 512)
        gradient.setColorAt(0, QColor(self.fgcolor))
        gradient.setColorAt(1, QColor(self.bgcolor))
        qp.fillRect(myQRect, gradient)
        qp.setPen(QPen(QColor(0, 0, 0, 255), 1))
        qp.setBrush(QBrush(QColor(0, 0, 0, 0)))
        qp.drawRect(497, 1, 14, 510)

        # Draw the fore/back color boxes
        qp.setPen(Qt.NoPen)
        qp.drawImage(464, 453, self.switcharrowsImg)
        qp.drawImage(436, 486, self.defaultblackwhiteImg)
        qp.setBrush(QColor(self.bgcolor))
        qp.drawRect(452, 468, 28, 28)
        qp.drawImage(452, 468, self.colorboxImg)
        qp.setBrush(QColor(self.fgcolor))
        qp.drawRect(436, 452, 28, 28)
        qp.drawImage(436, 452, self.colorboxImg)

        # Save a copy of the finished image locally.
        self.local_image = qimage
    def setup_chat_area(self):
        """Defines the main area where the messages will be displayed"""
        self.scroll_area.setContentsMargins(2, 40, 2, 2)
        self.scroll_area.setWidgetResizable(True)
        self.scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.scroll_area.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)

        self.scroll_area.setStyleSheet("""
            QWidget {
                 border: 1px solid black;
                 border-radius:7;
                } 
            """)

        palette = QPalette()
        gradient = QLinearGradient(0, 0, 0, 300)
        gradient.setColorAt(0.0, Colors.light_sandstone)
        gradient.setColorAt(1.0, Colors.light_sage)
        palette.setBrush(QPalette.Window, QBrush(gradient))
        self.scroll_area.setPalette(palette)

        widget = QWidget()
        self.scroll_area.setWidget(widget)
        self.scroll_area_layout = QVBoxLayout(widget)
        self.scroll_area_layout.setAlignment(Qt.AlignTop)
Exemplo n.º 14
0
    def drawSpan(self, painter, rect):
        opt = QStyleOptionSlider()
        QSlider.initStyleOption(self, opt)

        # area
        groove = self.style().subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderGroove, self)
        if opt.orientation == QtCore.Qt.Horizontal:
            groove.adjust(0, 0, -1, 0)
        else:
            groove.adjust(0, 0, 0, -1)

        # pen & brush
        painter.setPen(QPen(self.gradientLeftColor, 0))
        if opt.orientation == QtCore.Qt.Horizontal:
            self.setupPainter(painter, opt.orientation, groove.center().x(),
                              groove.top(), groove.center().x(),
                              groove.bottom())
        else:
            self.setupPainter(painter, opt.orientation, groove.left(),
                              groove.center().y(), groove.right(),
                              groove.center().y())

        # draw groove
        intersected = QtCore.QRectF(rect.intersected(groove))
        gradient = QLinearGradient(intersected.topLeft(), intersected.topRight())
        gradient.setColorAt(0, self.gradientLeft)
        gradient.setColorAt(1, self.gradientRight)
        painter.fillRect(intersected, gradient)
Exemplo n.º 15
0
    def paintNodeBody(self, painter, lod):
        painter.setPen(Qt.black)

        #Subtle gradient
        if lod > 0.2:
            gradient = QLinearGradient(0, 0, self.nodeBodyWidth,
                                       self.nodeBodyHeight)
            gradient.setColorAt(0, self.nodeBodyColor)
            gradient.setColorAt(1, self.nodeBodyColorGradient)
            brush = QBrush(gradient)
        else:
            brush = QBrush(self.nodeBodyColor)

        if self.hover:
            brush = QBrush(self.nodeBodyColorHover)

        if QGraphicsItem.isSelected(self):
            brush = QBrush(self.nodeBodyColorSelected)

        painter.setBrush(brush)

        if lod > 0.1:
            painter.drawRoundedRect(0, 0, self.nodeBodyWidth,
                                    self.nodeBodyHeight, 10, 5)
        else:
            painter.drawRect(0, 0, self.nodeBodyWidth, self.nodeBodyHeight)
Exemplo n.º 16
0
    def createImage(self, transform):
        scaledRect = transform.mapRect(QRect(0, 0, 25, 25))
        image = QImage(scaledRect.width(), scaledRect.height(),
                       QImage.Format_ARGB32_Premultiplied)
        image.fill(0)
        painter = QPainter(image)
        painter.scale(transform.m11(), transform.m22())
        painter.setRenderHints(QPainter.TextAntialiasing
                               | QPainter.Antialiasing
                               | QPainter.SmoothPixmapTransform)
        painter.setPen(Qt.NoPen)

        if Colors.useEightBitPalette:
            painter.setBrush(QColor(102, 175, 54))
            painter.drawEllipse(0, 0, 25, 25)
            painter.setFont(Colors.tickerFont())
            painter.setPen(QColor(255, 255, 255))
            painter.drawText(10, 15, self.letter)
        else:
            brush = QLinearGradient(0, 0, 0, 25)
            brush.setSpread(QLinearGradient.PadSpread)
            brush.setColorAt(0.0, QColor(102, 175, 54, 200))
            brush.setColorAt(1.0, QColor(102, 175, 54, 60))
            painter.setBrush(brush)
            painter.drawEllipse(0, 0, 25, 25)
            painter.setFont(Colors.tickerFont())
            painter.setPen(QColor(255, 255, 255, 255))
            painter.drawText(10, 15, self.letter)

        return image
Exemplo n.º 17
0
    def drawBackground(self, painter, rect):
        # Shadow.
        sceneRect = self.sceneRect()
        rightShadow = QRectF(sceneRect.right(), sceneRect.top() + 5, 5,
                sceneRect.height())
        bottomShadow = QRectF(sceneRect.left() + 5, sceneRect.bottom(),
                sceneRect.width(), 5)
        if rightShadow.intersects(rect) or rightShadow.contains(rect):
	        painter.fillRect(rightShadow, Qt.darkGray)
        if bottomShadow.intersects(rect) or bottomShadow.contains(rect):
	        painter.fillRect(bottomShadow, Qt.darkGray)

        # Fill.
        gradient = QLinearGradient(sceneRect.topLeft(), sceneRect.bottomRight())
        gradient.setColorAt(0, Qt.white)
        gradient.setColorAt(1, Qt.lightGray)
        painter.fillRect(rect.intersected(sceneRect), QBrush(gradient))
        painter.setBrush(Qt.NoBrush)
        painter.drawRect(sceneRect)

        # Text.
        textRect = QRectF(sceneRect.left() + 4, sceneRect.top() + 4,
                sceneRect.width() - 4, sceneRect.height() - 4)
        message = "Click and drag the nodes around, and zoom with the " \
                "mouse wheel or the '+' and '-' keys"

        font = painter.font()
        font.setBold(True)
        font.setPointSize(14)
        painter.setFont(font)
        painter.setPen(Qt.lightGray)
        painter.drawText(textRect.translated(2, 2), message)
        painter.setPen(Qt.black)
        painter.drawText(textRect, message)
Exemplo n.º 18
0
    def setup_scene(self):
        self.m_scene.setSceneRect(0, 0, MAP_WIDTH, MAP_HEIGHT)

        linear_grad = QLinearGradient(QPointF(-100, -100), QPointF(100, 100))
        linear_grad.setColorAt(0, QColor(255, 255, 255))
        linear_grad.setColorAt(1, QColor(192, 192, 255))
        self.setBackgroundBrush(linear_grad)
Exemplo n.º 19
0
    def getSeries(self):
        # 创建Series
        series0 = QLineSeries(self)
        series1 = QLineSeries(self)

        # 添加数据
        series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) \
                << QPointF(12, 6) << QPointF(16, 7) << QPointF(18, 5)
        series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) \
                << QPointF(12, 3) << QPointF(16, 4) << QPointF(18, 3)

        # 创建区域图
        series = QAreaSeries(series0, series1)
        series.setName('Batman')

        # 画笔
        pen = QPen(0x059605)
        pen.setWidth(3)
        series.setPen(pen)

        # 设置画刷
        gradient = QLinearGradient(QPointF(0, 0), QPointF(0, 1))
        gradient.setColorAt(0.0, QColor(0x3cc63c))
        gradient.setColorAt(1.0, QColor(0x26f626))
        gradient.setCoordinateMode(QGradient.ObjectBoundingMode)
        series.setBrush(gradient)

        return series
Exemplo n.º 20
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        W = self.width()
        H = self.height()
        side = min(W, H)
        rect = QRect((W-side)/2, (H-side)/2, side, side)
        painter.drawRect((rect))
        painter.setViewport(rect)
        painter.setWindow(-100, -100, 200, 200)

        pen = QPen()
        pen.setWidth(1)
        pen.setColor(Qt.blue)
        pen.setStyle(Qt.SolidLine)
        painter.setPen(pen)

        linearGrad = QLinearGradient(0, 0, 100, 0)
        linearGrad.setColorAt(0, Qt.yellow)
        linearGrad.setColorAt(0.8, Qt.green)
        linearGrad.setSpread(QGradient.ReflectSpread)
        painter.setBrush(linearGrad)

        painter.setCompositionMode(QPainter.CompositionMode_Difference)


        for i in range(36):
            painter.drawEllipse(QPoint(50, 0), 50, 50)
            painter.rotate(10)
Exemplo n.º 21
0
    def __init__(self):
        super().__init__()

        # Set layout
        layout = QVBoxLayout(self)
        self.setLayout(layout)

        # Remove margins and spacing
        layout.setContentsMargins(12, 12, 12, 12)
        layout.setSpacing(0)

        # Use a background gradient
        palette = QPalette()
        gradient = QLinearGradient(0, 0, 0, 700)
        gradient.setColorAt(0, QColor('#0093da'))
        gradient.setColorAt(1, QColor('#0c3e75'))
        palette.setBrush(QPalette.Background, QBrush(gradient))
        self.setPalette(palette)
        self.setAutoFillBackground(True)

        # User profile
        self.user_profile = UserProfile()

        # Hide user profile widget until user logs in
        self.user_profile.hide()

        # Add widgets to layout
        layout.addWidget(self.user_profile)

        # Align content to the top of pane
        layout.addStretch()
Exemplo n.º 22
0
    def drawSpan(self, painter, rect):
        opt = QStyleOptionSlider()
        QSlider.initStyleOption(self, opt)

        # area
        groove = self.style().subControlRect(QStyle.CC_Slider, opt,
                                             QStyle.SC_SliderGroove, self)
        if opt.orientation == QtCore.Qt.Horizontal:
            groove.adjust(0, 0, -1, 0)
        else:
            groove.adjust(0, 0, 0, -1)

        # pen & brush
        painter.setPen(QPen(self.gradientLeftColor, 0))
        if opt.orientation == QtCore.Qt.Horizontal:
            self.setupPainter(painter, opt.orientation,
                              groove.center().x(), groove.top(),
                              groove.center().x(), groove.bottom())
        else:
            self.setupPainter(painter, opt.orientation, groove.left(),
                              groove.center().y(), groove.right(),
                              groove.center().y())

        # draw groove
        intersected = QtCore.QRectF(rect.intersected(groove))
        gradient = QLinearGradient(intersected.topLeft(),
                                   intersected.topRight())
        gradient.setColorAt(0, self.gradientLeft)
        gradient.setColorAt(1, self.gradientRight)
        painter.fillRect(intersected, gradient)
Exemplo n.º 23
0
    def ustawgradient(self, x1, y1, x2, y2, r1, g1, b1, r2, g2, b2):
        gradient = QLinearGradient(x1, y1, x2, y2)
        gradient.setColorAt(0, QColor(r1, g1, b1))
        gradient.setColorAt(1, QColor(r2, g2, b2))
        self.kolorW = gradient

        self.update
Exemplo n.º 24
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.º 25
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.º 26
0
    def createImage(self, transform):
        scaledRect = transform.mapRect(QRect(0, 0, 25, 25))
        image = QImage(scaledRect.width(), scaledRect.height(),
                QImage.Format_ARGB32_Premultiplied)
        image.fill(0)
        painter = QPainter(image)
        painter.scale(transform.m11(), transform.m22())
        painter.setRenderHints(QPainter.TextAntialiasing | QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
        painter.setPen(Qt.NoPen)

        if Colors.useEightBitPalette:
            painter.setBrush(QColor(102, 175, 54))
            painter.drawEllipse(0, 0, 25, 25)
            painter.setFont(Colors.tickerFont())
            painter.setPen(QColor(255, 255, 255))
            painter.drawText(10, 15, self.letter)
        else:
            brush = QLinearGradient(0, 0, 0, 25)
            brush.setSpread(QLinearGradient.PadSpread)
            brush.setColorAt(0.0, QColor(102, 175, 54, 200))
            brush.setColorAt(1.0, QColor(102, 175, 54, 60))
            painter.setBrush(brush)
            painter.drawEllipse(0, 0, 25, 25)
            painter.setFont(Colors.tickerFont())
            painter.setPen(QColor(255, 255, 255, 255))
            painter.drawText(10, 15, self.letter)

        return image
Exemplo n.º 27
0
    def __init__(self, parent = None):
        super().__init__(parent)
        self.monitorWin = parent
        if self.monitorWin:
            self.monitorWin.sigTaskUpdating.connect(self.slotTaskUpdate)

        self.scene = QGraphicsScene(self)
        self.scene.setSceneRect(0, 0, self.SIZE[0], self.SIZE[1])
        self.setScene(self.scene)

        self._speedsPen = QPen(Qt.white)

        gradient = QLinearGradient(0, 0, self.SIZE[0], self.SIZE[1])
        gradient.setColorAt(0.0, Qt.darkGreen)
        gradient.setColorAt(1.0, Qt.yellow)
        self._speedsBrush = QBrush(gradient)

        # add elements to the scene
        self._speedsPolygon = self.scene.addPolygon(QPolygonF(),
                                                    self._speedsPen,
                                                    self._speedsBrush)
        self._progressText = self.scene.addText("")
        self._progressText.setPos(10, 0)

        self.setupDropSupport()
Exemplo n.º 28
0
 def getCheckedGradient(button):
     gradient = QLinearGradient(
         QPoint(button.rect().left(), self.menu_height / 2),
         QPoint(button.rect().right(), self.menu_height / 2))
     gradient.setSpread(QGradient.PadSpread)
     gradient.setColorAt(0, self.resource.qt_color_primary_light)
     gradient.setColorAt(1, self.resource.qt_color_gradient_primary)
     return gradient
Exemplo n.º 29
0
 def get_color(self):
     if self.col2 is None:
         return self.col1
     else:
         grad = QLinearGradient(self.x1, self.y1, self.x2, self.y2)
         grad.setColorAt(0, self.col1)
         grad.setColorAt(1, self.col2)
         return grad
Exemplo n.º 30
0
 def _gradient(self):
     gradient = QLinearGradient()
     gradient.setStart(
         (self._bounds.topLeft() + self._bounds.topRight()) / 2)
     gradient.setFinalStop(
         (self._bounds.bottomLeft() + self._bounds.bottomRight()) / 2)
     gradient.setColorAt(0, self._color)
     gradient.setColorAt(1, self._color.darker(200))
     return gradient
Exemplo n.º 31
0
 def get_linear_gradient(self):
     fontHeight = self.fontMetrics().height()
     startPoint = QPoint(self.rect().x(), self.rect().y() + 0.5 * (self.rect().height() - fontHeight))
     endPoint = QPoint(startPoint.x(), startPoint.y() + fontHeight)
     linear = QLinearGradient(startPoint, endPoint)
     colorCounts = len(self.colors)
     for i in range(colorCounts):
         linear.setColorAt(0.2 + i / colorCounts, self.colors[i])
     return linear
Exemplo n.º 32
0
 def setnewtabcolor(self,tab):
     p = QPalette()
     gradient = QLinearGradient(0, 0, 0, 400)
     gradient.setColorAt(0.0, QColor(255,253,253))
     #gradient.setColorAt(1.0, QColor(248, 248, 255))
     gradient.setColorAt(1.0, QColor(255, 225, 225))
     p.setBrush(QPalette.Window, QBrush(gradient))
     tab.setAutoFillBackground(True)
     tab.setPalette(p)
Exemplo n.º 33
0
 def drawCellBackground(self, painter, rect):
     if self.shouldDrawMarkColor:
         markColor = self.glyph.markColor
         if markColor is not None:
             color = colorToQColor(markColor)
             markGradient = QLinearGradient(
                 0, 0, 0, self.height - GlyphCellHeaderHeight)
             markGradient.setColorAt(1.0, color)
             markGradient.setColorAt(0.0, color.lighter(115))
             painter.fillRect(*(rect + (markGradient, )))
Exemplo n.º 34
0
 def setupPainter(self, painter, orientation, x1, y1, x2, y2):
     highlight = self.palette().color(QPalette.Highlight)
     gradient = QLinearGradient(x1, y1, x2, y2)
     gradient.setColorAt(0, highlight.darker(120))
     gradient.setColorAt(1, highlight.lighter(108))
     painter.setBrush(gradient)
     if orientation == Qt.Horizontal:
         painter.setPen(QPen(highlight.darker(130), 0))
     else:
         painter.setPen(QPen(highlight.darker(150), 0))
Exemplo n.º 35
0
 def _draw_overlay(self, painter, draw_width, draw_height, scrolled):
     painter.save()
     rect = QRect(0, 0, draw_width, draw_height)
     painter.translate(0, -scrolled)
     gradient = QLinearGradient(rect.topLeft(), rect.bottomLeft())
     gradient.setColorAt(0, self.palette().color(QPalette.Window))
     gradient.setColorAt(1, self.palette().color(QPalette.Base))
     painter.setBrush(gradient)
     painter.drawRect(rect)
     painter.restore()
Exemplo n.º 36
0
 def paintEvent(self, e):
     """ 绘制遮罩和图标 """
     painter = QPainter(self)
     painter.setPen(Qt.NoPen)
     # 绘制遮罩
     gradientColor = QLinearGradient(0, self.height(), self.width(), 0)
     gradientColor.setColorAt(0, QColor(0, 0, 0, 128))
     gradientColor.setColorAt(1, QColor(0, 0, 0, 0))
     painter.setBrush(QBrush(gradientColor))
     painter.drawRect(self.rect())
Exemplo n.º 37
0
    def drawOutline(self, painter):

        path = QPainterPath()

        path.moveTo(-7.5, 257)
        path.quadTo(-12.5, 263, -12.5, 267.5)
        path.quadTo(-12.5, 278, 0, 280)
        path.quadTo(12.5, 278, 12.5, 267.5)
        path.moveTo(12.5, 267.5)
        path.quadTo(12.5, 263, 7.5, 257)

        path.lineTo(7.5, 25)
        path.quadTo(7.5, 12.5, 0, 12.5)
        path.quadTo(-7.5, 12.5, -7.5, 25)
        path.lineTo(-7.5, 257)

        p1 = QPointF(-2.0, 0)
        p2 = QPointF(12.5, 0)

        linearGrad = QLinearGradient(p1, p2)
        linearGrad.setSpread(QGradient.ReflectSpread)
        linearGrad.setColorAt(1, QColor(0, 150, 255, 170))
        linearGrad.setColorAt(0, QColor(255, 255, 255, 0))

        painter.setBrush(QBrush(linearGrad))
        painter.setPen(Qt.black)
        painter.drawPath(path)

        pen = QPen()
        length = 12

        for i in range(33):

            pen.setWidthF(1.0)
            length = 12

            if i % 4:
                length = 8
                pen.setWidthF(0.8)

            if i % 2:
                length = 5
                pen.setWidthF(0.6)

            painter.setPen(pen)
            painter.drawLine(-7, 28 + i * 7, -7 + length, 28 + i * 7)

        for i in range(9):

            num = self.m_min + i * (self.m_max - self.m_min) / 8
            val = "{0}".format(num)
            fm = painter.fontMetrics()
            size = fm.size(Qt.TextSingleLine, val)
            point = QPointF(OFFSET, 252 - i * 28 + size.width() / 4.0)
            painter.drawText(point, val)
Exemplo n.º 38
0
 def paintEvent(self, event):
     painter = QPainter(self)
     font_metrics = QFontMetrics(self.font())
     if font_metrics.width(self.text()) > self.contentsRect().width():
         label_width = self.size().width()
         fade_start = 1 - 50.0/label_width if label_width > 50 else 0.0
         gradient = QLinearGradient(0, 0, label_width, 0)
         gradient.setColorAt(fade_start, self.palette().color(self.foregroundRole()))
         gradient.setColorAt(1.0, Qt.transparent)
         painter.setPen(QPen(QBrush(gradient), 1.0))
     painter.drawText(self.contentsRect(), Qt.TextSingleLine | int(self.alignment()), self.text())
Exemplo n.º 39
0
    def setupPainter(self, painter, orientation, x1, y1, x2, y2):
        highlight = self.palette().color(QPalette.Highlight)
        gradient = QLinearGradient(x1, y1, x2, y2)
        gradient.setColorAt(0, highlight.darker(120))
        gradient.setColorAt(1, highlight.lighter(108))
        painter.setBrush(gradient)

        if orientation == Qt.Horizontal:
            painter.setPen(QPen(highlight.darker(130), 0))
        else:
            painter.setPen(QPen(highlight.darker(150), 0))
Exemplo n.º 40
0
    def paintEvent(self, _event):
        qp = QPainter(self)

        g = QLinearGradient(0.0, 0.0, 0.0, self.height())
        g.setColorAt(0, Qt.white)
        g.setColorAt(1, Qt.black)

        y = self.height() - self.reflectivity * self.height() / 4095.0

        qp.fillRect(0, 0, self.width(), self.height(), g)
        qp.setPen(Qt.red)
        qp.drawLine(0, y, self.width(), y)
Exemplo n.º 41
0
    def setup_scene(self):
        self.m_scene.setSceneRect(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT)
        self.centerOn(WINDOW_WIDTH/2, WINDOW_HEIGHT/2)

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

        link = Link(parent=self)
        link.move_sprite([WINDOW_WIDTH/2, WINDOW_HEIGHT/2])
        self.m_sprites.append(link)
Exemplo n.º 42
0
    def __init__(self):
        gradient = QLinearGradient(QPointF(50, -20), QPointF(80, 20))
        gradient.setColorAt(0.0, Qt.white)
        gradient.setColorAt(1.0, QColor(0xa6, 0xce, 0x39))

        self.background = QBrush(QColor(64, 32, 64))
        self.circleBrush = QBrush(gradient)
        self.circlePen = QPen(Qt.black)
        self.circlePen.setWidth(1)
        self.textPen = QPen(Qt.white)
        self.textFont = QFont()
        self.textFont.setPixelSize(50)
Exemplo n.º 43
0
class RoundRectItem(QGraphicsObject):
    def __init__(self, bounds, color, parent=None):
        super(RoundRectItem, self).__init__(parent)

        self.fillRect = False
        self.bounds = QRectF(bounds)
        self.pix = QPixmap()

        self.gradient = QLinearGradient()
        self.gradient.setStart(self.bounds.topLeft())
        self.gradient.setFinalStop(self.bounds.bottomRight())
        self.gradient.setColorAt(0, color)
        self.gradient.setColorAt(1, color.darker(200))

        self.setCacheMode(QGraphicsItem.ItemCoordinateCache)

    def setFill(self, fill):
        self.fillRect = fill
        self.update()

    def fill(self):
        return self.fillRect

    fill = pyqtProperty(bool, fill, setFill)

    def paint(self, painter, option, widget):
        painter.setPen(Qt.NoPen)
        painter.setBrush(QColor(0, 0, 0, 64))
        painter.drawRoundedRect(self.bounds.translated(2, 2), 25.0, 25.0)

        if self.fillRect:
            painter.setBrush(QApplication.palette().brush(QPalette.Window))
        else:
            painter.setBrush(self.gradient)

        painter.setPen(QPen(Qt.black, 1))
        painter.drawRoundedRect(self.bounds, 25.0, 25.0)
        if not self.pix.isNull():
            painter.scale(1.95, 1.95)
            painter.drawPixmap(-self.pix.width() / 2, -self.pix.height() / 2, self.pix)

    def boundingRect(self):
        return self.bounds.adjusted(0, 0, 2, 2)

    def pixmap(self):
        return QPixmap(self.pix)

    def setPixmap(self, pixmap):
        self.pix = QPixmap(pixmap)
        self.update()
Exemplo n.º 44
0
    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.fillRect(event.rect(), QBrush(QColor(255, 255, 255, 127)))
        painter.setPen(QPen(Qt.NoPen))

        for i in range(6):
            x_pos = self.width() / 2 + 30 * \
                math.cos(2 * math.pi * i / 6.0) - 10
            y_pos = self.height() / 2 + 30 * \
                math.sin(2 * math.pi * i / 6.0) - 10
            if (self.counter / 5) % 6 == i:
                linear_gradient = QLinearGradient(
                    x_pos + 10, x_pos, y_pos + 10, y_pos)
                linear_gradient.setColorAt(0, QColor(135, 206, 250))
                linear_gradient.setColorAt(1, QColor(0, 0, 128))
                painter.setBrush(QBrush(linear_gradient))
            else:
                linear_gradient = QLinearGradient(
                    x_pos - 10, x_pos, y_pos + 10, y_pos)
                linear_gradient.setColorAt(0, QColor(105, 105, 105))
                linear_gradient.setColorAt(1, QColor(0, 0, 0))
                painter.setBrush(QBrush(linear_gradient))
            painter.drawEllipse(
                x_pos,
                y_pos,
                20, 20)

        painter.end()
Exemplo n.º 45
0
    def createImage(self, transform):
        original = QImage(self.image)
        if original.isNull():
            return original

        size = transform.map(QPoint(self.maxWidth, self.maxHeight))
        w = size.x()
        h = size.y()

        # Optimization: if image is smaller than maximum allowed size, just
        # return the loaded image.
        if original.size().height() <= h and original.size().width() <= w and not self.adjustSize and self.scale == 1:
            return original

        # Calculate what the size of the final image will be.
        w = min(w, float(original.size().width()) * self.scale)
        h = min(h, float(original.size().height()) * self.scale)

        adjustx = 1.0
        adjusty = 1.0
        if self.adjustSize:
            adjustx = min(transform.m11(), transform.m22())
            adjusty = max(transform.m22(), adjustx)
            w *= adjustx
            h *= adjusty

        # Create a new image with correct size, and draw original on it.
        image = QImage(int(w + 2), int(h + 2),
                QImage.Format_ARGB32_Premultiplied)
        image.fill(QColor(0, 0, 0, 0).rgba())
        painter = QPainter(image)
        painter.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
        if self.adjustSize:
            painter.scale(adjustx, adjusty)
        if self.scale != 1:
            painter.scale(self.scale, self.scale)
        painter.drawImage(0, 0, original)

        if not self.adjustSize:
            # Blur out edges.
            blur = 30

            if h < original.height():
                brush1 = QLinearGradient(0, h - blur, 0, h)
                brush1.setSpread(QLinearGradient.PadSpread)
                brush1.setColorAt(0.0, QColor(0, 0, 0, 0))
                brush1.setColorAt(1.0, Colors.sceneBg1)
                painter.fillRect(0, int(h) - blur, original.width(), int(h),
                        brush1)

            if w < original.width():
                brush2 = QLinearGradient(w - blur, 0, w, 0)
                brush2.setSpread(QLinearGradient.PadSpread)
                brush2.setColorAt(0.0, QColor(0, 0, 0, 0))
                brush2.setColorAt(1.0, Colors.sceneBg1)
                painter.fillRect(int(w) - blur, 0, int(w), original.height(),
                        brush2)

        return image
Exemplo n.º 46
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.scale(self.width() / 100.0, self.height() / 100.0)
        painter.translate(50.0, 50.0)
        painter.rotate(-self.rotationAngle)
        painter.translate(-50.0, -50.0)

        painter.setPen(
                QPen(self.penColor, self.penWidth, Qt.SolidLine, Qt.RoundCap,
                        Qt.RoundJoin))
        gradient = QLinearGradient(0, 0, 0, 100)
        gradient.setColorAt(0.0, self.fillColor1)
        gradient.setColorAt(1.0, self.fillColor2)
        painter.setBrush(QBrush(gradient))
        painter.drawPath(self.path)
Exemplo n.º 47
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.º 48
0
    def paint(self, painter, option, widget):
        down = option.state & QStyle.State_Sunken
        r = self.boundingRect()

        grad = QLinearGradient(r.topLeft(), r.bottomRight())
        if option.state & QStyle.State_MouseOver:
            color_0 = Qt.white
        else:
            color_0 = Qt.lightGray

        color_1 = Qt.darkGray

        if down:
            color_0, color_1 = color_1, color_0

        grad.setColorAt(0, color_0)
        grad.setColorAt(1, color_1)

        painter.setPen(Qt.darkGray)
        painter.setBrush(grad)
        painter.drawEllipse(r)

        color_0 = Qt.darkGray
        color_1 = Qt.lightGray

        if down:
            color_0, color_1 = color_1, color_0

        grad.setColorAt(0, color_0)
        grad.setColorAt(1, color_1)

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

        if down:
            painter.translate(2, 2)

        painter.drawEllipse(r.adjusted(5, 5, -5, -5))
        painter.drawPixmap(-self._pix.width() / 2, -self._pix.height() / 2,
                self._pix)
Exemplo n.º 49
0
 def paintEvent(self, evt):
     """
     Protected method handling a paint event.
     
     @param evt reference to the paint event (QPaintEvent)
     """
     if self.__privateMode:
         backgroundColor = QColor(220, 220, 220)     # light gray
         foregroundColor = Qt.black
     else:
         backgroundColor = QApplication.palette().color(QPalette.Base)
         foregroundColor = QApplication.palette().color(QPalette.Text)
     
     if self.__browser is not None:
         p = self.palette()
         progress = self.__browser.progress()
         if progress == 0 or progress == 100:
             if self.__browser.url().scheme() == "https":
                 if QSslCertificate is not None:
                     if self.__browser.page().hasValidSslInfo():
                         backgroundColor = Preferences.getHelp(
                             "SaveUrlColor")
                 else:
                     backgroundColor = Preferences.getHelp("SaveUrlColor")
             p.setBrush(QPalette.Base, backgroundColor)
             p.setBrush(QPalette.Text, foregroundColor)
         else:
             if self.__browser.url().scheme() == "https":
                 if QSslCertificate is not None:
                     if self.__browser.page().hasValidSslInfo():
                         backgroundColor = Preferences.getHelp(
                             "SaveUrlColor")
                 else:
                     backgroundColor = Preferences.getHelp("SaveUrlColor")
             highlight = QApplication.palette().color(QPalette.Highlight)
             r = (highlight.red() + 2 * backgroundColor.red()) // 3
             g = (highlight.green() + 2 * backgroundColor.green()) // 3
             b = (highlight.blue() + 2 * backgroundColor.blue()) // 3
             
             loadingColor = QColor(r, g, b)
             if abs(loadingColor.lightness() -
                     backgroundColor.lightness()) < 20:
                 # special handling for special color schemes (e.g Gaia)
                 r = (2 * highlight.red() + backgroundColor.red()) // 3
                 g = (2 * highlight.green() + backgroundColor.green()) // 3
                 b = (2 * highlight.blue() + backgroundColor.blue()) // 3
                 loadingColor = QColor(r, g, b)
             
             gradient = QLinearGradient(
                 QPointF(0, 0), QPointF(self.width(), 0))
             gradient.setColorAt(0, loadingColor)
             gradient.setColorAt(progress / 100.0 - 0.000001, loadingColor)
             gradient.setColorAt(progress / 100.0, backgroundColor)
             p.setBrush(QPalette.Base, gradient)
         
         self.setPalette(p)
     
     E5LineEdit.paintEvent(self, evt)
Exemplo n.º 50
0
class TuningThermo(QWidget):
    def __init__(self, *args):
        super().__init__(*args)

        self.bar_width = 200 # px
        self.bar_height = 10 # px
        self.border = 3 # px
        self.value = 0
        self.max_value = 1000
        self.min_value = 300

        self.setFixedWidth(self.border + self.bar_width + self.border)
        self.setFixedHeight(self.border + self.bar_height + self.border)
        self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)

        self.gradient = QLinearGradient(0, 0, self.bar_width, 0)
        self.gradient.setColorAt(0, Qt.green)
        self.gradient.setColorAt(1, Qt.red)

    def paintEvent(self, event):
        painter = QPainter(self)
        width = self.width()
        height = self.height()

        painter.fillRect(0, 0, width, height, QColor(245, 245, 245))

        painter.setPen(QColor(190, 190, 190))
        painter.drawRect(0, 0, width - 1, height - 1)

        filled_bar_width = int(round(float(width - self.border * 2 - 1) * self.value / self.max_value + 1))

        painter.fillRect(self.border, self.border, filled_bar_width, height - self.border * 2, self.gradient)

    def set_value(self, value):
        value = value - self.min_value
        self.value = min(max(value, 0), self.max_value-self.min_value)

        self.update()
Exemplo n.º 51
0
    def paintNodeBody(self, painter, lod):
        painter.setPen(Qt.black)
      
        #Subtle gradient
        if lod > 0.2:
            gradient = QLinearGradient(0, 0, self.nodeBodyWidth, self.nodeBodyHeight)
            gradient.setColorAt(0, self.nodeBodyColor)
            gradient.setColorAt(1, self.nodeBodyColorGradient)
            brush = QBrush(gradient)
        else:
            brush = QBrush(self.nodeBodyColor)

        if self.hover:
            brush = QBrush(self.nodeBodyColorHover)

        if QGraphicsItem.isSelected(self):
            brush = QBrush(self.nodeBodyColorSelected)

        painter.setBrush(brush)

        if lod > 0.1:
            painter.drawRoundedRect(0, 0, self.nodeBodyWidth, self.nodeBodyHeight, 10, 5)
        else:
        	painter.drawRect(0, 0, self.nodeBodyWidth, self.nodeBodyHeight)
Exemplo n.º 52
0
    def __init__(self, parent=None):
        ChartView.__init__(self, parent)
        self.dataSource = None
        pen = QPen()
        pen.setColor(QColor(20, 158, 11))
        pen.setWidthF(self.LINE_WIDTH)
        self.linePen = pen

        gradient = QLinearGradient(0, 0, 0, 1)
        gradient.setCoordinateMode(QLinearGradient.ObjectBoundingMode)
        gradient.setColorAt(0, QColor(93, 188, 86)) # dark green
        gradient.setColorAt(1, QColor(164, 216, 158)) # light green
        self.graphBrush = QBrush(gradient)
        gradient = QLinearGradient(0, 0, 0, 1)
        gradient.setCoordinateMode(QLinearGradient.ObjectBoundingMode)
        gradient.setColorAt(0, Qt.darkGray)
        gradient.setColorAt(1, Qt.lightGray)
        self.graphFutureBrush = QBrush(gradient)
Exemplo n.º 53
0
 def paintEvent(self, event):
     color = self.state_colors[self.state]
     painter = QPainter(self)
     painter.setRenderHint(QPainter.Antialiasing, True)
     painter.setCompositionMode(QPainter.CompositionMode_SourceOver)
     gradient = QLinearGradient(0, 0, self.width(), 0)
     gradient.setColorAt(0.0, Qt.transparent)
     gradient.setColorAt(1.0, color)
     painter.setBrush(QBrush(gradient))
     gradient.setColorAt(1.0, color.stroke)
     painter.setPen(QPen(QBrush(gradient), 1))
     painter.drawRoundedRect(-4, 0, self.width()+4, self.height(), 3.7, 3.7)
Exemplo n.º 54
0
    def createImage(self, transform):
        sx = min(transform.m11(), transform.m22())
        sy = max(transform.m22(), sx)
        fm = QFontMetrics(Colors.headingFont())

        w = fm.width(self.text) + 1
        h = fm.height()
        xShadow = 3.0
        yShadow = 3.0

        image = QImage(int((w + xShadow) * sx), int((h + yShadow) * sy),
                QImage.Format_ARGB32_Premultiplied)
        image.fill(QColor(0, 0, 0, 0).rgba())
        painter = QPainter(image)
        painter.setFont(Colors.headingFont())
        painter.scale(sx, sy)

        # Draw shadow.
        brush_shadow = QLinearGradient(xShadow, yShadow, w, yShadow)
        brush_shadow.setSpread(QLinearGradient.PadSpread)
        if Colors.useEightBitPalette:
            brush_shadow.setColorAt(0.0, QColor(0, 0, 0))
        else:
            brush_shadow.setColorAt(0.0, QColor(0, 0, 0, 100))
        pen_shadow = QPen()
        pen_shadow.setBrush(brush_shadow)
        painter.setPen(pen_shadow)
        painter.drawText(int(xShadow), int(yShadow), int(w), int(h),
                Qt.AlignLeft, self.text)

        # Draw text.
        brush_text = QLinearGradient(0, 0, w, w)
        brush_text.setSpread(QLinearGradient.PadSpread)
        brush_text.setColorAt(0.0, QColor(255, 255, 255))
        brush_text.setColorAt(0.2, QColor(255, 255, 255))
        brush_text.setColorAt(0.5, QColor(190, 190, 190))
        pen_text = QPen()
        pen_text.setBrush(brush_text)
        painter.setPen(pen_text)
        painter.drawText(0, 0, int(w), int(h), Qt.AlignLeft, self.text)

        return image
Exemplo n.º 55
0
    def createRoundButtonBackground(self, transform):
        scaledRect = transform.mapRect(QRect(0, 0,
                self.logicalSize.width(), self.logicalSize.height()))

        image = QImage(scaledRect.width(), scaledRect.height(),
                QImage.Format_ARGB32_Premultiplied)
        image.fill(QColor(0, 0, 0, 0).rgba())
        painter = QPainter(image)
        painter.setRenderHint(QPainter.SmoothPixmapTransform)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)

        if Colors.useEightBitPalette:
            painter.setPen(QColor(120, 120, 120))
            if self.pressed:
                painter.setBrush(QColor(60, 60, 60))
            elif self.highlighted:
                painter.setBrush(QColor(100, 100, 100))
            else:
                painter.setBrush(QColor(80, 80, 80))
        else:
            outlinebrush = QLinearGradient(0, 0, 0, scaledRect.height())
            brush = QLinearGradient(0, 0, 0, scaledRect.height())

            brush.setSpread(QLinearGradient.PadSpread)
            highlight = QColor(255, 255, 255, 70)
            shadow = QColor(0, 0, 0, 70)
            sunken = QColor(220, 220, 220, 30)

            if self.type == TextButton.PANEL:
                normal1 = QColor(200, 170, 160, 50)
                normal2 = QColor(50, 10, 0, 50)
            else:
                normal1 = QColor(255, 255, 245, 60)
                normal2 = QColor(255, 255, 235, 10)

            if self.pressed:
                outlinebrush.setColorAt(0, shadow)
                outlinebrush.setColorAt(1, highlight)
                brush.setColorAt(0, sunken)
                painter.setPen(Qt.NoPen)
            else:
                outlinebrush.setColorAt(1, shadow)
                outlinebrush.setColorAt(0, highlight)
                brush.setColorAt(0, normal1)
                if not self.highlighted:
                    brush.setColorAt(1, normal2)
                painter.setPen(QPen(outlinebrush, 1))

            painter.setBrush(brush)

        if self.type == TextButton.PANEL:
            painter.drawRect(0, 0, scaledRect.width(), scaledRect.height())
        else:
            painter.drawRoundedRect(0, 0, scaledRect.width(),
                    scaledRect.height(), 10, 90, Qt.RelativeSize)

        return image
Exemplo n.º 56
0
    def createArrowBackground(self, transform):
        scaledRect = transform.mapRect(QRect(0, 0,
                self.logicalSize.width(), self.logicalSize.height()))

        image = QImage(scaledRect.width(), scaledRect.height(),
                QImage.Format_ARGB32_Premultiplied)
        image.fill(QColor(0, 0, 0, 0).rgba())
        painter = QPainter(image)
        painter.setRenderHint(QPainter.SmoothPixmapTransform)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)

        if Colors.useEightBitPalette:
            painter.setPen(QColor(120, 120, 120))
            if self.pressed:
                painter.setBrush(QColor(60, 60, 60))
            elif self.highlighted:
                painter.setBrush(QColor(100, 100, 100))
            else:
                painter.setBrush(QColor(80, 80, 80))
        else:
            outlinebrush = QLinearGradient(0, 0, 0, scaledRect.height())
            brush = QLinearGradient(0, 0, 0, scaledRect.height())

            brush.setSpread(QLinearGradient.PadSpread)
            highlight = QColor(255, 255, 255, 70)
            shadow = QColor(0, 0, 0, 70)
            sunken = QColor(220, 220, 220, 30)
            normal1 = QColor(200, 170, 160, 50)
            normal2 = QColor(50, 10, 0, 50)

            if self.pressed:
                outlinebrush.setColorAt(0, shadow)
                outlinebrush.setColorAt(1, highlight)
                brush.setColorAt(0, sunken)
                painter.setPen(Qt.NoPen)
            else:
                outlinebrush.setColorAt(1, shadow)
                outlinebrush.setColorAt(0, highlight)
                brush.setColorAt(0, normal1)
                if not self.highlighted:
                    brush.setColorAt(1, normal2)
                painter.setPen(QPen(outlinebrush, 1))

            painter.setBrush(brush);

        painter.drawRect(0, 0, scaledRect.width(), scaledRect.height())

        xOff = scaledRect.width() / 2
        yOff = scaledRect.height() / 2
        sizex = 3.0 * transform.m11()
        sizey = 1.5 * transform.m22()
        if self.type == TextButton.UP:
            sizey *= -1
        path = QPainterPath()
        path.moveTo(xOff, yOff + (5 * sizey))
        path.lineTo(xOff - (4 * sizex), yOff - (3 * sizey))
        path.lineTo(xOff + (4 * sizex), yOff - (3 * sizey))
        path.lineTo(xOff, yOff + (5 * sizey))
        painter.drawPath(path)

        return image
Exemplo n.º 57
0
Arquivo: gui.py Projeto: fqez/sandbox
	def __init__(self, machine, parent=None):
		super(RenderArea, self).__init__(parent)
  
		self.pen = QPen()
		self.brush = QBrush()
		
		self.antialiased = True
  
		self.setBackgroundRole(QPalette.Base)
		self.setAutoFillBackground(True)
		
		self.machine = machine

		self.dist_radius = min(self.width() / 4, self.height() / 4) * 1.5
		self.dist_center = QPoint(self.width() / 2.0, self.height() / 2.0)
		self.n_states = len(self.machine.getStates())

		self.state_radius = self.funcc(self.dist_radius, self.n_states)
		self.active = -1
		self.t_active = -1

		self.pts = []


		#Brushes
		linearGradient = QLinearGradient(-self.state_radius, -self.state_radius, self.state_radius, self.state_radius)
		linearGradient.setColorAt(0.0, Qt.darkGreen)
		linearGradient.setColorAt(0.7, Qt.green)
		linearGradient.setColorAt(0.3, Qt.green)
		linearGradient.setColorAt(1.0, Qt.white)
		self.greenGradientBrush = QBrush(linearGradient)

		linearGradient = QLinearGradient(-self.state_radius, -self.state_radius, self.state_radius, self.state_radius)
		linearGradient.setColorAt(0.0, Qt.darkGray)
		linearGradient.setColorAt(0.7, Qt.lightGray)
		linearGradient.setColorAt(0.3, Qt.gray)
		linearGradient.setColorAt(1.0, Qt.white)
		self.grayGradientBrush = QBrush(linearGradient)
		self.setBrush(self.grayGradientBrush)
Exemplo n.º 58
0
    def paintEvent(self, event):
        option = QStyleOption()
        option.initFrom(self)

        contents_rect = self.style().subElementRect(QStyle.SE_FrameContents, option, self) or self.contentsRect()  # the SE_FrameContents rect is Null unless the stylesheet defines decorations

        if self.graphStyle == self.BarStyle:
            graph_width = self.__dict__['graph_width'] = int(ceil(float(contents_rect.width()) / self.horizontalPixelsPerUnit))
        else:
            graph_width = self.__dict__['graph_width'] = int(ceil(float(contents_rect.width() - 1) / self.horizontalPixelsPerUnit) + 1)

        max_value = self.__dict__['max_value'] = max(chain([0], *(islice(reversed(graph.data), graph_width) for graph in self.graphs if graph.enabled)))

        if self.graphHeight == self.AutomaticHeight or self.graphHeight < 0:
            graph_height = self.__dict__['graph_height'] = max(self.scaler.get_height(max_value), self.minHeight)
        else:
            graph_height = self.__dict__['graph_height'] = max(self.graphHeight, self.minHeight)

        if self.graphStyle == self.BarStyle:
            height_scaling = float(contents_rect.height()) / graph_height
        else:
            height_scaling = float(contents_rect.height() - self.lineThickness) / graph_height

        painter = QStylePainter(self)
        painter.drawPrimitive(QStyle.PE_Widget, option)

        painter.setClipRect(contents_rect)

        painter.save()
        painter.translate(contents_rect.x() + contents_rect.width() - 1, contents_rect.y() + contents_rect.height() - 1)
        painter.scale(-1, -1)

        painter.setRenderHint(QStylePainter.Antialiasing, self.graphStyle != self.BarStyle)

        for graph in (graph for graph in self.graphs if graph.enabled and graph.data):
            if self.boundary is not None and 0 < self.boundary < graph_height:
                boundary_width = min(5.0/height_scaling, self.boundary-0, graph_height-self.boundary)
                pen_color = QLinearGradient(0, (self.boundary - boundary_width) * height_scaling, 0, (self.boundary + boundary_width) * height_scaling)
                pen_color.setColorAt(0, graph.color)
                pen_color.setColorAt(1, graph.over_boundary_color)
                brush_color = QLinearGradient(0, (self.boundary - boundary_width) * height_scaling, 0, (self.boundary + boundary_width) * height_scaling)
                brush_color.setColorAt(0, self.color_with_alpha(graph.color, self.fillTransparency))
                brush_color.setColorAt(1, self.color_with_alpha(graph.over_boundary_color, self.fillTransparency))
            else:
                pen_color = graph.color
                brush_color = self.color_with_alpha(graph.color, self.fillTransparency)
            dataset = islice(reversed(graph.data), graph_width)
            if self.graphStyle == self.BarStyle:
                lines = [QLineF(x*self.horizontalPixelsPerUnit, 0, x*self.horizontalPixelsPerUnit, y*height_scaling) for x, y in enumerate(dataset)]
                painter.setPen(QPen(pen_color, self.lineThickness))
                painter.drawLines(lines)
            else:
                painter.translate(0, +self.lineThickness/2 - 1)

                if self.smoothEnvelope and self.smoothFactor > 0:
                    min_value = 0
                    max_value = graph_height * height_scaling
                    cx_offset = self.horizontalPixelsPerUnit / 3.0
                    smoothness = self.smoothFactor

                    last_values = deque(3*[next(dataset) * height_scaling], maxlen=3)  # last 3 values: 0 last, 1 previous, 2 previous previous

                    envelope = QPainterPath()
                    envelope.moveTo(0, last_values[0])
                    for x, y in enumerate(dataset, 1):
                        x = x * self.horizontalPixelsPerUnit
                        y = y * height_scaling * (1 - smoothness) + last_values[0] * smoothness
                        last_values.appendleft(y)
                        c1x = x - cx_offset * 2
                        c2x = x - cx_offset
                        c1y = limit((1 + smoothness) * last_values[1] - smoothness * last_values[2], min_value, max_value)  # same gradient as previous previous value to previous value
                        c2y = limit((1 - smoothness) * last_values[0] + smoothness * last_values[1], min_value, max_value)  # same gradient as previous value to last value
                        envelope.cubicTo(c1x, c1y, c2x, c2y, x, y)
                else:
                    envelope = QPainterPath()
                    envelope.addPolygon(QPolygonF([QPointF(x*self.horizontalPixelsPerUnit, y*height_scaling) for x, y in enumerate(dataset)]))

                if self.fillEnvelope or graph.fill_envelope:
                    first_element = envelope.elementAt(0)
                    last_element = envelope.elementAt(envelope.elementCount() - 1)
                    fill_path = QPainterPath()
                    fill_path.moveTo(last_element.x, last_element.y)
                    fill_path.lineTo(last_element.x + 1, last_element.y)
                    fill_path.lineTo(last_element.x + 1, -self.lineThickness)
                    fill_path.lineTo(-self.lineThickness, -self.lineThickness)
                    fill_path.lineTo(-self.lineThickness, first_element.y)
                    fill_path.connectPath(envelope)
                    painter.fillPath(fill_path, brush_color)

                painter.strokePath(envelope, QPen(pen_color, self.lineThickness, join=Qt.RoundJoin))

                painter.translate(0, -self.lineThickness/2 + 1)

        if self.boundary is not None and self.boundaryColor:
            painter.setRenderHint(QStylePainter.Antialiasing, False)
            painter.setPen(QPen(self.boundaryColor, 1.0))
            painter.drawLine(0, self.boundary*height_scaling, contents_rect.width(), self.boundary*height_scaling)

        painter.restore()

        # queue the 'updated' signal to be emitted after returning to the main loop
        QMetaObject.invokeMethod(self, 'updated', Qt.QueuedConnection)
Exemplo n.º 59
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)

        redrawRect = event.rect()
        beginRow = redrawRect.top() // self.squareSize
        endRow = redrawRect.bottom() // self.squareSize
        # XXX: do we need to maintain self._column when we have (endColumn -
        # beginColumn)?
        beginColumn = redrawRect.left() // self.squareSize
        endColumn = redrawRect.right() // self.squareSize

        gradient = QLinearGradient(0, 0, 0, GlyphCellHeaderHeight)
        gradient.setColorAt(0.0, cellHeaderBaseColor)
        gradient.setColorAt(1.0, cellHeaderLineColor)
        dirtyGradient = QLinearGradient(0, 0, 0, GlyphCellHeaderHeight)
        dirtyGradient.setColorAt(0.0, cellHeaderBaseColor.darker(125))
        dirtyGradient.setColorAt(1.0, cellHeaderLineColor.darker(125))
        markGradient = QLinearGradient(0, 0, 0, self.squareSize-GlyphCellHeaderHeight)

        for row in range(beginRow, endRow + 1):
            for column in range(beginColumn, endColumn + 1):
                key = row * self._columns + column
                if key >= len(self._glyphs): break
                glyph = self._glyphs[key]

                painter.save()
                painter.translate(column * self.squareSize, row * self.squareSize)
                painter.fillRect(0, 0, self.squareSize, self.squareSize, Qt.white)
                # prepare header colors
                brushColor = gradient
                linesColor = cellHeaderHighlightLineColor
                # mark color
                if not glyph.template:
                    if glyph.markColor is not None:
                        markColor = QColor.fromRgbF(*tuple(glyph.markColor))
                        markGradient.setColorAt(1.0, markColor)
                        markGradient.setColorAt(0.0, markColor.lighter(125))
                        painter.fillRect(0, GlyphCellHeaderHeight, self.squareSize,
                              self.squareSize - GlyphCellHeaderHeight, QBrush(markGradient))
                    if glyph.dirty:
                        brushColor = dirtyGradient
                        linesColor = cellHeaderHighlightLineColor.darker(110)

                # header gradient
                painter.fillRect(0, 0, self.squareSize, GlyphCellHeaderHeight,
                    QBrush(brushColor))
                # header lines
                painter.setPen(linesColor)
                minOffset = painter.pen().width()
                # disable antialiasing to avoid lines bleeding over background
                painter.setRenderHint(QPainter.Antialiasing, False)
                painter.drawLine(0, 0, 0, GlyphCellHeaderHeight - 1)
                painter.drawLine(self.squareSize - 2, 0, self.squareSize - 2, GlyphCellHeaderHeight -1)
                painter.setPen(QColor(170, 170, 170))
                painter.drawLine(0, GlyphCellHeaderHeight, self.squareSize, GlyphCellHeaderHeight)
                painter.setRenderHint(QPainter.Antialiasing)
                # header text
                painter.setFont(headerFont)
                painter.setPen(QColor(80, 80, 80))
                name = metrics.elidedText(glyph.name, Qt.ElideRight, self.squareSize - 2)
                painter.drawText(1, 0, self.squareSize - 2, GlyphCellHeaderHeight - minOffset,
                      Qt.TextSingleLine | Qt.AlignCenter, name)
                painter.restore()

                painter.setPen(cellGridColor)
                rightEdgeX = column * self.squareSize + self.squareSize
                bottomEdgeY = row * self.squareSize + self.squareSize
                painter.drawLine(rightEdgeX, row * self.squareSize + 1, rightEdgeX, bottomEdgeY)
                painter.drawLine(rightEdgeX, bottomEdgeY, column * self.squareSize + 1, bottomEdgeY)
                if self._currentDropIndex is not None:
                    painter.setPen(Qt.green)
                    if self._currentDropIndex == key:
                        painter.drawLine(column * self.squareSize, row * self.squareSize,
                            column * self.squareSize, bottomEdgeY)
                    # special-case the end-column
                    elif column == endColumn and self._currentDropIndex == key+1:
                        yPos = self.mapFromGlobal(QCursor.pos()).y()
                        if row == yPos // self.squareSize:
                            painter.drawLine(rightEdgeX - 1, row * self.squareSize,
                                rightEdgeX - 1, bottomEdgeY)

                # selection code
                if key in self._selection:
                    painter.setRenderHint(QPainter.Antialiasing, False)
                    painter.fillRect(column * self.squareSize + 1,
                            row * self.squareSize + 1, self.squareSize - 3,
                            self.squareSize - 3, cellSelectionColor)
                    painter.setRenderHint(QPainter.Antialiasing)

                if not glyph.template:
                    font = glyph.getParent()
                    outline = glyph.getRepresentation("defconQt.QPainterPath")
                    uPM = font.info.unitsPerEm
                    if uPM is None or not uPM > 0:
                        uPM = 1000
                    descender = font.info.descender
                    if descender is None or not descender < 0:
                        descender = -250
                    factor = (self.squareSize-GlyphCellHeaderHeight) / (uPM*(1+2*GlyphCellBufferHeight))
                    x_offset = (self.squareSize-glyph.width*factor)/2
                    # If the glyph overflows horizontally we need to adjust the scaling factor
                    if x_offset < 0:
                        factor *= 1+2*x_offset/(glyph.width*factor)
                        x_offset = 0
                    # TODO: the * 1.8 below is somewhat artificial
                    y_offset = descender*factor * 1.8
                    painter.save()
                    painter.setClipRect(column * self.squareSize, row * self.squareSize+GlyphCellHeaderHeight,
                          self.squareSize, self.squareSize-GlyphCellHeaderHeight)
                    painter.translate(column * self.squareSize + x_offset, row * self.squareSize + self.squareSize + y_offset)
                    painter.scale(factor, -factor)
                    painter.fillPath(outline, Qt.black)
                    painter.restore()
                else:
                    painter.save()
                    painter.setFont(voidFont)
                    painter.setPen(QPen(Qt.lightGray))
                    rect = QRectF(column * self.squareSize, row * self.squareSize+GlyphCellHeaderHeight,
                          self.squareSize, self.squareSize-GlyphCellHeaderHeight)
                    # TODO: need to flag template glyphs as to whether they have unicodings or not
                    if glyph.unicode is not None:
                        text = chr(glyph.unicode)
                    else:
                        text = "✌"
                    painter.drawText(rect, Qt.AlignCenter, text)
                    painter.restore()