Mercurial > minori
annotate src/gui/widgets/poster.cc @ 198:bc1ae1810855
dep/animia: switch from using classes to global functions
the old idea was ok, but sort of hackish; this method doesn't use classes
at all, and this way (especially important!) we can do wayland stuff AND x11
at the same time, which wasn't really possible without stupid workarounds in
the other method
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 24 Dec 2023 02:59:42 -0500 |
parents | 9613d72b097e |
children | 2f5a9247e501 |
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 | |
83 | 19 Poster::Poster(QWidget* parent) : QFrame(parent) { |
66 | 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 |
83 | 28 label = new ClickableLabel(this); |
29 label->setAlignment(Qt::AlignCenter); | |
30 layout->addWidget(label); | |
31 } | |
66 | 32 |
83 | 33 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) { |
34 SetAnime(anime); | |
35 } | |
36 | |
37 void Poster::SetAnime(const Anime::Anime& anime) { | |
77 | 38 QThreadPool::globalInstance()->start([this, anime] { |
39 QByteArray ba = HTTP::Get(anime.GetPosterUrl(), {}); | |
40 ImageDownloadFinished(ba); | |
41 }); | |
75 | 42 |
83 | 43 label->disconnect(); |
76 | 44 connect(label, &ClickableLabel::clicked, this, |
45 [anime] { QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); }); | |
66 | 46 } |
47 | |
83 | 48 void Poster::ImageDownloadFinished(const QByteArray& arr) { |
75 | 49 img.loadFromData(arr); |
50 RenderToLabel(); | |
51 } | |
52 | |
53 void Poster::RenderToLabel() { | |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
54 const QPixmap pixmap = QPixmap::fromImage(img); |
76 | 55 if (pixmap.isNull()) |
56 return; | |
75 | 57 label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); |
58 } | |
59 | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
60 void Poster::resizeEvent(QResizeEvent*) { |
75 | 61 RenderToLabel(); |
66 | 62 } |
63 | |
64 #include "gui/widgets/moc_poster.cpp" |