comparison 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
comparison
equal deleted inserted replaced
82:8b65c417c225 83:d02fdf1d6708
14 #include <QPixmap> 14 #include <QPixmap>
15 #include <QThreadPool> 15 #include <QThreadPool>
16 #include <QUrl> 16 #include <QUrl>
17 #include <curl/curl.h> 17 #include <curl/curl.h>
18 18
19 Poster::Poster(int id, QWidget* parent) : QFrame(parent) { 19 Poster::Poster(QWidget* parent) : QFrame(parent) {
20 QHBoxLayout* layout = new QHBoxLayout(this); 20 QHBoxLayout* layout = new QHBoxLayout(this);
21 layout->setContentsMargins(1, 1, 1, 1); 21 layout->setContentsMargins(1, 1, 1, 1);
22 22
23 setCursor(Qt::PointingHandCursor); 23 setCursor(Qt::PointingHandCursor);
24 setFixedSize(150, 225); 24 setFixedSize(150, 225);
25 setFrameShape(QFrame::Box); 25 setFrameShape(QFrame::Box);
26 setFrameShadow(QFrame::Plain); 26 setFrameShadow(QFrame::Plain);
27 27
28 const Anime::Anime& anime = Anime::db.items[id]; 28 label = new ClickableLabel(this);
29 label->setAlignment(Qt::AlignCenter);
30 layout->addWidget(label);
31 }
29 32
33 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) {
34 SetAnime(anime);
35 }
36
37 void Poster::SetAnime(const Anime::Anime& anime) {
30 QThreadPool::globalInstance()->start([this, anime] { 38 QThreadPool::globalInstance()->start([this, anime] {
31 QByteArray ba = HTTP::Get(anime.GetPosterUrl(), {}); 39 QByteArray ba = HTTP::Get(anime.GetPosterUrl(), {});
32 ImageDownloadFinished(ba); 40 ImageDownloadFinished(ba);
33 }); 41 });
34 42
35 QPixmap pixmap = QPixmap::fromImage(img); 43 label->disconnect();
36
37 label = new ClickableLabel(this);
38 label->setAlignment(Qt::AlignCenter);
39 connect(label, &ClickableLabel::clicked, this, 44 connect(label, &ClickableLabel::clicked, this,
40 [anime] { QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); }); 45 [anime] { QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); });
41 layout->addWidget(label);
42 } 46 }
43 47
44 void Poster::ImageDownloadFinished(QByteArray arr) { 48 void Poster::ImageDownloadFinished(const QByteArray& arr) {
45 img.loadFromData(arr); 49 img.loadFromData(arr);
46 RenderToLabel(); 50 RenderToLabel();
47 } 51 }
48 52
49 void Poster::RenderToLabel() { 53 void Poster::RenderToLabel() {