comparison 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
comparison
equal deleted inserted replaced
294:99cbc51433e4 295:b82841e76e79
26 setFrameShadow(QFrame::Plain); 26 setFrameShadow(QFrame::Plain);
27 27
28 label_.setAlignment(Qt::AlignCenter); 28 label_.setAlignment(Qt::AlignCenter);
29 layout->addWidget(&label_); 29 layout->addWidget(&label_);
30 30
31 connect(&get_thread_, &HTTP::RequestThread::ReceivedData, this, &Poster::ImageDownloadFinished); 31 get_thread_ = new HTTP::RequestThread(HTTP::Type::Get);
32 connect(get_thread_, &HTTP::RequestThread::ReceivedData, this, &Poster::ImageDownloadFinished);
32 } 33 }
33 34
34 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) { 35 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) {
35 SetAnime(anime); 36 SetAnime(anime);
36 } 37 }
37 38
39 Poster::~Poster() {
40 /* schedule deletion of the thread */
41 get_thread_->deleteLater();
42 }
43
44 void Poster::DownloadPoster() {
45 if (get_thread_->isRunning())
46 get_thread_->Stop();
47 get_thread_->wait();
48
49 get_thread_->SetUrl(poster_url_);
50 get_thread_->start();
51 }
52
38 void Poster::SetAnime(const Anime::Anime& anime) { 53 void Poster::SetAnime(const Anime::Anime& anime) {
39 /* todo: only download on showEvent() */ 54 label_.clear();
40 if (get_thread_.isRunning())
41 get_thread_.Stop();
42 get_thread_.wait();
43 55
44 get_thread_.SetUrl(anime.GetPosterUrl()); 56 poster_url_ = anime.GetPosterUrl();
45 get_thread_.start(); 57 if (isVisible())
58 DownloadPoster();
59 else
60 need_refresh_ = true;
46 61
47 std::optional<std::string> url = anime.GetServiceUrl(session.config.service); 62 std::optional<std::string> url = anime.GetServiceUrl(session.config.service);
48 if (url) 63 if (url)
49 service_url_ = Strings::ToQString(url.value()); 64 service_url_ = Strings::ToQString(url.value());
50 65
51 if (clickable_) { 66 if (clickable_) {
52 label_.disconnect(); 67 label_.disconnect();
53 connect(&label_, &ClickableLabel::clicked, this, [this] { QDesktopServices::openUrl(service_url_); }); 68 connect(&label_, &ClickableLabel::clicked, this, [this] { QDesktopServices::openUrl(service_url_); });
69 }
70 }
71
72 void Poster::showEvent(QShowEvent* event) {
73 if (need_refresh_) {
74 DownloadPoster();
75 need_refresh_ = false;
54 } 76 }
55 } 77 }
56 78
57 void Poster::SetClickable(bool enabled) { 79 void Poster::SetClickable(bool enabled) {
58 clickable_ = enabled; 80 clickable_ = enabled;