Mercurial > minori
annotate src/gui/widgets/poster.cc @ 232:ff0061e75f0f
theme: add OS detection with glib
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sat, 13 Jan 2024 11:06:16 -0500 |
parents | 2f5a9247e501 |
children | 4d461ef7d424 |
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" |
7 #include <QByteArray> | |
8 #include <QDebug> | |
9 #include <QDesktopServices> | |
66 | 10 #include <QFrame> |
11 #include <QHBoxLayout> | |
76 | 12 #include <QLabel> |
13 #include <QMessageBox> | |
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 | 17 #include <curl/curl.h> |
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) { | |
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
187
diff
changeset
|
38 { |
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
39 QByteArray* ba = new QByteArray; |
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
187
diff
changeset
|
40 |
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
41 QThread* thread = QThread::create([ba, anime] { |
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
42 *ba = HTTP::Get(anime.GetPosterUrl(), {}); |
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 |
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
45 connect(thread, &QThread::finished, this, [this, ba] { |
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
46 ImageDownloadFinished(*ba); |
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
47 delete ba; |
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
187
diff
changeset
|
48 }); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
187
diff
changeset
|
49 |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
187
diff
changeset
|
50 thread->start(); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
187
diff
changeset
|
51 } |
75 | 52 |
83 | 53 label->disconnect(); |
76 | 54 connect(label, &ClickableLabel::clicked, this, |
55 [anime] { QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); }); | |
66 | 56 } |
57 | |
83 | 58 void Poster::ImageDownloadFinished(const QByteArray& arr) { |
75 | 59 img.loadFromData(arr); |
60 RenderToLabel(); | |
61 } | |
62 | |
63 void Poster::RenderToLabel() { | |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
64 const QPixmap pixmap = QPixmap::fromImage(img); |
76 | 65 if (pixmap.isNull()) |
66 return; | |
75 | 67 label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); |
68 } | |
69 | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
70 void Poster::resizeEvent(QResizeEvent*) { |
75 | 71 RenderToLabel(); |
66 | 72 } |
73 | |
74 #include "gui/widgets/moc_poster.cpp" |