Remember which sections have been expanded/collapsed

This commit is contained in:
David Sansome 2010-10-11 21:42:31 +00:00
parent 30414ef378
commit 566bd2e2f8
4 changed files with 23 additions and 6 deletions

View File

@ -40,6 +40,7 @@ CollapsibleInfoPane::CollapsibleInfoPane(const Data& data, QWidget* parent)
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
connect(header_, SIGNAL(ExpandedToggled(bool)), SLOT(ExpandedToggled(bool)));
connect(header_, SIGNAL(ExpandedToggled(bool)), SIGNAL(Toggled(bool)));
}
void CollapsibleInfoPane::Collapse() {

View File

@ -58,6 +58,9 @@ public slots:
void Expand();
void Collapse();
signals:
void Toggled(bool expanded);
private slots:
void ExpandedToggled(bool expanded);

View File

@ -155,12 +155,10 @@ void SongInfoBase::CollapseSections() {
// relevance section of each type and hide the rest)
// * If one or more sections in a type have been explicitly hidden/shown
// by the user before then hide all sections in that type and show only
// the ones that are explicitly shown. If there are multiple sections in
// that type, but they are all hidden, then show the first one.
// the ones that are explicitly shown.
QMap<CollapsibleInfoPane::Data::Type, CollapsibleInfoPane*> types_;
QSet<CollapsibleInfoPane::Data::Type> has_user_preference_;
QSet<CollapsibleInfoPane::Data::Type> has_user_preference_on_;
foreach (CollapsibleInfoPane* pane, sections_) {
const CollapsibleInfoPane::Data::Type type = pane->data().type_;
types_.insertMulti(type, pane);
@ -169,17 +167,29 @@ void SongInfoBase::CollapseSections() {
if (preference.isValid()) {
has_user_preference_.insert(type);
if (preference.toBool()) {
has_user_preference_on_.insert(type);
pane->Expand();
}
}
}
foreach (CollapsibleInfoPane::Data::Type type, types_.keys()) {
if (!has_user_preference_.contains(type) ||
(!has_user_preference_on_.contains(type) && types_.values(type).count() > 1)) {
if (!has_user_preference_.contains(type)) {
// Expand the first one
types_.values(type).last()->Expand();
}
}
foreach (CollapsibleInfoPane* pane, sections_) {
connect(pane, SIGNAL(Toggled(bool)), SLOT(SectionToggled(bool)));
}
}
void SongInfoBase::SectionToggled(bool value) {
CollapsibleInfoPane* pane = qobject_cast<CollapsibleInfoPane*>(sender());
if (!pane || !sections_.contains(pane))
return;
QSettings s;
s.beginGroup(kSettingsGroup);
s.setValue(pane->data().id_, value);
}

View File

@ -66,6 +66,9 @@ protected:
private:
void MaybeUpdate(const Song& metadata);
private slots:
void SectionToggled(bool value);
private:
QScrollArea* scroll_area_;