Mercurial > minori
comparison src/gui/pages/now_playing.cc @ 83:d02fdf1d6708
*: huuuge update
1. make the now playing page function correctly
2. de-constructorfy many of our custom widgets,
allowing them to be changed on-the-fly from
the Now Playing page
3. ... :)
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Tue, 24 Oct 2023 22:01:02 -0400 |
| parents | 8b65c417c225 |
| children | 2c27582a177c |
comparison
equal
deleted
inserted
replaced
| 82:8b65c417c225 | 83:d02fdf1d6708 |
|---|---|
| 1 #include "gui/pages/now_playing.h" | 1 #include "gui/pages/now_playing.h" |
| 2 #include "core/anime_db.h" | 2 #include "core/anime_db.h" |
| 3 #include "core/strings.h" | 3 #include "core/strings.h" |
| 4 #include "gui/widgets/anime_info.h" | 4 #include "gui/widgets/anime_info.h" |
| 5 #include "gui/widgets/text.h" | 5 #include "gui/widgets/text.h" |
| 6 #include "gui/widgets/poster.h" | |
| 6 #include <QLabel> | 7 #include <QLabel> |
| 7 #include <QStackedWidget> | 8 #include <QStackedWidget> |
| 9 #include <QHBoxLayout> | |
| 8 #include <QVBoxLayout> | 10 #include <QVBoxLayout> |
| 9 #include <QWidget> | 11 #include <QWidget> |
| 10 | 12 |
| 11 /* WARNING: HACKY STUFF HERE | 13 /* WARNING: HACKY STUFF HERE |
| 12 | 14 |
| 25 class Playing : public QWidget { | 27 class Playing : public QWidget { |
| 26 Q_OBJECT | 28 Q_OBJECT |
| 27 | 29 |
| 28 public: | 30 public: |
| 29 Playing(QWidget* parent = nullptr); | 31 Playing(QWidget* parent = nullptr); |
| 30 void SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info); | 32 void SetPlayingAnime(const Anime::Anime& anime, const std::unordered_map<std::string, std::string>& info); |
| 31 int GetPlayingAnime(); | 33 int GetPlayingAnime(); |
| 32 | 34 |
| 33 private: | 35 private: |
| 34 int _id = 0; | 36 int _id = 0; |
| 35 int _episode = 0; | 37 int _episode = 0; |
| 38 std::unique_ptr<QWidget> _main = nullptr; | |
| 36 std::unique_ptr<TextWidgets::Title> _title = nullptr; | 39 std::unique_ptr<TextWidgets::Title> _title = nullptr; |
| 37 std::unique_ptr<AnimeInfoWidget> _info = nullptr; | 40 std::unique_ptr<AnimeInfoWidget> _info = nullptr; |
| 41 std::unique_ptr<QWidget> _sidebar = nullptr; | |
| 42 std::unique_ptr<Poster> _poster = nullptr; | |
| 38 }; | 43 }; |
| 39 | 44 |
| 40 Default::Default(QWidget* parent) : QWidget(parent) { | 45 Default::Default(QWidget* parent) : QWidget(parent) { |
| 41 QVBoxLayout* layout = new QVBoxLayout(this); | 46 QVBoxLayout* layout = new QVBoxLayout(this); |
| 42 layout->setContentsMargins(0, 0, 0, 0); | 47 layout->setContentsMargins(0, 0, 0, 0); |
| 48 } | 53 } |
| 49 | 54 |
| 50 Playing::Playing(QWidget* parent) : QWidget(parent) { | 55 Playing::Playing(QWidget* parent) : QWidget(parent) { |
| 51 QHBoxLayout* layout = new QHBoxLayout(this); | 56 QHBoxLayout* layout = new QHBoxLayout(this); |
| 52 | 57 |
| 53 _title.reset(new TextWidgets::Title("\n", this)); | 58 _main.reset(new QWidget(this)); |
| 54 layout->addWidget(_title.get()); | 59 _main->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
| 55 | 60 |
| 56 _info.reset(new AnimeInfoWidget(this)); | 61 QVBoxLayout* main_layout = new QVBoxLayout(_main.get()); |
| 57 layout->addWidget(_info.get()); | 62 main_layout->setContentsMargins(0, 0, 0, 0); |
| 58 | 63 |
| 64 _title.reset(new TextWidgets::Title("", _main.get())); | |
| 65 main_layout->addWidget(_title.get()); | |
| 66 | |
| 67 _info.reset(new AnimeInfoWidget(_main.get())); | |
| 68 _info->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | |
| 69 main_layout->addWidget(_info.get()); | |
| 70 | |
| 71 /* "sidebar", includes... just the anime image :) */ | |
| 72 _sidebar.reset(new QWidget(this)); | |
| 73 QVBoxLayout* sidebar_layout = new QVBoxLayout(_sidebar.get()); | |
| 74 sidebar_layout->setContentsMargins(0, 0, 0, 0); | |
| 75 | |
| 76 _poster.reset(new Poster(_sidebar.get())); | |
| 77 sidebar_layout->addWidget(_poster.get()); | |
| 78 | |
| 79 sidebar_layout->addStretch(); | |
| 80 | |
| 81 layout->addWidget(_sidebar.get()); | |
| 82 layout->addWidget(_main.get()); | |
| 83 layout->setSpacing(10); | |
| 59 layout->setContentsMargins(0, 0, 0, 0); | 84 layout->setContentsMargins(0, 0, 0, 0); |
| 60 } | 85 } |
| 61 | 86 |
| 62 int Playing::GetPlayingAnime() { | 87 int Playing::GetPlayingAnime() { |
| 63 return _id; | 88 return _id; |
| 64 } | 89 } |
| 65 | 90 |
| 66 void Playing::SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info) { | 91 void Playing::SetPlayingAnime(const Anime::Anime& anime, const std::unordered_map<std::string, std::string>& info) { |
| 67 if (id == _id || id <= 0) | 92 if (_id == anime.GetId() && std::to_string(_episode) == info.at("episode")) |
| 68 return; | 93 return; |
| 69 if (Anime::db.items.find(id) != Anime::db.items.end()) { | 94 _id = anime.GetId(); |
| 70 const Anime::Anime& anime = Anime::db.items[_id = id]; | 95 try { |
| 71 _title->setText(Strings::ToQString(anime.GetUserPreferredTitle())); | 96 _episode = std::stoi(info.at("episode")); |
| 72 _info->SetAnime(anime); | 97 } catch (std::invalid_argument) { |
| 98 _episode = 0; | |
| 73 } | 99 } |
| 100 _title->SetText(Strings::ToQString(anime.GetUserPreferredTitle())); | |
| 101 _info->SetAnime(anime); | |
| 102 _poster->SetAnime(anime); | |
| 103 | |
| 104 updateGeometry(); | |
| 74 } | 105 } |
| 75 | 106 |
| 76 } // namespace NowPlayingPages | 107 } // namespace NowPlayingPages |
| 77 | 108 |
| 78 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) { | 109 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) { |
| 100 | 131 |
| 101 int NowPlayingPage::GetPlayingId() { | 132 int NowPlayingPage::GetPlayingId() { |
| 102 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime(); | 133 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime(); |
| 103 } | 134 } |
| 104 | 135 |
| 105 void NowPlayingPage::SetPlaying(int id, const std::unordered_map<std::string, std::string>& info) { | 136 void NowPlayingPage::SetPlaying(const Anime::Anime& anime, const std::unordered_map<std::string, std::string>& info) { |
| 106 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id, info); | 137 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(anime, info); |
| 107 stack->setCurrentIndex(1); | 138 stack->setCurrentIndex(1); |
| 139 updateGeometry(); | |
| 108 } | 140 } |
| 109 | 141 |
| 110 #include "gui/pages/moc_now_playing.cpp" | 142 #include "gui/pages/moc_now_playing.cpp" |
| 111 #include "now_playing.moc" | 143 #include "now_playing.moc" |
