Mercurial > minori
annotate src/gui/widgets/poster.cpp @ 75:d3e9310598b1
*: refactor some stuff
text: "TextParagraph"s are now called sections, because that's the
actual word for it :P
text: new classes: Line and OneLineSection, solves many problems with
paragraphs that are only one line long (ex. going out of bounds)
http: reworked http stuff to allow threaded get requests, also moved it
to its own file to (hopefully) remove clutter
eventually I'll make a threaded post request method and use that in
the "basic" function
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 04 Oct 2023 01:42:30 -0400 |
parents | 2417121d894e |
children | 3364fadc8a36 |
rev | line source |
---|---|
66 | 1 #include "gui/widgets/poster.h" |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
2 #include "gui/widgets/clickable_label.h" |
66 | 3 #include "core/anime_db.h" |
75 | 4 #include "core/http.h" |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
5 #include "core/strings.h" |
66 | 6 #include "core/session.h" |
7 #include <QFrame> | |
8 #include <QMessageBox> | |
9 #include <QLabel> | |
10 #include <QHBoxLayout> | |
11 #include <QByteArray> | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
12 #include <QDesktopServices> |
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
13 #include <QUrl> |
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
14 #include <QDebug> |
66 | 15 #include <QPixmap> |
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); | |
26 | |
27 const Anime::Anime& anime = Anime::db.items[id]; | |
28 | |
75 | 29 HTTP::HttpGetThread *image_thread = new HTTP::HttpGetThread(anime.GetPosterUrl(), {}, this); |
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); |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
38 connect(label, &ClickableLabel::clicked, this, [anime]{ |
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
39 QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); |
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
40 }); |
66 | 41 layout->addWidget(label); |
42 } | |
43 | |
75 | 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()) return; | |
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" |