aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2021-01-16 15:52:48 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2021-01-16 15:52:48 +0000
commit886f9be488970798b2725ad2e9ddf26b5cadee07 (patch)
treeed8c11574352818cafb69139f111c65110f2763b /src/plugins
parente336a9c15821384f6a45c3ef76bc133c133e35e5 (diff)
downloadqmmp-886f9be488970798b2725ad2e9ddf26b5cadee07.tar.gz
qmmp-886f9be488970798b2725ad2e9ddf26b5cadee07.tar.bz2
qmmp-886f9be488970798b2725ad2e9ddf26b5cadee07.zip
library: add context menu
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9639 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/General/library/librarymodel.cpp36
-rw-r--r--src/plugins/General/library/librarymodel.h4
-rw-r--r--src/plugins/General/library/librarywidget.cpp23
-rw-r--r--src/plugins/General/library/librarywidget.h8
4 files changed, 70 insertions, 1 deletions
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 <QHash>
#include <QJsonDocument>
#include <QJsonObject>
+#include <QWidget>
#include <qmmp/qmmp.h>
#include <qmmpui/playlistparser.h>
+#include <qmmpui/playlistmanager.h>
+#include <qmmpui/detailsdialog.h>
#include "librarymodel.h"
#define CONNECTION_NAME "qmmp_library_view"
@@ -303,6 +306,39 @@ void LibraryModel::refresh()
endResetModel();
}
+void LibraryModel::add(const QModelIndexList &indexes)
+{
+ QList<PlayListTrack *> 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<PlayListTrack *> 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<PlayListTrack *> 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 <QUrl>
#include <QAbstractItemModel>
+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<PlayListTrack *> 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 <QSettings>
+#include <QMenu>
+#include <QContextMenuEvent>
+#include <QIcon>
#include <qmmp/qmmp.h>
#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