1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-31 11:35:24 +01:00

Add a menu item to remove tracks from the playlist. Fixes issue #110

This commit is contained in:
David Sansome 2010-03-24 16:36:44 +00:00
parent ad30bad33c
commit 7d6a7101c9
5 changed files with 42 additions and 19 deletions

View File

@ -129,6 +129,7 @@ MainWindow::MainWindow(QNetworkAccessManager* network, QWidget *parent)
connect(ui_.action_ban, SIGNAL(triggered()), radio_model_->GetLastFMService(), SLOT(Ban())); connect(ui_.action_ban, SIGNAL(triggered()), radio_model_->GetLastFMService(), SLOT(Ban()));
connect(ui_.action_love, SIGNAL(triggered()), SLOT(Love())); connect(ui_.action_love, SIGNAL(triggered()), SLOT(Love()));
connect(ui_.action_clear_playlist, SIGNAL(triggered()), playlist_, SLOT(Clear())); connect(ui_.action_clear_playlist, SIGNAL(triggered()), playlist_, SLOT(Clear()));
connect(ui_.action_remove_from_playlist, SIGNAL(triggered()), SLOT(PlaylistRemoveCurrent()));
connect(ui_.action_edit_track, SIGNAL(triggered()), SLOT(EditTracks())); connect(ui_.action_edit_track, SIGNAL(triggered()), SLOT(EditTracks()));
connect(ui_.action_renumber_tracks, SIGNAL(triggered()), SLOT(RenumberTracks())); connect(ui_.action_renumber_tracks, SIGNAL(triggered()), SLOT(RenumberTracks()));
connect(ui_.action_selection_set_value, SIGNAL(triggered()), SLOT(SelectionSetValue())); connect(ui_.action_selection_set_value, SIGNAL(triggered()), SLOT(SelectionSetValue()));
@ -238,6 +239,8 @@ MainWindow::MainWindow(QNetworkAccessManager* network, QWidget *parent)
playlist_menu_->addAction(ui_.action_stop); playlist_menu_->addAction(ui_.action_stop);
playlist_stop_after_ = playlist_menu_->addAction(QIcon(":media-playback-stop.png"), tr("Stop after this track"), this, SLOT(PlaylistStopAfter())); playlist_stop_after_ = playlist_menu_->addAction(QIcon(":media-playback-stop.png"), tr("Stop after this track"), this, SLOT(PlaylistStopAfter()));
playlist_menu_->addSeparator(); playlist_menu_->addSeparator();
playlist_menu_->addAction(ui_.action_remove_from_playlist);
playlist_menu_->addSeparator();
playlist_menu_->addAction(ui_.action_edit_track); playlist_menu_->addAction(ui_.action_edit_track);
playlist_menu_->addAction(ui_.action_renumber_tracks); playlist_menu_->addAction(ui_.action_renumber_tracks);
playlist_menu_->addAction(ui_.action_selection_set_value); playlist_menu_->addAction(ui_.action_selection_set_value);
@ -572,9 +575,9 @@ void MainWindow::PlaylistRightClick(const QPoint& global_pos, const QModelIndex&
playlist_stop_after_->setEnabled(index.isValid()); playlist_stop_after_->setEnabled(index.isValid());
// Are any of the selected songs editable? // Are any of the selected songs editable?
QModelIndexList selection = ui_.playlist->selectionModel()->selection().indexes();
int editable = 0; int editable = 0;
foreach (const QModelIndex& index, foreach (const QModelIndex& index, selection) {
ui_.playlist->selectionModel()->selection().indexes()) {
if (index.column() != 0) if (index.column() != 0)
continue; continue;
if (playlist_->item_at(index.row())->Metadata().IsEditable()) { if (playlist_->item_at(index.row())->Metadata().IsEditable()) {
@ -584,6 +587,7 @@ void MainWindow::PlaylistRightClick(const QPoint& global_pos, const QModelIndex&
ui_.action_edit_track->setEnabled(editable); ui_.action_edit_track->setEnabled(editable);
ui_.action_renumber_tracks->setEnabled(editable); ui_.action_renumber_tracks->setEnabled(editable);
ui_.action_selection_set_value->setEnabled(editable >= 2); ui_.action_selection_set_value->setEnabled(editable >= 2);
ui_.action_remove_from_playlist->setEnabled(!selection.isEmpty());
if (!index.isValid()) { if (!index.isValid()) {
ui_.action_selection_set_value->setVisible(false); ui_.action_selection_set_value->setVisible(false);
@ -778,3 +782,7 @@ void MainWindow::AddStreamAccepted() {
playlist_->InsertStreamUrls(urls); playlist_->InsertStreamUrls(urls);
} }
void MainWindow::PlaylistRemoveCurrent() {
ui_.playlist->RemoveSelected();
}

View File

@ -71,6 +71,7 @@ class MainWindow : public QMainWindow {
void PlaylistRightClick(const QPoint& global_pos, const QModelIndex& index); void PlaylistRightClick(const QPoint& global_pos, const QModelIndex& index);
void PlaylistPlay(); void PlaylistPlay();
void PlaylistStopAfter(); void PlaylistStopAfter();
void PlaylistRemoveCurrent();
void EditTracks(); void EditTracks();
void RenumberTracks(); void RenumberTracks();
void SelectionSetValue(); void SelectionSetValue();

View File

@ -739,6 +739,15 @@
<string>Repeat mode</string> <string>Repeat mode</string>
</property> </property>
</action> </action>
<action name="action_remove_from_playlist">
<property name="icon">
<iconset resource="../data/data.qrc">
<normaloff>:/list-remove.png</normaloff>:/list-remove.png</iconset>
</property>
<property name="text">
<string>Remove from playlist</string>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<customwidgets> <customwidgets>

View File

@ -352,23 +352,7 @@ void PlaylistView::keyPressEvent(QKeyEvent* event) {
if (event->matches(QKeySequence::Delete) || if (event->matches(QKeySequence::Delete) ||
event->key() == Qt::Key_Backspace) { event->key() == Qt::Key_Backspace) {
QItemSelection selection(selectionModel()->selection()); RemoveSelected();
// Sort the selection so we remove the items at the *bottom* first, ensuring
// we don't have to mess around with changing row numbers
qSort(selection.begin(), selection.end(), CompareSelectionRanges);
foreach (const QItemSelectionRange& range, selection) {
model()->removeRows(range.top(), range.height(), range.parent());
}
// Select the new current item
if (currentIndex().isValid())
selectionModel()->select(
QItemSelection(currentIndex().sibling(currentIndex().row(), 0),
currentIndex().sibling(currentIndex().row(), model()->columnCount()-1)),
QItemSelectionModel::Select);
event->accept(); event->accept();
} else if (event->key() == Qt::Key_Enter || } else if (event->key() == Qt::Key_Enter ||
event->key() == Qt::Key_Return || event->key() == Qt::Key_Return ||
@ -385,3 +369,22 @@ void PlaylistView::contextMenuEvent(QContextMenuEvent* e) {
emit RightClicked(e->globalPos(), indexAt(e->pos())); emit RightClicked(e->globalPos(), indexAt(e->pos()));
e->accept(); e->accept();
} }
void PlaylistView::RemoveSelected() {
QItemSelection selection(selectionModel()->selection());
// Sort the selection so we remove the items at the *bottom* first, ensuring
// we don't have to mess around with changing row numbers
qSort(selection.begin(), selection.end(), CompareSelectionRanges);
foreach (const QItemSelectionRange& range, selection) {
model()->removeRows(range.top(), range.height(), range.parent());
}
// Select the new current item
if (currentIndex().isValid())
selectionModel()->select(
QItemSelection(currentIndex().sibling(currentIndex().row(), 0),
currentIndex().sibling(currentIndex().row(), model()->columnCount()-1)),
QItemSelectionModel::Select);
}

View File

@ -65,6 +65,8 @@ class PlaylistView : public QTreeView {
public: public:
PlaylistView(QWidget* parent = 0); PlaylistView(QWidget* parent = 0);
void RemoveSelected();
// QTreeView // QTreeView
void setModel(QAbstractItemModel *model); void setModel(QAbstractItemModel *model);
void drawRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; void drawRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;