Mercurial > minori
diff src/gui/widgets/poster.cc @ 370:ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
author | Paper <paper@tflc.us> |
---|---|
date | Fri, 25 Jul 2025 10:22:04 -0400 |
parents | 6b0768158dcd |
children |
line wrap: on
line diff
--- a/src/gui/widgets/poster.cc Fri Jul 25 10:16:02 2025 -0400 +++ b/src/gui/widgets/poster.cc Fri Jul 25 10:22:04 2025 -0400 @@ -18,8 +18,9 @@ #include <iostream> -Poster::Poster(QWidget* parent) : QFrame(parent) { - QHBoxLayout* layout = new QHBoxLayout(this); +Poster::Poster(QWidget *parent) : QFrame(parent) +{ + QHBoxLayout *layout = new QHBoxLayout(this); layout->setContentsMargins(1, 1, 1, 1); setCursor(Qt::PointingHandCursor); @@ -34,16 +35,19 @@ connect(get_thread_, &HTTP::RequestThread::ReceivedData, this, &Poster::ImageDownloadFinished); } -Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) { +Poster::Poster(const Anime::Anime &anime, QWidget *parent) : Poster(parent) +{ SetAnime(anime); } -Poster::~Poster() { +Poster::~Poster() +{ /* schedule deletion of the thread */ get_thread_->deleteLater(); } -void Poster::DownloadPoster() { +void Poster::DownloadPoster() +{ if (get_thread_->isRunning()) get_thread_->Stop(); get_thread_->wait(); @@ -52,7 +56,8 @@ get_thread_->start(); } -void Poster::SetAnime(const Anime::Anime& anime) { +void Poster::SetAnime(const Anime::Anime &anime) +{ label_.clear(); poster_url_ = anime.GetPosterUrl(); @@ -71,14 +76,16 @@ } } -void Poster::showEvent(QShowEvent* event) { +void Poster::showEvent(QShowEvent *event) +{ if (need_refresh_) { DownloadPoster(); need_refresh_ = false; } } -void Poster::SetClickable(bool enabled) { +void Poster::SetClickable(bool enabled) +{ clickable_ = enabled; if (clickable_ && !service_url_.isEmpty()) { @@ -91,34 +98,41 @@ } } -void Poster::ImageDownloadFinished(const QByteArray& arr) { +void Poster::ImageDownloadFinished(const QByteArray &arr) +{ img_.loadFromData(arr); RenderToLabel(); } -void Poster::RenderToLabel() { +void Poster::RenderToLabel() +{ const QPixmap pixmap = QPixmap::fromImage(img_); if (pixmap.isNull()) return; label_.setPixmap(pixmap.scaled(label_.size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); } -bool Poster::hasHeightForWidth(void) const { +bool Poster::hasHeightForWidth(void) const +{ return true; } -int Poster::heightForWidth(int w) const { +int Poster::heightForWidth(int w) const +{ return static_cast<int>(static_cast<double>(w) * 225 / 150); } -void Poster::resizeEvent(QResizeEvent*) { +void Poster::resizeEvent(QResizeEvent *) +{ RenderToLabel(); } -QSize Poster::minimumSizeHint() const { +QSize Poster::minimumSizeHint() const +{ return QSize(120, heightForWidth(120)); } -QSize Poster::sizeHint() const { +QSize Poster::sizeHint() const +{ return QSize(150, heightForWidth(150)); }