Fix saving playlist columns

This commit is contained in:
Jonas Kvinge
2019-04-28 14:14:19 +02:00
parent 1072dc0a41
commit 42de7de21d
3 changed files with 28 additions and 29 deletions

View File

@@ -2200,8 +2200,8 @@ void MainWindow::Exit() {
SaveGeometry(); SaveGeometry();
SavePlaybackStatus(); SavePlaybackStatus();
ui_->tabs->SaveSettings(kSettingsGroup); ui_->tabs->SaveSettings(kSettingsGroup);
ui_->playlist->view()->SaveSettings();
ui_->playlist->view()->SaveGeometry(); ui_->playlist->view()->SaveGeometry();
ui_->playlist->view()->SaveSettings();
app_->scrobbler()->WriteCache(); app_->scrobbler()->WriteCache();
if (app_->player()->engine()->is_fadeout_enabled()) { if (app_->player()->engine()->is_fadeout_enabled()) {

View File

@@ -143,6 +143,7 @@ PlaylistView::PlaylistView(QWidget *parent)
background_initialized_(false), background_initialized_(false),
setting_initial_header_layout_(false), setting_initial_header_layout_(false),
read_only_settings_(true), read_only_settings_(true),
state_loaded_(false),
previous_background_image_opacity_(0.0), previous_background_image_opacity_(0.0),
fade_animation_(new QTimeLine(1000, this)), fade_animation_(new QTimeLine(1000, this)),
force_background_redraw_(false), force_background_redraw_(false),
@@ -170,10 +171,14 @@ PlaylistView::PlaylistView(QWidget *parent)
setStyle(style_); setStyle(style_);
setMouseTracking(true); setMouseTracking(true);
connect(header_, SIGNAL(sectionResized(int,int,int)), SLOT(SaveGeometry()));
connect(header_, SIGNAL(sectionMoved(int,int,int)), SLOT(SaveGeometry()));
connect(header_, SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), SLOT(SaveGeometry()));
connect(header_, SIGNAL(SectionVisibilityChanged(int,bool)), SLOT(SaveGeometry()));
connect(header_, SIGNAL(sectionResized(int,int,int)), SLOT(InvalidateCachedCurrentPixmap())); connect(header_, SIGNAL(sectionResized(int,int,int)), SLOT(InvalidateCachedCurrentPixmap()));
connect(header_, SIGNAL(sectionMoved(int,int,int)), SLOT(InvalidateCachedCurrentPixmap())); connect(header_, SIGNAL(sectionMoved(int,int,int)), SLOT(InvalidateCachedCurrentPixmap()));
connect(header_, SIGNAL(SectionVisibilityChanged(int,bool)), SLOT(InvalidateCachedCurrentPixmap())); connect(header_, SIGNAL(SectionVisibilityChanged(int,bool)), SLOT(InvalidateCachedCurrentPixmap()));
connect(header_, SIGNAL(StretchEnabledChanged(bool)), SLOT(SaveSettings()));
connect(header_, SIGNAL(StretchEnabledChanged(bool)), SLOT(StretchChanged(bool))); connect(header_, SIGNAL(StretchEnabledChanged(bool)), SLOT(StretchChanged(bool)));
inhibit_autoscroll_timer_->setInterval(kAutoscrollGraceTimeout * 1000); inhibit_autoscroll_timer_->setInterval(kAutoscrollGraceTimeout * 1000);
@@ -287,14 +292,17 @@ void PlaylistView::setModel(QAbstractItemModel *m) {
void PlaylistView::LoadGeometry() { void PlaylistView::LoadGeometry() {
QSettings s; if (!state_loaded_) {
s.beginGroup(Playlist::kSettingsGroup); QSettings s;
QByteArray state(s.value("state").toByteArray()); s.beginGroup(Playlist::kSettingsGroup);
s.endGroup(); state_ = s.value("state").toByteArray();
state_loaded_ = true;
s.endGroup();
}
if (!header_->RestoreState(state)) { if (!header_->RestoreState(state_)) {
// Maybe we're upgrading from a version that persisted the state with QHeaderView. // Maybe we're upgrading from a version that persisted the state with QHeaderView.
if (!header_->restoreState(state)) { if (!header_->restoreState(state_)) {
header_->HideSection(Playlist::Column_AlbumArtist); header_->HideSection(Playlist::Column_AlbumArtist);
header_->HideSection(Playlist::Column_Performer); header_->HideSection(Playlist::Column_Performer);
header_->HideSection(Playlist::Column_Composer); header_->HideSection(Playlist::Column_Composer);
@@ -338,12 +346,8 @@ void PlaylistView::LoadGeometry() {
void PlaylistView::SaveGeometry() { void PlaylistView::SaveGeometry() {
if (!initialized_ || read_only_settings_) return; if (!initialized_ || !state_loaded_) return;
state_ = header_->SaveState();
QSettings settings;
settings.beginGroup(Playlist::kSettingsGroup);
settings.setValue("state", header_->SaveState());
settings.endGroup();
} }
@@ -1090,16 +1094,8 @@ void PlaylistView::SaveSettings() {
if (!initialized_ || read_only_settings_) return; if (!initialized_ || read_only_settings_) return;
QSettings s; QSettings s;
s.beginGroup(PlaylistSettingsPage::kSettingsGroup);
s.setValue("glow_effect", glow_enabled_);
s.endGroup();
s.beginGroup(AppearanceSettingsPage::kSettingsGroup);
s.setValue(AppearanceSettingsPage::kBackgroundImageType, background_image_type_);
s.endGroup();
s.beginGroup(Playlist::kSettingsGroup); s.beginGroup(Playlist::kSettingsGroup);
s.setValue("state", header_->SaveState());
s.setValue("column_alignments", QVariant::fromValue(column_alignment_)); s.setValue("column_alignments", QVariant::fromValue(column_alignment_));
s.endGroup(); s.endGroup();
@@ -1109,6 +1105,7 @@ void PlaylistView::StretchChanged(bool stretch) {
if (!initialized_) return; if (!initialized_) return;
setHorizontalScrollBarPolicy(stretch ? Qt::ScrollBarAlwaysOff : Qt::ScrollBarAsNeeded); setHorizontalScrollBarPolicy(stretch ? Qt::ScrollBarAlwaysOff : Qt::ScrollBarAsNeeded);
SaveGeometry();
} }
@@ -1287,15 +1284,15 @@ void PlaylistView::focusInEvent(QFocusEvent *event) {
void PlaylistView::ResetColumns() { void PlaylistView::ResetColumns() {
read_only_settings_ = true;
setting_initial_header_layout_ = true;
QSettings s; QSettings s;
s.beginGroup(Playlist::kSettingsGroup); s.beginGroup(Playlist::kSettingsGroup);
s.remove("state"); s.remove("state");
s.endGroup(); s.endGroup();
state_loaded_ = false;
read_only_settings_ = true;
setting_initial_header_layout_ = true;
ReloadSettings(); ReloadSettings();
LoadGeometry(); LoadGeometry();
ReloadSettings();
read_only_settings_ = false; read_only_settings_ = false;
SetPlaylist(playlist_); SetPlaylist(playlist_);

View File

@@ -113,10 +113,10 @@ class PlaylistView : public QTreeView {
void setModel(QAbstractItemModel *model); void setModel(QAbstractItemModel *model);
void ResetColumns(); void ResetColumns();
void SaveGeometry();
public slots: public slots:
void ReloadSettings(); void ReloadSettings();
void SaveGeometry();
void SaveSettings(); void SaveSettings();
void StopGlowing(); void StopGlowing();
void StartGlowing(); void StartGlowing();
@@ -171,9 +171,7 @@ class PlaylistView : public QTreeView {
void MaybeAutoscroll(); void MaybeAutoscroll();
void InvalidateCachedCurrentPixmap(); void InvalidateCachedCurrentPixmap();
void PlaylistDestroyed(); void PlaylistDestroyed();
void StretchChanged(bool stretch); void StretchChanged(bool stretch);
void FadePreviousBackgroundImage(qreal value); void FadePreviousBackgroundImage(qreal value);
private: private:
@@ -217,6 +215,7 @@ class PlaylistView : public QTreeView {
bool background_initialized_; bool background_initialized_;
bool setting_initial_header_layout_; bool setting_initial_header_layout_;
bool read_only_settings_; bool read_only_settings_;
bool state_loaded_;
QImage background_image_; QImage background_image_;
QImage current_song_cover_art_; QImage current_song_cover_art_;
@@ -264,6 +263,9 @@ class PlaylistView : public QTreeView {
bool drag_over_; bool drag_over_;
ColumnAlignmentMap column_alignment_; ColumnAlignmentMap column_alignment_;
QByteArray state_;
}; };
#endif // PLAYLISTVIEW_H #endif // PLAYLISTVIEW_H