Mercurial > minori
comparison src/gui/widgets/poster.cpp @ 67:442065432549
poster: make posters link to AniList
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 02 Oct 2023 07:06:44 -0400 |
parents | 6481c5aed3e1 |
children | 2417121d894e |
comparison
equal
deleted
inserted
replaced
66:6481c5aed3e1 | 67:442065432549 |
---|---|
1 #include "gui/widgets/poster.h" | 1 #include "gui/widgets/poster.h" |
2 #include "gui/widgets/clickable_label.h" | |
2 #include "core/anime_db.h" | 3 #include "core/anime_db.h" |
4 #include "core/strings.h" | |
3 #include "core/session.h" | 5 #include "core/session.h" |
4 #include <QFrame> | 6 #include <QFrame> |
5 #include <QMessageBox> | 7 #include <QMessageBox> |
6 #include <QLabel> | 8 #include <QLabel> |
7 #include <QHBoxLayout> | 9 #include <QHBoxLayout> |
8 #include <QByteArray> | 10 #include <QByteArray> |
11 #include <QDesktopServices> | |
12 #include <QUrl> | |
13 #include <QDebug> | |
9 #include <QPixmap> | 14 #include <QPixmap> |
10 #include <curl/curl.h> | 15 #include <curl/curl.h> |
11 | 16 |
12 static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userdata) { | 17 static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userdata) { |
13 reinterpret_cast<QByteArray*>(userdata)->append(reinterpret_cast<char*>(contents), size * nmemb); | 18 reinterpret_cast<QByteArray*>(userdata)->append(reinterpret_cast<char*>(contents), size * nmemb); |
37 | 42 |
38 Poster::Poster(int id, QWidget* parent) : QFrame(parent) { | 43 Poster::Poster(int id, QWidget* parent) : QFrame(parent) { |
39 QHBoxLayout* layout = new QHBoxLayout(this); | 44 QHBoxLayout* layout = new QHBoxLayout(this); |
40 layout->setContentsMargins(1, 1, 1, 1); | 45 layout->setContentsMargins(1, 1, 1, 1); |
41 | 46 |
47 setCursor(Qt::PointingHandCursor); | |
42 setFixedSize(150, 225); | 48 setFixedSize(150, 225); |
43 setFrameShape(QFrame::Box); | 49 setFrameShape(QFrame::Box); |
44 setFrameShadow(QFrame::Plain); | 50 setFrameShadow(QFrame::Plain); |
45 | 51 |
46 const Anime::Anime& anime = Anime::db.items[id]; | 52 const Anime::Anime& anime = Anime::db.items[id]; |
47 QByteArray ret = SendRequest(anime.GetPosterUrl()); | 53 QByteArray ret = SendRequest(anime.GetPosterUrl()); |
48 | 54 |
49 img.loadFromData(ret); | 55 img.loadFromData(ret); |
50 QPixmap pixmap = QPixmap::fromImage(img); | 56 QPixmap pixmap = QPixmap::fromImage(img); |
51 | 57 |
52 label = new QLabel(this); | 58 label = new ClickableLabel(this); |
53 label->setAlignment(Qt::AlignCenter); | 59 connect(label, &ClickableLabel::clicked, this, [anime]{ |
60 QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); | |
61 }); | |
54 layout->addWidget(label); | 62 layout->addWidget(label); |
55 } | 63 } |
56 | 64 |
57 void Poster::resizeEvent(QResizeEvent* event) { | 65 void Poster::resizeEvent(QResizeEvent*) { |
58 QPixmap pixmap = QPixmap::fromImage(img); | 66 QPixmap pixmap = QPixmap::fromImage(img).scaled(size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); |
59 label->setPixmap(pixmap.scaled(label->width(), label->height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); | 67 label->setPixmap(pixmap); |
60 } | 68 } |
61 | 69 |
62 #include "gui/widgets/moc_poster.cpp" | 70 #include "gui/widgets/moc_poster.cpp" |