Mercurial > minori
comparison src/gui/widgets/poster.cpp @ 76:3364fadc8a36
*: format source code
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Wed, 04 Oct 2023 01:46:33 -0400 |
| parents | d3e9310598b1 |
| children | 6f7385bd334c |
comparison
equal
deleted
inserted
replaced
| 75:d3e9310598b1 | 76:3364fadc8a36 |
|---|---|
| 1 #include "gui/widgets/poster.h" | 1 #include "gui/widgets/poster.h" |
| 2 #include "gui/widgets/clickable_label.h" | |
| 3 #include "core/anime_db.h" | 2 #include "core/anime_db.h" |
| 4 #include "core/http.h" | 3 #include "core/http.h" |
| 4 #include "core/session.h" | |
| 5 #include "core/strings.h" | 5 #include "core/strings.h" |
| 6 #include "core/session.h" | 6 #include "gui/widgets/clickable_label.h" |
| 7 #include <QByteArray> | |
| 8 #include <QDebug> | |
| 9 #include <QDesktopServices> | |
| 7 #include <QFrame> | 10 #include <QFrame> |
| 11 #include <QHBoxLayout> | |
| 12 #include <QLabel> | |
| 8 #include <QMessageBox> | 13 #include <QMessageBox> |
| 9 #include <QLabel> | 14 #include <QPixmap> |
| 10 #include <QHBoxLayout> | |
| 11 #include <QByteArray> | |
| 12 #include <QDesktopServices> | |
| 13 #include <QUrl> | 15 #include <QUrl> |
| 14 #include <QDebug> | |
| 15 #include <QPixmap> | |
| 16 #include <curl/curl.h> | 16 #include <curl/curl.h> |
| 17 | 17 |
| 18 Poster::Poster(int id, QWidget* parent) : QFrame(parent) { | 18 Poster::Poster(int id, QWidget* parent) : QFrame(parent) { |
| 19 QHBoxLayout* layout = new QHBoxLayout(this); | 19 QHBoxLayout* layout = new QHBoxLayout(this); |
| 20 layout->setContentsMargins(1, 1, 1, 1); | 20 layout->setContentsMargins(1, 1, 1, 1); |
| 21 | 21 |
| 22 setCursor(Qt::PointingHandCursor); | 22 setCursor(Qt::PointingHandCursor); |
| 23 setFixedSize(150, 225); | 23 setFixedSize(150, 225); |
| 24 setFrameShape(QFrame::Box); | 24 setFrameShape(QFrame::Box); |
| 25 setFrameShadow(QFrame::Plain); | 25 setFrameShadow(QFrame::Plain); |
| 26 | 26 |
| 27 const Anime::Anime& anime = Anime::db.items[id]; | 27 const Anime::Anime& anime = Anime::db.items[id]; |
| 28 | 28 |
| 29 HTTP::HttpGetThread *image_thread = new HTTP::HttpGetThread(anime.GetPosterUrl(), {}, this); | 29 HTTP::HttpGetThread* image_thread = new HTTP::HttpGetThread(anime.GetPosterUrl(), {}, this); |
| 30 connect(image_thread, &HTTP::HttpGetThread::resultReady, this, &Poster::ImageDownloadFinished); | 30 connect(image_thread, &HTTP::HttpGetThread::resultReady, this, &Poster::ImageDownloadFinished); |
| 31 connect(image_thread, &HTTP::HttpGetThread::finished, image_thread, &QObject::deleteLater); | 31 connect(image_thread, &HTTP::HttpGetThread::finished, image_thread, &QObject::deleteLater); |
| 32 image_thread->start(); | 32 image_thread->start(); |
| 33 | 33 |
| 34 QPixmap pixmap = QPixmap::fromImage(img); | 34 QPixmap pixmap = QPixmap::fromImage(img); |
| 35 | 35 |
| 36 label = new ClickableLabel(this); | 36 label = new ClickableLabel(this); |
| 37 label->setAlignment(Qt::AlignCenter); | 37 label->setAlignment(Qt::AlignCenter); |
| 38 connect(label, &ClickableLabel::clicked, this, [anime]{ | 38 connect(label, &ClickableLabel::clicked, this, |
| 39 QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); | 39 [anime] { QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); }); |
| 40 }); | |
| 41 layout->addWidget(label); | 40 layout->addWidget(label); |
| 42 } | 41 } |
| 43 | 42 |
| 44 void Poster::ImageDownloadFinished(QByteArray arr) { | 43 void Poster::ImageDownloadFinished(QByteArray arr) { |
| 45 img.loadFromData(arr); | 44 img.loadFromData(arr); |
| 46 RenderToLabel(); | 45 RenderToLabel(); |
| 47 } | 46 } |
| 48 | 47 |
| 49 void Poster::RenderToLabel() { | 48 void Poster::RenderToLabel() { |
| 50 QPixmap pixmap = QPixmap::fromImage(img); | 49 QPixmap pixmap = QPixmap::fromImage(img); |
| 51 if (pixmap.isNull()) return; | 50 if (pixmap.isNull()) |
| 51 return; | |
| 52 label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); | 52 label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void Poster::resizeEvent(QResizeEvent*) { | 55 void Poster::resizeEvent(QResizeEvent*) { |
| 56 RenderToLabel(); | 56 RenderToLabel(); |
