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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include "gui/widgets/poster.h"
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 #include "core/anime_db.h"
75
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
3 #include "core/http.h"
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
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
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
6 #include "gui/widgets/clickable_label.h"
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
7 #include <QByteArray>
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
8 #include <QDebug>
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
9 #include <QDesktopServices>
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 #include <QFrame>
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 #include <QHBoxLayout>
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
12 #include <QLabel>
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
13 #include <QMessageBox>
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
14 #include <QPixmap>
67
442065432549 poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents: 66
diff changeset
15 #include <QUrl>
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 #include <curl/curl.h>
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 Poster::Poster(int id, QWidget* parent) : QFrame(parent) {
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 QHBoxLayout* layout = new QHBoxLayout(this);
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 layout->setContentsMargins(1, 1, 1, 1);
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21
67
442065432549 poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents: 66
diff changeset
22 setCursor(Qt::PointingHandCursor);
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 setFixedSize(150, 225);
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 setFrameShape(QFrame::Box);
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 setFrameShadow(QFrame::Plain);
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
26
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27 const Anime::Anime& anime = Anime::db.items[id];
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
29 HTTP::HttpGetThread* image_thread = new HTTP::HttpGetThread(anime.GetPosterUrl(), {}, this);
75
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
30 connect(image_thread, &HTTP::HttpGetThread::resultReady, this, &Poster::ImageDownloadFinished);
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
31 connect(image_thread, &HTTP::HttpGetThread::finished, image_thread, &QObject::deleteLater);
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
32 image_thread->start();
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
33
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
34 QPixmap pixmap = QPixmap::fromImage(img);
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
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
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
38 connect(label, &ClickableLabel::clicked, this,
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
39 [anime] { QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); });
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
40 layout->addWidget(label);
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
41 }
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
42
75
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
43 void Poster::ImageDownloadFinished(QByteArray arr) {
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
44 img.loadFromData(arr);
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
45 RenderToLabel();
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
46 }
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
47
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
48 void Poster::RenderToLabel() {
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
49 QPixmap pixmap = QPixmap::fromImage(img);
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
50 if (pixmap.isNull())
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
51 return;
75
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
52 label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
53 }
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
54
67
442065432549 poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents: 66
diff changeset
55 void Poster::resizeEvent(QResizeEvent*) {
75
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
56 RenderToLabel();
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
57 }
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
58
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
59 #include "gui/widgets/moc_poster.cpp"