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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
1 #include "gui/pages/now_playing.h"
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
2 #include "core/anime_db.h"
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
3 #include "gui/widgets/anime_info.h"
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
4 #include "gui/widgets/text.h"
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
5 #include <QLabel>
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
6 #include <QStackedWidget>
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
7 #include <QVBoxLayout>
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
8 #include <QWidget>
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
9
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
10 /* This is here to make it easier to switch between the
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
11 "sub-pages", i.e., not playing and playing.
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
12
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
13 TODO: find a way to do this more efficiently */
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
14 namespace NowPlayingPages {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
15
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
16 class Default : public QWidget {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
17 Q_OBJECT
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
18
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
19 public:
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
20 Default(QWidget* parent = nullptr);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
21 };
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
22
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
23 class Playing : public QWidget {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
24 Q_OBJECT
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
25
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
26 public:
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
27 Playing(QWidget* parent = nullptr);
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
28 void SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info);
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
29 int GetPlayingAnime();
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
30
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
31 private:
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
32 int _id = 0;
79
c489dd4434af *: what did I do again?
Paper <mrpapersonic@gmail.com>
parents: 69
diff changeset
33 int _episode = 0;
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
34 std::unique_ptr<TextWidgets::Title> _title = nullptr;
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
35 std::unique_ptr<AnimeInfoWidget> _info = nullptr;
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
36 };
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
37
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
38 Default::Default(QWidget* parent) : QWidget(parent) {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
39 QVBoxLayout* layout = new QVBoxLayout(this);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
40 layout->setContentsMargins(0, 0, 0, 0);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
41
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
42 TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this);
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
43 layout->addWidget(title);
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
44
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
45 layout->addStretch();
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
46 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
47
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
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
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
51 _title.reset(new TextWidgets::Title("\n", this));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
52 layout->addWidget(_title.get());
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
53
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
54 _info.reset(new AnimeInfoWidget(this));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
55 layout->addWidget(_info.get());
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
56
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
57 layout->setContentsMargins(0, 0, 0, 0);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
58 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
59
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
60 int Playing::GetPlayingAnime() {
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
61 return _id;
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
62 }
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
63
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
64 void Playing::SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info) {
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
65 if (id == _id || id <= 0)
79
c489dd4434af *: what did I do again?
Paper <mrpapersonic@gmail.com>
parents: 69
diff changeset
66 return;
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
67 if (Anime::db.items.find(id) != Anime::db.items.end()) {
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
68 const Anime::Anime& anime = Anime::db.items[_id = id];
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
69 _title->setText(anime.GetUserPreferredTitle());
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
70 _info->SetAnime(anime);
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
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
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
74 } // namespace NowPlayingPages
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
75
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
76 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
77 QVBoxLayout* layout = new QVBoxLayout(this);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
78
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
79 setFrameShape(QFrame::Box);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
80 setFrameShadow(QFrame::Sunken);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
81
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
82 QPalette pal = QPalette();
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
83 pal.setColor(QPalette::Window, pal.color(QPalette::Base));
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
84 setPalette(pal);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
85 setAutoFillBackground(true);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
86
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
87 stack = new QStackedWidget(this);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
88 stack->addWidget(new NowPlayingPages::Default(stack));
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
89 stack->addWidget(new NowPlayingPages::Playing(stack));
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
90 layout->addWidget(stack);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
91
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
92 SetDefault();
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
93 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
94
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
95 void NowPlayingPage::SetDefault() {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
96 stack->setCurrentIndex(0);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
97 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
98
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
99 int NowPlayingPage::GetPlayingId() {
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
100 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime();
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
101 }
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
102
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
103 void NowPlayingPage::SetPlaying(int id, const std::unordered_map<std::string, std::string>& info) {
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
104 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id, info);
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
105 stack->setCurrentIndex(1);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
106 }
7
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
107
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
108 #include "gui/pages/moc_now_playing.cpp"
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
109 #include "now_playing.moc"