Skip to content

Commit

Permalink
gui: remove multiple songs from playlist (#874)
Browse files Browse the repository at this point in the history
  • Loading branch information
cosven authored Oct 26, 2024
1 parent 74055a1 commit 30023db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
18 changes: 11 additions & 7 deletions feeluown/gui/components/player_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ def __init__(self, app, *args, **kwargs):
self.setModel(PlayerPlaylistView._model)

def contextMenuEvent(self, e):
index = self.indexAt(e.pos())
if not index.isValid():
indexes = self.selectedIndexes()
if not indexes:
return

song = index.data(Qt.UserRole)[0]
songs = [index.data(Qt.UserRole)[0] for index in indexes]
menu = QMenu()
action = menu.addAction('从播放队列中移除')
menu.addSeparator()
SongMenuInitializer(self._app, song).apply(menu)

action.triggered.connect(lambda: self._app.playlist.remove(song))
action.triggered.connect(lambda: self._remove_songs(songs))
if len(songs) == 1:
menu.addSeparator()
SongMenuInitializer(self._app, songs).apply(menu)
menu.exec_(e.globalPos())

def scroll_to_current_song(self):
Expand All @@ -88,3 +88,7 @@ def scroll_to_current_song(self):
# In order to highlight the current song.
self.selectionModel().select(index, QItemSelectionModel.SelectCurrent)
self.scrollTo(index, QAbstractItemView.PositionAtCenter)

def _remove_songs(self, songs):
for song in songs:
self._app.playlist.remove(song)
1 change: 1 addition & 0 deletions feeluown/gui/widgets/song_minicard_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ class SongMiniCardListView(ItemViewNoScrollMixin, QListView):
def __init__(self, parent=None, **kwargs):
super().__init__(parent=parent, **kwargs)

self.setSelectionMode(QListView.ContiguousSelection)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.setMouseTracking(True)
Expand Down

0 comments on commit 30023db

Please sign in to comment.