8000 修复歌曲卡的标签样式问题 · ag-python-qt/Groove@9ea393d · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ea393d

Browse files
committed
修复歌曲卡的标签样式问题
1 parent ba1f403 commit 9ea393d

File tree

17 files changed

+76230
-76206
lines changed

17 files changed

+76230
-76206
lines changed

app/View/play_bar/play_bar_buttons.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# coding:utf-8
22
from common.signal_bus import signalBus
3-
from components.buttons.tooltip_button import TooltipButton
3+
from components.buttons.tool_tip_button import ToolTipButton
44
from PyQt5.QtCore import QEvent, Qt
55
from PyQt5.QtGui import QBrush, QColor, QPainter, QPen, QPixmap
66
from PyQt5.QtMultimedia import QMediaPlaylist
77

88

9-
class PlayButton(TooltipButton):
9+
class PlayButton(ToolTipButton):
1010
""" Play button """
1111

1212
def __init__(self, parent=None):
@@ -87,7 +87,7 @@ def paintEvent(self, e):
8787
painter.drawPixmap(3, 3, 59, 59, iconPix)
8888

8989

90-
class RandomPlayButton(TooltipButton):
90+
class RandomPlayButton(ToolTipButton):
9191
""" Random play button """
9292

9393
def __init__(self, parent=None):
@@ -173,7 +173,7 @@ def paintEvent(self, e):
173173
painter.drawPixmap(1, 1, 45, 45, self.image)
174174

175175

176-
class BasicButton(TooltipButton):
176+
class BasicButton(ToolTipButton):
177177
""" Basic circle button """
178178

179179
def __init__(self, iconPath: str, parent=None):
@@ -232,7 +232,7 @@ def paintEvent(self, e):
232232
painter.drawPixmap(2, 2, 42, 42, image)
233233

234234

235-
class LoopModeButton(TooltipButton):
235+
class LoopModeButton(ToolTipButton):
236236
""" Loop mode button """
237237

238238
def __init__(self, parent=None):
@@ -343,7 +343,7 @@ def __updateToolTip(self):
343343
self.setToolTip(text)
344344

345345

346-
class VolumeButton(TooltipButton):
346+
class VolumeButton(ToolTipButton):
347347
""" Volume button """
348348

349349
def __init__(self, parent=None):

app/common/resource.py

Lines changed: 76049 additions & 76039 deletions
Large diffs are not rendered by default.

app/components/buttons/blur_button.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from PyQt5.QtCore import QPropertyAnimation, Qt, pyqtProperty
44
from PyQt5.QtGui import QBrush, QEnterEvent, QPainter, QPixmap
55

6-
from .tooltip_button import TooltipButton
6+
from .tool_tip_button import ToolTipButton
77
from common.image_utils import readImage
88

99

10-
class BlurButton(TooltipButton):
10+
class BlurButton(ToolTipButton):
1111
""" Blur button class """
1212

1313
def __init__(self, parent, cropPos: tuple, iconPath: str, blurPicPath: str,
@@ -52,6 +52,7 @@ def __init__(self, parent, cropPos: tuple, iconPath: str, blurPicPath: str,
5252
self.radiusAni = QPropertyAnimation(self, b'paintRadius', self)
5353
self.opacityAni = QPropertyAnimation(self, b'opacity', self)
5454
self.setToolTip(text)
55+
self.setToolTipDelay(250)
5556

5657
def setBlurPic(self, blurPicPath, blurRadius=35):
5758
""" set the image to be blurred """

app/components/buttons/circle_button.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# coding:utf-8
2-
from .tooltip_button import TooltipButton
2+
from .tool_tip_button import ToolTipButton
33
from PyQt5.QtCore import Qt, QEvent
44
from PyQt5.QtGui import QPainter, QPixmap, QBrush, QColor
55

66

7-
class CircleButton(TooltipButton):
7+
class CircleButton(ToolTipButton):
88
""" Circle button """
99

1010
def __init__(self, iconPath: str, parent=None, iconSize: tuple = (47, 47), buttonSize: tuple = (47, 47)):
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# coding:utf-8
2+
from common.config import config, Theme
3+
from components.widgets.tooltip import ToolTip
4+
from PyQt5.QtCore import QEvent, QObject, QPoint, QTimer
5+
from PyQt5.QtWidgets import QToolButton, QPushButton
6+
7+
8+
class ToolTipButton(QToolButton):
9+
""" Tool button with a tool tip """
10+
11+
def __init__(self, parent=None):
12+
super().__init__(parent=parent)
13+
self.isEnter = False
14+
self._tooltip = None
15+
self._tooltipDelay = 300
16+
self._isDarkTheme = config.theme == Theme.DARK
17+
self.timer = QTimer(self)
18+
self.installEventFilter(self)
19+
20+
def eventFilter(self, obj: QObject, e: QEvent) -> bool:
21+
if obj is self:
22+
if e.type() == QEvent.ToolTip:
23+
return True
24+
25+
return super().eventFilter(obj, e)
26+
27+
def enterEvent(self, e):
28+
super().enterEvent(e)
29+
self.isEnter = True
30+
if not self.toolTip():
31+
return
32+
33+
if self._tooltip is None:
34+
self._tooltip = ToolTip(self.toolTip(), self.window())
35+
self._tooltip.setDarkTheme(self._isDarkTheme)
36+
37+
# update tooltip
38+
QTimer.singleShot(self._tooltipDelay, self.__showToolTip)
39+
40+
def __showToolTip(self):
41+
""" show tool tip """
42+
if not self.isEnter:
43+
return
44+
45+
self._tooltip.setText(self.toolTip())
46+
self._tooltip.adjustPos(self.mapToGlobal(QPoint()), self.size())
47+
self._tooltip.show()
48+
49+
def leaveEvent(self, e):
50+
super().leaveEvent(e)
51+
self.isEnter = False
52+
if self._tooltip:
53+
self._tooltip.hide()
54+
55+
def hideEvent(self, e):
56+
super().hideEvent(e)
57+
if self._tooltip:
58+
self._tooltip.hide()
59+
60+
def setDarkToolTip(self, dark=False):
61+
""" set whether to use the dark theme of tooltip """
62+
self._isDarkTheme = dark
63+
64+
def setToolTipDelay(self, delay: int):
65+
""" set the delay of tool tip """
66+
self._tooltipDelay = delay
67+
68+
def hideToolTip(self):
69+
""" hide tooltip """
70+
if self._tooltip:
71+
self._tooltip.hide()

app/components/buttons/tooltip_button.py

Lines changed: 0 additions & 105 deletions
This file was deleted.

app/components/selection_mode_interface/selection_mode_interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from ..singer_card import SingerCardViewBase
1515
from ..song_list_widget import BasicSongListWidget
1616
from ..widgets.menu import AddToMenu, DownloadMenu
17-
from ..widgets.scroll_area import ScrollArea
17+
from ..widgets.scroll_area import ScrollArea, SmoothScrollArea
1818
from .bar import SelectionModeBarFactory, SelectionModeBarType
1919

2020

@@ -32,7 +32,7 @@ def uncheckAll(self):
3232
raise NotImplementedError
3333

3434

35-
class SelectionModeInterface(ScrollArea):
35+
class SelectionModeInterface(SmoothScrollArea):
3636
""" Selection mode interface """
3737

3838
def __init__(self, barType: SelectionModeBarType, parent=None):

app/components/song_list_widget/basic_song_card.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,11 @@ def setSelected(self, isSelected: bool):
158158

159159
self.isSelected = isSelected
160160
if isSelected:
161-
self.setCardState(CardState.SELECTED_LEAVE)
162-
self.setWidgetState(WidgetState.SELECTED)
161+
self.setState(WidgetState.SELECTED, CardState.SELECTED_LEAVE)
163162
else:
164163
self.songNameCard.setWidgetHidden(True)
165-
self.setCardState(CardState.LEAVE)
166164
state = WidgetState.PLAY if self.isPlaying else WidgetState.NORMAL
167-
self.setWidgetState(state)
165+
self.setState(state, CardState.LEAVE)
168166

169167
self.setStyle(QApplication.style())
170168

@@ -178,11 +176,9 @@ def setPlay(self, isPlay: bool):
178176

179177
if isPlay:
180178
self.isSelected = True
181-
self.setWidgetState(WidgetState.SELECTED)
182-
self.setCardState(CardState.SELECTED_LEAVE)
179+
self.setState(WidgetState.SELECTED, CardState.SELECTED_LEAVE)
183180
else:
184-
self.setWidgetState(WidgetState.NORMAL)
185-
self.setCardState(CardState.LEAVE)
181+
self.setState(WidgetState.NORMAL, CardState.LEAVE)
186182

187183
self.songNameCard.setPlay(isPlay, self.isSongExist)
188184
self.setStyle(QApplication.style())
@@ -210,6 +206,11 @@ def setCardState(self, state: CardState):
210206
self.songNameCard.setButtonGroupState(state)
211207
self.setProperty("state", state.value)
212208

209+
def setState(self, widgetState: WidgetState, cardState: CardState):
210+
""" set the state of card and widget """
211+
self.setWidgetState(widgetState)
212+
self.setCardState(cardState)
213+
213214
def setAnimation(self, widgets: list, deltaXs: list):
214215
""" set the animation of widgets
215216
@@ -282,8 +283,7 @@ def eventFilter(self, obj, e: QEvent):
282283
self.setStyle(QApplication.style())
283284

284285
elif e.type() == QEvent.MouseButtonRelease and e.button() == Qt.LeftButton:
285-
self.setCardState(CardState.SELECTED_LEAVE)
286-
self.setWidgetState(WidgetState.SELECTED)
286+
self.setState(WidgetState.SELECTED, CardState.SELECTED_LEAVE)
287287
self.setStyle(QApplication.style())
288288

289289
elif e.type() == QEvent.MouseButtonDblClick:

app/components/song_list_widget/song_card.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ def __init__(self, songInfo: SongInfo, songCardType, parent=None):
1717
super().__init__(songInfo, songCardType, parent)
1818
self.durationLabel = QLabel(self.duration, self)
1919
self.setAttribute(Qt.WA_StyledBackground)
20-
self.setCardState(CardState.LEAVE)
21-
self.setWidgetState(WidgetState.NORMAL)
20+
self.setState(WidgetState.NORMAL, CardState.LEAVE)
2221

2322
def resizeEvent(self, e):
2423
super().resizeEvent(e)
@@ -68,6 +67,7 @@ def __initWidget(self):
6867

6968
self.setClickableLabels([self.singerLabel, self.albumLabel])
7069
self.setClickableLabelCursor(Qt.PointingHandCursor)
70+
self.setState(WidgetState.NORMAL, CardState.LEAVE)
7171

7272
# connect signal to slot
7373
self.addToButton.clicked.connect(self._showAddToMenu)
@@ -113,6 +113,7 @@ def __initWidget(self):
113113
# set clickable labels
114114
self.setClickableLabels([self.singerLabel])
115115
self.setClickableLabelCursor(Qt.PointingHandCursor)
116+
self.setState(WidgetState.NORMAL, CardState.LEAVE)
116117

117118
# connect signal to slot
118119
self.singerLabel.clicked.connect(
@@ -170,6 +171,7 @@ def __initWidget(self):
170171

171172
self.setClickableLabels([self.singerLabel, self.albumLabel])
172173
self.setClickableLabelCursor(Qt.PointingHandCursor)
174+
self.setState(WidgetState.NORMAL, CardState.LEAVE)
173175

174176
# connect signal to slot
175177
self.singerLabel.clicked.connect(
@@ -238,6 +240,7 @@ def __initWidget(self):
238240

239241
self.setClickableLabels([self.singerLabel, self.albumLabel])
240242
self.setClickableLabelCursor(Qt.PointingHandCursor)
243+
self.setState(WidgetState.NORMAL, CardState.LEAVE)
241244

242245
# connect signal to slot
243246
self.singerLabel.clicked.connect(
@@ -285,6 +288,7 @@ def __initWidget(self):
285288
105,
286289
)
287290
self.setDynamicStyleLabels(self.labels)
291+
self.setState(WidgetState.NORMAL, CardState.LEAVE)
288292

289293
# set song card clicked animation
290294
self.setAnimation(self.widgets, [13, 6, -3, -6, -13])

0 commit comments

Comments
 (0)
0