Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
369:47c9f8502269 | 370:ea3a74ed2ef9 |
---|---|
16 #include <QThread> | 16 #include <QThread> |
17 #include <QUrl> | 17 #include <QUrl> |
18 | 18 |
19 #include <iostream> | 19 #include <iostream> |
20 | 20 |
21 Poster::Poster(QWidget* parent) : QFrame(parent) { | 21 Poster::Poster(QWidget *parent) : QFrame(parent) |
22 QHBoxLayout* layout = new QHBoxLayout(this); | 22 { |
23 QHBoxLayout *layout = new QHBoxLayout(this); | |
23 layout->setContentsMargins(1, 1, 1, 1); | 24 layout->setContentsMargins(1, 1, 1, 1); |
24 | 25 |
25 setCursor(Qt::PointingHandCursor); | 26 setCursor(Qt::PointingHandCursor); |
26 setFixedSize(150, 225); // FIXME need to kill this | 27 setFixedSize(150, 225); // FIXME need to kill this |
27 setFrameShape(QFrame::Box); | 28 setFrameShape(QFrame::Box); |
32 | 33 |
33 get_thread_ = new HTTP::RequestThread(HTTP::Type::Get); | 34 get_thread_ = new HTTP::RequestThread(HTTP::Type::Get); |
34 connect(get_thread_, &HTTP::RequestThread::ReceivedData, this, &Poster::ImageDownloadFinished); | 35 connect(get_thread_, &HTTP::RequestThread::ReceivedData, this, &Poster::ImageDownloadFinished); |
35 } | 36 } |
36 | 37 |
37 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) { | 38 Poster::Poster(const Anime::Anime &anime, QWidget *parent) : Poster(parent) |
39 { | |
38 SetAnime(anime); | 40 SetAnime(anime); |
39 } | 41 } |
40 | 42 |
41 Poster::~Poster() { | 43 Poster::~Poster() |
44 { | |
42 /* schedule deletion of the thread */ | 45 /* schedule deletion of the thread */ |
43 get_thread_->deleteLater(); | 46 get_thread_->deleteLater(); |
44 } | 47 } |
45 | 48 |
46 void Poster::DownloadPoster() { | 49 void Poster::DownloadPoster() |
50 { | |
47 if (get_thread_->isRunning()) | 51 if (get_thread_->isRunning()) |
48 get_thread_->Stop(); | 52 get_thread_->Stop(); |
49 get_thread_->wait(); | 53 get_thread_->wait(); |
50 | 54 |
51 get_thread_->SetUrl(poster_url_); | 55 get_thread_->SetUrl(poster_url_); |
52 get_thread_->start(); | 56 get_thread_->start(); |
53 } | 57 } |
54 | 58 |
55 void Poster::SetAnime(const Anime::Anime& anime) { | 59 void Poster::SetAnime(const Anime::Anime &anime) |
60 { | |
56 label_.clear(); | 61 label_.clear(); |
57 | 62 |
58 poster_url_ = anime.GetPosterUrl(); | 63 poster_url_ = anime.GetPosterUrl(); |
59 if (isVisible()) | 64 if (isVisible()) |
60 DownloadPoster(); | 65 DownloadPoster(); |
69 label_.disconnect(); | 74 label_.disconnect(); |
70 connect(&label_, &ClickableLabel::clicked, this, [this] { QDesktopServices::openUrl(service_url_); }); | 75 connect(&label_, &ClickableLabel::clicked, this, [this] { QDesktopServices::openUrl(service_url_); }); |
71 } | 76 } |
72 } | 77 } |
73 | 78 |
74 void Poster::showEvent(QShowEvent* event) { | 79 void Poster::showEvent(QShowEvent *event) |
80 { | |
75 if (need_refresh_) { | 81 if (need_refresh_) { |
76 DownloadPoster(); | 82 DownloadPoster(); |
77 need_refresh_ = false; | 83 need_refresh_ = false; |
78 } | 84 } |
79 } | 85 } |
80 | 86 |
81 void Poster::SetClickable(bool enabled) { | 87 void Poster::SetClickable(bool enabled) |
88 { | |
82 clickable_ = enabled; | 89 clickable_ = enabled; |
83 | 90 |
84 if (clickable_ && !service_url_.isEmpty()) { | 91 if (clickable_ && !service_url_.isEmpty()) { |
85 setCursor(Qt::PointingHandCursor); | 92 setCursor(Qt::PointingHandCursor); |
86 label_.disconnect(); | 93 label_.disconnect(); |
89 setCursor(Qt::ArrowCursor); | 96 setCursor(Qt::ArrowCursor); |
90 label_.disconnect(); | 97 label_.disconnect(); |
91 } | 98 } |
92 } | 99 } |
93 | 100 |
94 void Poster::ImageDownloadFinished(const QByteArray& arr) { | 101 void Poster::ImageDownloadFinished(const QByteArray &arr) |
102 { | |
95 img_.loadFromData(arr); | 103 img_.loadFromData(arr); |
96 RenderToLabel(); | 104 RenderToLabel(); |
97 } | 105 } |
98 | 106 |
99 void Poster::RenderToLabel() { | 107 void Poster::RenderToLabel() |
108 { | |
100 const QPixmap pixmap = QPixmap::fromImage(img_); | 109 const QPixmap pixmap = QPixmap::fromImage(img_); |
101 if (pixmap.isNull()) | 110 if (pixmap.isNull()) |
102 return; | 111 return; |
103 label_.setPixmap(pixmap.scaled(label_.size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); | 112 label_.setPixmap(pixmap.scaled(label_.size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); |
104 } | 113 } |
105 | 114 |
106 bool Poster::hasHeightForWidth(void) const { | 115 bool Poster::hasHeightForWidth(void) const |
116 { | |
107 return true; | 117 return true; |
108 } | 118 } |
109 | 119 |
110 int Poster::heightForWidth(int w) const { | 120 int Poster::heightForWidth(int w) const |
121 { | |
111 return static_cast<int>(static_cast<double>(w) * 225 / 150); | 122 return static_cast<int>(static_cast<double>(w) * 225 / 150); |
112 } | 123 } |
113 | 124 |
114 void Poster::resizeEvent(QResizeEvent*) { | 125 void Poster::resizeEvent(QResizeEvent *) |
126 { | |
115 RenderToLabel(); | 127 RenderToLabel(); |
116 } | 128 } |
117 | 129 |
118 QSize Poster::minimumSizeHint() const { | 130 QSize Poster::minimumSizeHint() const |
131 { | |
119 return QSize(120, heightForWidth(120)); | 132 return QSize(120, heightForWidth(120)); |
120 } | 133 } |
121 | 134 |
122 QSize Poster::sizeHint() const { | 135 QSize Poster::sizeHint() const |
136 { | |
123 return QSize(150, heightForWidth(150)); | 137 return QSize(150, heightForWidth(150)); |
124 } | 138 } |