annotate src/gui/widgets/poster.cc @ 236:4d461ef7d424

HUGE UPDATE: convert build system to autotools why? because cmake sucks :)
author Paper <mrpapersonic@gmail.com>
date Fri, 19 Jan 2024 00:24:02 -0500
parents ff0061e75f0f
children d14f8e0e40c3
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>
230
2f5a9247e501 torrents: implement download button
Paper <paper@paper.us.eu.org>
parents: 187
diff changeset
15 #include <QThread>
67
442065432549 poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents: 66
diff changeset
16 #include <QUrl>
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 #include <curl/curl.h>
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
19 Poster::Poster(QWidget* parent) : QFrame(parent) {
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 QHBoxLayout* layout = new QHBoxLayout(this);
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 layout->setContentsMargins(1, 1, 1, 1);
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22
67
442065432549 poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents: 66
diff changeset
23 setCursor(Qt::PointingHandCursor);
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 setFixedSize(150, 225);
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 setFrameShape(QFrame::Box);
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 setFrameShadow(QFrame::Plain);
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
27
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
28 label = new ClickableLabel(this);
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
29 label->setAlignment(Qt::AlignCenter);
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
30 layout->addWidget(label);
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
31 }
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
33 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) {
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
34 SetAnime(anime);
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
35 }
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
36
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
37 void Poster::SetAnime(const Anime::Anime& anime) {
230
2f5a9247e501 torrents: implement download button
Paper <paper@paper.us.eu.org>
parents: 187
diff changeset
38 {
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 232
diff changeset
39 HTTP::GetThread* thread = new HTTP::GetThread(anime.GetPosterUrl(), {}, this);
230
2f5a9247e501 torrents: implement download button
Paper <paper@paper.us.eu.org>
parents: 187
diff changeset
40
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 232
diff changeset
41 connect(thread, &HTTP::GetThread::ReceivedData, this, &Poster::ImageDownloadFinished);
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 232
diff changeset
42 connect(thread, &HTTP::GetThread::finished, thread, &HTTP::GetThread::deleteLater);
230
2f5a9247e501 torrents: implement download button
Paper <paper@paper.us.eu.org>
parents: 187
diff changeset
43
2f5a9247e501 torrents: implement download button
Paper <paper@paper.us.eu.org>
parents: 187
diff changeset
44 thread->start();
2f5a9247e501 torrents: implement download button
Paper <paper@paper.us.eu.org>
parents: 187
diff changeset
45 }
75
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
46
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
47 label->disconnect();
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
48 connect(label, &ClickableLabel::clicked, this,
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
49 [anime] { QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); });
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50 }
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
51
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
52 void Poster::ImageDownloadFinished(const QByteArray& arr) {
75
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
53 img.loadFromData(arr);
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
54 RenderToLabel();
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
55 }
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
56
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
57 void Poster::RenderToLabel() {
187
9613d72b097e *: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
58 const QPixmap pixmap = QPixmap::fromImage(img);
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
59 if (pixmap.isNull())
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
60 return;
75
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
61 label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
62 }
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
63
67
442065432549 poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents: 66
diff changeset
64 void Poster::resizeEvent(QResizeEvent*) {
75
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
65 RenderToLabel();
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
66 }