Mercurial > minori
annotate 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 |
rev | line source |
---|---|
9 | 1 #include "gui/pages/now_playing.h" |
64 | 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 | |
80 | 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 */ | |
64 | 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); | |
80 | 28 void SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info); |
69 | 29 int GetPlayingAnime(); |
64 | 30 |
31 private: | |
69 | 32 int _id = 0; |
79 | 33 int _episode = 0; |
80 | 34 std::unique_ptr<TextWidgets::Title> _title = nullptr; |
35 std::unique_ptr<AnimeInfoWidget> _info = nullptr; | |
64 | 36 }; |
37 | |
38 Default::Default(QWidget* parent) : QWidget(parent) { | |
39 QVBoxLayout* layout = new QVBoxLayout(this); | |
40 layout->setContentsMargins(0, 0, 0, 0); | |
2 | 41 |
80 | 42 TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this); |
43 layout->addWidget(title); | |
44 | |
64 | 45 layout->addStretch(); |
46 } | |
47 | |
48 Playing::Playing(QWidget* parent) : QWidget(parent) { | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
49 QHBoxLayout* layout = new QHBoxLayout(this); |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
50 |
80 | 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 | |
64 | 57 layout->setContentsMargins(0, 0, 0, 0); |
58 } | |
59 | |
69 | 60 int Playing::GetPlayingAnime() { |
61 return _id; | |
62 } | |
63 | |
80 | 64 void Playing::SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info) { |
65 if (id == _id || id <= 0) | |
79 | 66 return; |
69 | 67 if (Anime::db.items.find(id) != Anime::db.items.end()) { |
80 | 68 const Anime::Anime& anime = Anime::db.items[_id = id]; |
69 _title->setText(anime.GetUserPreferredTitle()); | |
70 _info->SetAnime(anime); | |
69 | 71 } |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
72 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
73 |
64 | 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 | |
69 | 99 int NowPlayingPage::GetPlayingId() { |
100 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime(); | |
101 } | |
102 | |
80 | 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); | |
64 | 105 stack->setCurrentIndex(1); |
2 | 106 } |
7 | 107 |
46 | 108 #include "gui/pages/moc_now_playing.cpp" |
64 | 109 #include "now_playing.moc" |