diff --git a/src/playlist/playlistcontainer.cpp b/src/playlist/playlistcontainer.cpp index 3116f913d..b73cf6681 100644 --- a/src/playlist/playlistcontainer.cpp +++ b/src/playlist/playlistcontainer.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -160,7 +161,7 @@ void PlaylistContainer::SetManager(PlaylistManager *manager) { connect(ui_->tab_bar, SIGNAL(PlaylistOrderChanged(QList)), manager, SLOT(ChangePlaylistOrder(QList))); - connect(manager, SIGNAL(CurrentChanged(Playlist*)), SLOT(SetViewModel(Playlist*))); + connect(manager, SIGNAL(CurrentChanged(Playlist*, int)), SLOT(SetViewModel(Playlist*, int))); connect(manager, SIGNAL(PlaylistAdded(int, QString, bool)), SLOT(PlaylistAdded(int, QString, bool))); connect(manager, SIGNAL(PlaylistManagerInitialized()), SLOT(Started())); connect(manager, SIGNAL(PlaylistClosed(int)), SLOT(PlaylistClosed(int))); @@ -168,7 +169,7 @@ void PlaylistContainer::SetManager(PlaylistManager *manager) { } -void PlaylistContainer::SetViewModel(Playlist *playlist) { +void PlaylistContainer::SetViewModel(Playlist *playlist, const int scroll_position) { if (view()->selectionModel()) { disconnect(view()->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(SelectionChanged())); @@ -191,6 +192,7 @@ void PlaylistContainer::SetViewModel(Playlist *playlist) { view()->setModel(playlist->proxy()); view()->SetPlaylist(playlist); view()->selectionModel()->select(manager_->current_selection(), QItemSelectionModel::ClearAndSelect); + if (scroll_position != 0) view()->verticalScrollBar()->setValue(scroll_position); playlist->IgnoreSorting(false); connect(view()->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(SelectionChanged())); diff --git a/src/playlist/playlistcontainer.h b/src/playlist/playlistcontainer.h index cb248033e..95aefa270 100644 --- a/src/playlist/playlistcontainer.h +++ b/src/playlist/playlistcontainer.h @@ -80,7 +80,7 @@ class PlaylistContainer : public QWidget { void GoToNextPlaylistTab(); void GoToPreviousPlaylistTab(); - void SetViewModel(Playlist *playlist); + void SetViewModel(Playlist *playlist, const int scroll_position); void PlaylistAdded(int id, const QString &name, bool favorite); void PlaylistClosed(int id); void PlaylistRenamed(int id, const QString &new_name); diff --git a/src/playlist/playlistmanager.cpp b/src/playlist/playlistmanager.cpp index 208f124e3..36b227f28 100644 --- a/src/playlist/playlistmanager.cpp +++ b/src/playlist/playlistmanager.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -366,8 +367,14 @@ void PlaylistManager::OneOfPlaylistsChanged() { void PlaylistManager::SetCurrentPlaylist(int id) { Q_ASSERT(playlists_.contains(id)); + + // Save the scroll position for the current playlist. + if (playlists_.contains(current_)) { + playlists_[current_].scroll_position = playlist_container_->view()->verticalScrollBar()->value(); + } + current_ = id; - emit CurrentChanged(current()); + emit CurrentChanged(current(), playlists_[id].scroll_position); UpdateSummaryText(); } diff --git a/src/playlist/playlistmanager.h b/src/playlist/playlistmanager.h index d4cc39a83..cc5d18e4d 100644 --- a/src/playlist/playlistmanager.h +++ b/src/playlist/playlistmanager.h @@ -112,7 +112,7 @@ class PlaylistManagerInterface : public QObject { void PlaylistClosed(int id); void PlaylistRenamed(int id, const QString &new_name); void PlaylistFavorited(int id, bool favorite); - void CurrentChanged(Playlist *new_playlist); + void CurrentChanged(Playlist *new_playlist, const int scroll_position = 0); void ActiveChanged(Playlist *new_playlist); void Error(const QString &message); @@ -223,10 +223,11 @@ class PlaylistManager : public PlaylistManagerInterface { private: struct Data { - explicit Data(Playlist *_p = nullptr, const QString& _name = QString()) : p(_p), name(_name) {} + explicit Data(Playlist *_p = nullptr, const QString& _name = QString()) : p(_p), name(_name), scroll_position(0) {} Playlist *p; QString name; QItemSelection selection; + int scroll_position; }; Application *app_;