Save and restore playlist scrollbar position when switching between playlists
This commit is contained in:
parent
16a753bd95
commit
15ddf6ff20
|
@ -25,6 +25,7 @@
|
|||
#include <QWidget>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QScrollBar>
|
||||
#include <QAction>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
|
@ -160,7 +161,7 @@ void PlaylistContainer::SetManager(PlaylistManager *manager) {
|
|||
|
||||
connect(ui_->tab_bar, SIGNAL(PlaylistOrderChanged(QList<int>)), manager, SLOT(ChangePlaylistOrder(QList<int>)));
|
||||
|
||||
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()));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <QRegularExpression>
|
||||
#include <QUrl>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QScrollBar>
|
||||
#include <QSettings>
|
||||
#include <QtDebug>
|
||||
|
||||
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
|
@ -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_;
|
||||
|
|
Loading…
Reference in New Issue