Mercurial > minori
annotate src/gui/widgets/poster.cpp @ 76:3364fadc8a36
*: format source code
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 04 Oct 2023 01:46:33 -0400 |
parents | d3e9310598b1 |
children | 6f7385bd334c |
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> | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
15 #include <QUrl> |
66 | 16 #include <curl/curl.h> |
17 | |
18 Poster::Poster(int id, QWidget* parent) : QFrame(parent) { | |
19 QHBoxLayout* layout = new QHBoxLayout(this); | |
20 layout->setContentsMargins(1, 1, 1, 1); | |
21 | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
22 setCursor(Qt::PointingHandCursor); |
66 | 23 setFixedSize(150, 225); |
24 setFrameShape(QFrame::Box); | |
25 setFrameShadow(QFrame::Plain); | |
76 | 26 |
66 | 27 const Anime::Anime& anime = Anime::db.items[id]; |
28 | |
76 | 29 HTTP::HttpGetThread* image_thread = new HTTP::HttpGetThread(anime.GetPosterUrl(), {}, this); |
75 | 30 connect(image_thread, &HTTP::HttpGetThread::resultReady, this, &Poster::ImageDownloadFinished); |
31 connect(image_thread, &HTTP::HttpGetThread::finished, image_thread, &QObject::deleteLater); | |
32 image_thread->start(); | |
33 | |
66 | 34 QPixmap pixmap = QPixmap::fromImage(img); |
35 | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
36 label = new ClickableLabel(this); |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
67
diff
changeset
|
37 label->setAlignment(Qt::AlignCenter); |
76 | 38 connect(label, &ClickableLabel::clicked, this, |
39 [anime] { QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); }); | |
66 | 40 layout->addWidget(label); |
41 } | |
42 | |
75 | 43 void Poster::ImageDownloadFinished(QByteArray arr) { |
44 img.loadFromData(arr); | |
45 RenderToLabel(); | |
46 } | |
47 | |
48 void Poster::RenderToLabel() { | |
49 QPixmap pixmap = QPixmap::fromImage(img); | |
76 | 50 if (pixmap.isNull()) |
51 return; | |
75 | 52 label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); |
53 } | |
54 | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
55 void Poster::resizeEvent(QResizeEvent*) { |
75 | 56 RenderToLabel(); |
66 | 57 } |
58 | |
59 #include "gui/widgets/moc_poster.cpp" |