Mercurial > minori
diff src/gui/widgets/poster.cc @ 295:b82841e76e79
*: better support on Windows
things now look much better in dark mode
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sun, 12 May 2024 20:24:09 -0400 |
parents | 9a88e1725fd2 |
children | b1f625b0227c |
line wrap: on
line diff
--- a/src/gui/widgets/poster.cc Sun May 12 18:16:08 2024 -0400 +++ b/src/gui/widgets/poster.cc Sun May 12 20:24:09 2024 -0400 @@ -28,21 +28,36 @@ label_.setAlignment(Qt::AlignCenter); layout->addWidget(&label_); - connect(&get_thread_, &HTTP::RequestThread::ReceivedData, this, &Poster::ImageDownloadFinished); + get_thread_ = new HTTP::RequestThread(HTTP::Type::Get); + connect(get_thread_, &HTTP::RequestThread::ReceivedData, this, &Poster::ImageDownloadFinished); } Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) { SetAnime(anime); } +Poster::~Poster() { + /* schedule deletion of the thread */ + get_thread_->deleteLater(); +} + +void Poster::DownloadPoster() { + if (get_thread_->isRunning()) + get_thread_->Stop(); + get_thread_->wait(); + + get_thread_->SetUrl(poster_url_); + get_thread_->start(); +} + void Poster::SetAnime(const Anime::Anime& anime) { - /* todo: only download on showEvent() */ - if (get_thread_.isRunning()) - get_thread_.Stop(); - get_thread_.wait(); + label_.clear(); - get_thread_.SetUrl(anime.GetPosterUrl()); - get_thread_.start(); + poster_url_ = anime.GetPosterUrl(); + if (isVisible()) + DownloadPoster(); + else + need_refresh_ = true; std::optional<std::string> url = anime.GetServiceUrl(session.config.service); if (url) @@ -54,6 +69,13 @@ } } +void Poster::showEvent(QShowEvent* event) { + if (need_refresh_) { + DownloadPoster(); + need_refresh_ = false; + } +} + void Poster::SetClickable(bool enabled) { clickable_ = enabled;