Skip to content

Commit

Permalink
重写生涯界面表格样式的实现
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzaphkiel committed Sep 13, 2023
1 parent 3742acf commit 1eef889
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 33 deletions.
71 changes: 40 additions & 31 deletions app/view/career_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
QSizePolicy, QTableWidgetItem, QHeaderView,
QWidget, QFrame, QStackedWidget)
from PyQt5.QtCore import Qt, pyqtSignal
from qfluentwidgets import (ScrollArea, TableWidget, Theme, PushButton,
ComboBox, SmoothScrollArea, ToolTipFilter,
from qfluentwidgets import (ScrollArea, TableWidget, Theme, PushButton, ComboBox,
SmoothScrollArea, ToolTipFilter, setCustomStyleSheet,
ToolTipPosition, ToolButton, IndeterminateProgressRing,
Flyout, FlyoutViewBase, FlyoutAnimationType)

Expand Down Expand Up @@ -43,9 +43,9 @@ def __init__(self, parent=None):
self.IconNameHBoxLayout = QHBoxLayout()
self.nameLevelVLayout = QVBoxLayout()
self.icon = RoundLevelAvatar('app/resource/images/champion-0.png',
0,
1,
parent=self)
0,
1,
parent=self)
self.name = QLabel(self.tr("Connecting..."))
self.copyButton = ToolButton(Icon.COPY)
self.nameButtonLayout = QHBoxLayout()
Expand Down Expand Up @@ -152,7 +152,7 @@ def __initWidget(self):
self.__updateTable()

StyleSheet.CAREER_INTERFACE.apply(self)
self.setTableStyle(cfg.theme)
self.setTableStyle()

def __initLayout(self):
self.nameButtonLayout.setContentsMargins(0, 0, 0, 0)
Expand Down Expand Up @@ -262,30 +262,36 @@ def __updateTable(self):
self.rankTable.horizontalHeader().setSectionResizeMode(
QHeaderView.Stretch)

def setTableStyle(self, theme=None):
if cfg.theme == Theme.LIGHT:
borderColor = "rgba(0, 0, 0, 0.095)"
backgroundColor = "rgba(255, 255, 255, 0.667)"
else:
borderColor = "rgb(35, 35, 35)"
backgroundColor = "rgba(255, 255, 255, 0.051)"

qss = self.rankTable.styleSheet()
qss += f'''
QHeaderView::section:horizontal {{
border: none;
border-bottom: 1px solid {borderColor};
}}
QTableView {{
border: 1px solid {borderColor};
border-radius: 6px;
background: {backgroundColor};
}}'''
self.rankTable.setStyleSheet(qss)
def setTableStyle(self):
light = '''
QHeaderView::section:horizontal {
border: none;
border-bottom: 1px solid rgba(0, 0, 0, 0.095);
}
QTableView {
border: 1px solid rgba(0, 0, 0, 0.095);
border-radius: 6px;
background: rgba(255, 255, 255, 0.667);
}
'''

dark = '''
QHeaderView::section:horizontal {
border: none;
border-bottom: 1px solid rgb(35, 35, 35);
}
QTableView {
border: 1px solid rgb(35, 35, 35);
border-radius: 6px;
background: rgba(255, 255, 255, 0.051);
}
'''

setCustomStyleSheet(self.rankTable, light, dark)

def __connectSignalToSlot(self):
cfg.themeChanged.connect(self.setTableStyle)
self.careerInfoChanged.connect(self.__onCareerInfoChanged)
self.IconLevelExpChanged.connect(self.__onChangeIconLevelAndExp)
self.filterComboBox.currentIndexChanged.connect(
Expand Down Expand Up @@ -313,7 +319,8 @@ def __onChangeIconLevelAndExp(self, info):

self.name.setText(name)
levelStr = str(level) if level != -1 else "None"
self.icon.updateIcon(icon, xpSinceLastLevel, xpUntilNextLevel, levelStr)
self.icon.updateIcon(icon, xpSinceLastLevel,
xpUntilNextLevel, levelStr)

def __onCareerInfoChanged(self, info: dict):
if not info['triggerByUser'] and not self.isCurrentSummoner():
Expand All @@ -329,7 +336,8 @@ def __onCareerInfoChanged(self, info: dict):
games = info['games']

levelStr = str(level) if level != -1 else "None"
self.icon.updateIcon(icon, xpSinceLastLevel, xpUntilNextLevel, levelStr)
self.icon.updateIcon(icon, xpSinceLastLevel,
xpUntilNextLevel, levelStr)
self.name.setText(name)

self.puuid = puuid
Expand Down Expand Up @@ -493,7 +501,8 @@ def __onfilterComboBoxChanged(self, index):
else:
targetId = 0

hitGames, kills, deaths, assists, wins, losses = parseGames(self.games["games"], targetId)
hitGames, kills, deaths, assists, wins, losses = parseGames(
self.games["games"], targetId)

for game in hitGames:
bar = GameInfoBar(game)
Expand Down
4 changes: 2 additions & 2 deletions app/view/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,8 @@ def exceptHook(self, ty, value, tb):
self.oldHook(ty, value, tb)

def __onCurrentStackedChanged(self, index):
if index == self.stackedWidget.indexOf(self.careerInterface):
self.careerInterface.setTableStyle()
# if index == self.stackedWidget.indexOf(self.careerInterface):
# self.careerInterface.setTableStyle()

widget: SmoothScrollArea = self.stackedWidget.view.currentWidget()
widget.delegate.vScrollBar.resetValue(0)

0 comments on commit 1eef889

Please sign in to comment.