Only show delete and save playlist button when item is selected

Fixes #500
This commit is contained in:
Jonas Kvinge 2020-08-06 16:00:03 +02:00
parent 276a34bb66
commit 7aa5f0d258
4 changed files with 27 additions and 3 deletions

View File

@ -116,6 +116,7 @@ PlaylistListContainer::PlaylistListContainer(QWidget *parent)
proxy_->sort(0);
ui_->tree->setModel(proxy_);
connect(ui_->tree, SIGNAL(ItemsSelectedChanged(bool)), SLOT(ItemsSelectedChanged(bool)));
connect(ui_->tree, SIGNAL(doubleClicked(QModelIndex)), SLOT(ItemDoubleClicked(QModelIndex)));
model_->invisibleRootItem()->setData(PlaylistListModel::Type_Folder, PlaylistListModel::Role_Type);
@ -168,6 +169,9 @@ void PlaylistListContainer::ReloadSettings() {
void PlaylistListContainer::showEvent(QShowEvent *e) {
ui_->remove->setEnabled(ui_->tree->ItemsSelected());
ui_->save_playlist->setEnabled(ui_->tree->ItemsSelected());
// Loading icons is expensive so only do it when the view is first opened
if (loaded_icons_) {
QWidget::showEvent(e);
@ -331,6 +335,11 @@ void PlaylistListContainer::PlaylistPathChanged(int id, const QString &new_path)
}
void PlaylistListContainer::ItemsSelectedChanged(const bool selected) {
ui_->remove->setEnabled(selected);
ui_->save_playlist->setEnabled(selected);
}
void PlaylistListContainer::ItemDoubleClicked(const QModelIndex &proxy_index) {
const QModelIndex &index = proxy_->mapToSource(proxy_index);
@ -342,8 +351,7 @@ void PlaylistListContainer::ItemDoubleClicked(const QModelIndex &proxy_index) {
}
void PlaylistListContainer::CopyToDevice()
{
void PlaylistListContainer::CopyToDevice() {
#ifndef Q_OS_WIN
// Reuse the organize dialog, but set the detail about the playlist name
if (!organize_dialog_) {

View File

@ -83,7 +83,9 @@ class PlaylistListContainer : public QWidget {
void ActivePaused();
void ActiveStopped();
private:
void ItemsSelectedChanged(const bool selected);
private:
QStandardItem *ItemForPlaylist(const QString &name, int id);
QStandardItem *ItemForFolder(const QString &name) const;
void RecursivelySetIcons(QStandardItem *parent) const;

View File

@ -56,3 +56,11 @@ void PlaylistListView::paintEvent(QPaintEvent *event) {
AutoExpandingTreeView::paintEvent(event);
}
}
bool PlaylistListView::ItemsSelected() const {
return selectionModel()->selectedRows().count() > 0;
}
void PlaylistListView::selectionChanged(const QItemSelection&, const QItemSelection&) {
emit ItemsSelectedChanged(selectionModel()->selectedRows().count() > 0);
}

View File

@ -37,9 +37,15 @@ class PlaylistListView : public AutoExpandingTreeView {
public:
explicit PlaylistListView(QWidget *parent = nullptr);
bool ItemsSelected() const;
signals:
void ItemsSelectedChanged(bool);
protected:
// QWidget
void paintEvent(QPaintEvent *event) override;
void selectionChanged(const QItemSelection&, const QItemSelection&) override;
};
#endif // PLAYLISTVIEW_H