Mercurial > minori
annotate src/gui/widgets/poster.cpp @ 77:6f7385bd334c
*: update
formatted all source files, no more subclassing QThread... many other
changes :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 06 Oct 2023 06:18:53 -0400 |
parents | 3364fadc8a36 |
children |
rev | line source |
---|---|
66 | 1 #include "gui/widgets/poster.h" |
2 #include "core/anime_db.h" | |
75 | 3 #include "core/http.h" |
76 | 4 #include "core/session.h" |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
5 #include "core/strings.h" |
76 | 6 #include "gui/widgets/clickable_label.h" |
7 #include <QByteArray> | |
8 #include <QDebug> | |
9 #include <QDesktopServices> | |
66 | 10 #include <QFrame> |
11 #include <QHBoxLayout> | |
76 | 12 #include <QLabel> |
13 #include <QMessageBox> | |
14 #include <QPixmap> | |
77 | 15 #include <QThreadPool> |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
16 #include <QUrl> |
66 | 17 #include <curl/curl.h> |
18 | |
19 Poster::Poster(int id, QWidget* parent) : QFrame(parent) { | |
20 QHBoxLayout* layout = new QHBoxLayout(this); | |
21 layout->setContentsMargins(1, 1, 1, 1); | |
22 | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
23 setCursor(Qt::PointingHandCursor); |
66 | 24 setFixedSize(150, 225); |
25 setFrameShape(QFrame::Box); | |
26 setFrameShadow(QFrame::Plain); | |
76 | 27 |
66 | 28 const Anime::Anime& anime = Anime::db.items[id]; |
29 | |
77 | 30 QThreadPool::globalInstance()->start([this, anime] { |
31 QByteArray ba = HTTP::Get(anime.GetPosterUrl(), {}); | |
32 ImageDownloadFinished(ba); | |
33 }); | |
75 | 34 |
66 | 35 QPixmap pixmap = QPixmap::fromImage(img); |
36 | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
37 label = new ClickableLabel(this); |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
67
diff
changeset
|
38 label->setAlignment(Qt::AlignCenter); |
76 | 39 connect(label, &ClickableLabel::clicked, this, |
40 [anime] { QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); }); | |
66 | 41 layout->addWidget(label); |
42 } | |
43 | |
75 | 44 void Poster::ImageDownloadFinished(QByteArray arr) { |
45 img.loadFromData(arr); | |
46 RenderToLabel(); | |
47 } | |
48 | |
49 void Poster::RenderToLabel() { | |
50 QPixmap pixmap = QPixmap::fromImage(img); | |
76 | 51 if (pixmap.isNull()) |
52 return; | |
75 | 53 label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); |
54 } | |
55 | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
56 void Poster::resizeEvent(QResizeEvent*) { |
75 | 57 RenderToLabel(); |
66 | 58 } |
59 | |
60 #include "gui/widgets/moc_poster.cpp" |