comparison src/gui/widgets/poster.cc @ 254:d14f8e0e40c3

[UNFINISHED] *: update anime button
author Paper <paper@paper.us.eu.org>
date Wed, 07 Feb 2024 07:57:37 -0500
parents 4d461ef7d424
children fe702c8f161f
comparison
equal deleted inserted replaced
253:b3549da699a6 254:d14f8e0e40c3
2 #include "core/anime_db.h" 2 #include "core/anime_db.h"
3 #include "core/http.h" 3 #include "core/http.h"
4 #include "core/session.h" 4 #include "core/session.h"
5 #include "core/strings.h" 5 #include "core/strings.h"
6 #include "gui/widgets/clickable_label.h" 6 #include "gui/widgets/clickable_label.h"
7
7 #include <QByteArray> 8 #include <QByteArray>
8 #include <QDebug> 9 #include <QDebug>
9 #include <QDesktopServices> 10 #include <QDesktopServices>
10 #include <QFrame> 11 #include <QFrame>
11 #include <QHBoxLayout> 12 #include <QHBoxLayout>
12 #include <QLabel> 13 #include <QLabel>
13 #include <QMessageBox> 14 #include <QMessageBox>
14 #include <QPixmap> 15 #include <QPixmap>
15 #include <QThread> 16 #include <QThread>
16 #include <QUrl> 17 #include <QUrl>
17 #include <curl/curl.h>
18 18
19 Poster::Poster(QWidget* parent) : QFrame(parent) { 19 Poster::Poster(QWidget* parent) : QFrame(parent) {
20 QHBoxLayout* layout = new QHBoxLayout(this); 20 QHBoxLayout* layout = new QHBoxLayout(this);
21 layout->setContentsMargins(1, 1, 1, 1); 21 layout->setContentsMargins(1, 1, 1, 1);
22 22
42 connect(thread, &HTTP::GetThread::finished, thread, &HTTP::GetThread::deleteLater); 42 connect(thread, &HTTP::GetThread::finished, thread, &HTTP::GetThread::deleteLater);
43 43
44 thread->start(); 44 thread->start();
45 } 45 }
46 46
47 label->disconnect(); 47 service_url = Strings::ToQString(anime.GetServiceUrl());
48 connect(label, &ClickableLabel::clicked, this, 48
49 [anime] { QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); }); 49 if (clickable) {
50 label->disconnect();
51 connect(label, &ClickableLabel::clicked, this,
52 [this] { QDesktopServices::openUrl(service_url); });
53 }
54 }
55
56 void Poster::SetClickable(bool enabled) {
57 clickable = enabled;
58
59 if (clickable && !service_url.isEmpty()) {
60 setCursor(Qt::PointingHandCursor);
61 label->disconnect();
62 connect(label, &ClickableLabel::clicked, this,
63 [this] { QDesktopServices::openUrl(service_url); });
64 } else {
65 setCursor(Qt::ArrowCursor);
66 label->disconnect();
67 }
50 } 68 }
51 69
52 void Poster::ImageDownloadFinished(const QByteArray& arr) { 70 void Poster::ImageDownloadFinished(const QByteArray& arr) {
53 img.loadFromData(arr); 71 img.loadFromData(arr);
54 RenderToLabel(); 72 RenderToLabel();