Ejemplo n.º 1
0
    def draw_filled_polygon(self, outline_pen_with=0):
        if not self.scale_polygon_colors == None:
            painter_filled_polygon = QPainter(self)
            painter_filled_polygon.setRenderHint(QPainter.Antialiasing)
            # Koordinatenursprung in die Mitte der Flaeche legen
            painter_filled_polygon.translate(self.width() / 2, self.height() / 2)

            painter_filled_polygon.setPen(Qt.NoPen)

            self.pen.setWidth(outline_pen_with)
            if outline_pen_with > 0:
                painter_filled_polygon.setPen(self.pen)

            colored_scale_polygon = self.create_polygon_pie(
                ((self.widget_diameter / 2) - (self.pen.width() / 2)) * self.gauge_color_outer_radius_factor,
                (((self.widget_diameter / 2) - (self.pen.width() / 2)) * self.gauge_color_inner_radius_factor),
                self.scale_angle_start_value, self.scale_angle_size)

            gauge_rect = QRect(QPoint(0, 0), QSize(self.widget_diameter / 2 - 1, self.widget_diameter - 1))
            grad = QConicalGradient(QPointF(0, 0), - self.scale_angle_size - self.scale_angle_start_value +
                                    self.angle_offset - 1)

            # todo definition scale color as array here
            for eachcolor in self.scale_polygon_colors:
                grad.setColorAt(eachcolor[0], eachcolor[1])
            # grad.setColorAt(.00, Qt.red)
            # grad.setColorAt(.1, Qt.yellow)
            # grad.setColorAt(.15, Qt.green)
            # grad.setColorAt(1, Qt.transparent)
            painter_filled_polygon.setBrush(grad)
            # self.brush = QBrush(QColor(255, 0, 255, 255))
            # painter_filled_polygon.setBrush(self.brush)
            painter_filled_polygon.drawPolygon(colored_scale_polygon)
Ejemplo n.º 2
0
 def rebuildDataBrushIfNeeded(self):
     if not self.m_rebuildBrush or not self.m_gradientData:
         return
     self.m_rebuildBrush = False
     p = self.palette()
     dataBrush = QConicalGradient(QPointF(0.5, 0.5), self.m_nullPosition)
     dataBrush.setCoordinateMode(QGradient.StretchToDeviceMode)
     for i in range(0, len(self.m_gradientData)):
         dataBrush.setColorAt(1 - self.m_gradientData[i][0],
                              self.m_gradientData[i][1])
         p.setBrush(QPalette.Highlight, dataBrush)
     self.setPalette(p)
Ejemplo n.º 3
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(painter.Antialiasing)

        tamanio = self.geometry().size()

        nuevoRect = QtCore.QRect(math.floor(self.anchoLinea / 2), math.floor(self.anchoLinea / 2), tamanio.width() - self.anchoLinea, tamanio.height() - self.anchoLinea)
        verde = QColor()
        verde.setNamedColor("#00FF00")

        amarillo = QColor()
        amarillo.setNamedColor("#FFFF00")

        rojo = QColor()
        rojo.setNamedColor("#FF0000")

        gradiente = QConicalGradient()
        gradiente.setCoordinateMode(QGradient.ObjectBoundingMode)
        gradiente.setAngle(60)
        gradiente.setColorAt(0, rojo)
        gradiente.setColorAt(0.25, amarillo)
        gradiente.setColorAt(0.50, verde)

        colorSeleccionado = QColor()
        colorSeleccionado.setNamedColor(self.colorDial)

        lapizTrazo = QPen()
        lapizTrazo.setStyle(QtCore.Qt.SolidLine)
        lapizTrazo.setWidth(self.anchoLinea)
        lapizTrazo.setBrush(colorSeleccionado)

        porcentaje = self.valor / float(self.maxValor - self.minValor)
        span = math.floor((self.finishAngle - self.startAngle) * porcentaje)

        painter.setPen(lapizTrazo)
        painter.drawArc(nuevoRect, self.startAngle * 16, span * 16)

        super(BKGauge, self).paintEvent(event)
Ejemplo n.º 4
0
    def paintEvent(self, event):
        event.accept()

        painter = QPainter(self)
        painter.save()
        painter.setRenderHint(QPainter.Antialiasing, True)

        if self.fLabel:
            if self.fCustomPaint == self.CUSTOM_PAINT_NULL:
                painter.setPen(self.fColor2)
                painter.setBrush(self.fLabelGradient)
                painter.drawRect(self.fLabelGradientRect)

            painter.setFont(self.fLabelFont)
            painter.setPen(self.fColorT[0 if self.isEnabled() else 1])
            painter.drawText(self.fLabelPos, self.fLabel)

        if self.isEnabled():
            current = float(self.value() - self.minimum())
            divider = float(self.maximum() - self.minimum())

            if divider == 0.0:
                return

            value  = current / divider
            target = QRectF(0.0, 0.0, self.fSize, self.fSize)

            per = int((self.fCount - 1) * value)

            if self.fOrientation == self.HORIZONTAL:
                xpos = self.fSize * per
                ypos = 0.0
            else:
                xpos = 0.0
                ypos = self.fSize * per

            source = QRectF(xpos, ypos, self.fSize, self.fSize)
            painter.drawPixmap(target, self.fPixmap, source)

            # Custom knobs (Dry/Wet and Volume)
            if self.fCustomPaint in (self.CUSTOM_PAINT_CARLA_WET, self.CUSTOM_PAINT_CARLA_VOL):
                # knob color
                colorGreen = QColor(0x5D, 0xE7, 0x3D, 191 + self.fHoverStep*7)
                colorBlue  = QColor(0x3E, 0xB8, 0xBE, 191 + self.fHoverStep*7)

                # draw small circle
                ballRect = QRectF(8.0, 8.0, 15.0, 15.0)
                ballPath = QPainterPath()
                ballPath.addEllipse(ballRect)
                #painter.drawRect(ballRect)
                tmpValue  = (0.375 + 0.75*value)
                ballValue = tmpValue - floor(tmpValue)
                ballPoint = ballPath.pointAtPercent(ballValue)

                # draw arc
                startAngle = 216*16
                spanAngle  = -252*16*value

                if self.fCustomPaint == self.CUSTOM_PAINT_CARLA_WET:
                    painter.setBrush(colorBlue)
                    painter.setPen(QPen(colorBlue, 0))
                    painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.2, 2.2))

                    gradient = QConicalGradient(15.5, 15.5, -45)
                    gradient.setColorAt(0.0,   colorBlue)
                    gradient.setColorAt(0.125, colorBlue)
                    gradient.setColorAt(0.625, colorGreen)
                    gradient.setColorAt(0.75,  colorGreen)
                    gradient.setColorAt(0.76,  colorGreen)
                    gradient.setColorAt(1.0,   colorGreen)
                    painter.setBrush(gradient)
                    painter.setPen(QPen(gradient, 3))

                else:
                    painter.setBrush(colorBlue)
                    painter.setPen(QPen(colorBlue, 0))
                    painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.2, 2.2))

                    painter.setBrush(colorBlue)
                    painter.setPen(QPen(colorBlue, 3))

                painter.drawArc(4.0, 4.0, 26.0, 26.0, startAngle, spanAngle)

            # Custom knobs (L and R)
            elif self.fCustomPaint in (self.CUSTOM_PAINT_CARLA_L, self.CUSTOM_PAINT_CARLA_R):
                # knob color
                color = QColor(0xAD + self.fHoverStep*5, 0xD5 + self.fHoverStep*4, 0x4B + self.fHoverStep*5)

                # draw small circle
                ballRect = QRectF(7.0, 8.0, 11.0, 12.0)
                ballPath = QPainterPath()
                ballPath.addEllipse(ballRect)
                #painter.drawRect(ballRect)
                tmpValue  = (0.375 + 0.75*value)
                ballValue = tmpValue - floor(tmpValue)
                ballPoint = ballPath.pointAtPercent(ballValue)

                painter.setBrush(color)
                painter.setPen(QPen(color, 0))
                painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.0, 2.0))

                # draw arc
                if self.fCustomPaint == self.CUSTOM_PAINT_CARLA_L:
                    startAngle = 216*16
                    spanAngle  = -252.0*16*value
                elif self.fCustomPaint == self.CUSTOM_PAINT_CARLA_R:
                    startAngle = 324.0*16
                    spanAngle  = 252.0*16*(1.0-value)
                else:
                    return

                painter.setPen(QPen(color, 2))
                painter.drawArc(3.5, 4.5, 22.0, 22.0, startAngle, spanAngle)

            if self.HOVER_MIN < self.fHoverStep < self.HOVER_MAX:
                self.fHoverStep += 1 if self.fHovered else -1
                QTimer.singleShot(20, self, SLOT("update()"))

        else: # isEnabled()
            target = QRectF(0.0, 0.0, self.fSize, self.fSize)
            painter.drawPixmap(target, self.fPixmap, target)

        painter.restore()
Ejemplo n.º 5
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)

        if self.m_label:
            painter.setPen(self.m_color2)
            painter.setBrush(self.m_label_gradient)
            painter.drawRect(self.m_label_gradient_rect)

            painter.setPen(self.m_colorT[0] if self.isEnabled() else self.m_colorT[1])
            painter.drawText(self.m_label_pos, self.m_label)

        if self.isEnabled():
            current = float(self.value() - self.minimum())
            divider = float(self.maximum() - self.minimum())

            if divider == 0.0:
                return

            target = QRectF(0.0, 0.0, self.p_size, self.p_size)
            value  = (current / divider)

            ## Regular knobs
            #else:
            per = int((self.p_count - 1) * (current / divider))

            if self.m_orientation == self.HORIZONTAL:
                xpos = self.p_size * per
                ypos = 0.0
            else:
                xpos = 0.0
                ypos = self.p_size * per

            source = QRectF(xpos, ypos, self.p_size, self.p_size)
            painter.drawPixmap(target, self.m_pixmap, source)

            # Custom knobs (Dry/Wet and Volume)
            if self.m_custom_paint in (self.CUSTOM_PAINT_CARLA_WET, self.CUSTOM_PAINT_CARLA_VOL):
                # knob color
                colorGreen = QColor(0x5D, 0xE7, 0x3D, 191 + self.m_hover_step*7)
                colorBlue  = QColor(0x3E, 0xB8, 0xBE, 191 + self.m_hover_step*7)

                #colorGreen = QColor(0x5D + self.m_hover_step*6, 0xE7 + self.m_hover_step*1, 0x3D + self.m_hover_step*5)
                #colorBlue  = QColor(0x52 + self.m_hover_step*8, 0xEE + self.m_hover_step*1, 0xF8 + self.m_hover_step/2)

                # draw small circle
                ballPath = QPainterPath()
                ballRect = QRectF(8.0, 8.0, 15.0, 15.0)
                ballPath.addEllipse(ballRect)
                #painter.drawRect(ballRect)
                ballValue = (0.375 + 0.75*value) % 1.0
                ballPoint = ballPath.pointAtPercent(ballValue)

                # draw arc
                startAngle = 216*16
                spanAngle  = -252.0*16*value

                if self.m_custom_paint == self.CUSTOM_PAINT_CARLA_WET:
                    painter.setBrush(colorBlue)
                    painter.setPen(QPen(colorBlue, 0))
                    painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.2, 2.2))

                    gradient = QConicalGradient(15.5, 15.5, -45)
                    gradient.setColorAt(0.0,   colorBlue)
                    gradient.setColorAt(0.125, colorBlue)
                    gradient.setColorAt(0.625, colorGreen)
                    gradient.setColorAt(0.75,  colorGreen)
                    gradient.setColorAt(0.76,  colorGreen)
                    gradient.setColorAt(1.0,   colorGreen)
                    painter.setBrush(gradient)
                    painter.setPen(QPen(gradient, 3))

                else:
                    painter.setBrush(colorBlue)
                    painter.setPen(QPen(colorBlue, 0))
                    painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.2, 2.2))

                    painter.setBrush(colorBlue)
                    painter.setPen(QPen(colorBlue, 3))

                painter.drawArc(4.0, 4.0, 26.0, 26.0, startAngle, spanAngle)

            # Custom knobs (L and R)
            elif self.m_custom_paint in (self.CUSTOM_PAINT_CARLA_L, self.CUSTOM_PAINT_CARLA_R):
                # knob color
                color = QColor(0xAD + self.m_hover_step*5, 0xD5 + self.m_hover_step*4, 0x4B + self.m_hover_step*5)

                # draw small circle
                ballPath = QPainterPath()
                ballRect = QRectF(7.0, 8.0, 11.0, 12.0)
                ballPath.addEllipse(ballRect)
                #painter.drawRect(ballRect)
                ballValue = (0.375 + 0.75*value) % 1.0
                ballPoint = ballPath.pointAtPercent(ballValue)

                painter.setBrush(color)
                painter.setPen(QPen(color, 0))
                painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.0, 2.0))

                # draw arc
                if self.m_custom_paint == self.CUSTOM_PAINT_CARLA_L:
                    startAngle = 216*16
                    spanAngle  = -252.0*16*value
                elif self.m_custom_paint == self.CUSTOM_PAINT_CARLA_R:
                    startAngle = 324.0*16
                    spanAngle  = 252.0*16*(1.0-value)
                else:
                    return

                painter.setPen(QPen(color, 2))
                painter.drawArc(3.5, 4.5, 22.0, 22.0, startAngle, spanAngle)

            if self.HOVER_MIN < self.m_hover_step < self.HOVER_MAX:
                self.m_hover_step += 1 if self.m_hovered else -1
                QTimer.singleShot(20, self, SLOT("update()"))

        elif not self.m_custom_paint:
            target = QRectF(0.0, 0.0, self.p_size, self.p_size)
            source = target
            painter.drawPixmap(target, self.m_pixmap, source)