fix(ui): 换个正常的主页
This commit is contained in:
@@ -745,19 +745,6 @@ class AppConfig:
|
||||
class GlobalConfig(QConfig):
|
||||
"""全局配置"""
|
||||
|
||||
function_HomePage = OptionsConfigItem(
|
||||
"Function",
|
||||
"HomePage",
|
||||
"https://ak.hypergryph.com/news",
|
||||
OptionsValidator(
|
||||
[
|
||||
"https://ak.hypergryph.com/news",
|
||||
"https://ak-webview.hypergryph.com/gameBulletin",
|
||||
"https://ak.hypergryph.com/user/home",
|
||||
"https://prts.wiki/w/%E9%A6%96%E9%A1%B5",
|
||||
]
|
||||
),
|
||||
)
|
||||
function_HistoryRetentionTime = OptionsConfigItem(
|
||||
"Function", "HistoryRetentionTime", 0, OptionsValidator([7, 15, 30, 60, 0])
|
||||
)
|
||||
|
||||
157
app/ui/Widget.py
157
app/ui/Widget.py
@@ -25,9 +25,9 @@ v4.2
|
||||
作者:DLmaster_361
|
||||
"""
|
||||
|
||||
from PySide6.QtCore import Qt, QTime
|
||||
from PySide6.QtGui import QIcon
|
||||
from PySide6.QtWidgets import QWidget, QHBoxLayout
|
||||
from PySide6.QtCore import Qt, QTime, QEvent
|
||||
from PySide6.QtGui import QIcon, QPixmap, QPainter, QPainterPath
|
||||
from qfluentwidgets import (
|
||||
LineEdit,
|
||||
PasswordLineEdit,
|
||||
@@ -47,8 +47,13 @@ from qfluentwidgets import (
|
||||
ConfigItem,
|
||||
TimeEdit,
|
||||
OptionsConfigItem,
|
||||
TeachingTip,
|
||||
TransparentToolButton,
|
||||
TeachingTipTailPosition,
|
||||
)
|
||||
from typing import Union, List
|
||||
from qfluentwidgets.common.overload import singledispatchmethod
|
||||
import os
|
||||
from typing import Optional, Union, List
|
||||
|
||||
from app.services import Crypto
|
||||
|
||||
@@ -373,3 +378,149 @@ class QuantifiedItemCard(CardWidget):
|
||||
self.Layout.addWidget(self.Name)
|
||||
self.Layout.addStretch(1)
|
||||
self.Layout.addWidget(self.Numb)
|
||||
|
||||
|
||||
class IconButton(TransparentToolButton):
|
||||
"""包含下拉框的自定义设置卡片类。"""
|
||||
|
||||
@singledispatchmethod
|
||||
def __init__(self, parent: QWidget = None):
|
||||
TransparentToolButton.__init__(self, parent)
|
||||
|
||||
self._tooltip: Optional[TeachingTip] = None
|
||||
|
||||
@__init__.register
|
||||
def _(self, icon: Union[str, QIcon, FluentIconBase], parent: QWidget = None):
|
||||
self.__init__(parent)
|
||||
self.setIcon(icon)
|
||||
|
||||
@__init__.register
|
||||
def _(
|
||||
self,
|
||||
icon: Union[str, QIcon, FluentIconBase],
|
||||
isTooltip: bool,
|
||||
tip_title: str,
|
||||
tip_content: str,
|
||||
parent: QWidget = None,
|
||||
):
|
||||
self.__init__(parent)
|
||||
self.setIcon(icon)
|
||||
|
||||
# 处理工具提示
|
||||
if isTooltip:
|
||||
self.installEventFilter(self)
|
||||
|
||||
self.tip_title: str = tip_title
|
||||
self.tip_content: str = tip_content
|
||||
|
||||
def eventFilter(self, obj, event: QEvent) -> bool:
|
||||
"""处理鼠标事件。"""
|
||||
if event.type() == QEvent.Type.Enter:
|
||||
self._show_tooltip()
|
||||
elif event.type() == QEvent.Type.Leave:
|
||||
self._hide_tooltip()
|
||||
return super().eventFilter(obj, event)
|
||||
|
||||
def _show_tooltip(self) -> None:
|
||||
"""显示工具提示。"""
|
||||
self._tooltip = TeachingTip.create(
|
||||
target=self,
|
||||
title=self.tip_title,
|
||||
content=self.tip_content,
|
||||
tailPosition=TeachingTipTailPosition.RIGHT,
|
||||
isClosable=False,
|
||||
duration=-1,
|
||||
parent=self,
|
||||
)
|
||||
# 设置偏移
|
||||
if self._tooltip:
|
||||
tooltip_pos = self.mapToGlobal(self.rect().topRight())
|
||||
|
||||
tooltip_pos.setX(
|
||||
tooltip_pos.x() - self._tooltip.size().width() - 40
|
||||
) # 水平偏移
|
||||
tooltip_pos.setY(
|
||||
tooltip_pos.y() - self._tooltip.size().height() / 2 + 35
|
||||
) # 垂直偏移
|
||||
|
||||
self._tooltip.move(tooltip_pos)
|
||||
|
||||
def _hide_tooltip(self) -> None:
|
||||
"""隐藏工具提示。"""
|
||||
if self._tooltip:
|
||||
self._tooltip.close()
|
||||
self._tooltip = None
|
||||
|
||||
def __hash__(self):
|
||||
return id(self)
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, self.__class__):
|
||||
return NotImplemented
|
||||
return self is other
|
||||
|
||||
|
||||
class Banner(QWidget):
|
||||
"""展示带有圆角的固定大小横幅小部件"""
|
||||
|
||||
def __init__(self, image_path: str, parent=None):
|
||||
QWidget.__init__(self, parent)
|
||||
self.image_path = image_path
|
||||
self.banner_image = self.load_banner_image(image_path)
|
||||
self.scaled_image = None
|
||||
self.update_scaled_image()
|
||||
|
||||
def load_banner_image(self, image_path: str):
|
||||
"""加载横幅图片,或创建渐变备用图片"""
|
||||
if os.path.isfile(image_path):
|
||||
return QPixmap(image_path)
|
||||
return self._create_fallback_image()
|
||||
|
||||
def _create_fallback_image(self):
|
||||
"""创建渐变备用图片"""
|
||||
fallback_image = QPixmap(2560, 1280) # 使用原始图片的大小
|
||||
fallback_image.fill(Qt.GlobalColor.gray)
|
||||
return fallback_image
|
||||
|
||||
def update_scaled_image(self):
|
||||
"""按高度缩放图片,宽度保持比例,超出裁剪"""
|
||||
if self.banner_image:
|
||||
self.scaled_image = self.banner_image.scaled(
|
||||
self.size(),
|
||||
Qt.AspectRatioMode.KeepAspectRatioByExpanding,
|
||||
Qt.TransformationMode.SmoothTransformation,
|
||||
)
|
||||
self.update()
|
||||
|
||||
def paintEvent(self, event):
|
||||
"""重载 paintEvent 以绘制缩放后的图片"""
|
||||
if self.scaled_image:
|
||||
painter = QPainter(self)
|
||||
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||
painter.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform)
|
||||
|
||||
# 创建圆角路径
|
||||
path = QPainterPath()
|
||||
path.addRoundedRect(self.rect(), 20, 20)
|
||||
painter.setClipPath(path)
|
||||
|
||||
# 计算绘制位置,使图片居中
|
||||
x = (self.width() - self.scaled_image.width()) // 2
|
||||
y = (self.height() - self.scaled_image.height()) // 2
|
||||
|
||||
# 绘制缩放后的图片
|
||||
painter.drawPixmap(x, y, self.scaled_image)
|
||||
|
||||
def resizeEvent(self, event):
|
||||
"""重载 resizeEvent 以更新缩放后的图片"""
|
||||
self.update_scaled_image()
|
||||
QWidget.resizeEvent(self, event)
|
||||
|
||||
def set_percentage_size(self, width_percentage, height_percentage):
|
||||
"""设置 Banner 的大小为窗口大小的百分比"""
|
||||
parent = self.parentWidget()
|
||||
if parent:
|
||||
new_width = int(parent.width() * width_percentage)
|
||||
new_height = int(parent.height() * height_percentage)
|
||||
self.setFixedSize(new_width, new_height)
|
||||
self.update_scaled_image()
|
||||
|
||||
163
app/ui/home.py
163
app/ui/home.py
@@ -27,41 +27,160 @@ v4.2
|
||||
|
||||
from loguru import logger
|
||||
from PySide6.QtWidgets import (
|
||||
QFrame,
|
||||
QWidget,
|
||||
QVBoxLayout,
|
||||
QHBoxLayout,
|
||||
QSpacerItem,
|
||||
QSizePolicy,
|
||||
)
|
||||
from qframelesswindow.webengine import FramelessWebEngineView
|
||||
from PySide6.QtCore import QUrl
|
||||
from PySide6.QtCore import Qt, QSize, QUrl
|
||||
from PySide6.QtGui import QDesktopServices, QColor
|
||||
from qfluentwidgets import FluentIcon, ScrollArea, SimpleCardWidget
|
||||
|
||||
from app.core import Config
|
||||
from .Widget import Banner, IconButton
|
||||
|
||||
|
||||
class Home(QFrame):
|
||||
class Home(QWidget):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setObjectName("主页")
|
||||
|
||||
widget = Banner(str(Config.app_path / "resources/images/Home.png"))
|
||||
widget.set_percentage_size(
|
||||
0.8, 0.5
|
||||
) # 设置 Banner 大小为窗口的 80% 宽度和 50% 高度
|
||||
|
||||
v_layout = QVBoxLayout(widget)
|
||||
v_layout.setContentsMargins(0, 0, 0, 15)
|
||||
v_layout.setSpacing(5)
|
||||
v_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
|
||||
|
||||
# 空白占位符
|
||||
v_layout.addItem(
|
||||
QSpacerItem(10, 20, QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Minimum)
|
||||
)
|
||||
|
||||
# 顶部部分 (按钮组)
|
||||
h1_layout = QHBoxLayout()
|
||||
h1_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
|
||||
|
||||
# 左边留白区域
|
||||
h1_layout.addStretch()
|
||||
|
||||
# 按钮组
|
||||
buttonGroup = ButtonGroup()
|
||||
buttonGroup.setMaximumHeight(320)
|
||||
h1_layout.addWidget(buttonGroup)
|
||||
|
||||
# 空白占位符
|
||||
h1_layout.addItem(
|
||||
QSpacerItem(20, 10, QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Minimum)
|
||||
)
|
||||
|
||||
# 将顶部水平布局添加到垂直布局
|
||||
v_layout.addLayout(h1_layout)
|
||||
|
||||
# 中间留白区域
|
||||
v_layout.addItem(
|
||||
QSpacerItem(10, 10, QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Minimum)
|
||||
)
|
||||
v_layout.addStretch()
|
||||
|
||||
layout = QVBoxLayout()
|
||||
scrollArea = ScrollArea()
|
||||
scrollArea.setWidgetResizable(True)
|
||||
scrollArea.setWidget(widget)
|
||||
layout.addWidget(scrollArea)
|
||||
self.setLayout(layout)
|
||||
|
||||
|
||||
class ButtonGroup(SimpleCardWidget):
|
||||
"""显示主页和 GitHub 按钮的竖直按钮组"""
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent=parent)
|
||||
self.setObjectName("主界面")
|
||||
|
||||
self.webView = FramelessWebEngineView(self)
|
||||
self.setFixedSize(56, 180)
|
||||
|
||||
self.vBoxLayout = QVBoxLayout(self)
|
||||
self.vBoxLayout.setContentsMargins(0, 0, 0, 0)
|
||||
self.vBoxLayout.addWidget(self.webView)
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setAlignment(Qt.AlignmentFlag.AlignTop)
|
||||
|
||||
self.current_url = None
|
||||
# 创建主页按钮
|
||||
home_button = IconButton(
|
||||
FluentIcon.HOME.icon(color=QColor("#fff")),
|
||||
tip_title="AUTO_MAA官网",
|
||||
tip_content="AUTO_MAA官方文档站",
|
||||
isTooltip=True,
|
||||
)
|
||||
home_button.setIconSize(QSize(32, 32))
|
||||
home_button.clicked.connect(self.open_home)
|
||||
layout.addWidget(home_button)
|
||||
|
||||
self.refresh()
|
||||
# 创建 GitHub 按钮
|
||||
github_button = IconButton(
|
||||
FluentIcon.GITHUB.icon(color=QColor("#fff")),
|
||||
tip_title="Github仓库",
|
||||
tip_content="如果本项目有帮助到您~\n不妨给项目点一个Star⭐",
|
||||
isTooltip=True,
|
||||
)
|
||||
github_button.setIconSize(QSize(32, 32))
|
||||
github_button.clicked.connect(self.open_github)
|
||||
layout.addWidget(github_button)
|
||||
|
||||
def refresh(self):
|
||||
# # 创建 文档 按钮
|
||||
# doc_button = IconButton(
|
||||
# FluentIcon.DICTIONARY.icon(color=QColor("#fff")),
|
||||
# tip_title="自助排障文档",
|
||||
# tip_content="点击打开自助排障文档,好孩子都能看懂",
|
||||
# isTooltip=True,
|
||||
# )
|
||||
# doc_button.setIconSize(QSize(32, 32))
|
||||
# doc_button.clicked.connect(self.open_doc)
|
||||
# layout.addWidget(doc_button)
|
||||
|
||||
if (
|
||||
Config.global_config.get(Config.global_config.function_HomePage)
|
||||
!= self.current_url
|
||||
):
|
||||
# 创建 Q群 按钮
|
||||
doc_button = IconButton(
|
||||
FluentIcon.CHAT.icon(color=QColor("#fff")),
|
||||
tip_title="官方社群",
|
||||
tip_content="加入官方群聊【AUTO_MAA绝赞DeBug中!】",
|
||||
isTooltip=True,
|
||||
)
|
||||
doc_button.setIconSize(QSize(32, 32))
|
||||
doc_button.clicked.connect(self.open_chat)
|
||||
layout.addWidget(doc_button)
|
||||
|
||||
self.webView.load(
|
||||
QUrl(Config.global_config.get(Config.global_config.function_HomePage))
|
||||
)
|
||||
self.current_url = Config.global_config.get(
|
||||
Config.global_config.function_HomePage
|
||||
)
|
||||
# 创建 官方店铺 按钮 (当然没有)
|
||||
doc_button = IconButton(
|
||||
FluentIcon.SHOPPING_CART.icon(color=QColor("#fff")),
|
||||
tip_title="官方店铺",
|
||||
tip_content="暂时没有官方店铺,但是可以加入官方群聊哦~",
|
||||
isTooltip=True,
|
||||
)
|
||||
doc_button.setIconSize(QSize(32, 32))
|
||||
doc_button.clicked.connect(self.open_sales)
|
||||
layout.addWidget(doc_button)
|
||||
|
||||
def _normalBackgroundColor(self):
|
||||
return QColor(0, 0, 0, 96)
|
||||
|
||||
def open_home(self):
|
||||
"""打开主页链接"""
|
||||
QDesktopServices.openUrl(QUrl("https://clozya.github.io/AUTOMAA_docs"))
|
||||
|
||||
def open_github(self):
|
||||
"""打开 GitHub 链接"""
|
||||
QDesktopServices.openUrl(QUrl("https://github.com/DLmaster361/AUTO_MAA"))
|
||||
|
||||
def open_chat(self):
|
||||
"""打开 Q群 链接"""
|
||||
QDesktopServices.openUrl(QUrl("https://qm.qq.com/q/bd9fISNoME"))
|
||||
|
||||
def open_doc(self):
|
||||
"""打开 文档 链接"""
|
||||
QDesktopServices.openUrl(QUrl("https://clozya.github.io/AUTOMAA_docs"))
|
||||
|
||||
def open_sales(self):
|
||||
"""其实还是打开 Q群 链接"""
|
||||
QDesktopServices.openUrl(QUrl("https://qm.qq.com/q/bd9fISNoME"))
|
||||
|
||||
@@ -125,9 +125,6 @@ class AUTO_MAA(MSFluentWindow):
|
||||
FluentIcon.SETTING,
|
||||
NavigationItemPosition.BOTTOM,
|
||||
)
|
||||
self.stackedWidget.currentChanged.connect(
|
||||
lambda index: (self.home.refresh() if index == 0 else None)
|
||||
)
|
||||
self.stackedWidget.currentChanged.connect(
|
||||
lambda index: (self.member_manager.refresh() if index == 1 else None)
|
||||
)
|
||||
|
||||
@@ -60,14 +60,8 @@ class Setting(QWidget):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.setObjectName("设置")
|
||||
|
||||
layout = QVBoxLayout()
|
||||
|
||||
scrollArea = ScrollArea()
|
||||
scrollArea.setWidgetResizable(True)
|
||||
|
||||
content_widget = QWidget()
|
||||
content_layout = QVBoxLayout(content_widget)
|
||||
|
||||
@@ -94,10 +88,11 @@ class Setting(QWidget):
|
||||
content_layout.addWidget(self.updater)
|
||||
content_layout.addWidget(self.other)
|
||||
|
||||
scrollArea = ScrollArea()
|
||||
scrollArea.setWidgetResizable(True)
|
||||
scrollArea.setWidget(content_widget)
|
||||
|
||||
layout = QVBoxLayout()
|
||||
layout.addWidget(scrollArea)
|
||||
|
||||
self.setLayout(layout)
|
||||
|
||||
def agree_bilibili(self) -> None:
|
||||
@@ -414,18 +409,6 @@ class FunctionSettingCard(HeaderCardWidget):
|
||||
super().__init__(parent)
|
||||
self.setTitle("功能")
|
||||
|
||||
self.card_HomePage = ComboBoxSettingCard(
|
||||
configItem=Config.global_config.function_HomePage,
|
||||
icon=FluentIcon.PAGE_RIGHT,
|
||||
title="主页内容",
|
||||
content="选择AUTO_MAA主页展示的内容",
|
||||
texts=[
|
||||
"明日方舟官网情报",
|
||||
"明日方舟游戏公告",
|
||||
"明日方舟个人中心",
|
||||
"PRTS百科网站首页",
|
||||
],
|
||||
)
|
||||
self.card_HistoryRetentionTime = ComboBoxSettingCard(
|
||||
configItem=Config.global_config.function_HistoryRetentionTime,
|
||||
icon=FluentIcon.PAGE_RIGHT,
|
||||
@@ -448,7 +431,6 @@ class FunctionSettingCard(HeaderCardWidget):
|
||||
)
|
||||
|
||||
Layout = QVBoxLayout()
|
||||
Layout.addWidget(self.card_HomePage)
|
||||
Layout.addWidget(self.card_HistoryRetentionTime)
|
||||
Layout.addWidget(self.card_IfAllowSleep)
|
||||
Layout.addWidget(self.card_IfSilence)
|
||||
|
||||
1
main.py
1
main.py
@@ -45,7 +45,6 @@ def main():
|
||||
|
||||
window = AUTO_MAA()
|
||||
window.show_ui("显示主窗口")
|
||||
window.setMicaEffectEnabled(True)
|
||||
window.start_up_task()
|
||||
sys.exit(application.exec())
|
||||
|
||||
|
||||
BIN
resources/images/Home.png
Normal file
BIN
resources/images/Home.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 MiB |
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"main_version": "4.2.4.3",
|
||||
"main_version": "4.2.4.4",
|
||||
"updater_version": "1.1.2.0",
|
||||
"announcement": "\n## 新增功能\n- 历史记录统计功能上线\n- 添加软件主页\n- 添加启动时直接最小化功能\n## 修复BUG\n- 更新器修正`channel`\n## 程序优化\n- 添加MAA监测字段:`未检测到任何模拟器`\n- 取消MAA运行中自动更新",
|
||||
"proxy_list": [
|
||||
|
||||
Reference in New Issue
Block a user