Only show delete and save playlist button when item is selected
Fixes #500
This commit is contained in:
parent
276a34bb66
commit
7aa5f0d258
|
@ -116,6 +116,7 @@ PlaylistListContainer::PlaylistListContainer(QWidget *parent)
|
||||||
proxy_->sort(0);
|
proxy_->sort(0);
|
||||||
ui_->tree->setModel(proxy_);
|
ui_->tree->setModel(proxy_);
|
||||||
|
|
||||||
|
connect(ui_->tree, SIGNAL(ItemsSelectedChanged(bool)), SLOT(ItemsSelectedChanged(bool)));
|
||||||
connect(ui_->tree, SIGNAL(doubleClicked(QModelIndex)), SLOT(ItemDoubleClicked(QModelIndex)));
|
connect(ui_->tree, SIGNAL(doubleClicked(QModelIndex)), SLOT(ItemDoubleClicked(QModelIndex)));
|
||||||
|
|
||||||
model_->invisibleRootItem()->setData(PlaylistListModel::Type_Folder, PlaylistListModel::Role_Type);
|
model_->invisibleRootItem()->setData(PlaylistListModel::Type_Folder, PlaylistListModel::Role_Type);
|
||||||
|
@ -168,6 +169,9 @@ void PlaylistListContainer::ReloadSettings() {
|
||||||
|
|
||||||
void PlaylistListContainer::showEvent(QShowEvent *e) {
|
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
|
// Loading icons is expensive so only do it when the view is first opened
|
||||||
if (loaded_icons_) {
|
if (loaded_icons_) {
|
||||||
QWidget::showEvent(e);
|
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) {
|
void PlaylistListContainer::ItemDoubleClicked(const QModelIndex &proxy_index) {
|
||||||
|
|
||||||
const QModelIndex &index = proxy_->mapToSource(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
|
#ifndef Q_OS_WIN
|
||||||
// Reuse the organize dialog, but set the detail about the playlist name
|
// Reuse the organize dialog, but set the detail about the playlist name
|
||||||
if (!organize_dialog_) {
|
if (!organize_dialog_) {
|
||||||
|
|
|
@ -83,7 +83,9 @@ class PlaylistListContainer : public QWidget {
|
||||||
void ActivePaused();
|
void ActivePaused();
|
||||||
void ActiveStopped();
|
void ActiveStopped();
|
||||||
|
|
||||||
private:
|
void ItemsSelectedChanged(const bool selected);
|
||||||
|
|
||||||
|
private:
|
||||||
QStandardItem *ItemForPlaylist(const QString &name, int id);
|
QStandardItem *ItemForPlaylist(const QString &name, int id);
|
||||||
QStandardItem *ItemForFolder(const QString &name) const;
|
QStandardItem *ItemForFolder(const QString &name) const;
|
||||||
void RecursivelySetIcons(QStandardItem *parent) const;
|
void RecursivelySetIcons(QStandardItem *parent) const;
|
||||||
|
|
|
@ -56,3 +56,11 @@ void PlaylistListView::paintEvent(QPaintEvent *event) {
|
||||||
AutoExpandingTreeView::paintEvent(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);
|
||||||
|
}
|
||||||
|
|
|
@ -37,9 +37,15 @@ class PlaylistListView : public AutoExpandingTreeView {
|
||||||
public:
|
public:
|
||||||
explicit PlaylistListView(QWidget *parent = nullptr);
|
explicit PlaylistListView(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
bool ItemsSelected() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void ItemsSelectedChanged(bool);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// QWidget
|
// QWidget
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
void selectionChanged(const QItemSelection&, const QItemSelection&) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLAYLISTVIEW_H
|
#endif // PLAYLISTVIEW_H
|
||||||
|
|
Loading…
Reference in New Issue