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:
parent
ad30bad33c
commit
7d6a7101c9
@ -129,6 +129,7 @@ MainWindow::MainWindow(QNetworkAccessManager* network, QWidget *parent)
|
||||
connect(ui_.action_ban, SIGNAL(triggered()), radio_model_->GetLastFMService(), SLOT(Ban()));
|
||||
connect(ui_.action_love, SIGNAL(triggered()), SLOT(Love()));
|
||||
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_renumber_tracks, SIGNAL(triggered()), SLOT(RenumberTracks()));
|
||||
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_stop_after_ = playlist_menu_->addAction(QIcon(":media-playback-stop.png"), tr("Stop after this track"), this, SLOT(PlaylistStopAfter()));
|
||||
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_renumber_tracks);
|
||||
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());
|
||||
|
||||
// Are any of the selected songs editable?
|
||||
QModelIndexList selection = ui_.playlist->selectionModel()->selection().indexes();
|
||||
int editable = 0;
|
||||
foreach (const QModelIndex& index,
|
||||
ui_.playlist->selectionModel()->selection().indexes()) {
|
||||
foreach (const QModelIndex& index, selection) {
|
||||
if (index.column() != 0)
|
||||
continue;
|
||||
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_renumber_tracks->setEnabled(editable);
|
||||
ui_.action_selection_set_value->setEnabled(editable >= 2);
|
||||
ui_.action_remove_from_playlist->setEnabled(!selection.isEmpty());
|
||||
|
||||
if (!index.isValid()) {
|
||||
ui_.action_selection_set_value->setVisible(false);
|
||||
@ -778,3 +782,7 @@ void MainWindow::AddStreamAccepted() {
|
||||
|
||||
playlist_->InsertStreamUrls(urls);
|
||||
}
|
||||
|
||||
void MainWindow::PlaylistRemoveCurrent() {
|
||||
ui_.playlist->RemoveSelected();
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ class MainWindow : public QMainWindow {
|
||||
void PlaylistRightClick(const QPoint& global_pos, const QModelIndex& index);
|
||||
void PlaylistPlay();
|
||||
void PlaylistStopAfter();
|
||||
void PlaylistRemoveCurrent();
|
||||
void EditTracks();
|
||||
void RenumberTracks();
|
||||
void SelectionSetValue();
|
||||
|
@ -739,6 +739,15 @@
|
||||
<string>Repeat mode</string>
|
||||
</property>
|
||||
</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>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
|
@ -352,23 +352,7 @@ void PlaylistView::keyPressEvent(QKeyEvent* event) {
|
||||
|
||||
if (event->matches(QKeySequence::Delete) ||
|
||||
event->key() == Qt::Key_Backspace) {
|
||||
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);
|
||||
|
||||
RemoveSelected();
|
||||
event->accept();
|
||||
} else if (event->key() == Qt::Key_Enter ||
|
||||
event->key() == Qt::Key_Return ||
|
||||
@ -385,3 +369,22 @@ void PlaylistView::contextMenuEvent(QContextMenuEvent* e) {
|
||||
emit RightClicked(e->globalPos(), indexAt(e->pos()));
|
||||
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);
|
||||
}
|
||||
|
@ -65,6 +65,8 @@ class PlaylistView : public QTreeView {
|
||||
public:
|
||||
PlaylistView(QWidget* parent = 0);
|
||||
|
||||
void RemoveSelected();
|
||||
|
||||
// QTreeView
|
||||
void setModel(QAbstractItemModel *model);
|
||||
void drawRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user