Skip to content

Commit

Permalink
给死亡数字标签颜色提供用户自定义设置 (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzaphkiel committed Nov 21, 2024
1 parent b281964 commit fc07a64
Show file tree
Hide file tree
Showing 11 changed files with 424 additions and 99 deletions.
5 changes: 5 additions & 0 deletions app/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class Config(QConfig):
remakeCardColor = ColorConfigItem(
"Personalization", "RemakeCardColor", '#28a2a2a2')

lightDeathsNumberColor = ColorConfigItem(
"Personalization", "LightDeathsNumberColor", "#ffb60000")
darkDeathsNumberColor = ColorConfigItem(
"Personalization", "DarkDeathsNumberColor", "#ffff8d8d")

careerGamesNumber = RangeConfigItem("Functions", "CareerGamesNumber", 20,
RangeValidator(10, 100))
apiConcurrencyNumber = RangeConfigItem("Functions", "ApiConcurrencyNumber", 1,
Expand Down
1 change: 1 addition & 0 deletions app/common/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Icon(FluentIconBase, Enum):
WINDOW = "Window"
ERASER = "Eraser"
ATTACHTEXT = "AttachText"
TEXTCOLOR = "TextColor"

def path(self, theme=Theme.AUTO):
return f'./app/resource/icons/{self.value}_{getIconColor(theme)}.svg'
33 changes: 32 additions & 1 deletion app/common/style_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

from PyQt5.QtGui import QColor, QClipboard
from PyQt5.QtCore import QObject
from app.common.qfluentwidgets import StyleSheetBase, Theme, qconfig, isDarkTheme
from app.common.qfluentwidgets import (StyleSheetBase, Theme, qconfig, isDarkTheme,
themeColor)

from app.common.config import cfg
from app.common.signals import signalBus
Expand Down Expand Up @@ -223,6 +224,36 @@ def __getTier5Color():
return __getStyleSheetColor(color)


@colorManager.registerColor("deaths")
def __getDeathsNumberColor():
if isDarkTheme():
color = cfg.get(cfg.darkDeathsNumberColor)
else:
color = cfg.get(cfg.lightDeathsNumberColor)

return __getStyleSheetColor(color)


@colorManager.registerColor("deathsLight")
def __getDeathsNumberColor():
color = cfg.get(cfg.lightDeathsNumberColor)

return __getStyleSheetColor(color)


@colorManager.registerColor("deathsDark")
def __getDeathsNumberColor():
color = cfg.get(cfg.darkDeathsNumberColor)

return __getStyleSheetColor(color)


@colorManager.registerColor("theme")
def __getThemeColor():
color = themeColor()
return __getStyleSheetColor(color)


def __getStyleSheetColor(color: QColor):
'''
返回主颜色、鼠标悬停颜色、鼠标按下颜色以及边框颜色
Expand Down
17 changes: 3 additions & 14 deletions app/components/color_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,12 @@ def __init__(self, text: str = None, type: str = None, parent=None):
ColorChangeable.__init__(self, type)

def setColor(self, c1, c2, c3, c4):
self.setStyleSheet(f"ColorLabel {{color: {c1.name()}}}")
self.setStyleSheet(f"ColorLabel {{color: {c1.name()};}}")


class DeathsLabel(ColorLabel):
def __init__(self, text: str = None, parent=None):
super().__init__(text=text, type='lose', parent=parent)
super().__init__(text=text, type='deaths', parent=parent)

def setColor(self, c1: QColor, c2, c3, c4):
r, g, b, a = c1.getRgb()

if isDarkTheme():
r = int(min(255, (r+50)*1.4))
g = int(min(255, (g+50)*1.4))
b = int(min(255, (b+50)*1.4))
else:
r = int(min(255, r*0.9))
g = int(min(255, g*0.9))
b = int(min(255, b*0.9))

self.setStyleSheet(f"ColorLabel {{color: rgb({r}, {g}, {b});}}")
self.setStyleSheet(f"DeathsLabel {{color: {c1.name()};}}")
216 changes: 212 additions & 4 deletions app/components/setting_cards.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# coding:utf-8
from typing import Union

from app.common.qfluentwidgets import (
FluentIconBase, ExpandGroupSettingCard, ConfigItem, qconfig, PushButton, SpinBox,
ColorDialog, LineEdit, SwitchButton, IndicatorPosition, setCustomStyleSheet,
SwitchSettingCard, TransparentToolButton, FluentIcon)
from app.common.qfluentwidgets import (FluentIconBase, ExpandGroupSettingCard,
ConfigItem, qconfig, PushButton, SpinBox,
ColorDialog, LineEdit, SwitchButton,
IndicatorPosition, setCustomStyleSheet, SwitchSettingCard, TransparentToolButton, FluentIcon, setThemeColor)
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QIcon, QColor
from PyQt5.QtWidgets import (QWidget, QLabel, QHBoxLayout, QGridLayout, QFrame, QPushButton,
Expand Down Expand Up @@ -221,6 +221,214 @@ def __reset(self):
signalBus.customColorChanged.emit('remake')


class DeathsNumberColorSettingCard(ExpandGroupSettingCard):
def __init__(self, title, content=None, lightConfigItem: ConfigItem = None,
darkConfigItem: ConfigItem = None, parent=None):
super().__init__(Icon.TEXTCOLOR, title, content, parent)

self.statusLabel = QLabel(self)

self.inputWidget = QWidget(self.view)
self.inputLayout = QGridLayout(self.inputWidget)

self.lightHintLabel = QLabel(self.tr("Color in Light theme:"))
self.darkHintLabel = QLabel(self.tr("Color in Dark theme:"))

self.lightSettingButton = ColorAnimationFrame(type='deathsLight')
self.darkSettingButton = ColorAnimationFrame(type='deathsDark')

self.resetWidget = QWidget()
self.resetLayout = QHBoxLayout(self.resetWidget)
self.resetButton = PushButton(self.tr("Reset"))

self.defaultLightColor = QColor(lightConfigItem.defaultValue)
self.defaultDarkColor = QColor(darkConfigItem.defaultValue)

self.lightConfigItem = lightConfigItem
self.darkConfigItem = darkConfigItem

self.__initWidget()
self.__initLayout()

def __initLayout(self):
self.addWidget(self.statusLabel)

self.inputLayout.setSpacing(19)
self.inputLayout.setAlignment(Qt.AlignTop)
self.inputLayout.setContentsMargins(48, 18, 44, 18)

self.inputLayout.addWidget(
self.lightHintLabel, 0, 0, alignment=Qt.AlignLeft)
self.inputLayout.addWidget(
self.darkHintLabel, 1, 0, alignment=Qt.AlignLeft)

self.inputLayout.addWidget(
self.lightSettingButton, 0, 1, alignment=Qt.AlignRight)
self.inputLayout.addWidget(
self.darkSettingButton, 1, 1, alignment=Qt.AlignRight)

self.inputLayout.setSizeConstraint(QHBoxLayout.SetMinimumSize)

self.resetLayout.setContentsMargins(48, 18, 44, 18)
self.resetLayout.addWidget(self.resetButton, 0, Qt.AlignRight)
self.resetLayout.setSizeConstraint(QHBoxLayout.SetMinimumSize)

self.viewLayout.setSpacing(0)
self.viewLayout.setContentsMargins(0, 0, 0, 0)
self.addGroupWidget(self.inputWidget)
self.addGroupWidget(self.resetWidget)

def __initWidget(self):
self.lightSettingButton.setFixedSize(100, 32)
self.darkSettingButton.setFixedSize(100, 32)

self.resetButton.setMinimumWidth(100)

self.setValue(qconfig.get(self.lightConfigItem),
qconfig.get(self.darkConfigItem))

self.lightSettingButton.clicked.connect(
lambda: self.__onSettingButtonClicked('deathsLight'))
self.darkSettingButton.clicked.connect(
lambda: self.__onSettingButtonClicked('deathsDark'))

self.resetButton.clicked.connect(self.__reset)

def setValue(self, lightColor: QColor = None, darkColor: QColor = None):
if lightColor:
qconfig.set(self.lightConfigItem, lightColor)

if darkColor:
qconfig.set(self.darkConfigItem, darkColor)

self.__setStatusLabel()

def __setStatusLabel(self):
if (qconfig.get(self.lightConfigItem) == self.defaultLightColor and
qconfig.get(self.darkConfigItem) == self.defaultDarkColor):
self.statusLabel.setText(self.tr("Default color"))
self.resetButton.setEnabled(False)
else:
self.statusLabel.setText(self.tr("Custom color"))
self.resetButton.setEnabled(True)

def __onSettingButtonClicked(self, name):
if name == 'deathsLight':
configItem = self.lightConfigItem
elif name == 'deathsDark':
configItem = self.darkConfigItem

w = ColorDialog(
qconfig.get(configItem), self.tr('Choose color'), self.window())
w.colorChanged.connect(
lambda color: self.__onColorChanged(color, name))
w.exec()

def __onColorChanged(self, color, name):
if name == 'deathsLight':
self.setValue(lightColor=color)
elif name == 'deathsDark':
self.setValue(darkColor=color)

signalBus.customColorChanged.emit(name)
signalBus.customColorChanged.emit("deaths")

def __reset(self):
self.setValue(self.defaultLightColor, self.defaultDarkColor)

signalBus.customColorChanged.emit('deathsLight')
signalBus.customColorChanged.emit('deathsDark')
signalBus.customColorChanged.emit("deaths")


class ThemeColorSettingCard(ExpandGroupSettingCard):
def __init__(self, title, content=None,
colorConfigItem: ConfigItem = None,
parent=None):
super().__init__(Icon.PALETTE, title, content, parent)

self.statusLabel = QLabel(self)

self.inputWidget = QWidget(self.view)
self.inputLayout = QGridLayout(self.inputWidget)

self.colorHintLabel = QLabel(self.tr("Theme color:"))

self.colorSettingButton = ColorAnimationFrame(type='theme')

self.resetWidget = QWidget()
self.resetLayout = QHBoxLayout(self.resetWidget)
self.resetButton = PushButton(self.tr("Reset"))

self.defaultColor = QColor(colorConfigItem.defaultValue)

self.colorConfigItem = colorConfigItem

self.__initWidget()
self.__initLayout()

def __initLayout(self):
self.addWidget(self.statusLabel)

self.inputLayout.setSpacing(19)
self.inputLayout.setAlignment(Qt.AlignTop)
self.inputLayout.setContentsMargins(48, 18, 44, 18)

self.inputLayout.addWidget(
self.colorHintLabel, 0, 0, alignment=Qt.AlignLeft)

self.inputLayout.addWidget(
self.colorSettingButton, 0, 1, alignment=Qt.AlignRight)
self.inputLayout.setSizeConstraint(QHBoxLayout.SetMinimumSize)

self.resetLayout.setContentsMargins(48, 18, 44, 18)
self.resetLayout.addWidget(self.resetButton, 0, Qt.AlignRight)
self.resetLayout.setSizeConstraint(QHBoxLayout.SetMinimumSize)

self.viewLayout.setSpacing(0)
self.viewLayout.setContentsMargins(0, 0, 0, 0)
self.addGroupWidget(self.inputWidget)
self.addGroupWidget(self.resetWidget)

def __initWidget(self):
self.colorSettingButton.setFixedSize(100, 32)
self.resetButton.setMinimumWidth(100)

self.setValue(qconfig.get(self.colorConfigItem))

self.colorSettingButton.clicked.connect(self.__onSettingButtonClicked)
self.resetButton.clicked.connect(
lambda: self.__onColorChanged(self.defaultColor))

def setValue(self, color):
qconfig.set(self.colorConfigItem, color)

self.__setStatusLabel()

def __setStatusLabel(self):
if qconfig.get(self.colorConfigItem) == self.defaultColor:
self.statusLabel.setText(self.tr("Default color"))
self.resetButton.setEnabled(False)
else:
self.statusLabel.setText(self.tr("Custom color"))
self.resetButton.setEnabled(True)

def __onSettingButtonClicked(self):
configItem = self.colorConfigItem

w = ColorDialog(
qconfig.get(configItem), self.tr('Choose color'), self.window(), False)
w.colorChanged.connect(self.__onColorChanged)

w.exec()

def __onColorChanged(self, color):
self.setValue(color=color)

signalBus.customColorChanged.emit('theme')
setThemeColor(color)


class ProxySettingCard(ExpandGroupSettingCard):
def __init__(self, title, content, enableConfigItem: ConfigItem = None,
addrConfigItem: ConfigItem = None, parent=None):
Expand Down
Binary file modified app/resource/i18n/Seraphine.zh_CN.qm
Binary file not shown.
Loading

0 comments on commit fc07a64

Please sign in to comment.