Mercurial > minori
annotate src/gui/widgets/poster.cc @ 187:9613d72b097e
*: multiple performance improvements
like marking `static const` when it makes sense...
date: change old stupid heap-based method to a structure which should
make copying the thing actually make a copy.
also many performance-based changes, like removing the std::tie
dependency and forward-declaring nlohmann json
*: replace every instance of QString::fromUtf8 to Strings::ToQString.
the main difference is that our function will always convert exactly
what is in the string, while some other times it would only convert
up to the nearest NUL byte
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 06 Dec 2023 13:43:54 -0500 |
parents | d02fdf1d6708 |
children | 2f5a9247e501 |
rev | line source |
---|---|
66 | 1 #include "gui/widgets/poster.h" |
2 #include "core/anime_db.h" | |
75 | 3 #include "core/http.h" |
76 | 4 #include "core/session.h" |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
5 #include "core/strings.h" |
76 | 6 #include "gui/widgets/clickable_label.h" |
7 #include <QByteArray> | |
8 #include <QDebug> | |
9 #include <QDesktopServices> | |
66 | 10 #include <QFrame> |
11 #include <QHBoxLayout> | |
76 | 12 #include <QLabel> |
13 #include <QMessageBox> | |
14 #include <QPixmap> | |
77 | 15 #include <QThreadPool> |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
16 #include <QUrl> |
66 | 17 #include <curl/curl.h> |
18 | |
83 | 19 Poster::Poster(QWidget* parent) : QFrame(parent) { |
66 | 20 QHBoxLayout* layout = new QHBoxLayout(this); |
21 layout->setContentsMargins(1, 1, 1, 1); | |
22 | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
23 setCursor(Qt::PointingHandCursor); |
66 | 24 setFixedSize(150, 225); |
25 setFrameShape(QFrame::Box); | |
26 setFrameShadow(QFrame::Plain); | |
76 | 27 |
83 | 28 label = new ClickableLabel(this); |
29 label->setAlignment(Qt::AlignCenter); | |
30 layout->addWidget(label); | |
31 } | |
66 | 32 |
83 | 33 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) { |
34 SetAnime(anime); | |
35 } | |
36 | |
37 void Poster::SetAnime(const Anime::Anime& anime) { | |
77 | 38 QThreadPool::globalInstance()->start([this, anime] { |
39 QByteArray ba = HTTP::Get(anime.GetPosterUrl(), {}); | |
40 ImageDownloadFinished(ba); | |
41 }); | |
75 | 42 |
83 | 43 label->disconnect(); |
76 | 44 connect(label, &ClickableLabel::clicked, this, |
45 [anime] { QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); }); | |
66 | 46 } |
47 | |
83 | 48 void Poster::ImageDownloadFinished(const QByteArray& arr) { |
75 | 49 img.loadFromData(arr); |
50 RenderToLabel(); | |
51 } | |
52 | |
53 void Poster::RenderToLabel() { | |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
54 const QPixmap pixmap = QPixmap::fromImage(img); |
76 | 55 if (pixmap.isNull()) |
56 return; | |
75 | 57 label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); |
58 } | |
59 | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
60 void Poster::resizeEvent(QResizeEvent*) { |
75 | 61 RenderToLabel(); |
66 | 62 } |
63 | |
64 #include "gui/widgets/moc_poster.cpp" |