mirror of
https://github.com/KenanZhu/AutoLibrary.git
synced 2026-06-18 07:23:03 +08:00
feat(theme): 新增 BlueForest 官方深色主题样式
- 新增 BlueForest.qss,基于 Fusion 控件规格的纯配色深色主题 - 深蓝底色 + 亮青绿强调色,控件尺寸与 Fusion 风格保持一致 - 全局统一 selection-background-color 为 #2dd4bf - 背景色分层:页面 > 头部栏 > 交互控件 > 弹出层 > 输入区 - Border 属性统一拆分为 style/color/width 三段式 - AppInitializer / ALSettingsWidget 配合主题加载 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+31
-18
@@ -26,7 +26,6 @@ from PySide6.QtWidgets import (
|
||||
QApplication,
|
||||
QFileDialog,
|
||||
QMessageBox,
|
||||
QStyle,
|
||||
QStyleFactory,
|
||||
QWidget
|
||||
)
|
||||
@@ -40,6 +39,16 @@ from interfaces.ConfigProvider import (
|
||||
)
|
||||
|
||||
|
||||
_active_style_name = ""
|
||||
|
||||
|
||||
def _setActiveStyleName(
|
||||
name: str
|
||||
):
|
||||
|
||||
global _active_style_name
|
||||
_active_style_name = name
|
||||
|
||||
def _clearQss(
|
||||
):
|
||||
|
||||
@@ -76,6 +85,7 @@ def _applyTheme(
|
||||
theme: str
|
||||
):
|
||||
|
||||
global _active_style_name
|
||||
app : QApplication | None = QApplication.instance()
|
||||
if not app:
|
||||
return
|
||||
@@ -85,7 +95,7 @@ def _applyTheme(
|
||||
app.styleHints().setColorScheme(Qt.ColorScheme.Light)
|
||||
else:
|
||||
app.styleHints().setColorScheme(Qt.ColorScheme.Unknown)
|
||||
app.setStyle(QStyleFactory.create(app.style().objectName()))
|
||||
app.setStyle(QStyleFactory.create(_active_style_name))
|
||||
|
||||
def _restartApp(
|
||||
):
|
||||
@@ -104,7 +114,7 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
|
||||
):
|
||||
super().__init__(parent)
|
||||
self.__cfg_mgr: ConfigProvider = ConfigManager.instance()
|
||||
self.__original_style: QStyle | None = None
|
||||
self.__original_style: str = ""
|
||||
|
||||
self.setupUi(self)
|
||||
self.modifyUi()
|
||||
@@ -137,6 +147,12 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
|
||||
self.StyleComboBox.clear()
|
||||
self.StyleComboBox.addItems(QStyleFactory.keys())
|
||||
|
||||
def currentStyleKey(
|
||||
self
|
||||
) -> str:
|
||||
|
||||
return _active_style_name
|
||||
|
||||
def connectSignals(
|
||||
self
|
||||
):
|
||||
@@ -184,7 +200,7 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
|
||||
theme = self.__cfg_mgr.get(CfgKey.GLOBAL.APPEARANCE.THEME, "system")
|
||||
style = self.__cfg_mgr.get(CfgKey.GLOBAL.APPEARANCE.STYLE, "Fusion")
|
||||
custom_qss = self.__cfg_mgr.get(CfgKey.GLOBAL.APPEARANCE.CUSTOM_QSS, "")
|
||||
self.__original_style = QApplication.instance().style()
|
||||
self.__original_style = self.currentStyleKey()
|
||||
if theme == "light":
|
||||
self.LightThemeRadio.setChecked(True)
|
||||
elif theme == "dark":
|
||||
@@ -192,10 +208,9 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
|
||||
else:
|
||||
self.SystemThemeRadio.setChecked(True)
|
||||
index = self.StyleComboBox.findText(style)
|
||||
if index >= 0:
|
||||
self.StyleComboBox.setCurrentIndex(index)
|
||||
else:
|
||||
self.StyleComboBox.setCurrentIndex(0)
|
||||
if index < 0:
|
||||
index = 0
|
||||
self.StyleComboBox.setCurrentIndex(index)
|
||||
self.QssPathEdit.setText(custom_qss)
|
||||
self.updateQssStatus(custom_qss)
|
||||
|
||||
@@ -205,7 +220,8 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
|
||||
):
|
||||
|
||||
if qss_path and os.path.isfile(qss_path):
|
||||
self.QssStatusLabel.setText(f"已加载自定义样式文件:{qss_path}")
|
||||
filename = os.path.basename(qss_path)
|
||||
self.QssStatusLabel.setText(f"已加载自定义样式文件:{filename}")
|
||||
else:
|
||||
self.QssStatusLabel.setText("当前使用程序默认外观。")
|
||||
|
||||
@@ -219,7 +235,7 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
|
||||
theme = "dark"
|
||||
else:
|
||||
theme = "system"
|
||||
style = QStyleFactory.create(self.StyleComboBox.currentText())
|
||||
style = self.StyleComboBox.currentText()
|
||||
custom_qss = self.QssPathEdit.text().strip()
|
||||
return theme, style, custom_qss
|
||||
|
||||
@@ -229,16 +245,13 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
|
||||
|
||||
theme, style, custom_qss = self.collectSettings()
|
||||
self.__cfg_mgr.set(CfgKey.GLOBAL.APPEARANCE.THEME, theme)
|
||||
self.__cfg_mgr.set(CfgKey.GLOBAL.APPEARANCE.STYLE, style.name())
|
||||
self.__cfg_mgr.set(CfgKey.GLOBAL.APPEARANCE.STYLE, style)
|
||||
self.__cfg_mgr.set(CfgKey.GLOBAL.APPEARANCE.CUSTOM_QSS, custom_qss)
|
||||
if custom_qss and os.path.isfile(custom_qss):
|
||||
_applyQss(custom_qss)
|
||||
else:
|
||||
_clearQss()
|
||||
_applyQss(custom_qss)
|
||||
_applyTheme(theme)
|
||||
self.setNavigationIcons()
|
||||
self.updateQssStatus(custom_qss)
|
||||
self.__original_style = QApplication.instance().style()
|
||||
self.__original_style = self.currentStyleKey()
|
||||
|
||||
def maybeRestart(
|
||||
self
|
||||
@@ -322,7 +335,7 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
|
||||
):
|
||||
|
||||
_, style, _ = self.collectSettings()
|
||||
style_changed = self.__original_style.name() != style.name()
|
||||
style_changed = self.__original_style != style
|
||||
self.saveAndApply()
|
||||
if style_changed:
|
||||
self.maybeRestart()
|
||||
@@ -333,7 +346,7 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
|
||||
):
|
||||
|
||||
_, style, _ = self.collectSettings()
|
||||
style_changed = self.__original_style.name() != style.name()
|
||||
style_changed = self.__original_style != style
|
||||
self.saveAndApply()
|
||||
if style_changed:
|
||||
self.maybeRestart()
|
||||
|
||||
Reference in New Issue
Block a user