Mercurial > minori
diff src/gui/widgets/poster.cc @ 83:d02fdf1d6708
*: huuuge update
1. make the now playing page function correctly
2. de-constructorfy many of our custom widgets,
allowing them to be changed on-the-fly from
the Now Playing page
3. ... :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 24 Oct 2023 22:01:02 -0400 |
parents | 9b2b41f83a5e |
children | 9613d72b097e |
line wrap: on
line diff
--- a/src/gui/widgets/poster.cc Mon Oct 23 13:37:42 2023 -0400 +++ b/src/gui/widgets/poster.cc Tue Oct 24 22:01:02 2023 -0400 @@ -16,7 +16,7 @@ #include <QUrl> #include <curl/curl.h> -Poster::Poster(int id, QWidget* parent) : QFrame(parent) { +Poster::Poster(QWidget* parent) : QFrame(parent) { QHBoxLayout* layout = new QHBoxLayout(this); layout->setContentsMargins(1, 1, 1, 1); @@ -25,23 +25,27 @@ setFrameShape(QFrame::Box); setFrameShadow(QFrame::Plain); - const Anime::Anime& anime = Anime::db.items[id]; + label = new ClickableLabel(this); + label->setAlignment(Qt::AlignCenter); + layout->addWidget(label); +} +Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) { + SetAnime(anime); +} + +void Poster::SetAnime(const Anime::Anime& anime) { QThreadPool::globalInstance()->start([this, anime] { QByteArray ba = HTTP::Get(anime.GetPosterUrl(), {}); ImageDownloadFinished(ba); }); - QPixmap pixmap = QPixmap::fromImage(img); - - label = new ClickableLabel(this); - label->setAlignment(Qt::AlignCenter); + label->disconnect(); connect(label, &ClickableLabel::clicked, this, [anime] { QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); }); - layout->addWidget(label); } -void Poster::ImageDownloadFinished(QByteArray arr) { +void Poster::ImageDownloadFinished(const QByteArray& arr) { img.loadFromData(arr); RenderToLabel(); }