Adds a narrow first column showing a small bold gold "H" for any album with hires_streamable=true. Applies to both fav albums and artist pages. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
76 lines
2.8 KiB
C++
76 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include <QTreeWidget>
|
|
#include <QTreeWidgetItem>
|
|
#include <QHeaderView>
|
|
#include <QFont>
|
|
#include <QJsonObject>
|
|
#include <QJsonArray>
|
|
|
|
/// A simple list of albums (used for fav albums and artist detail pages).
|
|
/// Double-clicking an item emits albumSelected(albumId).
|
|
/// Column 0 shows a small gold "H" for hi-res streamable albums.
|
|
class AlbumListView : public QTreeWidget
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit AlbumListView(QWidget *parent = nullptr) : QTreeWidget(parent)
|
|
{
|
|
setColumnCount(5);
|
|
setHeaderLabels({tr(""), tr("Title"), tr("Artist"), tr("Year"), tr("Tracks")});
|
|
setRootIsDecorated(false);
|
|
setAlternatingRowColors(true);
|
|
setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
setSortingEnabled(true);
|
|
|
|
header()->setStretchLastSection(false);
|
|
header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); // H column
|
|
header()->setSectionResizeMode(1, QHeaderView::Stretch);
|
|
header()->setSectionResizeMode(2, QHeaderView::Stretch);
|
|
header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
|
header()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
|
|
|
|
connect(this, &QTreeWidget::itemDoubleClicked,
|
|
this, [this](QTreeWidgetItem *item, int) {
|
|
const QString id = item->data(1, Qt::UserRole).toString();
|
|
if (!id.isEmpty()) emit albumSelected(id);
|
|
});
|
|
}
|
|
|
|
void setAlbums(const QJsonArray &albums)
|
|
{
|
|
clear();
|
|
QFont hiResFont;
|
|
hiResFont.setBold(true);
|
|
hiResFont.setPointSizeF(hiResFont.pointSizeF() * 0.85);
|
|
|
|
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();
|
|
const bool hiRes = a["hires_streamable"].toBool();
|
|
|
|
auto *item = new QTreeWidgetItem(this);
|
|
if (hiRes) {
|
|
item->setText(0, QStringLiteral("H"));
|
|
item->setForeground(0, QColor(QStringLiteral("#FFD700")));
|
|
item->setFont(0, hiResFont);
|
|
item->setTextAlignment(0, Qt::AlignCenter);
|
|
}
|
|
item->setText(1, title);
|
|
item->setText(2, artist);
|
|
item->setText(3, year);
|
|
item->setText(4, tracks > 0 ? QString::number(tracks) : QString());
|
|
item->setData(1, Qt::UserRole, id);
|
|
}
|
|
}
|
|
|
|
signals:
|
|
void albumSelected(const QString &albumId);
|
|
};
|