Add an option to disable the library view's behaviour of automatically opening nodes without many children.
This commit is contained in:
parent
7415b7f4bd
commit
1f2220ac63
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "libraryconfig.h"
|
||||
#include "librarydirectorymodel.h"
|
||||
#include "libraryview.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QSettings>
|
||||
|
@ -75,3 +76,17 @@ void LibraryConfig::BackendReady() {
|
|||
ui_.add->setEnabled(true);
|
||||
ui_.remove->setEnabled(true);
|
||||
}
|
||||
|
||||
void LibraryConfig::Save() {
|
||||
QSettings s;
|
||||
s.beginGroup(LibraryView::kSettingsGroup);
|
||||
|
||||
s.setValue("auto_open", ui_.auto_open->isChecked());
|
||||
}
|
||||
|
||||
void LibraryConfig::showEvent(QShowEvent *) {
|
||||
QSettings s;
|
||||
s.beginGroup(LibraryView::kSettingsGroup);
|
||||
|
||||
ui_.auto_open->setChecked(s.value("auto_open", true).toBool());
|
||||
}
|
||||
|
|
|
@ -31,6 +31,12 @@ class LibraryConfig : public QWidget {
|
|||
|
||||
void SetModel(LibraryDirectoryModel* model);
|
||||
|
||||
public slots:
|
||||
void Save();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
|
||||
private slots:
|
||||
void Add();
|
||||
void Remove();
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>489</width>
|
||||
<height>232</height>
|
||||
<width>481</width>
|
||||
<height>320</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
|
@ -88,6 +88,22 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Options</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="auto_open">
|
||||
<property name="text">
|
||||
<string>Automatically open single categories in the library tree</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
|
|
|
@ -25,3 +25,8 @@ LibraryConfigDialog::LibraryConfigDialog(QWidget *parent)
|
|||
void LibraryConfigDialog::SetModel(LibraryDirectoryModel* model) {
|
||||
ui_.config->SetModel(model);
|
||||
}
|
||||
|
||||
void LibraryConfigDialog::accept() {
|
||||
ui_.config->Save();
|
||||
QDialog::accept();
|
||||
}
|
||||
|
|
|
@ -30,6 +30,9 @@ class LibraryConfigDialog : public QDialog {
|
|||
|
||||
void SetModel(LibraryDirectoryModel* model);
|
||||
|
||||
public slots:
|
||||
void accept();
|
||||
|
||||
private:
|
||||
Ui::LibraryConfigDialog ui_;
|
||||
};
|
||||
|
|
|
@ -22,8 +22,10 @@
|
|||
#include <QContextMenuEvent>
|
||||
#include <QMenu>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QSettings>
|
||||
|
||||
const int LibraryView::kRowsToShow = 50;
|
||||
const char* LibraryView::kSettingsGroup = "LibraryView";
|
||||
|
||||
LibraryItemDelegate::LibraryItemDelegate(QObject *parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
|
@ -75,6 +77,7 @@ LibraryView::LibraryView(QWidget* parent)
|
|||
: QTreeView(parent),
|
||||
library_(NULL),
|
||||
total_song_count_(-1),
|
||||
auto_open_(true),
|
||||
nomusic_(":nomusic.png"),
|
||||
context_menu_(new QMenu(this))
|
||||
{
|
||||
|
@ -86,6 +89,15 @@ LibraryView::LibraryView(QWidget* parent)
|
|||
tr("Show in various artists"), this, SLOT(ShowInVarious()));
|
||||
no_show_in_various_ = context_menu_->addAction(
|
||||
tr("Don't show in various artists"), this, SLOT(NoShowInVarious()));
|
||||
|
||||
ReloadSettings();
|
||||
}
|
||||
|
||||
void LibraryView::ReloadSettings() {
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
|
||||
auto_open_ = s.value("auto_open", true).toBool();
|
||||
}
|
||||
|
||||
void LibraryView::SetLibrary(Library *library) {
|
||||
|
@ -108,8 +120,10 @@ void LibraryView::reset() {
|
|||
QTreeView::reset();
|
||||
|
||||
// Expand nodes in the tree until we have about 50 rows visible in the view
|
||||
int rows = model()->rowCount(rootIndex());
|
||||
RecursivelyExpand(rootIndex(), &rows);
|
||||
if (auto_open_) {
|
||||
int rows = model()->rowCount(rootIndex());
|
||||
RecursivelyExpand(rootIndex(), &rows);
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryView::paintEvent(QPaintEvent* event) {
|
||||
|
@ -166,7 +180,7 @@ bool LibraryView::RecursivelyExpand(const QModelIndex& index, int* count) {
|
|||
}
|
||||
|
||||
void LibraryView::ItemExpanded(const QModelIndex& index) {
|
||||
if (model()->rowCount(index) == 1)
|
||||
if (model()->rowCount(index) == 1 && auto_open_)
|
||||
expand(model()->index(0, 0, index));
|
||||
}
|
||||
|
||||
|
|
|
@ -34,10 +34,13 @@ class LibraryView : public QTreeView {
|
|||
public:
|
||||
LibraryView(QWidget* parent = 0);
|
||||
|
||||
static const char* kSettingsGroup;
|
||||
|
||||
void SetLibrary(Library* library);
|
||||
|
||||
public slots:
|
||||
void TotalSongCountUpdated(int count);
|
||||
void ReloadSettings();
|
||||
|
||||
signals:
|
||||
void ShowConfigDialog();
|
||||
|
@ -66,6 +69,7 @@ class LibraryView : public QTreeView {
|
|||
|
||||
Library* library_;
|
||||
int total_song_count_;
|
||||
bool auto_open_;
|
||||
|
||||
QPixmap nomusic_;
|
||||
|
||||
|
|
|
@ -261,6 +261,7 @@ MainWindow::MainWindow(QNetworkAccessManager* network, QWidget *parent)
|
|||
library_menu->addSeparator();
|
||||
library_menu->addAction(tr("Configure library..."), library_config_dialog_, SLOT(show()));
|
||||
ui_.library_options->setMenu(library_menu);
|
||||
connect(library_config_dialog_, SIGNAL(accepted()), ui_.library_view, SLOT(ReloadSettings()));
|
||||
|
||||
// Playlist menu
|
||||
playlist_play_pause_ = playlist_menu_->addAction(tr("Play"), this, SLOT(PlaylistPlay()));
|
||||
|
@ -315,6 +316,7 @@ MainWindow::MainWindow(QNetworkAccessManager* network, QWidget *parent)
|
|||
// Settings
|
||||
connect(settings_dialog_, SIGNAL(accepted()), player_, SLOT(ReloadSettings()));
|
||||
connect(settings_dialog_, SIGNAL(accepted()), osd_, SLOT(ReloadSettings()));
|
||||
connect(settings_dialog_, SIGNAL(accepted()), ui_.library_view, SLOT(ReloadSettings()));
|
||||
|
||||
// Add stream dialog
|
||||
connect(add_stream_dialog_, SIGNAL(accepted()), SLOT(AddStreamAccepted()));
|
||||
|
|
|
@ -120,6 +120,8 @@ void SettingsDialog::accept() {
|
|||
s.setValue("popup_pos", pretty_popup_->current_pos());
|
||||
s.endGroup();
|
||||
|
||||
ui_.library_config->Save();
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue