Skip to content

Commit

Permalink
Album context menu in search results
Browse files Browse the repository at this point in the history
  • Loading branch information
kraxarn committed Jul 26, 2020
1 parent 4faf328 commit 2f8a133
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
16 changes: 15 additions & 1 deletion src/searchview.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "searchview.hpp"

SearchView::SearchView(spt::Spotify &spotify, QWidget *parent) : QDockWidget(parent)
SearchView::SearchView(spt::Spotify &spotify, QWidget *parent)
: spotify(spotify), parent(parent), QDockWidget(parent)
{
auto window = (MainWindow*) parent;
auto layout = new QVBoxLayout();
Expand Down Expand Up @@ -80,6 +81,10 @@ SearchView::SearchView(spt::Spotify &spotify, QWidget *parent) : QDockWidget(par
window->setStatus(QString("Failed to load album"), true);
});

// Album context menu
albumList->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
QWidget::connect(albumList, &QWidget::customContextMenuRequested, this, &SearchView::albumMenu);

// Open artist
QListWidget::connect(artistList, &QListWidget::itemClicked, [this, window](QListWidgetItem *item) {
window->openArtist(item->data(RoleArtistId).toString());
Expand Down Expand Up @@ -146,4 +151,13 @@ QTreeWidget *SearchView::defaultTree(const QStringList &headers)
tree->setColumnCount(headers.length());
tree->setHeaderLabels(headers);
return tree;
}

void SearchView::albumMenu(const QPoint &pos)
{
auto item = albumList->itemAt(pos);
auto albumId = item->data(0, RoleAlbumId).toString();
if (albumId.isEmpty())
return;
(new AlbumMenu(spotify, albumId, parent))->popup(albumList->mapToGlobal(pos));
}
14 changes: 10 additions & 4 deletions src/searchview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@
#include <QTreeWidgetItem>
#include <QVBoxLayout>

class SearchView : public QDockWidget
class SearchView: public QDockWidget
{
Q_OBJECT
Q_OBJECT

public:
explicit SearchView(spt::Spotify &spotify, QWidget *parent = nullptr);

private:
QTreeWidget *trackList, *albumList;
QListWidget *artistList, *playlistList;
QListWidget *artistList = nullptr;
QListWidget *playlistList = nullptr;
QTreeWidget *albumList = nullptr;
QTreeWidget *trackList = nullptr;
QWidget *parent = nullptr;
spt::Spotify &spotify;

QTreeWidget *defaultTree(const QStringList &headers);
void albumMenu(const QPoint &pos);
};

0 comments on commit 2f8a133

Please sign in to comment.