comparison src/gui/pages/now_playing.cpp @ 69:27a19dd6cba1

*: fix up some stuff settings: due to my own incompetence OnOK caused the entire program to crash, now that's fixed :)
author Paper <mrpapersonic@gmail.com>
date Tue, 03 Oct 2023 03:38:25 -0400
parents 2417121d894e
children c489dd4434af
comparison
equal deleted inserted replaced
68:2417121d894e 69:27a19dd6cba1
20 Q_OBJECT 20 Q_OBJECT
21 21
22 public: 22 public:
23 Playing(QWidget* parent = nullptr); 23 Playing(QWidget* parent = nullptr);
24 void SetPlayingAnime(int id); 24 void SetPlayingAnime(int id);
25 int GetPlayingAnime();
25 26
26 private: 27 private:
28 int _id = 0;
27 std::unique_ptr<AnimeInfoWidget> info = nullptr; 29 std::unique_ptr<AnimeInfoWidget> info = nullptr;
28 }; 30 };
29 31
30 Default::Default(QWidget* parent) : QWidget(parent) { 32 Default::Default(QWidget* parent) : QWidget(parent) {
31 QVBoxLayout* layout = new QVBoxLayout(this); 33 QVBoxLayout* layout = new QVBoxLayout(this);
38 QHBoxLayout* layout = new QHBoxLayout(this); 40 QHBoxLayout* layout = new QHBoxLayout(this);
39 41
40 layout->setContentsMargins(0, 0, 0, 0); 42 layout->setContentsMargins(0, 0, 0, 0);
41 } 43 }
42 44
45 int Playing::GetPlayingAnime() {
46 return _id;
47 }
48
43 void Playing::SetPlayingAnime(int id) { 49 void Playing::SetPlayingAnime(int id) {
44 if (info.get()) 50 if (info.get())
45 layout()->removeWidget(info.get()); 51 layout()->removeWidget(info.get());
46 info.reset(new AnimeInfoWidget(Anime::db.items[id])); 52 if (Anime::db.items.find(id) != Anime::db.items.end()) {
47 layout()->addWidget(info.get()); 53 info.reset(new AnimeInfoWidget(Anime::db.items[_id = id]));
54 layout()->addWidget(info.get());
55 }
48 } 56 }
49 57
50 } // namespace NowPlayingPages 58 } // namespace NowPlayingPages
51 59
52 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) { 60 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) {
73 81
74 void NowPlayingPage::SetDefault() { 82 void NowPlayingPage::SetDefault() {
75 stack->setCurrentIndex(0); 83 stack->setCurrentIndex(0);
76 } 84 }
77 85
86 int NowPlayingPage::GetPlayingId() {
87 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime();
88 }
89
78 void NowPlayingPage::SetPlaying(int id) { 90 void NowPlayingPage::SetPlaying(int id) {
79 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id); 91 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id);
80 stack->setCurrentIndex(1); 92 stack->setCurrentIndex(1);
81 } 93 }
82 94