Mercurial > minori
annotate src/gui/widgets/poster.cc @ 258:862d0d8619f6
*: HUUUGE changes
animia has been renamed to animone, so instead of thinking of a
health condition, you think of a beautiful flower :)
I've also edited some of the code for animone, but I have no idea
if it even works or not because I don't have a mac or windows
machine lying around. whoops!
... anyway, all of the changes divergent from Anisthesia are now
licensed under BSD. it's possible that I could even rewrite most
of the code to where I don't even have to keep the MIT license,
but that's thinking too far into the future
I've been slacking off on implementing the anime seasons page,
mostly out of laziness. I think I'd have to create another db file
specifically for the seasons
anyway, this code is being pushed *primarily* because the hard drive
it's on is failing! yay :)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Mon, 01 Apr 2024 02:43:44 -0400 |
parents | fe702c8f161f |
children | f31305b9f60a |
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" |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
7 |
76 | 8 #include <QByteArray> |
9 #include <QDebug> | |
10 #include <QDesktopServices> | |
66 | 11 #include <QFrame> |
12 #include <QHBoxLayout> | |
76 | 13 #include <QLabel> |
14 #include <QMessageBox> | |
15 #include <QPixmap> | |
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
187
diff
changeset
|
16 #include <QThread> |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
17 #include <QUrl> |
66 | 18 |
83 | 19 Poster::Poster(QWidget* parent) : QFrame(parent) { |
66 | 20 QHBoxLayout* layout = new QHBoxLayout(this); |
21 layout->setContentsMargins(1, 1, 1, 1); | |
22 | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
23 setCursor(Qt::PointingHandCursor); |
66 | 24 setFixedSize(150, 225); |
25 setFrameShape(QFrame::Box); | |
26 setFrameShadow(QFrame::Plain); | |
76 | 27 |
83 | 28 label = new ClickableLabel(this); |
29 label->setAlignment(Qt::AlignCenter); | |
30 layout->addWidget(label); | |
31 } | |
66 | 32 |
83 | 33 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) { |
34 SetAnime(anime); | |
35 } | |
36 | |
37 void Poster::SetAnime(const Anime::Anime& anime) { | |
255 | 38 /* todo: only download on showEvent() */ |
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
187
diff
changeset
|
39 { |
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
40 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
|
41 |
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
42 connect(thread, &HTTP::GetThread::ReceivedData, this, &Poster::ImageDownloadFinished); |
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
43 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
|
44 |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
187
diff
changeset
|
45 thread->start(); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
187
diff
changeset
|
46 } |
75 | 47 |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
48 service_url = Strings::ToQString(anime.GetServiceUrl()); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
49 |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
50 if (clickable) { |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
51 label->disconnect(); |
258 | 52 connect(label, &ClickableLabel::clicked, this, [this] { QDesktopServices::openUrl(service_url); }); |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
53 } |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
54 } |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
55 |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
56 void Poster::SetClickable(bool enabled) { |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
57 clickable = enabled; |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
58 |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
59 if (clickable && !service_url.isEmpty()) { |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
60 setCursor(Qt::PointingHandCursor); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
61 label->disconnect(); |
258 | 62 connect(label, &ClickableLabel::clicked, this, [this] { QDesktopServices::openUrl(service_url); }); |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
63 } else { |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
64 setCursor(Qt::ArrowCursor); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
65 label->disconnect(); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
66 } |
66 | 67 } |
68 | |
83 | 69 void Poster::ImageDownloadFinished(const QByteArray& arr) { |
75 | 70 img.loadFromData(arr); |
71 RenderToLabel(); | |
72 } | |
73 | |
74 void Poster::RenderToLabel() { | |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
75 const QPixmap pixmap = QPixmap::fromImage(img); |
76 | 76 if (pixmap.isNull()) |
77 return; | |
75 | 78 label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); |
79 } | |
80 | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
81 void Poster::resizeEvent(QResizeEvent*) { |
75 | 82 RenderToLabel(); |
66 | 83 } |