Mercurial > minori
comparison src/gui/widgets/poster.cc @ 81:9b2b41f83a5e
boring: mass rename to cc
because this is a very unix-y project, it makes more sense to use the
'cc' extension
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 23 Oct 2023 12:07:27 -0400 |
parents | src/gui/widgets/poster.cpp@6f7385bd334c |
children | d02fdf1d6708 |
comparison
equal
deleted
inserted
replaced
80:825506f0e221 | 81:9b2b41f83a5e |
---|---|
1 #include "gui/widgets/poster.h" | |
2 #include "core/anime_db.h" | |
3 #include "core/http.h" | |
4 #include "core/session.h" | |
5 #include "core/strings.h" | |
6 #include "gui/widgets/clickable_label.h" | |
7 #include <QByteArray> | |
8 #include <QDebug> | |
9 #include <QDesktopServices> | |
10 #include <QFrame> | |
11 #include <QHBoxLayout> | |
12 #include <QLabel> | |
13 #include <QMessageBox> | |
14 #include <QPixmap> | |
15 #include <QThreadPool> | |
16 #include <QUrl> | |
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 | |
23 setCursor(Qt::PointingHandCursor); | |
24 setFixedSize(150, 225); | |
25 setFrameShape(QFrame::Box); | |
26 setFrameShadow(QFrame::Plain); | |
27 | |
28 const Anime::Anime& anime = Anime::db.items[id]; | |
29 | |
30 QThreadPool::globalInstance()->start([this, anime] { | |
31 QByteArray ba = HTTP::Get(anime.GetPosterUrl(), {}); | |
32 ImageDownloadFinished(ba); | |
33 }); | |
34 | |
35 QPixmap pixmap = QPixmap::fromImage(img); | |
36 | |
37 label = new ClickableLabel(this); | |
38 label->setAlignment(Qt::AlignCenter); | |
39 connect(label, &ClickableLabel::clicked, this, | |
40 [anime] { QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); }); | |
41 layout->addWidget(label); | |
42 } | |
43 | |
44 void Poster::ImageDownloadFinished(QByteArray arr) { | |
45 img.loadFromData(arr); | |
46 RenderToLabel(); | |
47 } | |
48 | |
49 void Poster::RenderToLabel() { | |
50 QPixmap pixmap = QPixmap::fromImage(img); | |
51 if (pixmap.isNull()) | |
52 return; | |
53 label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); | |
54 } | |
55 | |
56 void Poster::resizeEvent(QResizeEvent*) { | |
57 RenderToLabel(); | |
58 } | |
59 | |
60 #include "gui/widgets/moc_poster.cpp" |