Mercurial > minori
annotate src/gui/widgets/poster.cc @ 284:e66ffc338d82
anime: refactor title structure to a map
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 08 May 2024 16:21:05 -0400 |
parents | f31305b9f60a |
children | 53e3c015a973 |
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 |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
28 label_.setAlignment(Qt::AlignCenter); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
29 layout->addWidget(&label_); |
83 | 30 } |
66 | 31 |
83 | 32 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) { |
33 SetAnime(anime); | |
34 } | |
35 | |
36 void Poster::SetAnime(const Anime::Anime& anime) { | |
255 | 37 /* todo: only download on showEvent() */ |
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 | 46 |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
47 service_url_ = Strings::ToQString(anime.GetServiceUrl()); |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
48 |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
49 if (clickable_) { |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
50 label_.disconnect(); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
51 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
|
52 } |
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 void Poster::SetClickable(bool enabled) { |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
56 clickable_ = enabled; |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
57 |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
58 if (clickable_ && !service_url_.isEmpty()) { |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
59 setCursor(Qt::PointingHandCursor); |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
60 label_.disconnect(); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
61 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
|
62 } else { |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
63 setCursor(Qt::ArrowCursor); |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
64 label_.disconnect(); |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
236
diff
changeset
|
65 } |
66 | 66 } |
67 | |
83 | 68 void Poster::ImageDownloadFinished(const QByteArray& arr) { |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
69 img_.loadFromData(arr); |
75 | 70 RenderToLabel(); |
71 } | |
72 | |
73 void Poster::RenderToLabel() { | |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
74 const QPixmap pixmap = QPixmap::fromImage(img_); |
76 | 75 if (pixmap.isNull()) |
76 return; | |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
77 label_.setPixmap(pixmap.scaled(label_.size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); |
75 | 78 } |
79 | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
80 void Poster::resizeEvent(QResizeEvent*) { |
75 | 81 RenderToLabel(); |
66 | 82 } |