Center on last played song when restoring playlist. Fixes issue 410.

This commit is contained in:
Arnaud Bienner 2011-02-10 20:55:19 +00:00
parent 0544cfa90a
commit 79159700fc
4 changed files with 26 additions and 0 deletions

View File

@ -1123,6 +1123,7 @@ void Playlist::ItemsLoaded() {
last_played_item_index_ =
p.last_played == -1 ? QModelIndex() : index(p.last_played);
current_item_index_ = last_played_item_index_;
if (!p.dynamic_type.isEmpty()) {
GeneratorPtr gen = Generator::Create(p.dynamic_type);
@ -1143,6 +1144,7 @@ void Playlist::ItemsLoaded() {
}
}
}
emit RestoreFinished();
}
static bool DescendingIntLessThan(int a, int b) {

View File

@ -233,6 +233,7 @@ class Playlist : public QAbstractListModel {
void TurnOffDynamicPlaylist();
signals:
void RestoreFinished();
void CurrentSongChanged(const Song& metadata);
void EditingFinished(const QModelIndex& index);
void PlayRequested(const QModelIndex& index);

View File

@ -168,8 +168,11 @@ void PlaylistView::SetPlaylist(Playlist *playlist) {
LoadGeometry();
ReloadSettings();
DynamicModeChanged(playlist->is_dynamic());
setFocus();
read_only_settings_ = false;
connect(playlist_, SIGNAL(RestoreFinished()), SLOT(JumpToLastPlayedTrack()));
connect(playlist_, SIGNAL(CurrentSongChanged(Song)), SLOT(MaybeAutoscroll()));
connect(playlist_, SIGNAL(DynamicModeChanged(bool)), SLOT(DynamicModeChanged(bool)));
connect(playlist_, SIGNAL(destroyed()), SLOT(PlaylistDestroyed()));
@ -671,6 +674,25 @@ void PlaylistView::JumpToCurrentlyPlayingTrack() {
currently_autoscrolling_ = false;
}
void PlaylistView::JumpToLastPlayedTrack() {
Q_ASSERT(playlist_);
if (playlist_->last_played_row() == -1)
return;
QModelIndex last_played = playlist_->proxy()->mapFromSource(
playlist_->index(playlist_->last_played_row(), 0));
if (!last_played.isValid())
return;
currently_autoscrolling_ = true;
// Scroll to the item
scrollTo(last_played, QAbstractItemView::PositionAtCenter);
currently_autoscrolling_ = false;
}
void PlaylistView::paintEvent(QPaintEvent* event) {
// Reimplemented to draw the drop indicator
// When the user is dragging some stuff over the playlist paintEvent gets

View File

@ -81,6 +81,7 @@ class PlaylistView : public QTreeView {
void StopGlowing();
void StartGlowing();
void JumpToCurrentlyPlayingTrack();
void JumpToLastPlayedTrack();
void closeEditor(QWidget* editor, QAbstractItemDelegate::EndEditHint hint);
void DynamicModeChanged(bool dynamic);