More items in playlist context menu
This commit is contained in:
parent
e7b94dfafc
commit
a49f5506ac
1
TODO
1
TODO
@ -8,7 +8,6 @@
|
||||
- Make QSortFilterProxyModel on the library obey hasChildren()
|
||||
- Database versioning
|
||||
- Clicking play plays selected item
|
||||
- More actions in playlist context menu
|
||||
|
||||
Long-term:
|
||||
- iPod
|
||||
|
@ -36,6 +36,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
playlist_(new Playlist(this)),
|
||||
player_(new Player(playlist_, radio_model_->GetLastFMService(), this)),
|
||||
library_(new Library(player_->GetEngine(), this)),
|
||||
playlist_menu_(new QMenu(this)),
|
||||
library_sort_model_(new QSortFilterProxyModel(this)),
|
||||
track_position_timer_(new QTimer(this))
|
||||
{
|
||||
@ -120,6 +121,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
connect(ui_.playlist, SIGNAL(doubleClicked(QModelIndex)), SLOT(PlayIndex(QModelIndex)));
|
||||
connect(ui_.playlist, SIGNAL(PlayPauseItem(QModelIndex)), SLOT(PlayIndex(QModelIndex)));
|
||||
connect(ui_.playlist, SIGNAL(RightClicked(QPoint,QModelIndex)), SLOT(PlaylistRightClick(QPoint,QModelIndex)));
|
||||
|
||||
// Library connections
|
||||
connect(library_, SIGNAL(Error(QString)), SLOT(ReportError(QString)));
|
||||
@ -161,6 +163,13 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
library_menu->addAction("Configure library...", library_, SLOT(ShowConfig()));
|
||||
ui_.library_options->setMenu(library_menu);
|
||||
|
||||
// Playlist menu
|
||||
playlist_play_pause_ = playlist_menu_->addAction("Play", this, SLOT(PlaylistPlay()));
|
||||
playlist_menu_->addAction(ui_.action_stop);
|
||||
playlist_stop_after_ = playlist_menu_->addAction(QIcon(":media-playback-stop.png"), "Stop after this track", this, SLOT(PlaylistStopAfter()));
|
||||
playlist_menu_->addSeparator();
|
||||
playlist_menu_->addAction(ui_.action_clear_playlist);
|
||||
|
||||
// Radio connections
|
||||
connect(radio_model_, SIGNAL(LoadingStarted()), ui_.playlist, SLOT(StartRadioLoading()));
|
||||
connect(radio_model_, SIGNAL(LoadingFinished()), ui_.playlist, SLOT(StopRadioLoading()));
|
||||
@ -400,3 +409,32 @@ void MainWindow::InsertRadioItem(RadioItem* item) {
|
||||
if (first_song.isValid() && player_->GetState() != Engine::Playing)
|
||||
player_->PlayAt(first_song.row());
|
||||
}
|
||||
|
||||
void MainWindow::PlaylistRightClick(const QPoint& global_pos, const QModelIndex& index) {
|
||||
playlist_menu_index_ = index;
|
||||
|
||||
if (playlist_->current_index() == index.row()) {
|
||||
playlist_play_pause_->setText("Pause");
|
||||
playlist_play_pause_->setIcon(QIcon(":media-playback-pause.png"));
|
||||
} else {
|
||||
playlist_play_pause_->setText("Play");
|
||||
playlist_play_pause_->setIcon(QIcon(":media-playback-start.png"));
|
||||
}
|
||||
|
||||
playlist_play_pause_->setEnabled(index.isValid());
|
||||
playlist_stop_after_->setEnabled(index.isValid());
|
||||
|
||||
playlist_menu_->popup(global_pos);
|
||||
}
|
||||
|
||||
void MainWindow::PlaylistPlay() {
|
||||
if (playlist_->current_index() == playlist_menu_index_.row()) {
|
||||
player_->PlayPause();
|
||||
} else {
|
||||
player_->PlayAt(playlist_menu_index_.row());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::PlaylistStopAfter() {
|
||||
playlist_->StopAfter(playlist_menu_index_.row());
|
||||
}
|
||||
|
@ -40,6 +40,10 @@ class MainWindow : public QMainWindow {
|
||||
void MediaPaused();
|
||||
void MediaPlaying();
|
||||
|
||||
void PlaylistRightClick(const QPoint& global_pos, const QModelIndex& index);
|
||||
void PlaylistPlay();
|
||||
void PlaylistStopAfter();
|
||||
|
||||
void PlayIndex(const QModelIndex& index);
|
||||
void StopAfterCurrent();
|
||||
|
||||
@ -72,6 +76,11 @@ class MainWindow : public QMainWindow {
|
||||
Player* player_;
|
||||
Library* library_;
|
||||
|
||||
QMenu* playlist_menu_;
|
||||
QAction* playlist_play_pause_;
|
||||
QAction* playlist_stop_after_;
|
||||
QModelIndex playlist_menu_index_;
|
||||
|
||||
QSortFilterProxyModel* library_sort_model_;
|
||||
|
||||
QTimer* track_position_timer_;
|
||||
|
@ -134,7 +134,6 @@ PlaylistView::PlaylistView(QWidget *parent)
|
||||
row_height_(-1),
|
||||
currenttrack_play_(":currenttrack_play.png"),
|
||||
currenttrack_pause_(":currenttrack_pause.png"),
|
||||
menu_(new QMenu(this)),
|
||||
radio_loading_(new RadioLoadingIndicator(this))
|
||||
{
|
||||
setItemDelegate(new PlaylistDelegateBase(this));
|
||||
@ -150,9 +149,6 @@ PlaylistView::PlaylistView(QWidget *parent)
|
||||
glow_timer_->setInterval(1500 / kGlowIntensitySteps);
|
||||
connect(glow_timer_, SIGNAL(timeout()), SLOT(GlowIntensityChanged()));
|
||||
|
||||
menu_->addAction(QIcon(":media-playback-stop.png"), "Stop playing after track",
|
||||
this, SLOT(StopAfter()));
|
||||
|
||||
radio_loading_->hide();
|
||||
}
|
||||
|
||||
@ -335,21 +331,10 @@ void PlaylistView::keyPressEvent(QKeyEvent* event) {
|
||||
}
|
||||
|
||||
void PlaylistView::contextMenuEvent(QContextMenuEvent* e) {
|
||||
menu_index_ = indexAt(e->pos());
|
||||
if (!menu_index_.isValid())
|
||||
return;
|
||||
|
||||
menu_->popup(e->globalPos());
|
||||
emit RightClicked(e->globalPos(), indexAt(e->pos()));
|
||||
e->accept();
|
||||
}
|
||||
|
||||
void PlaylistView::StopAfter() {
|
||||
Playlist* playlist = qobject_cast<Playlist*>(model());
|
||||
Q_ASSERT(playlist);
|
||||
|
||||
playlist->StopAfter(menu_index_.row());
|
||||
}
|
||||
|
||||
void PlaylistView::resizeEvent(QResizeEvent *event) {
|
||||
const QPoint kPadding(5,5);
|
||||
|
||||
|
@ -57,6 +57,7 @@ class PlaylistView : public QTreeView {
|
||||
|
||||
signals:
|
||||
void PlayPauseItem(const QModelIndex& index);
|
||||
void RightClicked(const QPoint& global_pos, const QModelIndex& index);
|
||||
|
||||
protected:
|
||||
void hideEvent(QHideEvent* event);
|
||||
@ -67,8 +68,6 @@ class PlaylistView : public QTreeView {
|
||||
void SaveGeometry();
|
||||
void GlowIntensityChanged();
|
||||
|
||||
void StopAfter();
|
||||
|
||||
private:
|
||||
void ReloadBarPixmaps();
|
||||
QList<QPixmap> LoadBarPixmap(const QString& filename);
|
||||
@ -90,9 +89,6 @@ class PlaylistView : public QTreeView {
|
||||
QPixmap currenttrack_play_;
|
||||
QPixmap currenttrack_pause_;
|
||||
|
||||
QMenu* menu_;
|
||||
QModelIndex menu_index_;
|
||||
|
||||
RadioLoadingIndicator* radio_loading_;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user