Ejemplo n.º 1
0
    def createImage(self, color, alpha=255):
        self._color = QColor(color)
        self._color.setAlpha(255)
        self._image = QImage(self.size(), QImage.Format_ARGB32)

        painter = QPainter()
        painter.begin(self._image)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
        # 背景色
        painter.fillRect(self.rect(), color)
        # 白色渐变
        gradient = QLinearGradient(0, 0, self.width(), 0)
        gradient.setColorAt(0, Qt.white)
        gradient.setColorAt(1, QColor.fromHslF(0.055, 0.42, 0.65, 0))
        painter.fillRect(self.rect(), gradient)
        # 黑色渐变
        gradient = QLinearGradient(0, self.height(), 0, 0)
        gradient.setColorAt(1, QColor.fromHslF(0.055, 0.42, 0.65, 0))
        gradient.setColorAt(0, Qt.black)
        painter.fillRect(self.rect(), gradient)
        painter.end()

        self.update()

        if self._image and self._pointerPos:
            self.colorChanged.emit(
                self._image.pixelColor(
                    max(min(self._pointerPos.x(),
                            self.width() - 1), 0),
                    max(min(self._pointerPos.y(),
                            self.height() - 1), 0)))
Ejemplo n.º 2
0
 def getColorByValue(self, value):
     """Get QVector4D-color from green (value == 0) to red (value == 1)
     :param value: 0 - 1
     """
     hue = 120 * (1 - value) / 360
     color = QColor.fromHslF(hue, 1, 0.5)
     color_vec = QVector4D(color.redF(), color.greenF(), color.blueF(), 0.5)
     return color_vec
Ejemplo n.º 3
0
def get_foreground_color(color: QColor):
    """Получить цвет текста по цвету фона

    :param color: Цвет фона
    :type color: QColor
    """
    text_color = QColor.fromHslF((color.hslHueF() + 0.5) % 1,
                                 (color.hslSaturationF() + 0.5) % 1,
                                 (color.lightnessF() + 0.5) % 1)
    return text_color
Ejemplo n.º 4
0
 def paintEvent(self, event):
     painter = QPainter(self)
     image = QImage(100, 100, QImage.Format_ARGB32)
     for x in range(100):
         for y in range(100):
             s = x / 100.0
             l = (100 - y) / 100.0
             a = 1.0
             color = QColor.fromHslF(self._hue, s, l, a)
             image.setPixel(x, y, color.rgba())
     painter.drawImage(0, 0, image)
Ejemplo n.º 5
0
 def update_text(self, min_val):
     self.min_val = min_val
     if self.val < self.min_val:
         self.back = QColor(Qt.lightGray)
     else:
         p = (self.val - self.min_val) / (1 - self.min_val)
         hue = 120 / 360 * p
         self.back = QColor.fromHslF(hue, 0.6, 0.5)
     self.front = get_foreground_color(self.back)
     self.setBackground(QBrush(self.back))
     self.setForeground(QBrush(self.front))
     self.setText(str(int(self.val * 100)) + '%')
Ejemplo n.º 6
0
    def updateColor(self, color):
        """Sets the top right color of the panel."""
        color = QColor(color)
        color.setAlpha(255)

        self._color = color
        self._image = QImage(self.size(), QImage.Format_ARGB32)

        painter = SmoothPainter(self._image)

        # Render top right corner
        # Choose brightest, most saturated color for the given hue. Undefined hues (greys) should default to red hue.
        h = max(0, color.hsvHue())
        color_full = QColor.fromHsv(h, 255, 255)
        painter.fillRect(self.rect(), color_full)

        # Create vertical shading
        gradient = QLinearGradient(0, 0, self.width(), 0)
        gradient.setColorAt(0, Qt.white)
        gradient.setColorAt(1, QColor.fromHslF(0.055, 0.42, 0.65, 0))
        painter.fillRect(self.rect(), gradient)

        # Create horizontal shading
        gradient = QLinearGradient(0, self.height(), 0, 0)
        gradient.setColorAt(1, QColor.fromHslF(0.055, 0.42, 0.65, 0))
        gradient.setColorAt(0, Qt.black)
        painter.fillRect(self.rect(), gradient)

        self._createSkinToneIndicator(painter)
        painter.end()

        w, h = self.width(), self.height()
        _, s, v, _ = color.getHsvF()
        x, y = s * w, (1 - v) * h
        self._pointerPos = QPoint(x, y)
        self.update()
Ejemplo n.º 7
0
 def getColor(self, event):
     x = event.pos().x()
     y = event.pos().y()
     if x < 0:
         x = 0
     if x > 100:
         x = 100
     if y < 0:
         y = 0
     if y > 100:
         y = 100
     s = x / 100.0
     l = (100 - y) / 100.0
     a = 1.0
     return QColor.fromHslF(self._hue, s, l, a)
Ejemplo n.º 8
0
 def get_color(self):
     hue = 120 * self.weight / 360
     color = QColor.fromHslF(hue, 1, 0.5)
     return color
Ejemplo n.º 9
0
 def lightnessValueChanged(self, value):
     color = QColor.fromHslF(self.hue.value() / 100.0, self.saturation.value() / 100.0, value / 100.0, 1.0)
     self.setColorParts(color)
     self.colorChanged.emit(color)
Ejemplo n.º 10
0
 def huePicked(self):
     value = self.hueSlider.value()
     self.colorPicker.setHue(value / 100.0)
     color = QColor.fromHslF(value / 100.0, self.saturation.value() / 100.0, self.lightness.value() / 100.0, 1.0)
     self.setColorParts(color)
     self.colorChanged.emit(color)
Ejemplo n.º 11
0
 def hueValueChanged(self, value):
     self.hueSlider.setValue(value)
     color = QColor.fromHslF(value / 100.0, self.saturation.value() / 100.0, self.lightness.value() / 100.0, 1.0)
     self.setColorParts(color)
     self.colorChanged.emit(color)
Ejemplo n.º 12
0
 def hueChanged(self, value):
     self.colorPicker.setHue(value / 100.0)
     color = QColor.fromHslF(value / 100.0, self.saturation.value() / 100.0, self.lightness.value() / 100.0, 1.0)
     self.setColorParts(color)
Ejemplo n.º 13
0
def get_color_by_weight(w: int):
    hue = 120 * w / 360
    color = QColor.fromHslF(hue, 1, 0.5)
    return color