From 30023dbfb518a3f1459b496345c011faf470bd6c Mon Sep 17 00:00:00 2001 From: Shaowen Yin Date: Sat, 26 Oct 2024 22:07:42 +0800 Subject: [PATCH] gui: remove multiple songs from playlist (#874) --- feeluown/gui/components/player_playlist.py | 18 +++++++++++------- feeluown/gui/widgets/song_minicard_list.py | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/feeluown/gui/components/player_playlist.py b/feeluown/gui/components/player_playlist.py index ab3698dad9..4588e74d0f 100644 --- a/feeluown/gui/components/player_playlist.py +++ b/feeluown/gui/components/player_playlist.py @@ -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): @@ -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) diff --git a/feeluown/gui/widgets/song_minicard_list.py b/feeluown/gui/widgets/song_minicard_list.py index df36ea8439..893a5d116f 100644 --- a/feeluown/gui/widgets/song_minicard_list.py +++ b/feeluown/gui/widgets/song_minicard_list.py @@ -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)