Mercurial > minori
comparison src/gui/pages/now_playing.cc @ 81:9b2b41f83a5e
boring: mass rename to cc
because this is a very unix-y project, it makes more sense to use the
'cc' extension
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Mon, 23 Oct 2023 12:07:27 -0400 |
| parents | src/gui/pages/now_playing.cpp@825506f0e221 |
| children | 8b65c417c225 |
comparison
equal
deleted
inserted
replaced
| 80:825506f0e221 | 81:9b2b41f83a5e |
|---|---|
| 1 #include "gui/pages/now_playing.h" | |
| 2 #include "core/anime_db.h" | |
| 3 #include "gui/widgets/anime_info.h" | |
| 4 #include "gui/widgets/text.h" | |
| 5 #include <QLabel> | |
| 6 #include <QStackedWidget> | |
| 7 #include <QVBoxLayout> | |
| 8 #include <QWidget> | |
| 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 */ | |
| 14 namespace NowPlayingPages { | |
| 15 | |
| 16 class Default : public QWidget { | |
| 17 Q_OBJECT | |
| 18 | |
| 19 public: | |
| 20 Default(QWidget* parent = nullptr); | |
| 21 }; | |
| 22 | |
| 23 class Playing : public QWidget { | |
| 24 Q_OBJECT | |
| 25 | |
| 26 public: | |
| 27 Playing(QWidget* parent = nullptr); | |
| 28 void SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info); | |
| 29 int GetPlayingAnime(); | |
| 30 | |
| 31 private: | |
| 32 int _id = 0; | |
| 33 int _episode = 0; | |
| 34 std::unique_ptr<TextWidgets::Title> _title = nullptr; | |
| 35 std::unique_ptr<AnimeInfoWidget> _info = nullptr; | |
| 36 }; | |
| 37 | |
| 38 Default::Default(QWidget* parent) : QWidget(parent) { | |
| 39 QVBoxLayout* layout = new QVBoxLayout(this); | |
| 40 layout->setContentsMargins(0, 0, 0, 0); | |
| 41 | |
| 42 TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this); | |
| 43 layout->addWidget(title); | |
| 44 | |
| 45 layout->addStretch(); | |
| 46 } | |
| 47 | |
| 48 Playing::Playing(QWidget* parent) : QWidget(parent) { | |
| 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()); | |
| 56 | |
| 57 layout->setContentsMargins(0, 0, 0, 0); | |
| 58 } | |
| 59 | |
| 60 int Playing::GetPlayingAnime() { | |
| 61 return _id; | |
| 62 } | |
| 63 | |
| 64 void Playing::SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info) { | |
| 65 if (id == _id || id <= 0) | |
| 66 return; | |
| 67 if (Anime::db.items.find(id) != Anime::db.items.end()) { | |
| 68 const Anime::Anime& anime = Anime::db.items[_id = id]; | |
| 69 _title->setText(anime.GetUserPreferredTitle()); | |
| 70 _info->SetAnime(anime); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 } // namespace NowPlayingPages | |
| 75 | |
| 76 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) { | |
| 77 QVBoxLayout* layout = new QVBoxLayout(this); | |
| 78 | |
| 79 setFrameShape(QFrame::Box); | |
| 80 setFrameShadow(QFrame::Sunken); | |
| 81 | |
| 82 QPalette pal = QPalette(); | |
| 83 pal.setColor(QPalette::Window, pal.color(QPalette::Base)); | |
| 84 setPalette(pal); | |
| 85 setAutoFillBackground(true); | |
| 86 | |
| 87 stack = new QStackedWidget(this); | |
| 88 stack->addWidget(new NowPlayingPages::Default(stack)); | |
| 89 stack->addWidget(new NowPlayingPages::Playing(stack)); | |
| 90 layout->addWidget(stack); | |
| 91 | |
| 92 SetDefault(); | |
| 93 } | |
| 94 | |
| 95 void NowPlayingPage::SetDefault() { | |
| 96 stack->setCurrentIndex(0); | |
| 97 } | |
| 98 | |
| 99 int NowPlayingPage::GetPlayingId() { | |
| 100 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime(); | |
| 101 } | |
| 102 | |
| 103 void NowPlayingPage::SetPlaying(int id, const std::unordered_map<std::string, std::string>& info) { | |
| 104 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id, info); | |
| 105 stack->setCurrentIndex(1); | |
| 106 } | |
| 107 | |
| 108 #include "gui/pages/moc_now_playing.cpp" | |
| 109 #include "now_playing.moc" |
