feat: restore most-popular search and top results badges
Some checks failed
Build for Windows / build-windows (push) Has been cancelled
Some checks failed
Build for Windows / build-windows (push) Has been cancelled
This commit is contained in:
@@ -39,6 +39,14 @@ SearchTab::SearchTab(QobuzBackend *backend, PlayQueue *queue, QWidget *parent)
|
||||
// Result tabs
|
||||
m_resultTabs = new QTabWidget(this);
|
||||
|
||||
m_topResults = new QTreeWidget(this);
|
||||
m_topResults->setHeaderLabels({tr(""), tr("Top Result"), tr("Info")});
|
||||
m_topResults->setRootIsDecorated(false);
|
||||
m_topResults->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
||||
m_topResults->header()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||
m_topResults->header()->setSectionResizeMode(2, QHeaderView::Stretch);
|
||||
m_topResults->header()->setStretchLastSection(false);
|
||||
|
||||
m_trackResults = new QTreeWidget(this);
|
||||
m_trackResults->setHeaderLabels({tr("Title"), tr("Artist"), tr("Album")});
|
||||
m_trackResults->setRootIsDecorated(false);
|
||||
@@ -57,6 +65,7 @@ SearchTab::SearchTab(QobuzBackend *backend, PlayQueue *queue, QWidget *parent)
|
||||
m_artistResults->setHeaderLabels({tr("Artist")});
|
||||
m_artistResults->setRootIsDecorated(false);
|
||||
|
||||
m_resultTabs->addTab(m_topResults, tr("Top Results"));
|
||||
m_resultTabs->addTab(m_trackResults, tr("Tracks"));
|
||||
m_resultTabs->addTab(m_albumResults, tr("Albums"));
|
||||
m_resultTabs->addTab(m_artistResults, tr("Artists"));
|
||||
@@ -66,7 +75,9 @@ SearchTab::SearchTab(QobuzBackend *backend, PlayQueue *queue, QWidget *parent)
|
||||
connect(m_searchBox, &QLineEdit::returnPressed, this, &SearchTab::onSearchSubmit);
|
||||
|
||||
connect(m_backend, &QobuzBackend::searchResult, this, &SearchTab::onSearchResult);
|
||||
connect(m_backend, &QobuzBackend::mostPopularResult, this, &SearchTab::onMostPopularResult);
|
||||
|
||||
connect(m_topResults, &QTreeWidget::itemDoubleClicked, this, &SearchTab::onItemDoubleClicked);
|
||||
connect(m_trackResults, &QTreeWidget::itemDoubleClicked, this, &SearchTab::onItemDoubleClicked);
|
||||
connect(m_albumResults, &QTreeWidget::itemDoubleClicked, this, &SearchTab::onItemDoubleClicked);
|
||||
connect(m_artistResults, &QTreeWidget::itemDoubleClicked, this, &SearchTab::onItemDoubleClicked);
|
||||
@@ -86,8 +97,67 @@ void SearchTab::setUserPlaylists(const QVector<QPair<qint64, QString>> &playlist
|
||||
void SearchTab::onSearchSubmit()
|
||||
{
|
||||
const QString q = m_searchBox->text().trimmed();
|
||||
if (!q.isEmpty())
|
||||
if (!q.isEmpty()) {
|
||||
m_backend->mostPopularSearch(q, 8);
|
||||
m_backend->search(q, 0, 20);
|
||||
m_resultTabs->setCurrentIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
void SearchTab::onMostPopularResult(const QJsonObject &result)
|
||||
{
|
||||
m_topResults->clear();
|
||||
|
||||
QFont badgeFont;
|
||||
badgeFont.setBold(true);
|
||||
|
||||
const QJsonArray items = result["most_popular"].toObject()["items"].toArray();
|
||||
for (const auto &value : items) {
|
||||
const QJsonObject itemObj = value.toObject();
|
||||
const QString type = itemObj["type"].toString();
|
||||
const QJsonObject content = itemObj["content"].toObject();
|
||||
|
||||
auto *item = new QTreeWidgetItem(m_topResults);
|
||||
item->setData(0, JsonRole, content);
|
||||
|
||||
if (type == QStringLiteral("tracks")) {
|
||||
const QString title = content["title"].toString();
|
||||
const QString artist = content["performer"].toObject()["name"].toString();
|
||||
const QString album = content["album"].toObject()["title"].toString();
|
||||
item->setText(0, QStringLiteral("T"));
|
||||
item->setForeground(0, QColor(QStringLiteral("#2FA84F")));
|
||||
item->setFont(0, badgeFont);
|
||||
item->setTextAlignment(0, Qt::AlignCenter);
|
||||
item->setText(1, title);
|
||||
item->setText(2, artist.isEmpty() ? album : QStringLiteral("%1 - %2").arg(artist, album));
|
||||
item->setData(0, TypeRole, QStringLiteral("track"));
|
||||
item->setData(0, IdRole, static_cast<qint64>(content["id"].toDouble()));
|
||||
} else if (type == QStringLiteral("albums")) {
|
||||
const QString title = content["title"].toString();
|
||||
const QString artist = content["artist"].toObject()["name"].toString();
|
||||
const bool hiRes = content["hires_streamable"].toBool()
|
||||
|| content["rights"].toObject()["hires_streamable"].toBool();
|
||||
item->setText(0, hiRes ? QStringLiteral("H") : QStringLiteral("A"));
|
||||
item->setForeground(0, hiRes
|
||||
? QColor(QStringLiteral("#FFB232"))
|
||||
: QColor(QStringLiteral("#8E8E93")));
|
||||
item->setFont(0, badgeFont);
|
||||
item->setTextAlignment(0, Qt::AlignCenter);
|
||||
item->setText(1, title);
|
||||
item->setText(2, artist);
|
||||
item->setData(0, TypeRole, QStringLiteral("album"));
|
||||
item->setData(1, IdRole, content["id"].toString());
|
||||
} else if (type == QStringLiteral("artists")) {
|
||||
item->setText(0, QStringLiteral("A"));
|
||||
item->setForeground(0, QColor(QStringLiteral("#2B7CD3")));
|
||||
item->setFont(0, badgeFont);
|
||||
item->setTextAlignment(0, Qt::AlignCenter);
|
||||
item->setText(1, content["name"].toString());
|
||||
item->setText(2, tr("Artist"));
|
||||
item->setData(0, TypeRole, QStringLiteral("artist"));
|
||||
item->setData(0, IdRole, static_cast<qint64>(content["id"].toDouble()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SearchTab::onSearchResult(const QJsonObject &result)
|
||||
|
||||
Reference in New Issue
Block a user