From fe3f6108781f384d1ec4abcd775bd657b6b20da9 Mon Sep 17 00:00:00 2001 From: 283375 Date: Fri, 28 Jun 2024 20:05:10 +0800 Subject: [PATCH] core.color --- core/color.py | 10 ++++++++++ ui/extends/shared/color.py | 16 ---------------- .../components/ratingClassRadioButton.py | 4 ++-- 3 files changed, 12 insertions(+), 18 deletions(-) create mode 100644 core/color.py delete mode 100644 ui/extends/shared/color.py diff --git a/core/color.py b/core/color.py new file mode 100644 index 0000000..af27649 --- /dev/null +++ b/core/color.py @@ -0,0 +1,10 @@ +from PySide6.QtGui import QColor + + +def mixColor(source: QColor, mix: QColor, ratio: float = 0.5): + r = round((mix.red() - source.red()) * ratio + source.red()) + g = round((mix.green() - source.green()) * ratio + source.green()) + b = round((mix.blue() - source.blue()) * ratio + source.blue()) + a = round((mix.alpha() - source.alpha()) * ratio + source.alpha()) + + return QColor(r, g, b, a) diff --git a/ui/extends/shared/color.py b/ui/extends/shared/color.py deleted file mode 100644 index 9d36507..0000000 --- a/ui/extends/shared/color.py +++ /dev/null @@ -1,16 +0,0 @@ -from PySide6.QtGui import QColor - - -def mix_color(source_color: QColor, mix_color: QColor, mix_ratio: float = 0.5): - r = round((mix_color.red() - source_color.red()) * mix_ratio + source_color.red()) - g = round( - (mix_color.green() - source_color.green()) * mix_ratio + source_color.green() - ) - b = round( - (mix_color.blue() - source_color.blue()) * mix_ratio + source_color.blue() - ) - a = round( - (mix_color.alpha() - source_color.alpha()) * mix_ratio + source_color.alpha() - ) - - return QColor(r, g, b, a) diff --git a/ui/implements/components/ratingClassRadioButton.py b/ui/implements/components/ratingClassRadioButton.py index be2b2f4..476ddae 100644 --- a/ui/implements/components/ratingClassRadioButton.py +++ b/ui/implements/components/ratingClassRadioButton.py @@ -2,7 +2,7 @@ from PySide6.QtCore import Slot from PySide6.QtGui import QColor from PySide6.QtWidgets import QGraphicsColorizeEffect, QRadioButton -from ui.extends.shared.color import mix_color +from core.color import mixColor STYLESHEET = """ QRadioButton {{ @@ -40,7 +40,7 @@ class RatingClassRadioButton(QRadioButton): def setColors(self, dark_color: QColor, text_color: QColor): self._dark_color = dark_color self._text_color = text_color - self._mid_color = mix_color(dark_color, text_color, 0.616) + self._mid_color = mixColor(dark_color, text_color, 0.616) self.updateEffects() def isColorsSet(self) -> bool: