Mercurial > minori
annotate src/gui/widgets/poster.cc @ 255:fe702c8f161f
*: whatever
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 07 Feb 2024 17:04:06 -0500 |
parents | d14f8e0e40c3 |
children | 862d0d8619f6 |
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(); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
52 connect(label, &ClickableLabel::clicked, this, |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
53 [this] { QDesktopServices::openUrl(service_url); }); |
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 |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
57 void Poster::SetClickable(bool enabled) { |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
58 clickable = enabled; |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
59 |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
60 if (clickable && !service_url.isEmpty()) { |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
61 setCursor(Qt::PointingHandCursor); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
62 label->disconnect(); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
63 connect(label, &ClickableLabel::clicked, this, |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
64 [this] { QDesktopServices::openUrl(service_url); }); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
65 } else { |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
66 setCursor(Qt::ArrowCursor); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
67 label->disconnect(); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
68 } |
66 | 69 } |
70 | |
83 | 71 void Poster::ImageDownloadFinished(const QByteArray& arr) { |
75 | 72 img.loadFromData(arr); |
73 RenderToLabel(); | |
74 } | |
75 | |
76 void Poster::RenderToLabel() { | |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
77 const QPixmap pixmap = QPixmap::fromImage(img); |
76 | 78 if (pixmap.isNull()) |
79 return; | |
75 | 80 label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); |
81 } | |
82 | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
83 void Poster::resizeEvent(QResizeEvent*) { |
75 | 84 RenderToLabel(); |
66 | 85 } |