From 886f9be488970798b2725ad2e9ddf26b5cadee07 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sat, 16 Jan 2021 15:52:48 +0000 Subject: library: add context menu git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9639 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/library/librarymodel.cpp | 36 +++++++++++++++++++++++++++ src/plugins/General/library/librarymodel.h | 4 ++- src/plugins/General/library/librarywidget.cpp | 23 +++++++++++++++++ src/plugins/General/library/librarywidget.h | 8 ++++++ 4 files changed, 70 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/plugins/General/library/librarymodel.cpp b/src/plugins/General/library/librarymodel.cpp index fef15669f..d02e9ba27 100644 --- a/src/plugins/General/library/librarymodel.cpp +++ b/src/plugins/General/library/librarymodel.cpp @@ -26,8 +26,11 @@ #include #include #include +#include #include #include +#include +#include #include "librarymodel.h" #define CONNECTION_NAME "qmmp_library_view" @@ -303,6 +306,39 @@ void LibraryModel::refresh() endResetModel(); } +void LibraryModel::add(const QModelIndexList &indexes) +{ + QList tracks; + + for(const QModelIndex &index : indexes) + { + if(index.isValid()) + { + tracks << getTracks(index); + } + } + + PlayListManager::instance()->add(tracks); +} + +void LibraryModel::showInformation(const QModelIndexList &indexes, QWidget *parent) +{ + QList tracks; + + for(const QModelIndex &index : indexes) + { + if(index.isValid()) + { + tracks << getTracks(index); + } + } + + DetailsDialog *dialog = new DetailsDialog(tracks, parent); + dialog->setAttribute(Qt::WA_DeleteOnClose, true); + dialog->show(); + connect(dialog, &QObject::destroyed, [=]() { qDeleteAll(tracks); }); +} + QList LibraryModel::getTracks(const QModelIndex &index) const { QSqlDatabase db = QSqlDatabase::database(CONNECTION_NAME); diff --git a/src/plugins/General/library/librarymodel.h b/src/plugins/General/library/librarymodel.h index f1d604b38..5ba99d936 100644 --- a/src/plugins/General/library/librarymodel.h +++ b/src/plugins/General/library/librarymodel.h @@ -26,6 +26,7 @@ #include #include +class QWidget; class QSqlDatabase; class LibraryTreeItem; class PlayListTrack; @@ -50,7 +51,8 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const override; void setFilter(const QString &filter); void refresh(); - + void add(const QModelIndexList &indexes); + void showInformation(const QModelIndexList &indexes, QWidget *parent); private: QList getTracks(const QModelIndex &index) const; diff --git a/src/plugins/General/library/librarywidget.cpp b/src/plugins/General/library/librarywidget.cpp index 5b6f108e4..eea4ce983 100644 --- a/src/plugins/General/library/librarywidget.cpp +++ b/src/plugins/General/library/librarywidget.cpp @@ -19,6 +19,9 @@ ***************************************************************************/ #include +#include +#include +#include #include #include "librarymodel.h" #include "ui_librarywidget.h" @@ -43,6 +46,11 @@ LibraryWidget::LibraryWidget(bool dialog, QWidget *parent) : m_ui->buttonBox->hide(); } + m_menu = new QMenu(this); + m_menu->addAction(QIcon::fromTheme("list-add"), tr("&Add to Playlist"), this, SLOT(addSelected())); + m_menu->addSeparator(); + m_menu->addAction(QIcon::fromTheme("dialog-information"), tr("&View Track Details"), this, SLOT(showInformation())); + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); m_ui->filterLineEdit->setVisible(settings.value("Library/quick_search_visible", true).toBool()); } @@ -58,6 +66,11 @@ void LibraryWidget::refresh() m_model->refresh(); } +void LibraryWidget::contextMenuEvent(QContextMenuEvent *e) +{ + m_menu->exec(mapToGlobal(e->pos())); +} + void LibraryWidget::on_filterLineEdit_textChanged(const QString &text) { m_model->setFilter(text); @@ -65,3 +78,13 @@ void LibraryWidget::on_filterLineEdit_textChanged(const QString &text) if(text.count() >= 3) m_ui->treeView->expandAll(); } + +void LibraryWidget::addSelected() +{ + m_model->add(m_ui->treeView->selectionModel()->selectedIndexes()); +} + +void LibraryWidget::showInformation() +{ + m_model->showInformation(m_ui->treeView->selectionModel()->selectedIndexes(), this); +} diff --git a/src/plugins/General/library/librarywidget.h b/src/plugins/General/library/librarywidget.h index a77e543a8..126c916c4 100644 --- a/src/plugins/General/library/librarywidget.h +++ b/src/plugins/General/library/librarywidget.h @@ -27,7 +27,9 @@ namespace Ui { class LibraryWidget; } +class QMenu; class LibraryModel; +class QContextMenuEvent; class LibraryWidget : public QWidget { @@ -37,12 +39,18 @@ public: ~LibraryWidget(); void refresh(); +private: + void contextMenuEvent(QContextMenuEvent *e); + private slots: void on_filterLineEdit_textChanged(const QString &text); + void addSelected(); + void showInformation(); private: Ui::LibraryWidget *m_ui; LibraryModel *m_model; + QMenu *m_menu; }; #endif // LIBRARYWIDGET_H -- cgit v1.2.3-13-gbd6f