Mercurial > minori
view src/gui/widgets/poster.cc @ 229:adc20fa321c1
theme: force Fusion style on platforms other than Win32 or OS X
I was reluctant to do this, but most of the other styles just
look like pure shite regardless of whether I force a stylesheet
on them or not. KDE's style is actually hilariously bad paired
with my stylesheet, so I've decided to also make the stylesheet
Windows-specific as well, because that's really the only platform
where it makes sense in the first place.
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 10 Jan 2024 21:23:57 -0500 |
parents | 9613d72b097e |
children | 2f5a9247e501 |
line wrap: on
line source
#include "gui/widgets/poster.h" #include "core/anime_db.h" #include "core/http.h" #include "core/session.h" #include "core/strings.h" #include "gui/widgets/clickable_label.h" #include <QByteArray> #include <QDebug> #include <QDesktopServices> #include <QFrame> #include <QHBoxLayout> #include <QLabel> #include <QMessageBox> #include <QPixmap> #include <QThreadPool> #include <QUrl> #include <curl/curl.h> Poster::Poster(QWidget* parent) : QFrame(parent) { QHBoxLayout* layout = new QHBoxLayout(this); layout->setContentsMargins(1, 1, 1, 1); setCursor(Qt::PointingHandCursor); setFixedSize(150, 225); setFrameShape(QFrame::Box); setFrameShadow(QFrame::Plain); label = new ClickableLabel(this); label->setAlignment(Qt::AlignCenter); layout->addWidget(label); } Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) { SetAnime(anime); } void Poster::SetAnime(const Anime::Anime& anime) { QThreadPool::globalInstance()->start([this, anime] { QByteArray ba = HTTP::Get(anime.GetPosterUrl(), {}); ImageDownloadFinished(ba); }); label->disconnect(); connect(label, &ClickableLabel::clicked, this, [anime] { QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); }); } void Poster::ImageDownloadFinished(const QByteArray& arr) { img.loadFromData(arr); RenderToLabel(); } void Poster::RenderToLabel() { const QPixmap pixmap = QPixmap::fromImage(img); if (pixmap.isNull()) return; label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); } void Poster::resizeEvent(QResizeEvent*) { RenderToLabel(); } #include "gui/widgets/moc_poster.cpp"