feat: album list, artist list, and artist detail views
- Fav albums: now shows a sortable list (title/artist/year/tracks); double-click opens the album - Fav artists: now shows a sortable list; double-click opens the artist - Artist detail page: name, biography summary, and their album list - Rust ArtistDto gains albums field; get_artist fixed to extra=albums only - Volume popup minimum width set so "100%" label is never clipped Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
61
src/view/albumlistview.hpp
Normal file
61
src/view/albumlistview.hpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include <QTreeWidget>
|
||||
#include <QTreeWidgetItem>
|
||||
#include <QHeaderView>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
/// A simple list of albums (used for fav albums and artist detail pages).
|
||||
/// Double-clicking an item emits albumSelected(albumId).
|
||||
class AlbumListView : public QTreeWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AlbumListView(QWidget *parent = nullptr) : QTreeWidget(parent)
|
||||
{
|
||||
setColumnCount(4);
|
||||
setHeaderLabels({tr("Title"), tr("Artist"), tr("Year"), tr("Tracks")});
|
||||
setRootIsDecorated(false);
|
||||
setAlternatingRowColors(true);
|
||||
setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
setSortingEnabled(true);
|
||||
|
||||
header()->setStretchLastSection(false);
|
||||
header()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
header()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||
header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
||||
header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
||||
|
||||
connect(this, &QTreeWidget::itemDoubleClicked,
|
||||
this, [this](QTreeWidgetItem *item, int) {
|
||||
const QString id = item->data(0, Qt::UserRole).toString();
|
||||
if (!id.isEmpty()) emit albumSelected(id);
|
||||
});
|
||||
}
|
||||
|
||||
void setAlbums(const QJsonArray &albums)
|
||||
{
|
||||
clear();
|
||||
for (const auto &v : albums) {
|
||||
const QJsonObject a = v.toObject();
|
||||
const QString id = a["id"].toString();
|
||||
const QString title = a["title"].toString();
|
||||
const QString artist = a["artist"].toObject()["name"].toString();
|
||||
const QString date = a["release_date_original"].toString();
|
||||
const QString year = date.left(4);
|
||||
const int tracks = a["tracks_count"].toInt();
|
||||
|
||||
auto *item = new QTreeWidgetItem(this);
|
||||
item->setText(0, title);
|
||||
item->setText(1, artist);
|
||||
item->setText(2, year);
|
||||
item->setText(3, tracks > 0 ? QString::number(tracks) : QString());
|
||||
item->setData(0, Qt::UserRole, id);
|
||||
}
|
||||
}
|
||||
|
||||
signals:
|
||||
void albumSelected(const QString &albumId);
|
||||
};
|
||||
Reference in New Issue
Block a user