Mercurial > minori
diff 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 |
line wrap: on
line diff
--- a/src/gui/pages/now_playing.cpp Thu Oct 12 11:31:39 2023 -0400 +++ b/src/gui/pages/now_playing.cpp Fri Oct 13 13:15:19 2023 -0400 @@ -7,6 +7,10 @@ #include <QVBoxLayout> #include <QWidget> +/* This is here to make it easier to switch between the + "sub-pages", i.e., not playing and playing. + + TODO: find a way to do this more efficiently */ namespace NowPlayingPages { class Default : public QWidget { @@ -21,25 +25,35 @@ public: Playing(QWidget* parent = nullptr); - void SetPlayingAnime(int id, int episode); + void SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info); int GetPlayingAnime(); private: int _id = 0; int _episode = 0; - std::unique_ptr<AnimeInfoWidget> info = nullptr; + std::unique_ptr<TextWidgets::Title> _title = nullptr; + std::unique_ptr<AnimeInfoWidget> _info = nullptr; }; Default::Default(QWidget* parent) : QWidget(parent) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); + TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this); + layout->addWidget(title); + layout->addStretch(); } Playing::Playing(QWidget* parent) : QWidget(parent) { QHBoxLayout* layout = new QHBoxLayout(this); + _title.reset(new TextWidgets::Title("\n", this)); + layout->addWidget(_title.get()); + + _info.reset(new AnimeInfoWidget(this)); + layout->addWidget(_info.get()); + layout->setContentsMargins(0, 0, 0, 0); } @@ -47,14 +61,13 @@ return _id; } -void Playing::SetPlayingAnime(int id, int episodes) { - if (id == _id) +void Playing::SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info) { + if (id == _id || id <= 0) return; - if (info.get()) - layout()->removeWidget(info.get()); if (Anime::db.items.find(id) != Anime::db.items.end()) { - info.reset(new AnimeInfoWidget(Anime::db.items[_id = id])); - layout()->addWidget(info.get()); + const Anime::Anime& anime = Anime::db.items[_id = id]; + _title->setText(anime.GetUserPreferredTitle()); + _info->SetAnime(anime); } } @@ -71,9 +84,6 @@ setPalette(pal); setAutoFillBackground(true); - TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this); - layout->addWidget(title); - stack = new QStackedWidget(this); stack->addWidget(new NowPlayingPages::Default(stack)); stack->addWidget(new NowPlayingPages::Playing(stack)); @@ -90,8 +100,8 @@ return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime(); } -void NowPlayingPage::SetPlaying(int id, int episodes) { - reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id, episodes); +void NowPlayingPage::SetPlaying(int id, const std::unordered_map<std::string, std::string>& info) { + reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id, info); stack->setCurrentIndex(1); }