Mercurial > minori
comparison src/gui/pages/now_playing.cpp @ 80:825506f0e221
[UNFINISHED]: stuff
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 13 Oct 2023 13:15:19 -0400 |
parents | c489dd4434af |
children |
comparison
equal
deleted
inserted
replaced
79:c489dd4434af | 80:825506f0e221 |
---|---|
5 #include <QLabel> | 5 #include <QLabel> |
6 #include <QStackedWidget> | 6 #include <QStackedWidget> |
7 #include <QVBoxLayout> | 7 #include <QVBoxLayout> |
8 #include <QWidget> | 8 #include <QWidget> |
9 | 9 |
10 /* This is here to make it easier to switch between the | |
11 "sub-pages", i.e., not playing and playing. | |
12 | |
13 TODO: find a way to do this more efficiently */ | |
10 namespace NowPlayingPages { | 14 namespace NowPlayingPages { |
11 | 15 |
12 class Default : public QWidget { | 16 class Default : public QWidget { |
13 Q_OBJECT | 17 Q_OBJECT |
14 | 18 |
19 class Playing : public QWidget { | 23 class Playing : public QWidget { |
20 Q_OBJECT | 24 Q_OBJECT |
21 | 25 |
22 public: | 26 public: |
23 Playing(QWidget* parent = nullptr); | 27 Playing(QWidget* parent = nullptr); |
24 void SetPlayingAnime(int id, int episode); | 28 void SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info); |
25 int GetPlayingAnime(); | 29 int GetPlayingAnime(); |
26 | 30 |
27 private: | 31 private: |
28 int _id = 0; | 32 int _id = 0; |
29 int _episode = 0; | 33 int _episode = 0; |
30 std::unique_ptr<AnimeInfoWidget> info = nullptr; | 34 std::unique_ptr<TextWidgets::Title> _title = nullptr; |
35 std::unique_ptr<AnimeInfoWidget> _info = nullptr; | |
31 }; | 36 }; |
32 | 37 |
33 Default::Default(QWidget* parent) : QWidget(parent) { | 38 Default::Default(QWidget* parent) : QWidget(parent) { |
34 QVBoxLayout* layout = new QVBoxLayout(this); | 39 QVBoxLayout* layout = new QVBoxLayout(this); |
35 layout->setContentsMargins(0, 0, 0, 0); | 40 layout->setContentsMargins(0, 0, 0, 0); |
36 | 41 |
42 TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this); | |
43 layout->addWidget(title); | |
44 | |
37 layout->addStretch(); | 45 layout->addStretch(); |
38 } | 46 } |
39 | 47 |
40 Playing::Playing(QWidget* parent) : QWidget(parent) { | 48 Playing::Playing(QWidget* parent) : QWidget(parent) { |
41 QHBoxLayout* layout = new QHBoxLayout(this); | 49 QHBoxLayout* layout = new QHBoxLayout(this); |
50 | |
51 _title.reset(new TextWidgets::Title("\n", this)); | |
52 layout->addWidget(_title.get()); | |
53 | |
54 _info.reset(new AnimeInfoWidget(this)); | |
55 layout->addWidget(_info.get()); | |
42 | 56 |
43 layout->setContentsMargins(0, 0, 0, 0); | 57 layout->setContentsMargins(0, 0, 0, 0); |
44 } | 58 } |
45 | 59 |
46 int Playing::GetPlayingAnime() { | 60 int Playing::GetPlayingAnime() { |
47 return _id; | 61 return _id; |
48 } | 62 } |
49 | 63 |
50 void Playing::SetPlayingAnime(int id, int episodes) { | 64 void Playing::SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info) { |
51 if (id == _id) | 65 if (id == _id || id <= 0) |
52 return; | 66 return; |
53 if (info.get()) | |
54 layout()->removeWidget(info.get()); | |
55 if (Anime::db.items.find(id) != Anime::db.items.end()) { | 67 if (Anime::db.items.find(id) != Anime::db.items.end()) { |
56 info.reset(new AnimeInfoWidget(Anime::db.items[_id = id])); | 68 const Anime::Anime& anime = Anime::db.items[_id = id]; |
57 layout()->addWidget(info.get()); | 69 _title->setText(anime.GetUserPreferredTitle()); |
70 _info->SetAnime(anime); | |
58 } | 71 } |
59 } | 72 } |
60 | 73 |
61 } // namespace NowPlayingPages | 74 } // namespace NowPlayingPages |
62 | 75 |
68 | 81 |
69 QPalette pal = QPalette(); | 82 QPalette pal = QPalette(); |
70 pal.setColor(QPalette::Window, pal.color(QPalette::Base)); | 83 pal.setColor(QPalette::Window, pal.color(QPalette::Base)); |
71 setPalette(pal); | 84 setPalette(pal); |
72 setAutoFillBackground(true); | 85 setAutoFillBackground(true); |
73 | |
74 TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this); | |
75 layout->addWidget(title); | |
76 | 86 |
77 stack = new QStackedWidget(this); | 87 stack = new QStackedWidget(this); |
78 stack->addWidget(new NowPlayingPages::Default(stack)); | 88 stack->addWidget(new NowPlayingPages::Default(stack)); |
79 stack->addWidget(new NowPlayingPages::Playing(stack)); | 89 stack->addWidget(new NowPlayingPages::Playing(stack)); |
80 layout->addWidget(stack); | 90 layout->addWidget(stack); |
88 | 98 |
89 int NowPlayingPage::GetPlayingId() { | 99 int NowPlayingPage::GetPlayingId() { |
90 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime(); | 100 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime(); |
91 } | 101 } |
92 | 102 |
93 void NowPlayingPage::SetPlaying(int id, int episodes) { | 103 void NowPlayingPage::SetPlaying(int id, const std::unordered_map<std::string, std::string>& info) { |
94 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id, episodes); | 104 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id, info); |
95 stack->setCurrentIndex(1); | 105 stack->setCurrentIndex(1); |
96 } | 106 } |
97 | 107 |
98 #include "gui/pages/moc_now_playing.cpp" | 108 #include "gui/pages/moc_now_playing.cpp" |
99 #include "now_playing.moc" | 109 #include "now_playing.moc" |