Mercurial > minori
comparison src/gui/widgets/poster.cc @ 273:f31305b9f60a
*: various code safety changes
this also makes the code build on Qt 5.7. I can't test it though
because I don't have it working... FAIL!
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 18 Apr 2024 16:53:17 -0400 |
parents | 862d0d8619f6 |
children | 53e3c015a973 |
comparison
equal
deleted
inserted
replaced
272:5437009cb10e | 273:f31305b9f60a |
---|---|
23 setCursor(Qt::PointingHandCursor); | 23 setCursor(Qt::PointingHandCursor); |
24 setFixedSize(150, 225); | 24 setFixedSize(150, 225); |
25 setFrameShape(QFrame::Box); | 25 setFrameShape(QFrame::Box); |
26 setFrameShadow(QFrame::Plain); | 26 setFrameShadow(QFrame::Plain); |
27 | 27 |
28 label = new ClickableLabel(this); | 28 label_.setAlignment(Qt::AlignCenter); |
29 label->setAlignment(Qt::AlignCenter); | 29 layout->addWidget(&label_); |
30 layout->addWidget(label); | |
31 } | 30 } |
32 | 31 |
33 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) { | 32 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) { |
34 SetAnime(anime); | 33 SetAnime(anime); |
35 } | 34 } |
43 connect(thread, &HTTP::GetThread::finished, thread, &HTTP::GetThread::deleteLater); | 42 connect(thread, &HTTP::GetThread::finished, thread, &HTTP::GetThread::deleteLater); |
44 | 43 |
45 thread->start(); | 44 thread->start(); |
46 } | 45 } |
47 | 46 |
48 service_url = Strings::ToQString(anime.GetServiceUrl()); | 47 service_url_ = Strings::ToQString(anime.GetServiceUrl()); |
49 | 48 |
50 if (clickable) { | 49 if (clickable_) { |
51 label->disconnect(); | 50 label_.disconnect(); |
52 connect(label, &ClickableLabel::clicked, this, [this] { QDesktopServices::openUrl(service_url); }); | 51 connect(&label_, &ClickableLabel::clicked, this, [this] { QDesktopServices::openUrl(service_url_); }); |
53 } | 52 } |
54 } | 53 } |
55 | 54 |
56 void Poster::SetClickable(bool enabled) { | 55 void Poster::SetClickable(bool enabled) { |
57 clickable = enabled; | 56 clickable_ = enabled; |
58 | 57 |
59 if (clickable && !service_url.isEmpty()) { | 58 if (clickable_ && !service_url_.isEmpty()) { |
60 setCursor(Qt::PointingHandCursor); | 59 setCursor(Qt::PointingHandCursor); |
61 label->disconnect(); | 60 label_.disconnect(); |
62 connect(label, &ClickableLabel::clicked, this, [this] { QDesktopServices::openUrl(service_url); }); | 61 connect(&label_, &ClickableLabel::clicked, this, [this] { QDesktopServices::openUrl(service_url_); }); |
63 } else { | 62 } else { |
64 setCursor(Qt::ArrowCursor); | 63 setCursor(Qt::ArrowCursor); |
65 label->disconnect(); | 64 label_.disconnect(); |
66 } | 65 } |
67 } | 66 } |
68 | 67 |
69 void Poster::ImageDownloadFinished(const QByteArray& arr) { | 68 void Poster::ImageDownloadFinished(const QByteArray& arr) { |
70 img.loadFromData(arr); | 69 img_.loadFromData(arr); |
71 RenderToLabel(); | 70 RenderToLabel(); |
72 } | 71 } |
73 | 72 |
74 void Poster::RenderToLabel() { | 73 void Poster::RenderToLabel() { |
75 const QPixmap pixmap = QPixmap::fromImage(img); | 74 const QPixmap pixmap = QPixmap::fromImage(img_); |
76 if (pixmap.isNull()) | 75 if (pixmap.isNull()) |
77 return; | 76 return; |
78 label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); | 77 label_.setPixmap(pixmap.scaled(label_.size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); |
79 } | 78 } |
80 | 79 |
81 void Poster::resizeEvent(QResizeEvent*) { | 80 void Poster::resizeEvent(QResizeEvent*) { |
82 RenderToLabel(); | 81 RenderToLabel(); |
83 } | 82 } |