feat: gold H badge on hi-res albums in album list view
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>
This commit is contained in:
@@ -3,11 +3,13 @@
|
||||
#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
|
||||
@@ -15,22 +17,23 @@ class AlbumListView : public QTreeWidget
|
||||
public:
|
||||
explicit AlbumListView(QWidget *parent = nullptr) : QTreeWidget(parent)
|
||||
{
|
||||
setColumnCount(4);
|
||||
setHeaderLabels({tr("Title"), tr("Artist"), tr("Year"), tr("Tracks")});
|
||||
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::Stretch);
|
||||
header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); // H column
|
||||
header()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||
header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
||||
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(0, Qt::UserRole).toString();
|
||||
const QString id = item->data(1, Qt::UserRole).toString();
|
||||
if (!id.isEmpty()) emit albumSelected(id);
|
||||
});
|
||||
}
|
||||
@@ -38,6 +41,10 @@ public:
|
||||
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();
|
||||
@@ -46,13 +53,20 @@ public:
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user