Mercurial > minori
changeset 67:442065432549
poster: make posters link to AniList
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 02 Oct 2023 07:06:44 -0400 |
parents | 6481c5aed3e1 |
children | 2417121d894e |
files | CMakeLists.txt include/core/anime.h include/gui/widgets/clickable_label.h include/gui/widgets/poster.h src/core/anime.cpp src/gui/widgets/clickable_label.cpp src/gui/widgets/poster.cpp |
diffstat | 7 files changed, 60 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Mon Oct 02 05:56:32 2023 -0400 +++ b/CMakeLists.txt Mon Oct 02 07:06:44 2023 -0400 @@ -77,6 +77,7 @@ # Custom widgets src/gui/widgets/anime_info.cpp src/gui/widgets/poster.cpp + src/gui/widgets/clickable_label.cpp src/gui/widgets/sidebar.cpp src/gui/widgets/text.cpp src/gui/widgets/optional_date.cpp
--- a/include/core/anime.h Mon Oct 02 05:56:32 2023 -0400 +++ b/include/core/anime.h Mon Oct 02 07:06:44 2023 -0400 @@ -139,6 +139,7 @@ std::string GetSynopsis() const; int GetDuration() const; std::string GetPosterUrl() const; + std::string GetServiceUrl() const; void SetId(int id); void SetRomajiTitle(std::string const& title);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/gui/widgets/clickable_label.h Mon Oct 02 07:06:44 2023 -0400 @@ -0,0 +1,22 @@ +#ifndef __gui__widgets__clickable_label_h +#define __gui__widgets__clickable_label_h + +#include <QLabel> + +class QWidget; + +class ClickableLabel : public QLabel { + Q_OBJECT + + public: + explicit ClickableLabel(QWidget* parent = nullptr); + ~ClickableLabel(); + + signals: + void clicked(); + + protected: + void mousePressEvent(QMouseEvent*) override; +}; + +#endif // __gui__widgets__clickable_label_h
--- a/include/gui/widgets/poster.h Mon Oct 02 05:56:32 2023 -0400 +++ b/include/gui/widgets/poster.h Mon Oct 02 07:06:44 2023 -0400 @@ -4,7 +4,7 @@ #include <QImage> class QWidget; -class QLabel; +class ClickableLabel; class Poster : public QFrame { Q_OBJECT @@ -13,11 +13,11 @@ Poster(int id, QWidget* parent = nullptr); protected: - void resizeEvent(QResizeEvent* event) override; + void resizeEvent(QResizeEvent*) override; private: QImage img; - QLabel* label; + ClickableLabel* label; }; #endif // __gui__widgets__poster_h \ No newline at end of file
--- a/src/core/anime.cpp Mon Oct 02 05:56:32 2023 -0400 +++ b/src/core/anime.cpp Mon Oct 02 07:06:44 2023 -0400 @@ -206,6 +206,10 @@ return info_.poster_url; } +std::string Anime::GetServiceUrl() const { + return "https://anilist.co/anime/" + std::to_string(GetId()); +} + void Anime::SetId(int id) { info_.id = id; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gui/widgets/clickable_label.cpp Mon Oct 02 07:06:44 2023 -0400 @@ -0,0 +1,16 @@ +#include "gui/widgets/clickable_label.h" +/* NOTE: this can likely be moved to poster.cpp, as + it's really the only place this will ever be used */ + +ClickableLabel::ClickableLabel(QWidget* parent) : QLabel(parent) { + setCursor(Qt::PointingHandCursor); +} + +ClickableLabel::~ClickableLabel() { +} + +void ClickableLabel::mousePressEvent(QMouseEvent*) { + emit clicked(); +} + +#include "gui/widgets/moc_clickable_label.cpp"
--- a/src/gui/widgets/poster.cpp Mon Oct 02 05:56:32 2023 -0400 +++ b/src/gui/widgets/poster.cpp Mon Oct 02 07:06:44 2023 -0400 @@ -1,11 +1,16 @@ #include "gui/widgets/poster.h" +#include "gui/widgets/clickable_label.h" #include "core/anime_db.h" +#include "core/strings.h" #include "core/session.h" #include <QFrame> #include <QMessageBox> #include <QLabel> #include <QHBoxLayout> #include <QByteArray> +#include <QDesktopServices> +#include <QUrl> +#include <QDebug> #include <QPixmap> #include <curl/curl.h> @@ -39,6 +44,7 @@ QHBoxLayout* layout = new QHBoxLayout(this); layout->setContentsMargins(1, 1, 1, 1); + setCursor(Qt::PointingHandCursor); setFixedSize(150, 225); setFrameShape(QFrame::Box); setFrameShadow(QFrame::Plain); @@ -49,14 +55,16 @@ img.loadFromData(ret); QPixmap pixmap = QPixmap::fromImage(img); - label = new QLabel(this); - label->setAlignment(Qt::AlignCenter); + label = new ClickableLabel(this); + connect(label, &ClickableLabel::clicked, this, [anime]{ + QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); + }); layout->addWidget(label); } -void Poster::resizeEvent(QResizeEvent* event) { - QPixmap pixmap = QPixmap::fromImage(img); - label->setPixmap(pixmap.scaled(label->width(), label->height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); +void Poster::resizeEvent(QResizeEvent*) { + QPixmap pixmap = QPixmap::fromImage(img).scaled(size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); + label->setPixmap(pixmap); } #include "gui/widgets/moc_poster.cpp"